4 // Author: I. Hrivnacova
6 // Class AliTrackingAction
7 // -----------------------
8 // See the class description in the header file.
10 #include "AliTrackingAction.h"
11 #include "AliTrackInformation.h"
13 #include "AliGlobals.h"
14 #include "TG4StepManager.h"
15 #include "TG4PhysicsManager.h"
16 #include "TG4ParticlesManager.h"
19 #include <G4TrackVector.hh>
20 #include <G4VUserTrackInformation.hh>
21 #include <G4TrackingManager.hh>
22 #include <G4SteppingManager.hh>
23 #include <G4UImanager.hh>
25 // static data members
26 AliTrackingAction* AliTrackingAction::fgInstance = 0;
28 //_____________________________________________________________________________
29 AliTrackingAction::AliTrackingAction()
30 : AliVerbose("trackingAction",2),
33 fNewVerboseTrackID(-1),
40 AliGlobals::Exception("AliTrackingAction constructed twice.");
46 //_____________________________________________________________________________
47 AliTrackingAction::AliTrackingAction(const AliTrackingAction& right)
48 : AliVerbose("trackingAction"),
51 AliGlobals::Exception("AliTrackingAction is protected from copying.");
54 //_____________________________________________________________________________
55 AliTrackingAction::~AliTrackingAction() {
61 //_____________________________________________________________________________
63 AliTrackingAction::operator=(const AliTrackingAction &right)
65 // check assignement to self
66 if (this == &right) return *this;
68 AliGlobals::Exception("AliTrackingAction is protected from assigning.");
75 //_____________________________________________________________________________
76 AliTrackInformation* AliTrackingAction::GetTrackInformation(
78 const G4String& method) const
80 // Returns user track information.
84 G4VUserTrackInformation* trackInfo = track->GetUserInformation();
85 if (!trackInfo) return 0;
87 AliTrackInformation* aliTrackInfo
88 = dynamic_cast<AliTrackInformation*>(trackInfo);
90 G4String text = "AliTrackingAction::" + method + ":\n";
91 text = text + " Unknown track information type";
92 AliGlobals::Exception(text);
97 return (AliTrackInformation*)track->GetUserInformation();
103 //_____________________________________________________________________________
104 void AliTrackingAction::PrepareNewEvent()
106 // Called by G4 kernel at the beginning of event.
111 // set g4 stepping manager pointer
112 TG4StepManager* stepManager = TG4StepManager::Instance();
113 stepManager->SetSteppingManager(fpTrackingManager->GetSteppingManager());
116 //_____________________________________________________________________________
117 void AliTrackingAction::PreTrackingAction(const G4Track* aTrack)
119 // Called by G4 kernel before starting tracking.
122 // track index in the particles array
123 G4int trackID = aTrack->GetTrackID();
124 G4int parentID = aTrack->GetParentID();
127 // in AliRoot (from V3.0) track numbering starts from 0
128 trackIndex = trackID-1;
131 trackIndex = gAlice->GetNtrack();
134 // set track index to track information
135 AliTrackInformation* trackInfo
136 = GetTrackInformation(aTrack, "PreTrackingAction");
138 // create track information and set it to G4Track
139 // if it does not yet exist
140 trackInfo = new AliTrackInformation(trackIndex);
141 fpTrackingManager->SetUserTrackInformation(trackInfo);
142 // the track information is deleted together with its
146 trackInfo->SetTrackParticleID(trackIndex);
148 // set current track number
149 gAlice->SetCurrentTrack(trackIndex);
152 // finish previous primary track
153 FinishPrimaryTrack();
154 fPrimaryTrackID = aTrack->GetTrackID();
156 // begin this primary track
157 gAlice->BeginPrimary();
160 // save secondary particles info
165 if (trackID == fNewVerboseTrackID) {
166 G4String command = "/tracking/verbose ";
167 AliGlobals::AppendNumberToString(command, fNewVerboseLevel);
168 G4UImanager::GetUIpointer()->ApplyCommand(command);
171 // aliroot pre track actions
175 //_____________________________________________________________________________
176 void AliTrackingAction::PostTrackingAction(const G4Track* aTrack)
178 // Called by G4 kernel after finishing tracking.
183 // set parent track particle index to all secondary tracks
184 G4TrackVector* secondaryTracks
185 = fpTrackingManager->GetSteppingManager()->GetSecondary();
186 if (secondaryTracks){
188 for (i=0; i<secondaryTracks->size(); i++) {
189 G4Track* track = (*secondaryTracks)[i];
191 if (track->GetUserInformation()) {
192 // this should never happen
193 G4String text = "AliTrackingAction::PostTrackingAction:\n";
194 text = text + " Inconsistent track information.";
195 AliGlobals::Exception(text);
198 // get parent track index
199 AliTrackInformation* aliParentInfo
200 = GetTrackInformation(aTrack, "PostTrackingAction");
201 G4int parentParticleID
202 = aliParentInfo->GetTrackParticleID();
204 // create track information and set it to the G4Track
205 AliTrackInformation* trackInfo
206 = new AliTrackInformation(-1, parentParticleID);
207 track->SetUserInformation(trackInfo);
208 // the track information is deleted together with its
213 // aliroot post track actions
217 //_____________________________________________________________________________
218 void AliTrackingAction::FinishPrimaryTrack()
220 // Calls AliRun::PurifyKine and fills trees of hits
221 // after finishing tracking of each primary track.
222 // !! This method has to be also called from AlEventAction::EndOfEventAction()
223 // for storing the last primary track of the current event.
226 if (fPrimaryTrackID>0) {
229 if (VerboseLevel() == 3) {
230 G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
232 else if (VerboseLevel() == 2 && fPrimaryTrackID % 10 == 0 ) {
233 G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
235 else if (VerboseLevel() == 1 && fPrimaryTrackID % 100 == 0 ) {
236 G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
239 // aliroot finish primary track
240 gAlice->FinishPrimary();
245 //_____________________________________________________________________________
246 void AliTrackingAction::SaveTrack(const G4Track* track)
248 // Get all needed parameters from G4track and pass them
249 // to AliRun::SetTrack() that creates corresponding TParticle
250 // in the AliRun::fParticles array.
253 // parent particle index
254 G4int parentID = track->GetParentID();
261 = GetTrackInformation(track,"SaveTrack")->GetParentParticleID();
264 //G4cout << "SaveTrack: TrackID = " << track->GetTrackID()
265 // << " Parent ID = " << track->GetParentID()
266 // << " Index = " << gAlice->CurrentTrack()
267 // << " Parent Index = " << motherIndex
272 = TG4ParticlesManager::Instance()
273 ->GetPDGEncodingFast(track->GetDefinition());
276 G4ThreeVector momentum = track->GetMomentum();
278 G4double px = momentum.x()/GeV;
279 G4double py = momentum.y()/GeV;
280 G4double pz = momentum.z()/GeV;
281 G4double e = track->GetTotalEnergy()/GeV;
283 G4ThreeVector position = track->GetPosition();
284 G4double vx = position.x()/cm;
285 G4double vy = position.y()/cm;
286 G4double vz = position.z()/cm;
287 // time of production - check if ekvivalent with G4
288 G4double t = track->GetGlobalTime();
290 G4ThreeVector polarization = track->GetPolarization();
291 G4double polX = polarization.x();
292 G4double polY = polarization.y();
293 G4double polZ = polarization.z();
295 // production process
296 AliMCProcess mcProcess;
297 const G4VProcess* kpProcess = track->GetCreatorProcess();
299 mcProcess = kPPrimary;
302 mcProcess = TG4PhysicsManager::Instance()->GetMCProcess(kpProcess);
303 // distinguish kPDeltaRay from kPEnergyLoss
304 if (mcProcess == kPEnergyLoss) mcProcess = kPDeltaRay;
309 gAlice->SetTrack(1, motherIndex, pdg, px, py, pz, e, vx, vy, vz, t,
310 polX, polY, polZ, mcProcess, ntr);
314 //_____________________________________________________________________________
315 void AliTrackingAction::SetNewVerboseLevel(G4int level)
317 // Set the new verbose level that will be set when the track with
318 // specified track ID (fNewVerboseTrackID) starts tracking.
321 fNewVerboseLevel = level;
324 //_____________________________________________________________________________
325 void AliTrackingAction::SetNewVerboseTrackID(G4int trackID)
327 // Set the trackID for which the new verbose level (fNewVerboseLevel)
331 fNewVerboseTrackID = trackID;