Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:13

0001 #include "DQM/EcalCommon/interface/MESetBinningUtils.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 
0009 #include "TPRegexp.h"
0010 #include "TObjArray.h"
0011 
0012 namespace ecaldqm {
0013   namespace binning {
0014     AxisSpecs getBinning(EcalElectronicsMapping const *electronicsMap,
0015                          ObjectType _otype,
0016                          BinningType _btype,
0017                          bool _isMap,
0018                          int _axis,
0019                          unsigned _iME) {
0020       if (_otype >= nObjType || _btype >= unsigned(nPresetBinnings))
0021         return AxisSpecs();  // you are on your own
0022 
0023       switch (_otype) {
0024         case kEB:
0025           return getBinningEB_(_btype, _isMap, _axis);
0026         case kEE:
0027           return getBinningEE_(_btype, _isMap, 0, _axis);
0028         case kEEm:
0029           return getBinningEE_(_btype, _isMap, -1, _axis);
0030         case kEEp:
0031           return getBinningEE_(_btype, _isMap, 1, _axis);
0032         case kSM:
0033           return getBinningSM_(_btype, _isMap, _iME, _axis, electronicsMap);
0034         case kEBSM:
0035           return getBinningSM_(_btype, _isMap, _iME + 9, _axis, electronicsMap);
0036         case kEESM:
0037           if (_iME <= kEEmHigh)
0038             return getBinningSM_(_btype, _isMap, _iME, _axis, electronicsMap);
0039           else
0040             return getBinningSM_(_btype, _isMap, _iME + nEBDCC, _axis, electronicsMap);
0041         case kSMMEM:
0042           return getBinningSMMEM_(_btype, _isMap, _iME, _axis);
0043         case kEBSMMEM:
0044           return getBinningSMMEM_(_btype, _isMap, _iME + nEEDCCMEM / 2, _axis);
0045         case kEESMMEM:
0046           if (_iME <= kEEmHigh)
0047             return getBinningSMMEM_(_btype, _isMap, _iME, _axis);
0048           else
0049             return getBinningSMMEM_(_btype, _isMap, _iME + nEBDCC, _axis);
0050         case kEcal:
0051           return getBinningEcal_(_btype, _isMap, _axis);
0052         case kMEM:
0053           return getBinningMEM_(_btype, _isMap, -1, _axis);
0054         case kEBMEM:
0055           return getBinningMEM_(_btype, _isMap, EcalBarrel, _axis);
0056         case kEEMEM:
0057           return getBinningMEM_(_btype, _isMap, EcalEndcap, _axis);
0058         default:
0059           return AxisSpecs();
0060       }
0061     }
0062 
0063     int findBin1D(EcalElectronicsMapping const *electronicsMap,
0064                   ObjectType _otype,
0065                   BinningType _btype,
0066                   const DetId &_id) {
0067       switch (_otype) {
0068         case kSM:
0069         case kEBSM:
0070         case kEESM:
0071           if (_btype == kSuperCrystal)
0072             return towerId(_id, electronicsMap);
0073           else if (_btype == kTriggerTower) {
0074             unsigned tccid(tccId(_id, electronicsMap));
0075             if (tccid <= 36 || tccid >= 73) {  // EE
0076               unsigned bin(ttId(_id, electronicsMap));
0077               bool outer((tccid >= 19 && tccid <= 36) || (tccid >= 73 && tccid <= 90));
0078               // For the following, the constants nTTInner and nTTOuter are defined in
0079               // EcalDQMCommonUtils.h.
0080               if (outer)
0081                 bin += 2 * nTTInner;  // For outer TCCs, sets bin number to increment
0082               // by twice the number of TTs in inner TCCs, because numbering of bins
0083               // is in the order (inner1, inner2, outer1, outer2).
0084               // ("inner"" := closer to the beam)
0085               bin += (tccid % 2) * (outer ? nTTOuter : nTTInner);  // Yields x-axis bin number
0086               // in the format above; TTs in even-numbered TCCs are filled in inner1
0087               // or outer1, and those in odd-numbered TCC are filled in inner2 and
0088               // outer2.
0089               return bin;
0090             } else
0091               return ttId(_id, electronicsMap);
0092           } else
0093             break;
0094         case kEcal:
0095           if (_btype == kDCC)
0096             return dccId(_id, electronicsMap);
0097           else if (_btype == kTCC)
0098             return tccId(_id, electronicsMap);
0099           else
0100             break;
0101         case kEB:
0102           if (_btype == kDCC)
0103             return dccId(_id, electronicsMap) - 9;
0104           else if (_btype == kTCC)
0105             return tccId(_id, electronicsMap) - 36;
0106           else
0107             break;
0108         case kEEm:
0109           if (_btype == kDCC)
0110             return dccId(_id, electronicsMap);
0111           else if (_btype == kTCC)
0112             return tccId(_id, electronicsMap);
0113           else
0114             break;
0115         case kEEp:
0116           if (_btype == kDCC)
0117             return dccId(_id, electronicsMap) - 45;
0118           else if (_btype == kTCC)
0119             return tccId(_id, electronicsMap) - 72;
0120           else
0121             break;
0122         case kEE:
0123           if (_btype == kDCC) {
0124             int bin(dccId(_id, electronicsMap));
0125             if (bin >= 46)
0126               bin -= 36;
0127             return bin;
0128           } else if (_btype == kTCC) {
0129             int bin(tccId(_id, electronicsMap));
0130             if (bin >= 72)
0131               bin -= 36;
0132             return bin;
0133           } else
0134             break;
0135         case kSMMEM:
0136         case kEBSMMEM:
0137         case kEESMMEM:
0138           if (_btype == kCrystal)
0139             return EcalPnDiodeDetId(_id).iPnId();
0140           else
0141             break;
0142         default:
0143           break;
0144       }
0145 
0146       return 0;
0147     }
0148 
0149     int findBin1D(EcalElectronicsMapping const *electronicsMap,
0150                   ObjectType _otype,
0151                   BinningType _btype,
0152                   const EcalElectronicsId &_id) {
0153       switch (_otype) {
0154         case kSM:
0155         case kEBSM:
0156         case kEESM:
0157           if (_btype == kSuperCrystal)
0158             return towerId(_id);
0159           else if (_btype == kTriggerTower) {
0160             unsigned tccid(tccId(_id, electronicsMap));
0161             if (tccid <= 36 || tccid >= 73) {  // EE
0162               unsigned bin(ttId(_id, electronicsMap));
0163               bool outer((tccid >= 19 && tccid <= 36) || (tccid >= 73 && tccid <= 90));
0164               // For the following, the constants nTTInner and nTTOuter are defined in
0165               // EcalDQMCommonUtils.h.
0166               if (outer)
0167                 bin += 2 * nTTInner;  // For outer TCCs, sets bin number to increment
0168               // by twice the number of TTs in inner TCCs, because numbering of bins
0169               // is in the order (inner1, inner2, outer1, outer2).
0170               // ("inner"" := closer to the beam)
0171               bin += (tccid % 2) * (outer ? nTTOuter : nTTInner);  // Yields x-axis bin number
0172               // in the format above; TTs in even-numbered TCCs are filled in inner1
0173               // or outer1, and those in odd-numbered TCC are filled in inner2 and
0174               // outer2.
0175               return bin;
0176             } else
0177               return ttId(_id, electronicsMap);
0178           } else
0179             break;
0180         case kEcal:
0181           if (_btype == kDCC)
0182             return dccId(_id);
0183           else if (_btype == kTCC)
0184             return tccId(_id, electronicsMap);
0185           else
0186             break;
0187         case kEB:
0188           if (_btype == kDCC)
0189             return dccId(_id) - 9;
0190           else if (_btype == kTCC)
0191             return tccId(_id, electronicsMap) - 36;
0192           else
0193             break;
0194         case kEEm:
0195           if (_btype == kDCC)
0196             return dccId(_id);
0197           else if (_btype == kTCC)
0198             return tccId(_id, electronicsMap);
0199           else
0200             break;
0201         case kEEp:
0202           if (_btype == kDCC)
0203             return dccId(_id) - 45;
0204           else if (_btype == kTCC)
0205             return tccId(_id, electronicsMap) - 72;
0206           else
0207             break;
0208         case kEE:
0209           if (_btype == kDCC) {
0210             int bin(dccId(_id));
0211             if (bin >= 46)
0212               bin -= 36;
0213             return bin;
0214           } else if (_btype == kTCC) {
0215             int bin(tccId(_id, electronicsMap));
0216             if (bin >= 72)
0217               bin -= 36;
0218             return bin;
0219           } else
0220             break;
0221         default:
0222           break;
0223       }
0224 
0225       return 0;
0226     }
0227 
0228     int findBin1D(EcalElectronicsMapping const *electronicsMap, ObjectType _otype, BinningType _btype, int _dcctccid) {
0229       if (_otype == kEcal && _btype == kDCC)
0230         return _dcctccid;
0231       else if (_otype == kEcal && _btype == kTCC)
0232         return _dcctccid;
0233       if (_otype == kEB && _btype == kDCC)
0234         return _dcctccid - 9;
0235       else if (_otype == kEB && _btype == kTCC)
0236         return _dcctccid - 36;
0237       else if (_otype == kEEm && _btype == kDCC)
0238         return _dcctccid;
0239       else if (_otype == kEEm && _btype == kTCC)
0240         return _dcctccid;
0241       else if (_otype == kEEp && _btype == kDCC)
0242         return _dcctccid - 45;
0243       else if (_otype == kEEp && _btype == kTCC)
0244         return _dcctccid - 72;
0245       else if (_otype == kEE && _btype == kDCC)
0246         return _dcctccid <= 9 ? _dcctccid : _dcctccid - 36;
0247       else if (_otype == kEE && _btype == kTCC)
0248         return _dcctccid <= 36 ? _dcctccid : _dcctccid - 36;
0249 
0250       return 0;
0251     }
0252 
0253     int findBin2D(EcalElectronicsMapping const *electronicsMap,
0254                   ObjectType _otype,
0255                   BinningType _btype,
0256                   const DetId &_id) {
0257       if (_otype >= nObjType || _btype >= unsigned(nPresetBinnings))
0258         return 0;
0259 
0260       switch (_btype) {
0261         case kCrystal:
0262           return findBinCrystal_(electronicsMap, _otype, _id);
0263           break;
0264         case kTriggerTower:
0265           return findBinTriggerTower_(electronicsMap, _otype, _id);
0266           break;
0267         case kSuperCrystal:
0268           return findBinSuperCrystal_(electronicsMap, _otype, _id);
0269           break;
0270         case kPseudoStrip:
0271           return findBinPseudoStrip_(electronicsMap, _otype, _id);
0272           break;
0273         case kRCT:
0274           return findBinRCT_(_otype, _id);
0275           break;
0276         default:
0277           return 0;
0278       }
0279     }
0280 
0281     int findBin2D(EcalElectronicsMapping const *electronicsMap,
0282                   ObjectType _otype,
0283                   BinningType _btype,
0284                   const EcalElectronicsId &_id) {
0285       if (_otype >= nObjType || _btype >= unsigned(nPresetBinnings))
0286         return 0;
0287 
0288       switch (_btype) {
0289         case kCrystal:
0290           return findBinCrystal_(electronicsMap, _otype, _id);
0291           break;
0292         case kSuperCrystal:
0293           return findBinSuperCrystal_(electronicsMap, _otype, _id);
0294           break;
0295         default:
0296           return 0;
0297       }
0298     }
0299 
0300     int findBin2D(EcalElectronicsMapping const *electronicsMap, ObjectType _otype, BinningType _btype, int _dccid) {
0301       if (_otype != kEcal || _btype != kDCC)
0302         return 0;
0303 
0304       int nbinsX(9);
0305       unsigned iDCC(_dccid - 1);
0306       int xbin(0);
0307       if (iDCC <= kEEmHigh || iDCC >= kEEpLow)
0308         xbin = (iDCC + 6) % nbinsX + 1;
0309       else
0310         xbin = iDCC % nbinsX + 1;
0311       int ybin(6 - iDCC / nbinsX);
0312 
0313       return (nbinsX + 2) * ybin + xbin;
0314     }
0315 
0316     unsigned findPlotIndex(EcalElectronicsMapping const *electronicsMap, ObjectType _otype, const DetId &_id) {
0317       if (getNObjects(_otype) == 1)
0318         return 0;
0319 
0320       switch (_otype) {
0321         case kEcal3P:
0322           if (_id.subdetId() == EcalBarrel)
0323             return 1;
0324           else if (_id.subdetId() == EcalEndcap && zside(_id) > 0)
0325             return 2;
0326           else if (_id.subdetId() == EcalTriggerTower) {
0327             if (!isEndcapTTId(_id))
0328               return 1;
0329             else {
0330               if (zside(_id) > 0)
0331                 return 2;
0332               else
0333                 return 0;
0334             }
0335           } else
0336             return 0;
0337 
0338         case kEcal2P:
0339           if (_id.subdetId() == EcalBarrel)
0340             return 1;
0341           else if (_id.subdetId() == EcalTriggerTower && !isEndcapTTId(_id))
0342             return 1;
0343           else
0344             return 0;
0345 
0346         case kEE2P:
0347           if (zside(_id) > 0)
0348             return 1;
0349           else
0350             return 0;
0351 
0352         case kMEM2P:
0353           if (_id.subdetId() == EcalLaserPnDiode) {
0354             unsigned iDCC(dccId(_id, electronicsMap) - 1);
0355             if (iDCC >= kEBmLow && iDCC <= kEBpHigh)
0356               return 1;
0357             else
0358               return 0;
0359           } else
0360             return -1;
0361 
0362         default:
0363           return findPlotIndex(electronicsMap, _otype, dccId(_id, electronicsMap));
0364       }
0365     }
0366 
0367     unsigned findPlotIndex(EcalElectronicsMapping const *electronicsMap,
0368                            ObjectType _otype,
0369                            const EcalElectronicsId &_id) {
0370       if (getNObjects(_otype) == 1)
0371         return 0;
0372 
0373       return findPlotIndex(electronicsMap, _otype, _id.dccId());
0374     }
0375 
0376     unsigned findPlotIndex(EcalElectronicsMapping const *electronicsMap,
0377                            ObjectType _otype,
0378                            int _dcctccid,
0379                            BinningType _btype /* = kDCC*/) {
0380       if (getNObjects(_otype) == 1)
0381         return 0;
0382 
0383       int iSM(_dcctccid - 1);
0384 
0385       switch (_otype) {
0386         case kSM:
0387           if (_btype == kPseudoStrip) {
0388             iSM = iSM <= kEEmTCCHigh  ? (iSM + 1) % 18 / 2
0389                   : iSM >= kEEpTCCLow ? (iSM + 1 - 72) % 18 / 2 + 45
0390                                       : (iSM + 1) - kEEmTCCHigh;
0391             return iSM;
0392           } else
0393             return iSM;
0394 
0395         case kEBSM:
0396           return iSM - 9;
0397 
0398         case kEESM:
0399           if (iSM <= kEEmHigh)
0400             return iSM;
0401           else
0402             return iSM - nEBDCC;
0403 
0404         case kSMMEM:
0405           return memDCCIndex(_dcctccid);
0406 
0407         case kEBSMMEM:
0408           return memDCCIndex(_dcctccid) - nEEDCCMEM / 2;
0409 
0410         case kEESMMEM:
0411           if (iSM <= kEEmHigh)
0412             return memDCCIndex(_dcctccid);
0413           else
0414             return memDCCIndex(_dcctccid) - nEBDCC;
0415 
0416         case kEcal2P:
0417           if (_btype == kDCC) {
0418             if (iSM <= kEEmHigh || iSM >= kEEpLow)
0419               return 0;
0420             else
0421               return 1;
0422           } else if (_btype == kTCC) {
0423             if (iSM <= kEEmTCCHigh || iSM >= kEEpTCCLow)
0424               return 0;
0425             else
0426               return 1;
0427           } else {
0428             if (iSM == EcalBarrel - 1)
0429               return 1;
0430             else
0431               return 0;
0432           }
0433 
0434         case kEcal3P:
0435           if (_btype == kDCC) {
0436             if (iSM <= kEEmHigh)
0437               return 0;
0438             else if (iSM <= kEBpHigh)
0439               return 1;
0440             else
0441               return 2;
0442           } else if (_btype == kTCC) {
0443             if (iSM <= kEEmTCCHigh)
0444               return 0;
0445             else if (iSM <= kEBTCCHigh)
0446               return 1;
0447             else
0448               return 2;
0449           } else {
0450             if (iSM == -EcalEndcap - 1)
0451               return 0;
0452             else if (iSM == EcalBarrel - 1)
0453               return 1;
0454             else
0455               return 2;
0456           }
0457 
0458         case kEE2P:
0459           if (_btype == kDCC) {
0460             if (iSM >= kEEpLow)
0461               return 1;
0462             else
0463               return 0;
0464           } else {
0465             if (iSM >= kEEpTCCLow)
0466               return 1;
0467             else
0468               return 0;
0469           }
0470 
0471         case kMEM2P:
0472           if (_btype == kDCC) {
0473             if (iSM <= kEEmHigh || iSM >= kEEpLow)
0474               return 0;
0475             else
0476               return 1;
0477           } else if (_btype == kTCC)
0478             return -1;
0479           else {
0480             if (iSM == kEB)
0481               return 1;
0482             else
0483               return 0;
0484           }
0485         default:
0486           return -1;
0487       }
0488     }
0489 
0490     ObjectType getObject(ObjectType _otype, unsigned _iObj) {
0491       switch (_otype) {
0492         case kEcal3P:
0493           switch (_iObj) {
0494             case 0:
0495               return kEEm;
0496             case 1:
0497               return kEB;
0498             case 2:
0499               return kEEp;
0500             default:
0501               return nObjType;
0502           }
0503         case kEcal2P:
0504           switch (_iObj) {
0505             case 0:
0506               return kEE;
0507             case 1:
0508               return kEB;
0509             default:
0510               return nObjType;
0511           }
0512         case kEE2P:
0513           switch (_iObj) {
0514             case 0:
0515               return kEEm;
0516             case 1:
0517               return kEEp;
0518             default:
0519               return nObjType;
0520           }
0521         case kMEM2P:
0522           switch (_iObj) {
0523             case 0:
0524               return kEEMEM;
0525             case 1:
0526               return kEBMEM;
0527             default:
0528               return nObjType;
0529           }
0530         default:
0531           return _otype;
0532       }
0533     }
0534 
0535     unsigned getNObjects(ObjectType _otype) {
0536       switch (_otype) {
0537         case kSM:
0538           return nDCC;
0539         case kEBSM:
0540           return nEBDCC;
0541         case kEESM:
0542           return nEEDCC;
0543         case kSMMEM:
0544           return nDCCMEM;
0545         case kEBSMMEM:
0546           return nEBDCC;
0547         case kEESMMEM:
0548           return nEEDCCMEM;
0549         case kEcal2P:
0550           return 2;
0551         case kEcal3P:
0552           return 3;
0553         case kEE2P:
0554           return 2;
0555         case kMEM2P:
0556           return 2;
0557         default:
0558           return 1;
0559       }
0560     }
0561 
0562     bool isValidIdBin(
0563         EcalElectronicsMapping const *electronicsMap, ObjectType _otype, BinningType _btype, unsigned _iME, int _bin) {
0564       if (_otype == kEEm || _otype == kEEp) {
0565         if (_btype == kCrystal || _btype == kTriggerTower)
0566           return EEDetId::validDetId(_bin % 102, _bin / 102, 1);
0567         else if (_btype == kSuperCrystal)
0568           return EcalScDetId::validDetId(_bin % 22, _bin / 22, 1);
0569       } else if (_otype == kEE) {
0570         if (_btype == kCrystal || _btype == kTriggerTower) {
0571           int ix(_bin % 202);
0572           if (ix > 100)
0573             ix = (ix - 100) % 101;
0574           return EEDetId::validDetId(ix, _bin / 202, 1);
0575         } else if (_btype == kSuperCrystal) {
0576           int ix(_bin % 42);
0577           if (ix > 20)
0578             ix = (ix - 20) % 21;
0579           return EcalScDetId::validDetId(ix, _bin / 42, 1);
0580         }
0581       } else if (_otype == kSM || _otype == kEESM) {
0582         unsigned iSM(_iME);
0583         if (_otype == kEESM && iSM > kEEmHigh)
0584           iSM += nEBDCC;
0585 
0586         if (iSM >= kEBmLow && iSM <= kEBpHigh)
0587           return true;
0588 
0589         if (_btype == kCrystal || _btype == kTriggerTower) {
0590           int nX(nEESMX);
0591           if (iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08)
0592             nX = nEESMXExt;
0593           if (iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09)
0594             nX = nEESMXRed;
0595           int ix(_bin % (nX + 2) + xlow_(iSM));
0596           int iy(_bin / (nX + 2) + ylow_(iSM));
0597           int z(iSM <= kEEmHigh ? -1 : 1);
0598           return EEDetId::validDetId(ix, iy, 1) && iSM == dccId(EEDetId(ix, iy, z), electronicsMap) - 1;
0599         } else if (_btype == kSuperCrystal) {
0600           int nX(nEESMX / 5);
0601           if (iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08)
0602             nX = nEESMXExt / 5;
0603           if (iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09)
0604             nX = nEESMXRed / 5;
0605           int ix(_bin % (nX + 2) + xlow_(iSM) / 5);
0606           int iy(_bin / (nX + 2) + ylow_(iSM) / 5);
0607           int z(iSM <= kEEmHigh ? -1 : 1);
0608           return EcalScDetId::validDetId(ix, iy, z) && iSM == dccId(EcalScDetId(ix, iy, z), electronicsMap) - 1;
0609         }
0610       }
0611 
0612       return true;
0613     }
0614 
0615     std::string channelName(const EcalElectronicsMapping *electronicsMap,
0616                             uint32_t _rawId,
0617                             BinningType _btype /* = kDCC*/) {
0618       // assume the following IDs for respective binning types:
0619       // Crystal: EcalElectronicsId
0620       // TriggerTower: EcalTriggerElectronicsId (pstrip and channel ignored)
0621       // SuperCrystal: EcalElectronicsId (strip and crystal ignored)
0622       // TCC: TCC ID
0623       // DCC: DCC ID
0624 
0625       std::stringstream ss;
0626 
0627       switch (_btype) {
0628         case kCrystal: {
0629           // EB-03 DCC 12 CCU 12 strip 3 xtal 1 (EB ieta -13 iphi 60) (TCC 39 TT 12
0630           // pstrip 3 chan 1)
0631           EcalElectronicsId eid(_rawId);
0632           if (eid.towerId() >= 69)
0633             ss << smName(eid.dccId()) << " DCC " << eid.dccId() << " CCU " << eid.towerId() << " PN " << eid.xtalId();
0634           else {
0635             ss << smName(eid.dccId()) << " DCC " << eid.dccId() << " CCU " << eid.towerId() << " strip "
0636                << eid.stripId() << " xtal " << eid.xtalId();
0637 
0638             if (eid.dccId() >= kEBmLow + 1 && eid.dccId() <= kEBpHigh + 1) {
0639               EBDetId ebid(electronicsMap->getDetId(eid));
0640               ss << " (EB ieta " << std::showpos << ebid.ieta() << std::noshowpos << " iphi " << ebid.iphi() << ")";
0641             } else {
0642               EEDetId eeid(electronicsMap->getDetId(eid));
0643               ss << " (EE ix " << eeid.ix() << " iy " << eeid.iy() << ")";
0644             }
0645             EcalTriggerElectronicsId teid(electronicsMap->getTriggerElectronicsId(eid));
0646             ss << " (TCC " << teid.tccId() << " TT " << teid.ttId() << " pstrip " << teid.pseudoStripId() << " chan "
0647                << teid.channelId() << ")";
0648             break;
0649           }
0650         }
0651           [[fallthrough]];
0652         case kTriggerTower: {
0653           // EB-03 DCC 12 TCC 18 TT 3
0654           EcalTriggerElectronicsId teid(_rawId);
0655           EcalElectronicsId eid(electronicsMap->getElectronicsId(teid));
0656           ss << smName(eid.dccId()) << " DCC " << eid.dccId() << " TCC " << teid.tccId() << " TT " << teid.ttId();
0657           break;
0658         }
0659         case kSuperCrystal: {
0660           // EB-03 DCC 12 CCU 18 (EBTT ieta -13 iphi 60)
0661           EcalElectronicsId eid(_rawId);
0662           ss << smName(eid.dccId()) << " DCC " << eid.dccId() << " CCU " << eid.towerId();
0663           if (eid.dccId() >= kEBmLow + 1 && eid.dccId() <= kEBpHigh + 1) {
0664             EcalTrigTowerDetId ttid(EBDetId(electronicsMap->getDetId(eid)).tower());
0665             ss << " (EBTT ieta " << std::showpos << ttid.ieta() << std::noshowpos << " iphi " << ttid.iphi() << ")";
0666           } else {
0667             EcalScDetId scid(EEDetId(electronicsMap->getDetId(eid)).sc());
0668             ss << " (EESC ix " << scid.ix() << " iy " << scid.iy() << ")";
0669           }
0670           break;
0671         }
0672         case kTCC: {
0673           // EB-03 TCC 12
0674           int tccid(_rawId - nDCC);
0675           int dccid(electronicsMap->DCCid(electronicsMap->getTrigTowerDetId(tccid, 1)));
0676           ss << smName(dccid) << " TCC " << (_rawId - nDCC);
0677           break;
0678         }
0679         case kDCC:
0680           ss << smName(_rawId);
0681           break;
0682         default:
0683           break;
0684       }
0685 
0686       return ss.str();
0687     }
0688 
0689     uint32_t idFromName(std::string const &_name) {
0690       TString name(_name);
0691       TPRegexp re(
0692           "(EB|EE)([+-][0-9][0-9])(?: TCC ([0-9]+)| DCC ([0-9]+) (CCU|TCC) "
0693           "([0-9]+)(?: (TT|strip|PN) ([0-9]+)(?: xtal ([0-9]+)|)|)|)");
0694       //            1      2                       3             4        5 6 7 8 9
0695       uint32_t rawId(0);
0696 
0697       TObjArray *matches(re.MatchS(name));
0698       matches->SetOwner(true);
0699       if (matches->GetEntries() == 0)
0700         return 0;
0701       else if (matches->GetEntries() == 3) {
0702         TString subdet(static_cast<TObjString *>(matches->At(1))->GetString());
0703         if (subdet == "EB") {
0704           int dccid(static_cast<TObjString *>(matches->At(2))->GetString().Atoi());
0705           unsigned offset(0);
0706           if (dccid < 0) {
0707             dccid *= -1;
0708             offset = kEEmLow;
0709           } else
0710             offset = kEEpLow;
0711           rawId = (dccid + 2) % 9 + 1 + offset;
0712         } else {
0713           int dccid(static_cast<TObjString *>(matches->At(2))->GetString().Atoi());
0714           if (dccid < 0)
0715             dccid *= -1;
0716           else
0717             dccid += 18;
0718           rawId = kEBmLow + dccid;
0719         }
0720       } else if (matches->GetEntries() == 4)
0721         rawId = static_cast<TObjString *>(matches->At(3))->GetString().Atoi() + nDCC;
0722       else {
0723         TString subtype(static_cast<TObjString *>(matches->At(5))->GetString());
0724         if (subtype == "TCC") {
0725           int tccid(static_cast<TObjString *>(matches->At(6))->GetString().Atoi());
0726           int ttid(static_cast<TObjString *>(matches->At(8))->GetString().Atoi());
0727           rawId = EcalTriggerElectronicsId(tccid, ttid, 1, 1).rawId();
0728         } else {
0729           int dccid(static_cast<TObjString *>(matches->At(4))->GetString().Atoi());
0730           int towerid(static_cast<TObjString *>(matches->At(6))->GetString().Atoi());
0731           if (matches->GetEntries() == 7)
0732             rawId = EcalElectronicsId(dccid, towerid, 1, 1).rawId();
0733           else {
0734             TString chType(static_cast<TObjString *>(matches->At(7))->GetString());
0735             int stripOrPNid(static_cast<TObjString *>(matches->At(8))->GetString().Atoi());
0736             if (chType == "PN")
0737               rawId = EcalElectronicsId(dccid, towerid, 1, stripOrPNid).rawId();
0738             else if (chType == "strip") {
0739               int xtalid(static_cast<TObjString *>(matches->At(9))->GetString().Atoi());
0740               rawId = EcalElectronicsId(dccid, towerid, stripOrPNid, xtalid).rawId();
0741             }
0742             // case "TT" is already taken care of
0743           }
0744         }
0745       }
0746 
0747       delete matches;
0748 
0749       return rawId;
0750     }
0751 
0752     uint32_t idFromBin(ObjectType _otype, BinningType _btype, unsigned _iME, int _bin) {
0753       if (_otype == kEB) {
0754         if (_btype == kCrystal) {
0755           int ieta(_bin / 362 - 86);
0756           if (ieta >= 0)
0757             ++ieta;
0758           return EBDetId(ieta, _bin % 362);
0759         } else if (_btype == kTriggerTower || _btype == kSuperCrystal) {
0760           int ieta(_bin / 74 - 17);
0761           int z(1);
0762           if (ieta <= 0) {
0763             z = -1;
0764             ieta = -ieta + 1;
0765           }
0766           return EcalTrigTowerDetId(z, EcalBarrel, ieta, (_bin % 74 + 69) % 72 + 1);
0767         }
0768       } else if (_otype == kEEm || _otype == kEEp) {
0769         int z(_otype == kEEm ? -1 : 1);
0770         if (_btype == kCrystal || _btype == kTriggerTower)
0771           return EEDetId(_bin % 102, _bin / 102, z).rawId();
0772         else if (_btype == kSuperCrystal)
0773           return EcalScDetId(_bin % 22, _bin / 22, z).rawId();
0774       } else if (_otype == kEE) {
0775         if (_btype == kCrystal || _btype == kTriggerTower) {
0776           int ix(_bin % 202);
0777           int z(ix > 100 ? 1 : -1);
0778           if (z > 0)
0779             ix = (ix - 100) % 101;
0780           return EEDetId(ix, _bin / 202, z).rawId();
0781         } else if (_btype == kSuperCrystal) {
0782           int ix(_bin % 42);
0783           int z(ix > 20 ? 1 : -1);
0784           if (z > 0)
0785             ix = (ix - 20) % 21;
0786           return EcalScDetId(ix, _bin / 42, z).rawId();
0787         }
0788       } else if (_otype == kSM || _otype == kEBSM || _otype == kEESM) {
0789         unsigned iSM(_iME);
0790         if (_otype == kEBSM)
0791           iSM += 9;
0792         else if (_otype == kEESM && iSM > kEEmHigh)
0793           iSM += nEBDCC;
0794 
0795         int z(iSM <= kEBmHigh ? -1 : 1);
0796 
0797         if ((iSM >= kEBmLow && iSM <= kEBmHigh) || (iSM >= kEBpLow && iSM <= kEBpHigh)) {
0798           if (_btype == kCrystal) {
0799             int iphi(((iSM - 9) % 18) * 20 + (z < 0 ? _bin / 87 : 21 - _bin / 87));
0800             int ieta((_bin % 87) * z);
0801             return EBDetId(ieta, iphi).rawId();
0802           } else if (_btype == kTriggerTower || _btype == kSuperCrystal) {
0803             int iphi((((iSM - 9) % 18) * 4 + (z < 0 ? _bin / 19 : 5 - _bin / 19) + 69) % 72 + 1);
0804             int ieta(_bin % 19);
0805             return EcalTrigTowerDetId(z, EcalBarrel, ieta, iphi).rawId();
0806           }
0807         } else {
0808           if (_btype == kCrystal || _btype == kTriggerTower) {
0809             int nX(nEESMX);
0810             if (iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08)
0811               nX = nEESMXExt;
0812             if (iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09)
0813               nX = nEESMXRed;
0814             return EEDetId(_bin % (nX + 2) + xlow_(iSM), _bin / (nX + 2) + ylow_(iSM), z).rawId();
0815           } else if (_btype == kSuperCrystal) {
0816             int nX(nEESMX / 5);
0817             if (iSM == kEEm02 || iSM == kEEm08 || iSM == kEEp02 || iSM == kEEp08)
0818               nX = nEESMXExt / 5;
0819             if (iSM == kEEm01 || iSM == kEEm05 || iSM == kEEm09 || iSM == kEEp01 || iSM == kEEp05 || iSM == kEEp09)
0820               nX = nEESMXRed / 5;
0821             return EcalScDetId(_bin % (nX + 2) + xlow_(iSM) / 5, _bin / (nX + 2) + ylow_(iSM) / 5, z).rawId();
0822           }
0823         }
0824       }
0825 
0826       return 0;
0827     }
0828 
0829     AxisSpecs formAxis(edm::ParameterSet const &_axisParams) {
0830       AxisSpecs axis;
0831 
0832       if (_axisParams.existsAs<std::vector<double>>("edges", false)) {
0833         std::vector<double> const &vEdges(_axisParams.getUntrackedParameter<std::vector<double>>("edges"));
0834         axis.nbins = vEdges.size() - 1;
0835         axis.edges.assign(vEdges.begin(), vEdges.end());
0836       } else {
0837         axis.nbins = _axisParams.getUntrackedParameter<int>("nbins");
0838         axis.low = _axisParams.getUntrackedParameter<double>("low");
0839         bool highSet(_axisParams.existsAs<double>("high", false));
0840         bool perBinSet(_axisParams.existsAs<double>("unitsPerBin", false));
0841         if (highSet) {
0842           if (perBinSet)
0843             edm::LogWarning("EcalDQM") << "Maximum and bin width both set in an axis; using the former";
0844           axis.high = _axisParams.getUntrackedParameter<double>("high");
0845         } else if (perBinSet)
0846           axis.high = axis.low + _axisParams.getUntrackedParameter<double>("unitsPerBin") * axis.nbins;
0847         else
0848           axis.high = 0.;
0849       }
0850 
0851       if (_axisParams.existsAs<std::vector<std::string>>("labels", false)) {
0852         std::vector<std::string> const &labels(_axisParams.getUntrackedParameter<std::vector<std::string>>("labels"));
0853         if (int(labels.size()) == axis.nbins) {
0854           axis.labels = labels;
0855         }
0856       }
0857 
0858       axis.title = _axisParams.getUntrackedParameter<std::string>("title");
0859 
0860       return axis;
0861     }
0862 
0863     void fillAxisDescriptions(edm::ParameterSetDescription &_desc) {
0864       _desc.addUntracked<std::string>("title", "");
0865       _desc.addUntracked<int>("nbins", 0);
0866       _desc.addUntracked<double>("low", 0.);
0867       _desc.addOptionalNode(edm::ParameterDescription<double>("high", 0., false) ^
0868                                 edm::ParameterDescription<double>("unitsPerBin", 0., false),
0869                             false);
0870       _desc.addOptionalUntracked<std::vector<double>>("edges");
0871       _desc.addOptionalUntracked<std::vector<std::string>>("labels");
0872     }
0873 
0874     ObjectType translateObjectType(std::string const &_otypeName) {
0875       if (_otypeName == "EB")
0876         return kEB;
0877       else if (_otypeName == "EE")
0878         return kEE;
0879       else if (_otypeName == "EEm")
0880         return kEEm;
0881       else if (_otypeName == "EEp")
0882         return kEEp;
0883       else if (_otypeName == "SM")
0884         return kSM;
0885       else if (_otypeName == "EBSM")
0886         return kEBSM;
0887       else if (_otypeName == "EESM")
0888         return kEESM;
0889       else if (_otypeName == "SMMEM")
0890         return kSMMEM;
0891       else if (_otypeName == "EBSMMEM")
0892         return kEBSMMEM;
0893       else if (_otypeName == "EESMMEM")
0894         return kEESMMEM;
0895       else if (_otypeName == "Ecal")
0896         return kEcal;
0897       else if (_otypeName == "MEM")
0898         return kMEM;
0899       else if (_otypeName == "EBMEM")
0900         return kEBMEM;
0901       else if (_otypeName == "EEMEM")
0902         return kEEMEM;
0903       else if (_otypeName == "Ecal2P")
0904         return kEcal2P;
0905       else if (_otypeName == "Ecal3P")
0906         return kEcal3P;
0907       else if (_otypeName == "EE2P")
0908         return kEE2P;
0909       else if (_otypeName == "MEM2P")
0910         return kMEM2P;
0911       else if (_otypeName == "Channel")
0912         return kChannel;
0913       else if (_otypeName == "None")
0914         return nObjType;
0915 
0916       throw cms::Exception("InvalidConfiguration") << "No object type " << _otypeName << " defined";
0917     }
0918 
0919     BinningType translateBinningType(std::string const &_btypeName) {
0920       if (_btypeName == "Crystal")
0921         return kCrystal;
0922       else if (_btypeName == "TriggerTower")
0923         return kTriggerTower;
0924       else if (_btypeName == "SuperCrystal")
0925         return kSuperCrystal;
0926       else if (_btypeName == "PseudoStrip")
0927         return kPseudoStrip;
0928       else if (_btypeName == "TCC")
0929         return kTCC;
0930       else if (_btypeName == "DCC")
0931         return kDCC;
0932       else if (_btypeName == "ProjEta")
0933         return kProjEta;
0934       else if (_btypeName == "ProjPhi")
0935         return kProjPhi;
0936       else if (_btypeName == "RCT")
0937         return kRCT;
0938       else if (_btypeName == "User")
0939         return kUser;
0940       else if (_btypeName == "Report")
0941         return kReport;
0942       else if (_btypeName == "Trend")
0943         return kTrend;
0944 
0945       throw cms::Exception("InvalidConfiguration") << "No binning type " << _btypeName << " defined";
0946     }
0947 
0948     dqm::reco::MonitorElement::Kind translateKind(std::string const &_kindName) {
0949       if (_kindName == "REAL")
0950         return dqm::reco::MonitorElement::Kind::REAL;
0951       else if (_kindName == "TH1F")
0952         return dqm::reco::MonitorElement::Kind::TH1F;
0953       else if (_kindName == "TProfile")
0954         return dqm::reco::MonitorElement::Kind::TPROFILE;
0955       else if (_kindName == "TH2F")
0956         return dqm::reco::MonitorElement::Kind::TH2F;
0957       else if (_kindName == "TProfile2D")
0958         return dqm::reco::MonitorElement::Kind::TPROFILE2D;
0959       else
0960         return dqm::reco::MonitorElement::Kind::INVALID;
0961     }
0962   }  // namespace binning
0963 }  // namespace ecaldqm