File indexing completed on 2026-03-28 07:51:00
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 "WLSPhotonDetSD.hh"
0030
0031 #include "WLSPhotonDetHit.hh"
0032 #include "WLSUserTrackInformation.hh"
0033
0034 #include "G4OpticalPhoton.hh"
0035 #include "G4SDManager.hh"
0036 #include "G4Step.hh"
0037 #include "G4ThreeVector.hh"
0038 #include "G4TouchableHistory.hh"
0039 #include "G4Track.hh"
0040 #include "G4VTouchable.hh"
0041
0042
0043
0044 WLSPhotonDetSD::WLSPhotonDetSD(G4String name) : G4VSensitiveDetector(name)
0045 {
0046 collectionName.insert("PhotonDetHitCollection");
0047 }
0048
0049
0050
0051 void WLSPhotonDetSD::Initialize(G4HCofThisEvent* HCE)
0052 {
0053 fPhotonDetHitCollection =
0054 new WLSPhotonDetHitsCollection(SensitiveDetectorName, collectionName[0]);
0055
0056 if (fHCID < 0) {
0057 fHCID = G4SDManager::GetSDMpointer()->GetCollectionID(fPhotonDetHitCollection);
0058 }
0059 HCE->AddHitsCollection(fHCID, fPhotonDetHitCollection);
0060 }
0061
0062
0063
0064 G4bool WLSPhotonDetSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
0065 {
0066 if (!aStep) return false;
0067 G4Track* theTrack = aStep->GetTrack();
0068
0069
0070 if (theTrack->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()) {
0071 return false;
0072 }
0073
0074
0075 G4StepPoint* thePostPoint = aStep->GetPostStepPoint();
0076
0077 auto trackInformation = (WLSUserTrackInformation*)theTrack->GetUserInformation();
0078
0079 auto theTouchable = (G4TouchableHistory*)(thePostPoint->GetTouchable());
0080
0081 G4ThreeVector photonExit = trackInformation->GetExitPosition();
0082 G4ThreeVector photonArrive = thePostPoint->GetPosition();
0083 G4double arrivalTime = theTrack->GetGlobalTime();
0084 G4double energy = theTrack->GetTotalEnergy();
0085
0086
0087
0088 photonArrive = theTouchable->GetHistory()->GetTopTransform().TransformPoint(photonArrive);
0089
0090
0091 fPhotonDetHitCollection->insert(
0092 new WLSPhotonDetHit(photonExit, photonArrive, arrivalTime, energy));
0093
0094 return true;
0095 }
0096
0097 void WLSPhotonDetSD::EndOfEvent(G4HCofThisEvent*)
0098 {
0099 if (verboseLevel > 1) {
0100 G4int nofHits = fPhotonDetHitCollection->entries();
0101 G4cout << G4endl << "-------->Hits Collection: in this event there are " << nofHits
0102 << " hits in the photon detector: " << G4endl;
0103 for (G4int i = 0; i < nofHits; i++)
0104 (*fPhotonDetHitCollection)[i]->Print();
0105 }
0106 }