HepMC Reference Documentation

HepMC

example_BuildEventFromScratch.cc

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     //
00072     // create vertex 1 and vertex 2, together with their inparticles
00073     GenVertex* v1 = new GenVertex();
00074     evt->add_vertex( v1 );
00075     v1->add_particle_in( new GenParticle( HepLorentzVector(0,0,7000,7000),
00076                                        2212, 3 ) );
00077     GenVertex* v2 = new GenVertex();
00078     evt->add_vertex( v2 );
00079     v2->add_particle_in( new GenParticle( HepLorentzVector(0,0,-7000,7000),
00080                                        2212, 3 ) );
00081     //
00082     // create the outgoing particles of v1 and v2
00083     GenParticle* p3 = 
00084         new GenParticle( HepLorentzVector(.750,-1.569,32.191,32.238), 1, 3 );
00085     v1->add_particle_out( p3 );
00086     GenParticle* p4 = 
00087         new GenParticle( HepLorentzVector(-3.047,-19.,-54.629,57.920), -2, 3 );
00088     v2->add_particle_out( p4 );
00089     //
00090     // create v3
00091     GenVertex* v3 = new GenVertex();
00092     evt->add_vertex( v3 );
00093     v3->add_particle_in( p3 );
00094     v3->add_particle_in( p4 );
00095     v3->add_particle_out( 
00096         new GenParticle( HepLorentzVector(-3.813,0.113,-1.833,4.233 ), 22, 1 )
00097         );
00098     GenParticle* p5 = 
00099         new GenParticle( HepLorentzVector(1.517,-20.68,-20.605,85.925), -24,3);
00100     v3->add_particle_out( p5 );
00101     //
00102     // create v4
00103     GenVertex* v4 = new GenVertex(HepLorentzVector(0.12,-0.3,0.05,0.004));
00104     evt->add_vertex( v4 );
00105     v4->add_particle_in( p5 );
00106     v4->add_particle_out( 
00107         new GenParticle( HepLorentzVector(-2.445,28.816,6.082,29.552), 1,1 )
00108         );
00109     v4->add_particle_out( 
00110         new GenParticle( HepLorentzVector(3.962,-49.498,-26.687,56.373), -2,1 )
00111         );
00112     //    
00113     // tell the event which vertex is the signal process vertex
00114     evt->set_signal_process_vertex( v3 );
00115     // the event is complete, we now print it out to the screen
00116     evt->print();
00117     
00118     // example conversion back to Lorentz vector
00119     // add all outgoing momenta
00120     std::cout << std::endl;
00121     std::cout << " Add output momenta " << std::endl;
00122     HepLorentzVector sum;
00123     for ( GenEvent::particle_const_iterator p = evt->particles_begin(); 
00124               p != evt->particles_end(); ++p ){
00125         if( (*p)->status() == 1 ) {
00126             sum += convertTo( (*p)->momentum() );
00127             (*p)->print();
00128         }
00129     }
00130     std::cout << "Vector Sum: " << sum << std::endl;
00131 
00132     // now clean-up by deleteing all objects from memory
00133     //
00134     // deleting the event deletes all contained vertices, and all particles
00135     // contained in those vertices
00136     delete evt;
00137 
00138     // delete all particle data objects in the particle data table pdt
00139     pdt.delete_all();
00140 
00141     return 0;
00142 }

Generated on Wed Mar 12 13:08:08 2008 for HepMC by  doxygen 1.5.1-3