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) {
18 
19  unsigned subdet(_id.subdetId());
20 
21  if (subdet == EcalBarrel)
22  return map->DCCid(EBDetId(_id));
23  else if (subdet == EcalTriggerTower)
24  return map->DCCid(EcalTrigTowerDetId(_id));
25  else if (subdet == EcalEndcap) {
26  if (isEcalScDetId(_id))
27  return map->getDCCandSC(EcalScDetId(_id)).first;
28  else
29  return map->getElectronicsId(EEDetId(_id)).dccId();
30  } else if (subdet == EcalLaserPnDiode)
31  return EcalPnDiodeDetId(_id).iDCCId();
32 
33  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::dccId(" << _id.rawId() << ")" << std::endl;
34 
35  return 0;
36  }
37 
38  unsigned dccId(const EcalElectronicsId &_id) { return _id.dccId(); }
39 
40  unsigned memDCCId(unsigned _index) {
41  // for DCCs with no MEM - map the index in an array of DCCs with no MEM to the
42  // DCC ID
43  if (_index >= memDCC.size())
44  return 0;
45  return memDCC.at(_index) + 1;
46  }
47 
48  unsigned memDCCIndex(unsigned _dccid) {
49  std::vector<unsigned>::const_iterator itr(std::find(memDCC.begin(), memDCC.end(), _dccid - 1));
50  if (itr == memDCC.end())
51  return -1;
52 
53  return (itr - memDCC.begin());
54  }
55 
56  unsigned tccId(const DetId &_id) {
58 
59  unsigned subdet(_id.subdetId());
60 
61  if (subdet == EcalBarrel)
62  return map->TCCid(EBDetId(_id));
63  else if (subdet == EcalTriggerTower)
64  return map->TCCid(EcalTrigTowerDetId(_id));
65  else if (subdet == EcalEndcap) {
66  if (isEcalScDetId(_id))
67  return 0; // incompatible
68  else
69  return map->getTriggerElectronicsId(EEDetId(_id)).tccId();
70  }
71 
72  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::tccId(" << uint32_t(_id) << ")" << std::endl;
73 
74  return 0;
75  }
76 
77  unsigned tccId(const EcalElectronicsId &_id) { return getElectronicsMap()->getTriggerElectronicsId(_id).tccId(); }
78 
79  unsigned towerId(const DetId &_id) {
80  unsigned subdet(_id.subdetId());
81 
82  if (subdet == EcalBarrel)
83  return EBDetId(_id).tower().iTT();
84  else if (subdet == EcalTriggerTower)
85  return EcalTrigTowerDetId(_id).iTT();
86  else if (subdet == EcalEndcap) {
87  if (isEcalScDetId(_id))
88  return getElectronicsMap()->getDCCandSC(EcalScDetId(_id)).second;
89  else
91  }
92 
93  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::towerId(" << std::hex << uint32_t(_id) << ")"
94  << std::endl;
95 
96  return 0;
97  }
98 
99  unsigned towerId(const EcalElectronicsId &_id) { return _id.towerId(); }
100 
101  unsigned ttId(const DetId &_id) {
102  unsigned subdet(_id.subdetId());
103 
104  if (subdet == EcalBarrel)
105  return EBDetId(_id).tower().iTT();
106  else if (subdet == EcalTriggerTower)
107  return getElectronicsMap()->iTT(EcalTrigTowerDetId(_id));
108  else if (subdet == EcalEndcap && !isEcalScDetId(_id))
110 
111  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::ttId(" << std::hex << uint32_t(_id) << ")"
112  << std::endl;
113 
114  return 0;
115  }
116 
117  unsigned ttId(const EcalElectronicsId &_id) { return getElectronicsMap()->getTriggerElectronicsId(_id).ttId(); }
118 
119  unsigned rtHalf(DetId const &_id) {
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) - 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) {
210  return _ebid.approxEta() + (_ebid.zside() < 0 ? 0.5 : -0.5) * EBDetId::crystalUnitToEta;
211  }
212 
213  double eta(const EEDetId &_id) { return getGeometry()->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 
414  /*
415  Note on concurrency compatibility:
416  Call to getters bellow must always happen after
417  EcalDQMonitor::ecaldqmGetSetupObjects or equivalent.
418  As long as check-set-get are executed in this order
419  within each thread, the following functions are
420  thread-safe.
421 */
422 
424  EcalElectronicsMapping const *electronicsMap(nullptr);
426  CaloGeometry const *geometry(nullptr);
427  CaloTopology const *topology(nullptr);
428 
429  bool checkElectronicsMap(bool _throw /* = true*/) {
430  std::lock_guard<std::mutex> lock(mapMutex);
431  if (electronicsMap)
432  return true;
433  if (_throw)
434  throw cms::Exception("InvalidCall") << "ElectronicsMapping not initialized";
435  return false;
436  }
437 
439  if (!electronicsMap)
441  return electronicsMap;
442  }
443 
445  std::lock_guard<std::mutex> lock(mapMutex);
446  electronicsMap = _map;
447  }
448 
449  bool checkTrigTowerMap(bool _throw /* = true*/) {
450  std::lock_guard<std::mutex> lock(mapMutex);
451  if (trigtowerMap)
452  return true;
453  if (_throw)
454  throw cms::Exception("InvalidCall") << "TrigTowerConstituentsMap not initialized";
455  return false;
456  }
457 
459  if (!trigtowerMap)
461  return trigtowerMap;
462  }
463 
465  std::lock_guard<std::mutex> lock(mapMutex);
466  trigtowerMap = _map;
467  }
468 
469  bool checkGeometry(bool _throw /* = true*/) {
470  std::lock_guard<std::mutex> lock(mapMutex);
471  if (geometry)
472  return true;
473  if (_throw)
474  throw cms::Exception("InvalidCall") << "CaloGeometry not initialized";
475  return false;
476  }
477 
479  if (!geometry)
480  checkGeometry();
481  return geometry;
482  }
483 
484  void setGeometry(CaloGeometry const *_geom) {
485  std::lock_guard<std::mutex> lock(mapMutex);
486  geometry = _geom;
487  }
488 
489  bool checkTopology(bool _throw /* = true*/) {
490  std::lock_guard<std::mutex> lock(mapMutex);
491  if (topology)
492  return true;
493  if (_throw)
494  throw cms::Exception("InvalidCall") << "CaloTopology not initialized";
495  return false;
496  }
497 
499  if (!topology)
500  checkTopology();
501  return topology;
502  }
503 
504  void setTopology(CaloTopology const *_geom) {
505  std::lock_guard<std::mutex> lock(mapMutex);
506  topology = _geom;
507  }
508 } // namespace ecaldqm
float approxEta() const
Definition: EBDetId.h:102
std::vector< unsigned > const memDCC
static boost::mutex mutex
Definition: Proxy.cc:11
unsigned memDCCIndex(unsigned)
int ix() const
Definition: EEDetId.h:77
int tccId() const
get the DCC (Ecal Local DCC value not global one) id
CaloTopology const * topology(0)
std::mutex mapMutex
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
double const etaBound
EcalElectronicsMapping const * getElectronicsMap()
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
unsigned tccId(DetId const &)
bool isForward(DetId const &)
std::pair< unsigned, unsigned > outerTCCs(unsigned)
int towerId() const
get the tower id
int iTT(const EcalTrigTowerDetId &id) const
returns the index of a Trigger Tower within its TCC.
int zside(DetId const &)
bool ccuExists(unsigned, unsigned)
std::pair< int, int > getDCCandSC(EcalScDetId id) const
CaloGeometry const * geometry(0)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
CaloGeometry const * getGeometry()
unsigned ttId(DetId const &)
unsigned nSuperCrystals(unsigned)
Definition: Electron.h:6
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
unsigned EEPnDCC(unsigned _dee, unsigned _ab)
bool isEndcapTTId(DetId const &)
int TCCid(const EBDetId &id) const
returns the TCCid of an EBDetId
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
unsigned nCrystals(unsigned)
CaloTopology const * getTopology()
int ix() const
Definition: EcalScDetId.h:70
bool checkElectronicsMap(bool=true)
EcalTrigTowerConstituentsMap const * getTrigTowerMap()
int ttId() const
get the tower id
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:74
void setGeometry(CaloGeometry const *)
EcalTriggerElectronicsId getTriggerElectronicsId(const DetId &id) const
Get the trigger electronics id for this det id.
unsigned rtHalf(DetId const &)
static const float crystalUnitToEta
Definition: EBDetId.h:153
int iy() const
Definition: EEDetId.h:83
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:57
int iDCCId() const
get the DCCId
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
unsigned towerId(DetId const &)
int iy() const
Definition: EcalScDetId.h:76
bool isEcalScDetId(DetId const &)
unsigned memDCCId(unsigned)
bool isSingleChannelId(DetId const &)
Definition: DetId.h:18
int iphi() const
get the tower iphi
void setTopology(CaloTopology const *)
std::string smName(unsigned)
bool checkTopology(bool=true)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
int DCCid(const EBDetId &id) const
returns the DCC of an EBDetId
int zside() const
Definition: EcalScDetId.h:64
bool checkTrigTowerMap(bool=true)
bool isCrystalId(DetId const &)
T eta() const
Definition: PV3DBase.h:76
void setElectronicsMap(EcalElectronicsMapping const *)
EcalElectronicsMapping const * electronicsMap(0)
std::pair< unsigned, unsigned > innerTCCs(unsigned)
unsigned memarr[]
EcalTrigTowerConstituentsMap const * trigtowerMap(0)
std::vector< DetId > scConstituents(EcalScDetId const &)
void setTrigTowerMap(EcalTrigTowerConstituentsMap const *)
int iTT() const
sequential index within one DCC
bool checkGeometry(bool=true)
unsigned dccId(DetId const &)
double eta(EBDetId const &)
double phi(EBDetId const &)
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39