CMS 3D CMS Logo

EcalDQMCommonUtils.cc
Go to the documentation of this file.
2 
4 
5 #include <mutex>
6 
7 namespace ecaldqm
8 {
9  unsigned memarr[] = {kEEm07, kEEm08, kEEm02, kEEm03,
15  const std::vector<unsigned> memDCC(memarr, memarr + 44);
16 
17  const double etaBound(1.479);
18 
19  unsigned
20  dccId(const DetId &_id)
21  {
23 
24  unsigned subdet(_id.subdetId());
25 
26  if(subdet == EcalBarrel) return map->DCCid(EBDetId(_id));
27  else if(subdet == EcalTriggerTower) return map->DCCid(EcalTrigTowerDetId(_id));
28  else if(subdet == EcalEndcap){
29  if(isEcalScDetId(_id)) return map->getDCCandSC(EcalScDetId(_id)).first;
30  else return map->getElectronicsId(EEDetId(_id)).dccId();
31  }
32  else if(subdet == EcalLaserPnDiode) return EcalPnDiodeDetId(_id).iDCCId();
33 
34  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::dccId(" << _id.rawId() << ")" << std::endl;
35 
36  return 0;
37  }
38 
39  unsigned
41  {
42  return _id.dccId();
43  }
44 
45  unsigned
46  memDCCId(unsigned _index)
47  {
48  // for DCCs with no MEM - map the index in an array of DCCs with no MEM to the DCC ID
49  if(_index >= memDCC.size()) return 0;
50  return memDCC.at(_index) + 1;
51  }
52 
53  unsigned
54  memDCCIndex(unsigned _dccid)
55  {
56  std::vector<unsigned>::const_iterator itr(std::find(memDCC.begin(), memDCC.end(), _dccid - 1));
57  if(itr == memDCC.end()) return -1;
58 
59  return (itr - memDCC.begin());
60  }
61 
62  unsigned
63  tccId(const DetId &_id)
64  {
66 
67  unsigned subdet(_id.subdetId());
68 
69  if(subdet == EcalBarrel) return map->TCCid(EBDetId(_id));
70  else if(subdet == EcalTriggerTower) return map->TCCid(EcalTrigTowerDetId(_id));
71  else if(subdet == EcalEndcap){
72  if(isEcalScDetId(_id)) return 0; // incompatible
73  else return map->getTriggerElectronicsId(EEDetId(_id)).tccId();
74  }
75 
76  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::tccId(" << uint32_t(_id) << ")" << std::endl;
77 
78  return 0;
79  }
80 
81  unsigned
83  {
85  }
86 
87 
88  unsigned
89  towerId(const DetId &_id)
90  {
91  unsigned subdet(_id.subdetId());
92 
93  if(subdet == EcalBarrel) return EBDetId(_id).tower().iTT();
94  else if(subdet == EcalTriggerTower) return EcalTrigTowerDetId(_id).iTT();
95  else if(subdet == EcalEndcap){
96  if(isEcalScDetId(_id)) return getElectronicsMap()->getDCCandSC(EcalScDetId(_id)).second;
97  else return getElectronicsMap()->getElectronicsId(EEDetId(_id)).towerId();
98  }
99 
100  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::towerId(" << std::hex << uint32_t(_id) << ")" << std::endl;
101 
102  return 0;
103  }
104 
105  unsigned
107  {
108  return _id.towerId();
109  }
110 
111  unsigned
112  ttId(const DetId& _id)
113  {
114  unsigned subdet(_id.subdetId());
115 
116  if(subdet == EcalBarrel)
117  return EBDetId(_id).tower().iTT();
118  else if(subdet == EcalTriggerTower)
119  return getElectronicsMap()->iTT(EcalTrigTowerDetId(_id));
120  else if(subdet == EcalEndcap && !isEcalScDetId(_id))
122 
123  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::ttId(" << std::hex << uint32_t(_id) << ")" << std::endl;
124 
125  return 0;
126  }
127 
128  unsigned
130  {
132  }
133 
134  unsigned
135  rtHalf(DetId const& _id)
136  {
137  if(_id.subdetId() == EcalBarrel){
138  int ic(EBDetId(_id).ic());
139  if((ic - 1) / 20 > 4 && (ic - 1) % 20 < 10) return 1;
140  }
141  else{
142  unsigned iDCC(dccId(_id) - 1);
143  if((iDCC == kEEm05 || iDCC == kEEp05) && EEDetId(_id).ix() > 50) return 1;
144  }
145 
146  return 0;
147  }
148 
149  std::pair<unsigned, unsigned>
150  innerTCCs(unsigned _dccId)
151  {
152  int iDCC(_dccId - 1);
153  std::pair<unsigned, unsigned> res;
154  if(iDCC <= kEEmHigh){
155  res.first = (iDCC - kEEmLow) * 2;
156  if(res.first == 0) res.first = 18;
157  res.second = (iDCC - kEEmLow) * 2 + 1;
158  }
159  else if(iDCC <- kEBpHigh)
160  res.first = res.second = _dccId + 27;
161  else{
162  res.first = (iDCC - kEEpLow) * 2 + 90;
163  if(res.first == 90) res.first = 108;
164  res.second = (iDCC - kEEpLow) * 2 + 91;
165  }
166 
167  return res;
168  }
169 
170  std::pair<unsigned, unsigned>
171  outerTCCs(unsigned _dccId)
172  {
173  int iDCC(_dccId - 1);
174  std::pair<unsigned, unsigned> res;
175  if(iDCC <= kEEmHigh){
176  res.first = (iDCC - kEEmLow) * 2 + 18;
177  if(res.first == 18) res.first = 36;
178  res.second = (iDCC - kEEmLow) * 2 + 19;
179  }
180  else if(iDCC <= kEBpHigh)
181  res.first = res.second = _dccId + 27;
182  else{
183  res.first = (iDCC - kEEpLow) * 2 + 72;
184  if(res.first == 72) res.first = 90;
185  res.second = (iDCC - kEEpLow) * 2 + 73;
186  }
187 
188  return res;
189  }
190 
191  std::vector<DetId>
193  {
194  std::vector<DetId> res;
195 
196  int ixbase((_scid.ix() - 1) * 5);
197  int iybase((_scid.iy() - 1) * 5);
198 
199  for(int ix(1); ix <= 5; ++ix){
200  for(int iy(1); iy <= 5; ++iy){
201  if(EEDetId::validDetId(ixbase + ix, iybase + iy, _scid.zside()))
202  res.push_back(EEDetId(ixbase + ix, iybase + iy, _scid.zside()));
203  }
204  }
205 
206  return res;
207  }
208 
209  int
210  zside(const DetId& _id)
211  {
212  uint32_t rawId(_id);
213 
214  switch(_id.subdetId()){
215  case EcalBarrel:
216  return (((rawId >> 16) & 0x1) == 1 ? 1 : -1);
217  case EcalEndcap:
218  return (((rawId >> 14) & 0x1) == 1 ? 1 : -1);
219  case EcalTriggerTower:
220  return (((rawId >> 15) & 0x1) == 1 ? 1 : -1);
221  case EcalLaserPnDiode:
222  return (((rawId >> 4) & 0x7f) > kEBpLow ? 1 : -1);
223  default:
224  throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::zside(" << std::hex << uint32_t(_id) << ")" << std::endl;
225  }
226 
227  return 0;
228  }
229 
230  double
231  eta(const EBDetId& _ebid)
232  {
233  return _ebid.approxEta() + (_ebid.zside() < 0 ? 0.5 : -0.5) * EBDetId::crystalUnitToEta;
234  }
235 
236  double
237  eta(const EEDetId& _id)
238  {
239  return getGeometry()->getPosition(_id).eta();
240  }
241 
242  double
243  phi(EBDetId const& _ebid)
244  {
245  const double degToRad(0.0174533);
246  return (_ebid.iphi() - 10.5) * degToRad;
247  }
248 
249  double
250  phi(EEDetId const& _eeid)
251  {
252  const double degToRad(0.0174533);
253  double p(std::atan2(_eeid.ix() - 50.5, _eeid.iy() - 50.5));
254  if(p < -10. * degToRad) p += 360. * degToRad;
255  return p;
256  }
257 
258  double
259  phi(EcalTrigTowerDetId const& _ttid)
260  {
261  const double degToRad(0.0174533);
262  double p((_ttid.iphi() - 0.5) * 5. * degToRad);
263  if(p > 350. * degToRad) p -= 360. * degToRad;
264  return p;
265  }
266 
267  double
268  phi(double _phi)
269  {
270  const double degToRad(0.0174533);
271  if(_phi < -10. * degToRad) _phi += 360. * degToRad;
272  return _phi;
273  }
274 
275  bool
277  {
278  // the numbers here roughly corresponds to a cut at |eta| > 2.2
279  // cf hepwww.rl.ac.uk/CMSecal/Dee-layout.html
280  if(_id.subdetId() != EcalEndcap) return false;
281  if(isEcalScDetId(_id)){
282  EcalScDetId scid(_id);
283  return (scid.ix() - 10) * (scid.ix() - 10) + (scid.iy() - 10) * (scid.iy() - 10) < 25.;
284  }
285  else{
286  EEDetId eeid(_id);
287  return (eeid.ix() - 50) * (eeid.ix() - 50) + (eeid.iy() - 50) * (eeid.iy() - 50) < 625.;
288  }
289  }
290 
291  bool
293  {
294  return (_id.det() == DetId::Ecal) && ((_id.subdetId() == EcalBarrel) || ((_id.subdetId() == EcalEndcap) && (((_id.rawId() >> 15) & 0x1) == 0)));
295  }
296 
297  bool
299  {
300  return (_id.det() == DetId::Ecal) && (isCrystalId(_id) || (_id.subdetId() == EcalLaserPnDiode));
301  }
302 
303  bool
305  {
306  return (_id.det() == DetId::Ecal) && ((_id.subdetId() == EcalEndcap) && ((_id.rawId() >> 15) & 0x1));
307  }
308 
309  bool
311  {
312  return (_id.det() == DetId::Ecal) && ((_id.subdetId() == EcalTriggerTower) && (((_id.rawId() >> 7) & 0x7f) > 17));
313  }
314 
315  unsigned
316  dccId(std::string const& _smName)
317  {
318  unsigned smNumber(std::atoi(_smName.substr(3).c_str()));
319 
320  if(_smName.find("EE-") == 0)
321  return kEEmLow + 1 + ((smNumber + 2) % 9);
322  else if(_smName.find("EB-") == 0)
323  return kEBmLow + 1 + smNumber;
324  else if(_smName.find("EB+") == 0)
325  return kEBpLow + 1 + smNumber;
326  else if(_smName.find("EE+") == 0)
327  return kEEpLow + 1 + ((smNumber + 2) % 9);
328  else
329  return 0;
330  }
331 
333  smName(unsigned _dccId)
334  {
335  std::stringstream ss;
336 
337  unsigned iSM(_dccId - 1);
338 
339  if(iSM <= kEEmHigh)
340  ss << "EE-" << std::setw(2) << std::setfill('0') << (((iSM - kEEmLow + 6) % 9) + 1);
341  else if(iSM <= kEBmHigh)
342  ss << "EB-" << std::setw(2) << std::setfill('0') << (iSM - kEBmLow + 1);
343  else if(iSM <= kEBpHigh)
344  ss << "EB+" << std::setw(2) << std::setfill('0') << (iSM - kEBpLow + 1);
345  else if(iSM <= kEEpHigh)
346  ss << "EE+" << std::setw(2) << std::setfill('0') << (((iSM - kEEpLow + 6) % 9) + 1);
347 
348  return ss.str();
349  }
350 
351  // numbers from CalibCalorimetry/EcalLaserAnalyzer/src/MEEEGeom.cc
352  unsigned
353  EEPnDCC(unsigned _dee, unsigned _ab)
354  {
355  switch(_dee){
356  case 1: // EE+F -> FEDs 649-653/0
357  if(_ab == 0) return 50;
358  else return 51;
359  case 2: // EE+N -> FEDs 646-648, 653/1, 654
360  if(_ab == 0) return 47;
361  else return 46;
362  case 3: // EE-N -> FEDs 601-603, 608/1, 609
363  if(_ab == 0) return 1;
364  else return 2;
365  case 4: // EE-F -> FEDs 604-608/0
366  if(_ab == 0) return 5;
367  else return 6;
368  default:
369  return 0;
370  }
371  }
372 
373  unsigned
374  nCrystals(unsigned _dccId)
375  {
376  unsigned iSM(_dccId - 1);
377 
378  if(iSM >= kEBmLow && iSM <= kEBpHigh) return 1700;
379 
380  switch(iSM){
381  case kEEm05:
382  case kEEp05:
383  return 810;
384  case kEEm07:
385  case kEEm03:
386  case kEEp07:
387  case kEEp03:
388  return 830;
389  case kEEm09:
390  case kEEm01:
391  case kEEp09:
392  case kEEp01:
393  return 815;
394  case kEEm08:
395  case kEEm02:
396  case kEEp08:
397  case kEEp02:
398  return 791;
399  case kEEm04:
400  case kEEm06:
401  case kEEp04:
402  case kEEp06:
403  return 821;
404  default:
405  return 0;
406  }
407  }
408 
409  unsigned
410  nSuperCrystals(unsigned _dccId)
411  {
412  unsigned iSM(_dccId - 1);
413 
414  if(iSM >= kEBmLow && iSM <= kEBpHigh) return 68;
415 
416  switch(iSM){
417  case kEEm05:
418  case kEEp05:
419  return 41;
420  case kEEm07:
421  case kEEm03:
422  case kEEp07:
423  case kEEp03:
424  return 34;
425  case kEEm09:
426  case kEEm01:
427  case kEEm04:
428  case kEEm06:
429  case kEEp09:
430  case kEEp01:
431  case kEEp04:
432  case kEEp06:
433  return 33;
434  case kEEm08:
435  case kEEm02:
436  case kEEp08:
437  case kEEp02:
438  return 32;
439  default:
440  return 0;
441  }
442  }
443 
444  bool
445  ccuExists(unsigned _dccId, unsigned _towerId)
446  {
447  if(_towerId == 69 || _towerId == 70) return true;
448  else if((_dccId == 8 || _dccId == 53) && _towerId >= 18 && _towerId <= 24) return false;
449  else if(_dccId <= kEEmHigh + 1 || _dccId >= kEEpLow + 1) return _towerId <= nSuperCrystals(_dccId);
450  else return _towerId <= 68;
451  }
452 
453 
454  /*
455  Note on concurrency compatibility:
456  Call to getters bellow must always happen after
457  EcalDQMonitor::ecaldqmGetSetupObjects or equivalent.
458  As long as check-set-get are executed in this order
459  within each thread, the following functions are
460  thread-safe.
461  */
462 
464  EcalElectronicsMapping const* electronicsMap(nullptr);
466  CaloGeometry const* geometry(nullptr);
467  CaloTopology const* topology(nullptr);
468 
469  bool
470  checkElectronicsMap(bool _throw/* = true*/)
471  {
472  std::lock_guard<std::mutex> lock(mapMutex);
473  if(electronicsMap) return true;
474  if(_throw) throw cms::Exception("InvalidCall") << "ElectronicsMapping not initialized";
475  return false;
476  }
477 
480  {
482  return electronicsMap;
483  }
484 
485  void
487  {
488  std::lock_guard<std::mutex> lock(mapMutex);
489  electronicsMap = _map;
490  }
491 
492  bool
493  checkTrigTowerMap(bool _throw/* = true*/)
494  {
495  std::lock_guard<std::mutex> lock(mapMutex);
496  if(trigtowerMap) return true;
497  if(_throw) throw cms::Exception("InvalidCall") << "TrigTowerConstituentsMap not initialized";
498  return false;
499  }
500 
503  {
505  return trigtowerMap;
506  }
507 
508  void
510  {
511  std::lock_guard<std::mutex> lock(mapMutex);
512  trigtowerMap = _map;
513  }
514 
515  bool
516  checkGeometry(bool _throw/* = true*/)
517  {
518  std::lock_guard<std::mutex> lock(mapMutex);
519  if(geometry) return true;
520  if(_throw) throw cms::Exception("InvalidCall") << "CaloGeometry not initialized";
521  return false;
522  }
523 
524  CaloGeometry const*
526  {
527  if(!geometry) checkGeometry();
528  return geometry;
529  }
530 
531  void
532  setGeometry(CaloGeometry const* _geom)
533  {
534  std::lock_guard<std::mutex> lock(mapMutex);
535  geometry = _geom;
536  }
537 
538  bool
539  checkTopology(bool _throw/* = true*/)
540  {
541  std::lock_guard<std::mutex> lock(mapMutex);
542  if(topology) return true;
543  if(_throw) throw cms::Exception("InvalidCall") << "CaloTopology not initialized";
544  return false;
545  }
546 
547  CaloTopology const*
549  {
550  if(!topology) checkTopology();
551  return topology;
552  }
553 
554  void
555  setTopology(CaloTopology const* _geom)
556  {
557  std::lock_guard<std::mutex> lock(mapMutex);
558  topology = _geom;
559  }
560 }
float approxEta() const
Definition: EBDetId.h:106
std::vector< unsigned > const memDCC
static boost::mutex mutex
Definition: Proxy.cc:11
unsigned memDCCIndex(unsigned)
int ix() const
Definition: EEDetId.h:76
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()
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:53
unsigned EEPnDCC(unsigned _dee, unsigned _ab)
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
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:71
bool checkElectronicsMap(bool=true)
EcalTrigTowerConstituentsMap const * getTrigTowerMap()
int ttId() const
get the tower id
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:69
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:160
int iy() const
Definition: EEDetId.h:82
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:59
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
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:77
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:65
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)
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
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:47