18 #include <FairDetector.h>
19 #include <FairGenericStack.h>
21 #include <FairLogger.h>
22 #include <FairMCPoint.h>
23 #include <FairRootManager.h>
26 #include <TClonesArray.h>
27 #include <TIterator.h>
28 #include <TLorentzVector.h>
29 #include <TMCProcess.h>
31 #include <TParticle.h>
32 #include <TRefArray.h>
44 : FairGenericStack(), fStack(), fParticles(new TClonesArray(
"TParticle", size)),
45 fTracks(new TClonesArray(
"AtMCTrack", size)), fStoreMap(), fStoreIter(), fIndexMap(), fIndexIter(), fPointsMap(),
46 fCurrentTrack(-1), fNPrimaries(0), fNParticles(0), fNTracks(0), fIndex(0), fStoreSecondaries(kTRUE), fMinPoints(1),
47 fEnergyCut(0.), fStoreMothers(kTRUE), fLogger(FairLogger::GetLogger())
67 void AtStack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px, Double_t py, Double_t pz,
68 Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly,
69 Double_t polz, TMCProcess proc, Int_t &ntr, Double_t weight, Int_t is)
72 PushTrack(toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, -1);
76 void AtStack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px, Double_t py, Double_t pz,
77 Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly,
78 Double_t polz, TMCProcess proc, Int_t &ntr, Double_t weight, Int_t is, Int_t secondparentID)
82 TClonesArray &partArray = *fParticles;
85 Int_t trackId = fNParticles;
87 Int_t daughter1Id = -1;
88 Int_t daughter2Id = -1;
89 auto *particle =
new (partArray[fNParticles++])
90 TParticle(pdgCode, trackId, parentId, nPoints, daughter1Id, daughter2Id, px, py, pz, e, vx, vy, vz, time);
91 particle->SetPolarisation(polx, poly, polz);
92 particle->SetWeight(weight);
93 particle->SetUniqueID(proc);
105 fStack.push(particle);
115 if (fStack.empty()) {
121 TParticle *thisParticle = fStack.top();
129 fCurrentTrack = thisParticle->GetStatusCode();
130 iTrack = fCurrentTrack;
144 if (iPrim < 0 || iPrim >= fNPrimaries) {
145 LOG(fatal) <<
"AtStack: Primary index out of range! " << iPrim;
150 auto *part =
dynamic_cast<TParticle *
>(fParticles->At(iPrim));
151 if (!(part->GetMother(0) < 0)) {
152 LOG(fatal) <<
"AtStack:: Not a primary track! " << iPrim;
162 TParticle *currentPart =
GetParticle(fCurrentTrack);
164 LOG(warning) <<
"AtStack: Current track not found in stack!";
173 TClonesArray &array = *fParticles;
174 auto *newPart =
new (array[fIndex]) TParticle(*oldPart);
175 newPart->SetWeight(oldPart->GetWeight());
176 newPart->SetUniqueID(oldPart->GetUniqueID());
185 LOG(debug) <<
"AtStack: Filling MCTrack array...";
195 for (Int_t iPart = 0; iPart < fNParticles; iPart++) {
197 fStoreIter = fStoreMap.find(iPart);
198 if (fStoreIter == fStoreMap.end()) {
199 LOG(fatal) <<
"AtStack: Particle " << iPart <<
" not found in storage map! ";
201 Bool_t store = (*fStoreIter).second;
206 fIndexMap[iPart] = fNTracks;
209 pair<Int_t, Int_t> a(iPart, iDet);
217 fIndexMap[iPart] = -2;
233 LOG(debug) <<
"AtStack: Updating track indizes...";
237 for (Int_t i = 0; i < fNTracks; i++) {
238 auto *track =
dynamic_cast<AtMCTrack *
>(fTracks->At(i));
240 fIndexIter = fIndexMap.find(iMotherOld);
241 if (fIndexIter == fIndexMap.end()) {
242 LOG(fatal) <<
"AtStack: Particle index " << iMotherOld <<
" not found in dex map! ";
244 track->SetMotherId((*fIndexIter).second);
247 if (fDetList ==
nullptr) {
249 fDetIter = detList->MakeIterator();
255 FairDetector *det =
nullptr;
256 while ((det =
dynamic_cast<FairDetector *
>(fDetIter->Next()))) {
260 TClonesArray *hitArray =
nullptr;
261 while ((hitArray = det->GetCollection(iColl++))) {
263 Int_t nPoints = hitArray->GetEntriesFast();
266 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
267 auto *point =
dynamic_cast<FairMCPoint *
>(hitArray->At(iPoint));
268 Int_t iTrack = point->GetTrackID();
270 fIndexIter = fIndexMap.find(iTrack);
271 if (fIndexIter == fIndexMap.end()) {
272 LOG(fatal) <<
"AtStack: Particle index " << iTrack <<
" not found in index map! ";
273 Fatal(
"AtStack::UpdateTrackIndex",
"Particle index not found in map");
275 point->SetTrackID((*fIndexIter).second);
276 point->SetLink(FairLink(
"MCTrack", (*fIndexIter).second));
281 LOG(debug) <<
"...stack and " << nColl <<
" collections updated.";
290 fNPrimaries = fNParticles = fNTracks = 0;
291 while (!fStack.empty()) {
303 FairRootManager::Instance()->Register(
"MCTrack",
"Stack", fTracks, kTRUE);
310 cout <<
"-I- AtStack: Number of primaries = " << fNPrimaries << endl;
311 cout <<
" Total number of particles = " << fNParticles << endl;
312 cout <<
" Number of tracks in output = " << fNTracks << endl;
314 for (Int_t iTrack = 0; iTrack < fNTracks; iTrack++) {
315 (
dynamic_cast<AtMCTrack *
>(fTracks->At(iTrack)))->Print(iTrack);
326 pair<Int_t, Int_t> a(fCurrentTrack, iDet);
327 if (fPointsMap.find(a) == fPointsMap.end()) {
342 pair<Int_t, Int_t> a(iTrack, iDet);
343 if (fPointsMap.find(a) == fPointsMap.end()) {
356 return currentPart->GetFirstMother();
366 if (trackID < 0 || trackID >= fNParticles) {
367 LOG(fatal) <<
"AtStack: Particle index " << trackID <<
" out of range.";
368 Fatal(
"AtStack::GetParticle",
"Index out of range");
370 return dynamic_cast<TParticle *
>(fParticles->At(trackID));
375 void AtStack::SelectTracks()
382 for (Int_t i = 0; i < fNParticles; i++) {
385 Bool_t store = kTRUE;
388 Int_t iMother = thisPart->GetMother(0);
390 thisPart->Momentum(p);
391 Double_t energy = p.E();
392 Double_t mass = p.M();
394 Double_t eKin = energy - mass;
399 pair<Int_t, Int_t> a(i, iDet);
400 if (fPointsMap.find(a) != fPointsMap.end()) {
401 nPoints += fPointsMap[a];
409 if (!fStoreSecondaries) {
412 if (nPoints < fMinPoints) {
415 if (eKin < fEnergyCut) {
421 fStoreMap[i] = store;
426 for (Int_t i = 0; i < fNParticles; i++) {
429 while (iMother >= 0) {
430 fStoreMap[iMother] = kTRUE;