File indexing completed on 2025-02-23 09:21:16
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 "F02CalorimeterSD.hh"
0036
0037 #include "F02CalorHit.hh"
0038 #include "F02DetectorConstruction.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 F02CalorimeterSD::F02CalorimeterSD(G4String name, F02DetectorConstruction* det)
0049 : G4VSensitiveDetector(name), fDetector(det), fHitID(new G4int[500])
0050 {
0051 collectionName.insert("CalCollection");
0052 }
0053
0054
0055
0056 F02CalorimeterSD::~F02CalorimeterSD()
0057 {
0058 delete[] fHitID;
0059 }
0060
0061
0062
0063 void F02CalorimeterSD::Initialize(G4HCofThisEvent*)
0064 {
0065 fCalCollection = new F02CalorHitsCollection(SensitiveDetectorName, collectionName[0]);
0066 for (G4int j = 0; j < 1; j++) {
0067 fHitID[j] = -1;
0068 };
0069 }
0070
0071
0072
0073 G4bool F02CalorimeterSD::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 F02CalorHit();
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 F02: " << number << G4endl;
0092 }
0093 else {
0094 if (physVol == fDetector->GetAbsorber()) (*fCalCollection)[fHitID[number]]->AddAbs(edep, stepl);
0095 if (verboseLevel > 0) G4cout << " Energy added to F02: " << number << G4endl;
0096 }
0097
0098 return true;
0099 }
0100
0101
0102
0103 void F02CalorimeterSD::EndOfEvent(G4HCofThisEvent* hce)
0104 {
0105 static G4int hcID = -1;
0106 if (hcID < 0) {
0107 hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0108 }
0109 hce->AddHitsCollection(hcID, fCalCollection);
0110 }
0111
0112