CMS 3D CMS Logo

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