ATLAS Offline Software
TRTDigCondBase.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRT_DIGITIZATION_TRTDIGCONDBASE_H
6 #define TRT_DIGITIZATION_TRTDIGCONDBASE_H
7 
10 #include "TRT_ConditionsServices/ITRT_StrawStatusSummaryTool.h" // added by Sasha for Argon
11 
12 #include "GaudiKernel/ServiceHandle.h"
13 #include "GaudiKernel/ToolHandle.h"
14 
15 
16 #include <atomic>
17 #include <map>
18 #include <mutex>
19 
20 class TRT_ID;
21 class Identifier;
22 
23 namespace CLHEP{
24  class HepRandomEngine;
25 }
26 
27 namespace InDetDD {
28  class TRT_DetectorManager;
29 }
30 class TRTDigSettings;
34 class TRTDigCondBase : public AthMessaging {
35 
36 public:
37 
41  const TRT_ID*,
42  int UseGasMix,
43  ToolHandle<ITRT_StrawStatusSummaryTool> sumTool
44  );
45 
47  virtual ~TRTDigCondBase() {};
48 
52  void initialize(CLHEP::HepRandomEngine* rndmEngine);
53 
55  float strawAverageNoiseLevel() const; //[first time slow, else fast]
56 
58  unsigned int totalNumberOfActiveStraws() const; //[fast]
59 
69  void getStrawData( const int& hitID,
70  double& lowthreshold,
71  double& noiseamplitude ) const;
72 
73  //--- For noise in unhit straws:
74 
79 
85  bool getNextNoisyStraw( CLHEP::HepRandomEngine*, int& hitID, float& noiselevel );
86 
87 
88  //Crosstalk noise
89  bool crossTalkNoise( CLHEP::HepRandomEngine* ) const;
90  bool crossTalkNoiseOtherEnd( CLHEP::HepRandomEngine* ) const;
91 
92  //--- For looping over all straws (only to be used at initialization):
93 
97  void resetGetNextStraw();
98 
105  bool getNextStraw( int& hitID, float& noiselevel, float& noiseamp );
106 
113  void setRefinedStrawParameters( const int& hitID,
114  const double& lowthreshold,
115  const double& noiseamplitude );
116 
117 protected:
118 
132  virtual void setStrawStateInfo(Identifier& TRT_Identifier,
133  const double& strawlength,
134  double& noiselevel,
135  double& relative_noiseamplitude,
136  CLHEP::HepRandomEngine *rndmEngine) = 0;
137 
138 protected:
141  const TRT_ID* m_id_helper{};
142 
143 private:
145  struct StrawState {
146  float noiselevel{};
147  float noiseamplitude{};
148  float lowthreshold{};
149  };
150 
151  //--- Data maps:
152 
154  // StrawState is struct with members:
155  // 1) noiselevel - the same for Xenon/Argon straws
156  // 2) noiseamplitude - the same for Xenon/Argon straws
157  // 3) lowthreshold - different for Xenon and Argon straws
158  // for more info see info for setStrawStateInfo function, 28 lines above!
159 
160  std::map<int,StrawState> m_hitid_to_StrawState; //<--------- 7MB!!!!
161 
162  //--- iterators:
163 
165  std::map<int,StrawState>::const_iterator m_it_hitid_to_StrawState{};
167  std::map<int,StrawState>::const_iterator m_it_hitid_to_StrawState_End{};
169  mutable std::map<int,StrawState>::const_iterator m_it_hitid_to_StrawState_Last ATLAS_THREAD_SAFE {}; // Guarded by m_mutex
171 
172  mutable std::atomic<float> m_averageNoiseLevel{};
175 
176  //--- For iterating through all of the straw hitids:
181 
182 protected:
183  int m_UseGasMix{};
184  ToolHandle<ITRT_StrawStatusSummaryTool> m_sumTool; // added by Sasha for Argon
185 
186 };
187 
191 
192 //___________________________________________________________________________
193 inline void TRTDigCondBase::getStrawData( const int& hitID,
194  double& lowthreshold,
195  double& noiseamplitude ) const {
196  //fixme: do we actually benefit from this caching?
197  std::lock_guard<std::mutex> lock(m_mutex);
198  if (m_it_hitid_to_StrawState_Last->first != hitID)
199  m_it_hitid_to_StrawState_Last = m_hitid_to_StrawState.find(hitID);
200 
201  lowthreshold = m_it_hitid_to_StrawState_Last->second.lowthreshold;
202  noiseamplitude = m_it_hitid_to_StrawState_Last->second.noiseamplitude;
203 }
204 
205 //___________________________________________________________________________
206 inline unsigned int TRTDigCondBase::totalNumberOfActiveStraws() const {
207  return m_hitid_to_StrawState.size();
208 }
209 
210 //___________________________________________________________________________
213 }
214 
215 //___________________________________________________________________________
216 inline bool TRTDigCondBase::getNextStraw( int& hitID,
217  float& noiselevel,
218  float& noiseamp ) {
221  hitID = 0;
222  noiselevel = 0.;
223  return false;
224  } else {
225  hitID = m_all_it_hitid_to_StrawState->first;
226  noiselevel = m_all_it_hitid_to_StrawState->second.noiselevel;
227  noiseamp = m_all_it_hitid_to_StrawState->second.noiseamplitude;
228  return true;
229  };
230 }
231 
232 //___________________________________________________________________________
233 inline void TRTDigCondBase::setRefinedStrawParameters( const int& hitID,
234  const double& lowthreshold,
235  const double& noiseamplitude ) {
236  //we might have the iterator cached already (fixme... nah)
237  if (hitID == m_all_it_hitid_to_StrawState_previous->first) {
238  m_all_it_hitid_to_StrawState_previous->second.lowthreshold = lowthreshold;
239  m_all_it_hitid_to_StrawState_previous->second.noiseamplitude =
240  noiseamplitude;
241  } else {
243  m_hitid_to_StrawState.find(hitID)->second.lowthreshold = lowthreshold;
244  m_hitid_to_StrawState.find(hitID)->second.noiseamplitude = noiseamplitude;
245  };
246 }
247 
248 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TRTDigCondBase::StrawState::lowthreshold
float lowthreshold
Low threshold discriminator setting.
Definition: TRTDigCondBase.h:148
TRTDigCondBase::crossTalkNoise
bool crossTalkNoise(CLHEP::HepRandomEngine *) const
Definition: TRTDigCondBase.cxx:194
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
TRTDigCondBase::~TRTDigCondBase
virtual ~TRTDigCondBase()
Destructor.
Definition: TRTDigCondBase.h:47
TRTDigCondBase::getNextStraw
bool getNextStraw(int &hitID, float &noiselevel, float &noiseamp)
For looping over all straws: get next straw.
Definition: TRTDigCondBase.h:216
TRTDigCondBase::getStrawData
void getStrawData(const int &hitID, double &lowthreshold, double &noiseamplitude) const
Get straw data mixed condition is implemented function will return both Argon and Xenon straws (with ...
Definition: TRTDigCondBase.h:193
TRTDigCondBase::setStrawStateInfo
virtual void setStrawStateInfo(Identifier &TRT_Identifier, const double &strawlength, double &noiselevel, double &relative_noiseamplitude, CLHEP::HepRandomEngine *rndmEngine)=0
Get straw state info based on hitid and strawlength.
TRTDigCondBase::StrawState::noiselevel
float noiselevel
Noise level
Definition: TRTDigCondBase.h:146
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
TRTDigCondBase::m_averageNoiseLevel
std::atomic< float > m_averageNoiseLevel
Average noise level.
Definition: TRTDigCondBase.h:172
TRTDigCondBase::m_it_hitid_to_StrawState_End
std::map< int, StrawState >::const_iterator m_it_hitid_to_StrawState_End
Iterator pointing to last straw in straw state map.
Definition: TRTDigCondBase.h:167
TRTDigCondBase::StrawState::noiseamplitude
float noiseamplitude
Noise amplitude
Definition: TRTDigCondBase.h:147
TRTDigCondBase::m_id_helper
const TRT_ID * m_id_helper
Definition: TRTDigCondBase.h:141
ITRT_StrawStatusSummaryTool.h
abstract interface to TRT straw status constants
TRTDigCondBase::m_all_it_hitid_to_StrawState
std::map< int, StrawState >::iterator m_all_it_hitid_to_StrawState
Iterator over straw state map.
Definition: TRTDigCondBase.h:178
TRTDigCondBase::totalNumberOfActiveStraws
unsigned int totalNumberOfActiveStraws() const
Get total number of active straws.
Definition: TRTDigCondBase.h:206
TRTDigCondBase::m_settings
const TRTDigSettings * m_settings
Definition: TRTDigCondBase.h:139
TRTDigCondBase::StrawState
Straw state.
Definition: TRTDigCondBase.h:145
TRTDigCondBase::getNextNoisyStraw
bool getNextNoisyStraw(CLHEP::HepRandomEngine *, int &hitID, float &noiselevel)
For simulation of noise in unhit straws: get next noisy straw.
Definition: TRTDigCondBase.cxx:181
TRTDigCondBase::m_it_hitid_to_StrawState
std::map< int, StrawState >::const_iterator m_it_hitid_to_StrawState
Iterator over straw state map.
Definition: TRTDigCondBase.h:165
CLHEP
STD'S.
Definition: CaloNoiseCompCondAlg.h:58
TRTDigCondBase::m_all_it_hitid_to_StrawState_previous
std::map< int, StrawState >::iterator m_all_it_hitid_to_StrawState_previous
Iterator used for caching.
Definition: TRTDigCondBase.h:180
TRTDigCondBase::m_crosstalk_noiselevel_other_end
double m_crosstalk_noiselevel_other_end
Definition: TRTDigCondBase.h:174
TRTDigCondBase::ATLAS_THREAD_SAFE
std::map< int, StrawState >::const_iterator m_it_hitid_to_StrawState_Last ATLAS_THREAD_SAFE
Iterator used for caching (ought to be called _Previous)
Definition: TRTDigCondBase.h:169
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
TRTDigCondBase::m_sumTool
ToolHandle< ITRT_StrawStatusSummaryTool > m_sumTool
Definition: TRTDigCondBase.h:184
TRTDigCondBase::crossTalkNoiseOtherEnd
bool crossTalkNoiseOtherEnd(CLHEP::HepRandomEngine *) const
Definition: TRTDigCondBase.cxx:200
TRTDigCondBase::TRTDigCondBase
TRTDigCondBase(const TRTDigSettings *, const InDetDD::TRT_DetectorManager *, const TRT_ID *, int UseGasMix, ToolHandle< ITRT_StrawStatusSummaryTool > sumTool)
Constructor.
Definition: TRTDigCondBase.cxx:25
TRTDigCondBase::m_UseGasMix
int m_UseGasMix
Definition: TRTDigCondBase.h:183
TRTDigCondBase::m_crosstalk_noiselevel
double m_crosstalk_noiselevel
Definition: TRTDigCondBase.h:173
TRTDigCondBase::m_hitid_to_StrawState
std::map< int, StrawState > m_hitid_to_StrawState
Global map from straw ID to straw state.
Definition: TRTDigCondBase.h:160
TRTDigCondBase::resetGetNextStraw
void resetGetNextStraw()
For looping over all straws: Rewind straw list to start from beginning.
Definition: TRTDigCondBase.h:211
TRTDigCondBase::m_mutex
std::mutex m_mutex
Definition: TRTDigCondBase.h:170
TRT_ID
Definition: TRT_ID.h:82
InDetDD::TRT_DetectorManager
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
Definition: TRT_DetectorManager.h:63
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
TRTDigCondBase::setRefinedStrawParameters
void setRefinedStrawParameters(const int &hitID, const double &lowthreshold, const double &noiseamplitude)
Set straw parameters.
Definition: TRTDigCondBase.h:233
AthMessaging.h
TRTDigCondBase::resetGetNextNoisyStraw
void resetGetNextNoisyStraw()
For noise in unhit straws: Rewind straw list to start from beginning.
Definition: TRTDigCondBase.cxx:176
TRTDigSettings
Class containing parameters and settings used by TRT digitization.
Definition: TRTDigSettings.h:34
checker_macros.h
Define macros for attributes used to control the static checker.
TRTDigCondBase::strawAverageNoiseLevel
float strawAverageNoiseLevel() const
Get average noise level in straw.
Definition: TRTDigCondBase.cxx:47
TRTDigCondBase::m_detmgr
const InDetDD::TRT_DetectorManager * m_detmgr
Definition: TRTDigCondBase.h:140
TRTDigCondBase::initialize
void initialize(CLHEP::HepRandomEngine *rndmEngine)
Definition: TRTDigCondBase.cxx:64
Identifier
Definition: IdentifierFieldParser.cxx:14
TRTDigCondBase
Communication with CondDB.
Definition: TRTDigCondBase.h:34