CbmRoot
Loading...
Searching...
No Matches
CbmFastDecayer.cxx
Go to the documentation of this file.
1/* Copyright (C) 2016 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Julian Book [committer] */
4
5#include "CbmFastDecayer.h"
6
7#include "CbmStack.h"
8
9#include "FairPrimaryGenerator.h"
10
11#include "TMCProcess.h"
12#include "TSystem.h"
13#include "TVirtualMC.h"
14#include <TParticle.h>
15
16#include <algorithm> // std::find
17#include <iostream> // std::cout
18#include <sstream> // stream
19#include <vector> // std::vector
20
21using std::string;
22using std::stringstream;
23
24#include <TVirtualMCDecayer.h>
25
29 : CbmFastDecayer("fastDecayer", "fastDecayer")
30{
31 //
32 // Default Construction
33 //
34}
35
37CbmFastDecayer::CbmFastDecayer(const char* fileName, TString particle)
38 : FairGenerator()
39 , fDecayPdgCodes(0)
40 , fGeantPdgCodes(0)
41{
42 //
43 // Standrad Construction
44 //
45 particle += fileName; // dummy against unsed variables
46}
47
50{
51 //
52 // Standard Destructor
53 //
54 if (fStack) { delete fStack; }
55 fStack = 0;
56 if (fDecayer) { delete fDecayer; }
57 fDecayer = 0;
58}
59
62{
63 //
64 // Standard CbmGenerator Initializer - no input
65 // 1) initialize decayer with default decay and particle table
66 // 2) set the decay mode to force particle
67 // 3) set a user decay table if defined
68 //
69 if (!fDecayer) { Fatal("Init", "CbmFastDecayer has no external decayer!!!"); }
70 // fDecayer = new CbmDecayerEvtGen();
71
73 // fDecayer->Init(); //read the default decay table DECAY.DEC and particle table
74
75 //if is set a decay mode: default decay mode is kAll
76 // fDecayer->SetForceDecay(fForceDecay);
77 // fDecayer->ForceDecay();
78
79 // //if is defined a user decay table
80 // if(fUserDecay)
81 // {
82 // fDecayer->SetDecayTablePath(fUserDecayTablePath);
83 // fDecayer->ReadDecayTable();
84 // }
85 return kTRUE;
86}
87
89Bool_t CbmFastDecayer::ReadEvent(FairPrimaryGenerator* primGen)
90{
91 //
92 //Generate method - Input none - Output none
93 //For each event:
94 //1)return the stack of the previous generator and select particles to be decayed by EvtGen
95 //2)decay particles selected and put the decay products on the stack
96 //
97 //
98
99 // ---> Check for primary generator
100 if (!primGen) {
101 Error("ReadEvent", "No PrimaryGenerator!");
102 return kFALSE;
103 }
104
105 // ---> Check for particle stack
106 fStack = dynamic_cast<CbmStack*>(gMC->GetStack());
107 if (!fStack) {
108 Error("ReadEvent", "Error: No stack found!");
109 return kFALSE;
110 }
111
112 Float_t polar[3] = {0, 0, 0}; // Polarisation of daughter particles
113 Float_t origin0[3]; // Origin of the parent particle
114 Float_t pc[3],
115 och[3]; // Momentum and origin of the children particles from EvtGen
116 Int_t nt;
117 Float_t tof;
118 Int_t nPrimStack;
119 Int_t nTrackStack;
120 TLorentzVector* mom = new TLorentzVector();
121
122 // create array with new particles/ deacy products
123 static TClonesArray* particles;
124 if (!particles) particles = new TClonesArray("TParticle", 1000);
125
126 nPrimStack = fStack->GetNprimary();
127 nTrackStack = fStack->GetNtrack();
128 Info("ReadEvent", "nPrimaries = %d and ntracks = %d before fast decayer", nPrimStack, nTrackStack);
129
131 primGen->DoTracking(kTRUE);
132 fStack->DoTracking(kTRUE);
133
135 std::vector<int>::iterator it;
136
137 // loop over all tracks need to decay
138 for (Int_t iTrack = 0; iTrack < nTrackStack; ++iTrack) {
139
140 // get particle
141 TParticle* part = fStack->GetParticle(iTrack);
142 Int_t pdg = part->GetPdgCode();
143
145 it = std::find(fDecayPdgCodes.begin(), fDecayPdgCodes.end(), TMath::Abs(pdg));
146 if (it == fDecayPdgCodes.end()) continue;
147
148 //check if particle is already decayed
150 //TODO: how?
151 if (/*part->GetStatusCode() != 1 ||*/ part->GetNDaughters() > 0) {
152 Info("ReadEvent", "Attention: particle %d is already decayed (code:%d,daughters:%d)!", pdg, part->GetStatusCode(),
153 part->GetNDaughters());
154 continue;
155 }
156
158 part->SetStatusCode(11); //Set particle as decayed : change the status code
159
161 mom->SetPxPyPzE(part->Px(), part->Py(), part->Pz(), part->Energy());
162 Int_t np;
163
165 do {
166 fDecayer->Decay(pdg, mom);
167 np = fDecayer->ImportParticles(particles); // into array
168 } while (np < 0);
169
170 Int_t* trackIt = new Int_t[np];
171 Int_t* pParent = new Int_t[np];
172
173 Info("ReadEvent", "number of products: np = %d for mother: %d", np - 1, pdg);
174 // mom->Print(); // debug
175
176 for (int i = 0; i < np; i++) {
177 pParent[i] = -1;
178 trackIt[i] = 0;
179 }
180
181 //select trackable particles (decay products)
182 if (np > 1) {
183 TParticle* iparticle = 0;
184
185 for (int i = 1; i < np; i++) {
186 iparticle = (TParticle*) particles->At(i);
187 Int_t ks = iparticle->GetStatusCode();
188 Int_t pdgd = iparticle->GetPdgCode();
189
190 //track last decay products
191 if (ks == 1) {
192
194 it = std::find(fGeantPdgCodes.begin(), fGeantPdgCodes.end(), TMath::Abs(pdgd));
195 if (it == fGeantPdgCodes.end()) trackIt[i] = 1;
196 else
197 continue;
198 }
199
200 } //decay particles loop
201
202 } // if decay products
203
205 origin0[0] = part->Vx(); //[cm]
206 origin0[1] = part->Vy(); //[cm]
207 origin0[2] = part->Vz(); //[cm]
208
210 // TParticle* mother = (TParticle *) particles->At(0);
211 // TLorentzVector motherL;
212 // motherL.SetPxPyPzE(mother->Px(),mother->Py(),mother->Pz(),mother->Energy());
213 // motherL.Print();
214
215 //
216 // Put decay products on the stack
217 //
218 for (int i = 1; i < np; i++) {
219 TParticle* iparticle = (TParticle*) particles->At(i);
220 Int_t kf = iparticle->GetPdgCode();
221 Int_t ksc = iparticle->GetStatusCode();
222 Int_t jpa = iparticle->GetFirstMother() - 1; //jpa = 0 for daughters ofmother particles
223
227 Int_t iparent = (jpa > 0) ? fStack->GetNtrack() - (i - jpa) : iTrack;
228
229 Info("ReadEvent", "FirstMother = %d (iparent %d), indicePart = %d, pdg = %d ", jpa, iparent, i, kf);
230
232 och[0] = origin0[0] + iparticle->Vx(); //[cm]
233 och[1] = origin0[1] + iparticle->Vy(); //[cm]
234 och[2] = origin0[2] + iparticle->Vz(); //[cm]
235 pc[0] = iparticle->Px(); //[GeV/c]
236 pc[1] = iparticle->Py(); //[GeV/c]
237 pc[2] = iparticle->Pz(); //[GeV/c]
238 tof = part->T() + iparticle->T();
239 Double_t ee = iparticle->Energy();
240
241
244 Info("ReadEvent",
245 " Add track %d to primary Generator: pdg=%d with parent=%d and do "
246 "tracking %d (stack primaries: %d, tracks: %d)",
247 i, kf, iparent, trackIt[i], fStack->GetNprimary(), fStack->GetNtrack());
248
249 primGen->AddTrack(kf, pc[0], pc[1], pc[2], och[0], och[1], och[2], iparent - nTrackStack, trackIt[i], ee);
250
251 } // Particle loop
252
253 // clean up
254 particles->Clear();
255 if (trackIt) delete[] trackIt;
256 if (pParent) delete[] pParent;
257 }
258
260 primGen->DoTracking(kFALSE);
261 fStack->DoTracking(kFALSE);
262
263 return kTRUE;
264}
265
267{
268
269 stringstream ss(pdgs);
270 int n;
271 char ch;
272
273 while (ss >> n) {
274 if (ss >> ch) fDecayPdgCodes.push_back(n);
275 else
276 fDecayPdgCodes.push_back(n);
277 }
278
279 // for (auto i = fDecayPdgCodes.begin(); i != fDecayPdgCodes.end(); ++i)
280 // std::cout << *i << ' ';
281}
282
284{
285
286 stringstream ss(pdgs);
287 int n;
288 char ch;
289
290 while (ss >> n) {
291 if (ss >> ch) fGeantPdgCodes.push_back(n);
292 else
293 fGeantPdgCodes.push_back(n);
294 }
295
296 // for (auto i = fGeantPdgCodes.begin(); i != fGeantPdgCodes.end(); ++i)
297 // std::cout << *i << ' ';
298}
ClassImp(CbmFastDecayer) CbmFastDecayer
TVirtualMCDecayer * fDecayer
pointer to CbmStack
void SetParticlesForGeant(char const *pdgs="")
void SetParticlesForDecay(char const *pdgs="")
CbmStack * fStack
virtual Bool_t Init()
std::vector< int > fGeantPdgCodes
Bool_t ReadEvent(FairPrimaryGenerator *primGen)
std::vector< int > fDecayPdgCodes
pointer to decayer
void DoTracking(Bool_t doTracking=kTRUE)
Definition CbmStack.h:240
virtual Int_t GetNtrack() const
Definition CbmStack.h:154
TParticle * GetParticle(Int_t trackId) const
Definition CbmStack.cxx:368
virtual Int_t GetNprimary() const
Definition CbmStack.h:160