StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testPolarization.cc
1 // testPolarization.cc
3 //
4 // garren@fnal.gov, Oct. 2010
6 
7 #include <iostream>
8 #include <fstream>
9 #include <vector>
10 
11 #include "HepMC/GenEvent.h"
12 #include "HepMC/IO_GenEvent.h"
13 
14 int main() {
15  //
16  // In this example we will place the following event into HepMC "by hand"
17  //
18  // name status pdg_id parent Px Py Pz Energy Mass
19  // 1 !p+! 3 2212 0,0 0.000 0.000 7000.000 7000.000 0.938
20  // 2 !p+! 3 2212 0,0 0.000 0.000-7000.000 7000.000 0.938
21  //=========================================================================
22  // 3 !d! 3 1 1,1 0.750 -1.569 32.191 32.238 0.000
23  // 4 !u~! 3 -2 2,2 -3.047 -19.000 -54.629 57.920 0.000
24  // 5 !W-! 3 -24 1,2 1.517 -20.68 -20.605 85.925 80.799
25  // 6 !gamma! 1 22 1,2 -3.813 0.113 -1.833 4.233 0.000
26  // 7 !d! 1 1 5,5 -2.445 28.816 6.082 29.552 0.010
27  // 8 !u~! 1 -2 5,5 3.962 -49.498 -26.687 56.373 0.006
28 
29  // open an output file
30  const char outfile[] = "testPolarization.cout";
31  std::ofstream os( outfile );
32  if( !os ) {
33  std::cerr << "cannot open " << outfile << std::endl;
34  exit(-1);
35  }
36  // declare several IO_GenEvent instances for comparison
37  HepMC::IO_GenEvent xout1("testPolarization1.dat",std::ios::out);
38  HepMC::IO_GenEvent xout2("testPolarization2.dat",std::ios::out);
39  // output streams for copy test
40  std::ofstream xout4( "testPolarization4.out" );
41  std::ofstream xout5( "testPolarization5.out" );
42 
43  // build the graph, which will look like
44  // p7 #
45  // p1 / #
46  // \v1__p3 p5---v4 #
47  // \_v3_/ \ #
48  // / \ p8 #
49  // v2__p4 \ #
50  // / p6 #
51  // p2 #
52  //
53  // define a flow pattern as p1 -> p3 -> p6
54  // and p2 -> p4 -> p5
55  //
56 
57  // First create the event container, with Signal Process 20, event number 1
58  //
59  HepMC::GenEvent* evt = new HepMC::GenEvent( 20, 1 );
60  //
61  // create vertex 1 and vertex 2, together with their inparticles
63  evt->add_vertex( v1 );
65  2212, 3 );
66  p1->set_flow(1,231);
67  p1->set_polarization(HepMC::Polarization(rand(),rand()));
68  v1->add_particle_in( p1 );
70  evt->add_vertex( v2 );
71  HepMC::GenParticle* p2 = new HepMC::GenParticle( HepMC::FourVector(0,0,-7000,7000),
72  2212, 3 );
73  p2->set_flow(1,243);
74  p2->set_polarization(HepMC::Polarization(rand(),rand()));
75  v2->add_particle_in( p2 );
76  //
77  // create the outgoing particles of v1 and v2
78  HepMC::GenParticle* p3 =
79  new HepMC::GenParticle( HepMC::FourVector(.750,-1.569,32.191,32.238),
80  1, 3 );
81  p3->set_flow(1,231);
82  p3->set_polarization(HepMC::Polarization(rand(),rand()));
83  v1->add_particle_out( p3 );
84  HepMC::GenParticle* p4 =
85  new HepMC::GenParticle( HepMC::FourVector(-3.047,-19.,-54.629,57.920),
86  -2, 3 );
87  p4->set_flow(1,243);
88  p4->set_polarization(HepMC::Polarization(rand(),rand()));
89  v2->add_particle_out( p4 );
90  //
91  // create v3
93  evt->add_vertex( v3 );
94  v3->add_particle_in( p3 );
95  v3->add_particle_in( p4 );
96  HepMC::GenParticle* p6 =
97  new HepMC::GenParticle( HepMC::FourVector(-3.813,0.113,-1.833,4.233 ),
98  22, 1 );
99  p6->set_flow(1,231);
100  p6->set_polarization(HepMC::Polarization(rand(),rand()));
101  v3->add_particle_out( p6 );
102  HepMC::GenParticle* p5 =
103  new HepMC::GenParticle( HepMC::FourVector(1.517,-20.68,-20.605,85.925),
104  -24, 3 );
105  p5->set_flow(1,243);
106  p5->set_polarization(HepMC::Polarization(rand(),rand()));
107  v3->add_particle_out( p5 );
108  //
109  // create v4
110  HepMC::GenVertex* v4 = new HepMC::GenVertex(HepMC::FourVector(0.12,-0.3,0.05,0.004));
111  evt->add_vertex( v4 );
112  v4->add_particle_in( p5 );
113  HepMC::GenParticle* p7 = new HepMC::GenParticle( HepMC::FourVector(-2.445,28.816,6.082,29.552), 1,1 );
114  v4->add_particle_out( p7 );
115  HepMC::GenParticle* p8 = new HepMC::GenParticle( HepMC::FourVector(3.962,-49.498,-26.687,56.373), -2,1 );
116  v4->add_particle_out( p8 );
117  //
118  // tell the event which vertex is the signal process vertex
119  evt->set_signal_process_vertex( v3 );
120  // the event is complete, we now print it out
121  evt->print( os );
122  // print each particle so we can see the polarization
124  ip != evt->particles_end(); ++ip ) {
125  (*ip)->print(os);
126  }
127 
128  // write event
129  xout1 << evt;
130  // call the write method directly
131  evt->write(xout4);
132  // make a copy and write it
133  HepMC::GenEvent(*evt).write(xout5);
134 
135  // try changing polarization
136  p2->set_polarization(HepMC::Polarization(rand(),rand()));
137  xout2 << evt;
138 
139  // now clean-up by deleteing all objects from memory
140  //
141  // deleting the event deletes all contained vertices, and all particles
142  // contained in those vertices
143  delete evt;
144 
145  return 0;
146 }
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
particle_const_iterator particles_begin() const
begin particle iteration
Definition: GenEvent.h:507
void set_flow(const Flow &f)
set particle flow
Definition: GenParticle.h:238
non-const particle iterator
Definition: GenEvent.h:520
GenVertex contains information about decay vertices.
Definition: GenVertex.h:52
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
IO_GenEvent also deals with HeavyIon and PdfInfo.
Definition: IO_GenEvent.h:63
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
std::ostream & write(std::ostream &)
The Polarization class stores theta and phi for a GenParticle.
Definition: Polarization.h:29
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
FourVector is a simple representation of a physics 4 vector.
Definition: SimpleVector.h:42
void set_polarization(const Polarization &pol=Polarization(0, 0))
set polarization
Definition: GenParticle.h:249
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60