Project
Loading...
Searching...
No Matches
FairGenericStack.cxx
Go to the documentation of this file.
1/********************************************************************************
2 * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3 * *
4 * This software is distributed under the terms of the *
5 * GNU Lesser General Public Licence (LGPL) version 3, *
6 * copied verbatim in the file "LICENSE" *
7 ********************************************************************************/
8// -------------------------------------------------------------------------
9// ----- FairGenericStack source file -----
10// ----- Created 10/08/04 by D. Bertini -----
11// -------------------------------------------------------------------------
12#include "FairGenericStack.h"
13
14#include "FairLogger.h" // for FairLogger
15
16#include <TGeoManager.h>
17#include <TLorentzVector.h>
18#include <TMCProcess.h>
19#include <TRefArray.h>
20#include <TString.h>
21#include <TVirtualMC.h>
22#include <cstring> // strcmp
23
26 , fLogger(FairLogger::GetLogger())
27 , fDetList(0)
28 , fDetIter(0)
29 , fVerbose(1)
30 , fFSTrackMap()
31 , fFSTrackIter()
32 , fFSMovedIndex(-2)
33 , fFSFirstSecondary(-2)
34 , fFSNofSecondaries(0)
35{}
36
37// ----- Constructor with estimated array dimension --------------------
40 , fLogger(FairLogger::GetLogger())
41 , fDetList(0)
42 , fDetIter(0)
43 , fVerbose(1)
44 , fFSTrackMap()
45 , fFSTrackIter()
46 , fFSMovedIndex(-2)
47 , fFSFirstSecondary(-2)
48 , fFSNofSecondaries(0)
49{}
50
52
54 : TVirtualMCStack(rhs)
55 , fLogger(FairLogger::GetLogger())
56 , fDetList(rhs.fDetList)
57 , fDetIter(0)
58 , fVerbose(rhs.fVerbose)
59{}
60
62{
63 // check assignment to self
64 if (this == &rhs)
65 return *this;
66
67 // base class assignment
68 TVirtualMCStack::operator=(rhs);
69
70 // assignment oiperator
71 fLogger = 0;
72 fDetList = 0;
73 fDetIter = 0;
74 fVerbose = rhs.fVerbose;
75
76 return *this;
77}
78
79void FairGenericStack::SetDetArrayList(TRefArray* detArray)
80{
81 fDetList = detArray;
82 if (fDetList != 0) {
83 fDetIter = fDetList->MakeIterator();
84 }
85}
86
88{
89 Fatal("CloneStack", "Has to be overriden in multi-threading applications.");
90 return 0;
91}
92
94 Double_t yy,
95 Double_t zz,
96 Double_t tt,
97 Double_t px,
98 Double_t py,
99 Double_t pz,
100 Double_t en)
101{
102 TLorentzVector curPos;
103 TVirtualMC::GetMC()->TrackPosition(curPos);
104 LOG(debug) << "track is in " << curPos.X() << "," << curPos.Y() << "," << curPos.Z() << ", moving to " << xx << ","
105 << yy << "," << zz;
106 TString curVolName(TVirtualMC::GetMC()->CurrentVolName());
107 TString targetVolName(gGeoManager->FindNode(xx, yy, zz)->GetVolume()->GetName());
108 if (curVolName.EqualTo(targetVolName)) {
109 LOG(fatal) << "FairStack::FastSimMoveParticleTo(" << xx << "," << yy << "," << zz << ": " << curVolName << " = "
110 << targetVolName << ") crashes the simulation.";
111 } else {
112 LOG(debug) << "gMC says track is in \"" << curVolName << "\" moving particle to \"" << targetVolName << "\".";
113 }
114
115 Int_t tobedone = 1;
116 Int_t parent = 0; // do not store it as mother
117 Int_t pdg = TVirtualMC::GetMC()->TrackPid();
118 Double_t polx = 0.;
119 Double_t poly = 0.;
120 Double_t polz = 0.;
121 TMCProcess proc = kPPrimary; // not important, the track will not be saved
122 Int_t ntr = 0; // Track number; to be filled by the stack
123 Int_t status = 0; // not important, the track will not be saved
124 Double_t weight = 0.;
125
126 PushTrack(tobedone, parent, pdg, px, py, pz, en, xx, yy, zz, tt, polx, poly, polz, proc, ntr, weight, status, -1);
127 fFSMovedIndex = GetListOfParticles()->GetEntries() - 1;
128 Int_t trackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber();
129 fFSTrackIter = fFSTrackMap.find(trackID); // check if this track is not already created by FastSimulation
130 if (fFSTrackIter != fFSTrackMap.end()) // indeed the track has been created by the FastSimulation mechanism
131 trackID = fFSTrackIter->second; // use the ID of the original track
132 fFSTrackMap[ntr] = trackID;
133
134 LOG(debug) << "FairStack::FastSimMoveParticleTo() created track number " << ntr << " to replace track number "
135 << trackID;
136
137 if (strcmp(TVirtualMC::GetMC()->GetName(), "TGeant3TGeo") == 0) {
138 TVirtualMC::GetMC()->StopTrack();
139 }
140}
141
143{
144 if (TVirtualMC::GetMC()->IsTrackStop())
145 LOG(fatal) << "FairStack::FastSimStopParticle() tries to stop particle that was probably moved!";
146 fFSMovedIndex = -1;
147 TVirtualMC::GetMC()->StopTrack();
148}
149
151 Int_t pdgCode,
152 Double_t xx,
153 Double_t yy,
154 Double_t zz,
155 Double_t tt,
156 Double_t px,
157 Double_t py,
158 Double_t pz,
159 Double_t en,
160 Double_t polx,
161 Double_t poly,
162 Double_t polz,
163 TMCProcess proc,
164 Double_t weight,
165 Int_t is)
166{
167 Int_t tobedone = 1;
168
169 Int_t ntr = 0; // Track number; to be filled by the stack
170 PushTrack(tobedone, parentID, pdgCode, px, py, pz, en, xx, yy, zz, tt, polx, poly, polz, proc, ntr, weight, is, -1);
171 if (fFSNofSecondaries == 0)
172 fFSFirstSecondary = GetListOfParticles()->GetEntries() - 1;
174}
175
std::ostringstream debug
ClassImp(FairGenericStack)
std::map< Int_t, Int_t > fFSTrackMap
virtual void FastSimMoveParticleTo(Double_t xx, Double_t yy, Double_t zz, Double_t tt, Double_t px, Double_t py, Double_t pz, Double_t en)
virtual void FastSimPushSecondary(Int_t parentID, Int_t pdgCode, Double_t xx, Double_t yy, Double_t zz, Double_t tt, Double_t px, Double_t py, Double_t pz, Double_t en, Double_t polx, Double_t poly, Double_t polz, TMCProcess proc, Double_t weight, Int_t is)
virtual void FastSimStopParticle()
std::map< Int_t, Int_t >::iterator fFSTrackIter
FairGenericStack & operator=(const FairGenericStack &)
void SetDetArrayList(TRefArray *detArray)
virtual TClonesArray * GetListOfParticles()
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, Int_t secondparentID)=0
virtual FairGenericStack * CloneStack() const
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"