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 ()) return fString;
22  int startIndex = fString.find_first_not_of(" \t\n");
23  int endIndex = fString.find_last_not_of(" \t\n");
24  return fString.substr(startIndex, (endIndex-startIndex)+1);
25  }
26 
27  int calibChannel (const std::string& fName) {
28  return
29  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 }
40 
42  const std::string& fField2, const std::string& fField3) {
43  if (!init (fFlavor, fField1, fField2, fField3)) {
44  std::cerr << "HcalText2DetIdConverter::HcalText2DetIdConverter-> Can not initiate detId from items: "
45  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
46  throw cms::Exception("HcalGenDetId initialization error")
47  << " Can not initiate detId from items: "
48  << fFlavor << '/' << fField1 << '/' << fField2 << '/' << fField3 << std::endl;
49  }
50 }
51 
53  init (fId);
54 }
55 
57  return HcalGenericDetId (mId).isHcalDetId ();
58 }
59 
62 }
63 
66 }
67 
70 }
71 
73  bool result = true;
74  flavorName = "UNKNOWN";
75  mId = fId;
76  HcalGenericDetId genId (mId);
77  if (fId == HcalDetId::Undefined) {
78  flavorName = "NA";
79  }
80  else if (genId.isHcalDetId ()) {
81  HcalDetId hcalId (mId);
85  genId.genericSubdet () == HcalGenericDetId::HcalGenForward ? "HF" : "H_UNKNOWN";
86  setField (1, hcalId.ieta());
87  setField (2, hcalId.iphi());
88  setField (3, hcalId.depth());
89  }
90  else if (genId.isHcalTrigTowerDetId ()) {
91  HcalTrigTowerDetId triggerId (mId);
92  if (triggerId == HcalTrigTowerDetId::Undefined) {
93  flavorName = "NT";
94  }
95  else {
96  flavorName = "HT";
97  setField (1, triggerId.ieta());
98  setField (2, triggerId.iphi());
99  setField (3, triggerId.version()*10 + triggerId.depth());
100 /*
101  if (triggerId.version() == 0) {
102  setField (1, triggerId.ieta());
103  setField (2, triggerId.iphi());
104  setField (3, 1);
105  } else if (triggerId.version() == 1) {
106  setField (1, triggerId.ieta());
107  setField (2, triggerId.iphi());
108  setField (3, 10); // We use the tens digit to indicate version
109  } else {
110  // Unknown version
111  }
112 */
113  }
114  }
115  else if (genId.isHcalZDCDetId ()) {
116  HcalZDCDetId zdcId (mId);
117  switch (zdcId.section()) {
118  case HcalZDCDetId::EM: flavorName = "ZDC_EM"; break;
119  case HcalZDCDetId::HAD: flavorName = "ZDC_HAD"; break;
120  case HcalZDCDetId::LUM: flavorName = "ZDC_LUM"; break;
121  case HcalZDCDetId::RPD: flavorName = "ZDC_RPD"; break;
122  default: result = false;
123  }
124  setField (1, zdcId.zside());
125  setField (2, zdcId.channel());
126  setField (3, -99);
127  }
128  else if (genId.isHcalCalibDetId ()) {
129  HcalCalibDetId calibId (mId);
131  switch (calibId.hcalSubdet()) {
132  case HcalBarrel: flavorName = "CALIB_HB"; break;
133  case HcalEndcap: flavorName = "CALIB_HE"; break;
134  case HcalOuter: flavorName = "CALIB_HO"; break;
135  case HcalForward: flavorName = "CALIB_HF"; break;
136  default: result = false;
137  }
138  setField (1, calibId.ieta());
139  setField (2, calibId.iphi());
140  setField (3, calibId.cboxChannel() );
141  } else if (calibId.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
142  flavorName="HOX";
143  setField (1, calibId.ieta());
144  setField (2, calibId.iphi());
145  setField (3, -999);
146  } else if (calibId.calibFlavor()==HcalCalibDetId::uMNqie) {
147  flavorName="UMNQIE";
148  setField (1, calibId.channel());
149  setField (2, -999);
150  setField (3, -999);
151  } else if (calibId.calibFlavor()==HcalCalibDetId::LASERMON) {
152  flavorName="LASMON";
153  setField (1, calibId.ieta());
154  setField (2, calibId.iphi());
155  setField (3, calibId.cboxChannel() );
156  } else if (calibId.calibFlavor()==HcalCalibDetId::CastorRadFacility) {
157  flavorName="CRF";
158  setField (1, calibId.rm());
159  setField (2, calibId.fiber());
160  setField (3, calibId.channel());
161  }
162  }
163  else {
164  flavorName = "UNKNOWN_FLAVOR";
165  std::cerr << "HcalText2DetIdConverter::init-> Unknown detId: " << std::hex << std::showbase << mId.rawId() << std::endl;
166  result = false;
167  }
168  return result;
169 }
170 
171 
172 bool HcalText2DetIdConverter::init (const std::string& fFlavor, const std::string& fField1,
173  const std::string& fField2, const std::string& fField3) {
174  bool result = true;
175  flavorName = strip (fFlavor);
176  field1 = strip (fField1);
177  field2 = strip (fField2);
178  field3 = strip (fField3);
179  if (flavorName == "HB" ||
180  flavorName == "HE" ||
181  flavorName == "HF" ||
182  flavorName == "HO") {
183  HcalSubdetector sub = flavorName == "HB" ? HcalBarrel :
184  flavorName == "HE" ? HcalEndcap :
185  flavorName == "HO" ? HcalOuter :
186  HcalForward;
187  mId = HcalDetId (sub, getField (1), getField (2), getField (3));
188  }
189  else if (flavorName == "HT") {
190  // We use the depth to signal the "version" being used (RCT or 1x1 HF). RCT
191  // has a 0 in the 10s digit, whereas 1x1 has a 1. The ones digit is still
192  // used to indicate depth, although in the 1x1 case this must be 0, so we
193  // set it as such.
194  mId = HcalTrigTowerDetId (getField (1), getField (2), getField (3));
195 /*
196  const int depth_field = getField(3);
197  const int ones = depth_field % 10;
198  const int tens = (depth_field - ones) / 10;
199  if (tens == 0) {
200  const int depth = ones;
201  const int version = 0;
202  mId = HcalTrigTowerDetId (getField (1), getField (2), depth, version);
203  } else if (tens == 1) {
204  const int depth = 0;
205  const int version = 1;
206  mId = HcalTrigTowerDetId(getField(1), getField(2), depth, version);
207  } else {
208  // Undefined version!
209  }
210 */
211  }
212  else if (flavorName.find ("ZDC_") == 0) {
214  if(flavorName == "ZDC_EM") section = HcalZDCDetId::EM;
215  else if(flavorName == "ZDC_HAD") section = HcalZDCDetId::HAD;
216  else if(flavorName == "ZDC_LUM") section = HcalZDCDetId::LUM;
217  else if(flavorName == "ZDC_RPD") section = HcalZDCDetId::RPD;
218  mId = HcalZDCDetId (section, getField (1)>0, getField (2));
219  }
220  else if (flavorName.find ("CALIB_") == 0) {
222  if (flavorName.find("HB")!=std::string::npos) sd=HcalBarrel;
223  else if (flavorName.find("HE")!=std::string::npos) sd=HcalEndcap;
224  else if (flavorName.find("HO")!=std::string::npos) sd=HcalOuter;
225  else if (flavorName.find("HF")!=std::string::npos) sd=HcalForward;
226 
227  int ieta=getField(1);
228  int iphi=getField(2);
229  int channel = calibChannel (field3);
230  mId = HcalCalibDetId (sd, ieta,iphi,channel);
231  }
232  else if (flavorName=="HOX") {
233  int ieta=getField(1);
234  int iphi=getField(2);
235  mId = HcalCalibDetId (ieta,iphi);
236  }
237  else if (flavorName=="UMNQIE") {
238  int channel=getField(1);
240  }
241  else if (flavorName == "LASMON" ) {
242  int ieta = getField(1);
243  int iphi = getField(2);
244  int channel = getField(3);
245  mId = HcalCalibDetId (HcalCalibDetId::LASERMON, ieta, iphi, channel);
246  }
247  else if (flavorName=="CRF") {
248  int rm=getField(1);
249  int fiber=getField(2);
250  int channel=getField(3);
252  }
253  else if (flavorName == "NA") {
255  }
256  else {
257  std::cerr << "HcalText2DetIdConverter::init-> Unknown HcalDetId flavor: " << flavorName << std::endl;
258  result = false;
259  }
260  return result;
261 }
262 
263 
265  char* endptr;
266  const char* nptr = i == 1 ? field1.c_str() :
267  i == 2 ? field2.c_str() : field3.c_str();
268  long result = strtol (nptr, &endptr, 0);
269  if (*nptr != '\0' && *endptr == '\0') {
270  return result;
271  }
272  if (i == 2 && isHcalCalibDetId ()) {
273  int result = calibChannel (field2);
274  if (i) return result;
275  }
276  if (*nptr != '\0') {
277  std::cerr << "HcalText2DetIdConverter::getField-> Can not convert string "<< nptr << " to int. Bad symbol: " << *endptr << std::endl;
278  }
279  return 0;
280  }
281 
282 void HcalText2DetIdConverter::setField (int i, int fValue) {
283  char buffer [128];
284  sprintf (buffer, "%d", fValue);
285  if (i == 1) field1 = buffer;
286  else if (i == 2) field2 = buffer;
287  else field3 = buffer;
288 }
289 
291  return flavorName + " " + field1 + " " + field2 + " " + field3;
292 }
static const HcalDetId Undefined
Definition: HcalDetId.h:268
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:47
int ieta() const
get the tower ieta
int ieta() const
get the rbx name (if relevant)
int depth() const
get the depth (zero for LHC Run 1, may be nonzero for later runs)
int depth() const
get the tower depth
Definition: HcalDetId.h:162
bool isHcalTrigTowerDetId() const
void setField(int i, int fValue)
int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
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")
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)
int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
Definition: DetId.h:18
double sd
int version() const
get the version code for the trigger tower
int channel() const
get the channel
Definition: HcalZDCDetId.cc:62
static const HcalTrigTowerDetId Undefined
Section section() const
get the section
Definition: HcalZDCDetId.cc:47
int cboxChannel() const
get the calibration box channel (if relevant)
bool isHcalCalibDetId() const
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
HcalGenericSubdetector genericSubdet() const
rm
Definition: submit.py:76
int channel() const
get the channel (for uMNio/qie or similar)
int iphi() const
get the tower iphi