21 #include <TClonesArray.h>
22 #include <TIterator.h>
23 #include <TLorentzVector.h>
24 #include <TParticle.h>
25 #include <TRefArray.h>
26 #include <TVirtualMC.h>
33 , fParticles(new TClonesArray(
"TParticle", size))
34 , fTracks(new TClonesArray(
"FairMCTrack", size))
45 , fStoreSecondaries(kTRUE)
48 , fStoreMothers(kTRUE)
83 toBeDone, parentId, pdgCode, px, py, pz, e, vx, vy, vz, time, polx, poly, polz, proc, ntr, weight, is, -1);
110 TClonesArray& partArray = *fParticles;
113 Int_t trackId = fNParticles;
115 Int_t daughter1Id = -1;
116 Int_t daughter2Id = -1;
117 TParticle* particle =
new (partArray[fNParticles++])
118 TParticle(pdgCode, trackId, parentId, nPoints, daughter1Id, daughter2Id, px, py, pz, e, vx, vy, vz, time);
119 particle->SetPolarisation(polx, poly, polz);
120 particle->SetWeight(weight);
121 particle->SetUniqueID(proc);
133 fStack.push(particle);
140 if (fStack.empty()) {
146 TParticle* thisParticle = fStack.top();
154 fCurrentTrack = thisParticle->GetStatusCode();
155 iTrack = fCurrentTrack;
166 if (iPrim < 0 || iPrim >= fNPrimaries) {
167 LOG(fatal) <<
"Primary index out of range!" << iPrim;
172 TParticle* part =
static_cast<TParticle*
>(fParticles->At(iPrim));
173 if (!(part->GetMother(0) < 0)) {
174 LOG(fatal) <<
"Not a primary track!" << iPrim;
182 TParticle* currentPart =
GetParticle(fCurrentTrack);
184 LOG(warn) <<
"Current track not found in stack!";
191 TClonesArray& array = *fParticles;
192 TParticle* newPart =
new (array[fIndex]) TParticle(*oldPart);
193 newPart->SetWeight(oldPart->GetWeight());
194 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;
244 std::map<Int_t, Int_t>::const_iterator tempIter =
247 return tempIter->second;
249 return fCurrentTrack;
257 for (Int_t i = 0; i < fNTracks; i++) {
260 fIndexIter = fIndexMap.find(iMotherOld);
261 if (fIndexIter == fIndexMap.end()) {
262 LOG(fatal) <<
"Particle index " << iMotherOld <<
" not found in index map!";
277 while ((det = static_cast<FairDetector*>(
fDetIter->Next()))) {
281 TClonesArray* hitArray;
284 Int_t nPoints = hitArray->GetEntriesFast();
287 for (Int_t iPoint = 0; iPoint < nPoints; iPoint++) {
293 FastSimUpdateTrackIndex<FairMCPoint>(point, iTrack);
295 fIndexIter = fIndexMap.find(iTrack);
296 if (fIndexIter == fIndexMap.end()) {
297 LOG(fatal) <<
"Particle index " << iTrack <<
" not found in index map!";
299 point->SetTrackID((*fIndexIter).second);
300 point->SetLink(
FairLink(
"MCTrack", (*fIndexIter).second));
306 LOG(debug) <<
"...stack and " << nColl <<
" collections updated.";
313 fNPrimaries = fNParticles = fNTracks = 0;
314 while (!fStack.empty()) {
334 LOG(info) <<
"FairStack: Number of primaries = " << fNPrimaries;
335 LOG(info) <<
" Total number of particles = " << fNParticles;
336 LOG(info) <<
" Number of tracks in output = " << fNTracks;
338 for (Int_t iTrack = 0; iTrack < fNTracks; iTrack++) {
347 Int_t iTr = fCurrentTrack;
353 pair<Int_t, Int_t> a(iTr, iDet);
354 if (fPointsMap.find(a) == fPointsMap.end()) {
372 pair<Int_t, Int_t> a(iTr, iDet);
373 if (fPointsMap.find(a) == fPointsMap.end()) {
384 return currentPart->GetFirstMother();
392 if (trackID < 0 || trackID >= fNParticles) {
393 LOG(fatal) <<
"Particle index " << trackID <<
" out of range.";
395 return static_cast<TParticle*
>(fParticles->At(trackID));
398 void FairStack::SelectTracks()
406 for (Int_t i = 0; i < fNParticles; i++) {
414 for (Int_t i = 0; i < fNParticles; i++) {
417 Bool_t store = kTRUE;
420 Int_t iMother = thisPart->GetMother(0);
422 thisPart->Momentum(p);
423 Double_t energy = p.E();
424 Double_t mass = p.M();
426 Double_t eKin = energy - mass;
431 pair<Int_t, Int_t> a(i, iDet);
432 if (fPointsMap.find(a) != fPointsMap.end()) {
433 nPoints += fPointsMap[a];
438 Bool_t fastSimTrack = kFALSE;
441 fastSimTrack = kTRUE;
447 if (!fStoreSecondaries) {
450 if (nPoints < fMinPoints) {
453 if (eKin < fEnergyCut) {
462 fStoreMap[i] = store;
467 for (Int_t i = 0; i < fNParticles; i++) {
470 while (iMother >= 0) {
471 fStoreMap[iMother] = kTRUE;
void SetNPoints(Int_t iDet, Int_t np)
std::map< Int_t, Int_t >::iterator fFSTrackIter
Int_t GetMotherId() const
virtual void Print(Option_t *) const
virtual TParticle * PopNextTrack(Int_t &iTrack)
void SetMotherId(Int_t id)
static FairRootManager * Instance()
virtual Int_t GetCurrentTrackNumber() const
ClassImp(FairEventBuilder)
virtual TParticle * GetCurrentTrack() const
virtual Int_t GetCurrentParentTrackNumber() const
Int_t GetTrackID() const
event identifier
virtual void AddParticle(TParticle *part)
virtual TParticle * PopPrimaryForTracking(Int_t iPrim)
virtual void UpdateTrackIndex(TRefArray *detArray=0)
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)
std::map< Int_t, Int_t > fFSTrackMap
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
virtual TClonesArray * GetCollection(Int_t iColl) const =0
virtual void FillTrackArray()
FairStack(Int_t size=100)
void AddPoint(DetectorId iDet)
void RegisterAny(const char *name, T *&obj, Bool_t toFile)
TParticle * GetParticle(Int_t trackId) const