![]() |
HepMC Reference DocumentationHepMC |
00001 00002 // Matt.Dobbs@Cern.CH, Feb 2000 00003 // Example of building an event and a particle data table from scratch 00004 // This is meant to be of use for persons implementing HepMC inside a MC 00005 // event generator 00007 // To Compile: go to the HepMC directory and type: 00008 // gmake examples/example_BuildEventFromScratch.exe 00009 // 00010 00011 #include <iostream> 00012 00013 #include "VectorConversion.h" 00014 #include "HepMC/GenEvent.h" 00015 #include "HepMC/ParticleDataTable.h" 00016 #include "CLHEP/Vector/LorentzVector.h" 00017 00018 // in this example we use the HepMC namespace, so that we do not have to 00019 // precede all HepMC classes with HepMC:: 00020 00021 // This example also shows how to use the CLHEP Lorentz vector with HepMC2 00022 00023 using namespace HepMC; 00024 using namespace CLHEP; 00025 00026 int main() { 00027 // 00028 // In this example we will place the following event into HepMC "by hand" 00029 // 00030 // name status pdg_id parent Px Py Pz Energy Mass 00031 // 1 !p+! 3 2212 0,0 0.000 0.000 7000.000 7000.000 0.938 00032 // 2 !p+! 3 2212 0,0 0.000 0.000-7000.000 7000.000 0.938 00033 //========================================================================= 00034 // 3 !d! 3 1 1,1 0.750 -1.569 32.191 32.238 0.000 00035 // 4 !u~! 3 -2 2,2 -3.047 -19.000 -54.629 57.920 0.000 00036 // 5 !W-! 3 -24 1,2 1.517 -20.68 -20.605 85.925 80.799 00037 // 6 !gamma! 1 22 1,2 -3.813 0.113 -1.833 4.233 0.000 00038 // 7 !d! 1 1 5,5 -2.445 28.816 6.082 29.552 0.010 00039 // 8 !u~! 1 -2 5,5 3.962 -49.498 -26.687 56.373 0.006 00040 00041 // first we construct a ParticleDataTable with all the particles we need 00042 ParticleDataTable pdt("my particle data table"); 00043 // create a particle data entry for the proton and add it to pdt at the 00044 // same time 00045 pdt.insert( new ParticleData( "p+", 2212, +1, 0.938, -1, .5 ) ); 00046 pdt.insert( new ParticleData( "d", 1, -2./3., 0, -1, .5 ) ); 00047 pdt.insert( new ParticleData( "u~", -2, -1./3., 0, -1, .5 ) ); 00048 pdt.insert( new ParticleData( "W-", -24, -1, 80.396, 00049 clifetime_from_width(2.06), 1 ) ); 00050 pdt.insert( new ParticleData( "gamma", 22, 0, 0, -1, 1 ) ); 00051 00052 // print out the GenParticle Data to the screen 00053 pdt.print(); 00054 00055 // now we build the graph, which will look like 00056 // p7 # 00057 // p1 / # 00058 // \v1__p3 p5---v4 # 00059 // \_v3_/ \ # 00060 // / \ p8 # 00061 // v2__p4 \ # 00062 // / p6 # 00063 // p2 # 00064 // # 00065 00066 // First create the event container, with Signal Process 20, event number 1 00067 // 00068 // Note that the HepLorentzVectors will be automatically converted to 00069 // HepMC::FourVector within GenParticle and GenVertex 00070 GenEvent* evt = new GenEvent( 20, 1 ); 00071 // define the units 00072 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM); 00073 // 00074 // create vertex 1 and vertex 2, together with their inparticles 00075 GenVertex* v1 = new GenVertex(); 00076 evt->add_vertex( v1 ); 00077 v1->add_particle_in( new GenParticle( HepLorentzVector(0,0,7000,7000), 00078 2212, 3 ) ); 00079 GenVertex* v2 = new GenVertex(); 00080 evt->add_vertex( v2 ); 00081 v2->add_particle_in( new GenParticle( HepLorentzVector(0,0,-7000,7000), 00082 2212, 3 ) ); 00083 // 00084 // create the outgoing particles of v1 and v2 00085 GenParticle* p3 = 00086 new GenParticle( HepLorentzVector(.750,-1.569,32.191,32.238), 1, 3 ); 00087 v1->add_particle_out( p3 ); 00088 GenParticle* p4 = 00089 new GenParticle( HepLorentzVector(-3.047,-19.,-54.629,57.920), -2, 3 ); 00090 v2->add_particle_out( p4 ); 00091 // 00092 // create v3 00093 GenVertex* v3 = new GenVertex(); 00094 evt->add_vertex( v3 ); 00095 v3->add_particle_in( p3 ); 00096 v3->add_particle_in( p4 ); 00097 v3->add_particle_out( 00098 new GenParticle( HepLorentzVector(-3.813,0.113,-1.833,4.233 ), 22, 1 ) 00099 ); 00100 GenParticle* p5 = 00101 new GenParticle( HepLorentzVector(1.517,-20.68,-20.605,85.925), -24,3); 00102 v3->add_particle_out( p5 ); 00103 // 00104 // create v4 00105 GenVertex* v4 = new GenVertex(HepLorentzVector(0.12,-0.3,0.05,0.004)); 00106 evt->add_vertex( v4 ); 00107 v4->add_particle_in( p5 ); 00108 v4->add_particle_out( 00109 new GenParticle( HepLorentzVector(-2.445,28.816,6.082,29.552), 1,1 ) 00110 ); 00111 v4->add_particle_out( 00112 new GenParticle( HepLorentzVector(3.962,-49.498,-26.687,56.373), -2,1 ) 00113 ); 00114 // 00115 // tell the event which vertex is the signal process vertex 00116 evt->set_signal_process_vertex( v3 ); 00117 // the event is complete, we now print it out to the screen 00118 evt->print(); 00119 00120 // example conversion back to Lorentz vector 00121 // add all outgoing momenta 00122 std::cout << std::endl; 00123 std::cout << " Add output momenta " << std::endl; 00124 HepLorentzVector sum; 00125 for ( GenEvent::particle_const_iterator p = evt->particles_begin(); 00126 p != evt->particles_end(); ++p ){ 00127 if( (*p)->status() == 1 ) { 00128 sum += convertTo( (*p)->momentum() ); 00129 (*p)->print(); 00130 } 00131 } 00132 std::cout << "Vector Sum: " << sum << std::endl; 00133 00134 // now clean-up by deleteing all objects from memory 00135 // 00136 // deleting the event deletes all contained vertices, and all particles 00137 // contained in those vertices 00138 delete evt; 00139 00140 // delete all particle data objects in the particle data table pdt 00141 pdt.delete_all(); 00142 00143 return 0; 00144 }