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