00001
00002
00003
00004
00005
00007
00008 #include <iostream>
00009 #include <fstream>
00010 #include <vector>
00011
00012 #include "HepMC/GenEvent.h"
00013 #include "HepMC/IO_GenEvent.h"
00014
00015 typedef std::vector<HepMC::GenParticle*> FlowVec;
00016
00017 int main() {
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 const char outfile[] = "testFlow.out";
00034 std::ofstream os( outfile );
00035 if( !os ) {
00036 std::cerr << "cannot open " << outfile << std::endl;
00037 exit(-1);
00038 }
00039
00040 HepMC::IO_GenEvent xout1("testFlow.out1",std::ios::out);
00041 HepMC::IO_GenEvent xout2("testFlow.out2",std::ios::out);
00042 HepMC::IO_GenEvent xout3("testFlow.out3",std::ios::out);
00043
00044 std::ofstream xout4( "testFlow.out4" );
00045 std::ofstream xout5( "testFlow.out5" );
00046
00047 int numbad = 0;
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 HepMC::GenEvent* evt = new HepMC::GenEvent( 20, 1 );
00067 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
00068
00069
00070 HepMC::GenVertex* v1 = new HepMC::GenVertex();
00071 evt->add_vertex( v1 );
00072 HepMC::GenParticle* p1 = new HepMC::GenParticle( HepMC::FourVector(0,0,7000,7000),
00073 2212, 3 );
00074 p1->set_flow(1,231);
00075 v1->add_particle_in( p1 );
00076 HepMC::GenVertex* v2 = new HepMC::GenVertex();
00077 evt->add_vertex( v2 );
00078 HepMC::GenParticle* p2 = new HepMC::GenParticle( HepMC::FourVector(0,0,-7000,7000),
00079 2212, 3 );
00080 p2->set_flow(1,243);
00081 v2->add_particle_in( p2 );
00082
00083
00084 HepMC::GenParticle* p3 =
00085 new HepMC::GenParticle( HepMC::FourVector(.750,-1.569,32.191,32.238),
00086 1, 3 );
00087 p3->set_flow(1,231);
00088 v1->add_particle_out( p3 );
00089 HepMC::GenParticle* p4 =
00090 new HepMC::GenParticle( HepMC::FourVector(-3.047,-19.,-54.629,57.920),
00091 -2, 3 );
00092 p4->set_flow(1,243);
00093 v2->add_particle_out( p4 );
00094
00095
00096 HepMC::GenVertex* v3 = new HepMC::GenVertex();
00097 evt->add_vertex( v3 );
00098 v3->add_particle_in( p3 );
00099 v3->add_particle_in( p4 );
00100 HepMC::GenParticle* p6 =
00101 new HepMC::GenParticle( HepMC::FourVector(-3.813,0.113,-1.833,4.233 ),
00102 22, 1 );
00103 p6->set_flow(1,231);
00104 v3->add_particle_out( p6 );
00105 HepMC::GenParticle* p5 =
00106 new HepMC::GenParticle( HepMC::FourVector(1.517,-20.68,-20.605,85.925),
00107 -24, 3 );
00108 p5->set_flow(1,243);
00109 v3->add_particle_out( p5 );
00110
00111
00112 HepMC::GenVertex* v4 = new HepMC::GenVertex(HepMC::FourVector(0.12,-0.3,0.05,0.004));
00113 evt->add_vertex( v4 );
00114 v4->add_particle_in( p5 );
00115 HepMC::GenParticle* p7 = new HepMC::GenParticle( HepMC::FourVector(-2.445,28.816,6.082,29.552), 1,1 );
00116 v4->add_particle_out( p7 );
00117 HepMC::GenParticle* p8 = new HepMC::GenParticle( HepMC::FourVector(3.962,-49.498,-26.687,56.373), -2,1 );
00118 v4->add_particle_out( p8 );
00119
00120
00121 evt->set_signal_process_vertex( v3 );
00122
00123 evt->print( os );
00124
00125
00126 os << std::endl;
00127 FlowVec result1 = p1->flow().dangling_connected_partners( p1->flow().icode(1) );
00128 FlowVec result2 = p1->flow().connected_partners( p1->flow().icode(1) );
00129 FlowVec::iterator it;
00130 os << "dangling partners of particle " << p1->barcode() << std::endl;
00131 for( it = result1.begin(); it != result1.end(); ++it ) {
00132 os << (*it)->barcode() << " " ;
00133 os.width(8);
00134 os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl;
00135 }
00136 os << "all partners of particle " << p1->barcode() << std::endl;
00137 for( it = result2.begin(); it != result2.end(); ++it ) {
00138 os << (*it)->barcode() << " " ;
00139 os.width(8);
00140 os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl;
00141 }
00142 FlowVec result3 = p2->flow().dangling_connected_partners( p2->flow().icode(1) );
00143 FlowVec result4 = p2->flow().connected_partners( p2->flow().icode(1) );
00144 os << "dangling partners of particle " << p2->barcode() << std::endl;
00145 for( it = result3.begin(); it != result3.end(); ++it ) {
00146 os << (*it)->barcode() << " " ;
00147 os.width(8);
00148 os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl;
00149 }
00150 os << "all partners of particle " << p2->barcode() << std::endl;
00151 for( it = result4.begin(); it != result4.end(); ++it ) {
00152 os << (*it)->barcode() << " " ;
00153 os.width(8);
00154 os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl;
00155 }
00156
00157 xout1 << evt;
00158
00159
00160 evt->write(xout4);
00161
00162 HepMC::GenEvent(*evt).write(xout5);
00163
00164
00165 p2->set_flow(2,345);
00166 xout2 << evt;
00167 FlowVec result5 = p2->flow().connected_partners( p2->flow().icode(1) );
00168 if ( result4 != result5 ) {
00169 std::cerr << "ERROR: list of partners has changed after adding flow" << std::endl;
00170 ++numbad;
00171 }
00172
00173
00174 HepMC::Flow f2 = p2->flow();
00175 if( f2.erase(2) ) {
00176 p2->set_flow( f2 );
00177 } else {
00178 std::cerr << "ERROR: first erase was NOT successful" << std::endl;
00179 ++numbad;
00180 }
00181 f2 = p2->flow();
00182 if( f2.erase(2) ) {
00183 std::cerr << "ERROR: second erase was successful" << std::endl;
00184 }
00185 xout3 << evt;
00186 FlowVec result6 = p2->flow().connected_partners( p2->flow().icode(1) );
00187 if ( result4 != result6 ) {
00188 std::cerr << "ERROR: list of partners has changed after removing flow" << std::endl;
00189 ++numbad;
00190 }
00191
00192
00193
00194
00195
00196 delete evt;
00197
00198 if( numbad > 0 ) std::cerr << numbad << " errors in testFlow" << std::endl;
00199
00200 return numbad;
00201 }