File indexing completed on 2025-02-23 09:21:17
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 #include "F03CalorimeterSD.hh"
0036
0037 #include "F03CalorHit.hh"
0038 #include "F03DetectorConstruction.hh"
0039
0040 #include "G4SDManager.hh"
0041 #include "G4Step.hh"
0042 #include "G4TouchableHistory.hh"
0043 #include "G4VPhysicalVolume.hh"
0044 #include "G4VTouchable.hh"
0045
0046
0047
0048 F03CalorimeterSD::F03CalorimeterSD(G4String name, F03DetectorConstruction* det)
0049 : G4VSensitiveDetector(name), fCalCollection(nullptr), fDetector(det), fHitID(new G4int[500])
0050 {
0051 collectionName.insert("CalCollection");
0052 }
0053
0054
0055
0056 F03CalorimeterSD::~F03CalorimeterSD()
0057 {
0058 delete[] fHitID;
0059 }
0060
0061
0062
0063 void F03CalorimeterSD::Initialize(G4HCofThisEvent*)
0064 {
0065 fCalCollection = new F03CalorHitsCollection(SensitiveDetectorName, collectionName[0]);
0066 for (G4int j = 0; j < 1; j++) {
0067 fHitID[j] = -1;
0068 };
0069 }
0070
0071
0072
0073 G4bool F03CalorimeterSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0074 {
0075 G4double edep = step->GetTotalEnergyDeposit();
0076 G4double stepl = 0.;
0077
0078 stepl = step->GetStepLength();
0079
0080 if ((edep == 0.) && (stepl == 0.)) return false;
0081
0082 auto theTouchable = (G4TouchableHistory*)(step->GetPreStepPoint()->GetTouchable());
0083
0084 G4VPhysicalVolume* physVol = theTouchable->GetVolume();
0085
0086 G4int number = 0;
0087 if (fHitID[number] == -1) {
0088 auto calHit = new F03CalorHit();
0089 if (physVol == fDetector->GetAbsorber()) calHit->AddAbs(edep, stepl);
0090 fHitID[number] = fCalCollection->insert(calHit) - 1;
0091 if (verboseLevel > 0) G4cout << " New Calorimeter Hit on F03: " << number << G4endl;
0092 }
0093 else {
0094 if (physVol == fDetector->GetAbsorber()) (*fCalCollection)[fHitID[number]]->AddAbs(edep, stepl);
0095 if (verboseLevel > 0) G4cout << " Energy added to F03: " << number << G4endl;
0096 }
0097 return true;
0098 }
0099
0100
0101
0102 void F03CalorimeterSD::EndOfEvent(G4HCofThisEvent* hce)
0103 {
0104 static G4int hcID = -1;
0105 if (hcID < 0) {
0106 hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0107 }
0108 hce->AddHitsCollection(hcID, fCalCollection);
0109 }
0110
0111