19#include <TClonesArray.h>
21#include "FairDetector.h"
22#include "FairLogger.h"
23#include "FairMCPoint.h"
24#include "FairRootManager.h"
28#include "TLorentzVector.h"
31#include "TVirtualMC.h"
43 , fParticles(new TClonesArray(
"TParticle", size))
44 , fTracks(new TClonesArray(
"R3BMCTrack", size))
56 , fStoreSecondaries(kTRUE)
59 , fStoreMothers(kTRUE)
62 TString MCName = gMC->GetName();
63 if (MCName.CompareTo(
"TGeant4") == 0)
113 toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, -1);
135 Int_t secondparentID)
139 TClonesArray& partArray = *fParticles;
142 Int_t trackId = fNParticles;
144 Int_t daughter1Id = -1;
145 Int_t daughter2Id = -1;
146 TParticle* particle =
new (partArray[fNParticles++])
147 TParticle(pdgCode, trackId, parentId, nPoints, daughter1Id, daughter2Id, px, py, pz, e, vx, vy, vz, time);
148 particle->SetPolarisation(polx, poly, polz);
149 particle->SetWeight(weight);
150 particle->SetUniqueID(proc);
161 fStack.push(particle);
177 TParticle* thisParticle = fStack.top();
186 fCurrentTrack = thisParticle->GetStatusCode();
187 iTrack = fCurrentTrack;
201 if (iPrim < 0 || iPrim >= fNPrimaries)
203 LOG(fatal) <<
"R3BStack: Primary index out of range! " << iPrim;
208 TParticle* part =
dynamic_cast<TParticle*
>(fParticles->At(iPrim));
209 if (!(part->GetMother(0) < 0))
211 LOG(fatal) <<
"R3BStack:: Not a primary track! " << iPrim;
221 TParticle* currentPart =
GetParticle(fCurrentTrack);
224 LOG(warn) <<
"R3BStack: Current track not found in stack!";
233 TClonesArray& array = *fParticles;
234 TParticle* newPart =
new (array[fIndex]) TParticle(*oldPart);
235 newPart->SetWeight(oldPart->GetWeight());
236 newPart->SetUniqueID(oldPart->GetUniqueID());
245 LOG(debug) <<
"R3BStack: Filling MCTrack array...";
269 for (Int_t iPart = 0; iPart < fNParticles; iPart++)
272 fStoreIter = fStoreMap.find(iPart);
273 if (fStoreIter == fStoreMap.end())
275 LOG(fatal) <<
"R3BStack: Particle " << iPart <<
" not found in storage map!";
277 Bool_t store = (*fStoreIter).second;
282 fIndexMap[iPart] = fNTracks;
289 LOG(debug) <<
"R3BMCStack IndexMap ---> -2 for iPart: " << iPart;
290 fIndexMap[iPart] = -2;
308 LOG(debug) <<
"R3BStack: Updating track indizes...";
312 for (Int_t i = 0; i < fNTracks; i++)
316 fIndexIter = fIndexMap.find(iMotherOld);
317 if (fIndexIter == fIndexMap.end())
319 LOG(fatal) <<
"R3BStack: Particle index " << iMotherOld <<
" not found in dex map! ";
325 TIterator* detIter = detList->MakeIterator();
327 FairDetector* det = NULL;
328 while ((det =
dynamic_cast<FairDetector*
>(detIter->Next())))
333 TClonesArray* hitArray;
334 while ((hitArray = det->GetCollection(iColl++)))
337 Int_t nPoints = hitArray->GetEntriesFast();
340 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++)
342 FairMCPoint* point =
dynamic_cast<FairMCPoint*
>(hitArray->At(iPoint));
343 Int_t iTrack = point->GetTrackID();
345 LOG(debug) <<
"R3BMCStack TrackID Get : " << iTrack;
347 fIndexIter = fIndexMap.find(iTrack);
348 if (fIndexIter == fIndexMap.end())
350 LOG(fatal) <<
"R3BStack: Particle index " << iTrack <<
" not found in index map! ";
352 LOG(debug) <<
"R3BMCStack TrackID Set : " << (*fIndexIter).second;
356 point->SetTrackID((*fIndexIter).second);
362 LOG(debug) <<
"...stack and " << nColl <<
" collections updated";
371 fNPrimaries = fNParticles = fNTracks = 0;
372 while (!fStack.empty())
381void R3BStack::Register() { FairRootManager::Instance()->Register(
"MCTrack",
"Stack", fTracks, kTRUE); }
389 LOG(info) <<
"R3BStack: Number of primaries = " << fNPrimaries;
390 LOG(info) <<
" Total number of particles = " << fNParticles;
391 LOG(info) <<
" Number of tracks in output = " << fNTracks;
392 for (Int_t iTrack = 0; iTrack < fNTracks; iTrack++)
395 sprintf(str,
"%d", iTrack);
396 (
dynamic_cast<R3BMCTrack*
>(fTracks->At(iTrack)))->Print((Option_t*)str);
405 if (fPointsMap.find(fCurrentTrack) == fPointsMap.end())
406 fPointsMap[fCurrentTrack][detId] = 1;
408 fPointsMap[fCurrentTrack][detId]++;
417 if (fPointsMap.find(iTrack) == fPointsMap.end())
418 fPointsMap[iTrack][detId] = 1;
420 fPointsMap[iTrack][detId]++;
429 return currentPart->GetFirstMother();
438 if (trackID < 0 || trackID >= fNParticles)
440 LOG(fatal) <<
"-E- R3BStack: Particle index " << trackID <<
" out of range";
442 return dynamic_cast<TParticle*
>(fParticles->At(trackID));
447void R3BStack::SelectTracks()
454 for (Int_t i = 0; i < fNParticles; i++)
458 Bool_t store = kTRUE;
461 Int_t iMother = thisPart->GetMother(0);
463 thisPart->Momentum(p);
464 Double_t energy = p.E();
465 Double_t mass = thisPart->GetMass();
466 Double_t eKin = energy - mass;
471 for (Int_t iDet =
kREF; iDet <
kLAST; iDet++)
473 if (fPointsMap.find(i) != fPointsMap.end())
474 nPoints += fPointsMap[i][iDet];
482 if (!fStoreSecondaries)
484 if (nPoints < fMinPoints)
486 if (eKin < fEnergyCut)
491 fStoreMap[i] = store;
497 for (Int_t i = 0; i < fNParticles; i++)
504 fStoreMap[iMother] = kTRUE;
DetectorId
Unique identifier for all R3B detector systems.
ClassImp(R3B::Neuland::Cal2HitPar)
void SetMotherId(int id)
Modifiers.
virtual void PrintStack(Int_t iVerbose) const
Output to screen.
virtual void UpdateTrackIndex(TRefArray *detArray)
Update the track index in the MCTracks and MCPoints.
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)
Add a TParticle to the stack.
virtual Int_t GetCurrentParentTrackNumber() const
Get the track number of the parent of the current track Declared in TVirtualMCStack.
virtual void Register()
Register the MCTrack array to the Root Manager.
virtual void AddParticle(TParticle *part)
Add a TParticle to the fParticles array.
virtual TParticle * PopPrimaryForTracking(Int_t iPrim)
Get primary particle by index for tracking from stack Declared in TVirtualMCStack.
virtual void Reset()
Resets arrays and stack and deletes particles and tracks.
virtual TParticle * GetCurrentTrack() const
Get the current track's particle Declared in TVirtualMCStack.
virtual TParticle * PopNextTrack(Int_t &iTrack)
Get next particle for tracking from the stack.
void AddPoint(DetectorId iDet)
Increment number of points for the current track in a given detector.
virtual ~R3BStack()
Destructor.
TParticle * GetParticle(Int_t trackId) const
Accessors.
R3BStack(Int_t size=100)
Default constructor param size Estimated track number.
virtual void FillTrackArray()
Fill the MCTrack output array, applying filter criteria.