ATLAS Offline Software
Loading...
Searching...
No Matches
TRTDigCondBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TRTDigCondBase.h"
6#include "TRTDigSettings.h"
7#include "TRTDigiHelper.h"
8
9#include <cmath>
10#include <cstdlib>
11#include <utility>
12
16
17//helpers for identifiers and hitids:
20
21// For the random numbers.
22#include "CLHEP/Random/RandFlat.h"
23
24//________________________________________________________________________________
26 const InDetDD::TRT_DetectorManager* detmgr,
27 const TRT_ID* trt_id,
28 int UseGasMix,
29 ToolHandle<ITRT_StrawStatusSummaryTool> sumTool
30 )
31 : AthMessaging("TRTDigCondBase"),
32 m_settings(digset),
33 m_detmgr(detmgr),
34 m_id_helper(trt_id),
38 m_UseGasMix(UseGasMix),
39 m_sumTool(std::move(sumTool))
40{
41 m_crosstalk_noiselevel = m_settings->crossTalkNoiseLevel();
42 m_crosstalk_noiselevel_other_end = m_settings->crossTalkNoiseLevelOtherEnd();
43}
44
45
46//________________________________________________________________________________
48
49 if (m_averageNoiseLevel>=0.0) {
51 } else {
52 std::map<int,StrawState>::const_iterator it(m_hitid_to_StrawState.begin());
54 double tmp(0.);
55 for ( ; it!=m_it_hitid_to_StrawState_End; ++it ) {
56 tmp += it->second.noiselevel;
57 };
60 };
61}
62
63//________________________________________________________________________________
64void TRTDigCondBase::initialize(CLHEP::HepRandomEngine* rndmEngine) {
65
66 ATH_MSG_INFO ( "TRTDigCondBase::initialize()" );
67
68 //id helpers:
69 const TRTHitIdHelper *hitid_helper(TRTHitIdHelper::GetHelper());
70
71 //We loop through all of the detector elements registered in the manager
74
75 unsigned int strawcount(0);
76 unsigned int nBAA[3][3] = {{0}}; // [ringwheel=0,1,2][strawGasType=0,1,2]
77 unsigned int nBAC[3][3] = {{0}}; // [ringwheel=0,1,2][strawGasType=0,1,2]
78 unsigned int nECA[14][3] = {{0}}; // [ringwheel=0--13][strawGasType=0,1,2]
79 unsigned int nECC[14][3] = {{0}}; // [ringwheel=0--13][strawGasType=0,1,2]
80
81 for (;it!=itE;++it) { // loop over straws
82
83 const double strawLength((*it)->strawLength());
84 const Identifier id((*it)->identify());
85
86 const int ringwheel(m_id_helper->layer_or_wheel(id));
87 const int phisector(m_id_helper->phi_module(id));
88 const int layer(m_id_helper->straw_layer(id));
89 const int side(m_id_helper->barrel_ec(id));
90
91 int endcap, isneg;
92 switch ( side ) {
93 case -2: endcap = 1; isneg = 1; break;
94 case -1: endcap = 0; isneg = 1; break;
95 case 1: endcap = 0; isneg = 0; break;
96 case 2: endcap = 1; isneg = 0; break;
97 default:
98 std::cout << "TRTDigitization::TRTDigCondBase::createListOfValidStraws "
99 << "FATAL - identifier problems - skipping detector element!!" << std::endl;
100 continue;
101 }
102
103 for (unsigned int iStraw(0); iStraw <(*it)->nStraws(); ++iStraw) {
104
105 // get ID of the straw, and the gas mix
106 const int hitid(hitid_helper->buildHitId( endcap, isneg, ringwheel, phisector, layer, iStraw));
107 Identifier strawId = m_id_helper->straw_id(side, phisector, ringwheel, layer, iStraw);
108 const int statusHT = m_sumTool->getStatusHT(strawId, Gaudi::Hive::currentContext());
109 const int strawGasType = TRTDigiHelper::StrawGasType(statusHT,m_UseGasMix, &msg());
110
111 //Get info about the straw conditions, then create and fill the strawstate
112 double noiselevel, relative_noiseamplitude;
113 setStrawStateInfo( strawId, strawLength, noiselevel, relative_noiseamplitude, rndmEngine );
114 StrawState strawstate{};
115 strawstate.noiselevel = noiselevel; // same for all gas types
116 strawstate.lowthreshold = ( !(hitid & 0x00200000) ) ? m_settings->lowThresholdBar(strawGasType) : m_settings->lowThresholdEC(strawGasType);
117 strawstate.noiseamplitude= relative_noiseamplitude; // These two are later regulated noise code
118 m_hitid_to_StrawState[ hitid ] = strawstate; // Insert into the map:
119
120 // Count the number of straws
121 ++strawcount;
122
123 // Count the gas fraction in a number of regions:
124 if ( side==+1 && ringwheel>=0 && ringwheel<=2 ) nBAA[ringwheel][strawGasType]++; // [ringwheel=0,1,2][strawGasType=0,1,2]
125 if ( side==-1 && ringwheel>=0 && ringwheel<=2 ) nBAC[ringwheel][strawGasType]++; // [ringwheel=0,1,2][strawGasType=0,1,2]
126 if ( side==+2 && ringwheel>=0 && ringwheel<=13 ) nECA[ringwheel][strawGasType]++; // [ringwheel=0, 13][strawGasType=0,1,2]
127 if ( side==-2 && ringwheel>=0 && ringwheel<=13 ) nECC[ringwheel][strawGasType]++; // [ringwheel=0, 13][strawGasType=0,1,2]
128
129 };
130
131 }; // end "loop over straws"
132
135
136 //just put it to something:
137 m_it_hitid_to_StrawState_Last = m_it_hitid_to_StrawState;
138
139 if (m_hitid_to_StrawState.empty()) {
140 ATH_MSG_ERROR("TRTDigCondBase::initialize it seems that ALL straws are dead/masked! This wont work.");
141 }
142
143 //just to avoid having an uninitialized iterator hanging around:
145
146 // Finally give some useful information about the gas mix chosen and that which we actually get!
147 if ( m_UseGasMix==0) std::cout << "TRTDigCondBase INFO Gas Geometry: UseGasMix==0; using StatusHT to determine the gas geometry." << std::endl;
148 if ( m_UseGasMix==1) std::cout << "TRTDigCondBase INFO Gas Geometry: UseGasMix==1; expect Xenon in the entire detector." << std::endl;
149 if ( m_UseGasMix==2) std::cout << "TRTDigCondBase INFO Gas Geometry: UseGasMix==2; expect Krypton in the entire detector." << std::endl;
150 if ( m_UseGasMix==3) std::cout << "TRTDigCondBase INFO Gas Geometry: UseGasMix==3; expect Argon in the entire detector." << std::endl;
152 std::cout << "TRTDigCondBase ERROR Gas Geometry: UseGasMix==" << m_UseGasMix << ", must be 0,1,2or 3!" << std::endl;
153 throw std::exception();
154 }
155 std::cout << "TRTDigCondBase INFO Gas Geometry: strawcount=" << strawcount << std::endl;
156
157 std::cout << "TRTDigCondBase INFO Gas Geometry: BA_A[Xe] = " << nBAA[0][0] << " " << nBAA[1][0] << " " << nBAA[2][0] << std::endl;
158 std::cout << "TRTDigCondBase INFO Gas Geometry: BA_A[Kr] = " << nBAA[0][1] << " " << nBAA[1][1] << " " << nBAA[2][1] << std::endl;
159 std::cout << "TRTDigCondBase INFO Gas Geometry: BA_A[Ar] = " << nBAA[0][2] << " " << nBAA[1][2] << " " << nBAA[2][2] << std::endl;
160
161 std::cout << "TRTDigCondBase INFO Gas Geometry: BA_C[Xe] = " << nBAC[0][0] << " " << nBAC[1][0] << " " << nBAC[2][0] << std::endl;
162 std::cout << "TRTDigCondBase INFO Gas Geometry: BA_C[Kr] = " << nBAC[0][1] << " " << nBAC[1][1] << " " << nBAC[2][1] << std::endl;
163 std::cout << "TRTDigCondBase INFO Gas Geometry: BA_C[Ar] = " << nBAC[0][2] << " " << nBAC[1][2] << " " << nBAC[2][2] << std::endl;
164
165 std::cout << "TRTDigCondBase INFO Gas Geometry: EC_A[Xe] = "; for (auto & i : nECA) std::cout << i[0] << " "; std::cout << std::endl;
166 std::cout << "TRTDigCondBase INFO Gas Geometry: EC_A[Kr] = "; for (auto & i : nECA) std::cout << i[1] << " "; std::cout << std::endl;
167 std::cout << "TRTDigCondBase INFO Gas Geometry: EC_A[Ar] = "; for (auto & i : nECA) std::cout << i[2] << " "; std::cout << std::endl;
168
169 std::cout << "TRTDigCondBase INFO Gas Geometry: EC_C[Xe] = "; for (auto & i : nECC) std::cout << i[0] << " "; std::cout << std::endl;
170 std::cout << "TRTDigCondBase INFO Gas Geometry: EC_C[Kr] = "; for (auto & i : nECC) std::cout << i[1] << " "; std::cout << std::endl;
171 std::cout << "TRTDigCondBase INFO Gas Geometry: EC_C[Ar] = "; for (auto & i : nECC) std::cout << i[2] << " "; std::cout << std::endl;
172
173}
174
175//________________________________________________________________________________
179
180//________________________________________________________________________________
181bool TRTDigCondBase::getNextNoisyStraw( CLHEP::HepRandomEngine* randengine, int& hitID, float& noiselvl ) {
183 noiselvl = m_it_hitid_to_StrawState->second.noiselevel;
184 if ( CLHEP::RandFlat::shoot(randengine, 0.0, 1.0) < noiselvl ) {
185 ++m_it_hitid_to_StrawState; //Important! if removed, iterator is not incremented in case rand<noiselevel!!!
186 hitID = m_it_hitid_to_StrawState->first;
187 return true;
188 };
189 };
190 return false;
191}
192
193//________________________________________________________________________________
194bool TRTDigCondBase::crossTalkNoise( CLHEP::HepRandomEngine* randengine ) const {
195 const float noise(- m_crosstalk_noiselevel * log(CLHEP::RandFlat::shoot(randengine, 0.0, 1.0)));
196 return CLHEP::RandFlat::shoot(randengine, 0.0, 1.0) < noise;
197}
198
199//________________________________________________________________________________
200bool TRTDigCondBase::crossTalkNoiseOtherEnd( CLHEP::HepRandomEngine* randengine ) const {
201 const float noise(- m_crosstalk_noiselevel_other_end * log(CLHEP::RandFlat::shoot(randengine, 0.0, 1.0)));
202 return CLHEP::RandFlat::shoot(randengine, 0.0, 1.0) < noise;
203}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
This is an Identifier helper class for the TRT subdetector.
MsgStream & msg() const
The standard message stream.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
double m_crosstalk_noiselevel_other_end
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.
float strawAverageNoiseLevel() const
Get average noise level in straw.
std::map< int, StrawState >::const_iterator m_it_hitid_to_StrawState_End
Iterator pointing to last straw in straw state map.
std::map< int, StrawState >::const_iterator m_it_hitid_to_StrawState
Iterator over straw state map.
std::map< int, StrawState > m_hitid_to_StrawState
Global map from straw ID to straw state.
std::atomic< float > m_averageNoiseLevel
Average noise level.
const InDetDD::TRT_DetectorManager * m_detmgr
bool getNextNoisyStraw(CLHEP::HepRandomEngine *, int &hitID, float &noiselevel)
For simulation of noise in unhit straws: get next noisy straw.
const TRT_ID * m_id_helper
const TRTDigSettings * m_settings
void initialize(CLHEP::HepRandomEngine *rndmEngine)
TRTDigCondBase(const TRTDigSettings *, const InDetDD::TRT_DetectorManager *, const TRT_ID *, int UseGasMix, ToolHandle< ITRT_StrawStatusSummaryTool > sumTool)
Constructor.
std::map< int, StrawState >::iterator m_all_it_hitid_to_StrawState_previous
Iterator used for caching.
bool crossTalkNoiseOtherEnd(CLHEP::HepRandomEngine *) const
ToolHandle< ITRT_StrawStatusSummaryTool > m_sumTool
double m_crosstalk_noiselevel
void resetGetNextNoisyStraw()
For noise in unhit straws: Rewind straw list to start from beginning.
bool crossTalkNoise(CLHEP::HepRandomEngine *) const
unsigned int totalNumberOfActiveStraws() const
Get total number of active straws.
Class containing parameters and settings used by TRT digitization.
static const TRTHitIdHelper * GetHelper()
int buildHitId(const int, const int, const int, const int, const int, const int) const
This is an Identifier helper class for the TRT subdetector.
Definition TRT_ID.h:82
int StrawGasType(int statusHT, int useGasMix, MsgStream *log)
STL namespace.
float noiseamplitude
Noise amplitude.
float lowthreshold
Low threshold discriminator setting.
float noiselevel
Noise level.