8#include "FairDetector.h"
10#include "FairLogger.h"
11#include "FairMCPoint.h"
12#include "FairRootManager.h"
15#include <TLorentzVector.h>
16#include <TParticlePDG.h>
17#include <TVirtualMC.h>
25 , fParticles(new TClonesArray(
"TParticle", size))
26 , fTracks(new TClonesArray(
"CbmMCTrack", size))
37 , fStoreSecondaries(kTRUE)
40 , fStartZCut(1000000.)
41 , fStoreMothers(kTRUE)
76 PushTrack(toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is,
105 TClonesArray& partArray = *fParticles;
108 Int_t trackId = fNParticles;
110 Int_t daughter1Id = -1;
111 Int_t daughter2Id = -1;
112 TParticle* particle =
new (partArray[fNParticles++])
113 TParticle(pdgCode, trackId, parentId, nPoints, daughter1Id, daughter2Id, px, py, pz, e, vx, vy, vz, time);
114 particle->SetPolarisation(polx, poly, polz);
115 particle->SetWeight(weight);
116 particle->SetUniqueID(proc);
128 fStack.push(particle);
136 if (fStack.empty()) {
142 TParticle* thisParticle = fStack.top();
150 fCurrentTrack = thisParticle->GetStatusCode();
151 iTrack = fCurrentTrack;
163 if (iPrim < 0 || iPrim >= fNPrimaries) {
164 LOG(fatal) <<
"Primary index out of range!" << iPrim;
169 TParticle* part =
static_cast<TParticle*
>(fParticles->At(iPrim));
170 if (!(part->GetMother(0) < 0)) {
171 LOG(fatal) <<
"Not a primary track!" << iPrim;
180 TParticle* currentPart =
GetParticle(fCurrentTrack);
182 LOG(warn) <<
"Current track not found in stack!";
190 TClonesArray& array = *fParticles;
191 TParticle* newPart =
new (array[fIndex]) TParticle(*oldPart);
192 newPart->SetWeight(oldPart->GetWeight());
193 newPart->SetUniqueID(oldPart->GetUniqueID());
201 LOG(debug) <<
"Filling MCTrack array...";
211 for (Int_t iPart = 0; iPart < fNParticles; iPart++) {
212 Bool_t store = kFALSE;
214 fStoreIter = fStoreMap.find(iPart);
215 if (fStoreIter == fStoreMap.end()) {
216 LOG(fatal) <<
"Particle " << iPart <<
" not found in storage map! ";
218 store = (*fStoreIter).second;
223 fIndexMap[iPart] = fNTracks;
226 pair<Int_t, Int_t> a(iPart, iDet);
231 fIndexMap[iPart] = -2;
245 LOG(info) <<
"Updating track indices...";
249 for (Int_t
i = 0;
i < fNTracks;
i++) {
254 fIndexIter = fIndexMap.find(iMotherOld);
255 if (fIndexIter == fIndexMap.end()) {
256 LOG(fatal) <<
"Particle index " << iMotherOld <<
" not found in index map!";
264 fDetIter = detList->MakeIterator();
270 FairDetector* det =
nullptr;
271 while ((det =
static_cast<FairDetector*
>(fDetIter->Next()))) {
274 TClonesArray* hitArray;
275 while ((hitArray = det->GetCollection(iColl++))) {
277 Int_t nPoints = hitArray->GetEntriesFast();
280 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
281 FairMCPoint* point =
static_cast<FairMCPoint*
>(hitArray->At(iPoint));
282 Int_t iTrack = point->GetTrackID();
290 fIndexIter = fIndexMap.find(iTrack);
291 if (fIndexIter == fIndexMap.end()) {
292 LOG(fatal) <<
"Particle index " << iTrack <<
" not found in index map!";
297 int trid = fIndexIter->second;
302 point->SetTrackID(trid);
303 point->AddLink(FairLink(
"MCTrack", trid));
310 LOG(info) <<
"...stack and " << nColl <<
" collections updated.";
318 fNPrimaries = fNParticles = fNTracks = 0;
319 while (!fStack.empty()) {
322 fParticles->Delete();
331 FairRootManager::Instance()->Register(
"MCTrack",
"Stack", fTracks, kTRUE);
333 FairRootManager::Instance()->RegisterAny(
"MCTrack", fTracks, kTRUE);
340 LOG(info) <<
"CbmStack: Number of primaries = " << fNPrimaries;
341 LOG(info) <<
" Total number of particles = " << fNParticles;
342 LOG(info) <<
" Number of tracks in output = " << fNTracks;
343 if (gLogger->IsLogNeeded(fair::Severity::debug1)) {
344 for (Int_t iTrack = 0; iTrack < fNTracks; iTrack++) {
354 Int_t iTr = fCurrentTrack;
355 pair<Int_t, Int_t> a(iTr, iDet);
356 if (fPointsMap.find(a) == fPointsMap.end()) {
371 pair<Int_t, Int_t> a(iTr, iDet);
372 if (fPointsMap.find(a) == fPointsMap.end()) {
384 return currentPart->GetFirstMother();
393 if (trackID < 0 || trackID >= fNParticles) {
394 LOG(fatal) <<
"Particle index " << trackID <<
" out of range.";
396 return static_cast<TParticle*
>(fParticles->At(trackID));
400void CbmStack::SelectTracks()
406 for (Int_t
i = 0;
i < fNParticles;
i++) {
409 Bool_t store = kTRUE;
412 Int_t iMother = thisPart->GetMother(0);
414 thisPart->Momentum(p);
415 Double_t energy = p.E();
416 Double_t mass = p.M();
418 Double_t eKin = energy - mass;
422 Int_t nPoints = 0, nPointsFHCAL = 0, nPointsNoFHCAL = 0;
425 pair<Int_t, Int_t> a(
i, iDet);
426 if (fPointsMap.find(a) != fPointsMap.end()) {
427 nPoints += fPointsMap[a];
429 nPointsFHCAL += fPointsMap[a];
431 nPointsNoFHCAL += fPointsMap[a];
439 if (!fStoreSecondaries) {
442 if (nPoints < fMinPoints) {
445 if (eKin < fEnergyCut) {
448 if (thisPart->Vz() > fStartZCut) {
451 if (nPointsFHCAL && !nPointsNoFHCAL)
455 if (nPoints < fMinPoints) {
458 mass = thisPart->GetPDG()->Mass();
459 if (mass < 1.8 && mother->GetPDG()->Mass() < 1.8) {
460 if (mass > 1.0 || mother->GetPDG()->Mass() > 1.0)
462 }
else if ((thisPart->GetPdgCode() > 1e9 && (thisPart->GetPdgCode() % 1000000000) / 10000000)
463 || (mother->GetPdgCode() > 1e9 && (mother->GetPdgCode() % 1000000000) / 10000000))
491 std::multimap<Int_t, Int_t> moths;
492 std::multimap<Int_t, Int_t>::iterator it;
493 pair<std::multimap<Int_t, Int_t>::iterator, std::multimap<Int_t, Int_t>::iterator> ret;
494 std::map<Int_t, Bool_t> copyMap = fStoreMap;
495 for (Int_t
i = 0;
i < fNParticles;
i++) {
498 moths.insert(pair<Int_t, Int_t>(iMother,
i));
501 for (Int_t
i = 0;
i < fNParticles;
i++) {
504 while (iMother >= 0) {
505 fStoreMap[iMother] = kTRUE;
506 ret = moths.equal_range(iMother);
507 for (it = ret.first; it != ret.second; ++it)
508 fStoreMap[it->second] = kTRUE;
515 for (Int_t
i = 0;
i < fNParticles; ++
i) {
519 while (iMother >= 0 && fStoreMap[iMother] == kFALSE) {
521 iMother = mother->GetMother(0);
Int_t GetMotherId() const
void SetNPoints(Int_t iDet, Long64_t np)
void SetMotherId(Int_t id)
virtual void UpdateTrackIndex(TRefArray *detArray=0)
virtual TParticle * PopNextTrack(Int_t &iTrack)
virtual Int_t GetCurrentParentTrackNumber() const
void AddPoint(DetectorId iDet)
virtual TParticle * PopPrimaryForTracking(Int_t iPrim)
virtual void AddParticle(TParticle *part)
virtual TParticle * GetCurrentTrack() const
virtual void Print(Option_t *) const
TParticle * GetParticle(Int_t trackId) const
virtual void FillTrackArray()
virtual void PushTrack(Int_t toBeDone, Int_t parentID, Int_t pdgCode, Double_t px, Double_t py, Double_t pz, Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly, Double_t polz, TMCProcess proc, Int_t &ntr, Double_t weight, Int_t is)
@ store
store tags as binary type