StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
taummk_pythia_example.c
1 
13 #include "Tauola/Log.h"
14 #include "Tauola/Plots.h"
15 #include "Tauola/Tauola.h"
16 #include "Tauola/TauolaHepMCEvent.h"
17 
18 //pythia header files
19 #ifdef PYTHIA8180_OR_LATER
20 #include "Pythia8/Pythia.h"
21 #include "Pythia8/Pythia8ToHepMC.h"
22 #else
23 #include "Pythia.h"
24 #include "HepMCInterface.h"
25 #endif
26 
27 #include "HepMC/IO_AsciiParticles.h"
28 
29 #include "tauola_print_parameters.h"
30 using namespace std;
31 using namespace Pythia8;
32 using namespace Tauolapp;
33 
34 bool ShowersOn=true;
35 int NumberOfEvents = 1000;
36 
37 double hratio(HepMC::GenEvent* HepMCEvt, double* hratio2)
38 {
39  double rat=0., rat2=0.;
40  int nhadrmode=0;
42  p!=HepMCEvt->particles_end();
43  ++p)
44  {
45  if(abs((*p)->pdg_id()) == 15 && (*p)->end_vertex() )
46  {
47  double ehadr=0.;
48  int ihadrmode=0;
49  for(HepMC::GenVertex::particle_iterator des = (*p)->end_vertex()->particles_begin(HepMC::children);
50  des!=(*p)->end_vertex()->particles_end(HepMC::children);
51  ++des)
52  {
53  if(abs((*des)->pdg_id()) == 20213 ||
54  abs((*des)->pdg_id()) == 213 ||
55  abs((*des)->pdg_id()) == 211 ||
56  abs((*des)->pdg_id()) == 321 )
57  {
58  ehadr += (*des)->momentum().e();
59  ihadrmode = 1;
60  }
61  }
62  rat += ehadr / (*p)->momentum().e();
63  rat2 += ehadr*ehadr / ( (*p)->momentum().e()*(*p)->momentum().e() );
64  nhadrmode += ihadrmode;
65  }
66  }
67  if(nhadrmode)
68  {
69  rat = rat / (double)nhadrmode;
70  rat2 = rat2 / (double)nhadrmode;
71  }
72  *hratio2 = rat2;
73  return rat;
74 }
75 
76 int main(int argc,char **argv)
77 {
78  Log::SummaryAtExit();
79  // Initialization of pythia
80  Pythia pythia;
81 
82  // Pythia8 HepMC interface depends on Pythia8 version
83 #ifdef PYTHIA8180_OR_LATER
84  HepMC::Pythia8ToHepMC ToHepMC;
85 #else
86  HepMC::I_Pythia8 ToHepMC;
87 #endif
88 
89  //HepMC::IO_AsciiParticles ascii_io("example_PythiaParticle.dat",std::ios::out);
90  HepMC::IO_AsciiParticles ascii_io1("cout",std::ios::out);
91 
92  if(!ShowersOn)
93  {
94  //pythia.readString("HadronLevel:all = off");
95  pythia.readString("HadronLevel:Hadronize = off");
96  pythia.readString("SpaceShower:QEDshower = off");
97  pythia.readString("SpaceShower:QEDshowerByL = off");
98  pythia.readString("SpaceShower:QEDshowerByQ = off");
99  pythia.readString("PartonLevel:ISR = off");
100  pythia.readString("PartonLevel:FSR = off");
101  }
102 
103  //pythia.readString("WeakSingleBoson:ffbar2gmZ = on");
104 
105  pythia.readString("WeakDoubleBoson:ffbar2ZW = on");
106 
107  //pythia.readString("HiggsSM:gg2H = on");
108  //pythia.readString("25:m0 = 200.");
109  //pythia.readString("25:onMode = off");
110  //pythia.readString("25:onIfAny = 23");
111 
112  pythia.readString("23:onMode = off");
113  pythia.readString("23:onIfAny = 15");
114  pythia.readString("24:onMode = off");
115  pythia.readString("24:onIfAny = 15");
116  //pythia.readString("23:onIfMatch = 15 -15");
117  pythia.init( 2212, 2212, 14000.0); //proton proton collisions
118 
119  // Set up TAUOLA
120  // Tauola::setSameParticleDecayMode(19); //19 and 22 contains K0
121  // Tauola::setOppositeParticleDecayMode(19); // 20 contains eta
122 
123  Tauola::initialize();
124 
125  tauola_print_parameters(); // Prints TAUOLA parameters (residing inside its library): e.g. to test user interface
126 
127  // our default is GEV and MM, that will be outcome units after TAUOLA
128  // if HepMC unit variables are correctly set.
129  // with the following coice you can fix the units for final outcome:
130  // Tauola::setUnits(Tauola::GEV,Tauola::MM);
131  // Tauola::setUnits(Tauola::MEV,Tauola::CM);
132 
133  Tauola::setEtaK0sPi(0,0,0); // switches to decay eta K0_S and pi0 1/0 on/off.
134 
135  // Tauola::setTauLifetime(0.0); //new tau lifetime in mm
136  // Tauola::spin_correlation.setAll(false);
137  // Log::LogDebug(true);
138 
139 // --- Event loop with pythia only --------------------------------------------
140  Log::Info()<<"FIRST LOOP: Pythia only" << endl;
141 
142  double rats=0., rats2=0.;
143 
144  for(int iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
145  {
146  if(iEvent%100==0) Log::Info()<<"Event: "<<iEvent<<endl;
147  if(!pythia.next()) continue;
148 
149  // Convert event record to HepMC
150  HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
151 
152  //Conversion needed if HepMC use different momentum units
153  //than Pythia. However, requires HepMC 2.04 or higher.
154  // HepMCEvt->use_units(HepMC::Units::GEV,HepMC::Units::MM);
155 
156  ToHepMC.fill_next_event(pythia, HepMCEvt);
157 
158  double rat2;
159  rats += hratio(HepMCEvt, &rat2);
160  rats2 += rat2;
161 
162  //clean up HepMC event
163  delete HepMCEvt;
164  }
165 
166  rats = rats / (double)NumberOfEvents;
167  rats2 = rats2 / (double)NumberOfEvents;
168 
169  double rpyt = rats;
170  double erpyt = sqrt( (rats2 - rats*rats)/ (double)NumberOfEvents );
171 
172 // --- Event loop with pythia and tauola --------------------------------------
173  Log::Info()<<"SECOND LOOP: Pythia + Tauola" << endl;
174 
175  pythia.particleData.readString("15:mayDecay = off");
176 
177  rats=0.; rats2=0.;
178 
179  for (int iEvent = 0; iEvent < NumberOfEvents; ++iEvent)
180  {
181  if(iEvent%100==0) Log::Info()<<"Event: "<<iEvent<<endl;
182  if (!pythia.next()) continue;
183 
184  // Convert event record to HepMC
185  HepMC::GenEvent * HepMCEvt = new HepMC::GenEvent();
186 
187  //Conversion needed if HepMC use different momentum units
188  //than Pythia. However, requires HepMC 2.04 or higher.
189  HepMCEvt->use_units(HepMC::Units::GEV,HepMC::Units::MM);
190 
191  ToHepMC.fill_next_event(pythia, HepMCEvt);
192 
193  //ascii_io << HepMCEvt;
194  if(iEvent<2)
195  {
196  cout << endl << "Event record before tauola:" << endl << endl;
197  ascii_io1 << HepMCEvt;
198  }
199 
200  //run TAUOLA on the event
201  TauolaHepMCEvent * t_event = new TauolaHepMCEvent(HepMCEvt);
202  //Since we let Pythia decay taus, we have to undecay them first.
203  //t_event->undecayTaus();
204  //ascii_io << HepMCEvt;
205 
206  t_event->decayTaus();
207 
208  //ascii_io << HepMCEvt;
209  if(iEvent < 2)
210  {
211  cout << endl << "Event record after tauola:" << endl << endl;
212  ascii_io1 << HepMCEvt;
213  }
214 
215  delete t_event;
216  Log::Debug(5) << "helicites = " << Tauola::getHelPlus() << " "
217  << Tauola::getHelMinus()
218  << " electroweak wt= " << Tauola::getEWwt() << endl;
219 
220  double rat2;
221  rats += hratio(HepMCEvt, &rat2);
222  rats2 += rat2;
223 
224  //clean up HepMC event
225  delete HepMCEvt;
226  }
227 
228  rats = rats / (double)NumberOfEvents;
229  rats2 = rats2 / (double)NumberOfEvents;
230  double ertau = sqrt( (rats2 - rats*rats)/ (double)NumberOfEvents );
231 
232  cout.precision(6);
233  cout << "******************************************************" << endl;
234  cout << "* f + fbar -> Z0 + W+/- *" << endl;
235  cout << "* with Z0 -> tau+ tau- and W+/- -> tau+/- nutau *" << endl;
236  cout << "* E(PI+- + K+- + A1+-) / E(TAU) ratio *" << endl;
237  cout << "* pythia = " << rpyt << " tauola = " << rats
238  << " *" << endl;
239  cout << "* erpythia = " << erpyt << " ertauola = " << ertau
240  << " *" << endl;
241  cout << "******************************************************" << endl;
242 
243  Log::RedirectOutput(Log::Info());
244  pythia.statistics();
245  Log::RevertOutput();
246 
247  // This is an access to old FORTRAN info on generated tau sample.
248  // That is why it refers to old version number (eg. 2.7) for TAUOLA.
249  //Tauola::summary();
250 }
particle_const_iterator particles_begin() const
begin particle iteration
Definition: GenEvent.h:507
non-const particle iterator
Definition: GenEvent.h:520
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
particle_const_iterator particles_end() const
end particle iteration
Definition: GenEvent.h:511
event input/output in ascii format for eye and machine reading
void use_units(Units::MomentumUnit, Units::LengthUnit)
Definition: GenEvent.h:856