StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
example_BuildEventFromScratch.cc
1 // Matt.Dobbs@Cern.CH, Feb 2000
3 // Example of building an event and a particle data table from scratch
4 // This is meant to be of use for persons implementing HepMC inside a MC
5 // event generator
7 // To Compile: go to the HepMC directory and type:
8 // gmake examples/example_BuildEventFromScratch.exe
9 //
10 
11 #include <iostream>
12 
13 #include "HepMC/GenEvent.h"
14 
15 // in this example we use the HepMC namespace, so that we do not have to
16 // precede all HepMC classes with HepMC::
17 
18 // This example also shows how to use the CLHEP Lorentz vector with HepMC2
19 
20 using namespace HepMC;
21 
22 int main() {
23  //
24  // In this example we will place the following event into HepMC "by hand"
25  //
26  // name status pdg_id parent Px Py Pz Energy Mass
27  // 1 !p+! 3 2212 0,0 0.000 0.000 7000.000 7000.000 0.938
28  // 2 !p+! 3 2212 0,0 0.000 0.000-7000.000 7000.000 0.938
29  //=========================================================================
30  // 3 !d! 3 1 1,1 0.750 -1.569 32.191 32.238 0.000
31  // 4 !u~! 3 -2 2,2 -3.047 -19.000 -54.629 57.920 0.000
32  // 5 !W-! 3 -24 1,2 1.517 -20.68 -20.605 85.925 80.799
33  // 6 !gamma! 1 22 1,2 -3.813 0.113 -1.833 4.233 0.000
34  // 7 !d! 1 1 5,5 -2.445 28.816 6.082 29.552 0.010
35  // 8 !u~! 1 -2 5,5 3.962 -49.498 -26.687 56.373 0.006
36 
37  // now we build the graph, which will look like
38  // p7 #
39  // p1 / #
40  // \v1__p3 p5---v4 #
41  // \_v3_/ \ #
42  // / \ p8 #
43  // v2__p4 \ #
44  // / p6 #
45  // p2 #
46  // #
47 
48  // First create the event container, with Signal Process 20, event number 1
49  //
50  GenEvent* evt = new GenEvent( 20, 1 );
51  // define the units
52  evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
53  //
54  // create vertex 1 and vertex 2, together with their inparticles
55  GenVertex* v1 = new GenVertex();
56  evt->add_vertex( v1 );
57  v1->add_particle_in( new GenParticle( FourVector(0,0,7000,7000),
58  2212, 3 ) );
59  GenVertex* v2 = new GenVertex();
60  evt->add_vertex( v2 );
61  v2->add_particle_in( new GenParticle( FourVector(0,0,-7000,7000),
62  2212, 3 ) );
63  //
64  // create the outgoing particles of v1 and v2
65  GenParticle* p3 =
66  new GenParticle( FourVector(.750,-1.569,32.191,32.238), 1, 3 );
67  v1->add_particle_out( p3 );
68  GenParticle* p4 =
69  new GenParticle( FourVector(-3.047,-19.,-54.629,57.920), -2, 3 );
70  v2->add_particle_out( p4 );
71  //
72  // create v3
73  GenVertex* v3 = new GenVertex();
74  evt->add_vertex( v3 );
75  v3->add_particle_in( p3 );
76  v3->add_particle_in( p4 );
77  v3->add_particle_out(
78  new GenParticle( FourVector(-3.813,0.113,-1.833,4.233 ), 22, 1 )
79  );
80  GenParticle* p5 =
81  new GenParticle( FourVector(1.517,-20.68,-20.605,85.925), -24,3);
82  v3->add_particle_out( p5 );
83  //
84  // create v4
85  GenVertex* v4 = new GenVertex(FourVector(0.12,-0.3,0.05,0.004));
86  evt->add_vertex( v4 );
87  v4->add_particle_in( p5 );
88  v4->add_particle_out(
89  new GenParticle( FourVector(-2.445,28.816,6.082,29.552), 1,1 )
90  );
91  v4->add_particle_out(
92  new GenParticle( FourVector(3.962,-49.498,-26.687,56.373), -2,1 )
93  );
94  //
95  // tell the event which vertex is the signal process vertex
96  evt->set_signal_process_vertex( v3 );
97  // the event is complete, we now print it out to the screen
98  evt->print();
99 
100  // now clean-up by deleteing all objects from memory
101  //
102  // deleting the event deletes all contained vertices, and all particles
103  // contained in those vertices
104  delete evt;
105 
106  return 0;
107 }
void set_signal_process_vertex(GenVertex *)
set pointer to the vertex containing the signal process
Definition: GenEvent.h:747
void add_particle_in(GenParticle *inparticle)
add incoming particle
Definition: GenVertex.cc:273
GenVertex contains information about decay vertices.
Definition: GenVertex.h:52
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
void add_particle_out(GenParticle *outparticle)
add outgoing particle
Definition: GenVertex.cc:284
bool add_vertex(GenVertex *vtx)
adds to evt and adopts
Definition: GenEvent.cc:334
void print(std::ostream &ostr=std::cout) const
dumps to ostr
Definition: GenEvent.cc:277
FourVector is a simple representation of a physics 4 vector.
Definition: SimpleVector.h:42
void use_units(Units::MomentumUnit, Units::LengthUnit)
Definition: GenEvent.h:856
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60