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