ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CCalStackingAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CCalStackingAction.cc
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  : fTimeLimit(10000*CLHEP::ns),isInitialized(false)
45 {}
46 
48 
50 
52  stage = firstStage;
53  nurgent = 0;
55 }
56 
58 
59  isInitialized = true;
60 
62 #ifdef debug
63  G4cout << "CCalStackingAction look for " << numberOfSD
64  << " calorimeter-like SD" << G4endl;
65 #endif
66  G4int 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 
77  if (sd != 0) {
78 
79  for (i=0; i<numberOfSD; i++){
80 
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 
100 
101  G4ClassificationOfNewTrack classification=fKill;
102  G4int parentID = aTrack->GetParentID();
103 #ifdef ddebug
104  G4TrackStatus status = aTrack->GetTrackStatus();
105  G4cout << "Classifying track " << aTrack->GetTrackID()
106  << " with status " << aTrack->GetTrackStatus() << G4endl;
107 #endif
108 
109  if (aTrack->GetGlobalTime() > fTimeLimit) {
110 #ifdef debug
111  G4cout << "Kills particle " << aTrack->GetDefinition()->GetParticleName()
112  << " of energy " << aTrack->GetKineticEnergy()/MeV << " MeV"
113  << G4endl;
114 #endif
115  return classification = fKill;
116  }
117 
118  if (stage<end) {
122  if (parentID == 0 ) {
123  if ( nurgent == 0) {
124  nurgent++;
125  classification = fUrgent;
126  setPrimaryID(aTrack->GetTrackID());
127  }
128  else classification = fWaiting;
129  }
130 
134 
135  if (parentID > 0) {
136  if (acceptSecondaries == 1) {
137  if (trackStartsInCalo(const_cast<G4Track *>(aTrack))!=0 )
138  classification = fUrgent;
139  else
140  classification = fWaiting;
141  } else {
142  if(nurgent == 0){
143  nurgent++;
144  classification = fUrgent;
145  setPrimaryID(aTrack->GetTrackID());
146  } else
147  classification = fWaiting;
148  }
149  }
150 
151 
152  } else
153  classification = G4UserStackingAction::ClassifyNewTrack(aTrack);
154 
155 #ifdef ddebug
156  G4cout << " returning classification= " << classification
157  << " for track "<< aTrack->GetTrackID() << G4endl;
158 #endif
159  return classification;
160 
161 }
162 
163 
165 
166 #ifdef ddebug
167  G4cout << "In NewStage with stage = " << stage << G4endl;
168 #endif
169  if (stage <end) {
170  nurgent = 0;
171  setPrimaryID(0);
172  acceptSecondaries = 0;
174  acceptSecondaries = 1;
175  if (stackManager->GetNUrgentTrack() == 0) {
176  stage = stageLevel(stage+1);
177  }
178 
179  }
180 }
181 
183 
190 
191  return true;
192 }
193 
195 
196  for (G4int i=0; i<numberOfSD; i++){
197  if(theCaloSD[i] != 0)theCaloSD[i]->SetPrimaryID(id);
198  }
199 
200 }