ATLAS Offline Software
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 // CLHEP headers
9 #include "CLHEP/Units/SystemOfUnits.h"
10 #include "CLHEP/Units/PhysicalConstants.h"
11 
12 //Geant4 headers
13 #include "G4ParticleTypes.hh"
14 #include "G4ParticleDefinition.hh"
15 #include "G4ProcessManager.hh"
16 #include "G4OpBoundaryProcess.hh"
17 #include "G4OpProcessSubType.hh"
18 
19 ZDC_FiberSD::ZDC_FiberSD(const G4String &name, const G4String &hitCollectionName, const float &readoutPos)
20  : G4VSensitiveDetector(name), m_HitColl(hitCollectionName), m_readoutPos(readoutPos)
21 {
22 
23 }
24 
25 
27 
28 }
29 
30 void ZDC_FiberSD::Initialize(G4HCofThisEvent *)
31 {
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 */
41 G4bool ZDC_FiberSD::ProcessHits(G4Step *aStep, G4TouchableHistory *)
42 {
43  G4ThreeVector pos = aStep->GetTrack()->GetPosition();
44  G4ThreeVector momentum = aStep->GetPreStepPoint()->GetMomentum();
45 
46  /*************************************************
47  * Reject everything but optical photons
48  **************************************************/
49  if (aStep->GetTrack()->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()){
50  return true;
51  }
52 
53 
54  /*************************************************
55  * Reject downward going photons
56  **************************************************/
57  if (momentum.y() < 0.0){
58  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
59  return true;
60  }
61 
62 
63  /*************************************************
64  * Reject photons not at the boundary of two volumes
65  **************************************************/
66  G4StepPoint *endPoint = aStep->GetPostStepPoint();
67  if (endPoint->GetStepStatus() != fGeomBoundary)
68  return true;
69 
70 
71  /*************************************************
72  * Reject photons that are reflected back down
73  * from the top of the fiber
74  **************************************************/
75 
76  // Get the refractive index
77  G4MaterialPropertiesTable *MPT = aStep->GetPreStepPoint()->GetMaterial()->GetMaterialPropertiesTable();
78  if (!MPT) //Safety check
79  return true;
80  G4MaterialPropertyVector *RindexMPV = MPT->GetProperty(kRINDEX);
81  if (!RindexMPV)//Safety check
82  return true;
83 
84  G4double Rindex;
85  size_t index = 0;
86  double photonEnergy = aStep->GetTrack()->GetDynamicParticle()->GetTotalMomentum();
87  Rindex = RindexMPV->Value(photonEnergy, index);
88 
89  //Determine the photon's angle from the vertical axis
90  G4ThreeVector momDir = aStep->GetPreStepPoint()->GetMomentumDirection();
91  G4double angleFromY = atan(sqrt(1 - pow(momDir.y(), 2.0)) / momDir.y());
92 
93  // kill the photon if angle is greater than TIR critical angle
94  // We're assuming the fiber's top face's normal vector is parallel to the y axis
95  if (angleFromY > asin(1.0 / Rindex)){
96  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
97  return true;
98  }
99 
100  /*************************************************
101  * Reject photons that are not totally internally
102  * reflected inside the fiber
103  **************************************************/
104 
105  G4bool isTIR = false;
106  G4ProcessVector *postStepDoItVector = G4OpticalPhoton::OpticalPhotonDefinition()->GetProcessManager()->GetPostStepProcessVector(typeDoIt);
107  G4int n_proc = postStepDoItVector->entries();
108  for (G4int i = 0; i < n_proc; ++i){
109  G4OpBoundaryProcess *opProc = dynamic_cast<G4OpBoundaryProcess *>((*postStepDoItVector)[i]);
110  if (opProc && opProc->GetStatus() == TotalInternalReflection){
111  isTIR = true;
112  break;
113  }
114  }
115 
116  if(!isTIR){
117  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
118  return true;
119  }
120 
121  /*************************************************
122  * Simulate absorption by calculating the photon's
123  * remaining path length and rolling a random number
124  * against its absorption chance
125  **************************************************/
126  G4MaterialPropertyVector *AbsMPV = MPT->GetProperty(kABSLENGTH);
127  G4double Absorption = AbsMPV->Value(aStep->GetTrack()->GetDynamicParticle()->GetTotalMomentum(), index);
128 
129  G4double pathLength = (m_readoutPos - pos.y()) / cos(angleFromY);
130  G4double absChance = 1 - exp(-pathLength / Absorption);
131 
132  // This check amounts to if(absorbed)
133  if (CLHEP::RandFlat::shoot(0.0, 1.0) < absChance){
134  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
135  return true;
136  }
137 
138  /*************************************************
139  * Record the survivors
140  **************************************************/
141 
142  //Get the hash for this volume to keep track of hits
143  Identifier id;
144  id = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetCopyNo();
145  uint32_t hash = id.get_identifier32().get_compact();
146 
148 
149  if(it == m_hitMap.end()){
150  //This is a new hit
151  ZDC_SimFiberHit *hit = new ZDC_SimFiberHit(id, 1, photonEnergy);
152  m_hitMap.insert(std::pair<uint32_t,ZDC_SimFiberHit*>(hash,hit));
153  }else{
154  it->second->Add(1, photonEnergy);
155  }
156 
157  /*************************************************
158  * Put the survivors out of their misery
159  **************************************************/
160  aStep->GetTrack()->SetTrackStatus(fStopAndKill);
161  return true;
162 }
163 
165 {
166 
167  //Move the hits from the hit set to the hit container
168  if (!m_HitColl.isValid())
169  m_HitColl = std::make_unique<ZDC_SimFiberHit_Collection>(m_HitColl.name());
170 
171  for(auto hit : m_hitMap){
172  m_HitColl->Emplace(*(hit.second));
173  }
174 
175 
176  if (verboseLevel > 5){
177  G4cout << "ZDC_FiberSD::EndOfAthenaEvent(): Printing Final Energy(eV) deposited in Fibers " << G4endl;
178 
179  int photonCount = 0;
180  float energyTotal = 0;
181  for(auto hit : m_hitMap){
182  photonCount += hit.second->getNPhotons();
183  energyTotal += hit.second->getEdep();
184  }
185 
186  G4cout << "ZDC_FiberSD::EndOfAthenaEvent(): Final Energy(eV) deposited in Fiber "
187  << energyTotal << " ev and Number of Photons deposited = " << photonCount
188  << " across " << m_hitMap.size() << " volumes" << G4endl;
189 
190  }
191  //Reset hit container
192  m_hitMap.clear();
193 
194  return;
195 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
skel.it
it
Definition: skel.GENtoEVGEN.py:396
ZDC_FiberSD::m_readoutPos
float m_readoutPos
Definition: ZDC_FiberSD.h:45
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ZDC_FiberSD.h
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
ZDC_FiberSD::EndOfAthenaEvent
void EndOfAthenaEvent()
Definition: ZDC_FiberSD.cxx:164
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
ZDC_FiberSD::ZDC_FiberSD
ZDC_FiberSD(const G4String &name, const G4String &hitCollectionName, const float &readoutPos)
Definition: ZDC_FiberSD.cxx:19
AtlasHitsVector::Emplace
void Emplace(Args &&... args)
Definition: AtlasHitsVector.h:81
ZDC_FiberSD::Initialize
void Initialize(G4HCofThisEvent *) override final
Definition: ZDC_FiberSD.cxx:30
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ZDC_FiberSD::~ZDC_FiberSD
~ZDC_FiberSD()
Definition: ZDC_FiberSD.cxx:26
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DeMoScan.index
string index
Definition: DeMoScan.py:364
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ZDC_FiberSD::m_hitMap
std::map< uint32_t, ZDC_SimFiberHit * > m_hitMap
Definition: ZDC_FiberSD.h:44
ZDC_FiberSD::m_HitColl
SG::WriteHandle< ZDC_SimFiberHit_Collection > m_HitColl
Definition: ZDC_FiberSD.h:43
ZDC_SimFiberHit
Definition: ZDC_SimFiberHit.h:11
ZDC_FiberSD::ProcessHits
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Definition: ZDC_FiberSD.cxx:41
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
Identifier
Definition: IdentifierFieldParser.cxx:14