File indexing completed on 2025-01-31 09:21:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #include "G4HCofThisEvent.hh"
0044 #include "G4Step.hh"
0045 #include "G4ThreeVector.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4ios.hh"
0048 #include "G4SteppingManager.hh"
0049 #include "G4EventManager.hh"
0050 #include "G4Cerenkov.hh"
0051
0052 #include "DRCalorimeterSD.hh"
0053 #include "ConfigurationManager.hh"
0054
0055 DRCalorimeterSD::DRCalorimeterSD(G4String name)
0056 : G4VSensitiveDetector(name)
0057 , fDRCalorimeterHitsCollection(0)
0058 , fHCID(0)
0059 {
0060 G4String HCname = name + "_HC";
0061 collectionName.insert(HCname);
0062 G4cout << collectionName.size() << " DRCalorimeterSD name: " << name
0063 << " collection Name: " << HCname << G4endl;
0064 fHCID = -1;
0065 verbose = ConfigurationManager::getInstance()->isEnable_verbose();
0066 }
0067
0068 DRCalorimeterSD::~DRCalorimeterSD() {}
0069
0070 void DRCalorimeterSD::Initialize(G4HCofThisEvent* hce)
0071 {
0072 fDRCalorimeterHitsCollection =
0073 new DRCalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]);
0074 if(fHCID < 0)
0075 {
0076 if(verbose)
0077 G4cout << "DRCalorimeterSD::Initialize: " << SensitiveDetectorName
0078 << " " << collectionName[0] << G4endl;
0079 fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0080 }
0081 hce->AddHitsCollection(fHCID, fDRCalorimeterHitsCollection);
0082 }
0083
0084 G4bool DRCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0085 {
0086 G4double edep = aStep->GetTotalEnergyDeposit() / CLHEP::MeV;
0087 if(edep == 0.)
0088 return false;
0089 G4double time = aStep->GetPreStepPoint()->GetGlobalTime() / CLHEP::ns;
0090 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0091 G4ThreeVector cellpos = touch->GetTranslation();
0092 unsigned int ID = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
0093 G4Track* theTrack = aStep->GetTrack();
0094 G4String particleType = theTrack->GetDefinition()->GetParticleName();
0095 unsigned int NCerenPhotons = 0;
0096 G4SteppingManager* fpSteppingManager = G4EventManager::GetEventManager()
0097 ->GetTrackingManager()
0098 ->GetSteppingManager();
0099 G4StepStatus stepStatus = fpSteppingManager->GetfStepStatus();
0100 if(stepStatus != fAtRestDoItProc)
0101 {
0102 G4ProcessVector* procPost = fpSteppingManager->GetfPostStepDoItVector();
0103 size_t MAXofPostStepLoops = fpSteppingManager->GetMAXofPostStepLoops();
0104 for(size_t i3 = 0; i3 < MAXofPostStepLoops; i3++)
0105 {
0106 if((*procPost)[i3]->GetProcessName() == "Cerenkov")
0107 {
0108 G4Cerenkov* proc = (G4Cerenkov*) (*procPost)[i3];
0109 NCerenPhotons += proc->GetNumPhotons();
0110 }
0111 }
0112 }
0113
0114
0115
0116 for(unsigned int j = 0; j < fDRCalorimeterHitsCollection->entries(); j++)
0117 {
0118 DRCalorimeterHit* aPreviousHit = (*fDRCalorimeterHitsCollection)[j];
0119 if(ID == aPreviousHit->GetId())
0120 {
0121 aPreviousHit->SetEdep(aStep->GetTotalEnergyDeposit() +
0122 aPreviousHit->GetEdep());
0123 aPreviousHit->SetNceren(aPreviousHit->GetNceren() + NCerenPhotons);
0124 if((particleType == "e+") || (particleType == "gamma") ||
0125 (particleType == "e-"))
0126 {
0127 aPreviousHit->SetEm_Edep(edep + aPreviousHit->GetEm_Edep());
0128 }
0129 return true;
0130 }
0131 }
0132
0133
0134
0135 DRCalorimeterHit* newHit;
0136 if((particleType == "e+") || (particleType == "gamma") ||
0137 (particleType == "e-"))
0138 {
0139 newHit = new DRCalorimeterHit(ID, edep, edep, NCerenPhotons, time, cellpos);
0140 }
0141 else
0142 {
0143 newHit = new DRCalorimeterHit(ID, edep, 0.0, time, NCerenPhotons, cellpos);
0144 }
0145 fDRCalorimeterHitsCollection->insert(newHit);
0146 return true;
0147 }
0148
0149 void DRCalorimeterSD::EndOfEvent(G4HCofThisEvent*)
0150 {
0151 G4int NbHits = fDRCalorimeterHitsCollection->entries();
0152 if(verbose)
0153 G4cout << " Number of DRCalorimeterHits: " << NbHits << G4endl;
0154 }