StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
example_VectorConversion.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 "VectorConversion.h"
14 #include "HepMC/GenEvent.h"
15 #include "CLHEP/Vector/LorentzVector.h"
16 
17 // in this example we use the HepMC namespace, so that we do not have to
18 // precede all HepMC classes with HepMC::
19 
20 // This example also shows how to use the CLHEP Lorentz vector with HepMC2
21 
22 using namespace HepMC;
23 using namespace CLHEP;
24 
25 int main() {
26  //
27  // In this example we will place the following event into HepMC "by hand"
28  //
29  // name status pdg_id parent Px Py Pz Energy Mass
30  // 1 !p+! 3 2212 0,0 0.000 0.000 7000.000 7000.000 0.938
31  // 2 !p+! 3 2212 0,0 0.000 0.000-7000.000 7000.000 0.938
32  //=========================================================================
33  // 3 !d! 3 1 1,1 0.750 -1.569 32.191 32.238 0.000
34  // 4 !u~! 3 -2 2,2 -3.047 -19.000 -54.629 57.920 0.000
35  // 5 !W-! 3 -24 1,2 1.517 -20.68 -20.605 85.925 80.799
36  // 6 !gamma! 1 22 1,2 -3.813 0.113 -1.833 4.233 0.000
37  // 7 !d! 1 1 5,5 -2.445 28.816 6.082 29.552 0.010
38  // 8 !u~! 1 -2 5,5 3.962 -49.498 -26.687 56.373 0.006
39 
40  // now we build the graph, which will look like
41  // p7 #
42  // p1 / #
43  // \v1__p3 p5---v4 #
44  // \_v3_/ \ #
45  // / \ p8 #
46  // v2__p4 \ #
47  // / p6 #
48  // p2 #
49  // #
50 
51  // First create the event container, with Signal Process 20, event number 1
52  //
53  // Note that the HepLorentzVectors will be automatically converted to
54  // HepMC::FourVector within GenParticle and GenVertex
55  GenEvent* evt = new GenEvent( 20, 1 );
56  // define the units
57  evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
58  //
59  // create vertex 1 and vertex 2, together with their inparticles
60  GenVertex* v1 = new GenVertex();
61  evt->add_vertex( v1 );
62  v1->add_particle_in( new GenParticle( HepLorentzVector(0,0,7000,7000),
63  2212, 3 ) );
64  GenVertex* v2 = new GenVertex();
65  evt->add_vertex( v2 );
66  v2->add_particle_in( new GenParticle( HepLorentzVector(0,0,-7000,7000),
67  2212, 3 ) );
68  //
69  // create the outgoing particles of v1 and v2
70  GenParticle* p3 =
71  new GenParticle( HepLorentzVector(.750,-1.569,32.191,32.238), 1, 3 );
72  v1->add_particle_out( p3 );
73  GenParticle* p4 =
74  new GenParticle( HepLorentzVector(-3.047,-19.,-54.629,57.920), -2, 3 );
75  v2->add_particle_out( p4 );
76  //
77  // create v3
78  GenVertex* v3 = new GenVertex();
79  evt->add_vertex( v3 );
80  v3->add_particle_in( p3 );
81  v3->add_particle_in( p4 );
82  v3->add_particle_out(
83  new GenParticle( HepLorentzVector(-3.813,0.113,-1.833,4.233 ), 22, 1 )
84  );
85  GenParticle* p5 =
86  new GenParticle( HepLorentzVector(1.517,-20.68,-20.605,85.925), -24,3);
87  v3->add_particle_out( p5 );
88  //
89  // create v4
90  GenVertex* v4 = new GenVertex(HepLorentzVector(0.12,-0.3,0.05,0.004));
91  evt->add_vertex( v4 );
92  v4->add_particle_in( p5 );
93  v4->add_particle_out(
94  new GenParticle( HepLorentzVector(-2.445,28.816,6.082,29.552), 1,1 )
95  );
96  v4->add_particle_out(
97  new GenParticle( HepLorentzVector(3.962,-49.498,-26.687,56.373), -2,1 )
98  );
99  //
100  // tell the event which vertex is the signal process vertex
101  evt->set_signal_process_vertex( v3 );
102  // the event is complete, we now print it out to the screen
103  evt->print();
104 
105  // example conversion back to Lorentz vector
106  // add all outgoing momenta
107  std::cout << std::endl;
108  std::cout << " Add output momenta " << std::endl;
109  HepLorentzVector sum;
111  p != evt->particles_end(); ++p ){
112  if( (*p)->status() == 1 ) {
113  sum += convertTo( (*p)->momentum() );
114  (*p)->print();
115  }
116  }
117  std::cout << "Vector Sum: " << sum << std::endl;
118 
119  // now clean-up by deleteing all objects from memory
120  //
121  // deleting the event deletes all contained vertices, and all particles
122  // contained in those vertices
123  delete evt;
124 
125  return 0;
126 }
void set_signal_process_vertex(GenVertex *)
set pointer to the vertex containing the signal process
Definition: GenEvent.h:747
const particle iterator
Definition: GenEvent.h:464
void add_particle_in(GenParticle *inparticle)
add incoming particle
Definition: GenVertex.cc:273
particle_const_iterator particles_begin() const
begin particle iteration
Definition: GenEvent.h:507
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
particle_const_iterator particles_end() const
end particle iteration
Definition: GenEvent.h:511
void use_units(Units::MomentumUnit, Units::LengthUnit)
Definition: GenEvent.h:856
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60