HepMC Reference Documentation

HepMC

example_BuildEventFromScratch.cc

Go to the documentation of this file.
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 "HepMC/GenEvent.h"
00014 
00015 // in this example we use the HepMC namespace, so that we do not have to 
00016 // precede all HepMC classes with HepMC::
00017 
00018 // This example also shows how to use the CLHEP Lorentz vector with HepMC2
00019 
00020 using namespace HepMC;
00021 
00022 int main() {
00023     //
00024     // In this example we will place the following event into HepMC "by hand"
00025     //
00026     //     name status pdg_id  parent Px       Py    Pz       Energy      Mass
00027     //  1  !p+!    3   2212    0,0    0.000    0.000 7000.000 7000.000    0.938
00028     //  2  !p+!    3   2212    0,0    0.000    0.000-7000.000 7000.000    0.938
00029     //=========================================================================
00030     //  3  !d!     3      1    1,1    0.750   -1.569   32.191   32.238    0.000
00031     //  4  !u~!    3     -2    2,2   -3.047  -19.000  -54.629   57.920    0.000
00032     //  5  !W-!    3    -24    1,2    1.517   -20.68  -20.605   85.925   80.799
00033     //  6  !gamma! 1     22    1,2   -3.813    0.113   -1.833    4.233    0.000
00034     //  7  !d!     1      1    5,5   -2.445   28.816    6.082   29.552    0.010
00035     //  8  !u~!    1     -2    5,5    3.962  -49.498  -26.687   56.373    0.006
00036 
00037     // now we build the graph, which will look like
00038     //                       p7                         #
00039     // p1                   /                           #
00040     //   \v1__p3      p5---v4                           #
00041     //         \_v3_/       \                           #
00042     //         /    \        p8                         #
00043     //    v2__p4     \                                  #
00044     //   /            p6                                #
00045     // p2                                               #
00046     //                                                  #
00047 
00048     // First create the event container, with Signal Process 20, event number 1
00049     //
00050     GenEvent* evt = new GenEvent( 20, 1 );
00051     // define the units
00052     evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
00053     //
00054     // create vertex 1 and vertex 2, together with their inparticles
00055     GenVertex* v1 = new GenVertex();
00056     evt->add_vertex( v1 );
00057     v1->add_particle_in( new GenParticle( FourVector(0,0,7000,7000),
00058                                        2212, 3 ) );
00059     GenVertex* v2 = new GenVertex();
00060     evt->add_vertex( v2 );
00061     v2->add_particle_in( new GenParticle( FourVector(0,0,-7000,7000),
00062                                        2212, 3 ) );
00063     //
00064     // create the outgoing particles of v1 and v2
00065     GenParticle* p3 = 
00066         new GenParticle( FourVector(.750,-1.569,32.191,32.238), 1, 3 );
00067     v1->add_particle_out( p3 );
00068     GenParticle* p4 = 
00069         new GenParticle( FourVector(-3.047,-19.,-54.629,57.920), -2, 3 );
00070     v2->add_particle_out( p4 );
00071     //
00072     // create v3
00073     GenVertex* v3 = new GenVertex();
00074     evt->add_vertex( v3 );
00075     v3->add_particle_in( p3 );
00076     v3->add_particle_in( p4 );
00077     v3->add_particle_out( 
00078         new GenParticle( FourVector(-3.813,0.113,-1.833,4.233 ), 22, 1 )
00079         );
00080     GenParticle* p5 = 
00081         new GenParticle( FourVector(1.517,-20.68,-20.605,85.925), -24,3);
00082     v3->add_particle_out( p5 );
00083     //
00084     // create v4
00085     GenVertex* v4 = new GenVertex(FourVector(0.12,-0.3,0.05,0.004));
00086     evt->add_vertex( v4 );
00087     v4->add_particle_in( p5 );
00088     v4->add_particle_out( 
00089         new GenParticle( FourVector(-2.445,28.816,6.082,29.552), 1,1 )
00090         );
00091     v4->add_particle_out( 
00092         new GenParticle( FourVector(3.962,-49.498,-26.687,56.373), -2,1 )
00093         );
00094     //    
00095     // tell the event which vertex is the signal process vertex
00096     evt->set_signal_process_vertex( v3 );
00097     // the event is complete, we now print it out to the screen
00098     evt->print();
00099 
00100     // now clean-up by deleteing all objects from memory
00101     //
00102     // deleting the event deletes all contained vertices, and all particles
00103     // contained in those vertices
00104     delete evt;
00105 
00106     return 0;
00107 }

Generated on Fri Feb 17 00:31:25 2012 for HepMC by  doxygen 1.4.7