13#include "FairDetector.h"
14#include "FairMCPoint.h"
15#include "FairRootManager.h"
17#include "TClonesArray.h"
18#include "TLorentzVector.h"
36 , fParticles(new TClonesArray(
"TParticle",
size))
37 , fTracks(new TClonesArray(
"CbmMCTrack",
size))
46 , fStoreSecondaries(kTRUE)
49 , fStoreMothers(kTRUE)
73void CbmStack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px, Double_t py, Double_t pz,
74 Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly,
75 Double_t polz, TMCProcess proc, Int_t& ntr, Double_t weight, Int_t is)
81 PushTrack(toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, -1);
87void CbmStack::PushTrack(Int_t toBeDone, Int_t parentId, Int_t pdgCode, Double_t px, Double_t py, Double_t pz,
88 Double_t e, Double_t vx, Double_t vy, Double_t vz, Double_t time, Double_t polx, Double_t poly,
89 Double_t polz, TMCProcess proc, Int_t& ntr, Double_t weight, Int_t ,
90 Int_t generatorParentId)
97 if (parentId == -1 && generatorParentId <
fNParticles) parentId = generatorParentId;
102 Int_t daughter1Id = -1;
103 Int_t daughter2Id = -1;
104 TParticle* particle =
new ((*fParticles)[
fNParticles++])
105 TParticle(pdgCode, trackId, parentId, nPoints, daughter1Id, daughter2Id, px, py, pz, e, vx, vy, vz, time);
106 particle->SetPolarisation(polx, poly, polz);
107 particle->SetWeight(weight);
111 particle->SetUniqueID(proc);
139 TParticle* thisParticle =
fStack.top();
165 TParticle* part = (TParticle*)
fParticles->At(iPrim);
166 assert(part->GetUniqueID() == kPPrimary);
167 if (!part->TestBit(1)) {
return NULL; }
179 if (!currentPart) { LOG(warn) <<
"Current track not found in stack!"; }
189 TParticle* newPart =
new (array[
fIndex]) TParticle(*oldPart);
190 newPart->SetWeight(oldPart->GetWeight());
191 newPart->SetUniqueID(oldPart->GetUniqueID());
204 auto nParticles =
static_cast<std::size_t
>(
fParticles->GetEntriesFast());
205 assert(store.size() == nParticles);
212 for (Int_t indexP = 0; indexP <
fParticles->GetEntriesFast(); indexP++) {
217 Int_t indexT =
fTracks->GetEntriesFast();
225 auto it =
fPointsMap.find(make_pair(indexP, detector));
239 LOG(info) <<
"CbmStack: " <<
fParticles->GetEntriesFast() <<
" particles, " <<
fNTracks <<
" written to output.";
248 LOG(debug) <<
"Updating track indizes...";
252 for (Int_t i = 0; i <
fNTracks; i++) {
256 if (
fIndexIter ==
fIndexMap.end()) { LOG(fatal) <<
"Particle index " << iMotherOld <<
" not found in dex map! "; }
261 TIterator* detIter = detList->MakeIterator();
263 FairDetector* det =
nullptr;
264 while ((det = (FairDetector*) detIter->Next())) {
269 TClonesArray* hitArray;
270 while ((hitArray = det->GetCollection(iColl++))) {
272 Int_t nPoints = hitArray->GetEntriesFast();
275 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
276 FairMCPoint* point = (FairMCPoint*) hitArray->At(iPoint);
277 Int_t iTrack = point->GetTrackID();
280 if (
fIndexIter ==
fIndexMap.end()) { LOG(fatal) <<
"Particle index " << iTrack <<
" not found in index map! "; }
281 point->SetTrackID((*fIndexIter).second);
282 point->SetLink(FairLink(
"MCTrack", (*fIndexIter).second));
289 LOG(debug) <<
"...stack and " << nColl <<
" collections updated.";
318 LOG(debug) <<
"Number of primaries = " <<
fNPrimaries;
319 LOG(debug) <<
"Total number of particles = " <<
fNParticles;
320 LOG(debug) <<
"Number of tracks in output = " <<
fNTracks;
321 if (fair::Logger::Logging(fair::Severity::debug1)) {
322 for (Int_t iTrack = 0; iTrack <
fNTracks; iTrack++) {
323 LOG(debug1) <<
"MCTrack " << iTrack << ((
CbmMCTrack*)
fTracks->At(iTrack))->ToString();
345 if (iTrack < 0) {
return; }
346 pair<Int_t, ECbmModuleId> a(iTrack, detId);
359 if (currentPart) {
return currentPart->GetFirstMother(); }
370 if (trackID < 0 || trackID >=
fNParticles) { LOG(fatal) <<
"Particle index " << trackID <<
" out of range."; }
ClassImp(CbmConverterManager)
@ kNofSystems
For loops over active systems.
static constexpr size_t size()
void SetNPoints(ECbmModuleId iDet, int32_t np)
int32_t GetMotherId() const
void SetMotherId(int32_t id)
Class for filtering the stack before writing.
Int_t fNParticles
Number of primary particles.
void AddPoint(ECbmModuleId iDet)
virtual TParticle * PopNextTrack(Int_t &iTrack)
virtual Int_t GetCurrentParentTrackNumber() const
Int_t fIndex
Number of entries in fTracks.
Int_t fNPrimaries
Index of current track.
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 process, Int_t &ntr, Double_t weight, Int_t status)
Add a track to the stack (TVirtualMCStack)
std::map< std::pair< Int_t, ECbmModuleId >, Int_t > fPointsMap
virtual TParticle * PopPrimaryForTracking(Int_t iPrim)
virtual void AddParticle(TParticle *part)
virtual TParticle * GetCurrentTrack() const
TParticle * GetParticle(Int_t trackId) const
std::map< Int_t, Int_t >::iterator fIndexIter
virtual void FillTrackArray()
Int_t fNTracks
Number of entries in fParticles.
std::map< Int_t, Int_t > fIndexMap
TClonesArray * fParticles
Stack filter class.
virtual void UpdateTrackIndex(TRefArray *detArray)
virtual void Print(Option_t *="") const
std::stack< TParticle * > fStack
std::unique_ptr< CbmStackFilter > fFilter