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