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 "GammaRayTelTrackerSD.hh"
0038 #include "GammaRayTelTrackerHit.hh"
0039 #include "GammaRayTelDetectorConstruction.hh"
0040
0041 #include "G4RunManager.hh"
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 GammaRayTelTrackerSD::GammaRayTelTrackerSD(G4String name) : G4VSensitiveDetector(name) {
0053 auto *runManager = G4RunManager::GetRunManager();
0054
0055 detector = (GammaRayTelDetectorConstruction*) (runManager->GetUserDetectorConstruction());
0056
0057 auto numberOfTKRTiles = detector->GetNbOfTKRTiles();
0058 numberOfTKRStrips = detector->GetNbOfTKRStrips();
0059 numberOfTKRLayers = detector->GetNbOfTKRLayers();
0060 numberOfTKRStrips = numberOfTKRStrips * numberOfTKRTiles;
0061 numberOfTKRChannels = numberOfTKRStrips * numberOfTKRTiles * numberOfTKRLayers;
0062
0063 tkrHitXID = new G4int[numberOfTKRChannels];
0064 tkrHitYID = new G4int[numberOfTKRChannels];
0065
0066 constexpr auto TRACKER_COLLECTION_NAME = "TrackerCollection";
0067 collectionName.insert(TRACKER_COLLECTION_NAME);
0068 }
0069
0070
0071
0072 GammaRayTelTrackerSD::~GammaRayTelTrackerSD() {
0073 delete[] tkrHitXID;
0074 delete[] tkrHitYID;
0075 }
0076
0077
0078
0079 void GammaRayTelTrackerSD::Initialize(G4HCofThisEvent*) {
0080 trackerCollection = new GammaRayTelTrackerHitsCollection(SensitiveDetectorName, collectionName[0]);
0081
0082 for (auto i = 0; i < numberOfTKRChannels; i++) {
0083 tkrHitXID[i] = -1;
0084 tkrHitYID[i] = -1;
0085 };
0086 }
0087
0088
0089
0090 auto GammaRayTelTrackerSD::ProcessHits(G4Step *step, G4TouchableHistory*) -> G4bool {
0091 G4double depositedEnergy = 0.;
0092 depositedEnergy = step->GetTotalEnergyDeposit();
0093 if (depositedEnergy == 0.) {
0094 return false;
0095 }
0096
0097 auto totalNumberOfStrips = detector->GetNbOfTKRStrips();
0098 auto totalnumberOfTiles = detector->GetNbOfTKRTiles();
0099
0100
0101 auto *touchable = (G4TouchableHistory*) (step->GetPreStepPoint()->GetTouchable());
0102 auto *plane = touchable->GetVolume(2);
0103
0104 G4int planeNumber = 0;
0105 planeNumber = plane->GetCopyNo();
0106 auto planeName = plane->GetName();
0107
0108
0109
0110 G4int stripNumber = 0;
0111 G4VPhysicalVolume *strip{nullptr};
0112 strip = touchable->GetVolume();
0113
0114 G4String stripName = strip->GetName();
0115 stripNumber = strip->GetCopyNo();
0116
0117 auto *tile = touchable->GetVolume(1);
0118 auto tileNumber = tile->GetCopyNo();
0119 auto tileName = tile->GetName();
0120 auto NTile = (tileNumber % totalnumberOfTiles);
0121
0122 G4int channelNumber = 0;
0123
0124 for (auto j = 0; j < totalnumberOfTiles; j++) {
0125 if (NTile == j) {
0126 stripNumber += totalNumberOfStrips * NTile;
0127 }
0128 }
0129
0130 channelNumber = planeNumber * totalnumberOfTiles * totalNumberOfStrips + stripNumber;
0131
0132
0133
0134
0135
0136
0137
0138
0139 if (planeName == "TKRDetectorX") {
0140 if (tkrHitXID[channelNumber] == -1) {
0141 auto *trackerHit = new GammaRayTelTrackerHit;
0142 trackerHit->SetPlaneType(1);
0143 trackerHit->AddDepositedEnergy(depositedEnergy);
0144 trackerHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0145 trackerHit->SetSiliconPlaneNumber(planeNumber);
0146 trackerHit->SetStripNumber(stripNumber);
0147 tkrHitXID[channelNumber] = trackerCollection->insert(trackerHit) - 1;
0148 } else {
0149 (*trackerCollection)[tkrHitXID[channelNumber]]->AddDepositedEnergy(depositedEnergy);
0150
0151 }
0152 }
0153
0154
0155 if (planeName == "TKRDetectorY") {
0156 if (tkrHitYID[channelNumber] == -1) {
0157 auto *trackerHit = new GammaRayTelTrackerHit;
0158 trackerHit->SetPlaneType(0);
0159 trackerHit->AddDepositedEnergy(depositedEnergy);
0160 trackerHit->SetPosition(step->GetPreStepPoint()->GetPosition());
0161 trackerHit->SetSiliconPlaneNumber(planeNumber);
0162 trackerHit->SetStripNumber(stripNumber);
0163 tkrHitYID[channelNumber] = trackerCollection->insert(trackerHit) - 1;
0164 } else {
0165 (*trackerCollection)[tkrHitYID[channelNumber]]->AddDepositedEnergy(depositedEnergy);
0166
0167 }
0168 }
0169
0170 return true;
0171 }
0172
0173
0174
0175 void GammaRayTelTrackerSD::EndOfEvent(G4HCofThisEvent *collection) {
0176 static G4int collectionIdentifier = -1;
0177 if (collectionIdentifier < 0) {
0178 collectionIdentifier = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0179 }
0180 collection->AddHitsCollection(collectionIdentifier, trackerCollection);
0181
0182 for (auto i = 0; i < numberOfTKRChannels; i++) {
0183 tkrHitXID[i] = -1;
0184 tkrHitYID[i] = -1;
0185 }
0186 }
0187
0188
0189
0190 void GammaRayTelTrackerSD::clear() {
0191 }
0192
0193
0194
0195 void GammaRayTelTrackerSD::DrawAll() {
0196 }
0197
0198
0199
0200 void GammaRayTelTrackerSD::PrintAll() {
0201 }