StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarPythia8Decayer.cxx
1 #include "StarPythia8Decayer.h"
2 #include "TLorentzVector.h"
3 #include <assert.h>
4 #include "TParticle.h"
5 #include "StarGenerator/UTIL/StarRandom.h"
6 #include "TSystem.h"
7 #include "StMessMgr.h"
8 
9 #include "ParticleData.h"
10 
11 #ifndef Pythia8_version
12 #error "Pythia8_version is not defined"
13 #endif
14 
15 using namespace Pythia8;
16 
17 // ----------------------------------------------------------------------------
18 // Remap pythia's random number generator to StarRandom
19 class PyRand : public Pythia8::RndmEngine {
20 public:
21  double flat() { return StarRandom::Instance().flat(); }
22 };
23 
24 //..................................................................................................
26  mPythia(_pythia),
27  mOwner(false),
28  mDebug(0),
29  mRootS(510.0)
30 {
31 
32  if ( mPythia ) return; // If provided, we expect pythia to be correctly initialized
33 
34  TString path = "StRoot/StarGenerator/"; path+= Pythia8_version; path+="/xmldoc/";
35  {
36  ifstream in(path);
37  if (!in.good()) { path = "$(STAR)/"+path; }
38  path = gSystem->ExpandPathName(path.Data());
39  }
40 
41  Info(GetName(),Form("MC version is %s data at %s",Pythia8_version,path.Data()));
42  Info(GetName(),Form("Configuration files at %s",path.Data()));
43 
44  mPythia = new Pythia8::Pythia( path.Data() );
45  mPythia -> setRndmEnginePtr( new PyRand() );
46 
47  mPythia -> readString("ProcessLevel:all = off"); // switch off initial state machinery
48  mPythia -> readString("Check:event = off"); // no consistency checks against IS
49  mPythia -> init();
50 
51 }
52 //..................................................................................................
54 {
55 
56  mPythia->init( 2112, 2112, mRootS );
57 
58 }
59 //..................................................................................................
60 void StarPythia8Decayer::Decay( int pdgid, TLorentzVector *_p )
61 {
62 
63  LOG_INFO << "Decay pdgid=" << pdgid << endm;
64 
65  // Clear the event from the last run
66  ClearEvent();
67  // Add the particle to the pythia stack
68  AppendParticle( pdgid, _p );
69  // Get the particle ID and allow it to decay
70  // int id = mPythia -> event[0].id();
71  // mPythia->particleData.mayDecay( id, true );
72  mPythia->next();
73 
74  // Print list of pythia lines on debug
75  if ( mDebug ) mPythia->event.list();
76 }
77 //..................................................................................................
78 int StarPythia8Decayer::ImportParticles( TClonesArray *_array )
79 {
80  // Save the decay products
81  assert(_array);
82  TClonesArray &array = *_array;
83  array.Clear();
84 
85  int nparts = 0;
86 
87  for ( int i=0; i<mPythia->event.size();i++ )
88  {
89  //if ( mPythia->event[i].id() == 90 ) continue; //??
90  new(array[nparts++]) TParticle (
91  mPythia->event[i].id(),
92  mPythia->event[i].status(),
93  mPythia->event[i].mother1(),
94  mPythia->event[i].mother2(),
95  mPythia->event[i].daughter1(),
96  mPythia->event[i].daughter2(),
97  mPythia->event[i].px(), // [GeV/c]
98  mPythia->event[i].py(), // [GeV/c]
99  mPythia->event[i].pz(), // [GeV/c]
100  mPythia->event[i].e(), // [GeV]
101  mPythia->event[i].xProd(), // [mm]
102  mPythia->event[i].yProd(), // [mm]
103  mPythia->event[i].zProd(), // [mm]
104  mPythia->event[i].tProd()); // [mm/c]
105  };
106  return nparts;
107 }
108 //..................................................................................................
109 // not implemented. complain about it. loudly.
110 void StarPythia8Decayer::SetForceDecay( int type ){ assert(0); }
111 void StarPythia8Decayer::ForceDecay(){ assert(0); }
112 float StarPythia8Decayer::GetPartialBranchingRatio( int ipdg ){ assert(0); }
113 void StarPythia8Decayer::ReadDecayTable(){ assert(0); }
114 //..................................................................................................
115 float StarPythia8Decayer::GetLifetime(int pdg)
116 {
117  // return lifetime in seconds of teh particle with PDG number pdg
118  return (mPythia->particleData.tau0(pdg) * 3.3333e-12) ;
119 }
120 //..................................................................................................
121 void StarPythia8Decayer::AppendParticle(int pdg, TLorentzVector* p)
122 {
123  // Append a particle to the stack to be decayed
124  const int status = 23;
125 
126  double pt2 = p->Perp2(); // pt squared
127  double px = p->Px();
128  double py = p->Py();
129  double pz = p->Pz(); // z-component
130  double M2 = p->M2(); // mass squared
131 
132  // Lookup particle entry in pythia8
133  const auto* pde = mPythia->particleData.particleDataEntryPtr( pdg );
134  if ( pde ) {
135  M2 = pde->m0() * pde->m0();
136  }
137 
138  double E = TMath::Sqrt( pt2 + M2 + pz*pz );
139 
140  mPythia->event.append(pdg, status, 0, 0, px, py, pz, E, TMath::Sqrt(M2) );
141 }
142 //..................................................................................................
144 {
145  mPythia->event.reset(); // Reset the event
146 }
147 //..................................................................................................
149 {
150  if (mPythia) delete mPythia; // delete
151 }
static StarRandom & Instance()
Obtain the single instance of the random number generator.
Definition: StarRandom.cxx:87
float GetPartialBranchingRatio(int pdgid)
Return the branching ratio for the spdcified PDG ID.
~StarPythia8Decayer()
Class destructor.
int ImportParticles(TClonesArray *array=0)
Returns the decay products in a TClonesArray of TParticle.
Double_t flat() const
Return a random number uniformly distributed between 0 and 1.
Definition: StarRandom.cxx:68
void Init()
Initializes the decayer.
StarPythia8Decayer()
Class constructor.
void AppendParticle(int pdgid, TLorentzVector *p=0)
Add a particle with specified PDG ID to the stack.
void ClearEvent()
Clear the event.
float GetLifetime(int pdgid)
Return teh lifetime in seconds for the specified particle.
void Decay(int pdg, TLorentzVector *p=0)
Decays the particle specified by PDG id and lorentz vector.