ATLAS Offline Software
TRTSensitiveDetector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 // Class header
7 #include "TRTSensitiveDetector.h"
8 
9 // Athena includes
10 #include "TRT_G4Utilities/TRTParameters.hh"
11 #include "TRT_G4Utilities/TRTOutputFile.hh"
16 
17 //Geant4 includes
18 //#include "Randomize.hh"
19 #include "G4TouchableHistory.hh"
20 #include "G4Step.hh"
21 #include "G4Track.hh"
22 #include "G4VProcess.hh"
23 #include "G4ParticleDefinition.hh"
24 #include "G4StepPoint.hh"
25 #include "G4ThreeVector.hh"
26 #include "G4Geantino.hh"
27 #include "G4ChargedGeantino.hh"
28 #include "G4Gamma.hh"
29 #include "G4Electron.hh"
30 #include "G4Positron.hh"
31 #include "G4ProcessManager.hh"
32 #include "G4ProcessVector.hh"
33 #include "G4GammaGeneralProcess.hh"
34 #include "G4NistManager.hh"
35 
36 //stl includes
37 #include <cmath>
38 #include <memory> // For make unique
39 #include <utility>
40 
41 TRTSensitiveDetector::TRTSensitiveDetector(const std::string& name, const std::string& hitCollectionName, int setVerboseLevel)
42  : G4VSensitiveDetector( name ),
43  //Variables properly set during InitializeHitProcessing() method
44  m_hitsWithZeroEnergyDeposit(0), m_phot(nullptr),
45  m_energyThreshold(0.0), m_probabilityThreshold(0.0), m_energyDepositCorrection(0.0),
46  m_energyThresholdKr(0.0), m_probabilityThresholdKr(0.0), m_energyDepositCorrectionKr(0.0),
47  m_energyThresholdAr(0.0), m_probabilityThresholdAr(0.0), m_energyDepositCorrectionAr(0.0),
48  m_boundaryZ(0.0),
49  //End of variables properly set during InitializeHitProcessing() method
50  //Properties of current TRTUncompressedHit
51  m_hitID(0), m_particleEncoding(0), m_kineticEnergy(0.0),
52  m_energyDeposit(0.0), m_energyDepositInKeV(0.0), m_preStepX(0.0),
53  m_preStepY(0.0), m_preStepZ(0.0), m_postStepX(0.0), m_postStepY(0.0),
54  m_postStepZ(0.0), m_globalTime(0.0),
55  //End of Properties of current TRTUncompressedHit
56  m_HitColl( hitCollectionName ), m_pParameters(nullptr),
57  m_pProcessingOfBarrelHits(nullptr), m_pProcessingOfEndCapHits(nullptr),
58  m_pMaterialXe(nullptr), m_pMaterialKr(nullptr), m_pMaterialAr(nullptr)
59 {
60  m_pParameters = TRTParameters::GetPointer();
61 
62  m_printMessages = m_pParameters->GetInteger("PrintMessages"); //FIXME not used - remove?
63  verboseLevel = setVerboseLevel;
64 
66 
67  m_pParameters = nullptr;
68 }
69 
70 
71 // Called by TRTSensitiveDetector
72 // Once per run
73 
75 {
76  if(verboseLevel>4)
77  {
78  G4cout << GetName() << " InitializeHitProcessing()" << G4endl;
79  }
81  m_pParameters->GetInteger("HitsWithZeroEnergyDeposit");
82 
83  m_phot = nullptr;
84 
85  // Parameters describing flourecense in Xe gas mixture:
86  // Units of these numbers in management file are in keV; change to default units
87 
88  m_energyThreshold = m_pParameters->GetDouble("EnergyThreshold" ) * CLHEP::keV;
89  m_energyThresholdKr = m_pParameters->GetDouble("EnergyThresholdKr") * CLHEP::keV;
90  m_energyThresholdAr = m_pParameters->GetDouble("EnergyThresholdAr") * CLHEP::keV;
91  m_probabilityThreshold = m_pParameters->GetDouble("ProbabilityThreshold" );
92  m_probabilityThresholdKr = m_pParameters->GetDouble("ProbabilityThresholdKr");
93  m_probabilityThresholdAr = m_pParameters->GetDouble("ProbabilityThresholdAr");
94  m_energyDepositCorrection = m_pParameters->GetDouble("EnergyDepositCorrection" ) * CLHEP::keV;
95  m_energyDepositCorrectionKr = m_pParameters->GetDouble("EnergyDepositCorrectionKr") * CLHEP::keV;
96  m_energyDepositCorrectionAr = m_pParameters->GetDouble("EnergyDepositCorrectionAr") * CLHEP::keV;
97  if(verboseLevel>9)
98  {
99  G4cout << GetName() << " Fluorescence parameters: EnergyThreshold "
100  << m_energyThreshold << G4endl;
101  G4cout << GetName() << " Fluorescence parameters: EnergyThresholdKr "
102  << m_energyThresholdKr << G4endl;
103  G4cout << GetName() << " Fluorescence parameters: EnergyThresholdAr "
104  << m_energyThresholdAr << G4endl;
105  G4cout << GetName() << " Fluorescence parameters: ProbabilityThreshold "
106  << m_probabilityThreshold << G4endl;
107  G4cout << GetName() << " Fluorescence parameters: ProbabilityThresholdKr "
108  << m_probabilityThresholdKr << G4endl;
109  G4cout << GetName() << " Fluorescence parameters: ProbabilityThresholdAr "
110  << m_probabilityThresholdAr << G4endl;
111  G4cout << GetName() << " Fluorescence parameters: EnergyDepositCorrection "
112  << m_energyDepositCorrection << G4endl;
113  G4cout << GetName() << " Fluorescence parameters: EnergyDepositCorrectionKr "
114  << m_energyDepositCorrectionKr << G4endl;
115  G4cout << GetName() << " Fluorescence parameters: EnergyDepositCorrectionAr "
116  << m_energyDepositCorrectionAr << G4endl;
117  }
118  m_boundaryZ = m_pParameters->GetDouble("LengthOfBarrelVolume") / 2.;
119 
120  TRTParametersForBarrelHits* pParametersForBarrelHits = nullptr;
121  TRTParametersForEndCapHits* pParametersForEndCapHits = nullptr;
122 
125 
126  pParametersForBarrelHits =
128  pParametersForEndCapHits =
130 
131  delete pParametersForBarrelHits;
132  delete pParametersForEndCapHits;
133 
134  // Get nist material manager
135  G4NistManager* nist = G4NistManager::Instance();
136  m_pMaterialXe = nist->FindOrBuildMaterial("trt::XeCO2O2");
137  if (!m_pMaterialXe && verboseLevel>4)
138  {
139  G4cout << GetName() << " Could not find Xe material (Only OK if no TRT straws are filled with Xenon)" << G4endl;
140  }
141  m_pMaterialKr = nist->FindOrBuildMaterial("trt::KrCO2O2");
142  if (!m_pMaterialKr && verboseLevel>4)
143  {
144  G4cout << GetName() << " Could not find Kr material (Only OK if no TRT straws are filled with Krypton)" << G4endl;
145  }
146  m_pMaterialAr = nist->FindOrBuildMaterial("trt::ArCO2O2");
147  if (!m_pMaterialAr && verboseLevel>4)
148  {
149  G4cout << GetName() << " Could not find Ar material (Only OK if no TRT straws are filled with Argon)" << G4endl;
150  }
152  {
153  G4ExceptionDescription description;
154  description << "InitializeHitProcessing: Could not find Xe, Kr or Ar materials (Not OK!)";
155  G4Exception("TRTSensitiveDetector", "NoTRTGasesFound", FatalException, description);
156  }
157 
158  if(verboseLevel>4)
159  {
160  G4cout << GetName() << " InitializeHitProcessing() done" << G4endl;
161  }
162 }
163 
164 
165 // Called by Geant4
166 // For each event
167 
168 void TRTSensitiveDetector::Initialize(G4HCofThisEvent* /*pHCofThisEvent*/)
169 {
170  if(verboseLevel>4)
171  {
172  G4cout << GetName() << " Initialize()" << G4endl;
173  }
174 
175  // The following code etablishes a pointer to the "phot" process.
176  // This pointer is used in ProcessHits.
177  // For performance reasons we test directly on the pointer address rather
178  // than doing the string comparison for each hit in ProcessHits.
179 
180  if(!m_phot) { // Only for the first event
181  const G4ProcessVector* pVec =
182  G4Gamma::Definition()->GetProcessManager()->GetProcessList();
183  for(size_t ip=0;ip<pVec->entries();ip++)
184  {
185  if((*pVec)[ip]->GetProcessName()=="phot")
186  {
187  m_phot = (*pVec)[ip];
188  break;
189  }
190  if((*pVec)[ip]->GetProcessName()=="GammaGeneralProc")
191  {
192  G4GammaGeneralProcess *genproc = static_cast<G4GammaGeneralProcess*>((*pVec)[ip]);
193  G4VEmProcess *proc = genproc->GetEmProcess("phot");
194  if (proc && proc->GetProcessName()=="phot")
195  {
196  m_phot = proc;
197  break;
198  }
199  }
200  }
201  }
202  if(!m_phot) {
203  G4cout << GetName() << "ERROR Did not find the photoelectic process!!!" << G4endl;
204  }
205 
206 
207  if (!m_HitColl.isValid()) m_HitColl = std::make_unique<TRTUncompressedHitCollection>();
208 
209  if(verboseLevel>4)
210  {
211  G4cout << GetName() << " Initialize() done" << G4endl;
212  }
213 }
214 
215 
216 
217 // Called by Geant4
218 
220  G4TouchableHistory* /*pTouchableHistory*/)
221 {
222  m_energyDeposit = pStep->GetTotalEnergyDeposit();
223 
224  G4Track* pTrack = pStep->GetTrack();
225  G4ParticleDefinition* pParticleDefinition = pTrack->GetDefinition();
226 
227  // Skip particles which deposit no energy
229  {
230  if ( pParticleDefinition != G4Geantino::Definition() &&
231  pParticleDefinition != G4ChargedGeantino::Definition() )
232  {
233  return false;
234  }
235  }
236 
237  // Skip electrons which originate from a photoelectric process.
238  // These electrons have very low energy and even the PAI model will
239  // give the wrong energy deposit.
240  // Instead we count for a photon which undergoes a "phot" reaction
241  // the full energy as deposited in the interaction point (see below)
242  if(pTrack->GetCreatorProcess()==m_phot)
243  {
244  return false;
245  }
246 
247  // Get kinetic energy of depositing particle
248  m_kineticEnergy = pStep->GetPreStepPoint()->GetKineticEnergy();
249 
250  // If we are dealing with a photon undergoing a "phot" reaction, count
251  // the photon kinetic energy as deposited energy in the point of
252  // the reaction
253 
254  if ( pParticleDefinition==G4Gamma::GammaDefinition() &&
255  pStep->GetPostStepPoint()->GetProcessDefinedStep()==m_phot )
256  {
258  double current_energyThreshold = 1E+99;
259  double current_probabilityThreshold = 2.0;
260  double current_energyDepositCorrection = 0.0;
261  G4Material *pPreStepMaterial = pStep->GetPreStepPoint()->GetMaterial();
262  if (pPreStepMaterial == m_pMaterialXe)
263  {
264  current_energyThreshold = m_energyThreshold;
265  current_probabilityThreshold = m_probabilityThreshold;
266  current_energyDepositCorrection = m_energyDepositCorrection;
267  }
268  else if (pPreStepMaterial == m_pMaterialKr)
269  {
270  current_energyThreshold = m_energyThresholdKr;
271  current_probabilityThreshold = m_probabilityThresholdKr;
272  current_energyDepositCorrection = m_energyDepositCorrectionKr;
273  }
274  else if (pPreStepMaterial == m_pMaterialAr)
275  {
276  current_energyThreshold = m_energyThresholdAr;
277  current_probabilityThreshold = m_probabilityThresholdAr;
278  current_energyDepositCorrection = m_energyDepositCorrectionAr;
279  }
280  else
281  {
282  G4ExceptionDescription description;
283  description << "ProcessHits: Unknown prestep material";
284  G4Exception("TRTSensitiveDetector", "UnknownGasFound", FatalException, description);
285  return false; //The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
286  }
287  // Correct for flourescence (a la Nevski):
288  // - For some percentage (15%) of photons with
289  // energy above threshold (4.9 keV) reduce deposited energy
290  // by correction (4.0 keV)
291  // (Different numbers for Ar and Kr)
292  if ( m_energyDeposit > current_energyThreshold &&
293  CLHEP::RandFlat::shoot() > current_probabilityThreshold )
294  {
295  m_energyDeposit -= current_energyDepositCorrection;
296  }
297  }
298 
299 
300  // Particle code of depositing particle
301  m_particleEncoding = pParticleDefinition->GetPDGEncoding();
302 
303  bool trackerHit = false;
304 
305  if ( std::fabs(pStep->GetPreStepPoint()->GetPosition().z()) < m_boundaryZ )
306  {
307  trackerHit = m_pProcessingOfBarrelHits->ProcessHit(pStep);
308  }
309  else
310  {
311  trackerHit = m_pProcessingOfEndCapHits->ProcessHit(pStep);
312  }
313 
314  // TRTUncompressedHit appearently expects energyDeposit in keV.
315  // Convert:
317 
318  // Create UncompressedHit
319 
320  if (trackerHit)
321  {
322  // Build the hit straight onto the vector
324  (float) m_kineticEnergy, (float) m_energyDepositInKeV,
325  (float) m_preStepX, (float) m_preStepY, (float) m_preStepZ,
326  (float) m_postStepX, (float) m_postStepY, (float) m_postStepZ,
327  (float) m_globalTime );
328  }
329 
330  return true;
331 }
332 
333 
334 // It was called by TRTRunAction::EndOfRunAction ...
335 
337 {
338  if(verboseLevel>4)
339  {
340  G4cout << GetName() << " DeleteObjects()" << G4endl;
341  }
342 
345 
346  if(verboseLevel>4)
347  {
348  G4cout << GetName() << " DeleteObjects() done" << G4endl;
349  }
350 }
TRTSensitiveDetector::m_energyDepositInKeV
double m_energyDepositInKeV
Definition: TRTSensitiveDetector.h:74
TRTSensitiveDetector::m_pProcessingOfBarrelHits
TRTProcessingOfBarrelHits * m_pProcessingOfBarrelHits
Definition: TRTSensitiveDetector.h:89
TRTParametersForEndCapHits.h
TRTSensitiveDetector::m_energyDepositCorrectionKr
double m_energyDepositCorrectionKr
Definition: TRTSensitiveDetector.h:61
TRTSensitiveDetector::m_pMaterialAr
G4Material * m_pMaterialAr
Definition: TRTSensitiveDetector.h:95
TRTSensitiveDetector::m_energyThreshold
double m_energyThreshold
Definition: TRTSensitiveDetector.h:56
TRTSensitiveDetector::m_energyDeposit
double m_energyDeposit
Definition: TRTSensitiveDetector.h:73
TRTProcessingOfEndCapHits.h
TRTSensitiveDetector::DeleteObjects
void DeleteObjects()
Called by TRTRunAction::EndOfRunAction ...
Definition: TRTSensitiveDetector.cxx:336
TRTSensitiveDetector::m_HitColl
SG::WriteHandle< TRTUncompressedHitCollection > m_HitColl
Other member variables.
Definition: TRTSensitiveDetector.h:85
TRTSensitiveDetector::m_probabilityThresholdAr
double m_probabilityThresholdAr
Definition: TRTSensitiveDetector.h:63
TRTSensitiveDetector::m_hitsWithZeroEnergyDeposit
int m_hitsWithZeroEnergyDeposit
Definition: TRTSensitiveDetector.h:54
TRTSensitiveDetector::m_pProcessingOfEndCapHits
TRTProcessingOfEndCapHits * m_pProcessingOfEndCapHits
Definition: TRTSensitiveDetector.h:90
TRTSensitiveDetector::m_energyThresholdAr
double m_energyThresholdAr
Definition: TRTSensitiveDetector.h:62
TRTSensitiveDetector::m_probabilityThresholdKr
double m_probabilityThresholdKr
Definition: TRTSensitiveDetector.h:60
TRTSensitiveDetector::m_partLink
HepMcParticleLink m_partLink
Definition: TRTSensitiveDetector.h:70
python.SystemOfUnits.keV
int keV
Definition: SystemOfUnits.py:156
TRTSensitiveDetector::m_postStepX
double m_postStepX
Definition: TRTSensitiveDetector.h:78
TRTSensitiveDetector::m_energyDepositCorrectionAr
double m_energyDepositCorrectionAr
Definition: TRTSensitiveDetector.h:64
TRTParametersForEndCapHits
Definition: TRTParametersForEndCapHits.h:14
TRTSensitiveDetector::m_pMaterialKr
G4Material * m_pMaterialKr
Definition: TRTSensitiveDetector.h:94
TRTSensitiveDetector::m_globalTime
double m_globalTime
Definition: TRTSensitiveDetector.h:81
TRTSensitiveDetector::m_kineticEnergy
double m_kineticEnergy
Definition: TRTSensitiveDetector.h:72
TRTParametersForBarrelHits
Definition: TRTParametersForBarrelHits.h:14
TRTSensitiveDetector.h
TRTSensitiveDetector::m_postStepY
double m_postStepY
Definition: TRTSensitiveDetector.h:79
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
TRTSensitiveDetector::TRTProcessingOfEndCapHits
friend class TRTProcessingOfEndCapHits
Definition: TRTSensitiveDetector.h:31
TRTSensitiveDetector::m_pMaterialXe
G4Material * m_pMaterialXe
Definition: TRTSensitiveDetector.h:93
TRTSensitiveDetector::m_probabilityThreshold
double m_probabilityThreshold
Definition: TRTSensitiveDetector.h:57
TRTSensitiveDetector::m_preStepX
double m_preStepX
Definition: TRTSensitiveDetector.h:75
TRTSensitiveDetector::m_boundaryZ
double m_boundaryZ
Definition: TRTSensitiveDetector.h:65
TRTSensitiveDetector::m_energyThresholdKr
double m_energyThresholdKr
Definition: TRTSensitiveDetector.h:59
TRTProcessingOfBarrelHits.h
mc.proc
proc
Definition: mc.PhPy8EG_A14NNPDF23_gg4l_example.py:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TRTSensitiveDetector::ProcessHits
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Definition: TRTSensitiveDetector.cxx:219
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
TRTSensitiveDetector::TRTProcessingOfBarrelHits
friend class TRTProcessingOfBarrelHits
Definition: TRTSensitiveDetector.h:30
TRTSensitiveDetector::m_pParameters
const TRTParameters * m_pParameters
Definition: TRTSensitiveDetector.h:87
TRTSensitiveDetector::m_preStepY
double m_preStepY
Definition: TRTSensitiveDetector.h:76
TRTSensitiveDetector::m_postStepZ
double m_postStepZ
Definition: TRTSensitiveDetector.h:80
TRTProcessingOfBarrelHits::ProcessHit
bool ProcessHit(G4Step *)
Definition: TRTProcessingOfBarrelHits.cxx:123
TRTSensitiveDetector::m_energyDepositCorrection
double m_energyDepositCorrection
Definition: TRTSensitiveDetector.h:58
TRTSensitiveDetector::m_preStepZ
double m_preStepZ
Definition: TRTSensitiveDetector.h:77
TRTProcessingOfEndCapHits::ProcessHit
bool ProcessHit(G4Step *)
Definition: TRTProcessingOfEndCapHits.cxx:87
TRTParametersForBarrelHits.h
TRTSensitiveDetector::Initialize
void Initialize(G4HCofThisEvent *) override final
Definition: TRTSensitiveDetector.cxx:168
TRTSensitiveDetector::InitializeHitProcessing
void InitializeHitProcessing()
Definition: TRTSensitiveDetector.cxx:74
TRTSensitiveDetector::m_particleEncoding
int m_particleEncoding
Definition: TRTSensitiveDetector.h:71
TRTSensitiveDetector::m_printMessages
int m_printMessages
Configuration paremeters.
Definition: TRTSensitiveDetector.h:53
TRTSensitiveDetector::m_hitID
int m_hitID
Properties of current TRTUncompressedHit, set by TRTProcessingOfBarrelHits and TRTProcessingOfEndCapH...
Definition: TRTSensitiveDetector.h:69
TRTSensitiveDetector::m_phot
G4VProcess * m_phot
Definition: TRTSensitiveDetector.h:55
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88
TRTSensitiveDetector::TRTSensitiveDetector
TRTSensitiveDetector(const std::string &name, const std::string &hitCollectionName, int setVerboseLevel=0)
Definition: TRTSensitiveDetector.cxx:41