ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawTowerDefs.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawTowerDefs.h
1 #ifndef CALOBASE_RAWTOWERDEFS_H
2 #define CALOBASE_RAWTOWERDEFS_H
3 
4 #include <cstdlib>
5 #include <iostream>
6 #include <string>
7 #include <bitset>
8 
13 namespace RawTowerDefs
14 {
17  typedef unsigned int keytype;
18 
21  static unsigned int calo_idbits = 8;
22  static unsigned int tower_idbits = sizeof(keytype) * 8 - calo_idbits;
23  static unsigned int index1_idbits = tower_idbits / 2;
24 
29  {
30  NONE = 0,
31  CEMC = 1,
32  HCALOUT = 2,
33  HCALIN = 3,
34  EEMC = 4,
35  FEMC = 5,
36  FHCAL = 6,
37  DRCALO = 7,
38  EHCAL = 8,
40  EEMC_glass = 10,
41  LFHCAL = 11,
42  BECAL = 12,
43  ZDC = 13,
44  B0ECAL = 14,
45  BWD_0 = 15,
46  BWD_1 = 16,
47  BWD_2 = 17,
48  BWD_3 = 18,
49  BWD_4 = 19
50  };
51 
55  encode_towerid(const CalorimeterId calo_id, const unsigned int tower_index_1,
56  const unsigned int tower_index_2)
57  {
58  RawTowerDefs::keytype calo_tower_id = 0;
59 
60  if (tower_index_1 < 0xFFF && tower_index_2 < 0xFFF)
61  {
62  calo_tower_id = (calo_id << RawTowerDefs::tower_idbits) + (tower_index_1 << RawTowerDefs::index1_idbits) + tower_index_2;
63  }
64  else
65  {
66  std::cout << "too large index1 and/or index2; index1: "
67  << tower_index_1 << " (max val " << 0xFFF << ")"
68  << ", index2: "
69  << tower_index_2 << " (max val " << 0xFFF << ")" << std::endl;
70  exit(1);
71  }
72 
73  return calo_tower_id;
74  }
75 
79  encode_towerid(const CalorimeterId calo_id, const unsigned int tower_index)
80  {
81  RawTowerDefs::keytype calo_tower_id = 0;
82 
83  if (tower_index < 0xFFFFFF)
84  {
85  calo_tower_id = (calo_id << RawTowerDefs::tower_idbits) + tower_index;
86  }
87  else
88  {
89  std::cout << "too large index; index: " << tower_index
90  << " (max val " << 0xFFFFFF << ")" << std::endl;
91  exit(1);
92  }
93 
94  return calo_tower_id;
95  }
96 
99  inline CalorimeterId
100  decode_caloid(const unsigned int calo_tower_id)
101  {
102  return static_cast<CalorimeterId>((calo_tower_id >> RawTowerDefs::tower_idbits) & 0xFFF);
103  }
104 
107  inline unsigned int
108  decode_index(const unsigned int calo_tower_id)
109  {
110  return (calo_tower_id) &0xFFFFFF;
111  }
112 
115  inline unsigned int
116  decode_index1(const unsigned int calo_tower_id)
117  {
118  return (calo_tower_id >> RawTowerDefs::index1_idbits) & 0xFFF;
119  }
120 
123  inline unsigned int
124  decode_index2(const unsigned int calo_tower_id)
125  {
126  return calo_tower_id & 0xFFF;
127  }
128 
129 
132  inline unsigned int
133  decode_index1v2(const unsigned int calo_tower_id)
134  {
135 // static unsigned int bitsIndex1 = 10;
136  static unsigned int bitsIndex2 = 10; // max 0x3FF (1023)
137  static unsigned int bitsIndex3 = 4; // max 0xF (15)
138 
139 // std::cout << std::bitset<32>(calo_tower_id) << "\t index 1: " << ((calo_tower_id >> (bitsIndex2+bitsIndex3) & 0x3FF)) << "\t"<< std::bitset<32>((calo_tower_id >> (bitsIndex2+bitsIndex3))) << "\t"<< std::bitset<32>((calo_tower_id >> (bitsIndex2+bitsIndex3))& 0x3FF) <<std::endl;
140  return (calo_tower_id >> (bitsIndex2+bitsIndex3)) & 0x3FF;
141  }
142 
145  inline unsigned int
146  decode_index2v2(const unsigned int calo_tower_id)
147  {
148  static unsigned int bitsIndex3 = 4; // max 0xF (15)
149 // std::cout << std::bitset<32>(calo_tower_id) << "\t index 2: " << ((calo_tower_id >> (bitsIndex3) & 0x3FF)) << "\t"<< std::bitset<32>((calo_tower_id >> (bitsIndex3))) << "\t"<< std::bitset<32>((calo_tower_id >> (bitsIndex3))& 0x3FF) <<std::endl;
150  return (calo_tower_id >> (bitsIndex3)) & 0x3FF;
151  }
152 
155  inline unsigned int
156  decode_index3v2(const unsigned int calo_tower_id)
157  {
158 // std::cout << std::bitset<32>(calo_tower_id) << "\t index 3: " << (calo_tower_id & 0xF) << "\t"<< std::bitset<32>((calo_tower_id & 0xF)) <<std::endl;
159  return calo_tower_id & 0xF;
160  }
161 
164  inline RawTowerDefs::keytype
165  encode_towerid(const CalorimeterId calo_id, const unsigned int tower_index_1,
166  const unsigned int tower_index_2, const unsigned int tower_index_3)
167  {
168  RawTowerDefs::keytype calo_tower_id = 0;
169 
170 // static unsigned int bitsIndex1 = 10; // max 0x3FF (1023)
171  static unsigned int bitsIndex2 = 10; // max 0x3FF (1023)
172  static unsigned int bitsIndex3 = 4; // max 0xF (15)
173 
174  if (tower_index_1 < 0x3FF && tower_index_2 < 0x3FF && tower_index_3 < 0xF)
175  {
176  calo_tower_id = (calo_id << RawTowerDefs::tower_idbits) + (tower_index_1 << (bitsIndex2+bitsIndex3)) + (tower_index_2 << bitsIndex3) + tower_index_3;
177  }
178  else
179  {
180  std::cout << "too large index1 and/or index2; index1: "
181  << tower_index_1 << " (max val " << 0x3FF << ")"
182  << ", index2: "
183  << tower_index_2 << " (max val " << 0x3FF << ")"
184  << ", index3: "
185  << tower_index_3 << " (max val " << 0xF << ")"<< std::endl;
186  exit(1);
187  }
188 // std::cout << std::bitset<32>(calo_tower_id) << "\t" << std::bitset<8>(calo_id) << "\t"<< tower_index_1 << "\t"<< std::bitset<10>(tower_index_1) << "\t"<< tower_index_2 << "\t"<< std::bitset<10>(tower_index_2) << "\t"<< tower_index_3<< "\t"<< std::bitset<4>(tower_index_3) << std::endl;
189 // decode_index1v2(calo_tower_id);
190 // decode_index2v2(calo_tower_id);
191 // decode_index3v2(calo_tower_id);
192  return calo_tower_id;
193  }
194 
197  inline std::string
199  {
200  switch (calo_id)
201  {
202  case NONE:
203  return "NONE";
204  break;
205 
206  case DRCALO:
207  return "DRCALO";
208  break;
209 
210  case CEMC:
211  return "CEMC";
212  break;
213 
214  case HCALIN:
215  return "HCALIN";
216  break;
217 
218  case HCALOUT:
219  return "HCALOUT";
220  break;
221 
222  case EEMC:
223  return "EEMC";
224  break;
225 
226  case EHCAL:
227  return "EHCAL";
228  break;
229 
230  case FEMC:
231  return "FEMC";
232  break;
233 
234  case FHCAL:
235  return "FHCAL";
236  break;
237 
238  case BECAL:
239  return "BECAL";
240  break;
241 
242  case EEMC_crystal:
243  return "EEMC_crystal";
244  break;
245 
246  case EEMC_glass:
247  return "EEMC_glass";
248  break;
249 
250  case LFHCAL:
251  return "LFHCAL";
252  break;
253 
254  case ZDC:
255  return "ZDC";
256  break;
257 
258  case B0ECAL:
259  return "B0ECAL";
260  break;
261 
262  case BWD_0:
263  return "BWD_0";
264  break;
265 
266  case BWD_1:
267  return "BWD_1";
268  break;
269 
270  case BWD_2:
271  return "BWD_2";
272  break;
273 
274  case BWD_3:
275  return "BWD_3";
276  break;
277 
278  case BWD_4:
279  return "BWD_4";
280  break;
281 
282  default:
283  std::cout
284  << "Invalid calorimeter ID passed to RawTowerDefs::convert_caloid_to_name"
285  << std::endl;
286  exit(1);
287  }
288  }
289 
293  convert_name_to_caloid(const std::string &caloname)
294  {
295  if (caloname == "NONE")
296  return NONE;
297 
298  else if (caloname == "CEMC")
299  return CEMC;
300 
301  else if (caloname == "DRCALO")
302  return DRCALO;
303 
304  else if (caloname == "HCALIN")
305  return HCALIN;
306 
307  else if (caloname == "HCALOUT")
308  return HCALOUT;
309 
310  else if (caloname == "EEMC")
311  return EEMC;
312 
313  else if (caloname == "EHCAL")
314  return EHCAL;
315 
316  else if (caloname == "FEMC")
317  return FEMC;
318 
319  else if (caloname == "FHCAL")
320  return FHCAL;
321 
322  else if (caloname == "EEMC_crystal")
323  return EEMC_crystal;
324 
325  else if (caloname == "EEMC_glass")
326  return EEMC_glass;
327 
328  else if (caloname == "LFHCAL")
329  return LFHCAL;
330 
331  else if (caloname == "BECAL")
332  return BECAL;
333 
334  else if (caloname == "ZDC")
335  return ZDC;
336 
337  else if (caloname == "B0ECAL")
338  return B0ECAL;
339 
340  else if (caloname == "BWD_0")
341  return BWD_0;
342 
343  else if (caloname == "BWD_1")
344  return BWD_1;
345 
346  else if (caloname == "BWD_2")
347  return BWD_2;
348 
349  else if (caloname == "BWD_3")
350  return BWD_3;
351 
352  else if (caloname == "BWD_4")
353  return BWD_4;
354 
355  else
356  {
357  std::cout << "Invalid calorimeter name " << caloname
358  << " passed to RawTowerDefs::convert_name_to_caloid" << std::endl;
359  exit(1);
360  }
361  }
362 
363 } // end namespace RawTowerDefs
364 
365 #endif