]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliStackingAction.cxx
Decay_t moved to AliDecayer.h
[u/mrichter/AliRoot.git] / AliGeant4 / AliStackingAction.cxx
1 // $Id$
2 // Category: event
3 //
4 // See the class description in the header file.
5
6 #include "AliStackingAction.h"
7 #include "AliStackingActionMessenger.h"
8 #include "AliTrackingAction.h"
9 #include "AliGlobals.h"
10
11 #include <G4Track.hh>
12 #include <G4TrackStack.hh>
13 #include <G4StackedTrack.hh>
14 #include <G4StackManager.hh>
15 #include <G4NeutrinoE.hh>
16 #include <G4NeutrinoMu.hh>
17 #include <G4NeutrinoTau.hh>
18 #include <G4AntiNeutrinoE.hh>
19 #include <G4AntiNeutrinoMu.hh>
20 #include <G4AntiNeutrinoTau.hh>
21
22 AliStackingAction::AliStackingAction()
23   : fStage(0), 
24     fVerboseLevel(0),
25     fSavePrimaries(true),
26     fTrackingAction(0) 
27 {
28 // 
29   fPrimaryStack = new G4TrackStack();
30   fMessenger = new AliStackingActionMessenger(this);
31 }
32
33 AliStackingAction::AliStackingAction(const AliStackingAction& right) {
34 //
35   AliGlobals::Exception("AliStackingAction is protected from copying.");
36 }
37
38 AliStackingAction::~AliStackingAction() {
39 // 
40   delete fPrimaryStack;
41   delete fMessenger; 
42 }
43
44 // operators
45
46 AliStackingAction& 
47 AliStackingAction::operator=(const AliStackingAction &right)
48 {
49   // check assignement to self
50   if (this == &right) return *this;
51   
52   AliGlobals::Exception("AliStackingAction is protected from assigning.");
53
54   return *this;
55 }
56
57 // public methods
58
59 G4ClassificationOfNewTrack 
60 AliStackingAction::ClassifyNewTrack(const G4Track* track)
61 {
62 // Classifies the new track.
63 // ---
64
65   G4ClassificationOfNewTrack classification;
66   if (fStage == 0) { 
67     // move all primaries to PrimaryStack
68     G4Track* nonconstTrack = (G4Track*)track;
69     G4StackedTrack* newTrack = new G4StackedTrack(nonconstTrack);
70     fPrimaryStack->PushToStack(newTrack);  
71     classification = fPostpone;
72
73     // save primary particle info
74     // (secondary particles are stored 
75     //  by AlTrackingAction::PreUserTrackingAction() method)
76     if (fSavePrimaries)
77       fTrackingAction->SaveTrack(track);
78   }  
79   else {
80      // exclude neutrinos
81     G4ParticleDefinition* particle = track->GetDefinition();
82     if( particle == G4NeutrinoE::NeutrinoEDefinition() ||
83         particle == G4NeutrinoMu::NeutrinoMuDefinition() ||
84         particle == G4NeutrinoTau::NeutrinoTauDefinition() ||
85         particle == G4AntiNeutrinoE::AntiNeutrinoEDefinition() ||
86         particle == G4AntiNeutrinoMu::AntiNeutrinoMuDefinition() ||
87         particle == G4AntiNeutrinoTau::AntiNeutrinoTauDefinition()) {
88
89         return fKill;    
90      }  
91      
92      G4int parentID = track->GetParentID();
93      if (parentID ==0) { 
94         return fUrgent; 
95      }
96      else { 
97         return fWaiting; 
98      }
99   }
100   return classification;
101 }
102
103 void AliStackingAction::NewStage()
104 {
105 // Called by G4 kernel at the new stage of stacking.
106 // ---
107
108   fStage++;
109   if (fVerboseLevel>0) 
110   {
111     G4cout << "AliStackingAction::NewStage " << fStage 
112            << " has been started." << G4endl;
113   }
114
115   G4int nofUrgent = stackManager->GetNUrgentTrack();
116   if (nofUrgent == 0)
117   {
118     G4int nofPrimary = fPrimaryStack->GetNTrack();
119     if (nofPrimary>0)
120     { 
121        G4StackedTrack* stackedTrack
122          = fPrimaryStack->PopFromStack();
123        G4Track* primaryTrack
124          = stackedTrack->GetTrack();
125        delete stackedTrack;
126        stackManager->PushOneTrack(primaryTrack);
127      }
128   }
129 }
130     
131 void AliStackingAction::ClearPrimaryStack()
132 {
133 // Clears the primary stack.
134 // ---
135
136   stackManager->ClearPostponeStack();
137 }
138
139 void AliStackingAction::PrepareNewEvent()
140 {
141 // Called by G4 kernel at the beginning of event.
142 // ---
143
144   fStage = 0;
145   ClearPrimaryStack();
146   fTrackingAction = AliTrackingAction::Instance();
147   fSavePrimaries = fTrackingAction->GetSavePrimaries();
148 }
149
150