Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-17 23:26:16

0001 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0002 
0003 #include "DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h"
0004 
0005 #include <mutex>
0006 
0007 namespace ecaldqm {
0008   unsigned memarr[] = {kEEm07, kEEm08, kEEm02, kEEm03, kEBm01, kEBm02, kEBm03, kEBm04, kEBm05, kEBm06, kEBm07,
0009                        kEBm08, kEBm09, kEBm10, kEBm11, kEBm12, kEBm13, kEBm14, kEBm15, kEBm16, kEBm17, kEBm18,
0010                        kEBp01, kEBp02, kEBp03, kEBp04, kEBp05, kEBp06, kEBp07, kEBp08, kEBp09, kEBp10, kEBp11,
0011                        kEBp12, kEBp13, kEBp14, kEBp15, kEBp16, kEBp17, kEBp18, kEEp07, kEEp08, kEEp02, kEEp03};
0012   const std::vector<unsigned> memDCC(memarr, memarr + 44);
0013 
0014   const double etaBound(1.479);
0015 
0016   unsigned dccId(const DetId &_id, const EcalElectronicsMapping *map) {
0017     unsigned subdet(_id.subdetId());
0018 
0019     if (subdet == EcalBarrel)
0020       return map->DCCid(EBDetId(_id));
0021     else if (subdet == EcalTriggerTower)
0022       return map->DCCid(EcalTrigTowerDetId(_id));
0023     else if (subdet == EcalEndcap) {
0024       if (isEcalScDetId(_id))
0025         return map->getDCCandSC(EcalScDetId(_id)).first;
0026       else
0027         return map->getElectronicsId(EEDetId(_id)).dccId();
0028     } else if (subdet == EcalLaserPnDiode)
0029       return EcalPnDiodeDetId(_id).iDCCId();
0030 
0031     throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::dccId(" << _id.rawId() << ")" << std::endl;
0032 
0033     return 0;
0034   }
0035 
0036   unsigned dccId(const EcalElectronicsId &_id) { return _id.dccId(); }
0037 
0038   unsigned memDCCId(unsigned _index) {
0039     // for DCCs with no MEM - map the index in an array of DCCs with no MEM to the
0040     // DCC ID
0041     if (_index >= memDCC.size())
0042       return 0;
0043     return memDCC.at(_index) + 1;
0044   }
0045 
0046   unsigned memDCCIndex(unsigned _dccid) {
0047     std::vector<unsigned>::const_iterator itr(std::find(memDCC.begin(), memDCC.end(), _dccid - 1));
0048     if (itr == memDCC.end())
0049       return -1;
0050 
0051     return (itr - memDCC.begin());
0052   }
0053 
0054   unsigned tccId(const DetId &_id, const EcalElectronicsMapping *map) {
0055     unsigned subdet(_id.subdetId());
0056 
0057     if (subdet == EcalBarrel)
0058       return map->TCCid(EBDetId(_id));
0059     else if (subdet == EcalTriggerTower)
0060       return map->TCCid(EcalTrigTowerDetId(_id));
0061     else if (subdet == EcalEndcap) {
0062       if (isEcalScDetId(_id))
0063         return 0;  // incompatible
0064       else
0065         return map->getTriggerElectronicsId(EEDetId(_id)).tccId();
0066     }
0067 
0068     throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::tccId(" << uint32_t(_id) << ")" << std::endl;
0069 
0070     return 0;
0071   }
0072 
0073   unsigned tccId(const EcalElectronicsId &_id, const EcalElectronicsMapping *map) {
0074     return map->getTriggerElectronicsId(_id).tccId();
0075   }
0076 
0077   unsigned towerId(const DetId &_id, const EcalElectronicsMapping *map) {
0078     unsigned subdet(_id.subdetId());
0079 
0080     if (subdet == EcalBarrel)
0081       return EBDetId(_id).tower().iTT();
0082     else if (subdet == EcalTriggerTower)
0083       return EcalTrigTowerDetId(_id).iTT();
0084     else if (subdet == EcalEndcap) {
0085       if (isEcalScDetId(_id))
0086         return map->getDCCandSC(EcalScDetId(_id)).second;
0087       else
0088         return map->getElectronicsId(EEDetId(_id)).towerId();
0089     }
0090 
0091     throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::towerId(" << std::hex << uint32_t(_id) << ")"
0092                                          << std::endl;
0093 
0094     return 0;
0095   }
0096 
0097   unsigned towerId(const EcalElectronicsId &_id) { return _id.towerId(); }
0098 
0099   unsigned ttId(const DetId &_id, const EcalElectronicsMapping *map) {
0100     unsigned subdet(_id.subdetId());
0101 
0102     if (subdet == EcalBarrel)
0103       return EBDetId(_id).tower().iTT();
0104     else if (subdet == EcalTriggerTower)
0105       return map->iTT(EcalTrigTowerDetId(_id));
0106     else if (subdet == EcalEndcap && !isEcalScDetId(_id))
0107       return map->getTriggerElectronicsId(_id).ttId();
0108 
0109     throw cms::Exception("InvalidDetId") << "EcalDQMCommonUtils::ttId(" << std::hex << uint32_t(_id) << ")"
0110                                          << std::endl;
0111 
0112     return 0;
0113   }
0114 
0115   unsigned ttId(const EcalElectronicsId &_id, const EcalElectronicsMapping *map) {
0116     return map->getTriggerElectronicsId(_id).ttId();
0117   }
0118 
0119   unsigned rtHalf(DetId const &_id, const EcalElectronicsMapping *electronicsMap) {
0120     if (_id.subdetId() == EcalBarrel) {
0121       int ic(EBDetId(_id).ic());
0122       if ((ic - 1) / 20 > 4 && (ic - 1) % 20 < 10)
0123         return 1;
0124     } else {
0125       unsigned iDCC(dccId(_id, electronicsMap) - 1);
0126       if ((iDCC == kEEm05 || iDCC == kEEp05) && EEDetId(_id).ix() > 50)
0127         return 1;
0128     }
0129 
0130     return 0;
0131   }
0132 
0133   std::pair<unsigned, unsigned> innerTCCs(unsigned _dccId) {
0134     int iDCC(_dccId - 1);
0135     std::pair<unsigned, unsigned> res;
0136     if (iDCC <= kEEmHigh) {
0137       res.first = (iDCC - kEEmLow) * 2;
0138       if (res.first == 0)
0139         res.first = 18;
0140       res.second = (iDCC - kEEmLow) * 2 + 1;
0141     } else if (iDCC < -kEBpHigh)
0142       res.first = res.second = _dccId + 27;
0143     else {
0144       res.first = (iDCC - kEEpLow) * 2 + 90;
0145       if (res.first == 90)
0146         res.first = 108;
0147       res.second = (iDCC - kEEpLow) * 2 + 91;
0148     }
0149 
0150     return res;
0151   }
0152 
0153   std::pair<unsigned, unsigned> outerTCCs(unsigned _dccId) {
0154     int iDCC(_dccId - 1);
0155     std::pair<unsigned, unsigned> res;
0156     if (iDCC <= kEEmHigh) {
0157       res.first = (iDCC - kEEmLow) * 2 + 18;
0158       if (res.first == 18)
0159         res.first = 36;
0160       res.second = (iDCC - kEEmLow) * 2 + 19;
0161     } else if (iDCC <= kEBpHigh)
0162       res.first = res.second = _dccId + 27;
0163     else {
0164       res.first = (iDCC - kEEpLow) * 2 + 72;
0165       if (res.first == 72)
0166         res.first = 90;
0167       res.second = (iDCC - kEEpLow) * 2 + 73;
0168     }
0169 
0170     return res;
0171   }
0172 
0173   std::vector<DetId> scConstituents(EcalScDetId const &_scid) {
0174     std::vector<DetId> res;
0175 
0176     int ixbase((_scid.ix() - 1) * 5);
0177     int iybase((_scid.iy() - 1) * 5);
0178 
0179     for (int ix(1); ix <= 5; ++ix) {
0180       for (int iy(1); iy <= 5; ++iy) {
0181         if (EEDetId::validDetId(ixbase + ix, iybase + iy, _scid.zside()))
0182           res.push_back(EEDetId(ixbase + ix, iybase + iy, _scid.zside()));
0183       }
0184     }
0185 
0186     return res;
0187   }
0188 
0189   int zside(const DetId &_id) {
0190     uint32_t rawId(_id);
0191 
0192     switch (_id.subdetId()) {
0193       case EcalBarrel:
0194         return (((rawId >> 16) & 0x1) == 1 ? 1 : -1);
0195       case EcalEndcap:
0196         return (((rawId >> 14) & 0x1) == 1 ? 1 : -1);
0197       case EcalTriggerTower:
0198         return (((rawId >> 15) & 0x1) == 1 ? 1 : -1);
0199       case EcalLaserPnDiode:
0200         return (((rawId >> 4) & 0x7f) > kEBpLow ? 1 : -1);
0201       default:
0202         throw cms::Exception("InvalidDetId")
0203             << "EcalDQMCommonUtils::zside(" << std::hex << uint32_t(_id) << ")" << std::endl;
0204     }
0205 
0206     return 0;
0207   }
0208 
0209   double eta(const EBDetId &_ebid, const CaloGeometry *geometry) {
0210     return _ebid.approxEta() + (_ebid.zside() < 0 ? 0.5 : -0.5) * EBDetId::crystalUnitToEta;
0211   }
0212 
0213   double eta(const EEDetId &_id, const CaloGeometry *geometry) { return geometry->getPosition(_id).eta(); }
0214 
0215   double phi(EBDetId const &_ebid) {
0216     const double degToRad(0.0174533);
0217     return (_ebid.iphi() - 10.5) * degToRad;
0218   }
0219 
0220   double phi(EEDetId const &_eeid) {
0221     const double degToRad(0.0174533);
0222     double p(std::atan2(_eeid.ix() - 50.5, _eeid.iy() - 50.5));
0223     if (p < -10. * degToRad)
0224       p += 360. * degToRad;
0225     return p;
0226   }
0227 
0228   double phi(EcalTrigTowerDetId const &_ttid) {
0229     const double degToRad(0.0174533);
0230     double p((_ttid.iphi() - 0.5) * 5. * degToRad);
0231     if (p > 350. * degToRad)
0232       p -= 360. * degToRad;
0233     return p;
0234   }
0235 
0236   double phi(double _phi) {
0237     const double degToRad(0.0174533);
0238     if (_phi < -10. * degToRad)
0239       _phi += 360. * degToRad;
0240     return _phi;
0241   }
0242 
0243   bool isForward(DetId const &_id) {
0244     // the numbers here roughly corresponds to a cut at |eta| > 2.2
0245     // cf hepwww.rl.ac.uk/CMSecal/Dee-layout.html
0246     if (_id.subdetId() != EcalEndcap)
0247       return false;
0248     if (isEcalScDetId(_id)) {
0249       EcalScDetId scid(_id);
0250       return (scid.ix() - 10) * (scid.ix() - 10) + (scid.iy() - 10) * (scid.iy() - 10) < 25.;
0251     } else {
0252       EEDetId eeid(_id);
0253       return (eeid.ix() - 50) * (eeid.ix() - 50) + (eeid.iy() - 50) * (eeid.iy() - 50) < 625.;
0254     }
0255   }
0256 
0257   bool isCrystalId(const DetId &_id) {
0258     return (_id.det() == DetId::Ecal) &&
0259            ((_id.subdetId() == EcalBarrel) || ((_id.subdetId() == EcalEndcap) && (((_id.rawId() >> 15) & 0x1) == 0)));
0260   }
0261 
0262   bool isSingleChannelId(const DetId &_id) {
0263     return (_id.det() == DetId::Ecal) && (isCrystalId(_id) || (_id.subdetId() == EcalLaserPnDiode));
0264   }
0265 
0266   bool isEcalScDetId(const DetId &_id) {
0267     return (_id.det() == DetId::Ecal) && ((_id.subdetId() == EcalEndcap) && ((_id.rawId() >> 15) & 0x1));
0268   }
0269 
0270   bool isEndcapTTId(const DetId &_id) {
0271     return (_id.det() == DetId::Ecal) && ((_id.subdetId() == EcalTriggerTower) && (((_id.rawId() >> 7) & 0x7f) > 17));
0272   }
0273 
0274   unsigned dccId(std::string const &_smName) {
0275     unsigned smNumber(std::atoi(_smName.substr(3).c_str()));
0276 
0277     if (_smName.find("EE-") == 0)
0278       return kEEmLow + 1 + ((smNumber + 2) % 9);
0279     else if (_smName.find("EB-") == 0)
0280       return kEBmLow + 1 + smNumber;
0281     else if (_smName.find("EB+") == 0)
0282       return kEBpLow + 1 + smNumber;
0283     else if (_smName.find("EE+") == 0)
0284       return kEEpLow + 1 + ((smNumber + 2) % 9);
0285     else
0286       return 0;
0287   }
0288 
0289   std::string smName(unsigned _dccId) {
0290     std::stringstream ss;
0291 
0292     unsigned iSM(_dccId - 1);
0293 
0294     if (iSM <= kEEmHigh)
0295       ss << "EE-" << std::setw(2) << std::setfill('0') << (((iSM - kEEmLow + 6) % 9) + 1);
0296     else if (iSM <= kEBmHigh)
0297       ss << "EB-" << std::setw(2) << std::setfill('0') << (iSM - kEBmLow + 1);
0298     else if (iSM <= kEBpHigh)
0299       ss << "EB+" << std::setw(2) << std::setfill('0') << (iSM - kEBpLow + 1);
0300     else if (iSM <= kEEpHigh)
0301       ss << "EE+" << std::setw(2) << std::setfill('0') << (((iSM - kEEpLow + 6) % 9) + 1);
0302 
0303     return ss.str();
0304   }
0305 
0306   // numbers from CalibCalorimetry/EcalLaserAnalyzer/src/MEEEGeom.cc
0307   unsigned EEPnDCC(unsigned _dee, unsigned _ab) {
0308     switch (_dee) {
0309       case 1:  // EE+F -> FEDs 649-653/0
0310         if (_ab == 0)
0311           return 50;
0312         else
0313           return 51;
0314       case 2:  // EE+N -> FEDs 646-648, 653/1, 654
0315         if (_ab == 0)
0316           return 47;
0317         else
0318           return 46;
0319       case 3:  // EE-N -> FEDs 601-603, 608/1, 609
0320         if (_ab == 0)
0321           return 1;
0322         else
0323           return 2;
0324       case 4:  // EE-F -> FEDs 604-608/0
0325         if (_ab == 0)
0326           return 5;
0327         else
0328           return 6;
0329       default:
0330         return 0;
0331     }
0332   }
0333 
0334   unsigned nCrystals(unsigned _dccId) {
0335     unsigned iSM(_dccId - 1);
0336 
0337     if (iSM >= kEBmLow && iSM <= kEBpHigh)
0338       return 1700;
0339 
0340     switch (iSM) {
0341       case kEEm05:
0342       case kEEp05:
0343         return 810;
0344       case kEEm07:
0345       case kEEm03:
0346       case kEEp07:
0347       case kEEp03:
0348         return 830;
0349       case kEEm09:
0350       case kEEm01:
0351       case kEEp09:
0352       case kEEp01:
0353         return 815;
0354       case kEEm08:
0355       case kEEm02:
0356       case kEEp08:
0357       case kEEp02:
0358         return 791;
0359       case kEEm04:
0360       case kEEm06:
0361       case kEEp04:
0362       case kEEp06:
0363         return 821;
0364       default:
0365         return 0;
0366     }
0367   }
0368 
0369   unsigned nSuperCrystals(unsigned _dccId) {
0370     unsigned iSM(_dccId - 1);
0371 
0372     if (iSM >= kEBmLow && iSM <= kEBpHigh)
0373       return 68;
0374 
0375     switch (iSM) {
0376       case kEEm05:
0377       case kEEp05:
0378         return 41;
0379       case kEEm07:
0380       case kEEm03:
0381       case kEEp07:
0382       case kEEp03:
0383         return 34;
0384       case kEEm09:
0385       case kEEm01:
0386       case kEEm04:
0387       case kEEm06:
0388       case kEEp09:
0389       case kEEp01:
0390       case kEEp04:
0391       case kEEp06:
0392         return 33;
0393       case kEEm08:
0394       case kEEm02:
0395       case kEEp08:
0396       case kEEp02:
0397         return 32;
0398       default:
0399         return 0;
0400     }
0401   }
0402 
0403   bool ccuExists(unsigned _dccId, unsigned _towerId) {
0404     if (_towerId == 69 || _towerId == 70)
0405       return true;
0406     else if ((_dccId == 8 || _dccId == 53) && _towerId >= 18 && _towerId <= 24)
0407       return false;
0408     else if (_dccId <= kEEmHigh + 1 || _dccId >= kEEpLow + 1)
0409       return _towerId <= nSuperCrystals(_dccId);
0410     else
0411       return _towerId <= 68;
0412   }
0413 }  // namespace ecaldqm