Geant4  10.01.p03
CCalStackingAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
27 // File: CCalStackingAction.cc
28 // Description: Stacking action needed for the application
30 #include "CCalStackingAction.hh"
31 #include "G4StackManager.hh"
32 
33 #include "G4SystemOfUnits.hh"
34 #include "G4SDManager.hh"
35 #include "CCaloSD.hh"
36 #include "CCalSDList.hh"
37 #include "G4RunManager.hh"
38 #include "G4Navigator.hh"
39 
40 //#define debug
41 //#define ddebug
42 
44 
45 
47 
48 
50 
52  stage = firstStage;
53  nurgent = 0;
55 
56 }
57 
59 
60  isInitialized = true;
61 
63 #ifdef debug
64  G4cout << "CCalStackingAction look for " << numberOfSD
65  << " calorimeter-like SD" << G4endl;
66 #endif
67  int i = 0;
68  for (i=0; i<numberOfSD; i++) {
69  G4String theName(CCalSDList::getInstance()->getCaloSDName(i));
70  SDName[i] = theName;
71 #ifdef debug
72  G4cout << "Found SD name " << theName << G4endl;
73 #endif
74  theCaloSD[i] = 0;
75  }
76 
78  if (sd != 0) {
79 
80  for (i=0; i<numberOfSD; i++){
81 
83  if (aSD==0) {
84 #ifdef debug
85  G4cout << "CCalStackingAction::initialize: No SD with name " << SDName[i]
86  << " in this Setup " << G4endl;
87 #endif
88  } else {
89  theCaloSD[i] = dynamic_cast<CCaloSD*>(aSD);
90  theCaloSD[i]->SetPrimaryID(0);
91  }
92  }
93 #ifdef debug
94  G4cout << "CCalStackingAction::initialize: Could not get SD Manager !"
95  << G4endl;
96 #endif
97  }
98 
99 }
100 
102 
103  G4ClassificationOfNewTrack classification=fKill;
104  int parentID = aTrack->GetParentID();
105 #ifdef ddebug
106  G4TrackStatus status = aTrack->GetTrackStatus();
107  G4cout << "Classifying track " << aTrack->GetTrackID()
108  << " with status " << aTrack->GetTrackStatus() << G4endl;
109 #endif
110 
111  if (parentID < 0) {
112 #ifdef debug
113  G4cout << "Killing track " << aTrack->GetTrackID()
114  << " from previous event. Should not happen" << G4endl;
115  G4cout << "returning classification= " << classification << G4endl;
116 #endif
117  return classification= fKill;
118  }
119 
120  if (aTrack->GetDefinition()->GetParticleName() == "gamma" &&
121  aTrack->GetKineticEnergy() < 1.*eV) {
122 #ifdef debug
123  G4cout << "Kills particle " << aTrack->GetDefinition()->GetParticleName()
124  << " of energy " << aTrack->GetKineticEnergy()/MeV << " MeV"
125  << G4endl;
126 #endif
127  return classification= fKill;
128  }
129 
130  if (stage<end) {
134  if (parentID == 0 ) {
135  if ( nurgent == 0) {
136  nurgent++;
137  classification = fUrgent;
138  setPrimaryID(aTrack->GetTrackID());
139  }
140  else classification = fWaiting;
141  }
142 
146 
147  if (parentID > 0) {
148  if (acceptSecondaries == 1) {
149  if (trackStartsInCalo(const_cast<G4Track *>(aTrack))!=0 )
150  classification = fUrgent;
151  else
152  classification = fWaiting;
153  } else {
154  if(nurgent == 0){
155  nurgent++;
156  classification = fUrgent;
157  setPrimaryID(aTrack->GetTrackID());
158  } else
159  classification = fWaiting;
160  }
161  }
162 
163 
164  } else
165  classification = G4UserStackingAction::ClassifyNewTrack(aTrack);
166 
167 #ifdef ddebug
168  G4cout << " returning classification= " << classification
169  << " for track "<< aTrack->GetTrackID() << G4endl;
170 #endif
171  return classification;
172 
173 }
174 
175 
177 
178 #ifdef ddebug
179  G4cout << "In NewStage with stage = " << stage << G4endl;
180 #endif
181  if (stage <end) {
182  nurgent = 0;
183  setPrimaryID(0);
184  acceptSecondaries = 0;
186  acceptSecondaries = 1;
187  if (stackManager->GetNUrgentTrack() == 0) {
188  stage = stageLevel(stage+1);
189  }
190 
191  }
192 }
193 
195 
202 
203  return true;
204 }
205 
207 
208  for (int i=0; i<numberOfSD; i++){
209  if(theCaloSD[i] != 0)theCaloSD[i]->SetPrimaryID(id);
210  }
211 
212 }
G4ParticleDefinition * GetDefinition() const
G4int GetParentID() const
static const double MeV
Definition: G4SIunits.hh:193
G4String SDName[maxNumberOfSD]
static CCalSDList * getInstance()
Definition: CCalSDList.cc:37
G4TrackStatus GetTrackStatus() const
CCaloSD * theCaloSD[maxNumberOfSD]
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4int GetNUrgentTrack() const
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
G4double GetKineticEnergy() const
G4GLOB_DLL std::ostream G4cout
void SetPrimaryID(int i)
Definition: CCaloSD.hh:74
virtual void PrepareNewEvent()
bool G4bool
Definition: G4Types.hh:79
G4int GetTrackID() const
G4VSensitiveDetector * FindSensitiveDetector(G4String dName, G4bool warning=true)
Definition: G4SDManager.cc:124
static const double eV
Definition: G4SIunits.hh:194
virtual G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack)
int getNumberOfCaloSD()
Definition: CCalSDList.cc:76
#define G4endl
Definition: G4ios.hh:61
G4StackManager * stackManager
G4TrackStatus
G4bool trackStartsInCalo(const G4Track *atrack)
G4bool isInitialized()
Check if the generator is initialized.
void setPrimaryID(G4int id)
static G4SDManager * GetSDMpointerIfExist()
Definition: G4SDManager.cc:49