File indexing completed on 2025-02-23 09:19:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include "CCalStackingAction.hh"
0031 #include "G4StackManager.hh"
0032
0033 #include "G4SystemOfUnits.hh"
0034 #include "G4SDManager.hh"
0035 #include "CCaloSD.hh"
0036 #include "CCalSDList.hh"
0037 #include "G4RunManager.hh"
0038 #include "G4Navigator.hh"
0039
0040
0041
0042
0043 CCalStackingAction::CCalStackingAction()
0044 : fTimeLimit(10000*CLHEP::ns),isInitialized(false)
0045 {}
0046
0047 CCalStackingAction::~CCalStackingAction(){}
0048
0049 void CCalStackingAction::PrepareNewEvent(){
0050
0051 if(!isInitialized) initialize();
0052 stage = firstStage;
0053 nurgent = 0;
0054 acceptSecondaries = 1;
0055 }
0056
0057 void CCalStackingAction::initialize(){
0058
0059 isInitialized = true;
0060
0061 numberOfSD = CCalSDList::getInstance()->getNumberOfCaloSD();
0062 #ifdef debug
0063 G4cout << "CCalStackingAction look for " << numberOfSD
0064 << " calorimeter-like SD" << G4endl;
0065 #endif
0066 G4int i = 0;
0067 for (i=0; i<numberOfSD; i++) {
0068 G4String theName(CCalSDList::getInstance()->getCaloSDName(i));
0069 SDName[i] = theName;
0070 #ifdef debug
0071 G4cout << "Found SD name " << theName << G4endl;
0072 #endif
0073 theCaloSD[i] = 0;
0074 }
0075
0076 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist();
0077 if (sd != 0) {
0078
0079 for (i=0; i<numberOfSD; i++){
0080
0081 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(SDName[i]);
0082 if (aSD==0) {
0083 #ifdef debug
0084 G4cout << "CCalStackingAction::initialize: No SD with name " << SDName[i]
0085 << " in this Setup " << G4endl;
0086 #endif
0087 } else {
0088 theCaloSD[i] = dynamic_cast<CCaloSD*>(aSD);
0089 theCaloSD[i]->SetPrimaryID(0);
0090 }
0091 }
0092 #ifdef debug
0093 G4cout << "CCalStackingAction::initialize: Could not get SD Manager !"
0094 << G4endl;
0095 #endif
0096 }
0097 }
0098
0099 G4ClassificationOfNewTrack CCalStackingAction::ClassifyNewTrack(const G4Track* aTrack){
0100
0101 G4ClassificationOfNewTrack classification=fKill;
0102 G4int parentID = aTrack->GetParentID();
0103 #ifdef ddebug
0104 G4TrackStatus status = aTrack->GetTrackStatus();
0105 G4cout << "Classifying track " << aTrack->GetTrackID()
0106 << " with status " << aTrack->GetTrackStatus() << G4endl;
0107 #endif
0108
0109 if (aTrack->GetGlobalTime() > fTimeLimit) {
0110 #ifdef debug
0111 G4cout << "Kills particle " << aTrack->GetDefinition()->GetParticleName()
0112 << " of energy " << aTrack->GetKineticEnergy()/MeV << " MeV"
0113 << G4endl;
0114 #endif
0115 return classification = fKill;
0116 }
0117
0118 if (stage<end) {
0119
0120
0121
0122 if (parentID == 0 ) {
0123 if ( nurgent == 0) {
0124 nurgent++;
0125 classification = fUrgent;
0126 setPrimaryID(aTrack->GetTrackID());
0127 }
0128 else classification = fWaiting;
0129 }
0130
0131
0132
0133
0134
0135 if (parentID > 0) {
0136 if (acceptSecondaries == 1) {
0137 if (trackStartsInCalo(const_cast<G4Track *>(aTrack))!=0 )
0138 classification = fUrgent;
0139 else
0140 classification = fWaiting;
0141 } else {
0142 if(nurgent == 0){
0143 nurgent++;
0144 classification = fUrgent;
0145 setPrimaryID(aTrack->GetTrackID());
0146 } else
0147 classification = fWaiting;
0148 }
0149 }
0150
0151
0152 } else
0153 classification = G4UserStackingAction::ClassifyNewTrack(aTrack);
0154
0155 #ifdef ddebug
0156 G4cout << " returning classification= " << classification
0157 << " for track "<< aTrack->GetTrackID() << G4endl;
0158 #endif
0159 return classification;
0160
0161 }
0162
0163
0164 void CCalStackingAction::NewStage(){
0165
0166 #ifdef ddebug
0167 G4cout << "In NewStage with stage = " << stage << G4endl;
0168 #endif
0169 if (stage <end) {
0170 nurgent = 0;
0171 setPrimaryID(0);
0172 acceptSecondaries = 0;
0173 stackManager->ReClassify();
0174 acceptSecondaries = 1;
0175 if (stackManager->GetNUrgentTrack() == 0) {
0176 stage = stageLevel(stage+1);
0177 }
0178
0179 }
0180 }
0181
0182 G4bool CCalStackingAction::trackStartsInCalo(const G4Track* ){
0183
0184
0185
0186
0187
0188
0189
0190
0191 return true;
0192 }
0193
0194 void CCalStackingAction::setPrimaryID(G4int id){
0195
0196 for (G4int i=0; i<numberOfSD; i++){
0197 if(theCaloSD[i] != 0)theCaloSD[i]->SetPrimaryID(id);
0198 }
0199
0200 }