CMS 3D CMS Logo

TauolappInterface.cc
Go to the documentation of this file.
1 /* this is the code for the new Tauola++ */
2 
3 #include <iostream>
4 
6 
7 #include "Tauola/Tauola.h"
8 #include "Tauola/TauolaHepMCEvent.h"
9 #include "Tauola/Log.h"
10 #include "Tauola/TauolaHepMCParticle.h"
11 #include "Tauola/TauolaParticle.h"
16 
17 #include "CLHEP/Random/RandomEngine.h"
18 
19 #include "HepMC/GenEvent.h"
20 #include "HepMC/IO_HEPEVT.h"
21 #include "HepMC/HEPEVT_Wrapper.h"
22 
24 
25 // LHE Run
28 
29 // LHE Event
32 
33 using namespace gen;
34 using namespace edm;
35 using namespace std;
36 
37 CLHEP::HepRandomEngine* TauolappInterface::fRandomEngine = nullptr;
38 
39 extern "C" {
40 
41 void gen::ranmar_(float* rvec, int* lenv) {
42  for (int i = 0; i < *lenv; i++)
43  *rvec++ = TauolappInterface::flat();
44  return;
45 }
46 
47 void gen::rmarin_(int*, int*, int*) { return; }
48 }
49 
51  : fPolarization(false),
52  fPSet(nullptr),
53  fIsInitialized(false),
54  fMDTAU(-1),
55  fSelectDecayByEvent(false),
56  lhe(nullptr),
57  dmMatch(0.5),
58  dolhe(false),
59  dolheBosonCorr(false),
60  ntries(10) {
61  if (fPSet != nullptr)
62  throw cms::Exception("TauolappInterfaceError") << "Attempt to override Tauola an existing ParameterSet\n"
63  << std::endl;
64  fPSet = new ParameterSet(pset);
65 }
66 
68  if (fPSet != nullptr)
69  delete fPSet;
70 }
71 
73  if (fIsInitialized)
74  return; // do init only once
75  if (fPSet == nullptr)
76  throw cms::Exception("TauolappInterfaceError") << "Attempt to initialize Tauola with an empty ParameterSet\n"
77  << std::endl;
78 
79  fIsInitialized = true;
80 
81  es.getData(fPDGTable);
82 
83  Tauolapp::Tauola::setDecayingParticle(15);
84 
85  // LHE Information
86  dmMatch = fPSet->getUntrackedParameter<double>("dmMatch", 0.5);
87  dolhe = fPSet->getUntrackedParameter<bool>("dolhe", false);
88  dolheBosonCorr = fPSet->getUntrackedParameter<bool>("dolheBosonCorr", true);
89  ntries = fPSet->getUntrackedParameter<int>("ntries", 10);
90 
91  // polarization switch
92  // fPolarization = fPSet->getParameter<bool>("UseTauolaPolarization") ? 1 : 0 ;
93  fPolarization = fPSet->getParameter<bool>("UseTauolaPolarization");
94 
95  // read tau decay mode switches
96  //
97  ParameterSet cards = fPSet->getParameter<ParameterSet>("InputCards");
98 
99  fMDTAU = cards.getParameter<int>("mdtau");
100 
101  if (fMDTAU == 0 || fMDTAU == 1) {
102  Tauolapp::Tauola::setSameParticleDecayMode(cards.getParameter<int>("pjak1"));
103  Tauolapp::Tauola::setOppositeParticleDecayMode(cards.getParameter<int>("pjak2"));
104  }
105 
106  Tauolapp::Tauola::spin_correlation.setAll(fPolarization);
107 
108  // some more options, copied over from an example
109  // Default values
110  //Tauola::setEtaK0sPi(0,0,0); // switches to decay eta K0_S and pi0 1/0 on/off.
111 
112  const HepPDT::ParticleData* PData =
113  fPDGTable->particle(HepPDT::ParticleID(abs(Tauolapp::Tauola::getDecayingParticle())));
114  double lifetime = PData->lifetime().value();
115  Tauolapp::Tauola::setTauLifetime(lifetime);
116 
117  fPDGs.push_back(Tauolapp::Tauola::getDecayingParticle());
118 
119  Tauolapp::Tauola::setRandomGenerator(gen::TauolappInterface::flat);
120 
121  if (fPSet->exists("parameterSets")) {
122  std::vector<std::string> par = fPSet->getParameter<std::vector<std::string> >("parameterSets");
123  for (unsigned int ip = 0; ip < par.size(); ++ip) {
124  std::string curSet = par[ip];
125  if (curSet == "setNewCurrents")
126  Tauolapp::Tauola::setNewCurrents(fPSet->getParameter<int>(curSet));
127  }
128  }
129 
131 
132  Tauolapp::Tauola::spin_correlation.setAll(
133  fPolarization); // Tauola switches this on during Tauola::initialise(); so we add this here to keep it on/off
134 
135  if (fPSet->exists("parameterSets")) {
136  std::vector<std::string> par = fPSet->getParameter<std::vector<std::string> >("parameterSets");
137  for (unsigned int ip = 0; ip < par.size(); ++ip) {
138  std::string curSet = par[ip];
139  if (curSet == "spinCorrelationSetAll")
140  Tauolapp::Tauola::spin_correlation.setAll(fPSet->getParameter<bool>(curSet));
141  if (curSet == "spinCorrelationGAMMA")
142  Tauolapp::Tauola::spin_correlation.GAMMA = fPSet->getParameter<bool>(curSet);
143  if (curSet == "spinCorrelationZ0")
144  Tauolapp::Tauola::spin_correlation.Z0 = fPSet->getParameter<bool>(curSet);
145  if (curSet == "spinCorrelationHIGGS")
146  Tauolapp::Tauola::spin_correlation.HIGGS = fPSet->getParameter<bool>(curSet);
147  if (curSet == "spinCorrelationHIGGSH")
148  Tauolapp::Tauola::spin_correlation.HIGGS_H = fPSet->getParameter<bool>(curSet);
149  if (curSet == "spinCorrelationHIGGSA")
150  Tauolapp::Tauola::spin_correlation.HIGGS_A = fPSet->getParameter<bool>(curSet);
151  if (curSet == "spinCorrelationHIGGSPLUS")
152  Tauolapp::Tauola::spin_correlation.HIGGS_PLUS = fPSet->getParameter<bool>(curSet);
153  if (curSet == "spinCorrelationHIGGSMINUS")
154  Tauolapp::Tauola::spin_correlation.HIGGS_MINUS = fPSet->getParameter<bool>(curSet);
155  if (curSet == "spinCorrelationWPLUS")
156  Tauolapp::Tauola::spin_correlation.W_PLUS = fPSet->getParameter<bool>(curSet);
157  if (curSet == "spinCorrelationWMINUS")
158  Tauolapp::Tauola::spin_correlation.W_MINUS = fPSet->getParameter<bool>(curSet);
159 
160  if (curSet == "setHiggsScalarPseudoscalarPDG")
161  Tauolapp::Tauola::setHiggsScalarPseudoscalarPDG(fPSet->getParameter<int>(curSet));
162  if (curSet == "setHiggsScalarPseudoscalarMixingAngle")
163  Tauolapp::Tauola::setHiggsScalarPseudoscalarMixingAngle(fPSet->getParameter<double>(curSet));
164 
165  if (curSet == "setRadiation")
166  Tauolapp::Tauola::setRadiation(fPSet->getParameter<bool>(curSet));
167  if (curSet == "setRadiationCutOff")
168  Tauolapp::Tauola::setRadiationCutOff(fPSet->getParameter<double>(curSet));
169 
170  if (curSet == "setEtaK0sPi") {
171  std::vector<int> vpar = fPSet->getParameter<std::vector<int> >(curSet);
172  if (vpar.size() == 3)
173  Tauolapp::Tauola::setEtaK0sPi(vpar[0], vpar[1], vpar[2]);
174  else {
175  std::cout << "WARNING invalid size for setEtaK0sPi: " << vpar.size() << " Require 3 elements " << std::endl;
176  }
177  }
178 
179  if (curSet == "setTaukle") {
180  std::vector<double> vpar = fPSet->getParameter<std::vector<double> >(curSet);
181  if (vpar.size() == 4)
182  Tauolapp::Tauola::setTaukle(vpar[0], vpar[1], vpar[2], vpar[3]);
183  else {
184  std::cout << "WARNING invalid size for setTaukle: " << vpar.size() << " Require 4 elements " << std::endl;
185  }
186  }
187 
188  if (curSet == "setTauBr") {
190  std::vector<int> vJAK = cfg.getParameter<std::vector<int> >("JAK");
191  std::vector<double> vBR = cfg.getParameter<std::vector<double> >("BR");
192  if (vJAK.size() == vBR.size()) {
193  for (unsigned int i = 0; i < vJAK.size(); i++)
194  Tauolapp::Tauola::setTauBr(vJAK[i], vBR[i]);
195  } else {
196  std::cout << "WARNING invalid size for setTauBr - JAK: " << vJAK.size() << " BR: " << vBR.size() << std::endl;
197  }
198  }
199  }
200  }
201 
202  // override decay modes if needs be
203  //
204  // we have to do it AFTER init because otherwises branching ratios are NOT filled in
205  //
206  if (fMDTAU != 0 && fMDTAU != 1) {
208  }
209 
211 
212  return;
213 }
214 
216  if (!fRandomEngine) {
217  throw cms::Exception("LogicError")
218  << "TauolaInterface::flat: Attempt to generate random number when engine pointer is null\n"
219  << "This might mean that the code was modified to generate a random number outside the\n"
220  << "event and beginLuminosityBlock methods, which is not allowed.\n";
221  }
222  return fRandomEngine->flat();
223 }
224 
226  if (!fIsInitialized)
227  return evt;
228  Tauolapp::Tauola::setRandomGenerator(
229  gen::TauolappInterface::flat); // rest tauola++ random number incase other modules use tauola++
230  int NPartBefore = evt->particles_size();
231  int NVtxBefore = evt->vertices_size();
232 
233  // what do we do if Hep::GenEvent size is larger than 10K ???
234  // Tauola (& Photos, BTW) can only handle up to 10K via HEPEVT,
235  // and in case of CMS, it's only up to 4K !!!
236  // override decay mode if needs be
237 
238  if (fSelectDecayByEvent) {
240  }
241  if (dolhe && lhe != nullptr) {
242  std::vector<HepMC::GenParticle> particles;
243  std::vector<int> m_idx;
244  std::vector<double> spinup = lhe->getHEPEUP()->SPINUP;
245  std::vector<int> pdg = lhe->getHEPEUP()->IDUP;
246  for (unsigned int i = 0; i < spinup.size(); i++) {
247  particles.push_back(HepMC::GenParticle(HepMC::FourVector(lhe->getHEPEUP()->PUP.at(i)[0],
248  lhe->getHEPEUP()->PUP.at(i)[1],
249  lhe->getHEPEUP()->PUP.at(i)[2],
250  lhe->getHEPEUP()->PUP.at(i)[3]),
251  lhe->getHEPEUP()->IDUP.at(i)));
252  int status = lhe->getHEPEUP()->ISTUP.at(i);
253  particles.at(particles.size() - 1).set_generated_mass(lhe->getHEPEUP()->PUP.at(i)[4]);
254  particles.at(particles.size() - 1).set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
255  m_idx.push_back(lhe->getHEPEUP()->MOTHUP.at(i).first - 1); // correct for fortran index offset
256  }
257  // match to taus in hepmc and identify mother of taus
258  bool hastaus(false);
259  std::vector<HepMC::GenParticle*> match;
260  for (HepMC::GenEvent::particle_const_iterator iter = evt->particles_begin(); iter != evt->particles_end(); iter++) {
261  if (abs((*iter)->pdg_id()) == 15) {
262  hastaus = true;
263  int mother_pid(0);
264  // check imediate parent to avoid parent tau ie tau->taugamma
265  for (HepMC::GenVertex::particle_iterator mother = (*iter)->production_vertex()->particles_begin(HepMC::parents);
266  mother != (*iter)->production_vertex()->particles_end(HepMC::parents);
267  mother++) {
268  mother_pid = (*mother)->pdg_id();
269  if (mother_pid != (*iter)->pdg_id()) {
270  // match against lhe record
271  if (abs(mother_pid) == 24 || // W
272  abs(mother_pid) == 37 || // H+/-
273  abs(mother_pid) == 23 || // Z
274  abs(mother_pid) == 22 || // gamma
275  abs(mother_pid) == 25 || // H0 SM
276  abs(mother_pid) == 35 || // H0
277  abs(mother_pid) == 36 // A0
278  ) {
279  bool isfound = false;
280  for (unsigned int k = 0; k < match.size(); k++) {
281  if ((*mother) == match.at(k))
282  isfound = true;
283  }
284  if (!isfound)
285  match.push_back(*mother);
286  }
287  }
288  }
289  }
290  }
291  if (hastaus) {
292  // if is single gauge boson decay and match helicities
293  if (match.size() == 1 && dolheBosonCorr) {
294  for (int i = 0; i < ntries; i++) {
295  // re-decay taus then check if helicities match
296  auto* t_event = new Tauolapp::TauolaHepMCEvent(evt);
297  t_event->undecayTaus();
298  t_event->decayTaus();
299  bool ismatch = true;
300  for (unsigned int j = 0; j < spinup.size(); j++) {
301  if (abs(pdg.at(j)) == 15) {
302  double diffhelminus = (-1.0 * (double)Tauolapp::Tauola::getHelMinus() -
303  spinup.at(j)); // -1.0 to correct for tauola feature
304  double diffhelplus = ((double)Tauolapp::Tauola::getHelPlus() - spinup.at(j));
305  if (pdg.at(j) == 15 && diffhelminus > 0.5)
306  ismatch = false;
307  if (pdg.at(j) == -15 && diffhelplus > 0.5)
308  ismatch = false;
309  }
310  }
311  delete t_event;
312  if (ismatch)
313  break;
314  }
315  } else {
316  // If the event does not contain a single gauge boson the code will be run with
317  // remove all tau decays
318  auto* t_event = new Tauolapp::TauolaHepMCEvent(evt);
319  t_event->undecayTaus();
320  delete t_event;
321  // decay all taus manually based on the helicity
322  for (HepMC::GenEvent::particle_const_iterator iter = evt->particles_begin(); iter != evt->particles_end();
323  iter++) {
324  if (abs((*iter)->pdg_id()) == 15 && isLastTauInChain(*iter)) {
325  TLorentzVector ltau(
326  (*iter)->momentum().px(), (*iter)->momentum().py(), (*iter)->momentum().pz(), (*iter)->momentum().e());
327  HepMC::GenParticle* m = GetMother(*iter);
328  TLorentzVector mother(m->momentum().px(), m->momentum().py(), m->momentum().pz(), m->momentum().e());
329  TVector3 boost = -1.0 * mother.BoostVector(); // boost into mother's CM frame
330  TLorentzVector ltau_lab = ltau;
331  ltau.Boost(boost);
332  mother.Boost(boost);
333  HepMC::GenEvent* tauevt = make_simple_tau_event(ltau, (*iter)->pdg_id(), (*iter)->status());
334  HepMC::GenParticle* p = (*(tauevt->particles_begin()));
335  Tauolapp::TauolaParticle* tp = new Tauolapp::TauolaHepMCParticle(p);
336  double helicity = MatchedLHESpinUp(*iter, particles, spinup, m_idx); // get helicity from lhe
337  if ((*iter)->pdg_id() == 15)
338  helicity *= -1.0;
339  tp->undecay();
340  // use |S_{tau}|=0.999999 to avoid issues with numerical roundoff
341  Tauolapp::Tauola::decayOne(tp, true, 0, 0, ((double)helicity) * 0.999999);
342  boost *= -1.0; // boost back to lab frame
343  mother.Boost(boost);
344  update_particles((*iter), evt, p, boost);
345  //correct tau liftetime for boost (change rest frame from mothers to taus)
346  BoostProdToLabLifeTimeInDecays((*iter), ltau_lab, ltau);
347  delete tauevt;
348  }
349  }
350  }
351  }
352  } else {
353  //construct tmp TAUOLA event
354  auto* t_event = new Tauolapp::TauolaHepMCEvent(evt);
355  //t_event->undecayTaus();
356  t_event->decayTaus();
357  delete t_event;
358  }
359 
360  for (int iv = NVtxBefore + 1; iv <= evt->vertices_size(); iv++) {
361  HepMC::GenVertex* GenVtx = evt->barcode_to_vertex(-iv);
362  //
363  // now find decay products with funky barcode, weed out and replace with clones of sensible barcode
364  // we can NOT change the barcode while iterating, because iterators do depend on the barcoding
365  // thus we have to take a 2-step procedure
366  //
367  std::vector<int> BCodes;
368  BCodes.clear();
369  for (HepMC::GenVertex::particle_iterator pitr = GenVtx->particles_begin(HepMC::children);
370  pitr != GenVtx->particles_end(HepMC::children);
371  ++pitr) {
372  if ((*pitr)->barcode() > 10000) {
373  BCodes.push_back((*pitr)->barcode());
374  }
375  }
376  if (!BCodes.empty()) {
377  for (size_t ibc = 0; ibc < BCodes.size(); ibc++) {
378  HepMC::GenParticle* p1 = evt->barcode_to_particle(BCodes[ibc]);
379  int nbc = p1->barcode() - 10000 + NPartBefore;
380  p1->suggest_barcode(nbc);
381  }
382  }
383  }
384 
385  for (HepMC::GenEvent::particle_const_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p) {
386  if ((*p)->end_vertex() && (*p)->status() == 1)
387  (*p)->set_status(2);
388  if ((*p)->end_vertex() && (*p)->end_vertex()->particles_out_size() == 0)
389  edm::LogWarning("TauolappInterface::decay error: empty end vertex!");
390  }
391 
392  return evt;
393 }
394 
396 
398  // Note-1:
399  // I have to hack the common block directly because set<...>DecayMode(...)
400  // only changes it in the Tauola++ instance but does NOT passes it over
401  // to the Fortran core - this it does only one, via initialize() stuff...
402  //
403  // So I'll do both ways of settings, just for consistency...
404  // but I probably need to communicate it to the Tauola(++) team...
405  //
406 
407  // Note-2:
408  // originally, the 1xx settings are meant for tau's from hard event,
409  // and the 2xx settings are for any tau in the event record;
410  //
411  // later one, we'll have to take this into account...
412  // but first I'll have to sort out what happens in the 1xx case
413  // to tau's coming outside of hard event (if any in the record)
414  //
415 
416  if (mdtau == 101 || mdtau == 201) {
417  // override with electron mode for both tau's
418  //
419  Tauolapp::jaki_.jak1 = 1;
420  Tauolapp::jaki_.jak2 = 1;
421  Tauolapp::Tauola::setSameParticleDecayMode(1);
422  Tauolapp::Tauola::setOppositeParticleDecayMode(1);
423  return;
424  }
425 
426  if (mdtau == 102 || mdtau == 202) {
427  // override with muon mode for both tau's
428  //
429  Tauolapp::jaki_.jak1 = 2;
430  Tauolapp::jaki_.jak2 = 2;
431  Tauolapp::Tauola::setSameParticleDecayMode(2);
432  Tauolapp::Tauola::setOppositeParticleDecayMode(2);
433  return;
434  }
435 
436  if (mdtau == 111 || mdtau == 211) {
437  // override with electron mode for 1st tau
438  // and any mode for 2nd tau
439  //
440  Tauolapp::jaki_.jak1 = 1;
441  Tauolapp::jaki_.jak2 = 0;
442  Tauolapp::Tauola::setSameParticleDecayMode(1);
443  Tauolapp::Tauola::setOppositeParticleDecayMode(0);
444  return;
445  }
446 
447  if (mdtau == 112 || mdtau == 212) {
448  // override with muon mode for the 1st tau
449  // and any mode for the 2nd tau
450  //
451  Tauolapp::jaki_.jak1 = 2;
452  Tauolapp::jaki_.jak2 = 0;
453  Tauolapp::Tauola::setSameParticleDecayMode(2);
454  Tauolapp::Tauola::setOppositeParticleDecayMode(0);
455  return;
456  }
457 
458  if (mdtau == 121 || mdtau == 221) {
459  // override with any mode for the 1st tau
460  // and electron mode for the 2nd tau
461  //
462  Tauolapp::jaki_.jak1 = 0;
463  Tauolapp::jaki_.jak2 = 1;
464  Tauolapp::Tauola::setSameParticleDecayMode(0);
465  Tauolapp::Tauola::setOppositeParticleDecayMode(1);
466  return;
467  }
468 
469  if (mdtau == 122 || mdtau == 222) {
470  // override with any mode for the 1st tau
471  // and muon mode for the 2nd tau
472  //
473  Tauolapp::jaki_.jak1 = 0;
474  Tauolapp::jaki_.jak2 = 2;
475  Tauolapp::Tauola::setSameParticleDecayMode(0);
476  Tauolapp::Tauola::setOppositeParticleDecayMode(2);
477  return;
478  }
479 
480  if (mdtau == 140 || mdtau == 240) {
481  // override with pi+/- nutau mode for both tau's
482  //
483  Tauolapp::jaki_.jak1 = 3;
484  Tauolapp::jaki_.jak2 = 3;
485  Tauolapp::Tauola::setSameParticleDecayMode(3);
486  Tauolapp::Tauola::setOppositeParticleDecayMode(3);
487  return;
488  }
489 
490  if (mdtau == 141 || mdtau == 241) {
491  // override with pi+/- nutau mode for the 1st tau
492  // and any mode for the 2nd tau
493  //
494  Tauolapp::jaki_.jak1 = 3;
495  Tauolapp::jaki_.jak2 = 0;
496  Tauolapp::Tauola::setSameParticleDecayMode(3);
497  Tauolapp::Tauola::setOppositeParticleDecayMode(0);
498  return;
499  }
500 
501  if (mdtau == 142 || mdtau == 242) {
502  // override with any mode for the 1st tau
503  // and pi+/- nutau mode for 2nd tau
504  //
505  Tauolapp::jaki_.jak1 = 0;
506  Tauolapp::jaki_.jak2 = 3;
507  Tauolapp::Tauola::setSameParticleDecayMode(0);
508  Tauolapp::Tauola::setOppositeParticleDecayMode(3);
509  return;
510  }
511 
512  // OK, we come here for semi-inclusive modes
513  //
514 
515  // First of all, leptons and hadron modes sums
516  //
517  // re-scale branching ratios, just in case...
518  //
519  double sumBra = 0;
520 
521  // the number of decay modes is hardcoded at 22 because that's what it is right now in Tauola
522  // in the future, perhaps an asscess method would be useful - communicate to Tauola team...
523  //
524 
525  for (int i = 0; i < 22; i++) {
526  sumBra += Tauolapp::taubra_.gamprt[i];
527  }
528  if (sumBra == 0.)
529  return; // perhaps need to throw ?
530  for (int i = 0; i < 22; i++) {
531  double newBra = Tauolapp::taubra_.gamprt[i] / sumBra;
532  Tauolapp::Tauola::setTauBr(i + 1, newBra);
533  }
534  sumBra = 1.0;
535 
536  double sumLeptonBra = Tauolapp::taubra_.gamprt[0] + Tauolapp::taubra_.gamprt[1];
537  double sumHadronBra = sumBra - sumLeptonBra;
538 
539  for (int i = 0; i < 2; i++) {
540  fLeptonModes.push_back(i + 1);
541  fScaledLeptonBrRatios.push_back((Tauolapp::taubra_.gamprt[i] / sumLeptonBra));
542  }
543  for (int i = 2; i < 22; i++) {
544  fHadronModes.push_back(i + 1);
545  fScaledHadronBrRatios.push_back((Tauolapp::taubra_.gamprt[i] / sumHadronBra));
546  }
547 
548  fSelectDecayByEvent = true;
549  return;
550 }
551 
553  if (fMDTAU == 100 || fMDTAU == 200) {
554  int mode = selectLeptonic();
555  Tauolapp::jaki_.jak1 = mode;
556  Tauolapp::Tauola::setSameParticleDecayMode(mode);
557  mode = selectLeptonic();
558  Tauolapp::jaki_.jak2 = mode;
559  Tauolapp::Tauola::setOppositeParticleDecayMode(mode);
560  return;
561  }
562 
563  int modeL = selectLeptonic();
564  int modeH = selectHadronic();
565 
566  if (fMDTAU == 110 || fMDTAU == 210) {
567  Tauolapp::jaki_.jak1 = modeL;
568  Tauolapp::jaki_.jak2 = 0;
569  Tauolapp::Tauola::setSameParticleDecayMode(modeL);
570  Tauolapp::Tauola::setOppositeParticleDecayMode(0);
571  return;
572  }
573 
574  if (fMDTAU == 120 || fMDTAU == 22) {
575  Tauolapp::jaki_.jak1 = 0;
576  Tauolapp::jaki_.jak2 = modeL;
577  Tauolapp::Tauola::setSameParticleDecayMode(0);
578  Tauolapp::Tauola::setOppositeParticleDecayMode(modeL);
579  return;
580  }
581 
582  if (fMDTAU == 114 || fMDTAU == 214) {
583  Tauolapp::jaki_.jak1 = modeL;
584  Tauolapp::jaki_.jak2 = modeH;
585  Tauolapp::Tauola::setSameParticleDecayMode(modeL);
586  Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
587  return;
588  }
589 
590  if (fMDTAU == 124 || fMDTAU == 224) {
591  Tauolapp::jaki_.jak1 = modeH;
592  Tauolapp::jaki_.jak2 = modeL;
593  Tauolapp::Tauola::setSameParticleDecayMode(modeH);
594  Tauolapp::Tauola::setOppositeParticleDecayMode(modeL);
595  return;
596  }
597 
598  if (fMDTAU == 115 || fMDTAU == 215) {
599  Tauolapp::jaki_.jak1 = 1;
600  Tauolapp::jaki_.jak2 = modeH;
601  Tauolapp::Tauola::setSameParticleDecayMode(1);
602  Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
603  return;
604  }
605 
606  if (fMDTAU == 125 || fMDTAU == 225) {
607  Tauolapp::jaki_.jak1 = modeH;
608  Tauolapp::jaki_.jak2 = 1;
609  Tauolapp::Tauola::setSameParticleDecayMode(modeH);
610  Tauolapp::Tauola::setOppositeParticleDecayMode(1);
611  return;
612  }
613 
614  if (fMDTAU == 116 || fMDTAU == 216) {
615  Tauolapp::jaki_.jak1 = 2;
616  Tauolapp::jaki_.jak2 = modeH;
617  Tauolapp::Tauola::setSameParticleDecayMode(2);
618  Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
619  return;
620  }
621 
622  if (fMDTAU == 126 || fMDTAU == 226) {
623  Tauolapp::jaki_.jak1 = modeH;
624  Tauolapp::jaki_.jak2 = 2;
625  Tauolapp::Tauola::setSameParticleDecayMode(modeH);
626  Tauolapp::Tauola::setOppositeParticleDecayMode(2);
627  return;
628  }
629 
630  if (fMDTAU == 130 || fMDTAU == 230) {
631  Tauolapp::jaki_.jak1 = modeH;
632  Tauolapp::jaki_.jak2 = selectHadronic();
633  Tauolapp::Tauola::setSameParticleDecayMode(modeH);
634  Tauolapp::Tauola::setOppositeParticleDecayMode(Tauolapp::jaki_.jak2);
635  return;
636  }
637 
638  if (fMDTAU == 131 || fMDTAU == 231) {
639  Tauolapp::jaki_.jak1 = modeH;
640  Tauolapp::jaki_.jak2 = 0;
641  Tauolapp::Tauola::setSameParticleDecayMode(modeH);
642  Tauolapp::Tauola::setOppositeParticleDecayMode(0);
643  return;
644  }
645 
646  if (fMDTAU == 132 || fMDTAU == 232) {
647  Tauolapp::jaki_.jak1 = 0;
648  Tauolapp::jaki_.jak2 = modeH;
649  Tauolapp::Tauola::setSameParticleDecayMode(0);
650  Tauolapp::Tauola::setOppositeParticleDecayMode(modeH);
651  return;
652  }
653 
654  // unlikely that we get here on unknown mdtau
655  // - there's a protection earlier
656  // but if we do, just set defaults
657  // probably need to spit a warning...
658  //
659  Tauolapp::Tauola::setSameParticleDecayMode(0);
660  Tauolapp::Tauola::setOppositeParticleDecayMode(0);
661 
662  return;
663 }
664 
666  float prob = flat();
667 
668  if (prob > 0. && prob <= fScaledLeptonBrRatios[0]) {
669  return 1;
670  } else if (prob > fScaledLeptonBrRatios[1] && prob <= 1.) {
671  return 2;
672  }
673 
674  return 0;
675 }
676 
678  float prob = 0.;
679  int len = 1;
680  ranmar_(&prob, &len);
681 
682  double sumBra = fScaledHadronBrRatios[0];
683  if (prob > 0. && prob <= sumBra) {
684  return fHadronModes[0];
685  } else {
686  int NN = fScaledHadronBrRatios.size();
687  for (int i = 1; i < NN; i++) {
688  if (prob > sumBra && prob <= (sumBra + fScaledHadronBrRatios[i])) {
689  return fHadronModes[i];
690  }
691  sumBra += fScaledHadronBrRatios[i];
692  }
693  }
694 
695  return 0;
696 }
697 
699  HepMC::GenEvent* event = new HepMC::GenEvent();
700  // make tau's four vector
701  HepMC::FourVector momentum_tau1(l.Px(), l.Py(), l.Pz(), l.E());
702  // make particles
703  HepMC::GenParticle* tau1 = new HepMC::GenParticle(momentum_tau1, pdgid, status);
704  // make the vertex
705  HepMC::GenVertex* vertex = new HepMC::GenVertex();
706  vertex->add_particle_out(tau1);
707  event->add_vertex(vertex);
708  return event;
709 }
710 
712  HepMC::GenEvent* theEvent,
714  TVector3& boost) {
715  partHep->set_status(p->status());
716  if (p->end_vertex()) {
717  if (!partHep->end_vertex()) {
718  HepMC::GenVertex* vtx = new HepMC::GenVertex(p->end_vertex()->position());
719  theEvent->add_vertex(vtx);
720  vtx->add_particle_in(partHep);
721  }
722  if (p->end_vertex()->particles_out_size() != 0) {
723  for (HepMC::GenVertex::particles_out_const_iterator d = p->end_vertex()->particles_out_const_begin();
724  d != p->end_vertex()->particles_out_const_end();
725  d++) {
726  // Create daughter and add to event
727  TLorentzVector l((*d)->momentum().px(), (*d)->momentum().py(), (*d)->momentum().pz(), (*d)->momentum().e());
728  l.Boost(boost);
729  HepMC::FourVector momentum(l.Px(), l.Py(), l.Pz(), l.E());
730  HepMC::GenParticle* daughter = new HepMC::GenParticle(momentum, (*d)->pdg_id(), (*d)->status());
731  daughter->suggest_barcode(theEvent->particles_size() + 1);
732  partHep->end_vertex()->add_particle_out(daughter);
733  if ((*d)->end_vertex())
734  update_particles(daughter, theEvent, (*d), boost);
735  }
736  }
737  }
738 }
739 
741  if (tau->end_vertex()) {
742  HepMC::GenVertex::particle_iterator dau;
743  for (dau = tau->end_vertex()->particles_begin(HepMC::children);
744  dau != tau->end_vertex()->particles_end(HepMC::children);
745  dau++) {
746  int dau_pid = (*dau)->pdg_id();
747  if (dau_pid == tau->pdg_id())
748  return false;
749  }
750  }
751  return true;
752 }
753 
755  std::vector<HepMC::GenParticle>& p,
756  std::vector<double>& spinup,
757  std::vector<int>& m_idx) {
759  HepMC::GenParticle* mother = GetMother(Tau);
760  TLorentzVector t(tau->momentum().px(), tau->momentum().py(), tau->momentum().pz(), tau->momentum().e());
761  TLorentzVector m(mother->momentum().px(), mother->momentum().py(), mother->momentum().pz(), mother->momentum().e());
762  for (unsigned int i = 0; i < p.size(); i++) {
763  if (tau->pdg_id() == p.at(i).pdg_id()) {
764  if (mother->pdg_id() == p.at(m_idx.at(i)).pdg_id()) {
765  TLorentzVector pm(p.at(m_idx.at(i)).momentum().px(),
766  p.at(m_idx.at(i)).momentum().py(),
767  p.at(m_idx.at(i)).momentum().pz(),
768  p.at(m_idx.at(i)).momentum().e());
769  if (fabs(m.M() - pm.M()) < dmMatch)
770  return spinup.at(i);
771  }
772  }
773  }
774  return 0;
775 }
776 
778  if (tau->production_vertex()) {
779  HepMC::GenVertex::particle_iterator mother;
780  for (mother = tau->production_vertex()->particles_begin(HepMC::parents);
781  mother != tau->production_vertex()->particles_end(HepMC::parents);
782  mother++) {
783  if ((*mother)->pdg_id() == tau->pdg_id())
784  return FirstTauInChain(*mother); // recursive call to get mother with different pdgid
785  }
786  }
787  return tau;
788 }
789 
791  if (tau->production_vertex()) {
792  HepMC::GenVertex::particle_iterator mother;
793  for (mother = tau->production_vertex()->particles_begin(HepMC::parents);
794  mother != tau->production_vertex()->particles_end(HepMC::parents);
795  mother++) {
796  if ((*mother)->pdg_id() == tau->pdg_id())
797  return GetMother(*mother); // recursive call to get mother with different pdgid
798  return (*mother);
799  }
800  }
801  return tau;
802 }
803 
805  TLorentzVector& lab,
806  TLorentzVector& prod) {
807  if (p->end_vertex() && p->production_vertex()) {
808  HepMC::GenVertex* PGenVtx = p->production_vertex();
809  HepMC::GenVertex* EGenVtx = p->end_vertex();
810  double VxDec = PGenVtx->position().x() + lab.Px() / prod.Px() * (EGenVtx->position().x() - PGenVtx->position().x());
811  double VyDec = PGenVtx->position().y() + lab.Py() / prod.Py() * (EGenVtx->position().y() - PGenVtx->position().y());
812  double VzDec = PGenVtx->position().z() + lab.Pz() / prod.Pz() * (EGenVtx->position().z() - PGenVtx->position().z());
813  double VtDec = PGenVtx->position().t() + lab.Pt() / prod.Pt() * (EGenVtx->position().t() - PGenVtx->position().t());
814  EGenVtx->set_position(HepMC::FourVector(VxDec, VyDec, VzDec, VtDec));
815  for (HepMC::GenVertex::particle_iterator dau = p->end_vertex()->particles_begin(HepMC::children);
816  dau != p->end_vertex()->particles_end(HepMC::children);
817  dau++) {
818  BoostProdToLabLifeTimeInDecays((*dau), lab, prod); //recursively modify everything in the decay chain
819  }
820  }
821 }
HiggsValidation_cfi.pdg_id
pdg_id
Definition: HiggsValidation_cfi.py:6
lhef::LHEEvent::getHEPEUP
const HEPEUP * getHEPEUP() const
Definition: LHEEvent.h:38
gen::TauolappInterface::FirstTauInChain
HepMC::GenParticle * FirstTauInChain(HepMC::GenParticle *tau)
Definition: TauolappInterface.cc:777
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
lhef::HEPEUP::MOTHUP
std::vector< std::pair< int, int > > MOTHUP
Definition: LesHouches.h:234
metsig::tau
Definition: SignAlgoResolutions.h:49
gen::TauolappInterface::lifetime
double lifetime
Definition: TauolappInterface.h:90
mps_update.status
status
Definition: mps_update.py:68
taubra_
struct @779 taubra_
lhef::HEPEUP::ISTUP
std::vector< int > ISTUP
Definition: LesHouches.h:228
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
class-composition.children
children
Definition: class-composition.py:98
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
gen::TauolappInterface::dolheBosonCorr
bool dolheBosonCorr
Definition: TauolappInterface.h:88
jak2
int jak2
Definition: TauolaWrapper.h:67
lhef::HEPEUP::SPINUP
std::vector< double > SPINUP
Definition: LesHouches.h:259
gen::k
int k[5][pyjets_maxn]
Definition: Cascade2Hadronizer.cc:75
gen::TauolappInterface::fScaledLeptonBrRatios
std::vector< double > fScaledLeptonBrRatios
Definition: TauolappInterface.h:82
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
gen::TauolappInterface::dolhe
bool dolhe
Definition: TauolappInterface.h:87
Tau
Definition: Tau.py:1
mergeAndRegister.ntries
ntries
Definition: mergeAndRegister.py:92
boost
Definition: CLHEP.h:16
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
ecalTrigSettings_cff.particles
particles
Definition: ecalTrigSettings_cff.py:11
gamprt
float gamprt[30]
Definition: TauolaWrapper.h:78
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
ParticleData
HepPDT::ParticleData ParticleData
Definition: ParticleDataTable.h:9
gen::TauolappInterface::selectDecayByMDTAU
void selectDecayByMDTAU()
Definition: TauolappInterface.cc:552
LHERunInfoProduct.h
gen::TauolappInterface::fHadronModes
std::vector< int > fHadronModes
Definition: TauolappInterface.h:81
gen::TauolappInterface::make_simple_tau_event
HepMC::GenEvent * make_simple_tau_event(const TLorentzVector &l, int pdgid, int status)
Definition: TauolappInterface.cc:698
gen::TauolappInterface::flat
static double flat()
Definition: TauolappInterface.cc:215
gen::rmarin_
void rmarin_(int *, int *, int *)
Definition: TauolappInterface.cc:47
gen::TauolappInterface::dmMatch
double dmMatch
Definition: TauolappInterface.h:86
Service.h
gen::p
double p[5][pyjets_maxn]
Definition: Cascade2Hadronizer.cc:76
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
gen::TauolappInterface::BoostProdToLabLifeTimeInDecays
void BoostProdToLabLifeTimeInDecays(HepMC::GenParticle *p, TLorentzVector &lab, TLorentzVector &prod)
Definition: TauolappInterface.cc:804
gen::TauolappInterface::fIsInitialized
bool fIsInitialized
Definition: TauolappInterface.h:76
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
gen
Definition: PythiaDecays.h:13
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
gen::TauolappInterface::fScaledHadronBrRatios
std::vector< double > fScaledHadronBrRatios
Definition: TauolappInterface.h:83
gen::TauolappInterface::lhe
lhef::LHEEvent * lhe
Definition: TauolappInterface.h:84
gen::TauolappInterface::fPolarization
bool fPolarization
Definition: TauolappInterface.h:73
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
edm::ParameterSet
Definition: ParameterSet.h:47
ParticleDataTable.h
LHERunInfo.h
nanoDQM_cfi.GenVtx
GenVtx
Definition: nanoDQM_cfi.py:344
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
edmPickEvents.event
event
Definition: edmPickEvents.py:273
gen::ranmar_
void ranmar_(float *rvec, int *lenv)
Definition: TauolappInterface.cc:41
gen::TauolappInterface::fPDGs
std::vector< int > fPDGs
Definition: TauolappInterface.h:72
gen::TauolappInterface::selectHadronic
int selectHadronic()
Definition: TauolappInterface.cc:677
gen::TauolappInterface::isLastTauInChain
bool isLastTauInChain(const HepMC::GenParticle *tau)
Definition: TauolappInterface.cc:740
p1
double p1[4]
Definition: TauolaWrapper.h:89
edm::EventSetup
Definition: EventSetup.h:58
gen::TauolappInterface::GetMother
HepMC::GenParticle * GetMother(HepMC::GenParticle *tau)
Definition: TauolappInterface.cc:790
gen::TauolappInterface::fPSet
edm::ParameterSet * fPSet
Definition: TauolappInterface.h:75
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
gen::TauolappInterface::init
void init(const edm::EventSetup &) override
Definition: TauolappInterface.cc:72
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
looper.cfg
cfg
Definition: looper.py:296
gen::TauolappInterface::~TauolappInterface
~TauolappInterface() override
Definition: TauolappInterface.cc:67
LHEEventProduct.h
gen::TauolappInterface::MatchedLHESpinUp
double MatchedLHESpinUp(HepMC::GenParticle *tau, std::vector< HepMC::GenParticle > &p, std::vector< double > &spinup, std::vector< int > &m_idx)
Definition: TauolappInterface.cc:754
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
std
Definition: JetResolutionObject.h:76
TauolappInterface.h
mdtau
int mdtau
Definition: TauolaWrapper.h:59
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:19
gen::TauolappInterface::selectLeptonic
int selectLeptonic()
Definition: TauolappInterface.cc:665
gen::TauolappInterface::decodeMDTAU
void decodeMDTAU(int)
Definition: TauolappInterface.cc:397
lhef::HEPEUP::IDUP
std::vector< int > IDUP
Definition: LesHouches.h:223
gen::TauolappInterface::fSelectDecayByEvent
bool fSelectDecayByEvent
Definition: TauolappInterface.h:79
gen::TauolappInterface::fRandomEngine
static CLHEP::HepRandomEngine * fRandomEngine
Definition: TauolappInterface.h:71
gen::TauolappInterface::fPDGTable
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
Definition: TauolappInterface.h:74
Exception
Definition: hltDiff.cc:245
jets_cff.tau1
tau1
Definition: jets_cff.py:439
gen::TauolappInterface::fMDTAU
int fMDTAU
Definition: TauolappInterface.h:78
pdg
Definition: pdg_functions.h:28
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
LHEEvent.h
ztail.d
d
Definition: ztail.py:151
gen::TauolappInterface::decay
HepMC::GenEvent * decay(HepMC::GenEvent *) override
Definition: TauolappInterface.cc:225
initialize
static AlgebraicMatrix initialize()
Definition: BeamSpotTransientTrackingRecHit.cc:24
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
gen::TauolappInterface::update_particles
void update_particles(HepMC::GenParticle *partHep, HepMC::GenEvent *theEvent, HepMC::GenParticle *p, TVector3 &boost)
Definition: TauolappInterface.cc:711
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
parents
TPRegexp parents
Definition: eve_filter.cc:21
EgammaValidation_cff.pdgid
pdgid
Definition: EgammaValidation_cff.py:29
gen::TauolappInterface::TauolappInterface
TauolappInterface(const edm::ParameterSet &)
Definition: TauolappInterface.cc:50
gen::TauolappInterface::statistics
void statistics() override
Definition: TauolappInterface.cc:395
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::Log
Definition: MessageLogger.h:70
LHEGenericFilter_cfi.ParticleID
ParticleID
Definition: LHEGenericFilter_cfi.py:6
TtFullHadEvtBuilder_cfi.prob
prob
Definition: TtFullHadEvtBuilder_cfi.py:33
lhef::HEPEUP::PUP
std::vector< FiveVector > PUP
Definition: LesHouches.h:246
gen::TauolappInterface::fLeptonModes
std::vector< int > fLeptonModes
Definition: TauolappInterface.h:80
gen::TauolappInterface::ntries
int ntries
Definition: TauolappInterface.h:89
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27