// $Id$
// Category: event
//
+// Author: I. Hrivnacova
+//
+// Class AliTrackingAction
+// -----------------------
// See the class description in the header file.
#include "AliTrackingAction.h"
-#include "AliTrackingActionMessenger.h"
-#include "AliSensitiveDetector.h"
+#include "AliTrackInformation.h"
#include "AliRun.h"
#include "AliGlobals.h"
#include "TG4StepManager.h"
+#include "TG4PhysicsManager.h"
+#include "TG4ParticlesManager.h"
-#include <G4TrackingManager.hh>
#include <G4Track.hh>
-#include <G4Event.hh>
-#include <G4SDManager.hh>
-#include <G4VSensitiveDetector.hh>
-#include <G4VHitsCollection.hh>
-
-#include <TTree.h>
-#include <TParticle.h>
+#include <G4TrackVector.hh>
+#include <G4VUserTrackInformation.hh>
+#include <G4TrackingManager.hh>
+#include <G4SteppingManager.hh>
+#include <G4UImanager.hh>
// static data members
AliTrackingAction* AliTrackingAction::fgInstance = 0;
-// static methods
-AliTrackingAction* AliTrackingAction::Instance() {
-//
- return fgInstance;
-}
-
+//_____________________________________________________________________________
AliTrackingAction::AliTrackingAction()
- : fParticles(0),
+ : AliVerbose("trackingAction",2),
fPrimaryTrackID(0),
- fVerboseLevel(2),
+ fNewVerboseLevel(0),
+ fNewVerboseTrackID(-1),
fSavePrimaries(true),
- fPrimariesCounter(0),
- fParticlesCounter(0),
fTrackCounter(0),
- fLastParticleIndex(-1)
+ fMessenger(this)
{
//
if (fgInstance) {
AliGlobals::Exception("AliTrackingAction constructed twice.");
}
- fMessenger = new AliTrackingActionMessenger(this);
fgInstance = this;
}
-AliTrackingAction::AliTrackingAction(const AliTrackingAction& right) {
+//_____________________________________________________________________________
+AliTrackingAction::AliTrackingAction(const AliTrackingAction& right)
+ : AliVerbose("trackingAction"),
+ fMessenger(this) {
//
AliGlobals::Exception("AliTrackingAction is protected from copying.");
}
+//_____________________________________________________________________________
AliTrackingAction::~AliTrackingAction() {
//
- delete fMessenger;
}
// operators
+//_____________________________________________________________________________
AliTrackingAction&
AliTrackingAction::operator=(const AliTrackingAction &right)
{
return *this;
}
+// private methods
+
+//_____________________________________________________________________________
+AliTrackInformation* AliTrackingAction::GetTrackInformation(
+ const G4Track* track,
+ const G4String& method) const
+{
+// Returns user track information.
+// ---
+
+#ifdef TGEANT4_DEBUG
+ G4VUserTrackInformation* trackInfo = track->GetUserInformation();
+ if (!trackInfo) return 0;
+
+ AliTrackInformation* aliTrackInfo
+ = dynamic_cast<AliTrackInformation*>(trackInfo);
+ if (!aliTrackInfo) {
+ G4String text = "AliTrackingAction::" + method + ":\n";
+ text = text + " Unknown track information type";
+ AliGlobals::Exception(text);
+ }
+
+ return aliTrackInfo;
+#else
+ return (AliTrackInformation*)track->GetUserInformation();
+#endif
+}
+
// public methods
+//_____________________________________________________________________________
void AliTrackingAction::PrepareNewEvent()
{
// Called by G4 kernel at the beginning of event.
fTrackCounter = 0;
- // aliroot
- if (!fParticles) fParticles = gAlice->Particles();
-
- // set the particles and primaries counter to the
- // number of tracks already stored in AliRun::fParticles
- // (fParticles can already contain primary particles
- // saved by AliGenerator)
- G4int nofTracks = gAlice->GetNtrack();
- fPrimariesCounter = nofTracks;
- fParticlesCounter = nofTracks;
- fLastParticleIndex = nofTracks-1;
-
// set g4 stepping manager pointer
- G4SteppingManager* pG4StepManager
- = fpTrackingManager->GetSteppingManager();
- TG4StepManager* pStepManager = TG4StepManager::Instance();
- pStepManager->SetSteppingManager(pG4StepManager);
+ TG4StepManager* stepManager = TG4StepManager::Instance();
+ stepManager->SetSteppingManager(fpTrackingManager->GetSteppingManager());
}
+//_____________________________________________________________________________
void AliTrackingAction::PreTrackingAction(const G4Track* aTrack)
{
// Called by G4 kernel before starting tracking.
// ---
- // aliroot
// track index in the particles array
G4int trackID = aTrack->GetTrackID();
G4int parentID = aTrack->GetParentID();
Int_t trackIndex;
if (parentID==0) {
- trackIndex = trackID;
+ // in AliRoot (from V3.0) track numbering starts from 0
+ trackIndex = trackID-1;
}
else {
- trackIndex = GetNofSavedTracks();
+ trackIndex = gAlice->GetNtrack();
+ }
+
+ // set track index to track information
+ AliTrackInformation* trackInfo
+ = GetTrackInformation(aTrack, "PreTrackingAction");
+ if (!trackInfo) {
+ // create track information and set it to G4Track
+ // if it does not yet exist
+ trackInfo = new AliTrackInformation(trackIndex);
+ fpTrackingManager->SetUserTrackInformation(trackInfo);
+ // the track information is deleted together with its
+ // G4Track object
}
+ else
+ trackInfo->SetTrackParticleID(trackIndex);
- // in AliRoot (from V3.0) track numbering starts from 0
- gAlice->SetCurrentTrack(--trackIndex);
+ // set current track number
+ gAlice->SetCurrentTrack(trackIndex);
if (parentID == 0) {
- // save primary track
- SaveAndDestroyTrack();
+ // finish previous primary track
+ FinishPrimaryTrack();
fPrimaryTrackID = aTrack->GetTrackID();
+
+ // begin this primary track
+ gAlice->BeginPrimary();
}
else {
// save secondary particles info
- // improve this later with retrieving the generation process
- // (primary particles are stored
- // by AlStackingAction in ClassifyNewTrack() method)
- G4String origin = "secondary";
- SaveParticle(aTrack, origin);
+ SaveTrack(aTrack);
}
+
+ // verbose
+ if (trackID == fNewVerboseTrackID) {
+ G4String command = "/tracking/verbose ";
+ AliGlobals::AppendNumberToString(command, fNewVerboseLevel);
+ G4UImanager::GetUIpointer()->ApplyCommand(command);
+ }
+
+ // aliroot pre track actions
+ gAlice->PreTrack();
}
+//_____________________________________________________________________________
void AliTrackingAction::PostTrackingAction(const G4Track* aTrack)
{
// Called by G4 kernel after finishing tracking.
// ---
fTrackCounter++;
+
+ // set parent track particle index to all secondary tracks
+ G4TrackVector* secondaryTracks
+ = fpTrackingManager->GetSteppingManager()->GetSecondary();
+ if (secondaryTracks){
+ G4int i;
+ for (i=0; i<secondaryTracks->size(); i++) {
+ G4Track* track = (*secondaryTracks)[i];
+
+ if (track->GetUserInformation()) {
+ // this should never happen
+ G4String text = "AliTrackingAction::PostTrackingAction:\n";
+ text = text + " Inconsistent track information.";
+ AliGlobals::Exception(text);
+ }
+
+ // get parent track index
+ AliTrackInformation* aliParentInfo
+ = GetTrackInformation(aTrack, "PostTrackingAction");
+ G4int parentParticleID
+ = aliParentInfo->GetTrackParticleID();
+
+ // create track information and set it to the G4Track
+ AliTrackInformation* trackInfo
+ = new AliTrackInformation(-1, parentParticleID);
+ track->SetUserInformation(trackInfo);
+ // the track information is deleted together with its
+ // G4Track object
+ }
+ }
+
+ // aliroot post track actions
+ gAlice->PostTrack();
}
-void AliTrackingAction::SaveAndDestroyTrack()
+//_____________________________________________________________________________
+void AliTrackingAction::FinishPrimaryTrack()
{
// Calls AliRun::PurifyKine and fills trees of hits
// after finishing tracking of each primary track.
// for storing the last primary track of the current event.
// ---
- if (fPrimaryTrackID>0)
- {
- if (fVerboseLevel == 3) {
- G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
- }
- else if ( fVerboseLevel == 2 && fPrimaryTrackID % 10 == 0 ) {
- G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
- }
- else if ( fVerboseLevel == 1 && fPrimaryTrackID % 100 == 0 ) {
- G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
- }
-
- // aliroot
- G4int lastSavedTrack
- = gAlice->PurifyKine(fLastParticleIndex, fParticlesCounter);
- G4int nofPuredSavedTracks
- = gAlice->GetNtrack();
- fLastParticleIndex = lastSavedTrack;
- fParticlesCounter = nofPuredSavedTracks;
-
- if(gAlice->TreeH()) gAlice->TreeH()->Fill();
- gAlice->ResetHits();
- }
- else {
- fLastParticleIndex = fPrimariesCounter-1;
- }
- fPrimaryTrackID = 0;
+ if (fPrimaryTrackID>0) {
+
+ // verbose
+ if (VerboseLevel() == 3) {
+ G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
+ }
+ else if (VerboseLevel() == 2 && fPrimaryTrackID % 10 == 0 ) {
+ G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
+ }
+ else if (VerboseLevel() == 1 && fPrimaryTrackID % 100 == 0 ) {
+ G4cout << "$$$ Primary track " << fPrimaryTrackID << G4endl;
+ }
+
+ // aliroot finish primary track
+ gAlice->FinishPrimary();
+ }
+ fPrimaryTrackID = 0;
}
-void AliTrackingAction::SaveParticle(const G4Track* track,
- G4String processName)
+//_____________________________________________________________________________
+void AliTrackingAction::SaveTrack(const G4Track* track)
{
-// Converts G4track to TParticle and saves it in AliRun::fParticles
-// array.
+// Get all needed parameters from G4track and pass them
+// to AliRun::SetTrack() that creates corresponding TParticle
+// in the AliRun::fParticles array.
// ----
- fParticlesCounter++;
-
- // track history
- G4int firstDaughter = -1;
- G4int lastDaughter = -1;
+ // parent particle index
G4int parentID = track->GetParentID();
- G4int motherIndex1;
- G4int motherIndex2 = -1;
+ G4int motherIndex;
if (parentID == 0) {
- motherIndex1 = -1;
- fPrimariesCounter++;
+ motherIndex = -1;
}
else {
- // set first/last child for already defined particles
- motherIndex1 = GetParticleIndex(parentID);
- // aliroot
- TParticle* parent
- = dynamic_cast<TParticle*>(fParticles->UncheckedAt(motherIndex1));
- if (parent) {
- if (parent->GetFirstDaughter()<0)
- parent->SetFirstDaughter(fParticlesCounter);
- parent->SetLastDaughter(fParticlesCounter);
- }
- else {
- AliGlobals::Exception(
- "AliTrackingAction::SaveParticle: Unknown particle type");
- }
- };
+ motherIndex
+ = GetTrackInformation(track,"SaveTrack")->GetParentParticleID();
+ }
- // ?? status of particle
- // temporarily used for storing trackID from G4
- G4int ks = track->GetTrackID();
-
- // particle type
- // is this G3 ekvivalent ?? - check
- G4int pdg = track->GetDefinition()->GetPDGEncoding();
-
- // track kinematics
+ //G4cout << "SaveTrack: TrackID = " << track->GetTrackID()
+ // << " Parent ID = " << track->GetParentID()
+ // << " Index = " << gAlice->CurrentTrack()
+ // << " Parent Index = " << motherIndex
+ // << G4endl;
+
+ // PDG code
+ G4int pdg
+ = TG4ParticlesManager::Instance()
+ ->GetPDGEncodingFast(track->GetDefinition());
+
+ // track kinematics
G4ThreeVector momentum = track->GetMomentum();
+
G4double px = momentum.x()/GeV;
G4double py = momentum.y()/GeV;
G4double pz = momentum.z()/GeV;
G4double polY = polarization.y();
G4double polZ = polarization.z();
- // aliroot
- TClonesArray& theCollectionRef = *fParticles;
- G4int nofParticles = theCollectionRef.GetEntriesFast();
- TParticle* particle
- = new(theCollectionRef[nofParticles])
- TParticle(pdg, ks, motherIndex1, motherIndex1,
- firstDaughter, lastDaughter, px, py, pz, e, vx, vy, vz, t);
- particle->SetPolarisation(polX, polY, polZ);
- particle->SetBit(kKeepBit, false);
+ // production process
+ AliMCProcess mcProcess;
+ const G4VProcess* kpProcess = track->GetCreatorProcess();
+ if (!kpProcess) {
+ mcProcess = kPPrimary;
+ }
+ else {
+ mcProcess = TG4PhysicsManager::Instance()->GetMCProcess(kpProcess);
+ // distinguish kPDeltaRay from kPEnergyLoss
+ if (mcProcess == kPEnergyLoss) mcProcess = kPDeltaRay;
+ }
+
+ G4int ntr;
+ // create particle
+ gAlice->SetTrack(1, motherIndex, pdg, px, py, pz, e, vx, vy, vz, t,
+ polX, polY, polZ, mcProcess, ntr);
+
}
-G4int AliTrackingAction::GetParticleIndex(G4int trackID)
-{
-// Converts the trackID into the index of the particle
-// in AliRun::fParticles array.
+//_____________________________________________________________________________
+void AliTrackingAction::SetNewVerboseLevel(G4int level)
+{
+// Set the new verbose level that will be set when the track with
+// specified track ID (fNewVerboseTrackID) starts tracking.
// ---
- if (trackID <= fPrimariesCounter) {
- return trackID-1;
- }
- else
- for (G4int i=fLastParticleIndex+1; i<fParticlesCounter; i++) {
- // aliroot
- TParticle* particle
- = (TParticle*)fParticles->UncheckedAt(i);
- if (trackID == particle->GetStatusCode()) return i;
- }
-
- AliGlobals::Exception("AliTrackingAction::GetParticleIndex() has failed.");
- return 0;
+ fNewVerboseLevel = level;
+}
+
+//_____________________________________________________________________________
+void AliTrackingAction::SetNewVerboseTrackID(G4int trackID)
+{
+// Set the trackID for which the new verbose level (fNewVerboseLevel)
+// will be applied.
+// ---
+
+ fNewVerboseTrackID = trackID;
}