StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
single_tau_gun_example.c
1 #include <fstream>
2 
3 #include "Tauola/Tauola.h"
4 #include "Tauola/TauolaHepMCEvent.h"
5 
6 //pythia header files
7 #ifdef PYTHIA8180_OR_LATER
8 #include "Pythia8/Pythia.h"
9 #include "Pythia8/Pythia8ToHepMC.h"
10 #else
11 #include "Pythia.h"
12 #include "HepMCInterface.h"
13 #endif
14 
15 #include "tauola_print_parameters.h"
16 using namespace std;
17 using namespace Pythia8;
18 using namespace Tauolapp;
19 
20 int N = 10000;
21 int EventsToCheck=20;
22 
23 // elementary test of HepMC typically executed before
24 // detector simulation based on http://home.fnal.gov/~mrenna/HCPSS/HCPSShepmc.html
25 // similar test was performed in Fortran
26 // we perform it before and after Tauola (for the first several events)
27 void checkMomentumConservationInEvent(HepMC::GenEvent *evt)
28 {
29  //cout<<"List of stable particles: "<<endl;
30 
31  double px=0.0,py=0.0,pz=0.0,e=0.0;
32 
34  p != evt->particles_end(); ++p )
35  {
36  if( (*p)->status() == 1 )
37  {
38  HepMC::FourVector m = (*p)->momentum();
39  px+=m.px();
40  py+=m.py();
41  pz+=m.pz();
42  e +=m.e();
43  //(*p)->print();
44  }
45  }
46  cout.precision(6);
47  cout.setf(ios_base::floatfield);
48  cout<<endl<<"Vector Sum: "<<px<<" "<<py<<" "<<pz<<" "<<e<<endl;
49 }
50 
51 /*
52  Simple boost routine example.
53  Note that this routine will not respect direction of polarization vector along boost direction,
54  thus (0,0,1) does not mean helicity state. This is simply z component of spin for tau
55  with momentum px,py,pz. Can be thus helicitywise anything in range (-1,1).
56 */
57 void simpleBoost(TauolaParticle *tau, TauolaParticle *target)
58 {
59  double p1=tau->getPx();
60  double p2=tau->getPy();
61  double p3=tau->getPz();
62  double E =tau->getE();
63  double m =tau->getMass();
64 
65  double betx=p1/m;
66  double bety=p2/m;
67  double betz=p3/m;
68 
69  double gam=E/m;
70 
71  double pb=betx*target->getPx()+bety*target->getPy()+betz*target->getPz();
72 
73  target->setPx(target->getPx()+betx*(target->getE()+pb/(gam+1.0)));
74  target->setPy(target->getPy()+bety*(target->getE()+pb/(gam+1.0)));
75  target->setPz(target->getPz()+betz*(target->getE()+pb/(gam+1.0)));
76 
77  target->setE(target->getE()*gam+pb);
78 }
79 
80 int main()
81 {
82  // Initialization of pythia
83  Pythia pythia;
84  Event& event = pythia.event;
85 
86  // Pythia8 HepMC interface depends on Pythia8 version
87 #ifdef PYTHIA8180_OR_LATER
88  HepMC::Pythia8ToHepMC ToHepMC;
89 #else
90  HepMC::I_Pythia8 ToHepMC;
91 #endif
92 
93  pythia.readString("WeakSingleBoson:ffbar2gmZ = on");
94  pythia.readString("23:onMode = off");
95  pythia.readString("23:onIfAny = 15");
96 
97  // NOTE: this example is set up to pick undecayed tau
98  // changing this option requires changes in call to
99  // Tauola::decayOne and in tau searching 'for' loop
100  // See comments below
101  pythia.readString("15:mayDecay = off");
102 
103  pythia.init( 11, -11, 92.);
104 
105  Tauola::setSameParticleDecayMode(3);
106  Tauola::setOppositeParticleDecayMode(3);
107  Tauola::initialize();
108 
109  tauola_print_parameters(); // Prints TAUOLA parameters (residing inside its library): e.g. to test user interface
110 
111  ofstream s("out.txt");
112  double y=0;
113  int events_processed = 0;
114  for(int i=0;i<N;i++)
115  {
116  // Convert event record to HepMC
117  if(!pythia.next()) return -1;
118  HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
119  //Conversion needed if HepMC uses different momentum units
120  //than Pythia. However, requires HepMC 2.04 or higher.
121  HepMCEvt->use_units(HepMC::Units::GEV,HepMC::Units::MM);
122 
123  ToHepMC.fill_next_event(event, HepMCEvt);
124 
125  if(i<EventsToCheck)
126  {
127  cout<<" "<<endl;
128  cout<<"Momentum conservation chceck BEFORE/AFTER Tauola"<<endl;
129  checkMomentumConservationInEvent(HepMCEvt);
130  }
131 
132  //TauolaHepMCEvent *tEvent = new TauolaHepMCEvent(HepMCEvt);
133  // Search the event record for tau
134  HepMC::GenParticle *tau=0;
135  for(HepMC::GenEvent::particle_const_iterator p = HepMCEvt->particles_begin();p!=HepMCEvt->particles_end();p++)
136  {
137  if((*p)->pdg_id()==15)
138  {
139  if((*p)->status()!=1) continue;
140  tau=*p;
141  break;
142  }
143  }
144 
145  if(!tau) continue;
146  /*
147  Set boost routine if needed. Boost routine must look like:
148  void boost(TauolaParticle *tau, TauolaParticle *target)
149  See simpleBoost(...) function at the top of this file or documentation for more details
150  */
151  //Tauola::setBoostRoutine(simpleBoost);
152 
153  //Create TauolaParticle from HepMC tau
154  TauolaHepMCParticle *htau = new TauolaHepMCParticle(tau);
155 
156  // simplest use. For this demo it will do nothing because Pythia decayed taus already.
157  Tauola::decayOne(htau);
158 
159  //Decay single tau. If tau already has daughters - delete them.
160  //Tauola::decayOne(htau,true);
161  /*
162  The third parameter, if provided, will be used as the polarization vector.
163  */
164  //Tauola::decayOne(htau,true,0,0,1);
165 
166  if(i<EventsToCheck)
167  {
168  checkMomentumConservationInEvent(HepMCEvt);
169  }
170 
171  if(htau->getDaughters().size()>=2)
172  {
173  double x = ((htau->getDaughters())[1]->getE())/htau->getE();
174  //if(htau->getPz()<=0) x=1-x; // this is necessary for checking interface for tau-gun running with simple Tauola::setBoostRoutine(simpleBoost);
175  s<<x<<endl;
176  y+=x;
177  events_processed++;
178  }
179 
180  delete HepMCEvt;
181  }
182  cout.setf(ios::fixed);
183  cout<<y/events_processed<<endl;
184  s.close();
185 
186  // This is an access to old FORTRAN info on generated tau sample.
187  // That is why it refers to old version number (eg. 2.7) for TAUOLA.
188  //Tauola::summary();
189 
190  return 0;
191 }
const particle iterator
Definition: GenEvent.h:464
particle_const_iterator particles_begin() const
begin particle iteration
Definition: GenEvent.h:507
double e() const
return E
Definition: SimpleVector.h:73
virtual void setPz(double pz)=0
double px() const
return px
Definition: SimpleVector.h:70
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
virtual void setPx(double px)=0
double pz() const
return pz
Definition: SimpleVector.h:72
virtual double getPx()=0
virtual double getE()=0
virtual double getPz()=0
virtual void setE(double e)=0
particle_const_iterator particles_end() const
end particle iteration
Definition: GenEvent.h:511
virtual void setPy(double py)=0
FourVector is a simple representation of a physics 4 vector.
Definition: SimpleVector.h:42
double py() const
return py
Definition: SimpleVector.h:71
void use_units(Units::MomentumUnit, Units::LengthUnit)
Definition: GenEvent.h:856
virtual double getPy()=0
std::vector< TauolaParticle * > getDaughters()
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60