ATLAS Offline Software
Loading...
Searching...
No Matches
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
12const unsigned int TileCalibUtils::MAX_ROS;
13const unsigned int TileCalibUtils::MAX_DRAWER;
14const unsigned int TileCalibUtils::MAX_DRAWR0;
15const unsigned int TileCalibUtils::MAX_CHAN;
16const unsigned int TileCalibUtils::MAX_GAIN;
17const unsigned int TileCalibUtils::MAX_DRAWERIDX;
18const unsigned int TileCalibUtils::LAS_PART_CHAN;
19const unsigned int TileCalibUtils::TRIPS_DRAWERIDX;
20const unsigned int TileCalibUtils::TRIPS_ROS;
21const unsigned int TileCalibUtils::TRIPS_DRAWER;
29
30//
31//_____________________________________________________________________________
32std::string
33TileCalibUtils::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) {
47 folderTag += char(std::tolower(c));
48 } else {
49 folderTag += char(std::toupper(c));
50 isLower = true;
51 }
52 }
53
54 return (folderTag + "-" + tag);
55}
56
57//
58//_____________________________________________________________________________
59unsigned int
60TileCalibUtils::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//_____________________________________________________________________________
70unsigned int
72{
73 unsigned int ros = fragId >> 8;
74 unsigned int drawer = fragId & 0xFF;
75 return getDrawerIdx(ros, drawer);
76}
77
78//
79//_____________________________________________________________________________
80unsigned int
81TileCalibUtils::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//_____________________________________________________________________________
89unsigned int
90TileCalibUtils::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//_____________________________________________________________________________
99unsigned int
100TileCalibUtils::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//_____________________________________________________________________________
108unsigned int
109TileCalibUtils::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//_____________________________________________________________________________
117unsigned int
118TileCalibUtils::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//_____________________________________________________________________________
126unsigned int
127TileCalibUtils::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//_____________________________________________________________________________
135unsigned 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//_____________________________________________________________________________
144std::string
145TileCalibUtils::getDrawerString(unsigned int ros, unsigned int drawer)
146{
147 //=== check for valid index
148 TileCalibUtils::getDrawerIdx(ros, drawer);
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//_____________________________________________________________________________
163unsigned 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//_____________________________________________________________________________
244unsigned int
245TileCalibUtils::getDefaultDrawerIdx(unsigned int ros, unsigned int drawer)
246{
247 return getDefaultDrawerIdx(getDrawerIdx(ros, drawer));
248}
249
250//
251//_____________________________________________________________________________
252unsigned 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//____________________________________________________________________
267float
268TileCalibUtils::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
static unsigned int getAdcIdx(unsigned int ros, unsigned int drawer, unsigned int channel, unsigned int adc)
Returns an ADC hash.
static const unsigned int MAX_DRAWERIDX
Maximal drawer index.
static const unsigned int MAX_ROS
Number of ROSs.
static const unsigned int NOGAINL1_DEFINITION_CHAN
Channel used for storing of NoGainLevel1 channel definitions.
static const unsigned int LAS_PART_CHAN
Empty channel number to store laser partition variation.
static const unsigned int BADTIMING_DEFINITION_CHAN
Channel used for storing of bad timing channel definitions.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static unsigned int getDrawerIdxFromFragId(unsigned int fragId)
Returns a drawer hash from fragId This function assumes drawer context (i.e.
static const unsigned int WRONGBCID_DEFINITION_CHAN
Channel used for storing of wrong BCID channel definitions.
static const unsigned int TRIPS_ROS
Ros used for storing trips probabilities.
static float fixedPointPrecision(float val, unsigned int nBits=16)
Returns the input in fixed point precision.
static const unsigned int MAX_GAIN
Number of gains per channel.
static unsigned int getChanIdx(unsigned int ros, unsigned int drawer, unsigned int channel)
Returns a channel hash.
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
static const unsigned int NOISY_DEFINITION_CHAN
Channel used for storing of noisy channel definitions.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
static const unsigned int TRIPS_DRAWER
Drawer used for storing trips probabilities.
static unsigned int getFirstDrawerInPartitionIdx(unsigned int drawerIdx)
Returns the first drawer Idx in a partition of a given input drawer.
static unsigned int getMaxDrawer(unsigned int ros)
Returns the maximal channel number for a given drawer.
static const unsigned int TRIPS_DRAWERIDX
DrawerIdx used for storing trips probabilities.
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.
static unsigned int getAdcIdxFromFragId(unsigned int fragId, unsigned int channel, unsigned int adc)
Returns an ADC hash.
static const unsigned int DEFINITIONS_DRAWERIDX
Drawer used for storing of bad and noisy channel definitions.
static unsigned int getDefaultDrawerIdx(unsigned int drawerIdx)
Returns the default drawer for a given input drawer.
static const unsigned int MAX_CHAN
Number of channels in drawer.
static const unsigned int TIMINGDMUBCOFFSET_DEFINITION_CHAN
Channel used for storing of affected timing channel definitions.
static const unsigned int BAD_DEFINITION_CHAN
Channel used for storing of bad channel definitions.
static unsigned int getChanIdxFromFragId(unsigned int fragId, unsigned int channel)
Returns a channel hash.
static const unsigned int MAX_DRAWR0
Number of drawers in ROS 0.