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: CCaloSD.cc 27 // File: CCaloSD.cc 28 // Description: Stores hits of calorimetric ty 28 // Description: Stores hits of calorimetric type in appropriate container 29 ////////////////////////////////////////////// 29 /////////////////////////////////////////////////////////////////////////////// 30 30 31 #include "CCaloSD.hh" 31 #include "CCaloSD.hh" 32 #include "G4SystemOfUnits.hh" << 33 #include "G4VProcess.hh" 32 #include "G4VProcess.hh" 34 #include "G4SDManager.hh" 33 #include "G4SDManager.hh" 35 #include "G4VTouchable.hh" 34 #include "G4VTouchable.hh" 36 #include "CCalVOrganization.hh" 35 #include "CCalVOrganization.hh" 37 #include "CCalSDList.hh" 36 #include "CCalSDList.hh" 38 37 39 //#define debug 38 //#define debug 40 //#define ddebug 39 //#define ddebug 41 40 42 CCaloSD::CCaloSD(G4String name, CCalVOrganizat 41 CCaloSD::CCaloSD(G4String name, CCalVOrganization* numberingScheme): 43 G4VSensitiveDetector(name), HCID(-1), SDname 42 G4VSensitiveDetector(name), HCID(-1), SDname(name), theHC(0), 44 CurrentHit(0), theTrack(0), CurrentPV(0), Pr 43 CurrentHit(0), theTrack(0), CurrentPV(0), PreviousPV(0), UnitID(0), 45 PreviousUnitID(0), PreStepPoint(0), PostStep 44 PreviousUnitID(0), PreStepPoint(0), PostStepPoint(0), 46 theDescription(numberingScheme) { 45 theDescription(numberingScheme) { 47 46 48 collectionName.insert(name); 47 collectionName.insert(name); 49 48 50 G4cout << "********************************* 49 G4cout << "*******************************************************" << G4endl; 51 G4cout << "* 50 G4cout << "* *" << G4endl; 52 G4cout << "* Constructing a CCaloSD with na << 51 G4cout << "* Constructing a CCaloSD with name " << name << G4endl; 53 G4cout << "* 52 G4cout << "* *" << G4endl; 54 G4cout << "********************************* 53 G4cout << "*******************************************************" << G4endl; 55 54 56 CCalSDList::getInstance()->addCalo(name); 55 CCalSDList::getInstance()->addCalo(name); 57 } 56 } 58 57 >> 58 59 CCaloSD::~CCaloSD() { 59 CCaloSD::~CCaloSD() { 60 delete theDescription; << 60 G4cout << "CCaloSD: " << SDname << " deleted" << G4endl; >> 61 if (theDescription) >> 62 delete theDescription; 61 } 63 } 62 64 >> 65 63 void CCaloSD::Initialize(G4HCofThisEvent*HCE) 66 void CCaloSD::Initialize(G4HCofThisEvent*HCE) { 64 67 65 #ifdef debug 68 #ifdef debug 66 G4cout << "CCaloSD : Initialize called for " 69 G4cout << "CCaloSD : Initialize called for " << SDname << G4endl; 67 #endif 70 #endif 68 //This initialization is performed at the be 71 //This initialization is performed at the beginning of an event 69 //------------------------------------------ 72 //------------------------------------------------------------ 70 73 71 theHC = new CCalG4HitCollection(SDname, coll 74 theHC = new CCalG4HitCollection(SDname, collectionName[0]); 72 if (HCID<0) { << 75 if (HCID<0) 73 HCID = G4SDManager::GetSDMpointer()->GetCo 76 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); 74 } << 75 HCE->AddHitsCollection( HCID, theHC ); 77 HCE->AddHitsCollection( HCID, theHC ); 76 78 77 TSID = -2; 79 TSID = -2; 78 PrimID = -2; 80 PrimID = -2; 79 /////PrimaryID = -99; <--- initialized by S 81 /////PrimaryID = -99; <--- initialized by StackingAction. 80 } 82 } 81 83 82 G4bool CCaloSD::ProcessHits(G4Step*aStep, G4To << 83 84 84 if(aStep->GetTotalEnergyDeposit() > CLHEP::e << 85 G4bool CCaloSD::ProcessHits(G4Step*aStep,G4TouchableHistory*) { 85 getStepInfo(aStep); << 86 86 if (hitExists() == false && EdepositEM+Ede << 87 if (aStep == NULL) return true; 87 createNewHit(); << 88 88 } << 89 getStepInfo(aStep); 89 } << 90 if (hitExists() == false && EdepositEM+EdepositEHAD>0.) >> 91 createNewHit(); >> 92 90 return true; 93 return true; 91 } 94 } 92 95 93 void CCaloSD::getStepInfo(const G4Step* aStep) << 96 >> 97 void CCaloSD::getStepInfo(G4Step* aStep) { 94 98 95 PreStepPoint = aStep->GetPreStepPoint(); 99 PreStepPoint = aStep->GetPreStepPoint(); 96 PostStepPoint= aStep->GetPostStepPoint(); 100 PostStepPoint= aStep->GetPostStepPoint(); 97 HitPoint = PreStepPoint->GetPosition(); << 101 HitPoint = PreStepPoint->GetPosition(); 98 102 99 theTrack = aStep->GetTrack(); 103 theTrack = aStep->GetTrack(); 100 CurrentPV= PreStepPoint->GetPhysicalVolume() 104 CurrentPV= PreStepPoint->GetPhysicalVolume(); 101 105 102 G4String pname = theTrack->GetDefinition()-> << 106 G4String particleType = theTrack->GetDefinition()->GetParticleName(); 103 G4double de = aStep->GetTotalEnergyDeposit() << 104 //G4cout << "##### Process new step dE= " << << 105 // << " " << pname << " inside " << << 106 107 107 const G4VTouchable* touch = aStep->GetPreSte 108 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable(); 108 G4double weight = 1.; << 109 G4double weight; 109 if (touch->GetVolume(0)->GetName() == "Cryst << 110 if (touch->GetVolume(0)->GetName() == "CrystalMatrixCrystal") 110 weight = curve_LY(PreStepPoint); 111 weight = curve_LY(PreStepPoint); 111 } << 112 else >> 113 weight = 1.; 112 114 113 if (pname == "e-" || pname == "e+" || pname << 115 if (particleType == "e-" || 114 EdepositEM = weight*de; << 116 particleType == "e+" || 115 EdepositEHAD = 0.f; << 117 particleType == "gamma" ){ >> 118 EdepositEM = weight*(aStep->GetTotalEnergyDeposit()); >> 119 EdepositEHAD = 0.; 116 } else { 120 } else { 117 EdepositEM = 0.f; << 121 EdepositEM = 0.; 118 EdepositEHAD = weight*de; << 122 EdepositEHAD = weight*(aStep->GetTotalEnergyDeposit()); 119 } 123 } 120 124 121 TSlice = (PostStepPoint) ? PostStepPoint->Ge << 125 TSlice = (PostStepPoint->GetGlobalTime() )/nanosecond; 122 //G4cout << " W= " << weight << " T= " < << 126 TSliceID = (int) TSlice; 123 G4int it = (G4int)TSlice; << 127 if (theDescription!=0) 124 TSliceID = std::min(it, 10000); << 128 UnitID = theDescription->GetUnitID(aStep); 125 //G4cout << " tID= " << TSliceID << G4endl; << 129 else 126 << 130 UnitID = 0; 127 UnitID = (theDescription) ? theDescription-> << 131 128 } 132 } 129 133 >> 134 130 G4bool CCaloSD::hitExists() { 135 G4bool CCaloSD::hitExists() { 131 136 >> 137 if (PrimaryID<1) { >> 138 G4cerr << "***** CCaloSD error: PrimaryID = " << PrimaryID >> 139 << " Maybe detector name changed" >> 140 << G4endl; >> 141 } >> 142 >> 143 132 if ( CurrentPV==PreviousPV && PrimaryID == P 144 if ( CurrentPV==PreviousPV && PrimaryID == PrimID && TSliceID == TSID && 133 UnitID==PreviousUnitID) { 145 UnitID==PreviousUnitID) { 134 updateHit(); 146 updateHit(); 135 return true; 147 return true; 136 } 148 } 137 149 138 if (PrimaryID != PrimID) { ResetForNewPrimar << 150 >> 151 if (PrimaryID != PrimID) >> 152 ResetForNewPrimary(); 139 153 140 // look in HC whether a hit with the same pr << 154 141 // exists already: << 155 //look in HC whether a hit with the same primID,UnitID,TSliceID exists already: 142 156 143 G4bool found = false; 157 G4bool found = false; 144 for (std::size_t j=0; j<theHC->entries(); ++ << 158 for (G4int j=0; j<theHC->entries()&&!found; j++) { 145 159 146 CCalG4Hit* aPreviousHit = (*theHC)[j]; 160 CCalG4Hit* aPreviousHit = (*theHC)[j]; 147 if (aPreviousHit->getTrackID() == Primary 161 if (aPreviousHit->getTrackID() == PrimaryID && 148 aPreviousHit->getTimeSliceID() == TSli << 162 aPreviousHit->getTimeSliceID() == TSliceID && 149 aPreviousHit->getUnitID()== UnitID << 163 aPreviousHit->getUnitID()== UnitID ) { 150 CurrentHit = aPreviousHit; 164 CurrentHit = aPreviousHit; 151 found = true; 165 found = true; 152 break; << 153 } 166 } 154 } 167 } 155 168 156 if (found) { 169 if (found) { 157 updateHit(); 170 updateHit(); 158 return true; 171 return true; 159 } else { 172 } else { 160 return false; 173 return false; 161 } 174 } 162 } 175 } 163 176 >> 177 164 void CCaloSD::ResetForNewPrimary() { 178 void CCaloSD::ResetForNewPrimary() { 165 179 166 EntrancePoint = SetToLocal(HitPoint); 180 EntrancePoint = SetToLocal(HitPoint); 167 IncidentEnergy = PreStepPoint->GetKineticEne 181 IncidentEnergy = PreStepPoint->GetKineticEnergy(); 168 182 169 } 183 } 170 184 >> 185 171 void CCaloSD::StoreHit(CCalG4Hit* hit){ 186 void CCaloSD::StoreHit(CCalG4Hit* hit){ 172 187 173 if (PrimID<0) return; 188 if (PrimID<0) return; 174 if (hit == 0 ) { 189 if (hit == 0 ) { 175 G4cout << "CCaloSD: hit to be stored is NU 190 G4cout << "CCaloSD: hit to be stored is NULL !!" <<G4endl; 176 return; 191 return; 177 } 192 } 178 193 179 theHC->insert( hit ); 194 theHC->insert( hit ); 180 } 195 } 181 196 >> 197 182 void CCaloSD::createNewHit() { 198 void CCaloSD::createNewHit() { 183 199 184 #ifdef debug 200 #ifdef debug 185 G4int currentCopyNo = -999; 201 G4int currentCopyNo = -999; 186 G4int motherCopyNo = -999; 202 G4int motherCopyNo = -999; 187 G4TouchableHistory* theTouchable 203 G4TouchableHistory* theTouchable 188 = (G4TouchableHistory*)( theTrack->GetTouc 204 = (G4TouchableHistory*)( theTrack->GetTouchable() ); 189 if ( theTouchable ) { 205 if ( theTouchable ) { 190 currentCopyNo = theTouchable->GetReplicaNu 206 currentCopyNo = theTouchable->GetReplicaNumber( 0 ); 191 if ( theTouchable->GetHistoryDepth() > 0 ) 207 if ( theTouchable->GetHistoryDepth() > 0 ) { 192 motherCopyNo = theTouchable->GetReplicaN 208 motherCopyNo = theTouchable->GetReplicaNumber( 1 ); 193 } 209 } 194 } 210 } 195 G4cout << "CCaloSD createNewHit for" 211 G4cout << "CCaloSD createNewHit for" 196 << " PV " << CurrentPV->GetName() 212 << " PV " << CurrentPV->GetName() 197 << " PVid = " << currentCopyNo 213 << " PVid = " << currentCopyNo 198 << " MVid = " << motherCopyNo 214 << " MVid = " << motherCopyNo 199 << " Unit " << UnitID <<G4endl; 215 << " Unit " << UnitID <<G4endl; 200 G4cout << " primary " << PrimaryID 216 G4cout << " primary " << PrimaryID 201 << " time slice " << TSliceID 217 << " time slice " << TSliceID 202 << " For Track " << theTrack->GetTra 218 << " For Track " << theTrack->GetTrackID() 203 << " which is a " << theTrack->GetDe 219 << " which is a " << theTrack->GetDefinition()->GetParticleName(); 204 << 220 205 if (theTrack->GetTrackID()==1) { 221 if (theTrack->GetTrackID()==1) { 206 G4cout << " of energy " << theTrack->G 222 G4cout << " of energy " << theTrack->GetTotalEnergy(); 207 } else { 223 } else { 208 G4cout << " daughter of part. " << theTrac 224 G4cout << " daughter of part. " << theTrack->GetParentID(); 209 } 225 } 210 226 211 G4cout << " and created by " ; 227 G4cout << " and created by " ; 212 if (theTrack->GetCreatorProcess()!=NULL) 228 if (theTrack->GetCreatorProcess()!=NULL) 213 G4cout << theTrack->GetCreatorProcess()->G 229 G4cout << theTrack->GetCreatorProcess()->GetProcessName() ; 214 else 230 else 215 G4cout << "NO process"; 231 G4cout << "NO process"; 216 G4cout << G4endl; 232 G4cout << G4endl; 217 #endif 233 #endif 218 234 >> 235 219 CurrentHit = new CCalG4Hit; 236 CurrentHit = new CCalG4Hit; 220 CurrentHit->setTrackID(PrimaryID); 237 CurrentHit->setTrackID(PrimaryID); 221 CurrentHit->setTimeSlice(TSlice); 238 CurrentHit->setTimeSlice(TSlice); 222 CurrentHit->setUnitID(UnitID); 239 CurrentHit->setUnitID(UnitID); 223 CurrentHit->setEntry(EntrancePoint); 240 CurrentHit->setEntry(EntrancePoint); 224 CurrentHit->setIncidentEnergy(IncidentEnergy 241 CurrentHit->setIncidentEnergy(IncidentEnergy); 225 updateHit(); 242 updateHit(); 226 243 227 StoreHit(CurrentHit); 244 StoreHit(CurrentHit); 228 245 229 } << 246 } >> 247 230 248 231 void CCaloSD::updateHit() { 249 void CCaloSD::updateHit() { 232 if (EdepositEM+EdepositEHAD != 0) { 250 if (EdepositEM+EdepositEHAD != 0) { 233 CurrentHit->addEnergyDeposit(EdepositEM,Ed 251 CurrentHit->addEnergyDeposit(EdepositEM,EdepositEHAD); 234 #ifdef debug 252 #ifdef debug 235 G4cout << "Energy deposit in Unit " << Uni 253 G4cout << "Energy deposit in Unit " << UnitID << " em " << EdepositEM/MeV 236 << " hadronic " << EdepositEHAD/MeV < << 254 << " hadronic " << EdepositEHAD/MeV << " MeV" << G4endl; 237 #endif 255 #endif 238 } 256 } 239 257 240 // buffer for next steps: 258 // buffer for next steps: 241 TSID = TSliceID; 259 TSID = TSliceID; 242 PrimID = PrimaryID; 260 PrimID = PrimaryID; 243 PreviousPV = CurrentPV; 261 PreviousPV = CurrentPV; 244 PreviousUnitID = UnitID; 262 PreviousUnitID = UnitID; 245 } 263 } 246 264 247 G4ThreeVector CCaloSD::SetToLocal(const G4Thre << 265 >> 266 G4ThreeVector CCaloSD::SetToLocal(G4ThreeVector global){ 248 267 249 G4ThreeVector localPoint; 268 G4ThreeVector localPoint; 250 const G4VTouchable* touch= PreStepPoint->G 269 const G4VTouchable* touch= PreStepPoint->GetTouchable(); 251 localPoint=touch->GetHistory()->GetTopTransf 270 localPoint=touch->GetHistory()->GetTopTransform().TransformPoint(global); 252 271 253 return localPoint; 272 return localPoint; >> 273 254 } 274 } 255 275 >> 276 256 void CCaloSD::EndOfEvent(G4HCofThisEvent*) { 277 void CCaloSD::EndOfEvent(G4HCofThisEvent*) { 257 summarize(); 278 summarize(); 258 } 279 } 259 280 >> 281 260 void CCaloSD::summarize() { 282 void CCaloSD::summarize() { 261 } 283 } 262 284 >> 285 263 void CCaloSD::clear() { 286 void CCaloSD::clear() { 264 } 287 } 265 288 >> 289 266 void CCaloSD::DrawAll() { 290 void CCaloSD::DrawAll() { 267 } 291 } 268 292 >> 293 269 void CCaloSD::PrintAll() { 294 void CCaloSD::PrintAll() { 270 G4cout << "CCaloSD: Collection " << theHC->G 295 G4cout << "CCaloSD: Collection " << theHC->GetName() << G4endl; 271 theHC->PrintAllHits(); 296 theHC->PrintAllHits(); 272 } 297 } 273 298 >> 299 274 void CCaloSD::SetOrganization(CCalVOrganizatio 300 void CCaloSD::SetOrganization(CCalVOrganization* org){ 275 301 276 if (theDescription!=0) 302 if (theDescription!=0) 277 delete theDescription; 303 delete theDescription; 278 theDescription = org; 304 theDescription = org; 279 } 305 } 280 306 281 G4double CCaloSD::curve_LY(const G4StepPoint* << 307 >> 308 G4double CCaloSD::curve_LY(G4StepPoint* stepPoint) { 282 309 283 G4double weight = 1.; 310 G4double weight = 1.; 284 G4ThreeVector localPoint = SetToLocal(stepPo << 311 G4ThreeVector localPoint = SetToLocal(stepPoint->GetPosition()); 285 const G4double crlength = 230.; << 312 G4double crlength = 230.; 286 G4double dapd = 0.5 * crlength - localPoint. 313 G4double dapd = 0.5 * crlength - localPoint.z(); 287 if (dapd >= -0.1 || dapd <= crlength+0.1) { 314 if (dapd >= -0.1 || dapd <= crlength+0.1) { 288 if (dapd <= 100.) 315 if (dapd <= 100.) 289 weight = 1.05 - dapd * 0.0005; 316 weight = 1.05 - dapd * 0.0005; 290 } else { 317 } else { 291 G4cout << "CCaloSD, light coll curve : wro 318 G4cout << "CCaloSD, light coll curve : wrong distance to APD " << dapd 292 << " crlength = " << crlength << 319 << " crlength = " << crlength 293 << " z of localPoint = " << localPo << 320 << " z of localPoint = " << localPoint.z() 294 << " take weight = " << weight << G << 321 << " take weight = " << weight << G4endl; 295 } 322 } 296 #ifdef ddebug 323 #ifdef ddebug 297 G4cout << "CCaloSD, light coll curve : " << 324 G4cout << "CCaloSD, light coll curve : " << dapd 298 << " crlength = " << crlength << 325 << " crlength = " << crlength 299 << " z of localPoint = " << localPoin << 326 << " z of localPoint = " << localPoint.z() 300 << " take weight = " << weight << G4e << 327 << " take weight = " << weight << G4endl; 301 #endif 328 #endif 302 return weight; 329 return weight; 303 } 330 } 304 331