source: trunk/examples/advanced/composite_calorimeter/src/CCalStackingAction.cc@ 1323

Last change on this file since 1323 was 807, checked in by garnier, 17 years ago

update

File size: 6.2 KB
Line 
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//
26///////////////////////////////////////////////////////////////////////////////
27// File: CCalStackingAction.cc
28// Description: Stacking action needed for the application
29///////////////////////////////////////////////////////////////////////////////
30#include "CCalStackingAction.hh"
31#include "G4StackManager.hh"
32
33#include "G4SDManager.hh"
34#include "CCaloSD.hh"
35#include "CCalSDList.hh"
36#include "G4RunManager.hh"
37#include "G4Navigator.hh"
38
39//#define debug
40//#define ddebug
41
42CCalStackingAction::CCalStackingAction(): isInitialized(false) {}
43
44
45CCalStackingAction::~CCalStackingAction(){}
46
47
48void CCalStackingAction::PrepareNewEvent(){
49
50 if(!isInitialized) initialize();
51 stage = firstStage;
52 nurgent = 0;
53 acceptSecondaries = 1;
54
55}
56
57void CCalStackingAction::initialize(){
58
59 isInitialized = true;
60
61 numberOfSD = CCalSDList::getInstance()->getNumberOfCaloSD();
62#ifdef debug
63 G4cout << "CCalStackingAction look for " << numberOfSD
64 << " calorimeter-like SD" << G4endl;
65#endif
66 int i = 0;
67 for (i=0; i<numberOfSD; i++) {
68 G4String theName(CCalSDList::getInstance()->getCaloSDName(i));
69 SDName[i] = theName;
70#ifdef debug
71 G4cout << "Found SD name " << theName << G4endl;
72#endif
73 theCaloSD[i] = 0;
74 }
75
76 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
77 if (sd != 0) {
78
79 for (i=0; i<numberOfSD; i++){
80
81 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(SDName[i]);
82 if (aSD==0) {
83#ifdef debug
84 G4cout << "CCalStackingAction::initialize: No SD with name " << SDName[i]
85 << " in this Setup " << G4endl;
86#endif
87 } else {
88 theCaloSD[i] = dynamic_cast<CCaloSD*>(aSD);
89 theCaloSD[i]->SetPrimaryID(0);
90 }
91 }
92#ifdef debug
93 G4cout << "CCalStackingAction::initialize: Could not get SD Manager !"
94 << G4endl;
95#endif
96 }
97
98}
99
100G4ClassificationOfNewTrack CCalStackingAction::ClassifyNewTrack(const G4Track* aTrack){
101
102 G4ClassificationOfNewTrack classification=fKill;
103 int parentID = aTrack->GetParentID();
104#ifdef ddebug
105 G4TrackStatus status = aTrack->GetTrackStatus();
106 G4cout << "Classifying track " << aTrack->GetTrackID()
107 << " with status " << aTrack->GetTrackStatus() << G4endl;
108#endif
109
110 if (parentID < 0) {
111#ifdef debug
112 G4cout << "Killing track " << aTrack->GetTrackID()
113 << " from previous event. Should not happen" << G4endl;
114 G4cout << "returning classification= " << classification << G4endl;
115#endif
116 return classification= fKill;
117 }
118
119 if (aTrack->GetDefinition()->GetParticleName() == "gamma" &&
120 aTrack->GetKineticEnergy() < 1.*eV) {
121#ifdef debug
122 G4cout << "Kills particle " << aTrack->GetDefinition()->GetParticleName()
123 << " of energy " << aTrack->GetKineticEnergy()/MeV << " MeV"
124 << G4endl;
125#endif
126 return classification= fKill;
127 }
128
129 if (stage<end) {
130 /////////////////
131 /// PRIMARIES ///
132 /////////////////
133 if (parentID == 0 ) {
134 if ( nurgent == 0) {
135 nurgent++;
136 classification = fUrgent;
137 setPrimaryID(aTrack->GetTrackID());
138 }
139 else classification = fWaiting;
140 }
141
142 ///////////////////
143 /// SECONDARIES ///
144 ///////////////////
145
146 if (parentID > 0) {
147 if (acceptSecondaries == 1) {
148 if (trackStartsInCalo(const_cast<G4Track *>(aTrack))!=0 )
149 classification = fUrgent;
150 else
151 classification = fWaiting;
152 } else {
153 if(nurgent == 0){
154 nurgent++;
155 classification = fUrgent;
156 setPrimaryID(aTrack->GetTrackID());
157 } else
158 classification = fWaiting;
159 }
160 }
161
162
163 } else
164 classification = G4UserStackingAction::ClassifyNewTrack(aTrack);
165
166#ifdef ddebug
167 G4cout << " returning classification= " << classification
168 << " for track "<< aTrack->GetTrackID() << G4endl;
169#endif
170 return classification;
171
172}
173
174
175void CCalStackingAction::NewStage(){
176
177#ifdef ddebug
178 G4cout << "In NewStage with stage = " << stage << G4endl;
179#endif
180 if (stage <end) {
181 nurgent = 0;
182 setPrimaryID(0);
183 acceptSecondaries = 0;
184 stackManager->ReClassify();
185 acceptSecondaries = 1;
186 if (stackManager->GetNUrgentTrack() == 0) {
187 stage = stageLevel(stage+1);
188 }
189
190 }
191}
192
193G4bool CCalStackingAction::trackStartsInCalo(const G4Track* ){
194
195 /// This method should check that the secondary particle
196 /// was produced inside the detector calorimeter and
197 /// really is part of the shower.
198 /// If it has been produced before the calorimeter
199 /// for ex. Bremsstrahlung, it should be treated as a new
200 /// particle producing a new shower.
201
202 return true;
203}
204
205void CCalStackingAction::setPrimaryID(G4int id){
206
207 for (int i=0; i<numberOfSD; i++){
208 if(theCaloSD[i] != 0)theCaloSD[i]->SetPrimaryID(id);
209 }
210
211}
Note: See TracBrowser for help on using the repository browser.