HepMC Reference Documentation

HepMC

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

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