CMS 3D CMS Logo

Decayer.cc
Go to the documentation of this file.
6 
7 #include <Pythia8/Pythia.h>
8 #include "Pythia8Plugins/HepMC2.h"
9 
11 
13  : pythia_(new Pythia8::Pythia())
14  , pythiaRandomEngine_(new gen::P8RndmEngine())
15 {
16  pythia_->setRndmEnginePtr(pythiaRandomEngine_.get());
17  pythia_->settings.flag("ProcessLevel:all",false);
18  pythia_->settings.flag("PartonLevel:FSRinResonances",false);
19  pythia_->settings.flag("ProcessLevel:resonanceDecays",false);
20  pythia_->init();
21 
22  // forbid all decays
23  // (decays are allowed selectively in the decay function)
24  Pythia8::ParticleData & pdt = pythia_->particleData;
25  int pid = 0;
26  while(pdt.nextId(pid) > pid)
27  {
28  pid = pdt.nextId(pid);
29  pdt.mayDecay(pid,false);
30  }
31 }
32 
33 void
34 fastsim::Decayer::decay(const Particle & particle,std::vector<std::unique_ptr<fastsim::Particle> > & secondaries,CLHEP::HepRandomEngine & engine) const
35 {
36  // make sure pythia takes random numbers from the engine past through via the function arguments
38 
39  // inspired by method Pythia8Hadronizer::residualDecay() in GeneratorInterface/Pythia8Interface/src/Py8GunBase.cc
40  int pid = particle.pdgId();
41  // snip decay products of exotic particles or their children. These decay products are preserved from the event record.
42  // limitation: if exotic incurs heavy energy loss during propagation, the saved decay products could be too hard.
43  if (isExotic(pid) || isExotic(particle.getMotherPdgId())) {
44  return;
45  }
46 
47  pythia_->event.reset();
48 
49  // create a pythia particle which has the same properties as the FastSim particle
50  Pythia8::Particle pythiaParticle( pid , 93, 0, 0, 0, 0, 0, 0,
51  particle.momentum().X(),
52  particle.momentum().Y(),
53  particle.momentum().Z(),
54  particle.momentum().E(),
55  particle.momentum().M() );
56  pythiaParticle.vProd(particle.position().X(), particle.position().Y(), particle.position().Z(), particle.position().T());
57  pythia_->event.append(pythiaParticle);
58 
59 
60  int nentries_before = pythia_->event.size();
61  // switch on the decay of this and only this particle (avoid double decays)
62  pythia_->particleData.mayDecay(pid,true);
63  // do the decay
64  pythia_->next();
65  // switch it off again
66  pythia_->particleData.mayDecay(pid,false);
67  int nentries_after = pythia_->event.size();
68 
69  if(nentries_after <= nentries_before)return;
70 
71  // add decay products back to the event
72  for(int ipart=nentries_before; ipart<nentries_after; ipart++)
73  {
74  Pythia8::Particle& daughter = pythia_->event[ipart];
75 
76  secondaries.emplace_back(new fastsim::Particle(daughter.id()
77  ,math::XYZTLorentzVector(daughter.xProd(),daughter.yProd(),daughter.zProd(),daughter.tProd())
78  ,math::XYZTLorentzVector(daughter.px(), daughter.py(), daughter.pz(), daughter.e())));
79 
80  // daughter can inherit the SimTrackIndex of mother (if both charged): necessary for FastSim (cheat) tracking
81  if(particle.charge() != 0 && std::abs(particle.charge()-daughter.charge()) < 1E-10){
82  secondaries.back()->setMotherDeltaR(particle.momentum());
83  secondaries.back()->setMotherPdgId(particle.getMotherDeltaR() == -1 ? particle.pdgId() : particle.getMotherPdgId());
84  secondaries.back()->setMotherSimTrackIndex(particle.simTrackIndex());
85  }
86  }
87 
88  return;
89 }
std::unique_ptr< gen::P8RndmEngine > pythiaRandomEngine_
Instance of pythia Random Engine.
Definition: Decayer.h:56
const math::XYZTLorentzVector & position() const
Return position of the particle.
Definition: Particle.h:142
int getMotherPdgId() const
Get pdgIdto mother particle (only makes sense if mother and daughter charged).
Definition: Particle.h:213
int pdgId() const
Return pdgId of the particle.
Definition: Particle.h:136
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
~Decayer()
Default destructor.
Definition: Decayer.cc:10
bool isExotic(int pdgid_)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HepPDT::ParticleData ParticleData
void decay(const Particle &particle, std::vector< std::unique_ptr< Particle > > &secondaries, CLHEP::HepRandomEngine &engine) const
Decay particle using pythia.
Definition: Decayer.cc:34
int simTrackIndex() const
Return index of the SimTrack.
Definition: Particle.h:155
double getMotherDeltaR() const
Get delta R to mother particle (only makes sense if mother and daughter charged). ...
Definition: Particle.h:206
double charge() const
Return charge of the particle.
Definition: Particle.h:139
Decayer()
Default Constructor.
Definition: Decayer.cc:12
const math::XYZTLorentzVector & momentum() const
Return momentum of the particle.
Definition: Particle.h:145
Definition of a generic FastSim Particle which can be propagated through the detector (formerly Parti...
Definition: Particle.h:19
std::unique_ptr< Pythia8::Pythia > pythia_
Instance of pythia.
Definition: Decayer.h:55