ATLAS Offline Software
TRT_StrawMap.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef __STRAW_MAP_H__
6 #define __STRAW_MAP_H__
7 
8 
11 
12 #include <iostream>
13 #include <cassert>
14 #include <cmath>
15 
17 
18 // *************************************************************************************************************
19 // Sasa Fratina / July 22, 2011
20 //
21 // athena to detector read-out numbering mapping
22 // documented in ATL-COM-INDET-2010-002
23 // debugged using special noise scans done by Jon Stahlman and by Mike Hance
24 //
25 // call from your code by using one of the two constructors, and then access any value you want
26 // recommended: create one dummy instance of strawMap class that lives for the full length of the code, like:
27 // main() ... strawMap dummy_straw(1,0,0); - otherwise inicializations might be called many times
28 // *************************************************************************************************************
29 
30 class strawMap {
31 
32 public:
33 
34  strawMap(int side, int phi, int straw); // straw: unique straw index within a phi sector, 0-1641 for barrel and 1642-5481 for end-cap straws, used also bt TRT_StrawStatus
35  strawMap(int side, int phi, int layer, int strawLayer, int strawWithinStrawLayer); // the five athena identifiers
36 
37  ~strawMap();
38 
39  inline int side() const { return m_side; }
40  inline int phi() const { return m_phi; }
41  inline int straw() const { return m_straw; }
42 
43  inline int layer() const { return m_strawToLayer[m_straw]; };
44  inline int strawLayer() const { return m_strawToStrawLayer[m_straw]; };
45  inline int strawWithinLayer() const { return m_strawToStrawWithinLayer[m_straw]; };
46 
47  int DTMROC();
48  int ASDBLR();
49  int TTCgroup();
50 
51  int HVpad();
52 
53 private:
54 
55  int m_side; // +1 side A -1 side C
56  int m_phi;
57  int m_straw;
58 
62 
63  static int *m_strawToHVpad_barrel;
64 
65  static int *m_strawToLayer;
66  static int *m_strawToStrawLayer;
68 
69  static int m_instance_count;
70 
71  void initialize();
72  void clean_up();
73 
74  int barrelStrawNumber(int strawNumber, int strawlayerNumber, int LayerNumber);
75  int endcapStrawNumber(int strawNumber, int strawLayerNumber, int layerNumber);
76  int ec_chip(int side, int phi, int layerNumber, int strawLayerNumber, int strawNumber);
77 };
78 
82 
84 
88 
90 
91 
92 
93 strawMap::strawMap(int side, int phi, int straw) : m_side(side), m_phi(phi), m_straw(straw) {
94 
97 
98  assert( straw>=0 && straw<5482 );
99  assert( std::abs(side)==1 || std::abs(side)==2 );
100  assert( phi>=0 && phi<32 );
101 };
102 
103 strawMap::strawMap(int side, int phi, int layer, int strawLayer, int strawWithinStrawLayer) : m_side(side), m_phi(phi) {
104 
107 
108  m_straw = (std::abs(side)==1) ? barrelStrawNumber(strawWithinStrawLayer, strawLayer, layer) : endcapStrawNumber(strawWithinStrawLayer, strawLayer, layer);
109 
110  assert( m_straw>=0 && m_straw<5482 );
111  assert( std::abs(side)==1 || std::abs(side)==2 );
112  assert( phi>=0 && phi<32 );
113 };
114 
117  if (m_instance_count==0) clean_up();
118 };
119 
121 
122  if (std::abs(m_side)==1) return m_strawToDTMROC_barrel[m_straw];
123 
124  assert( std::abs(m_side)==2 ); // end-caps
125  int layerNumber = this->layer();
126  int strawLayerNumber = this->strawLayer();
127  int strawNumber = this->strawWithinLayer();
128 
129  int chip = ec_chip( m_side, m_phi, layerNumber, strawLayerNumber, strawNumber); // returns 0-11
130  chip += 12 * ( this->TTCgroup() - 9 ); // increment according to the board number
131  chip += 104;
132  return chip;
133 };
134 
136 
138  else if (m_side==-1) return m_strawToASDBLR_barrelSideC[m_straw];
139 
140  assert(std::abs(m_side)==2);
141 
142  int strawNumber = this->strawWithinLayer();
143  int strawLayerNumber = this->strawLayer();
144 
145  int asdblr = (strawNumber%4 - strawNumber%2) / 2;
146  if (!(asdblr==0||asdblr==1)) printf("ASDBLR error: %d\n", asdblr);
147  if (strawLayerNumber%8 >= 4) asdblr = 1 - asdblr;
148  if (m_side<0) asdblr = 1 - asdblr;
149 
150  return asdblr;
151 };
152 
154 
155  if (std::abs(m_side)==1) { // barrel
156 
157  // return logical board index:
158  // 0 for Board 1S (has 10 chips) 0 - 9
159  // 1 for 1L (11) 10 - 20
160  // 2 for 2S (15) 21 - 35
161  // 3 for 2L, first 9 chips 36 - 44
162  // 4 for 2L, second 9 chips 45 - 53
163  // 5 for 3S, first 11 54 - 64
164  // 6 for 3S, second 12 65 - 76
165  // 7 for 3L, first 13 77 - 89
166  // 8 for 3L, second 14 90 - 103
167 
168  const int list[] = {10, 11, 15, 9, 9, 11, 12, 13, 14};
169  int count = 0;
170 
171  int chip = this->DTMROC();
172 
173  for (int i=0; i<9; i++) {
174  count += list[i];
175  if (chip < count) return i;
176  }
177 
178  assert(count==104);
179  return -1;
180 
181  } else if (std::abs(m_side)==2) { // end-caps
182 
183  int straw = m_straw - 1642;
184  int board = 9;
185  while (straw>=192) { // the number of straws per triplet board
186  straw -= 192;
187  board++;
188  }
189  return board;
190  }
191 
192  assert(0);
193  return -1;
194 };
195 
197  if (std::abs(m_side)==1) return m_strawToHVpad_barrel[m_straw];
198  assert( std::abs(m_side)==2 ); // end-caps
199  auto asdblr = this->ASDBLR();
200  if (asdblr < 0){
201  throw std::runtime_error("asdblr is less than zero");
202  }
203  return ( (this->DTMROC()) * 2 + (asdblr) );
204 };
205 
207 
208  printf("strawMap::initialize - initialize table containters\n");
209  static int count_initialize(0); count_initialize++;
210  if (count_initialize>2) {
211  printf("strawMap::initialize - if you are seeing a lot of this messages, \n");
212  printf(" create one dummy instance of strawMap class that lives \n");
213  printf(" from start till the end of your programm. \n");
214  }
215 
216  int table_length = 1642; // N straws in barrel
217  m_strawToDTMROC_barrel = new int[table_length];
218  m_strawToASDBLR_barrelSideA = new int[table_length];
219  m_strawToASDBLR_barrelSideC = new int[table_length];
220  for (int i=0; i<table_length; i++) {
224  }
225  m_strawToHVpad_barrel = new int[table_length];
226 
227  table_length = 5482; // N straws in barrel + end-caps
228  m_strawToStrawLayer = new int[table_length];
229  m_strawToLayer = new int[table_length];
230  m_strawToStrawWithinLayer = new int[table_length];
231 
232  for (int i=0; i<table_length; i++) {
233  m_strawToLayer[i] = 0;
234  m_strawToStrawLayer[i] = 0;
236  }
237 
238  int index[15];
239  int count(0);
240  char filename[1000]; sprintf(filename, "%s", PathResolver::find_file("TRT_CalibAlgs/TRT_StrawMap.txt", "DATAPATH").c_str());
241  FILE *f = fopen(filename, "r");
242  if (!f) {
243  printf("TRT_StrawMap::initialize() ERROR: failed to open the mapping file %s \n", filename);
244  printf("TRT_StrawMap::initialize() ERROR: you need to fix the file name / link, WILL CRASH THE CODE NOW\n");
245  std::abort();
246  }
247  //what are these numbers, what are valid ranges?
248  while(fscanf(f, "%d %d %d %d %d %d %d %d\n", index, index+1, index+2, index+3, index+4, index+5, index+6, index+7)==8) {
249  assert(index[0]>=0 && index[0]<5482);
250  m_strawToLayer[index[0]] = index[1];
253  if (index[0]<1642) {
258  }
259  count++;
260  }
261  printf("read %d lines from file %s\n", count, filename);
262  fclose(f);
263 
264  return;
265 };
266 
268 
269  printf("strawMap::clean_up - delete all tables\n\n");
270 
271  delete[] m_strawToLayer; m_strawToLayer = 0;
274 
278 
280 
281  return;
282 };
283 
284 int strawMap::barrelStrawNumber(int strawNumber, int strawlayerNumber, int LayerNumber) {
285 
286  const int numberOfStraws[74] = { 0, 15, 31, 47, 63, 79, 96, 113, 130, 147, 164, 182, 200, 218, 236, 254, 273, 292, 311, 329, // layer 0, 329 straws, strawlayers 0-18
287  348, 368, 388, 408, 428, 448, 469, 490, 511, 532, 553, 575, 597, 619, 641, 663, 686, 709, 732, 755, 778, 802, 826, 849, // layer 1, 520 straws, strawLayers 0-23
288  872, 896, 920, 944, 968, 993, 1018, 1043, 1068, 1093, 1119, 1145, 1171, 1197, 1223, 1250, 1277, 1304, 1331, 1358, 1386, 1414, 1442, 1470, 1498, 1527, 1556, 1585, 1614, 1642 }; // layer 2
289 
290  if (LayerNumber==1) strawlayerNumber+= 19;
291  else if (LayerNumber==2) strawlayerNumber+= 43;
292 
293  return ( numberOfStraws[strawlayerNumber+1] - strawNumber -1 );
294 };
295 
296 int strawMap::endcapStrawNumber(int strawNumber, int strawLayerNumber, int layerNumber) {
297 
298  int board = layerNumber;
299  if (board<6) { board *= 2; if (strawLayerNumber>7) board++; }
300  else { board += 6; }
301 
302  int straw = board * 192 + strawNumber * 8 + strawLayerNumber % 8 ;
303  straw += 1642;
304  return straw;
305 };
306 
307 int strawMap::ec_chip(int side, int phi, int /*layerNumber*/, int strawLayerNumber, int strawNumber) {
308  // endcap only, return 0-12
309 
310  assert( std::abs(side)==2 );
311 
312  static int count = 0;
313  static int *map_A0 = new int[12];
314  static int *map_A8 = new int[12];
315  static int *map_C0 = new int[12];
316  static int *map_C8 = new int[12];
317  if (!count) {
318  count++;
319  int chipIndexToChipHardware_A0[] = {2, 1, 3, 0, 6, 5, 7, 4, 10, 9, 11, 8};
320  int chipIndexToChipHardware_A8[] = {8, 11, 9, 10, 4, 7, 5, 6, 0, 3, 1, 2};
321  int chipIndexToChipHardware_C0[] = {1, 2, 0, 3, 5, 6, 4, 7, 9, 10, 8, 11};
322  int chipIndexToChipHardware_C8[] = {11, 8, 10, 9, 7, 4, 6, 5, 3, 0, 2, 1};
323  int *map_list[] = {map_A0, map_A8, map_C0, map_C8};
324  int *chip_list[] = {chipIndexToChipHardware_A0, chipIndexToChipHardware_A8, chipIndexToChipHardware_C0, chipIndexToChipHardware_C8};
325  for (int i=0; i<4; i++) for (int j=0; j<12; j++) map_list[i][j] = chip_list[i][j];
326  }
327 
328  int chip = (strawNumber - strawNumber%4) / 2;
329  if (strawLayerNumber%8 >= 4) chip++;
330 
331  int nominal_reversed = 1 - ( (phi - phi%8)/8 ) %2 ;
332  int *map = 0;
333  if (side==2) map = nominal_reversed ? map_A8 : map_A0;
334  if (side==-2) map = nominal_reversed ? map_C8 : map_C0;
335  if (not map) {
336  throw std::runtime_error("map pointer is null in TRT_StrawMap.h");
337  }
338  chip = map[chip];
339  return chip;
340 }
341 
342 #endif // __STRAW_MAP_H__
strawMap::m_strawToHVpad_barrel
static int * m_strawToHVpad_barrel
Definition: TRT_StrawMap.h:63
strawMap::barrelStrawNumber
int barrelStrawNumber(int strawNumber, int strawlayerNumber, int LayerNumber)
Definition: TRT_StrawMap.h:284
strawMap::m_strawToLayer
static int * m_strawToLayer
Definition: TRT_StrawMap.h:65
strawMap::m_side
int m_side
Definition: TRT_StrawMap.h:55
TRT::Hit::straw
@ straw
Definition: HitInfo.h:82
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
strawMap::initialize
void initialize()
Definition: TRT_StrawMap.h:206
strawMap::m_straw
int m_straw
Definition: TRT_StrawMap.h:57
strawMap::m_strawToStrawLayer
static int * m_strawToStrawLayer
Definition: TRT_StrawMap.h:66
index
Definition: index.py:1
strawMap::strawLayer
int strawLayer() const
Definition: TRT_StrawMap.h:44
TRT::Hit::strawLayer
@ strawLayer
Definition: HitInfo.h:81
strawMap::m_instance_count
static int m_instance_count
Definition: TRT_StrawMap.h:69
strawMap::ASDBLR
int ASDBLR()
Definition: TRT_StrawMap.h:135
strawMap
Definition: TRT_StrawMap.h:30
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
TRT::Hit::side
@ side
Definition: HitInfo.h:83
strawMap::DTMROC
int DTMROC()
Definition: TRT_StrawMap.h:120
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Definition: TRT_StrawMap.h:10
strawMap::~strawMap
~strawMap()
Definition: TRT_StrawMap.h:115
lumiFormat.i
int i
Definition: lumiFormat.py:85
strawMap::strawMap
strawMap(int side, int phi, int straw)
Definition: TRT_StrawMap.h:93
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
hist_file_dump.f
f
Definition: hist_file_dump.py:135
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
strawMap::endcapStrawNumber
int endcapStrawNumber(int strawNumber, int strawLayerNumber, int layerNumber)
Definition: TRT_StrawMap.h:296
strawMap::straw
int straw() const
Definition: TRT_StrawMap.h:41
strawMap::side
int side() const
Definition: TRT_StrawMap.h:39
strawMap::m_phi
int m_phi
Definition: TRT_StrawMap.h:56
PathResolver.h
strawMap::phi
int phi() const
Definition: TRT_StrawMap.h:40
strawMap::TTCgroup
int TTCgroup()
Definition: TRT_StrawMap.h:153
strawMap::m_strawToASDBLR_barrelSideC
static int * m_strawToASDBLR_barrelSideC
Definition: TRT_StrawMap.h:61
strawMap::strawWithinLayer
int strawWithinLayer() const
Definition: TRT_StrawMap.h:45
strawMap::m_strawToStrawWithinLayer
static int * m_strawToStrawWithinLayer
Definition: TRT_StrawMap.h:67
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
strawMap::m_strawToDTMROC_barrel
static int * m_strawToDTMROC_barrel
Definition: TRT_StrawMap.h:59
strawMap::HVpad
int HVpad()
Definition: TRT_StrawMap.h:196
strawMap::clean_up
void clean_up()
Definition: TRT_StrawMap.h:267
strawMap::ec_chip
int ec_chip(int side, int phi, int layerNumber, int strawLayerNumber, int strawNumber)
Definition: TRT_StrawMap.h:307
checker_macros.h
Define macros for attributes used to control the static checker.
strawMap::m_strawToASDBLR_barrelSideA
static int * m_strawToASDBLR_barrelSideA
Definition: TRT_StrawMap.h:60
strawMap::layer
int layer() const
Definition: TRT_StrawMap.h:43