Belle II Software  release-06-00-14
EvtGenDecays.h
1 // This file is a copy of Pythia8Plugins/EvtGen.h from Pythia 8,
2 // but slightly modified in basf2 for extended EvtGen models
3 
4 // EvtGen.h is a part of the PYTHIA event generator.
5 // Copyright (C) 2016 Torbjorn Sjostrand.
6 // PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
7 // Please respect the MCnet Guidelines, see GUIDELINES for details.
8 // Author: Philip Ilten.
9 
10 // This file contains an EvtGen interface. HepMC and EvtGen must be enabled.
11 
12 #pragma once
13 
14 #include <generators/utilities/GeneratorConst.h>
15 #include "Pythia8/Pythia.h"
16 #include "EvtGen/EvtGen.hh"
17 #include "EvtGenBase/EvtRandomEngine.hh"
18 #include "EvtGenBase/EvtParticle.hh"
19 #include "EvtGenBase/EvtParticleFactory.hh"
20 #include "EvtGenBase/EvtPDL.hh"
21 #include "EvtGenBase/EvtDecayTable.hh"
22 #include "EvtGenBase/EvtParticleDecayList.hh"
23 #include "EvtGenBase/EvtDecayBase.hh"
24 #include "EvtGenExternal/EvtExternalGenList.hh"
25 
26 //==========================================================================
27 
29 class EvtGenRandom : public EvtRandomEngine {
30 
31 public:
32 
34  explicit EvtGenRandom(Pythia8::Rndm* rndmPtrIn) {rndmPtr = rndmPtrIn;}
35 
37  double random() {if (rndmPtr) return rndmPtr->flat(); else return -1.0;}
38 
40  Pythia8::Rndm* rndmPtr;
41 
42 };
43 
44 //==========================================================================
45 
88 class EvtGenDecays {
89 
90 public:
91 
93  EvtGenDecays(Pythia8::Pythia* pythiaPtrIn, EvtGen* evtGen, bool limit = true);
94 
96  EvtGenDecays(Pythia8::Pythia* pythiaPtrIn, std::string decayFile, std::string particleDataFile,
97  EvtExternalGenList* extPtrIn = 0, EvtAbsRadCorr* fsrPtrIn = 0,
98  int mixing = 1, bool xml = false, bool limit = true,
99  bool extUse = true, bool fsrUse = true);
100 
103  {
104  if (evtgen) delete evtgen;
105  if (extOwner && extPtr) delete extPtr;
106  if (fsrOwner && fsrPtr) delete fsrPtr;
107  }
108 
110  EvtGenDecays(const EvtGenDecays&) = delete;
111 
114 
116  void getDecayLimits(bool limit);
117 
119  double decay();
120 
122  void exclude(int id) {excIds.insert(id);}
123 
125  void updatePythia();
126 
128  void updateEvtGen();
129 
131  void readDecayFile(std::string decayFile, bool xml = false)
132  {
133  evtgen->readUDecay(decayFile.c_str(), xml); updateData();
134  }
135 
136  bool extOwner;
137  bool fsrOwner;
138  EvtExternalGenList* extPtr;
139  EvtAbsRadCorr* fsrPtr;
140  std::list<EvtDecayBase*> models;
143  struct Signal {
144  int status;
145  EvtId egId;
146  std::vector<double> bfs;
147  std::vector<int> map;
148  EvtParticleDecayList modes;
149  };
151  std::map<int, Signal> signals;
152 
154  std::string signalSuffix;
155 
156 protected:
157 
159  void updateData(bool final = false);
160 
162  void updateEvent(Pythia8::Particle* pyPro, EvtParticle* egPro,
163  std::vector<int>* pySigs = 0, std::vector<EvtParticle*>* egSigs = 0,
164  std::vector<double>* bfs = 0, double* wgt = 0);
165 
167  bool checkVertex(Pythia8::Particle* pyPro);
168 
170  bool checkSignal(Pythia8::Particle* pyPro);
171 
173  bool checkOsc(EvtParticle* egPro);
174 
176  static constexpr int NTRYDECAY = 1000;
177 
179  Pythia8::Pythia* pythiaPtr;
180 
183 
185  EvtGen* evtgen;
186 
187  std::set<int> incIds;
188  std::set<int> excIds;
191  bool updated;
192 
194  std::map<int, Signal>::iterator signal;
195 
200  double tau0Max;
201  double tauMax;
202  double rMax;
203  double xyMax;
204  double zMax;
205  bool limitTau0;
206  bool limitTau;
207  bool limitRadius;
209  bool limitDecay;
210 };
211 
212 //--------------------------------------------------------------------------
213 
214 // The constructor.
215 
216 // The EvtGenDecays object is associated with a single Pythia
217 // instance. This is to ensure a consistent random number generator
218 // across the two, as well as any updates to particle data, etc. Note
219 // that if multiple EvtGenDecays objects exist, that they will modify
220 // one anothers particle databases due to the design of EvtGen.
221 
222 // This constructor also sets all particles to be decayed by EvtGen as
223 // stable within Pythia. The parameters within Pythia used to check if
224 // a particle should be decayed, as described in the "Particle Decays"
225 // section of the Pythia manual, are set. Note that if the variable
226 // "limit" is set to "false", then no check will be made before
227 // decaying a particle with EvtGen.
228 
229 // The constructor is designed to have the exact same form as the
230 // EvtGen constructor except for these five differences.
231 // (1) The first variable is the pointer to the Pythia object.
232 // (2) The third last argument is a flag to limit decays based on the
233 // Pythia criteria (based on the particle decay vertex).
234 // (3) The second last argument is a flag if external models should be
235 // passed to EvtGen (default is true).
236 // (4) The last argument is a flag if an FSR model should be passed
237 // to EvtGen (default is true).
238 // (5) No random engine pointer is passed, as this is obtained from
239 // Pythia.
240 
241 // pythiaPtrIn: the pointer to the associated Pythia object.
242 // decayFile: the name of the decay file to pass to EvtGen.
243 // particleDataFile: the name of the particle data file to pass to EvtGen.
244 // extPtrIn: the optional EvtExternalGenList pointer, this must be
245 // be provided if fsrPtrIn is provided to avoid double
246 // initializations.
247 // fsrPtrIn: the EvtAbsRadCorr pointer to pass to EvtGen.
248 // mixing: the mixing type to pass to EvtGen.
249 // xml: flag to use XML files to pass to EvtGen.
250 // limit: flag to limit particle decays based on Pythia criteria.
251 // extUse: flag to use external models with EvtGen.
252 // fsrUse: flag to use radiative correction engine with EvtGen.
253 
254 
255 EvtGenDecays::EvtGenDecays(Pythia8::Pythia* pythiaPtrIn, EvtGen* evtGen, bool limit):
256  extOwner(false), fsrOwner(false), extPtr(nullptr), fsrPtr(nullptr),
257  signalSuffix("_SIGNAL"), pythiaPtr(pythiaPtrIn), rndm(nullptr),
258  evtgen(evtGen), updated(false)
259 {
260  getDecayLimits(limit);
261 }
262 
263 EvtGenDecays::EvtGenDecays(Pythia8::Pythia* pythiaPtrIn, std::string decayFile,
264  std::string particleDataFile, EvtExternalGenList* extPtrIn,
265  EvtAbsRadCorr* fsrPtrIn, int mixing, bool xml, bool limit,
266  bool extUse, bool fsrUse) : extPtr(extPtrIn), fsrPtr(fsrPtrIn),
267  signalSuffix("_SIGNAL"), pythiaPtr(pythiaPtrIn), rndm(&pythiaPtr->rndm),
268  updated(false)
269 {
270 
271  // Initialize EvtGen.
272  if (!extPtr && fsrPtr) {
273  B2ERROR("Error in EvtGenDecays::EvtGenDecays: extPtr is null but fsrPtr is provided");
274  return;
275  }
276  if (extPtr) extOwner = false;
277  else {extOwner = true; extPtr = new EvtExternalGenList();}
278  if (fsrPtr) fsrOwner = false;
279  else {fsrOwner = true; fsrPtr = extPtr->getPhotosModel();}
280  models = extPtr->getListOfModels();
281  evtgen = new EvtGen(decayFile.c_str(), particleDataFile.c_str(),
282  &rndm, fsrUse ? fsrPtr : 0, extUse ? &models : 0, mixing, xml);
283  getDecayLimits(limit);
284 }
285 
287 {
288  // Get the Pythia decay limits.
289  if (!pythiaPtr) return;
290  limitTau0 = pythiaPtr->settings.flag("ParticleDecays:limitTau0");
291  tau0Max = pythiaPtr->settings.parm("ParticleDecays:tau0Max");
292  limitTau = pythiaPtr->settings.flag("ParticleDecays:limitTau");
293  tauMax = pythiaPtr->settings.parm("ParticleDecays:tauMax");
294  limitRadius = pythiaPtr->settings.flag("ParticleDecays:limitRadius");
295  rMax = pythiaPtr->settings.parm("ParticleDecays:rMax");
296  limitCylinder = pythiaPtr->settings.flag("ParticleDecays:limitCylinder");
297  xyMax = pythiaPtr->settings.parm("ParticleDecays:xyMax");
298  zMax = pythiaPtr->settings.parm("ParticleDecays:zMax");
299  limitDecay = limit && (limitTau0 || limitTau ||
301 
302 }
303 
304 //--------------------------------------------------------------------------
305 
306 // Perform all decays and return the event weight.
307 
308 // All particles in the event record that can be decayed by EvtGen are
309 // decayed. If a particle is a signal particle, then this is stored in
310 // a vector of signal particles. A signal particle is only stored if
311 // its status is the same as the status provided in the signals map. A
312 // negative status in the signal map indicates that all statuses
313 // should be accepted. After all signal particles are identified, one
314 // is randomly chosen and decayed as signal. The remainder are decayed
315 // normally.
316 
317 // Forcing a signal decay changes the weight of an event from unity,
318 // and so the relative event weight is returned, given the forced
319 // signal decay. A weight of 0 indicates no signal in the event, while
320 // a weight of -1 indicates something is wrong, e.g. either the Pythia
321 // or EvtGen pointers are not available or the number of tries has
322 // been exceeded. For the event weight to be valid, one should not
323 // change the absolute branching fractions in the signal and inclusive
324 // definitions, but rather just remove the unwanted decay channels
325 // from the signal decay definition.
326 
328 {
329 
330  // Reset the signal and signal counters.
331  if (!pythiaPtr || !evtgen) return -1;
332  if (!updated) updateData(true);
333 
334  // Loop over all particles in the Pythia event.
335  Pythia8::Event& event = pythiaPtr->event;
336  std::vector<int> pySigs; std::vector<EvtParticle*> egSigs, egPrts;
337  std::vector<double> bfs; double wgt(1.);
338  for (int iPro = 0; iPro < event.size(); ++iPro) {
339 
340  // Check particle is final and can be decayed by EvtGen.
341  Pythia8::Particle* pyPro = &event[iPro];
342  if (!pyPro->isFinal()) continue;
343  if (incIds.find(pyPro->id()) == incIds.end()) continue;
344  if (pyPro->status() == 93 || pyPro->status() == 94) continue;
345 
346  // Decay the progenitor with EvtGen.
347  EvtParticle* egPro = EvtParticleFactory::particleFactory
348  (EvtPDL::evtIdFromStdHep(pyPro->id()),
349  EvtVector4R(pyPro->e(), pyPro->px(), pyPro->py(), pyPro->pz()));
350  egPrts.push_back(egPro);
351  egPro->setDiagonalSpinDensity();
352  evtgen->generateDecay(egPro);
353  pyPro->tau(egPro->getLifetime());
354  if (!checkVertex(pyPro)) continue;
355 
356  // Add oscillations to event record.
357  if (checkOsc(egPro))
358  updateEvent(pyPro, egPro, &pySigs, &egSigs, &bfs, &wgt);
359 
360  // Undo decay if signal (duplicate to stop oscillations).
361  else if (checkSignal(pyPro)) {
362  pySigs.push_back(pyPro->index());
363  egSigs.push_back(egPro);
364  bfs.push_back(signal->second.bfs[0]);
365  wgt *= 1 - bfs.back();
366  egPro->deleteDaughters();
367  EvtParticle* egDau = EvtParticleFactory::particleFactory
368  (EvtPDL::evtIdFromStdHep(pyPro->id()),
369  EvtVector4R(pyPro->e(), pyPro->px(), pyPro->py(), pyPro->pz()));
370  egDau->addDaug(egPro);
371  egDau->setDiagonalSpinDensity();
372 
373  // If not signal, add to event record.
374  } else updateEvent(pyPro, egPro, &pySigs, &egSigs, &bfs, &wgt);
375  }
376  if (pySigs.size() == 0) {
377  for (int iPrt = 0; iPrt < (int)egPrts.size(); ++iPrt)
378  egPrts[iPrt]->deleteTree();
379  return 0;
380  }
381 
382  // Determine the decays of the signal particles (signal or background).
383  std::vector<int> modes; int force(-1);
384  for (int iTry = 1; iTry <= NTRYDECAY; ++iTry) {
385  int n(0);
386 
387  modes.clear(); force = pythiaPtr->rndm.pick(bfs); n = 0;
388  for (int iSig = 0; iSig < (int)pySigs.size(); ++iSig) {
389  if (iSig == force) modes.push_back(0);
390  else modes.push_back(pythiaPtr->rndm.flat() > bfs[iSig]);
391  if (modes.back() == 0) ++n;
392  }
393  if (pythiaPtr->rndm.flat() <= 1.0 / n) break;
394  if (iTry == NTRYDECAY) {
395  wgt = 2.;
396  B2WARNING("Warning in EvtGenDecays::decay: maximum number of signal decay attempts exceeded"
397  << LogVar("maxTries", NTRYDECAY));
398  }
399  }
400 
401  // Decay the signal particles and mark forced decay.
402  for (int iSig = 0; iSig < (int)pySigs.size(); ++iSig) {
403  EvtParticle* egSig = egSigs[iSig];
404  Pythia8::Particle* pySig = &event[pySigs[iSig]];
405  signal = signals.find(pySig->id());
406  if (egSig->getNDaug() > 0) egSig = egSig->getDaug(0);
407  if (modes[iSig] == 0) egSig->setId(signal->second.egId);
408  else {
409  signal->second.modes.getDecayModel(egSig);
410  egSig->setChannel(signal->second.map[egSig->getChannel()]);
411  }
412  if (iSig == force)
413  pySig->status(pySig->status() == 92 || pySig->status() == 94 ? 96 : 95);
414  evtgen->generateDecay(egSig);
415  updateEvent(pySig, egSigs[iSig]);
416  }
417 
418  // Delete all EvtGen particles and return weight.
419  for (int iPrt = 0; iPrt < (int)egPrts.size(); ++iPrt)
420  egPrts[iPrt]->deleteTree();
421  return 1. - wgt;
422 
423 }
424 
425 //--------------------------------------------------------------------------
426 
427 // Update the Pythia particle database from EvtGen.
428 
429 // Note that only the particle spin type, charge type, nominal mass,
430 // width, minimum mass, maximum mass, and nominal lifetime are
431 // set. The name string is not set.
432 
434 {
435  if (!pythiaPtr || !evtgen) return;
436  for (int entry = 0; entry < (int)EvtPDL::entries(); ++entry) {
437  EvtId egId = EvtPDL::getEntry(entry);
438  int pyId = EvtPDL::getStdHep(egId);
439  pythiaPtr->particleData.spinType(pyId, EvtPDL::getSpinType(egId));
440  pythiaPtr->particleData.chargeType(pyId, EvtPDL::chg3(egId));
441  pythiaPtr->particleData.m0(pyId, EvtPDL::getMass(egId));
442  pythiaPtr->particleData.mWidth(pyId, EvtPDL::getWidth(egId));
443  pythiaPtr->particleData.mMin(pyId, EvtPDL::getMinMass(egId));
444  pythiaPtr->particleData.mMax(pyId, EvtPDL::getMaxMass(egId));
445  pythiaPtr->particleData.tau0(pyId, EvtPDL::getctau(egId));
446  }
447 }
448 
449 //--------------------------------------------------------------------------
450 
451 // Update the EvtGen particle database from Pythia.
452 
453 // The particle update database between Pythia and EvtGen is not
454 // symmetric. Particularly, it is not possible to update the spin
455 // type, charge, or nominal lifetime in the EvtGen particle database.
456 
458 {
459  if (!pythiaPtr || !evtgen) return;
460  int pyId = pythiaPtr->particleData.nextId(0);
461  while (pyId != 0) {
462  EvtId egId = EvtPDL::evtIdFromStdHep(pyId);
463  EvtPDL::reSetMass(egId, pythiaPtr->particleData.m0(pyId));
464  EvtPDL::reSetWidth(egId, pythiaPtr->particleData.mWidth(pyId));
465  EvtPDL::reSetMassMin(egId, pythiaPtr->particleData.mMin(pyId));
466  EvtPDL::reSetMassMax(egId, pythiaPtr->particleData.mMax(pyId));
467  pyId = pythiaPtr->particleData.nextId(pyId);
468  }
469 }
470 
471 //--------------------------------------------------------------------------
472 
473 // Update the particles to decay with EvtGen, and the selected signals.
474 
475 // If final is false, then only signals are initialized in the signal
476 // map. Any particle or alias that ends with signalSuffix is taken as
477 // a signal particle. If final is true all particle entries in EvtGen
478 // are checked to see if they should be set stable in Pythia. If an
479 // EvtGen particle has no decay modes, then Pythia is still allowed to
480 // decay the particle. Additionally, the signal decay channels are
481 // turned off for the non-aliased signal particle.
482 
483 void EvtGenDecays::updateData(bool final)
484 {
485 
486  // Loop over the EvtGen entries.
487  if (!pythiaPtr) return;
488  EvtDecayTable* egTable = EvtDecayTable::getInstance();
489  if (!egTable) return;
490  for (int iEntry = 0; iEntry < (int)EvtPDL::entries(); ++iEntry) {
491  EvtId egId = EvtPDL::getEntry(iEntry);
492  int pyId = EvtPDL::getStdHep(egId);
493  if (egTable->getNModes(egId) == 0) continue;
494  if (excIds.find(pyId) != excIds.end()) continue;
495 
496  // Stop Pythia from decaying the particle and include in decay set.
497  if (final) {
498  incIds.insert(pyId);
499  pythiaPtr->particleData.mayDecay(pyId, false);
500  }
501 
502  // Check for signal.
503  std::string egName = EvtPDL::name(egId);
504  if (egName.size() <= signalSuffix.size() || egName.substr
505  (egName.size() - signalSuffix.size()) != signalSuffix) continue;
506  signal = signals.find(pyId);
507  if (signal == signals.end()) {
508  signals[pyId].status = -1;
509  signal = signals.find(pyId);
510  }
511  signal->second.egId = egId;
512  signal->second.bfs = std::vector<double>(2, 0);
513  if (!final) continue;
514 
515  // Get the signal and background decay modes.
516  std::vector<EvtParticleDecayList> egList = egTable->getDecayTable();
517  int sigIdx = egId.getAlias();
518  int bkgIdx = EvtPDL::evtIdFromStdHep(pyId).getAlias();
519  if (sigIdx > (int)egList.size() || bkgIdx > (int)egList.size()) continue;
520  EvtParticleDecayList sigModes = egList[sigIdx];
521  EvtParticleDecayList bkgModes = egList[bkgIdx];
522  EvtParticleDecayList allModes = egList[bkgIdx];
523  double sum(0);
524 
525  // Sum signal branching fractions.
526  for (int iMode = 0; iMode < sigModes.getNMode(); ++iMode) {
527  EvtDecayBase* mode = sigModes.getDecayModel(iMode);
528  if (!mode) continue;
529  signal->second.bfs[0] += mode->getBranchingFraction();
530  sum += mode->getBranchingFraction();
531  }
532 
533  // Sum remaining background branching fractions.
534  for (int iMode = 0; iMode < allModes.getNMode(); ++iMode) {
535  EvtDecayBase* mode = allModes.getDecayModel(iMode);
536  if (!mode) continue;
537  bool match(false);
538  for (int jMode = 0; jMode < sigModes.getNMode(); ++jMode)
539  if (mode->matchingDecay(*(sigModes.getDecayModel(jMode)))) {
540  match = true; break;
541  }
542  if (match) bkgModes.removeMode(mode);
543  else {
544  signal->second.map.push_back(iMode);
545  signal->second.bfs[1] += mode->getBranchingFraction();
546  sum += mode->getBranchingFraction();
547  }
548  }
549  signal->second.modes = bkgModes;
550  for (int iBf = 0; iBf < (int)signal->second.bfs.size(); ++iBf)
551  signal->second.bfs[iBf] /= sum;
552  }
553  if (final) updated = true;
554 
555 }
556 
557 //--------------------------------------------------------------------------
558 
559 // Update the Pythia event record with an EvtGen decay tree.
560 
561 // The production vertex of each particle (which can also be obtained
562 // in EvtGen via EvtParticle::get4Pos()) is set by the decay vertex of
563 // its mother, which in turn is calculated from the mother's
564 // lifetime. The status code 93 is used to indicate an external decay,
565 // while the status code 94 is used to indicate an oscillated external
566 // decay. If the progenitor has a single daughter with the same ID,
567 // this daughter is used as the progenitor. This is used to prevent
568 // double oscillations.
569 
570 // If the arguments after egPro are no NULL and a particle in the
571 // decay tree is a signal particle, the decay for this particle is
572 // removed and the particle is stored as a signal candidate in the
573 // pySigs and egSigs vectors, to be decayed later. However, if any of
574 // these arguments is NULL then the entire tree is written.
575 
576 void EvtGenDecays::updateEvent(Pythia8::Particle* pyPro, EvtParticle* egPro,
577  std::vector<int>* pySigs, std::vector<EvtParticle*>* egSigs,
578  std::vector<double>* bfs, double* wgt)
579 {
580 
581  // Set up the mother vector.
582  if (!pythiaPtr) return;
583  EvtParticle* egMom = egPro;
584  if (egPro->getNDaug() == 1 && egPro->getPDGId() ==
585  egPro->getDaug(0)->getPDGId()) egMom = egPro->getDaug(0);
586  Pythia8::Event& event = pythiaPtr->event;
587  std::vector< std::pair<EvtParticle*, int> >
588  moms(1, std::pair<EvtParticle*, int>(egMom, pyPro->index()));
589 
590  // Loop over the mothers.
591  while (moms.size() != 0) {
592 
593  // Check if particle can decay.
594  egMom = moms.back().first;
595  int iMom = moms.back().second;
596  Pythia8::Particle* pyMom = &event[iMom];
597  moms.pop_back();
598  if (!checkVertex(pyMom)) continue;
599  bool osc(checkOsc(egMom));
600 
601  // Set the children of the mother.
602  pyMom->daughters(event.size(), event.size() + egMom->getNDaug() - 1);
603  pyMom->statusNeg();
604  Pythia8::Vec4 vProd = pyMom->vDec();
605  for (int iDtr = 0 ; iDtr < (int)egMom->getNDaug(); ++iDtr) {
606  EvtParticle* egDtr = egMom->getDaug(iDtr);
607  int id = egDtr->getPDGId();
608  EvtVector4R p = egDtr->getP4Lab();
609  int idx = event.append(id, 93, iMom, 0, 0, 0, 0, 0, p.get(1),
610  p.get(2), p.get(3), p.get(0), egDtr->mass());
611  Pythia8::Particle* pyDtr = &event.back();
612  pyDtr->vProd(vProd);
613  pyDtr->tau(egDtr->getLifetime());
614  if (pySigs && egSigs && bfs && wgt && checkSignal(pyDtr)) {
615  pySigs->push_back(pyDtr->index());
616  egSigs->push_back(egDtr);
617  bfs->push_back(signal->second.bfs[0]);
618  (*wgt) *= 1 - bfs->back();
619  egDtr->deleteDaughters();
620  }
621  if (osc) pyDtr->status(94);
622  if (egDtr->getAttribute("FSR"))
623  pyDtr->status(Belle2::GeneratorConst::FSR_STATUS_CODE);
624  if (egDtr->getNDaug() > 0)
625  moms.push_back(std::pair<EvtParticle*, int>(egDtr, idx));
626  }
627  }
628 
629 }
630 
631 //--------------------------------------------------------------------------
632 
633 // Check if a particle can decay.
634 
635 // Modified slightly from ParticleDecays::checkVertex.
636 
637 bool EvtGenDecays::checkVertex(Pythia8::Particle* pyPro)
638 {
639  using ::Pythia8::pow2;
640 
641  if (!limitDecay) return true;
642  if (limitTau0 && pyPro->tau0() > tau0Max) return false;
643  if (limitTau && pyPro->tau() > tauMax) return false;
644  if (limitRadius && pow2(pyPro->xDec()) + pow2(pyPro->yDec())
645  + pow2(pyPro->zDec()) > pow2(rMax)) return false;
646  if (limitCylinder && (pow2(pyPro->xDec()) + pow2(pyPro->yDec())
647  > pow2(xyMax) || abs(pyPro->zDec()) > zMax)) return false;
648  return true;
649 }
650 
651 //--------------------------------------------------------------------------
652 
653 // Check if a particle is signal.
654 
655 bool EvtGenDecays::checkSignal(Pythia8::Particle* pyPro)
656 {
657  signal = signals.find(pyPro->id());
658  if (signal != signals.end() && (signal->second.status < 0 ||
659  signal->second.status == pyPro->status())) return true;
660  else return false;
661 }
662 
663 //--------------------------------------------------------------------------
664 
665 // Check if an EvtGen particle has oscillated.
666 
667 // The criteria defined here for oscillation is a single daughter but
668 // with a different ID from the mother.
669 
670 bool EvtGenDecays::checkOsc(EvtParticle* egPro)
671 {
672  if (egPro && egPro->getNDaug() == 1 &&
673  egPro->getPDGId() != egPro->getDaug(0)->getPDGId()) return true;
674  else return false;
675 }
676 
677 //==========================================================================
A class to perform decays via the external EvtGen decay program, see http://evtgen....
Definition: EvtGenDecays.h:88
EvtGen * evtgen
The EvtGen object.
Definition: EvtGenDecays.h:185
void updateData(bool final=false)
Update the particles to decay with EvtGen, and the selected signals.
Definition: EvtGenDecays.h:483
EvtAbsRadCorr * fsrPtr
FSR model pointer.
Definition: EvtGenDecays.h:139
void exclude(int id)
Stop EvtGen decaying a particle.
Definition: EvtGenDecays.h:122
std::map< int, Signal >::iterator signal
The selected signal iterator.
Definition: EvtGenDecays.h:194
double tauMax
the pythia parameter ParticleDecays:tauMax
Definition: EvtGenDecays.h:201
EvtGenDecays & operator=(const EvtGenDecays &)=delete
forbid assignment
bool limitCylinder
the pythia parameter ParticleDecays:limitCylinder
Definition: EvtGenDecays.h:208
~EvtGenDecays()
Destructor.
Definition: EvtGenDecays.h:102
EvtGenDecays(Pythia8::Pythia *pythiaPtrIn, EvtGen *evtGen, bool limit=true)
Expert constructor which takes an already initialized EvtGen instance.
Definition: EvtGenDecays.h:255
bool fsrOwner
bool has FSR model
Definition: EvtGenDecays.h:137
std::map< int, Signal > signals
signal particles and statuses
Definition: EvtGenDecays.h:151
std::set< int > incIds
Set of particle IDs to include decays with EvtGen.
Definition: EvtGenDecays.h:187
std::list< EvtDecayBase * > models
list of model pointers
Definition: EvtGenDecays.h:140
bool checkSignal(Pythia8::Particle *pyPro)
Check if a particle is signal.
Definition: EvtGenDecays.h:655
bool updated
Flag whether the final particle update has been performed.
Definition: EvtGenDecays.h:191
EvtGenDecays(const EvtGenDecays &)=delete
forbid copy
EvtExternalGenList * extPtr
External model pointer.
Definition: EvtGenDecays.h:138
bool checkVertex(Pythia8::Particle *pyPro)
Check if a particle can decay.
Definition: EvtGenDecays.h:637
double zMax
the pythia parameter ParticleDecays:zMax
Definition: EvtGenDecays.h:204
void updatePythia()
Update the Pythia particle database from EvtGen.
Definition: EvtGenDecays.h:433
bool checkOsc(EvtParticle *egPro)
Check if an EvtGen particle has oscillated.
Definition: EvtGenDecays.h:670
double xyMax
the pythia parameter ParticleDecays:xyMax
Definition: EvtGenDecays.h:203
std::set< int > excIds
Set of particle IDs to exclude decays with EvtGen.
Definition: EvtGenDecays.h:188
bool limitTau
the pythia parameter ParticleDecays:limitTau
Definition: EvtGenDecays.h:206
double rMax
the pythia parameter ParticleDecays:rMax
Definition: EvtGenDecays.h:202
static constexpr int NTRYDECAY
Number of times to try a decay sampling (constant).
Definition: EvtGenDecays.h:176
void updateEvtGen()
Update the EvtGen particle database from Pythia.
Definition: EvtGenDecays.h:457
bool limitRadius
the pythia parameter ParticleDecays:limitRadius
Definition: EvtGenDecays.h:207
bool limitDecay
is the decay limited
Definition: EvtGenDecays.h:209
void readDecayFile(std::string decayFile, bool xml=false)
Read an EvtGen user decay file.
Definition: EvtGenDecays.h:131
bool extOwner
bool has external model
Definition: EvtGenDecays.h:136
void getDecayLimits(bool limit)
Get the Decay limits from Pythia.
Definition: EvtGenDecays.h:286
std::string signalSuffix
The suffix indicating an EvtGen particle or alias is signal.
Definition: EvtGenDecays.h:154
void updateEvent(Pythia8::Particle *pyPro, EvtParticle *egPro, std::vector< int > *pySigs=0, std::vector< EvtParticle * > *egSigs=0, std::vector< double > *bfs=0, double *wgt=0)
Update the Pythia event record with an EvtGen decay tree.
Definition: EvtGenDecays.h:576
EvtGenRandom rndm
Random number wrapper for EvtGen.
Definition: EvtGenDecays.h:182
double decay()
Perform all decays and return the event weight.
Definition: EvtGenDecays.h:327
bool limitTau0
the pythia parameter ParticleDecays:limitTau0
Definition: EvtGenDecays.h:205
Pythia8::Pythia * pythiaPtr
The pointer to the associated Pythia object.
Definition: EvtGenDecays.h:179
double tau0Max
Parameters used to check if a particle should decay (as set via Pythia).
Definition: EvtGenDecays.h:200
A class to wrap the Pythia random number generator for use by EvtGen.
Definition: EvtGenDecays.h:29
double random()
Return a random number.
Definition: EvtGenDecays.h:37
EvtGenRandom(Pythia8::Rndm *rndmPtrIn)
Constructor.
Definition: EvtGenDecays.h:34
Pythia8::Rndm * rndmPtr
The random number pointer.
Definition: EvtGenDecays.h:40
Class to store variables with their name which were sent to the logging service.
Map of signal particle info.
Definition: EvtGenDecays.h:143
std::vector< int > map
the map for statuses
Definition: EvtGenDecays.h:147
EvtId egId
the Lund ID
Definition: EvtGenDecays.h:145
int status
status needed to consider a particle a signal
Definition: EvtGenDecays.h:144
EvtParticleDecayList modes
list of decay modes &
Definition: EvtGenDecays.h:148
std::vector< double > bfs
branching fractions
Definition: EvtGenDecays.h:146