ATLAS Offline Software
TRTDigCondBase.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 "Identifier/Identifier.h"
11 #include "TRT_ConditionsServices/ITRT_StrawStatusSummaryTool.h" // added by Sasha for Argon
12 
13 #include "GaudiKernel/ServiceHandle.h"
14 #include "GaudiKernel/ToolHandle.h"
15 
16 #include "CLHEP/Random/RandomEngine.h"
17 
18 #include <atomic>
19 #include <map>
20 #include <mutex>
21 #include <set>
22 
23 class TRT_ID;
24 
25 namespace InDetDD {
26  class TRT_DetectorManager;
27 }
28 class TRTDigSettings;
32 class TRTDigCondBase : public AthMessaging {
33 
34 public:
35 
39  const TRT_ID*,
40  int UseGasMix,
41  ToolHandle<ITRT_StrawStatusSummaryTool> sumTool
42  );
43 
45  virtual ~TRTDigCondBase() {};
46 
50  void initialize(CLHEP::HepRandomEngine* rndmEngine);
51 
53  float strawAverageNoiseLevel() const; //[first time slow, else fast]
54 
56  unsigned int totalNumberOfActiveStraws() const; //[fast]
57 
67  void getStrawData( const int& hitID,
68  double& lowthreshold,
69  double& noiseamplitude ) const;
70 
71  //--- For noise in unhit straws:
72 
77 
83  bool getNextNoisyStraw( CLHEP::HepRandomEngine*, int& hitID, float& noiselevel );
84 
85 
86  //Crosstalk noise
87  bool crossTalkNoise( CLHEP::HepRandomEngine* ) const;
88  bool crossTalkNoiseOtherEnd( CLHEP::HepRandomEngine* ) const;
89 
90  //--- For looping over all straws (only to be used at initialization):
91 
95  void resetGetNextStraw();
96 
103  bool getNextStraw( int& hitID, float& noiselevel, float& noiseamp );
104 
111  void setRefinedStrawParameters( const int& hitID,
112  const double& lowthreshold,
113  const double& noiseamplitude );
114 
115 protected:
116 
130  virtual void setStrawStateInfo(Identifier& TRT_Identifier,
131  const double& strawlength,
132  double& noiselevel,
133  double& relative_noiseamplitude,
134  CLHEP::HepRandomEngine *rndmEngine) = 0;
135 
136 protected:
140 
141 private:
143  struct StrawState {
144  float noiselevel;
146  float lowthreshold;
147  };
148 
149  //--- Data maps:
150 
152  // StrawState is struct with members:
153  // 1) noiselevel - the same for Xenon/Argon straws
154  // 2) noiseamplitude - the same for Xenon/Argon straws
155  // 3) lowthreshold - different for Xenon and Argon straws
156  // for more info see info for setStrawStateInfo function, 28 lines above!
157 
158  std::map<int,StrawState> m_hitid_to_StrawState; //<--------- 7MB!!!!
159 
160  //--- iterators:
161 
163  std::map<int,StrawState>::const_iterator m_it_hitid_to_StrawState;
165  std::map<int,StrawState>::const_iterator m_it_hitid_to_StrawState_End;
167  mutable std::map<int,StrawState>::const_iterator m_it_hitid_to_StrawState_Last ATLAS_THREAD_SAFE; // Guarded by m_mutex
169 
170  mutable std::atomic<float> m_averageNoiseLevel;
173 
174  //--- For iterating through all of the straw hitids:
179 
180 protected:
182  ToolHandle<ITRT_StrawStatusSummaryTool> m_sumTool; // added by Sasha for Argon
183 
184 };
185 
189 
190 //___________________________________________________________________________
191 inline void TRTDigCondBase::getStrawData( const int& hitID,
192  double& lowthreshold,
193  double& noiseamplitude ) const {
194  //fixme: do we actually benefit from this caching?
195  std::lock_guard<std::mutex> lock(m_mutex);
196  if (m_it_hitid_to_StrawState_Last->first != hitID)
197  m_it_hitid_to_StrawState_Last = m_hitid_to_StrawState.find(hitID);
198 
199  lowthreshold = m_it_hitid_to_StrawState_Last->second.lowthreshold;
200  noiseamplitude = m_it_hitid_to_StrawState_Last->second.noiseamplitude;
201 }
202 
203 //___________________________________________________________________________
204 inline unsigned int TRTDigCondBase::totalNumberOfActiveStraws() const {
205  return m_hitid_to_StrawState.size();
206 }
207 
208 //___________________________________________________________________________
211 }
212 
213 //___________________________________________________________________________
214 inline bool TRTDigCondBase::getNextStraw( int& hitID,
215  float& noiselevel,
216  float& noiseamp ) {
219  hitID = 0;
220  noiselevel = 0.;
221  return false;
222  } else {
223  hitID = m_all_it_hitid_to_StrawState->first;
224  noiselevel = m_all_it_hitid_to_StrawState->second.noiselevel;
225  noiseamp = m_all_it_hitid_to_StrawState->second.noiseamplitude;
226  return true;
227  };
228 }
229 
230 //___________________________________________________________________________
231 inline void TRTDigCondBase::setRefinedStrawParameters( const int& hitID,
232  const double& lowthreshold,
233  const double& noiseamplitude ) {
234  //we might have the iterator cached already (fixme... nah)
235  if (hitID == m_all_it_hitid_to_StrawState_previous->first) {
236  m_all_it_hitid_to_StrawState_previous->second.lowthreshold = lowthreshold;
237  m_all_it_hitid_to_StrawState_previous->second.noiseamplitude =
238  noiseamplitude;
239  } else {
241  m_hitid_to_StrawState.find(hitID)->second.lowthreshold = lowthreshold;
242  m_hitid_to_StrawState.find(hitID)->second.noiseamplitude = noiseamplitude;
243  };
244 }
245 
246 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TRTDigCondBase::StrawState::lowthreshold
float lowthreshold
Low threshold discriminator setting.
Definition: TRTDigCondBase.h:146
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:45
TRTDigCondBase::getNextStraw
bool getNextStraw(int &hitID, float &noiselevel, float &noiseamp)
For looping over all straws: get next straw.
Definition: TRTDigCondBase.h:214
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:191
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:144
TRTDigCondBase::m_averageNoiseLevel
std::atomic< float > m_averageNoiseLevel
Average noise level.
Definition: TRTDigCondBase.h:170
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:165
TRTDigCondBase::StrawState::noiseamplitude
float noiseamplitude
Noise amplitude
Definition: TRTDigCondBase.h:145
TRTDigCondBase::m_id_helper
const TRT_ID * m_id_helper
Definition: TRTDigCondBase.h:139
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:176
TRTDigCondBase::totalNumberOfActiveStraws
unsigned int totalNumberOfActiveStraws() const
Get total number of active straws.
Definition: TRTDigCondBase.h:204
TRTDigCondBase::m_settings
const TRTDigSettings * m_settings
Definition: TRTDigCondBase.h:137
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
TRTDigCondBase::StrawState
Straw state.
Definition: TRTDigCondBase.h:143
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:163
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:178
TRTDigCondBase::m_crosstalk_noiselevel_other_end
double m_crosstalk_noiselevel_other_end
Definition: TRTDigCondBase.h:172
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:167
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
TRTDigCondBase::m_sumTool
ToolHandle< ITRT_StrawStatusSummaryTool > m_sumTool
Definition: TRTDigCondBase.h:182
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:181
TRTDigCondBase::m_crosstalk_noiselevel
double m_crosstalk_noiselevel
Definition: TRTDigCondBase.h:171
TRTDigCondBase::m_hitid_to_StrawState
std::map< int, StrawState > m_hitid_to_StrawState
Global map from straw ID to straw state.
Definition: TRTDigCondBase.h:158
TRTDigCondBase::resetGetNextStraw
void resetGetNextStraw()
For looping over all straws: Rewind straw list to start from beginning.
Definition: TRTDigCondBase.h:209
TRTDigCondBase::m_mutex
std::mutex m_mutex
Definition: TRTDigCondBase.h:168
TRT_ID
Definition: TRT_ID.h:84
InDetDD::TRT_DetectorManager
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
Definition: TRT_DetectorManager.h:69
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:231
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:35
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:138
TRTDigCondBase::initialize
void initialize(CLHEP::HepRandomEngine *rndmEngine)
Definition: TRTDigCondBase.cxx:64
TRTDigCondBase
Communication with CondDB.
Definition: TRTDigCondBase.h:32