]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: event | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "AliTrackingAction.h" | |
7 | #include "AliTrackingActionMessenger.h" | |
4240c1e8 | 8 | #include "AliTrackInformation.h" |
676fb573 | 9 | #include "AliRun.h" |
10 | #include "AliGlobals.h" | |
11 | #include "TG4StepManager.h" | |
c8bc1274 | 12 | #include "TG4PhysicsManager.h" |
676fb573 | 13 | |
676fb573 | 14 | #include <G4Track.hh> |
4240c1e8 | 15 | #include <G4TrackVector.hh> |
16 | #include <G4VUserTrackInformation.hh> | |
17 | #include <G4TrackingManager.hh> | |
18 | #include <G4SteppingManager.hh> | |
676fb573 | 19 | |
4240c1e8 | 20 | /* |
71c03be6 | 21 | #include <TTree.h> |
676fb573 | 22 | #include <TParticle.h> |
c97337f9 | 23 | #include <TClonesArray.h> |
4240c1e8 | 24 | */ |
676fb573 | 25 | |
26 | // static data members | |
27 | AliTrackingAction* AliTrackingAction::fgInstance = 0; | |
28 | ||
676fb573 | 29 | AliTrackingAction::AliTrackingAction() |
4240c1e8 | 30 | : fPrimaryTrackID(0), |
676fb573 | 31 | fVerboseLevel(2), |
32 | fSavePrimaries(true), | |
4240c1e8 | 33 | fTrackCounter(0) |
676fb573 | 34 | { |
35 | // | |
36 | if (fgInstance) { | |
37 | AliGlobals::Exception("AliTrackingAction constructed twice."); | |
38 | } | |
39 | ||
40 | fMessenger = new AliTrackingActionMessenger(this); | |
41 | fgInstance = this; | |
42 | } | |
43 | ||
44 | AliTrackingAction::AliTrackingAction(const AliTrackingAction& right) { | |
45 | // | |
46 | AliGlobals::Exception("AliTrackingAction is protected from copying."); | |
47 | } | |
48 | ||
49 | AliTrackingAction::~AliTrackingAction() { | |
50 | // | |
51 | delete fMessenger; | |
52 | } | |
53 | ||
54 | // operators | |
55 | ||
56 | AliTrackingAction& | |
57 | AliTrackingAction::operator=(const AliTrackingAction &right) | |
58 | { | |
59 | // check assignement to self | |
60 | if (this == &right) return *this; | |
61 | ||
62 | AliGlobals::Exception("AliTrackingAction is protected from assigning."); | |
63 | ||
64 | return *this; | |
65 | } | |
66 | ||
4240c1e8 | 67 | // private methods |
68 | ||
69 | AliTrackInformation* AliTrackingAction::GetTrackInformation( | |
70 | const G4Track* track, | |
71 | const G4String& method) const | |
72 | { | |
73 | // Returns user track information. | |
74 | // --- | |
75 | ||
76 | G4VUserTrackInformation* trackInfo = track->GetUserInformation(); | |
77 | if (!trackInfo) return 0; | |
78 | ||
79 | AliTrackInformation* aliTrackInfo | |
80 | = dynamic_cast<AliTrackInformation*>(trackInfo); | |
81 | if (!aliTrackInfo) { | |
82 | G4String text = "AliTrackingAction::" + method + ":\n"; | |
83 | text = text + " Unknown track information type"; | |
84 | AliGlobals::Exception(text); | |
85 | } | |
86 | ||
87 | return aliTrackInfo; | |
88 | } | |
89 | ||
676fb573 | 90 | // public methods |
91 | ||
92 | void AliTrackingAction::PrepareNewEvent() | |
93 | { | |
94 | // Called by G4 kernel at the beginning of event. | |
95 | // --- | |
96 | ||
3bfabcfc | 97 | fTrackCounter = 0; |
98 | ||
676fb573 | 99 | // set g4 stepping manager pointer |
4240c1e8 | 100 | TG4StepManager* stepManager = TG4StepManager::Instance(); |
101 | stepManager->SetSteppingManager(fpTrackingManager->GetSteppingManager()); | |
676fb573 | 102 | } |
103 | ||
9bcb6317 | 104 | void AliTrackingAction::PreTrackingAction(const G4Track* aTrack) |
676fb573 | 105 | { |
106 | // Called by G4 kernel before starting tracking. | |
107 | // --- | |
108 | ||
676fb573 | 109 | // track index in the particles array |
110 | G4int trackID = aTrack->GetTrackID(); | |
111 | G4int parentID = aTrack->GetParentID(); | |
112 | Int_t trackIndex; | |
113 | if (parentID==0) { | |
4240c1e8 | 114 | // in AliRoot (from V3.0) track numbering starts from 0 |
115 | trackIndex = trackID-1; | |
676fb573 | 116 | } |
117 | else { | |
4240c1e8 | 118 | trackIndex = gAlice->GetNtrack(); |
676fb573 | 119 | } |
4240c1e8 | 120 | |
121 | // set track index to track information | |
122 | AliTrackInformation* trackInfo | |
123 | = GetTrackInformation(aTrack, "PreTrackingAction"); | |
124 | if (!trackInfo) { | |
125 | // create track information and set it to G4Track | |
126 | // if it does not yet exist | |
127 | trackInfo = new AliTrackInformation(trackIndex); | |
128 | fpTrackingManager->SetUserTrackInformation(trackInfo); | |
129 | // the track information is deleted together with its | |
130 | // G4Track object | |
131 | } | |
132 | else | |
133 | trackInfo->SetTrackParticleID(trackIndex); | |
676fb573 | 134 | |
4240c1e8 | 135 | // set current track number |
136 | gAlice->SetCurrentTrack(trackIndex); | |
676fb573 | 137 | |
138 | if (parentID == 0) { | |
4240c1e8 | 139 | // finish previous primary track |
140 | FinishPrimaryTrack(); | |
676fb573 | 141 | fPrimaryTrackID = aTrack->GetTrackID(); |
142 | } | |
143 | else { | |
144 | // save secondary particles info | |
4240c1e8 | 145 | SaveTrack(aTrack); |
9bcb6317 | 146 | } |
b17c5755 | 147 | |
4240c1e8 | 148 | // aliroot pre track actions |
b17c5755 | 149 | gAlice->PreTrack(); |
676fb573 | 150 | } |
151 | ||
9bcb6317 | 152 | void AliTrackingAction::PostTrackingAction(const G4Track* aTrack) |
676fb573 | 153 | { |
154 | // Called by G4 kernel after finishing tracking. | |
155 | // --- | |
156 | ||
3bfabcfc | 157 | fTrackCounter++; |
4240c1e8 | 158 | |
159 | // set parent track particle index to all secondary tracks | |
160 | G4TrackVector* secondaryTracks | |
161 | = fpTrackingManager->GetSteppingManager()->GetSecondary(); | |
162 | if (secondaryTracks){ | |
163 | G4int i; | |
164 | for (i=0; i<secondaryTracks->entries(); i++) { | |
165 | G4Track* track = (*secondaryTracks)[i]; | |
166 | ||
167 | if (track->GetUserInformation()) { | |
168 | // this should never happen | |
169 | G4String text = "AliTrackingAction::PostTrackingAction:\n"; | |
170 | text = text + " Inconsistent track information."; | |
171 | AliGlobals::Exception(text); | |
172 | } | |
173 | ||
174 | // get parent track index | |
175 | AliTrackInformation* aliParentInfo | |
176 | = GetTrackInformation(aTrack, "PostTrackingAction"); | |
177 | G4int parentParticleID | |
178 | = aliParentInfo->GetTrackParticleID(); | |
179 | ||
180 | // create track information and set it to the G4Track | |
181 | AliTrackInformation* trackInfo | |
182 | = new AliTrackInformation(-1, parentParticleID); | |
183 | track->SetUserInformation(trackInfo); | |
184 | // the track information is deleted together with its | |
185 | // G4Track object | |
186 | } | |
187 | } | |
188 | ||
189 | // aliroot post track actions | |
b17c5755 | 190 | gAlice->PostTrack(); |
676fb573 | 191 | } |
192 | ||
4240c1e8 | 193 | void AliTrackingAction::FinishPrimaryTrack() |
676fb573 | 194 | { |
195 | // Calls AliRun::PurifyKine and fills trees of hits | |
196 | // after finishing tracking of each primary track. | |
197 | // !! This method has to be also called from AlEventAction::EndOfEventAction() | |
198 | // for storing the last primary track of the current event. | |
199 | // --- | |
200 | ||
4240c1e8 | 201 | if (fPrimaryTrackID>0) { |
202 | ||
203 | // verbose | |
204 | if (fVerboseLevel == 3) { | |
205 | G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl; | |
206 | } | |
207 | else if ( fVerboseLevel == 2 && fPrimaryTrackID % 10 == 0 ) { | |
208 | G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl; | |
209 | } | |
210 | else if ( fVerboseLevel == 1 && fPrimaryTrackID % 100 == 0 ) { | |
211 | G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl; | |
212 | } | |
213 | ||
214 | // aliroot finish primary track | |
215 | gAlice->FinishPrimary(); | |
216 | } | |
217 | fPrimaryTrackID = 0; | |
676fb573 | 218 | } |
219 | ||
4240c1e8 | 220 | void AliTrackingAction::SaveTrack(const G4Track* track) |
676fb573 | 221 | { |
4240c1e8 | 222 | // Get all needed parameters from G4track and pass them |
223 | // to AliRun::SetTrack() that creates corresponding TParticle | |
224 | // in the AliRun::fParticles array. | |
676fb573 | 225 | // ---- |
226 | ||
4240c1e8 | 227 | // parent particle index |
676fb573 | 228 | G4int parentID = track->GetParentID(); |
4240c1e8 | 229 | G4int motherIndex; |
676fb573 | 230 | if (parentID == 0) { |
4240c1e8 | 231 | motherIndex = -1; |
676fb573 | 232 | } |
233 | else { | |
4240c1e8 | 234 | motherIndex |
235 | = GetTrackInformation(track,"SaveTrack")->GetParentParticleID(); | |
236 | } | |
676fb573 | 237 | |
4240c1e8 | 238 | //G4cout << "SaveTrack: TrackID = " << track->GetTrackID() |
239 | // << " Parent ID = " << track->GetParentID() | |
240 | // << " Index = " << gAlice->CurrentTrack() | |
241 | // << " Parent Index = " << motherIndex | |
242 | // << G4endl; | |
243 | ||
244 | // PDG code | |
676fb573 | 245 | G4int pdg = track->GetDefinition()->GetPDGEncoding(); |
246 | ||
4240c1e8 | 247 | // track kinematics |
676fb573 | 248 | G4ThreeVector momentum = track->GetMomentum(); |
4240c1e8 | 249 | |
676fb573 | 250 | G4double px = momentum.x()/GeV; |
251 | G4double py = momentum.y()/GeV; | |
252 | G4double pz = momentum.z()/GeV; | |
253 | G4double e = track->GetTotalEnergy()/GeV; | |
254 | ||
255 | G4ThreeVector position = track->GetPosition(); | |
256 | G4double vx = position.x()/cm; | |
257 | G4double vy = position.y()/cm; | |
258 | G4double vz = position.z()/cm; | |
259 | // time of production - check if ekvivalent with G4 | |
260 | G4double t = track->GetGlobalTime(); | |
261 | ||
262 | G4ThreeVector polarization = track->GetPolarization(); | |
263 | G4double polX = polarization.x(); | |
264 | G4double polY = polarization.y(); | |
265 | G4double polZ = polarization.z(); | |
266 | ||
4240c1e8 | 267 | // production process |
c8bc1274 | 268 | AliMCProcess mcProcess; |
269 | const G4VProcess* kpProcess = track->GetCreatorProcess(); | |
270 | if (!kpProcess) { | |
271 | mcProcess = kPPrimary; | |
272 | } | |
273 | else { | |
274 | TG4PhysicsManager* pPhysicsManager = TG4PhysicsManager::Instance(); | |
20aace74 | 275 | mcProcess = pPhysicsManager->GetMCProcess(kpProcess); |
c8bc1274 | 276 | // distinguish kPDeltaRay from kPEnergyLoss |
277 | if (mcProcess == kPEnergyLoss) mcProcess = kPDeltaRay; | |
278 | } | |
4240c1e8 | 279 | |
280 | G4int ntr; | |
281 | // create particle | |
282 | gAlice->SetTrack(1, motherIndex, pdg, px, py, pz, e, vx, vy, vz, t, | |
283 | polX, polY, polZ, mcProcess, ntr); | |
284 | ||
676fb573 | 285 | } |
286 |