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