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))
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)
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);
177 TParticle* thisParticle =
fStack.top();
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;
224 LOG(warn) <<
"R3BStack: Current track not found in stack!";
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++)
275 LOG(fatal) <<
"R3BStack: Particle " << iPart <<
" not found in storage map!";
277 Bool_t store = (*fStoreIter).second;
289 LOG(debug) <<
"R3BMCStack IndexMap ---> -2 for iPart: " << iPart;
308 LOG(debug) <<
"R3BStack: Updating track indizes...";
312 for (Int_t i = 0; i <
fNTracks; i++)
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;
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";
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);
429 return currentPart->GetFirstMother();
440 LOG(fatal) <<
"-E- R3BStack: Particle index " << trackID <<
" out of range";
442 return dynamic_cast<TParticle*
>(
fParticles->At(trackID));
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++)
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.
std::map< int, std::array< int, kLAST+1 > > fPointsMap
STL map from track index and detector ID to number of MCPoints.
Int_t fIndex
Number of entries in fTracks.
void SelectTracks()
Mark tracks for output using selection criteria.
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.
TClonesArray * fParticles
Array of TParticles (contains all TParticles put into or created by the transport.
virtual void Register()
Register the MCTrack array to the Root Manager.
Int_t fNParticles
Number of primary particles.
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.
std::map< Int_t, Bool_t >::iterator fStoreIter
std::map< Int_t, Bool_t > fStoreMap
STL map from particle index to storage flag.
Bool_t fStoreSecondaries
index for MC units testing
std::stack< TParticle * > fStack
STL stack (FILO) used to handle the TParticles for tracking.
virtual void Reset()
Resets arrays and stack and deletes particles and tracks.
std::map< Int_t, Int_t >::iterator fIndexIter
Int_t fCurrentTrack
Some indizes and counters.
virtual TParticle * GetCurrentTrack() const
Get the current track's particle Declared in TVirtualMCStack.
std::map< Int_t, Int_t > fIndexMap
STL map from particle index to track index.
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.
Int_t fMC
Used for merging.
Int_t fNTracks
Number of entries in fParticles.
Int_t fNPrimaries
Index of current track.
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.
TClonesArray * fTracks
Array of R3BMCTracks containg the tracks written to the output.