File indexing completed on 2025-01-31 09:22:13
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 #include "G4RunManager.hh"
0038 #include "GammaRayTelCalorimeterSD.hh"
0039 #include "GammaRayTelCalorimeterHit.hh"
0040 #include "GammaRayTelDetectorConstruction.hh"
0041
0042 #include "G4SystemOfUnits.hh"
0043 #include "G4VPhysicalVolume.hh"
0044 #include "G4Step.hh"
0045 #include "G4VTouchable.hh"
0046 #include "G4TouchableHistory.hh"
0047 #include "G4SDManager.hh"
0048 #include "G4ios.hh"
0049
0050
0051
0052 GammaRayTelCalorimeterSD::GammaRayTelCalorimeterSD(G4String name) : G4VSensitiveDetector(name) {
0053 auto *runManager = G4RunManager::GetRunManager();
0054 detector = (GammaRayTelDetectorConstruction*) (runManager->GetUserDetectorConstruction());
0055
0056 numberOfCALBars = detector->GetNbOfCALBars();
0057 numberOfCALLayers = detector->GetNbOfCALLayers();
0058
0059
0060
0061
0062 numberOfCALChannels = numberOfCALBars * numberOfCALLayers;
0063
0064 calHitXID = new G4int[numberOfCALChannels];
0065 calHitYID = new G4int[numberOfCALChannels];
0066 collectionName.insert("CalorimeterCollection");
0067 }
0068
0069
0070
0071 GammaRayTelCalorimeterSD::~GammaRayTelCalorimeterSD() {
0072 delete[] calHitXID;
0073 delete[] calHitYID;
0074 }
0075
0076
0077
0078 void GammaRayTelCalorimeterSD::Initialize(G4HCofThisEvent*) {
0079 calorimeterCollection = new GammaRayTelCalorimeterHitsCollection(SensitiveDetectorName, collectionName[0]);
0080 for (auto i = 0; i < numberOfCALChannels; i++) {
0081 calHitXID[i] = -1;
0082 calHitYID[i] = -1;
0083 }
0084 }
0085
0086
0087
0088 auto GammaRayTelCalorimeterSD::ProcessHits(G4Step *step, G4TouchableHistory*) -> G4bool {
0089 G4double depositedEnergy = 0.;
0090 depositedEnergy = step->GetTotalEnergyDeposit();
0091 if (depositedEnergy == 0.) {
0092 return false;
0093 }
0094
0095
0096 auto *theTouchable = (G4TouchableHistory*) (step->GetPreStepPoint()->GetTouchable());
0097 auto *calorimeterBar = theTouchable->GetVolume();
0098 auto *calorimeterPlane = theTouchable->GetVolume(1);
0099 auto calorimeterBarNumber = calorimeterBar->GetCopyNo();
0100 auto calorimeterBarName = calorimeterBar->GetName();
0101
0102 G4int planeNumber{0};
0103 planeNumber = calorimeterPlane->GetCopyNo();
0104
0105 auto planeName = calorimeterPlane->GetName();
0106
0107 G4int NChannel = 0;
0108 NChannel = planeNumber * numberOfCALBars + calorimeterBarNumber;
0109
0110 if (planeName == "CALLayerX") {
0111 if (calHitXID[NChannel] == -1) {
0112 auto *calorimeterHit = new GammaRayTelCalorimeterHit;
0113 calorimeterHit->SetCALType(1);
0114 calorimeterHit->AddEnergy(depositedEnergy);
0115 calorimeterHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0116 calorimeterHit->SetCALPlaneNumber(planeNumber);
0117 calorimeterHit->SetCALBarNumber(calorimeterBarNumber);
0118 calHitXID[NChannel] = calorimeterCollection->insert(calorimeterHit) - 1;
0119 } else {
0120 (*calorimeterCollection)[calHitXID[NChannel]]->AddEnergy(depositedEnergy);
0121 }
0122 }
0123
0124 if (planeName == "CALLayerY") {
0125 if (calHitYID[NChannel] == -1) {
0126 auto *calorimeterHit = new GammaRayTelCalorimeterHit;
0127 calorimeterHit->SetCALType(0);
0128 calorimeterHit->AddEnergy(depositedEnergy);
0129 calorimeterHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0130 calorimeterHit->SetCALPlaneNumber(planeNumber);
0131 calorimeterHit->SetCALBarNumber(calorimeterBarNumber);
0132 calHitYID[NChannel] = calorimeterCollection->insert(calorimeterHit) - 1;
0133 } else {
0134 (*calorimeterCollection)[calHitYID[NChannel]]->AddEnergy(depositedEnergy);
0135 }
0136 }
0137
0138 return true;
0139 }
0140
0141
0142
0143 void GammaRayTelCalorimeterSD::EndOfEvent(G4HCofThisEvent *HCE) {
0144 static G4int collectionIdentifier = -1;
0145 if (collectionIdentifier < 0) {
0146 collectionIdentifier = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0147 }
0148 HCE->AddHitsCollection(collectionIdentifier, calorimeterCollection);
0149
0150 for (auto i = 0; i < numberOfCALChannels; i++) {
0151 calHitXID[i] = -1;
0152 calHitYID[i] = -1;
0153 }
0154 }
0155
0156
0157
0158 void GammaRayTelCalorimeterSD::clear() {
0159 }
0160
0161
0162
0163 void GammaRayTelCalorimeterSD::DrawAll() {
0164 }
0165
0166
0167
0168 void GammaRayTelCalorimeterSD::PrintAll() {
0169 }