StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarEvtGenDecayer.cxx
1 #include "StarEvtGenDecayer.h"
2 
3 #include "EvtGenBase/EvtParticle.hh"
4 #include "EvtGenBase/EvtParticleFactory.hh"
5 //#include "EvtGenBase/EvtPatches.hh"
6 #include "EvtGenBase/EvtPDL.hh"
7 #include "EvtGenBase/EvtRandom.hh"
8 //#include "EvtGenBase/EvtReport.hh"
9 #include "EvtGenBase/EvtHepMCEvent.hh"
10 #include "EvtGenBase/EvtSimpleRandomEngine.hh"
11 #include "EvtGenBase/EvtMTRandomEngine.hh"
12 #include "EvtGenBase/EvtAbsRadCorr.hh"
13 #include "EvtGenBase/EvtDecayBase.hh"
14 #include "EvtGenExternal/EvtExternalGenList.hh"
15 
16 #include <list>
17 #include "TParticle.h"
18 #include "TLorentzVector.h"
19 #include "TClonesArray.h"
20 #include "TSystem.h"
21 #include "StMessMgr.h"
22 #include <iostream>
23 
24 using namespace HepMC;
25 
26 StarEvtGenDecayer::StarEvtGenDecayer(EvtGen* evtGen): mEvtGen(evtGen), mEvtGenRandomEngine(NULL), mParticle(NULL), mVertex(NULL), mOwner(false), mDebug(0)
27 {
28  if(mEvtGen) return; // trust that mEvtGen is properly initialized by the user
29  mOwner = true;
30 
31 #ifdef EVTGEN_CPP11
32  // Use the Mersenne-Twister generator (C++11 only)
33  mEvtGenRandomEngine = new EvtMTRandomEngine(stime);
34 #else
35  mEvtGenRandomEngine = new EvtSimpleRandomEngine();
36 #endif
37  EvtRandom::setRandomEngine((EvtRandomEngine*)mEvtGenRandomEngine);
38  EvtExternalGenList genList;
39  EvtAbsRadCorr* radCorrEngine = genList.getPhotosModel();
40  std::list<EvtDecayBase*> extraModels = genList.getListOfModels();
41 
42  // the hardcoded paths are temporary
43  TString decay = "StRoot/StarGenerator/EvtGen1_06_00/DECAY.DEC";
44  TString evt = "StRoot/StarGenerator/EvtGen1_06_00/evt.pdl";
45 
46  ifstream in(decay);
47  if (!in.good()) {
48  decay = "$(STAR)/"+decay; decay = gSystem->ExpandPathName( decay.Data() );
49  evt = "$(STAR)/"+evt; evt = gSystem->ExpandPathName( evt.Data() );
50  }
51 
52  mEvtGen = new EvtGen( decay,
53  evt,
54  (EvtRandomEngine*)mEvtGenRandomEngine,
55  radCorrEngine,
56  &extraModels);
57 
58  //theEvent=new EvtHepMCEvent();
59 }
60 
62 {
63  if(mOwner) {
64  delete mEvtGen;
65  delete mEvtGenRandomEngine;
66  }
67  mParticle->deleteTree();
68  delete mVertex;
69  //delete theEvent;
70 }
71 
72 void StarEvtGenDecayer::Init()
73 {
74  LOG_INFO << " Init Done" << endm;
75 }
76 
77 void StarEvtGenDecayer::Decay(int pdgId, TLorentzVector* _p)
78 {
79  LOG_INFO << "Decay pdgid=" << pdgId << endm;
80 
81  // Clear the event from the last run
82  ClearEvent();
83 
84  // Add the particle to the pythia stack
85  AppendParticle(pdgId, _p );
86 
87  // Decay the particle
88  mEvtGen->generateDecay(mParticle);
89 }
91 {
92  mVertex=new EvtVector4R(0,0,0,0);// Reset the postion for mother particle,Default is(0,0,0,0)
93  if(mParticle) mParticle->deleteTree(); // this deletes the daughter and mParticle itself (the object commits suicide)
94 }
95 
96 void StarEvtGenDecayer::AppendParticle(Int_t pdg, TLorentzVector* _p)
97 {
98  // Append a particle to the stack to be decayed
99  EvtVector4R p_init(_p->E(), _p->Px(), _p->Py(), _p->Pz());
100  EvtId parentID = EvtPDL::evtIdFromLundKC(pdg);
101  mParticle = EvtParticleFactory::particleFactory(parentID, p_init);
102  mParticle->setDiagonalSpinDensity();
103 }
104 
105 Int_t StarEvtGenDecayer::ImportParticles(TClonesArray* _array)
106 {
107  // Save the decay products
108  assert(_array);
109  TClonesArray &array = *_array;
110  array.Clear();
111 
112  EvtHepMCEvent theEvent;
113  theEvent.constructEvent(mParticle);
114  // Print list of EvtGen lines on debug
115  if (mDebug) {
116  theEvent.getEvent()->print(std::cout);
117  }
118 
119  Int_t nparts = 0;
120  Int_t particle_barcode[100];
121 
122  for ( GenEvent::vertex_const_iterator vtx = theEvent.getEvent()->vertices_begin();
123  vtx != theEvent.getEvent()->vertices_end(); ++vtx ) {
124  if(vtx==theEvent.getEvent()->vertices_begin()) {
125  for ( GenVertex::particles_in_const_iterator part = (*vtx)->particles_in_const_begin();part != (*vtx)->particles_in_const_end(); part++ ) {
126  particle_barcode[nparts]=(*part)->barcode();
127  nparts++;
128  }
129  }
130  for ( GenVertex::particles_out_const_iterator part = (*vtx)->particles_out_const_begin();part != (*vtx)->particles_out_const_end(); part++ ) {
131  particle_barcode[nparts]=(*part)->barcode();
132  nparts++;
133  }
134  }
135 
136  GenParticle* p;
137  for(Int_t np=0;np<nparts;np++) {
138  p=theEvent.getEvent()->barcode_to_particle(particle_barcode[np]);
139  int firstmother=0, firstdaughter=0, lastdaughter=0;
140  int firstmother_barcode=-1, firstdaughter_barcode=-1;
141  if(np>0) firstmother_barcode=(*(p->production_vertex()->particles_in_const_begin()))->barcode();
142  if(p->status()==2&&p->end_vertex()) {
143  firstdaughter_barcode=(*(p->end_vertex()->particles_out_const_begin()))->barcode();
144  }
145  for(int i=0;i<nparts;i++) {
146  if(particle_barcode[i]==firstmother_barcode) firstmother=i;
147  if(particle_barcode[i]==firstdaughter_barcode) {
148  firstdaughter=i;
149  lastdaughter=i;
150  if(p->status()==2&&p->end_vertex()) lastdaughter=i+p->end_vertex()->particles_out_size()-1;
151  }
152  }
153  if(np==0) {
154  new(array[np]) TParticle(p->pdg_id(), p->status()==1?11:-11,
155  firstmother, 0,
156  firstdaughter, lastdaughter,
157  p->momentum().px(),
158  p->momentum().py(),
159  p->momentum().pz(),
160  p->momentum().e(),
161  mVertex->get(1),
162  mVertex->get(2),
163  mVertex->get(3),
164  mVertex->get(0));
165  } else {
166  new(array[np]) TParticle(p->pdg_id(), p->status()==1?91:-91,
167  firstmother, 0,
168  firstdaughter, lastdaughter,
169  p->momentum().px(),
170  p->momentum().py(),
171  p->momentum().pz(),
172  p->momentum().e(),
173  mVertex->get(1)+p->production_vertex()->position().x(),
174  mVertex->get(2)+p->production_vertex()->position().y(),
175  mVertex->get(3)+p->production_vertex()->position().z(),
176  mVertex->get(0)+p->production_vertex()->position().t());
177  }
178 
179  if (mDebug) {
180  cout<<np<<" "<<((TParticle*)array[np])->GetStatusCode()
181  <<" "<<((TParticle*)array[np])->GetFirstDaughter()
182  <<" "<<((TParticle*)array[np])->GetLastDaughter()
183  <<" "<<((TParticle*)array[np])->Vx()
184  <<" "<<((TParticle*)array[np])->T()<<" ";
185  ((TParticle*)array[np])->Print();
186  }
187  }
188  return nparts;
189 }
190 
191 void StarEvtGenDecayer::SetForceDecay(Int_t type)
192 {
193  LOG_ERROR << "StarEvtGenDecayer::SetForceDecay method is not implemented in this class" <<endm;
194 }
195 
196 void StarEvtGenDecayer::ForceDecay()
197 {
198  LOG_ERROR << "StarEvtGenDecayer::ForceDecay method is not implemented in this class" <<endm;
199 }
200 
202 {
203  LOG_ERROR << "StarEvtGenDecayer::GetPartialBranchingRatio method is not implemented in this class" <<endm;
204  return 1.0;
205 }
206 
207 void StarEvtGenDecayer::ReadDecayTable()
208 {
209  LOG_ERROR << "StarEvtGenDecayer::ReadDecayTable method is not implemented in this class" <<endm;
210 }
211 
213 {
214  return (EvtPDL::getctau(EvtPDL::evtIdFromLundKC(pdg)) * 3.3333e-12) ;
215 }
216 
217 void StarEvtGenDecayer::SetDecayTable(TString decayTable)
218 {
219  mEvtGen->readUDecay(decayTable);
220 }
221 
222 void StarEvtGenDecayer::SetVertex(TLorentzVector* r)
223 {
224  mVertex->set(r->T(),r->X(),r->Y(),r->Z());
225 }
StarEvtGenDecayer(EvtGen *evtGen=NULL)
Class constructor.
int pdg_id() const
particle ID
Definition: GenParticle.h:214
double z() const
return z
Definition: SimpleVector.h:77
std::vector< HepMC::GenParticle * >::const_iterator particles_in_const_iterator
const iterator for incoming particles
Definition: GenVertex.h:152
int barcode() const
particle barcode
Definition: GenParticle.h:252
std::vector< HepMC::GenParticle * >::const_iterator particles_out_const_iterator
const iterator for outgoing particles
Definition: GenVertex.h:155
Float_t GetPartialBranchingRatio(Int_t ipart)
Return the branching ratio for the spdcified PDG ID.
void SetDecayTable(TString decayTable)
Modify EvtGen behavior.
double e() const
return E
Definition: SimpleVector.h:73
double y() const
return y
Definition: SimpleVector.h:76
~StarEvtGenDecayer()
Class destructor.
double px() const
return px
Definition: SimpleVector.h:70
GenVertex * production_vertex() const
pointer to the production vertex
Definition: GenParticle.h:218
double pz() const
return pz
Definition: SimpleVector.h:72
Definition: EvtId.hh:27
void ClearEvent()
Clear the event.
int status() const
HEPEVT decay status.
Definition: GenParticle.h:216
vertex_const_iterator vertices_end() const
end vertex iteration
Definition: GenEvent.h:381
void SetVertex(TLorentzVector *r)
Modify initial vertex position.
Definition: EvtGen.hh:46
double x() const
return x
Definition: SimpleVector.h:75
Int_t ImportParticles(TClonesArray *particles=0)
Returns the decay products in a TClonesArray of TParticle.
void deleteTree()
int particles_out_size() const
number of outgoing particles
Definition: GenVertex.h:458
void Decay(Int_t pdgId, TLorentzVector *p)
Decays the particle specified by PDG id and lorentz vector.
void print(std::ostream &ostr=std::cout) const
dumps to ostr
Definition: GenEvent.cc:277
GenParticle * barcode_to_particle(int barCode) const
assign a barcode to a particle
Definition: GenEvent.h:798
particles_out_const_iterator particles_out_const_begin() const
begin iteration of outgoing particles
Definition: GenVertex.h:445
const FourVector & position() const
vertex position and time
Definition: GenVertex.h:406
const FourVector & momentum() const
standard 4 momentum
Definition: GenParticle.h:211
void setDiagonalSpinDensity()
vertex_const_iterator vertices_begin() const
begin vertex iteration
Definition: GenEvent.h:377
Float_t GetLifetime(Int_t pdgid)
Return teh lifetime in seconds for the specified particle.
GenVertex * end_vertex() const
pointer to the decay vertex
Definition: GenParticle.h:221
double py() const
return py
Definition: SimpleVector.h:71
particles_in_const_iterator particles_in_const_begin() const
begin iteration of incoming particles
Definition: GenVertex.h:435
double t() const
return t
Definition: SimpleVector.h:78
void AppendParticle(Int_t pdgid, TLorentzVector *p=0)
Add a particle with specified PDG ID to the stack.
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60