Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // ******************************************************************** 27 // 28 // CaTS (Calorimetry and Tracking Simulation) 29 // 30 // Authors : Hans Wenzel 31 // Soon Yung Jun 32 // (Fermi National Accelerator Laboratory) 33 // 34 // History 35 // October 18th, 2021 : first implementation 36 // 37 // ******************************************************************** 38 // 39 /// \file DRCalorimeterSD.cc 40 /// \brief Implementation of the CaTS::DRCalorimeterSD class 41 42 // Geant4 headers 43 #include "G4HCofThisEvent.hh" 44 #include "G4Step.hh" 45 #include "G4ThreeVector.hh" 46 #include "G4SDManager.hh" 47 #include "G4ios.hh" 48 #include "G4SteppingManager.hh" 49 #include "G4EventManager.hh" 50 #include "G4Cerenkov.hh" 51 // project headers 52 #include "DRCalorimeterSD.hh" 53 #include "ConfigurationManager.hh" 54 55 DRCalorimeterSD::DRCalorimeterSD(G4String name) 56 : G4VSensitiveDetector(name) 57 , fDRCalorimeterHitsCollection(0) 58 , fHCID(0) 59 { 60 G4String HCname = name + "_HC"; 61 collectionName.insert(HCname); 62 G4cout << collectionName.size() << " DRCalorimeterSD name: " << name 63 << " collection Name: " << HCname << G4endl; 64 fHCID = -1; 65 verbose = ConfigurationManager::getInstance()->isEnable_verbose(); 66 } 67 68 DRCalorimeterSD::~DRCalorimeterSD() {} 69 70 void DRCalorimeterSD::Initialize(G4HCofThisEvent* hce) 71 { 72 fDRCalorimeterHitsCollection = 73 new DRCalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]); 74 if(fHCID < 0) 75 { 76 if(verbose) 77 G4cout << "DRCalorimeterSD::Initialize: " << SensitiveDetectorName 78 << " " << collectionName[0] << G4endl; 79 fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); 80 } 81 hce->AddHitsCollection(fHCID, fDRCalorimeterHitsCollection); 82 } 83 84 G4bool DRCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) 85 { 86 G4double edep = aStep->GetTotalEnergyDeposit() / CLHEP::MeV; 87 if(edep == 0.) 88 return false; 89 G4double time = aStep->GetPreStepPoint()->GetGlobalTime() / CLHEP::ns; 90 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable(); 91 G4ThreeVector cellpos = touch->GetTranslation(); 92 unsigned int ID = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo(); 93 G4Track* theTrack = aStep->GetTrack(); 94 G4String particleType = theTrack->GetDefinition()->GetParticleName(); 95 unsigned int NCerenPhotons = 0; 96 G4SteppingManager* fpSteppingManager = G4EventManager::GetEventManager() 97 ->GetTrackingManager() 98 ->GetSteppingManager(); 99 G4StepStatus stepStatus = fpSteppingManager->GetfStepStatus(); 100 if(stepStatus != fAtRestDoItProc) 101 { 102 G4ProcessVector* procPost = fpSteppingManager->GetfPostStepDoItVector(); 103 size_t MAXofPostStepLoops = fpSteppingManager->GetMAXofPostStepLoops(); 104 for(size_t i3 = 0; i3 < MAXofPostStepLoops; i3++) 105 { 106 if((*procPost)[i3]->GetProcessName() == "Cerenkov") 107 { 108 G4Cerenkov* proc = (G4Cerenkov*) (*procPost)[i3]; 109 NCerenPhotons += proc->GetNumPhotons(); 110 } 111 } 112 } 113 // 114 // check if this cell has been hit before 115 // fDRCalorimeterHitsCollection 116 for(unsigned int j = 0; j < fDRCalorimeterHitsCollection->entries(); j++) 117 { 118 DRCalorimeterHit* aPreviousHit = (*fDRCalorimeterHitsCollection)[j]; 119 if(ID == aPreviousHit->GetId()) 120 { 121 aPreviousHit->SetEdep(aStep->GetTotalEnergyDeposit() + 122 aPreviousHit->GetEdep()); 123 aPreviousHit->SetNceren(aPreviousHit->GetNceren() + NCerenPhotons); 124 if((particleType == "e+") || (particleType == "gamma") || 125 (particleType == "e-")) 126 { 127 aPreviousHit->SetEm_Edep(edep + aPreviousHit->GetEm_Edep()); 128 } 129 return true; 130 } 131 } 132 // 133 // otherwise create a new hit: 134 // 135 DRCalorimeterHit* newHit; 136 if((particleType == "e+") || (particleType == "gamma") || 137 (particleType == "e-")) 138 { 139 newHit = new DRCalorimeterHit(ID, edep, edep, NCerenPhotons, time, cellpos); 140 } 141 else 142 { 143 newHit = new DRCalorimeterHit(ID, edep, 0.0, time, NCerenPhotons, cellpos); 144 } 145 fDRCalorimeterHitsCollection->insert(newHit); 146 return true; 147 } 148 149 void DRCalorimeterSD::EndOfEvent(G4HCofThisEvent*) 150 { 151 G4int NbHits = fDRCalorimeterHitsCollection->entries(); 152 if(verbose) 153 G4cout << " Number of DRCalorimeterHits: " << NbHits << G4endl; 154 } 155