ATLAS Offline Software
TileCalibUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <cctype>
8 #include <sstream>
9 #include <iomanip>
10 #include <cmath>
11 
12 const unsigned int TileCalibUtils::MAX_ROS;
13 const unsigned int TileCalibUtils::MAX_DRAWER;
14 const unsigned int TileCalibUtils::MAX_DRAWR0;
15 const unsigned int TileCalibUtils::MAX_CHAN;
16 const unsigned int TileCalibUtils::MAX_GAIN;
17 const unsigned int TileCalibUtils::MAX_DRAWERIDX;
18 const unsigned int TileCalibUtils::LAS_PART_CHAN;
19 const unsigned int TileCalibUtils::TRIPS_DRAWERIDX;
20 const unsigned int TileCalibUtils::TRIPS_ROS;
21 const unsigned int TileCalibUtils::TRIPS_DRAWER;
22 const unsigned int TileCalibUtils::DEFINITIONS_DRAWERIDX;
23 const unsigned int TileCalibUtils::BAD_DEFINITION_CHAN;
24 const unsigned int TileCalibUtils::NOISY_DEFINITION_CHAN;
29 
30 //
31 //_____________________________________________________________________________
32 std::string
33 TileCalibUtils::getFullTag(const std::string& folder, const std::string& tag)
34  //===
35  //=== build a unique cool tag based on the tag conventions outline here:
36  //=== https://twiki.cern.ch/twiki/bin/view/Atlas/CoolTagging
37  //=== "tag" should be of the form "xxx-yy" for real data
38  //===
39 {
40 
41  std::string folderTag("");
42  bool isLower(true);
43  for (const char& c : folder) {
44  if(c == '/'){
45  isLower = false;
46  } else if(isLower) {
48  } else {
49  folderTag += char(std::toupper(c));
50  isLower = true;
51  }
52  }
53 
54  return (folderTag + "-" + tag);
55 }
56 
57 //
58 //_____________________________________________________________________________
59 unsigned int
60 TileCalibUtils::getDrawerIdx(unsigned int ros, unsigned int drawer)
61 {
62  if(ros >= MAX_ROS){ throw TileCalib::IndexOutOfRange("TileCalibUtils::getDrawerIdx", ros , MAX_ROS );}
63  if(!ros){ if(drawer >= MAX_DRAWR0) throw TileCalib::IndexOutOfRange("TileCalibUtils::getDrawerIdx", drawer, MAX_DRAWR0);}
64  else { if(drawer >= MAX_DRAWER) throw TileCalib::IndexOutOfRange("TileCalibUtils::getDrawerIdx", drawer, MAX_DRAWER);}
65  return (ros == 0 ? 0 : MAX_DRAWR0 + (ros - 1) * MAX_DRAWER) + drawer;
66 }
67 
68 //
69 //_____________________________________________________________________________
70 unsigned int
72 {
73  unsigned int ros = fragId >> 8;
74  unsigned int drawer = fragId & 0xFF;
75  return getDrawerIdx(ros, drawer);
76 }
77 
78 //
79 //_____________________________________________________________________________
80 unsigned int
81 TileCalibUtils::getChanIdx(unsigned int ros, unsigned int drawer, unsigned int channel)
82 {
83  if(channel >= MAX_CHAN) throw TileCalib::IndexOutOfRange("TileCalibUtils::getChanIdx", channel, MAX_CHAN);
84  return getDrawerIdx(ros, drawer) * MAX_CHAN + channel;
85 }
86 
87 //
88 //_____________________________________________________________________________
89 unsigned int
90 TileCalibUtils::getChanIdx(unsigned int drawerIdx, unsigned int channel)
91 {
92  if(drawerIdx >= MAX_DRAWERIDX) throw TileCalib::IndexOutOfRange("TileCalibUtils::getChanIdx(drawIdx)", channel, MAX_DRAWERIDX);
93  if(channel >= MAX_CHAN ) throw TileCalib::IndexOutOfRange("TileCalibUtils::getChanIdx(channel)", channel, MAX_CHAN);
94  return drawerIdx * MAX_CHAN + channel;
95 }
96 
97 //
98 //_____________________________________________________________________________
99 unsigned int
100 TileCalibUtils::getChanIdxFromFragId(unsigned int fragId, unsigned int channel)
101 {
102  if(channel >= MAX_CHAN) throw TileCalib::IndexOutOfRange("TileCalibUtils::getChanIdx", channel, MAX_CHAN);
103  return getDrawerIdxFromFragId(fragId) * MAX_CHAN + channel;
104 }
105 
106 //
107 //_____________________________________________________________________________
108 unsigned int
109 TileCalibUtils::getAdcIdx(unsigned int ros, unsigned int drawer, unsigned int channel, unsigned int adc)
110 {
111  if(adc >= MAX_GAIN) throw TileCalib::IndexOutOfRange("TileCalibUtils::getAdcIdx", adc, MAX_GAIN);
112  return getChanIdx(ros, drawer, channel) * MAX_GAIN + adc;
113 }
114 
115 //
116 //_____________________________________________________________________________
117 unsigned int
118 TileCalibUtils::getAdcIdx(unsigned int drawerIdx, unsigned int channel, unsigned int adc)
119 {
120  if(adc >= MAX_GAIN) throw TileCalib::IndexOutOfRange("TileCalibUtils::getAdcIdx", adc, MAX_GAIN);
121  return getChanIdx(drawerIdx, channel) * MAX_GAIN + adc;
122 }
123 
124 //
125 //_____________________________________________________________________________
126 unsigned int
127 TileCalibUtils::getAdcIdxFromFragId(unsigned int fragId, unsigned int channel, unsigned int adc)
128 {
129  if(adc >= MAX_GAIN) throw TileCalib::IndexOutOfRange("TileCalibUtils::getAdcIdx", adc, MAX_GAIN);
130  return getChanIdxFromFragId(fragId, channel) * MAX_GAIN + adc;
131 }
132 
133 //
134 //_____________________________________________________________________________
135 unsigned int
137 {
138  if(ros >= MAX_ROS){throw TileCalib::IndexOutOfRange("TileCalibUtils::getMaxDrawer", ros, MAX_ROS);}
139  return ros == 0 ? MAX_DRAWR0 : MAX_DRAWER;
140 }
141 
142 //
143 //_____________________________________________________________________________
144 std::string
145 TileCalibUtils::getDrawerString(unsigned int ros, unsigned int drawer)
146 {
147  //=== check for valid index
149  //=== build ros name
150  std::ostringstream name;
151  if (ros == 1){ name << "LBA"; }
152  else if(ros == 2){ name << "LBC"; }
153  else if(ros == 3){ name << "EBA"; }
154  else if(ros == 4){ name << "EBC"; }
155  else{ name << "AUX"; }
156  //=== add drawer number
157  name << std::setw(2) << std::setfill('0') << drawer + 1;
158  return name.str();
159 }
160 
161 //
162 //_____________________________________________________________________________
163 unsigned int TileCalibUtils::getDefaultDrawerIdx(unsigned int drawerIdx) {
164 
165  //=== Global Detector defaults in 0 - 3
166  //===
167  //=== Defaults for LB in 4 - 11
168  //=== Defaults for EB in 12 - 19
169  //===
170  //===
171  //=== Defaults are further shifted in extended barrel:
172  //--- + 1 for Inner MBTS and special C10
173  //--- + 2 for Outer MBTS
174  //--- + 3 for Merged E1
175  //--- + 4 for E4'
176  //--- + 5 for Special D40 with missing D4: EBA15/EBC18
177  //--- + 6 for Special D4 reduced in size
178  //--- + 7 for D4 on the top of EB around special D4
179  //
180  //--- e.g.:
181 
182  //--- LB in 4
183 
184  //--- EB in 12
185  //--- EB (Inner MBTS + special C10) in 13
186  //--- EB (Outer MBTS) in 14
187  //--- EB (Merged E1) in 15
188  //--- EB (E4') in 16
189  //--- EB (Special D40: EBA15/EBC18) in 17
190  //--- EB (Special D4 reduced in size) in 18
191  //--- EB (D4 on the top of EB around specail D4) in 19
192 
193 
194  //=== defaults for defaults
195  if(drawerIdx < MAX_DRAWR0) {
196  if (drawerIdx < 4) return 0;
197  unsigned int mod = (drawerIdx - 4) % 8;
198  return mod > 0 ? drawerIdx - mod : 0;
199  }
200 
201 
202  //=== defaults for existing drawers
203  drawerIdx -= MAX_DRAWR0;
204  if (drawerIdx < 2 * MAX_DRAWER) return 4; // LB
205 
206  drawerIdx -= 2 * MAX_DRAWER;
207  if (drawerIdx < MAX_DRAWER) { // EBA
208 
209  int OffsetEBA[] = { 0, 0, 0, 0, 0, 0, 3, 2, // Merged E+1: EBA07; Outer MBTS: EBA08
210  0, 0, 0, 0, 7, 6, 5, 7, // D+4: EBA13, EBA16; Special D+4: EBA14; Special D+40: EBA15
211  7, 6, 6, 7, 0, 0, 0, 2, // D+4: EBA17, EBA20; Special D+4: EBA18, EBA19; Outer MBTS: EBA24
212  3, 0, 0, 0, 0, 0, 0, 0, // Merged E+1: EBA25
213  0, 0, 0, 0, 0, 0, 1, 1, // Inner MBTS + special C+10: EBA39, EBA40
214  1, 1, 2, 3, 0, 0, 0, 0, // Inner MBTS + special C+10: EBA41, EBA42; Outer MBTS: EBA43; Merged E+1: EBA44
215  0, 0, 0, 0, 3, 2, 1, 1, // Merged E+1: EBA53; Outer MBTS: EBA54; Inner MBTS + special C+10: EBA55, EBA56
216  1, 1, 0, 0, 0, 0, 0, 0 // Inner MBTS + special C+10: EBA57, EBA58
217 
218  };
219 
220  return 12 + OffsetEBA[drawerIdx];
221 
222  }
223 
224  // EBC
225  drawerIdx -= MAX_DRAWER;
226  int OffsetEBC[] = { 0, 0, 0, 0, 0, 0, 3, 2, // Merged E-1: EBC07; Outer MBTS: EBC08
227  0, 0, 0, 0, 7, 6, 6, 7, // D-4: EBC13, EBC16; Special D-4: EBC14, EBC15;
228  7, 5, 6, 7, 0, 0, 0, 2, // D-4: EBC17, EBC20; Special D-40 EBC18; Special D-4: EBC19; Outer MBTS: EBC24
229  3, 0, 0, 3, 4, 0, 3, 4, // Merged E-1: EBC25, EBC28, EBC31; E-4': EBC29, EBC32
230  0, 4, 3, 0, 4, 3, 1, 1, // E-4': EBC34, EBC37; Merged E-1: EBC35, EBC38; Inner MBTS + special C-10: EBC39, EBC40
231  1, 1, 2, 3, 0, 0, 0, 0, // Inner MBTS + special C-10: EBC41, EBC42; Outer MBTS: EBC43; Merged E-1: EBC44
232  0, 0, 0, 0, 3, 2, 1, 1, // Merged E-1: EBC53; Outer MBTS: EBC54; Inner MBTS + special C-10: EBC55, EBC56
233  1, 1, 0, 0, 0, 0, 0, 0 // Inner MBTS + special C-10: EBC57, EBC58
234  };
235 
236  // Without this check we get a cppcheck false positive.
237  if (drawerIdx >= std::size(OffsetEBC)) std::abort();
238  return 12 + OffsetEBC[drawerIdx];
239 
240 }
241 
242 //
243 //_____________________________________________________________________________
244 unsigned int
245 TileCalibUtils::getDefaultDrawerIdx(unsigned int ros, unsigned int drawer)
246 {
248 }
249 
250 //
251 //_____________________________________________________________________________
252 unsigned int
254 {
255  if(drawerIdx >= MAX_DRAWERIDX) throw TileCalib::IndexOutOfRange("TileCalibUtils::getChanIdx(drawIdx)", 0, MAX_DRAWERIDX);
256 
257  unsigned int drawer0 = 0;
258  if(drawerIdx < MAX_DRAWR0) return drawer0;
259  else if(drawerIdx < MAX_DRAWR0 + 1 * MAX_DRAWER) return MAX_DRAWR0;
260  else if(drawerIdx < MAX_DRAWR0 + 2 * MAX_DRAWER) return MAX_DRAWR0 + 1 * MAX_DRAWER;
261  else if(drawerIdx < MAX_DRAWR0 + 3 * MAX_DRAWER) return MAX_DRAWR0 + 2 * MAX_DRAWER;
262  else return MAX_DRAWR0 + 3 * MAX_DRAWER;
263 }
264 
265 //
266 //____________________________________________________________________
267 float
268 TileCalibUtils::fixedPointPrecision(float val, unsigned int nBits)
269 {
270  nBits -= 1;
271 
272  //=== get scale
273  int scale = 0;
274  float absVal = std::fabs(val);
275  if(absVal != 0.){
276  scale = static_cast<int>( ::truncf(std::log((std::pow(2., static_cast<int>(nBits)) - 1.)/absVal)*(1./std::log(2.))) );
277  }
278  //=== return input value with fixed point precision
279  return ::roundf(val * std::pow(2., scale)) / std::pow(2., scale);
280 }
281 
TileCalibUtils::getMaxDrawer
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
Definition: TileCalibUtils.cxx:136
TileCalib::IndexOutOfRange
Thrown if an index is out of range.
Definition: TileCalorimeter/TileCalib/TileCalibBlobObjs/TileCalibBlobObjs/Exception.h:141
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
TileCalibUtils::MAX_DRAWERIDX
static const unsigned int MAX_DRAWERIDX
Maximal drawer index
Definition: TileCalibUtils.h:143
TileCalibUtils::getFirstDrawerInPartitionIdx
static unsigned int getFirstDrawerInPartitionIdx(unsigned int drawerIdx)
Returns the first drawer Idx in a partition of a given input drawer.
Definition: TileCalibUtils.cxx:253
xAOD::char
char
Definition: TrigDecision_v1.cxx:38
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
TileCalibUtils::TRIPS_DRAWER
static const unsigned int TRIPS_DRAWER
Drawer used for storing trips probabilities.
Definition: TileCalibUtils.h:147
TileCalibUtils::TRIPS_ROS
static const unsigned int TRIPS_ROS
Ros used for storing trips probabilities.
Definition: TileCalibUtils.h:146
TileCalibUtils::NOISY_DEFINITION_CHAN
static const unsigned int NOISY_DEFINITION_CHAN
Channel used for storing of noisy channel definitions.
Definition: TileCalibUtils.h:150
TileCalibUtils.h
TileCalibUtils::TRIPS_DRAWERIDX
static const unsigned int TRIPS_DRAWERIDX
DrawerIdx used for storing trips probabilities.
Definition: TileCalibUtils.h:145
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
TileCalibUtils::TIMINGDMUBCOFFSET_DEFINITION_CHAN
static const unsigned int TIMINGDMUBCOFFSET_DEFINITION_CHAN
Channel used for storing of affected timing channel definitions.
Definition: TileCalibUtils.h:154
TileCalibUtils::MAX_DRAWER
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
Definition: TileCalibUtils.h:139
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TileCalibUtils::WRONGBCID_DEFINITION_CHAN
static const unsigned int WRONGBCID_DEFINITION_CHAN
Channel used for storing of wrong BCID channel definitions.
Definition: TileCalibUtils.h:153
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
tolower
void tolower(std::string &s)
Definition: AthenaSummarySvc.cxx:111
TileCalibUtils::DEFINITIONS_DRAWERIDX
static const unsigned int DEFINITIONS_DRAWERIDX
Drawer used for storing of bad and noisy channel definitions.
Definition: TileCalibUtils.h:148
TileCalibUtils::BADTIMING_DEFINITION_CHAN
static const unsigned int BADTIMING_DEFINITION_CHAN
Channel used for storing of bad timing channel definitions.
Definition: TileCalibUtils.h:152
TileCalibUtils::getAdcIdxFromFragId
static unsigned int getAdcIdxFromFragId(unsigned int fragId, unsigned int channel, unsigned int adc)
Returns an ADC hash.
Definition: TileCalibUtils.cxx:127
TileCalibUtils::MAX_ROS
static const unsigned int MAX_ROS
Number of ROSs
Definition: TileCalibUtils.h:138
maskDeadModules.ros
ros
Definition: maskDeadModules.py:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TileCalibUtils::getDefaultDrawerIdx
static unsigned int getDefaultDrawerIdx(unsigned int drawerIdx)
Returns the default drawer for a given input drawer.
Definition: TileCalibUtils.cxx:163
TileCalibUtils::getChanIdx
static unsigned int getChanIdx(unsigned int ros, unsigned int drawer, unsigned int channel)
Returns a channel hash.
Definition: TileCalibUtils.cxx:81
TileCalibUtils::getChanIdxFromFragId
static unsigned int getChanIdxFromFragId(unsigned int fragId, unsigned int channel)
Returns a channel hash.
Definition: TileCalibUtils.cxx:100
TileCalibUtils::getDrawerString
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Definition: TileCalibUtils.cxx:145
CaloCondBlobAlgs_fillNoiseFromASCII.folderTag
folderTag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:52
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TileCalibUtils::BAD_DEFINITION_CHAN
static const unsigned int BAD_DEFINITION_CHAN
Channel used for storing of bad channel definitions.
Definition: TileCalibUtils.h:149
TileCalibUtils::NOGAINL1_DEFINITION_CHAN
static const unsigned int NOGAINL1_DEFINITION_CHAN
Channel used for storing of NoGainLevel1 channel definitions.
Definition: TileCalibUtils.h:151
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
TileCalibUtils::getAdcIdx
static unsigned int getAdcIdx(unsigned int ros, unsigned int drawer, unsigned int channel, unsigned int adc)
Returns an ADC hash.
Definition: TileCalibUtils.cxx:109
TileCalibUtils::getDrawerIdx
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Definition: TileCalibUtils.cxx:60
TileCalibUtils::fixedPointPrecision
static float fixedPointPrecision(float val, unsigned int nBits=16)
Returns the input in fixed point precision.
Definition: TileCalibUtils.cxx:268
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
TileCalibUtils::LAS_PART_CHAN
static const unsigned int LAS_PART_CHAN
Empty channel number to store laser partition variation.
Definition: TileCalibUtils.h:144
TileCalibUtils::MAX_CHAN
static const unsigned int MAX_CHAN
Number of channels in drawer.
Definition: TileCalibUtils.h:141
Exception.h
TileCalibUtils::getDrawerIdxFromFragId
static unsigned int getDrawerIdxFromFragId(unsigned int fragId)
Returns a drawer hash from fragId This function assumes drawer context (i.e.
Definition: TileCalibUtils.cxx:71
python.compressB64.c
def c
Definition: compressB64.py:93
TileCalibUtils::MAX_DRAWR0
static const unsigned int MAX_DRAWR0
Number of drawers in ROS 0
Definition: TileCalibUtils.h:140
TileCalibUtils::getFullTag
static std::string getFullTag(const std::string &folder, const std::string &tag)
Returns the full tag string, composed of camelized folder name and tag part.
Definition: TileCalibUtils.cxx:33
TileCalibUtils::MAX_GAIN
static const unsigned int MAX_GAIN
Number of gains per channel
Definition: TileCalibUtils.h:142