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