Analysis Software
Documentation for sPHENIX simulation 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 <bitset>
5 #include <cstdlib>
6 #include <iostream>
7 #include <string>
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 
131  inline unsigned int
132  decode_index1v2(const unsigned int calo_tower_id)
133  {
134  // static unsigned int bitsIndex1 = 10;
135  static unsigned int bitsIndex2 = 10; // max 0x3FF (1023)
136  static unsigned int bitsIndex3 = 4; // max 0xF (15)
137 
138  // 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;
139  return (calo_tower_id >> (bitsIndex2 + bitsIndex3)) & 0x3FF;
140  }
141 
144  inline unsigned int
145  decode_index2v2(const unsigned int calo_tower_id)
146  {
147  static unsigned int bitsIndex3 = 4; // max 0xF (15)
148  // 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;
149  return (calo_tower_id >> (bitsIndex3)) & 0x3FF;
150  }
151 
154  inline unsigned int
155  decode_index3v2(const unsigned int calo_tower_id)
156  {
157  // 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;
158  return calo_tower_id & 0xF;
159  }
160 
163  inline RawTowerDefs::keytype
164  encode_towerid(const CalorimeterId calo_id, const unsigned int tower_index_1,
165  const unsigned int tower_index_2, const unsigned int tower_index_3)
166  {
167  RawTowerDefs::keytype calo_tower_id = 0;
168 
169  // static unsigned int bitsIndex1 = 10; // max 0x3FF (1023)
170  static unsigned int bitsIndex2 = 10; // max 0x3FF (1023)
171  static unsigned int bitsIndex3 = 4; // max 0xF (15)
172 
173  if (tower_index_1 < 0x3FF && tower_index_2 < 0x3FF && tower_index_3 < 0xF)
174  {
175  calo_tower_id = (calo_id << RawTowerDefs::tower_idbits) + (tower_index_1 << (bitsIndex2 + bitsIndex3)) + (tower_index_2 << bitsIndex3) + tower_index_3;
176  }
177  else
178  {
179  std::cout << "too large index1 and/or index2; index1: "
180  << tower_index_1 << " (max val " << 0x3FF << ")"
181  << ", index2: "
182  << tower_index_2 << " (max val " << 0x3FF << ")"
183  << ", index3: "
184  << tower_index_3 << " (max val " << 0xF << ")" << std::endl;
185  exit(1);
186  }
187  // 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;
188  // decode_index1v2(calo_tower_id);
189  // decode_index2v2(calo_tower_id);
190  // decode_index3v2(calo_tower_id);
191  return calo_tower_id;
192  }
193 
196  inline std::string
198  {
199  switch (calo_id)
200  {
201  case NONE:
202  return "NONE";
203  break;
204 
205  case DRCALO:
206  return "DRCALO";
207  break;
208 
209  case CEMC:
210  return "CEMC";
211  break;
212 
213  case HCALIN:
214  return "HCALIN";
215  break;
216 
217  case HCALOUT:
218  return "HCALOUT";
219  break;
220 
221  case EEMC:
222  return "EEMC";
223  break;
224 
225  case EHCAL:
226  return "EHCAL";
227  break;
228 
229  case FEMC:
230  return "FEMC";
231  break;
232 
233  case FHCAL:
234  return "FHCAL";
235  break;
236 
237  case BECAL:
238  return "BECAL";
239  break;
240 
241  case EEMC_crystal:
242  return "EEMC_crystal";
243  break;
244 
245  case EEMC_glass:
246  return "EEMC_glass";
247  break;
248 
249  case LFHCAL:
250  return "LFHCAL";
251  break;
252 
253  case ZDC:
254  return "ZDC";
255  break;
256 
257  case B0ECAL:
258  return "B0ECAL";
259  break;
260 
261  case BWD_0:
262  return "BWD_0";
263  break;
264 
265  case BWD_1:
266  return "BWD_1";
267  break;
268 
269  case BWD_2:
270  return "BWD_2";
271  break;
272 
273  case BWD_3:
274  return "BWD_3";
275  break;
276 
277  case BWD_4:
278  return "BWD_4";
279  break;
280 
281  default:
282  std::cout
283  << "Invalid calorimeter ID passed to RawTowerDefs::convert_caloid_to_name"
284  << std::endl;
285  exit(1);
286  }
287  }
288 
293  {
294  if (caloname == "NONE")
295  return NONE;
296 
297  else if (caloname == "CEMC")
298  return CEMC;
299 
300  else if (caloname == "DRCALO")
301  return DRCALO;
302 
303  else if (caloname == "HCALIN")
304  return HCALIN;
305 
306  else if (caloname == "HCALOUT")
307  return HCALOUT;
308 
309  else if (caloname == "EEMC")
310  return EEMC;
311 
312  else if (caloname == "EHCAL")
313  return EHCAL;
314 
315  else if (caloname == "FEMC")
316  return FEMC;
317 
318  else if (caloname == "FHCAL")
319  return FHCAL;
320 
321  else if (caloname == "EEMC_crystal")
322  return EEMC_crystal;
323 
324  else if (caloname == "EEMC_glass")
325  return EEMC_glass;
326 
327  else if (caloname == "LFHCAL")
328  return LFHCAL;
329 
330  else if (caloname == "BECAL")
331  return BECAL;
332 
333  else if (caloname == "ZDC")
334  return ZDC;
335 
336  else if (caloname == "B0ECAL")
337  return B0ECAL;
338 
339  else if (caloname == "BWD_0")
340  return BWD_0;
341 
342  else if (caloname == "BWD_1")
343  return BWD_1;
344 
345  else if (caloname == "BWD_2")
346  return BWD_2;
347 
348  else if (caloname == "BWD_3")
349  return BWD_3;
350 
351  else if (caloname == "BWD_4")
352  return BWD_4;
353 
354  else
355  {
356  std::cout << "Invalid calorimeter name " << caloname
357  << " passed to RawTowerDefs::convert_name_to_caloid" << std::endl;
358  exit(1);
359  }
360  }
361 
362 } // end namespace RawTowerDefs
363 
364 #endif