Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 ////////////////////////////////////////////// 26 /////////////////////////////////////////////////////////////////////////////// 27 // File: CCalStackingAction.cc 27 // File: CCalStackingAction.cc 28 // Description: Stacking action needed for the 28 // Description: Stacking action needed for the application 29 ////////////////////////////////////////////// 29 /////////////////////////////////////////////////////////////////////////////// 30 #include "CCalStackingAction.hh" 30 #include "CCalStackingAction.hh" 31 #include "G4StackManager.hh" 31 #include "G4StackManager.hh" 32 32 33 #include "G4SystemOfUnits.hh" << 34 #include "G4SDManager.hh" 33 #include "G4SDManager.hh" 35 #include "CCaloSD.hh" 34 #include "CCaloSD.hh" 36 #include "CCalSDList.hh" 35 #include "CCalSDList.hh" 37 #include "G4RunManager.hh" 36 #include "G4RunManager.hh" 38 #include "G4Navigator.hh" 37 #include "G4Navigator.hh" 39 38 40 //#define debug 39 //#define debug 41 //#define ddebug 40 //#define ddebug 42 41 43 CCalStackingAction::CCalStackingAction() << 42 CCalStackingAction::CCalStackingAction(): isInitialized(false) {} 44 : fTimeLimit(10000*CLHEP::ns),isInitialized( << 43 45 {} << 46 44 47 CCalStackingAction::~CCalStackingAction(){} 45 CCalStackingAction::~CCalStackingAction(){} 48 46 >> 47 49 void CCalStackingAction::PrepareNewEvent(){ 48 void CCalStackingAction::PrepareNewEvent(){ 50 49 51 if(!isInitialized) initialize(); 50 if(!isInitialized) initialize(); 52 stage = firstStage; 51 stage = firstStage; 53 nurgent = 0; 52 nurgent = 0; 54 acceptSecondaries = 1; 53 acceptSecondaries = 1; >> 54 55 } 55 } 56 56 57 void CCalStackingAction::initialize(){ 57 void CCalStackingAction::initialize(){ 58 58 59 isInitialized = true; 59 isInitialized = true; 60 60 61 numberOfSD = CCalSDList::getInstance()->getN 61 numberOfSD = CCalSDList::getInstance()->getNumberOfCaloSD(); 62 #ifdef debug 62 #ifdef debug 63 G4cout << "CCalStackingAction look for " << 63 G4cout << "CCalStackingAction look for " << numberOfSD 64 << " calorimeter-like SD" << G4endl; << 64 << " calorimeter-like SD" << G4endl; 65 #endif 65 #endif 66 G4int i = 0; << 66 int i = 0; 67 for (i=0; i<numberOfSD; i++) { 67 for (i=0; i<numberOfSD; i++) { 68 G4String theName(CCalSDList::getInstance() 68 G4String theName(CCalSDList::getInstance()->getCaloSDName(i)); 69 SDName[i] = theName; 69 SDName[i] = theName; 70 #ifdef debug 70 #ifdef debug 71 G4cout << "Found SD name " << theName << 71 G4cout << "Found SD name " << theName << G4endl; 72 #endif 72 #endif 73 theCaloSD[i] = 0; 73 theCaloSD[i] = 0; 74 } 74 } 75 75 76 G4SDManager* sd = G4SDManager::GetSDMpointer 76 G4SDManager* sd = G4SDManager::GetSDMpointerIfExist(); 77 if (sd != 0) { 77 if (sd != 0) { 78 78 79 for (i=0; i<numberOfSD; i++){ 79 for (i=0; i<numberOfSD; i++){ 80 80 81 G4VSensitiveDetector* aSD = sd->FindSens 81 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(SDName[i]); 82 if (aSD==0) { 82 if (aSD==0) { 83 #ifdef debug 83 #ifdef debug 84 G4cout << "CCalStackingAction::initial << 84 G4cout << "CCalStackingAction::initialize: No SD with name " << SDName[i] 85 << " in this Setup " << G4endl; << 85 << " in this Setup " << G4endl; 86 #endif 86 #endif 87 } else { 87 } else { 88 theCaloSD[i] = dynamic_cast<CCaloSD*>( << 88 theCaloSD[i] = dynamic_cast<CCaloSD*>(aSD); 89 theCaloSD[i]->SetPrimaryID(0); << 89 theCaloSD[i]->SetPrimaryID(0); 90 } << 90 } 91 } 91 } 92 #ifdef debug 92 #ifdef debug 93 G4cout << "CCalStackingAction::initialize: 93 G4cout << "CCalStackingAction::initialize: Could not get SD Manager !" 94 << G4endl; << 94 << G4endl; 95 #endif 95 #endif 96 } << 96 } >> 97 97 } 98 } 98 99 99 G4ClassificationOfNewTrack CCalStackingAction: 100 G4ClassificationOfNewTrack CCalStackingAction::ClassifyNewTrack(const G4Track* aTrack){ 100 101 101 G4ClassificationOfNewTrack classification=fK 102 G4ClassificationOfNewTrack classification=fKill; 102 G4int parentID = aTrack->GetParentID(); << 103 int parentID = aTrack->GetParentID(); 103 #ifdef ddebug 104 #ifdef ddebug 104 G4TrackStatus status = aTrack->GetTrackStatu 105 G4TrackStatus status = aTrack->GetTrackStatus(); 105 G4cout << "Classifying track " << aTrack->Ge 106 G4cout << "Classifying track " << aTrack->GetTrackID() 106 << " with status " << aTrack->GetTrac << 107 << " with status " << aTrack->GetTrackStatus() << G4endl; 107 #endif 108 #endif 108 109 109 if (aTrack->GetGlobalTime() > fTimeLimit) { << 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) { 110 #ifdef debug 121 #ifdef debug 111 G4cout << "Kills particle " << aTrack->Get 122 G4cout << "Kills particle " << aTrack->GetDefinition()->GetParticleName() 112 << " of energy " << aTrack->GetKine << 123 << " of energy " << aTrack->GetKineticEnergy()/MeV << " MeV" 113 << G4endl; << 124 << G4endl; 114 #endif 125 #endif 115 return classification = fKill; << 126 return classification= fKill; 116 } 127 } 117 128 118 if (stage<end) { 129 if (stage<end) { 119 ///////////////// 130 ///////////////// 120 /// PRIMARIES /// 131 /// PRIMARIES /// 121 ///////////////// 132 ///////////////// 122 if (parentID == 0 ) { 133 if (parentID == 0 ) { 123 if ( nurgent == 0) { 134 if ( nurgent == 0) { 124 nurgent++; << 135 nurgent++; 125 classification = fUrgent; << 136 classification = fUrgent; 126 setPrimaryID(aTrack->GetTrackID()); << 137 setPrimaryID(aTrack->GetTrackID()); 127 } 138 } 128 else classification = fWaiting; 139 else classification = fWaiting; 129 } 140 } 130 141 131 /////////////////// 142 /////////////////// 132 /// SECONDARIES /// 143 /// SECONDARIES /// 133 /////////////////// 144 /////////////////// 134 145 135 if (parentID > 0) { 146 if (parentID > 0) { 136 if (acceptSecondaries == 1) { 147 if (acceptSecondaries == 1) { 137 if (trackStartsInCalo(const_cast<G4Tra << 148 if (trackStartsInCalo(const_cast<G4Track *>(aTrack))!=0 ) 138 classification = fUrgent; << 149 classification = fUrgent; 139 else << 150 else 140 classification = fWaiting; << 151 classification = fWaiting; 141 } else { 152 } else { 142 if(nurgent == 0){ << 153 if(nurgent == 0){ 143 nurgent++; << 154 nurgent++; 144 classification = fUrgent; << 155 classification = fUrgent; 145 setPrimaryID(aTrack->GetTrackID()); << 156 setPrimaryID(aTrack->GetTrackID()); 146 } else << 157 } else 147 classification = fWaiting; << 158 classification = fWaiting; 148 } 159 } 149 } 160 } 150 161 151 162 152 } else 163 } else 153 classification = G4UserStackingAction::Cla 164 classification = G4UserStackingAction::ClassifyNewTrack(aTrack); 154 165 155 #ifdef ddebug 166 #ifdef ddebug 156 G4cout << " returning classification= " << c 167 G4cout << " returning classification= " << classification 157 << " for track "<< aTrack->GetTrackID << 168 << " for track "<< aTrack->GetTrackID() << G4endl; 158 #endif 169 #endif 159 return classification; 170 return classification; 160 171 161 } 172 } 162 173 163 174 164 void CCalStackingAction::NewStage(){ 175 void CCalStackingAction::NewStage(){ 165 176 166 #ifdef ddebug 177 #ifdef ddebug 167 G4cout << "In NewStage with stage = " << sta 178 G4cout << "In NewStage with stage = " << stage << G4endl; 168 #endif 179 #endif 169 if (stage <end) { 180 if (stage <end) { 170 nurgent = 0; << 181 nurgent = 0; 171 setPrimaryID(0); 182 setPrimaryID(0); 172 acceptSecondaries = 0; 183 acceptSecondaries = 0; 173 stackManager->ReClassify(); 184 stackManager->ReClassify(); 174 acceptSecondaries = 1; 185 acceptSecondaries = 1; 175 if (stackManager->GetNUrgentTrack() == 0) 186 if (stackManager->GetNUrgentTrack() == 0) { 176 stage = stageLevel(stage+1); 187 stage = stageLevel(stage+1); 177 } 188 } 178 << 189 179 } 190 } 180 } 191 } 181 192 182 G4bool CCalStackingAction::trackStartsInCalo(c 193 G4bool CCalStackingAction::trackStartsInCalo(const G4Track* ){ 183 194 184 /// This method should check that the seconda 195 /// This method should check that the secondary particle 185 /// was produced inside the detector calorime 196 /// was produced inside the detector calorimeter and 186 /// really is part of the shower. 197 /// really is part of the shower. 187 /// If it has been produced before the calori 198 /// If it has been produced before the calorimeter 188 /// for ex. Bremsstrahlung, it should be trea 199 /// for ex. Bremsstrahlung, it should be treated as a new 189 /// particle producing a new shower. 200 /// particle producing a new shower. 190 201 191 return true; 202 return true; 192 } 203 } 193 204 194 void CCalStackingAction::setPrimaryID(G4int id 205 void CCalStackingAction::setPrimaryID(G4int id){ 195 206 196 for (G4int i=0; i<numberOfSD; i++){ << 207 for (int i=0; i<numberOfSD; i++){ 197 if(theCaloSD[i] != 0)theCaloSD[i]->SetPrim 208 if(theCaloSD[i] != 0)theCaloSD[i]->SetPrimaryID(id); 198 } 209 } 199 210 200 } 211 } 201 212