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