CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalText2DetIdConverter.cc
Go to the documentation of this file.
1 
4 #include <cstdlib>
5 #include <iostream>
6 #include <iomanip>
7 #include <cstdio>
8 
10 
16 
18 
19 namespace {
20  std::string strip(const std::string& fString) {
21  if (fString.empty())
22  return fString;
23  int startIndex = fString.find_first_not_of(" \t\n");
24  int endIndex = fString.find_last_not_of(" \t\n");
25  return fString.substr(startIndex, (endIndex - startIndex) + 1);
26  }
27 
28  int calibChannel(const std::string& fName) {
29  return fName == "Mixer-High" ? 1
30  : fName == "Mixer-Low" ? 2
31  : fName == "Megatile" ? 3
32  : fName == "Mixer-Scintillator" ? 4
33  : fName == "RadDam1" ? 5
34  : fName == "RadDam2" ? 6
35  : fName == "RadDam3" ? 7
36  : atoi(fName.c_str());
37  // 0;
38  }
39 } // namespace
40 
42  const std::string& fField1,
43  const std::string& fField2,
44  const std::string& fField3) {
45  if (!init(fFlavor, fField1, fField2, fField3)) {
46  std::cerr << "HcalText2DetIdConverter::HcalText2DetIdConverter-> Can not initiate detId from items: " << fFlavor
47  << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
48  throw cms::Exception("HcalGenDetId initialization error")
49  << " Can not initiate detId from items: " << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3
50  << std::endl;
51  }
52 }
53 
55 
57 
59 
61 
63 
65  bool result = true;
66  flavorName = "UNKNOWN";
67  mId = fId;
68  HcalGenericDetId genId(mId);
69  if (fId == HcalDetId::Undefined) {
70  flavorName = "NA";
71  } else if (genId.isHcalDetId()) {
72  HcalDetId hcalId(mId);
77  : "H_UNKNOWN";
78  setField(1, hcalId.ieta());
79  setField(2, hcalId.iphi());
80  setField(3, hcalId.depth());
81  } else if (genId.isHcalTrigTowerDetId()) {
82  HcalTrigTowerDetId triggerId(mId);
83  if (triggerId == HcalTrigTowerDetId::Undefined) {
84  flavorName = "NT";
85  } else {
86  flavorName = "HT";
87  setField(1, triggerId.ieta());
88  setField(2, triggerId.iphi());
89  setField(3, triggerId.version() * 10 + triggerId.depth());
90  /*
91  if (triggerId.version() == 0) {
92  setField (1, triggerId.ieta());
93  setField (2, triggerId.iphi());
94  setField (3, 1);
95  } else if (triggerId.version() == 1) {
96  setField (1, triggerId.ieta());
97  setField (2, triggerId.iphi());
98  setField (3, 10); // We use the tens digit to indicate version
99  } else {
100  // Unknown version
101  }
102 */
103  }
104  } else if (genId.isHcalZDCDetId()) {
105  HcalZDCDetId zdcId(mId);
106  switch (zdcId.section()) {
107  case HcalZDCDetId::EM:
108  flavorName = "ZDC_EM";
109  break;
110  case HcalZDCDetId::HAD:
111  flavorName = "ZDC_HAD";
112  break;
113  case HcalZDCDetId::LUM:
114  flavorName = "ZDC_LUM";
115  break;
116  case HcalZDCDetId::RPD:
117  flavorName = "ZDC_RPD";
118  break;
119  default:
120  result = false;
121  }
122  setField(1, zdcId.zside());
123  setField(2, zdcId.channel());
124  setField(3, -99);
125  } else if (genId.isHcalCalibDetId()) {
126  HcalCalibDetId calibId(mId);
127  if (calibId.calibFlavor() == HcalCalibDetId::CalibrationBox) {
128  switch (calibId.hcalSubdet()) {
129  case HcalBarrel:
130  flavorName = "CALIB_HB";
131  break;
132  case HcalEndcap:
133  flavorName = "CALIB_HE";
134  break;
135  case HcalOuter:
136  flavorName = "CALIB_HO";
137  break;
138  case HcalForward:
139  flavorName = "CALIB_HF";
140  break;
141  default:
142  result = false;
143  }
144  setField(1, calibId.ieta());
145  setField(2, calibId.iphi());
146  setField(3, calibId.cboxChannel());
147  } else if (calibId.calibFlavor() == HcalCalibDetId::HOCrosstalk) {
148  flavorName = "HOX";
149  setField(1, calibId.ieta());
150  setField(2, calibId.iphi());
151  setField(3, -999);
152  } else if (calibId.calibFlavor() == HcalCalibDetId::uMNqie) {
153  flavorName = "UMNQIE";
154  setField(1, calibId.channel());
155  setField(2, -999);
156  setField(3, -999);
157  } else if (calibId.calibFlavor() == HcalCalibDetId::LASERMON) {
158  flavorName = "LASMON";
159  setField(1, calibId.ieta());
160  setField(2, calibId.iphi());
161  setField(3, calibId.cboxChannel());
162  } else if (calibId.calibFlavor() == HcalCalibDetId::CastorRadFacility) {
163  flavorName = "CRF";
164  setField(1, calibId.rm());
165  setField(2, calibId.fiber());
166  setField(3, calibId.channel());
167  } else if (calibId.calibFlavor() == HcalCalibDetId::HBX) {
168  flavorName = "HBX";
169  setField(1, calibId.ieta());
170  setField(2, calibId.iphi());
171  setField(3, -999);
172  } else if (calibId.calibFlavor() == HcalCalibDetId::HEX) {
173  flavorName = "HEX";
174  setField(1, calibId.ieta());
175  setField(2, calibId.iphi());
176  setField(3, -999);
177  }
178  } else {
179  flavorName = "UNKNOWN_FLAVOR";
180  std::cerr << "HcalText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId()
181  << std::endl;
182  result = false;
183  }
184  return result;
185 }
186 
188  const std::string& fField1,
189  const std::string& fField2,
190  const std::string& fField3) {
191  bool result = true;
192  flavorName = strip(fFlavor);
193  field1 = strip(fField1);
194  field2 = strip(fField2);
195  field3 = strip(fField3);
196  if (flavorName == "HB" || flavorName == "HE" || flavorName == "HF" || flavorName == "HO") {
197  HcalSubdetector sub = flavorName == "HB" ? HcalBarrel
198  : flavorName == "HE" ? HcalEndcap
199  : flavorName == "HO" ? HcalOuter
200  : HcalForward;
201  mId = HcalDetId(sub, getField(1), getField(2), getField(3));
202  } else if (flavorName == "HT") {
203  // We use the depth to signal the "version" being used (RCT or 1x1 HF). RCT
204  // has a 0 in the 10s digit, whereas 1x1 has a 1. The ones digit is still
205  // used to indicate depth, although in the 1x1 case this must be 0, so we
206  // set it as such.
208  /*
209  const int depth_field = getField(3);
210  const int ones = depth_field % 10;
211  const int tens = (depth_field - ones) / 10;
212  if (tens == 0) {
213  const int depth = ones;
214  const int version = 0;
215  mId = HcalTrigTowerDetId (getField (1), getField (2), depth, version);
216  } else if (tens == 1) {
217  const int depth = 0;
218  const int version = 1;
219  mId = HcalTrigTowerDetId(getField(1), getField(2), depth, version);
220  } else {
221  // Undefined version!
222  }
223 */
224  } else if (flavorName.find("ZDC_") == 0) {
226  if (flavorName == "ZDC_EM")
227  section = HcalZDCDetId::EM;
228  else if (flavorName == "ZDC_HAD")
229  section = HcalZDCDetId::HAD;
230  else if (flavorName == "ZDC_LUM")
231  section = HcalZDCDetId::LUM;
232  else if (flavorName == "ZDC_RPD")
233  section = HcalZDCDetId::RPD;
234  mId = HcalZDCDetId(section, getField(1) > 0, getField(2));
235  } else if (flavorName.find("CALIB_") == 0) {
237  if (flavorName.find("HB") != std::string::npos)
238  sd = HcalBarrel;
239  else if (flavorName.find("HE") != std::string::npos)
240  sd = HcalEndcap;
241  else if (flavorName.find("HO") != std::string::npos)
242  sd = HcalOuter;
243  else if (flavorName.find("HF") != std::string::npos)
244  sd = HcalForward;
245 
246  int ieta = getField(1);
247  int iphi = getField(2);
248  int channel = calibChannel(field3);
249  mId = HcalCalibDetId(sd, ieta, iphi, channel);
250  } else if (flavorName == "HOX" || flavorName == "HBX" || flavorName == "HEX") {
251  int ieta = getField(1);
252  int iphi = getField(2);
253  mId = (flavorName == "HOX") ? (HcalCalibDetId(HcalCalibDetId::HOCrosstalk, ieta, iphi))
254  : ((flavorName == "HBX") ? (HcalCalibDetId(HcalCalibDetId::HBX, ieta, iphi))
255  : (HcalCalibDetId(HcalCalibDetId::HEX, ieta, iphi)));
256  } else if (flavorName == "UMNQIE") {
257  int channel = getField(1);
259  } else if (flavorName == "LASMON") {
260  int ieta = getField(1);
261  int iphi = getField(2);
262  int channel = getField(3);
263  mId = HcalCalibDetId(HcalCalibDetId::LASERMON, ieta, iphi, channel);
264  } else if (flavorName == "CRF") {
265  int rm = getField(1);
266  int fiber = getField(2);
267  int channel = getField(3);
269  } else if (flavorName == "NA") {
271  } else {
272  std::cerr << "HcalText2DetIdConverter::init-> Unknown HcalDetId flavor: " << flavorName << std::endl;
273  result = false;
274  }
275  return result;
276 }
277 
279  char* endptr;
280  const char* nptr = i == 1 ? field1.c_str() : i == 2 ? field2.c_str() : field3.c_str();
281  long result = strtol(nptr, &endptr, 0);
282  if (*nptr != '\0' && *endptr == '\0') {
283  return result;
284  }
285  if (i == 2 && isHcalCalibDetId()) {
286  int result = calibChannel(field2);
287  if (i)
288  return result;
289  }
290  if (*nptr != '\0') {
291  std::cerr << "HcalText2DetIdConverter::getField-> Can not convert string " << nptr
292  << " to int. Bad symbol: " << *endptr << std::endl;
293  }
294  return 0;
295 }
296 
297 void HcalText2DetIdConverter::setField(int i, int fValue) {
298  char buffer[128];
299  sprintf(buffer, "%d", fValue);
300  if (i == 1)
301  field1 = buffer;
302  else if (i == 2)
303  field2 = buffer;
304  else
305  field3 = buffer;
306 }
307 
309  return flavorName + " " + field1 + " " + field2 + " " + field3;
310 }
static const HcalDetId Undefined
Definition: HcalDetId.h:273
int rm() const
get the rm (where relevant)
bool isHcalZDCDetId() const
int fiber() const
get the fiber (where relevant)
CalibDetType calibFlavor() const
get the flavor of this calibration detid
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:39
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int ieta() const
get the tower ieta
int ieta() const
tuple result
Definition: mps_fire.py:311
int depth() const
get the depth (zero for LHC Run 1, may be nonzero for later runs)
bool isHcalTrigTowerDetId() const
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
void setField(int i, int fValue)
HcalSubdetector
Definition: HcalAssistant.h:31
HcalText2DetIdConverter(const std::string &fFlavor="NA", const std::string &fField1="0", const std::string &fField2="0", const std::string &fField3="0")
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
bool isHcalDetId() const
int iphi() const
get the low-edge iphi (if relevant)
bool init(const std::string &fFlavor, const std::string &fField1, const std::string &fField2, const std::string &fField3)
Definition: DetId.h:17
double sd
int version() const
get the version code for the trigger tower
int channel() const
get the channel
Definition: HcalZDCDetId.cc:63
string section
Definition: vertexPlots.py:496
static const HcalTrigTowerDetId Undefined
Section section() const
get the section
Definition: HcalZDCDetId.cc:44
int cboxChannel() const
get the calibration box channel (if relevant)
bool isHcalCalibDetId() const
def rm
Definition: eostools.py:363
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
HcalGenericSubdetector genericSubdet() const
int channel() const
get the channel (for uMNio/qie or similar)
int iphi() const
get the tower iphi