File indexing completed on 2026-03-30 07:49:56
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 "HodoscopeSD.hh"
0030
0031 #include "HodoscopeHit.hh"
0032
0033 #include "G4AffineTransform.hh"
0034 #include "G4HCofThisEvent.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Step.hh"
0037 #include "G4StepPoint.hh"
0038 #include "G4VPhysicalVolume.hh"
0039 #include "G4VTouchable.hh"
0040
0041 namespace B5
0042 {
0043
0044
0045
0046 HodoscopeSD::HodoscopeSD(G4String name) : G4VSensitiveDetector(name)
0047 {
0048 collectionName.insert("hodoscopeColl");
0049 }
0050
0051
0052
0053 void HodoscopeSD::Initialize(G4HCofThisEvent* hce)
0054 {
0055 fHitsCollection = new HodoscopeHitsCollection(SensitiveDetectorName, collectionName[0]);
0056 if (fHCID < 0) {
0057 fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fHitsCollection);
0058 }
0059 hce->AddHitsCollection(fHCID, fHitsCollection);
0060 }
0061
0062
0063
0064 G4bool HodoscopeSD::ProcessHits(G4Step* step, G4TouchableHistory*)
0065 {
0066 auto edep = step->GetTotalEnergyDeposit();
0067 if (edep == 0.) return true;
0068
0069 auto preStepPoint = step->GetPreStepPoint();
0070 auto touchable = preStepPoint->GetTouchable();
0071 auto copyNo = touchable->GetVolume()->GetCopyNo();
0072 auto hitTime = preStepPoint->GetGlobalTime();
0073
0074
0075 auto ix = -1;
0076 for (std::size_t i = 0; i < fHitsCollection->entries(); ++i) {
0077 if ((*fHitsCollection)[i]->GetID() == copyNo) {
0078 ix = i;
0079 break;
0080 }
0081 }
0082
0083 if (ix >= 0) {
0084
0085 if ((*fHitsCollection)[ix]->GetTime() > hitTime) {
0086 (*fHitsCollection)[ix]->SetTime(hitTime);
0087 }
0088 }
0089 else {
0090
0091 auto hit = new HodoscopeHit(copyNo, hitTime);
0092 auto physical = touchable->GetVolume();
0093 hit->SetLogV(physical->GetLogicalVolume());
0094 auto transform = touchable->GetHistory()->GetTopTransform();
0095 transform.Invert();
0096 hit->SetRot(transform.NetRotation());
0097 hit->SetPos(transform.NetTranslation());
0098 fHitsCollection->insert(hit);
0099 }
0100 return true;
0101 }
0102
0103
0104
0105 }