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