CMS 3D CMS Logo

EcalDQMCommonUtils.cc
Go to the documentation of this file.
2 
4 
5 #include <mutex>
6 
7 namespace ecaldqm {
12  const std::vector<unsigned> memDCC(memarr, memarr + 44);
13 
14  const double etaBound(1.479);
15 
16  unsigned dccId(const DetId &_id, const EcalElectronicsMapping *map) {
17  unsigned subdet(_id.subdetId());
18 
19  if (subdet == EcalBarrel)
20  return map->DCCid(EBDetId(_id));
21  else if (subdet == EcalTriggerTower)
22  return map->DCCid(EcalTrigTowerDetId(_id));
23  else if (subdet == EcalEndcap) {
24  if (isEcalScDetId(_id))
25  return map->getDCCandSC(EcalScDetId(_id)).first;
26  else
27  return map->getElectronicsId(EEDetId(_id)).dccId();
28  } else if (subdet == EcalLaserPnDiode)
29  return EcalPnDiodeDetId(_id).iDCCId();
30 
31  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::dccId(" << _id.rawId() << ")" << std::endl;
32 
33  return 0;
34  }
35 
36  unsigned dccId(const EcalElectronicsId &_id) { return _id.dccId(); }
37 
38  unsigned memDCCId(unsigned _index) {
39  // for DCCs with no MEM - map the index in an array of DCCs with no MEM to the
40  // DCC ID
41  if (_index >= memDCC.size())
42  return 0;
43  return memDCC.at(_index) + 1;
44  }
45 
46  unsigned memDCCIndex(unsigned _dccid) {
47  std::vector<unsigned>::const_iterator itr(std::find(memDCC.begin(), memDCC.end(), _dccid - 1));
48  if (itr == memDCC.end())
49  return -1;
50 
51  return (itr - memDCC.begin());
52  }
53 
54  unsigned tccId(const DetId &_id, const EcalElectronicsMapping *map) {
55  unsigned subdet(_id.subdetId());
56 
57  if (subdet == EcalBarrel)
58  return map->TCCid(EBDetId(_id));
59  else if (subdet == EcalTriggerTower)
60  return map->TCCid(EcalTrigTowerDetId(_id));
61  else if (subdet == EcalEndcap) {
62  if (isEcalScDetId(_id))
63  return 0; // incompatible
64  else
65  return map->getTriggerElectronicsId(EEDetId(_id)).tccId();
66  }
67 
68  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::tccId(" << uint32_t(_id) << ")" << std::endl;
69 
70  return 0;
71  }
72 
73  unsigned tccId(const EcalElectronicsId &_id, const EcalElectronicsMapping *map) {
74  return map->getTriggerElectronicsId(_id).tccId();
75  }
76 
77  unsigned towerId(const DetId &_id, const EcalElectronicsMapping *map) {
78  unsigned subdet(_id.subdetId());
79 
80  if (subdet == EcalBarrel)
81  return EBDetId(_id).tower().iTT();
82  else if (subdet == EcalTriggerTower)
83  return EcalTrigTowerDetId(_id).iTT();
84  else if (subdet == EcalEndcap) {
85  if (isEcalScDetId(_id))
86  return map->getDCCandSC(EcalScDetId(_id)).second;
87  else
88  return map->getElectronicsId(EEDetId(_id)).towerId();
89  }
90 
91  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::towerId(" << std::hex << uint32_t(_id) << ")"
92  << std::endl;
93 
94  return 0;
95  }
96 
97  unsigned towerId(const EcalElectronicsId &_id) { return _id.towerId(); }
98 
99  unsigned ttId(const DetId &_id, const EcalElectronicsMapping *map) {
100  unsigned subdet(_id.subdetId());
101 
102  if (subdet == EcalBarrel)
103  return EBDetId(_id).tower().iTT();
104  else if (subdet == EcalTriggerTower)
105  return map->iTT(EcalTrigTowerDetId(_id));
106  else if (subdet == EcalEndcap && !isEcalScDetId(_id))
107  return map->getTriggerElectronicsId(_id).ttId();
108 
109  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::ttId(" << std::hex << uint32_t(_id) << ")"
110  << std::endl;
111 
112  return 0;
113  }
114 
115  unsigned ttId(const EcalElectronicsId &_id, const EcalElectronicsMapping *map) {
116  return map->getTriggerElectronicsId(_id).ttId();
117  }
118 
119  unsigned rtHalf(DetId const &_id, const EcalElectronicsMapping *electronicsMap) {
120  if (_id.subdetId() == EcalBarrel) {
121  int ic(EBDetId(_id).ic());
122  if ((ic - 1) / 20 > 4 && (ic - 1) % 20 < 10)
123  return 1;
124  } else {
125  unsigned iDCC(dccId(_id, electronicsMap) - 1);
126  if ((iDCC == kEEm05 || iDCC == kEEp05) && EEDetId(_id).ix() > 50)
127  return 1;
128  }
129 
130  return 0;
131  }
132 
133  std::pair<unsigned, unsigned> innerTCCs(unsigned _dccId) {
134  int iDCC(_dccId - 1);
135  std::pair<unsigned, unsigned> res;
136  if (iDCC <= kEEmHigh) {
137  res.first = (iDCC - kEEmLow) * 2;
138  if (res.first == 0)
139  res.first = 18;
140  res.second = (iDCC - kEEmLow) * 2 + 1;
141  } else if (iDCC < -kEBpHigh)
142  res.first = res.second = _dccId + 27;
143  else {
144  res.first = (iDCC - kEEpLow) * 2 + 90;
145  if (res.first == 90)
146  res.first = 108;
147  res.second = (iDCC - kEEpLow) * 2 + 91;
148  }
149 
150  return res;
151  }
152 
153  std::pair<unsigned, unsigned> outerTCCs(unsigned _dccId) {
154  int iDCC(_dccId - 1);
155  std::pair<unsigned, unsigned> res;
156  if (iDCC <= kEEmHigh) {
157  res.first = (iDCC - kEEmLow) * 2 + 18;
158  if (res.first == 18)
159  res.first = 36;
160  res.second = (iDCC - kEEmLow) * 2 + 19;
161  } else if (iDCC <= kEBpHigh)
162  res.first = res.second = _dccId + 27;
163  else {
164  res.first = (iDCC - kEEpLow) * 2 + 72;
165  if (res.first == 72)
166  res.first = 90;
167  res.second = (iDCC - kEEpLow) * 2 + 73;
168  }
169 
170  return res;
171  }
172 
173  std::vector<DetId> scConstituents(EcalScDetId const &_scid) {
174  std::vector<DetId> res;
175 
176  int ixbase((_scid.ix() - 1) * 5);
177  int iybase((_scid.iy() - 1) * 5);
178 
179  for (int ix(1); ix <= 5; ++ix) {
180  for (int iy(1); iy <= 5; ++iy) {
181  if (EEDetId::validDetId(ixbase + ix, iybase + iy, _scid.zside()))
182  res.push_back(EEDetId(ixbase + ix, iybase + iy, _scid.zside()));
183  }
184  }
185 
186  return res;
187  }
188 
189  int zside(const DetId &_id) {
190  uint32_t rawId(_id);
191 
192  switch (_id.subdetId()) {
193  case EcalBarrel:
194  return (((rawId >> 16) & 0x1) == 1 ? 1 : -1);
195  case EcalEndcap:
196  return (((rawId >> 14) & 0x1) == 1 ? 1 : -1);
197  case EcalTriggerTower:
198  return (((rawId >> 15) & 0x1) == 1 ? 1 : -1);
199  case EcalLaserPnDiode:
200  return (((rawId >> 4) & 0x7f) > kEBpLow ? 1 : -1);
201  default:
202  throw cms::Exception("InvalidDetId")
203  << "EcalDQMCommonUtils::zside(" << std::hex << uint32_t(_id) << ")" << std::endl;
204  }
205 
206  return 0;
207  }
208 
209  double eta(const EBDetId &_ebid, const CaloGeometry *geometry) {
210  return _ebid.approxEta() + (_ebid.zside() < 0 ? 0.5 : -0.5) * EBDetId::crystalUnitToEta;
211  }
212 
213  double eta(const EEDetId &_id, const CaloGeometry *geometry) { return geometry->getPosition(_id).eta(); }
214 
215  double phi(EBDetId const &_ebid) {
216  const double degToRad(0.0174533);
217  return (_ebid.iphi() - 10.5) * degToRad;
218  }
219 
220  double phi(EEDetId const &_eeid) {
221  const double degToRad(0.0174533);
222  double p(std::atan2(_eeid.ix() - 50.5, _eeid.iy() - 50.5));
223  if (p < -10. * degToRad)
224  p += 360. * degToRad;
225  return p;
226  }
227 
228  double phi(EcalTrigTowerDetId const &_ttid) {
229  const double degToRad(0.0174533);
230  double p((_ttid.iphi() - 0.5) * 5. * degToRad);
231  if (p > 350. * degToRad)
232  p -= 360. * degToRad;
233  return p;
234  }
235 
236  double phi(double _phi) {
237  const double degToRad(0.0174533);
238  if (_phi < -10. * degToRad)
239  _phi += 360. * degToRad;
240  return _phi;
241  }
242 
243  bool isForward(DetId const &_id) {
244  // the numbers here roughly corresponds to a cut at |eta| > 2.2
245  // cf hepwww.rl.ac.uk/CMSecal/Dee-layout.html
246  if (_id.subdetId() != EcalEndcap)
247  return false;
248  if (isEcalScDetId(_id)) {
249  EcalScDetId scid(_id);
250  return (scid.ix() - 10) * (scid.ix() - 10) + (scid.iy() - 10) * (scid.iy() - 10) < 25.;
251  } else {
252  EEDetId eeid(_id);
253  return (eeid.ix() - 50) * (eeid.ix() - 50) + (eeid.iy() - 50) * (eeid.iy() - 50) < 625.;
254  }
255  }
256 
257  bool isCrystalId(const DetId &_id) {
258  return (_id.det() == DetId::Ecal) &&
259  ((_id.subdetId() == EcalBarrel) || ((_id.subdetId() == EcalEndcap) && (((_id.rawId() >> 15) & 0x1) == 0)));
260  }
261 
262  bool isSingleChannelId(const DetId &_id) {
263  return (_id.det() == DetId::Ecal) && (isCrystalId(_id) || (_id.subdetId() == EcalLaserPnDiode));
264  }
265 
266  bool isEcalScDetId(const DetId &_id) {
267  return (_id.det() == DetId::Ecal) && ((_id.subdetId() == EcalEndcap) && ((_id.rawId() >> 15) & 0x1));
268  }
269 
270  bool isEndcapTTId(const DetId &_id) {
271  return (_id.det() == DetId::Ecal) && ((_id.subdetId() == EcalTriggerTower) && (((_id.rawId() >> 7) & 0x7f) > 17));
272  }
273 
274  unsigned dccId(std::string const &_smName) {
275  unsigned smNumber(std::atoi(_smName.substr(3).c_str()));
276 
277  if (_smName.find("EE-") == 0)
278  return kEEmLow + 1 + ((smNumber + 2) % 9);
279  else if (_smName.find("EB-") == 0)
280  return kEBmLow + 1 + smNumber;
281  else if (_smName.find("EB+") == 0)
282  return kEBpLow + 1 + smNumber;
283  else if (_smName.find("EE+") == 0)
284  return kEEpLow + 1 + ((smNumber + 2) % 9);
285  else
286  return 0;
287  }
288 
289  std::string smName(unsigned _dccId) {
290  std::stringstream ss;
291 
292  unsigned iSM(_dccId - 1);
293 
294  if (iSM <= kEEmHigh)
295  ss << "EE-" << std::setw(2) << std::setfill('0') << (((iSM - kEEmLow + 6) % 9) + 1);
296  else if (iSM <= kEBmHigh)
297  ss << "EB-" << std::setw(2) << std::setfill('0') << (iSM - kEBmLow + 1);
298  else if (iSM <= kEBpHigh)
299  ss << "EB+" << std::setw(2) << std::setfill('0') << (iSM - kEBpLow + 1);
300  else if (iSM <= kEEpHigh)
301  ss << "EE+" << std::setw(2) << std::setfill('0') << (((iSM - kEEpLow + 6) % 9) + 1);
302 
303  return ss.str();
304  }
305 
306  // numbers from CalibCalorimetry/EcalLaserAnalyzer/src/MEEEGeom.cc
307  unsigned EEPnDCC(unsigned _dee, unsigned _ab) {
308  switch (_dee) {
309  case 1: // EE+F -> FEDs 649-653/0
310  if (_ab == 0)
311  return 50;
312  else
313  return 51;
314  case 2: // EE+N -> FEDs 646-648, 653/1, 654
315  if (_ab == 0)
316  return 47;
317  else
318  return 46;
319  case 3: // EE-N -> FEDs 601-603, 608/1, 609
320  if (_ab == 0)
321  return 1;
322  else
323  return 2;
324  case 4: // EE-F -> FEDs 604-608/0
325  if (_ab == 0)
326  return 5;
327  else
328  return 6;
329  default:
330  return 0;
331  }
332  }
333 
334  unsigned nCrystals(unsigned _dccId) {
335  unsigned iSM(_dccId - 1);
336 
337  if (iSM >= kEBmLow && iSM <= kEBpHigh)
338  return 1700;
339 
340  switch (iSM) {
341  case kEEm05:
342  case kEEp05:
343  return 810;
344  case kEEm07:
345  case kEEm03:
346  case kEEp07:
347  case kEEp03:
348  return 830;
349  case kEEm09:
350  case kEEm01:
351  case kEEp09:
352  case kEEp01:
353  return 815;
354  case kEEm08:
355  case kEEm02:
356  case kEEp08:
357  case kEEp02:
358  return 791;
359  case kEEm04:
360  case kEEm06:
361  case kEEp04:
362  case kEEp06:
363  return 821;
364  default:
365  return 0;
366  }
367  }
368 
369  unsigned nSuperCrystals(unsigned _dccId) {
370  unsigned iSM(_dccId - 1);
371 
372  if (iSM >= kEBmLow && iSM <= kEBpHigh)
373  return 68;
374 
375  switch (iSM) {
376  case kEEm05:
377  case kEEp05:
378  return 41;
379  case kEEm07:
380  case kEEm03:
381  case kEEp07:
382  case kEEp03:
383  return 34;
384  case kEEm09:
385  case kEEm01:
386  case kEEm04:
387  case kEEm06:
388  case kEEp09:
389  case kEEp01:
390  case kEEp04:
391  case kEEp06:
392  return 33;
393  case kEEm08:
394  case kEEm02:
395  case kEEp08:
396  case kEEp02:
397  return 32;
398  default:
399  return 0;
400  }
401  }
402 
403  bool ccuExists(unsigned _dccId, unsigned _towerId) {
404  if (_towerId == 69 || _towerId == 70)
405  return true;
406  else if ((_dccId == 8 || _dccId == 53) && _towerId >= 18 && _towerId <= 24)
407  return false;
408  else if (_dccId <= kEEmHigh + 1 || _dccId >= kEEpLow + 1)
409  return _towerId <= nSuperCrystals(_dccId);
410  else
411  return _towerId <= 68;
412  }
413 } // namespace ecaldqm
std::vector< unsigned > const memDCC
unsigned memDCCIndex(unsigned)
int iTT() const
sequential index within one DCC
int zside() const
Definition: EcalScDetId.h:64
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
double const etaBound
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
int ix() const
Definition: EEDetId.h:77
bool isForward(DetId const &)
std::pair< unsigned, unsigned > outerTCCs(unsigned)
int zside(DetId const &)
bool ccuExists(unsigned, unsigned)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
unsigned nSuperCrystals(unsigned)
unsigned ttId(DetId const &, EcalElectronicsMapping const *)
Definition: Electron.h:6
float approxEta() const
Definition: EBDetId.h:102
unsigned EEPnDCC(unsigned _dee, unsigned _ab)
bool isEndcapTTId(DetId const &)
unsigned nCrystals(unsigned)
unsigned towerId(DetId const &, EcalElectronicsMapping const *)
int towerId() const
get the tower id
unsigned dccId(DetId const &, EcalElectronicsMapping const *)
static const float crystalUnitToEta
Definition: EBDetId.h:153
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
int iy() const
Definition: EcalScDetId.h:76
bool isEcalScDetId(DetId const &)
unsigned memDCCId(unsigned)
bool isSingleChannelId(DetId const &)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
Definition: DetId.h:17
std::string smName(unsigned)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
unsigned tccId(DetId const &, EcalElectronicsMapping const *)
bool isCrystalId(DetId const &)
unsigned rtHalf(DetId const &, EcalElectronicsMapping const *)
std::pair< unsigned, unsigned > innerTCCs(unsigned)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
double eta(EBDetId const &, CaloGeometry const *)
unsigned memarr[]
std::vector< DetId > scConstituents(EcalScDetId const &)
int iDCCId() const
get the DCCId
int iphi() const
get the tower iphi
float degToRad(float deg)
Definition: TPUtils.cc:9
double phi(EBDetId const &)
int iy() const
Definition: EEDetId.h:83
int ix() const
Definition: EcalScDetId.h:70