13#include "FairDetector.h"
14#include "FairLogger.h"
15#include "FairMCPoint.h"
16#include "FairRootManager.h"
19#include "TClonesArray.h"
21#include "TLorentzVector.h"
24#include "TVirtualMC.h"
25#include "TVirtualMCStack.h"
35 fParticles(new TClonesArray(
"TParticle", size)),
47 fStoreSecondaries(kTRUE),
50 fStoreMothers(kTRUE) {
51 fTracks =
new std::vector<ShipMCTrack>();
70 Double_t px, Double_t py, Double_t pz, Double_t e,
71 Double_t vx, Double_t vy, Double_t vz, Double_t time,
72 Double_t polx, Double_t poly, Double_t polz,
73 TMCProcess proc, Int_t& ntr, Double_t weight,
75 PushTrack(toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx,
76 poly, polz, proc, ntr, weight, is, -1);
81 Double_t px, Double_t py, Double_t pz, Double_t e,
82 Double_t vx, Double_t vy, Double_t vz, Double_t time,
83 Double_t polx, Double_t poly, Double_t polz,
84 TMCProcess proc, Int_t& ntr, Double_t weight,
85 Int_t is, Int_t secondparentID) {
95 Int_t daughter1Id = -1;
96 Int_t daughter2Id = -1;
97 TParticle* particle =
new (partArray[
fNParticles++])
98 TParticle(pdgCode, trackId, parentId, nPoints, daughter1Id, daughter2Id,
99 px, py, pz, e, vx, vy, vz, time);
105 particle->SetPolarisation(polx, poly, polz);
106 particle->SetWeight(weight);
107 particle->SetUniqueID(proc);
111 particle->SetFirstMother(secondparentID);
112 particle->SetLastMother(secondparentID);
114 particle->SetFirstMother(parentId);
115 particle->SetLastMother(parentId);
142 TParticle* thisParticle =
fStack.top();
164 LOGF(fatal,
"ShipStack: Primary index out of range! %i ", iPrim);
169 TParticle* part =
dynamic_cast<TParticle*
>(
fParticles->At(iPrim));
186 LOG(warning) <<
"ShipStack: Current track not found in stack!";
195 TParticle* newPart =
new (array[
fIndex]) TParticle(*oldPart);
196 newPart->SetWeight(oldPart->GetWeight());
197 newPart->SetUniqueID(oldPart->GetUniqueID());
204 LOG(
debug) <<
"ShipStack: Filling MCTrack array...";
208 if (gMC->GetStack() ==
nullptr)
return;
222 for (Int_t iPart = 0; iPart <
fNParticles; iPart++) {
225 LOGF(fatal,
"ShipStack: Particle %i not found in storage map! ", iPart);
227 Bool_t store = (*fStoreIter).second;
235 pair<Int_t, Int_t> a(iPart, iDet);
256 LOG(
debug) <<
"ShipStack: Updating track indizes...";
260 for (Int_t i = 0; i <
fNTracks; i++) {
265 LOGF(fatal,
"ShipStack: Particle index %i not found in dex map! ",
273 fDetIter = detList->MakeIterator();
279 FairDetector* det =
nullptr;
280 while ((det =
dynamic_cast<FairDetector*
>(fDetIter->Next()))) {
284 stlDet->UpdatePointTrackIndices(
fIndexMap);
289 TClonesArray* hitArray;
290 while ((hitArray = det->GetCollection(iColl++))) {
292 Int_t nPoints = hitArray->GetEntriesFast();
295 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
296 FairMCPoint* point =
dynamic_cast<FairMCPoint*
>(hitArray->At(iPoint));
297 Int_t iTrack = point->GetTrackID();
301 LOGF(fatal,
"ShipStack: Particle index %i not found in index map! ",
304 point->SetTrackID((*fIndexIter).second);
310 LOGF(
debug,
"...stack and %i collections updated.", nColl);
330 FairRootManager::Instance()->RegisterAny(
"MCTrack",
fTracks, kTRUE);
336 cout <<
"-I- ShipStack: Number of primaries = " <<
fNPrimaries << endl;
337 cout <<
" Total number of particles = " <<
fNParticles << endl;
338 cout <<
" Number of tracks in output = " <<
fNTracks << endl;
340 for (Int_t iTrack = 0; iTrack <
fNTracks; iTrack++) {
341 (*fTracks)[iTrack].Print(iTrack);
362 pair<Int_t, Int_t> a(iTrack, iDet);
371 return currentPart->GetFirstMother();
381 LOGF(fatal,
"ShipStack: Particle index %i out of range. Max=%i", trackID,
384 return dynamic_cast<TParticle*
>(
fParticles->At(trackID));
396 Bool_t store = kTRUE;
399 Int_t iMother = thisPart->GetMother(0);
401 thisPart->Momentum(p);
402 Double_t energy = p.E();
403 Double_t mass = p.M();
405 Double_t eKin = energy - mass;
410 pair<Int_t, Int_t> a(i, iDet);
449 while (iMother >= 0) {
Interface for detectors using STL containers (std::vector) for MC points.
void SetTrackID(const Int_t &trackID)
void SetEventID(const Int_t &eventID)
void SetNPoints(Int_t iDet, Int_t np)
Int_t GetMotherId() const
void SetMotherId(Int_t id)
void AddPoint(DetectorId iDet)
Int_t GetCurrentParentTrackNumber() const override
std::map< std::pair< Int_t, Int_t >, Int_t > fPointsMap
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) override
Int_t fNTracks
Number of entries in fParticles.
std::map< Int_t, Int_t > fIndexMap
TParticle * GetParticle(Int_t trackId) const
Int_t fIndex
Number of entries in fTracks.
TParticle * GetCurrentTrack() const override
virtual void Print(Int_t iVerbose=0) const
std::map< Int_t, Bool_t >::iterator fStoreIter
void UpdateTrackIndex(TRefArray *detArray=0) override
void FillTrackArray() override
Bool_t fStoreSecondaries
Used for merging.
TParticle * PopPrimaryForTracking(Int_t iPrim) override
TParticle * PopNextTrack(Int_t &iTrack) override
Int_t fNParticles
Number of primary particles.
std::map< Int_t, Bool_t > fStoreMap
Int_t fNPrimaries
Index of current track.
std::stack< TParticle * > fStack
std::map< Int_t, Int_t >::iterator fIndexIter
TClonesArray * fParticles
std::vector< ShipMCTrack > * fTracks
ShipStack(Int_t size=100)
void AddParticle(TParticle *part)