ATLAS Offline Software
Loading...
Searching...
No Matches
ZDC_FiberSD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Class header
6#include "ZDC_FiberSD.h"
7
8// Athena headers
11
12// CLHEP headers
13#include "CLHEP/Units/SystemOfUnits.h"
14#include "CLHEP/Units/PhysicalConstants.h"
15
16//Geant4 headers
17#include "G4ParticleTypes.hh"
18#include "G4ParticleDefinition.hh"
19#include "G4ProcessManager.hh"
20#include "G4OpBoundaryProcess.hh"
21#include "G4OpProcessSubType.hh"
22
23ZDC_FiberSD::ZDC_FiberSD(const G4String &name, const G4String &hitCollectionName, const float &readoutPos)
24 : G4VSensitiveDetector(name), m_hitCollectionName(hitCollectionName), m_readoutPos(readoutPos)
25{
26
27}
28
29void ZDC_FiberSD::Initialize(G4HCofThisEvent *)
30{
32}
33
34/*
35 * The goal of process hits for this SD is to find optical photons that are
36 * totally internally reflected on the side walls the optical fiber, while not
37 * also being reflected back down when it reaches the top of the fiber.
38 * This is done on the track's first step by looking at the PostStepProcessVector
39 * for the TotalInternalReflection optical process
40*/
41G4bool ZDC_FiberSD::ProcessHits(G4Step *aStep, G4TouchableHistory *)
42{
43 if (!m_HitColl) {
45 if (!m_HitColl) {
46 return false;
47 }
48 }
49
50 G4ThreeVector pos = aStep->GetTrack()->GetPosition();
51 G4ThreeVector momentum = aStep->GetPreStepPoint()->GetMomentum();
52
53 /*************************************************
54 * Reject everything but optical photons
55 **************************************************/
56 if (aStep->GetTrack()->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()){
57 return true;
58 }
59
60
61 /*************************************************
62 * Reject downward going photons
63 **************************************************/
64 if (momentum.y() < 0.0){
65 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
66 return true;
67 }
68
69
70 /*************************************************
71 * Reject photons not at the boundary of two volumes
72 **************************************************/
73 G4StepPoint *endPoint = aStep->GetPostStepPoint();
74 if (endPoint->GetStepStatus() != fGeomBoundary)
75 return true;
76
77
78 /*************************************************
79 * Reject photons that are reflected back down
80 * from the top of the fiber
81 **************************************************/
82
83 // Get the refractive index
84 G4MaterialPropertiesTable *MPT = aStep->GetPreStepPoint()->GetMaterial()->GetMaterialPropertiesTable();
85 if (!MPT) //Safety check
86 return true;
87 G4MaterialPropertyVector *RindexMPV = MPT->GetProperty(kRINDEX);
88 if (!RindexMPV)//Safety check
89 return true;
90
91 G4double Rindex;
92 size_t index = 0;
93 double photonEnergy = aStep->GetTrack()->GetDynamicParticle()->GetTotalMomentum();
94 Rindex = RindexMPV->Value(photonEnergy, index);
95
96 //Determine the photon's angle from the vertical axis
97 G4ThreeVector momDir = aStep->GetPreStepPoint()->GetMomentumDirection();
98 G4double angleFromY = atan(sqrt(1 - pow(momDir.y(), 2.0)) / momDir.y());
99
100 // kill the photon if angle is greater than TIR critical angle
101 // We're assuming the fiber's top face's normal vector is parallel to the y axis
102 if (angleFromY > asin(1.0 / Rindex)){
103 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
104 return true;
105 }
106
107 /*************************************************
108 * Reject photons that are not totally internally
109 * reflected inside the fiber
110 **************************************************/
111
112 G4bool isTIR = false;
113 G4ProcessVector *postStepDoItVector = G4OpticalPhoton::OpticalPhotonDefinition()->GetProcessManager()->GetPostStepProcessVector(typeDoIt);
114 G4int n_proc = postStepDoItVector->entries();
115 for (G4int i = 0; i < n_proc; ++i){
116 G4OpBoundaryProcess *opProc = dynamic_cast<G4OpBoundaryProcess *>((*postStepDoItVector)[i]);
117 if (opProc && opProc->GetStatus() == TotalInternalReflection){
118 isTIR = true;
119 break;
120 }
121 }
122
123 if(!isTIR){
124 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
125 return true;
126 }
127
128 /*************************************************
129 * Simulate absorption by calculating the photon's
130 * remaining path length and rolling a random number
131 * against its absorption chance
132 **************************************************/
133 G4MaterialPropertyVector *AbsMPV = MPT->GetProperty(kABSLENGTH);
134 G4double Absorption = AbsMPV->Value(aStep->GetTrack()->GetDynamicParticle()->GetTotalMomentum(), index);
135
136 G4double pathLength = (m_readoutPos - pos.y()) / cos(angleFromY);
137 G4double absChance = 1 - exp(-pathLength / Absorption);
138
139 // This check amounts to if(absorbed)
140 if (CLHEP::RandFlat::shoot(0.0, 1.0) < absChance){
141 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
142 return true;
143 }
144
145 /*************************************************
146 * Record the survivors
147 **************************************************/
148
149 Identifier id;
150 id = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
151 m_HitColl->AddHit(id, photonEnergy);
152
153 /*************************************************
154 * Put the survivors out of their misery
155 **************************************************/
156 aStep->GetTrack()->SetTrackStatus(fStopAndKill);
157 return true;
158}
159
161{
162 auto* eventInfo = AtlasG4EventUserInfo::GetEventUserInfo();
163 if (!eventInfo) {
164 return nullptr;
165 }
166 auto hitCollections = eventInfo->GetHitCollectionMap();
167 return hitCollections ? hitCollections->Find<ZDC_SimFiberHitCollectionBuilder>(m_hitCollectionName) : nullptr;
168}
static AtlasG4EventUserInfo * GetEventUserInfo()
void Initialize(G4HCofThisEvent *) override final
float m_readoutPos
Definition ZDC_FiberSD.h:40
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
ZDC_FiberSD(const G4String &name, const G4String &hitCollectionName, const float &readoutPos)
std::string m_hitCollectionName
Definition ZDC_FiberSD.h:37
ZDC_SimFiberHitCollectionBuilder * m_HitColl
Definition ZDC_FiberSD.h:39
ZDC_SimFiberHitCollectionBuilder * getHitCollection() const
Definition index.py:1