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