File indexing completed on 2026-03-30 07:51:08
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 #include "Par03SensitiveDetector.hh"
0030
0031 #include "Par03Hit.hh"
0032
0033 #include "G4HCofThisEvent.hh"
0034 #include "G4SDManager.hh"
0035 #include "G4Step.hh"
0036 #include "G4TouchableHistory.hh"
0037 #include "G4Track.hh"
0038
0039 Par03SensitiveDetector::Par03SensitiveDetector(G4String aName) : G4VSensitiveDetector(aName)
0040 {
0041 collectionName.insert("hits");
0042 }
0043
0044
0045 Par03SensitiveDetector::Par03SensitiveDetector(G4String aName, G4int aNumLayers, G4int aNumRho,
0046 G4int aNumPhi)
0047 : G4VSensitiveDetector(aName), fCellNoZ(aNumLayers), fCellNoRho(aNumRho), fCellNoPhi(aNumPhi)
0048 {
0049 collectionName.insert("hits");
0050 }
0051
0052
0053
0054 Par03SensitiveDetector::~Par03SensitiveDetector() = default;
0055
0056
0057
0058 void Par03SensitiveDetector::Initialize(G4HCofThisEvent* aHCE)
0059 {
0060 fHitsCollection = new Par03HitsCollection(SensitiveDetectorName, collectionName[0]);
0061 if (fHitCollectionID < 0) {
0062 fHitCollectionID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0063 }
0064 aHCE->AddHitsCollection(fHitCollectionID, fHitsCollection);
0065
0066
0067 for (G4int iphi = 0; iphi < fCellNoPhi; iphi++)
0068 for (G4int irho = 0; irho < fCellNoRho; irho++)
0069 for (G4int iz = 0; iz < fCellNoZ; iz++) {
0070 auto hit = new Par03Hit();
0071 fHitsCollection->insert(hit);
0072 }
0073 }
0074
0075
0076
0077 G4bool Par03SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0078 {
0079 G4double edep = aStep->GetTotalEnergyDeposit();
0080 if (edep == 0.) return true;
0081
0082 auto aTouchable = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
0083
0084 auto hit = RetrieveAndSetupHit(aTouchable);
0085
0086
0087 hit->AddEdep(edep);
0088
0089
0090
0091 if (hit->GetTime() == -1 || hit->GetTime() > aStep->GetTrack()->GetGlobalTime())
0092 hit->SetTime(aStep->GetTrack()->GetGlobalTime());
0093
0094
0095
0096 if (hit->GetType() != 1) hit->SetType(0);
0097
0098 return true;
0099 }
0100
0101
0102
0103 G4bool Par03SensitiveDetector::ProcessHits(const G4FastHit* aHit, const G4FastTrack* aTrack,
0104 G4TouchableHistory* aTouchable)
0105 {
0106 G4double edep = aHit->GetEnergy();
0107 if (edep == 0.) return true;
0108
0109 auto hit = RetrieveAndSetupHit(aTouchable);
0110
0111
0112 hit->AddEdep(edep);
0113
0114
0115
0116 if (hit->GetTime() == -1 || hit->GetTime() > aTrack->GetPrimaryTrack()->GetGlobalTime()) {
0117 hit->SetTime(aTrack->GetPrimaryTrack()->GetGlobalTime());
0118 }
0119
0120
0121
0122 hit->SetType(1);
0123
0124 return true;
0125 }
0126
0127
0128
0129 Par03Hit* Par03SensitiveDetector::RetrieveAndSetupHit(G4TouchableHistory* aTouchable)
0130 {
0131 G4int rhoNo = aTouchable->GetCopyNumber(0);
0132 G4int phiNo = aTouchable->GetCopyNumber(1);
0133 G4int zNo = aTouchable->GetCopyNumber(2);
0134
0135 std::size_t hitID = fCellNoRho * fCellNoZ * phiNo + fCellNoZ * rhoNo + zNo;
0136
0137 if (hitID >= fHitsCollection->entries()) {
0138 G4Exception("Par03SensitiveDetector::RetrieveAndSetupHit()", "InvalidSetup", FatalException,
0139 "Size of hit collection in Par03SensitiveDetector is smaller than the "
0140 "number of cells created in Par03DetectorConstruction!");
0141 }
0142 Par03Hit* hit = (*fHitsCollection)[hitID];
0143
0144 if (hit->GetRhoId() < 0) {
0145 hit->SetRhoId(rhoNo);
0146 hit->SetPhiId(phiNo);
0147 hit->SetZid(zNo);
0148 hit->SetLogV(aTouchable->GetVolume(0)->GetLogicalVolume());
0149 G4AffineTransform transform = aTouchable->GetHistory()->GetTopTransform();
0150 hit->SetRot(transform.NetRotation());
0151 transform.Invert();
0152 hit->SetPos(transform.NetTranslation());
0153 }
0154 return hit;
0155 }