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