EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RawTowerZDCDefs.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RawTowerZDCDefs.h
1 #ifndef EICZDCBASE_RAWTOWERZDCDEFS_H
2 #define EICZDCBASE_RAWTOWERZDCDEFS_H
3 
4 #include <cstdlib>
5 #include <iostream>
6 #include <string>
7 #include <bitset>
8 
13 namespace RawTowerZDCDefs
14 {
17  typedef unsigned int keytype;
18 
21  static unsigned int calo_idbits = 4;
22  static unsigned int tower_idbits = sizeof(keytype) * 8 - calo_idbits;
23  // static unsigned int bitsIndex1 = 10; //max 0x3FF (1023)
24  static unsigned int bitsIndex2 = 10; // max 0x3FF (1023)
25  static unsigned int bitsIndex3 = 8; // max 0xFF (255)
26  static unsigned int maxbitsCaloId = 0xF;
27  static unsigned int maxbitsIndex1 = 0x3FF;
28  static unsigned int maxbitsIndex2 = 0x3FF;
29  static unsigned int maxbitsIndex3 = 0xFF;
30 
35  {
36  NONE = 0,
40  ZDC_Sci = 4,
41  };
42 
45  inline CalorimeterId
46  decode_caloid(const unsigned int calo_tower_id)
47  {
48  return static_cast<CalorimeterId>((calo_tower_id >> RawTowerZDCDefs::tower_idbits) & maxbitsCaloId);
49  }
50 
53  inline unsigned int
54  decode_index1zdc(const unsigned int calo_tower_id)
55  {
56 
57  return (calo_tower_id >> (bitsIndex2+bitsIndex3)) & maxbitsIndex1;
58  }
59 
62  inline unsigned int
63  decode_index2zdc(const unsigned int calo_tower_id)
64  {
65 
66  return (calo_tower_id >> (bitsIndex3)) & maxbitsIndex2;
67  }
68 
71  inline unsigned int
72  decode_index3zdc(const unsigned int calo_tower_id)
73  {
74 
75  return calo_tower_id & maxbitsIndex3;
76  }
77 
78 
83  const unsigned int tower_index_1,
84  const unsigned int tower_index_2,
85  const unsigned int tower_index_3)
86  {
87  RawTowerZDCDefs::keytype calo_tower_id = 0;
88 
89  if (tower_index_1 < maxbitsIndex1 && tower_index_2 < maxbitsIndex2 && tower_index_3 < maxbitsIndex3)
90  {
91  calo_tower_id = (calo_id << RawTowerZDCDefs::tower_idbits) + (tower_index_1 << (bitsIndex2+bitsIndex3)) + (tower_index_2 << bitsIndex3) + tower_index_3;
92  }
93  else
94  {
95  std::cout << "too large index1 and/or index2; index1: "
96  << tower_index_1 << " (max val " << maxbitsIndex1 << ")"
97  << ", index2: "
98  << tower_index_2 << " (max val " << maxbitsIndex2 << ")"
99  << ", index3: "
100  << tower_index_3 << " (max val " << maxbitsIndex3 << ")"<< std::endl;
101  exit(1);
102  }
103 
104  return calo_tower_id;
105  }
106 
109  inline std::string
111  {
112  switch (calo_id)
113  {
114  case NONE:
115  return "NONE";
116  break;
117 
118  case ZDC_Crystal:
119  return "ZDC_Crtstal";
120  break;
121 
122  case ZDC_SiPixel:
123  return "ZDC_SiPixel";
124  break;
125 
126  case ZDC_SiPad:
127  return "ZDC_SiPad";
128  break;
129 
130  case ZDC_Sci:
131  return "ZDC_Sci";
132  break;
133 
134  default:
135  std::cout
136  << "Invalid calorimeter ID passed to RawTowerZDCDefs::convert_caloid_to_name"
137  << std::endl;
138  exit(1);
139  }
140  }
141 
145  convert_name_to_caloid(const std::string &caloname)
146  {
147  if (caloname == "NONE")
148  return NONE;
149 
150  else if (caloname == "ZDC_Crystal")
151  return ZDC_Crystal;
152 
153  else if (caloname == "ZDC_SiPixel")
154  return ZDC_SiPixel;
155 
156  else if (caloname == "ZDC_SiPad")
157  return ZDC_SiPad;
158 
159  else if (caloname == "ZDC_Sci")
160  return ZDC_Sci;
161 
162  else
163  {
164  std::cout << "Invalid calorimeter name " << caloname
165  << " passed to RawTowerZDCDefs::convert_name_to_caloid" << std::endl;
166  exit(1);
167  }
168  }
169 
170 } // end namespace RawTowerZDCDefs
171 
172 #endif