Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalCommon/interface/MESetProjection.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 
0005 namespace ecaldqm {
0006   MESetProjection::MESetProjection(std::string const &_fullPath,
0007                                    binning::ObjectType _otype,
0008                                    binning::BinningType _btype,
0009                                    MonitorElement::Kind _kind,
0010                                    binning::AxisSpecs const *_yaxis /* = 0*/)
0011       : MESetEcal(_fullPath, _otype, _btype, _kind, 1, nullptr, _yaxis) {
0012     switch (kind_) {
0013       case MonitorElement::Kind::TH1F:
0014       case MonitorElement::Kind::TPROFILE:
0015         break;
0016       default:
0017         throw_("Unsupported MonitorElement kind");
0018     }
0019 
0020     switch (btype_) {
0021       case binning::kProjEta:
0022       case binning::kProjPhi:
0023         break;
0024       default:
0025         throw_("Unsupported binning");
0026     }
0027   }
0028 
0029   MESetProjection::MESetProjection(MESetProjection const &_orig) : MESetEcal(_orig) {}
0030 
0031   MESetProjection::~MESetProjection() {}
0032 
0033   MESet *MESetProjection::clone(std::string const &_path /* = ""*/) const {
0034     std::string path(path_);
0035     if (!_path.empty())
0036       path_ = _path;
0037     MESet *copy(new MESetProjection(*this));
0038     path_ = path;
0039     return copy;
0040   }
0041 
0042   void MESetProjection::fill(EcalDQMSetupObjects const edso, DetId const &_id, double _w /* = 1.*/, double, double) {
0043     if (!active_)
0044       return;
0045 
0046     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0047     checkME_(iME);
0048 
0049     int subdet(_id.subdetId());
0050 
0051     if (subdet == EcalBarrel) {
0052       EBDetId ebid(_id);
0053       if (btype_ == binning::kProjEta)
0054         fill_(iME, eta(ebid, edso.geometry), _w, 0.);
0055       else if (btype_ == binning::kProjPhi)
0056         fill_(iME, phi(ebid), _w, 0.);
0057     } else if (subdet == EcalEndcap) {
0058       EEDetId eeid(_id);
0059       if (btype_ == binning::kProjEta)
0060         fill_(iME, eta(eeid, edso.geometry), _w, 0.);
0061       if (btype_ == binning::kProjPhi) {
0062         fill_(iME, phi(eeid), _w, 0.);
0063       }
0064     } else if (isEndcapTTId(_id)) {
0065       EcalTrigTowerDetId ttid(_id);
0066       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(ttid));
0067       unsigned nIds(ids.size());
0068       if (btype_ == binning::kProjEta) {
0069         for (unsigned iId(0); iId < nIds; iId++)
0070           fill_(iME, eta(EEDetId(ids[iId]), edso.geometry), _w / nIds, 0.);
0071       } else if (btype_ == binning::kProjPhi) {
0072         for (unsigned iId(0); iId < nIds; iId++)
0073           fill_(iME, phi(EEDetId(ids[iId])), _w / nIds, 0.);
0074       }
0075     } else if (subdet == EcalTriggerTower) {
0076       EcalTrigTowerDetId ttid(_id);
0077       if (btype_ == binning::kProjEta) {
0078         int ieta(ttid.ieta());
0079         if (ieta < 18 && ieta > 0)
0080           fill_(iME, (ieta * 5 - 2.5) * EBDetId::crystalUnitToEta, _w, 0.);
0081         else if (ieta > -18 && ieta < 0)
0082           fill_(iME, (ieta * 5 + 2.5) * EBDetId::crystalUnitToEta, _w, 0.);
0083       } else if (btype_ == binning::kProjPhi)
0084         fill_(iME, phi(ttid), _w, 0.);
0085     }
0086   }
0087 
0088   void MESetProjection::fill(
0089       EcalDQMSetupObjects const edso, int _subdet, double _x /* = 1.*/, double _w /* = 1.*/, double) {
0090     if (!active_)
0091       return;
0092 
0093     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _subdet, btype_));
0094     checkME_(iME);
0095 
0096     if (btype_ == binning::kProjPhi)
0097       _x = phi(_x);
0098 
0099     mes_[iME]->Fill(_x, _w);
0100   }
0101 
0102   void MESetProjection::fill(EcalDQMSetupObjects const edso, double _x, double _w /* = 1.*/, double) {
0103     if (!active_)
0104       return;
0105     if (btype_ != binning::kProjEta)
0106       return;
0107 
0108     unsigned iME;
0109     if (_x < -etaBound)
0110       iME = 0;
0111     else if (_x < etaBound)
0112       iME = 1;
0113     else
0114       iME = 2;
0115 
0116     if (otype_ == binning::kEcal2P && iME == 2)
0117       iME = 0;
0118 
0119     checkME_(iME);
0120 
0121     mes_[iME]->Fill(_x, _w);
0122   }
0123 
0124   void MESetProjection::setBinContent(EcalDQMSetupObjects const edso, DetId const &_id, double _content) {
0125     if (!active_)
0126       return;
0127 
0128     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0129     checkME_(iME);
0130 
0131     MonitorElement *me(mes_[iME]);
0132 
0133     if (isEndcapTTId(_id)) {
0134       EcalTrigTowerDetId ttid(_id);
0135       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(ttid));
0136       unsigned nIds(ids.size());
0137       std::set<int> bins;
0138       if (btype_ == binning::kProjEta) {
0139         for (unsigned iId(0); iId < nIds; iId++) {
0140           int bin(me->getTH1()->FindBin(eta(EEDetId(ids[iId]), edso.geometry)));
0141           if (bins.find(bin) != bins.end())
0142             continue;
0143           me->setBinContent(bin, _content);
0144         }
0145       } else if (btype_ == binning::kProjPhi) {
0146         for (unsigned iId(0); iId < nIds; iId++) {
0147           int bin(me->getTH1()->FindBin(phi(EEDetId(ids[iId]))));
0148           if (bins.find(bin) != bins.end())
0149             continue;
0150           me->setBinContent(bin, _content);
0151         }
0152       }
0153       return;
0154     }
0155 
0156     double x(0.);
0157     int subdet(_id.subdetId());
0158     if (subdet == EcalBarrel) {
0159       EBDetId ebid(_id);
0160       if (btype_ == binning::kProjEta)
0161         x = eta(ebid, edso.geometry);
0162       else if (btype_ == binning::kProjPhi)
0163         x = phi(ebid);
0164     } else if (subdet == EcalEndcap) {
0165       if (btype_ == binning::kProjEta)
0166         x = eta(EEDetId(_id), edso.geometry);
0167       else if (btype_ == binning::kProjPhi)
0168         x = phi(EEDetId(_id));
0169     } else if (subdet == EcalTriggerTower) {
0170       EcalTrigTowerDetId ttid(_id);
0171       if (btype_ == binning::kProjEta) {
0172         int ieta(ttid.ieta());
0173         if (ieta < 18 && ieta > 0)
0174           x = (ieta * 5 - 2.5) * EBDetId::crystalUnitToEta;
0175         else if (ieta > -18 && ieta < 0)
0176           x = (ieta * 5 + 2.5) * EBDetId::crystalUnitToEta;
0177       } else if (btype_ == binning::kProjPhi)
0178         x = phi(ttid);
0179     }
0180 
0181     int bin(me->getTH1()->FindBin(x));
0182     me->setBinContent(bin, _content);
0183   }
0184 
0185   void MESetProjection::setBinError(EcalDQMSetupObjects const edso, DetId const &_id, double _error) {
0186     if (!active_)
0187       return;
0188 
0189     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0190     checkME_(iME);
0191 
0192     MonitorElement *me(mes_[iME]);
0193 
0194     if (isEndcapTTId(_id)) {
0195       EcalTrigTowerDetId ttid(_id);
0196       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(ttid));
0197       unsigned nIds(ids.size());
0198       std::set<int> bins;
0199       if (btype_ == binning::kProjEta) {
0200         for (unsigned iId(0); iId < nIds; iId++) {
0201           int bin(me->getTH1()->FindBin(eta(EEDetId(ids[iId]), edso.geometry)));
0202           if (bins.find(bin) != bins.end())
0203             continue;
0204           me->setBinError(bin, _error);
0205         }
0206       } else if (btype_ == binning::kProjPhi) {
0207         for (unsigned iId(0); iId < nIds; iId++) {
0208           int bin(me->getTH1()->FindBin(phi(EEDetId(ids[iId]))));
0209           if (bins.find(bin) != bins.end())
0210             continue;
0211           me->setBinError(bin, _error);
0212         }
0213       }
0214       return;
0215     }
0216 
0217     double x(0.);
0218     int subdet(_id.subdetId());
0219     if (subdet == EcalBarrel) {
0220       EBDetId ebid(_id);
0221       if (btype_ == binning::kProjEta)
0222         x = eta(ebid, edso.geometry);
0223       else if (btype_ == binning::kProjPhi)
0224         x = phi(ebid);
0225     } else if (subdet == EcalEndcap) {
0226       if (btype_ == binning::kProjEta)
0227         x = eta(EEDetId(_id), edso.geometry);
0228       else if (btype_ == binning::kProjPhi)
0229         x = phi(EEDetId(_id));
0230     } else if (subdet == EcalTriggerTower) {
0231       EcalTrigTowerDetId ttid(_id);
0232       if (btype_ == binning::kProjEta) {
0233         int ieta(ttid.ieta());
0234         if (ieta < 18 && ieta > 0)
0235           x = (ieta * 5 - 2.5) * EBDetId::crystalUnitToEta;
0236         else if (ieta > -18 && ieta < 0)
0237           x = (ieta * 5 + 2.5) * EBDetId::crystalUnitToEta;
0238       } else if (btype_ == binning::kProjPhi)
0239         x = phi(ttid);
0240     }
0241 
0242     int bin(me->getTH1()->FindBin(x));
0243     me->setBinError(bin, _error);
0244   }
0245 
0246   void MESetProjection::setBinEntries(EcalDQMSetupObjects const edso, DetId const &_id, double _entries) {
0247     if (!active_)
0248       return;
0249 
0250     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0251     checkME_(iME);
0252 
0253     MonitorElement *me(mes_[iME]);
0254 
0255     if (isEndcapTTId(_id)) {
0256       EcalTrigTowerDetId ttid(_id);
0257       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(ttid));
0258       unsigned nIds(ids.size());
0259       std::set<int> bins;
0260       if (btype_ == binning::kProjEta) {
0261         for (unsigned iId(0); iId < nIds; iId++) {
0262           int bin(me->getTH1()->FindBin(eta(EEDetId(ids[iId]), edso.geometry)));
0263           if (bins.find(bin) != bins.end())
0264             continue;
0265           me->setBinEntries(bin, _entries);
0266         }
0267       } else if (btype_ == binning::kProjPhi) {
0268         for (unsigned iId(0); iId < nIds; iId++) {
0269           int bin(me->getTH1()->FindBin(phi(EEDetId(ids[iId]))));
0270           if (bins.find(bin) != bins.end())
0271             continue;
0272           me->setBinEntries(bin, _entries);
0273         }
0274       }
0275       return;
0276     }
0277 
0278     double x(0.);
0279     int subdet(_id.subdetId());
0280     if (subdet == EcalBarrel) {
0281       EBDetId ebid(_id);
0282       if (btype_ == binning::kProjEta)
0283         x = eta(ebid, edso.geometry);
0284       else if (btype_ == binning::kProjPhi)
0285         x = phi(ebid);
0286     } else if (subdet == EcalEndcap) {
0287       if (btype_ == binning::kProjEta)
0288         x = eta(EEDetId(_id), edso.geometry);
0289       else if (btype_ == binning::kProjPhi)
0290         x = phi(EEDetId(_id));
0291     } else if (subdet == EcalTriggerTower) {
0292       EcalTrigTowerDetId ttid(_id);
0293       if (btype_ == binning::kProjEta) {
0294         int ieta(ttid.ieta());
0295         if (ieta < 18 && ieta > 0)
0296           x = (ieta * 5 - 2.5) * EBDetId::crystalUnitToEta;
0297         else if (ieta > -18 && ieta < 0)
0298           x = (ieta * 5 + 2.5) * EBDetId::crystalUnitToEta;
0299       } else if (btype_ == binning::kProjPhi)
0300         x = phi(ttid);
0301     }
0302 
0303     int bin(me->getTH1()->FindBin(x));
0304     me->setBinEntries(bin, _entries);
0305   }
0306 
0307   double MESetProjection::getBinContent(EcalDQMSetupObjects const edso, DetId const &_id, int) const {
0308     if (!active_)
0309       return 0.;
0310 
0311     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0312     checkME_(iME);
0313 
0314     MonitorElement *me(mes_[iME]);
0315 
0316     if (isEndcapTTId(_id)) {
0317       EcalTrigTowerDetId ttid(_id);
0318       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(ttid));
0319       if (btype_ == binning::kProjEta) {
0320         int bin(me->getTH1()->FindBin(eta(EEDetId(ids[0]), edso.geometry)));
0321         return me->getBinContent(bin);
0322       } else if (btype_ == binning::kProjPhi) {
0323         int bin(me->getTH1()->FindBin(phi(EEDetId(ids[0]))));
0324         return me->getBinContent(bin);
0325       }
0326       return 0.;
0327     }
0328 
0329     double x(0.);
0330     int subdet(_id.subdetId());
0331     if (subdet == EcalBarrel) {
0332       EBDetId ebid(_id);
0333       if (btype_ == binning::kProjEta)
0334         x = eta(ebid, edso.geometry);
0335       else if (btype_ == binning::kProjPhi)
0336         x = phi(ebid);
0337     } else if (subdet == EcalEndcap) {
0338       if (btype_ == binning::kProjEta)
0339         x = eta(EEDetId(_id), edso.geometry);
0340       else if (btype_ == binning::kProjPhi)
0341         x = phi(EEDetId(_id));
0342     } else if (subdet == EcalTriggerTower) {
0343       EcalTrigTowerDetId ttid(_id);
0344       if (btype_ == binning::kProjEta) {
0345         int ieta(ttid.ieta());
0346         if (ieta < 18 && ieta > 0)
0347           x = (ieta * 5 - 2.5) * EBDetId::crystalUnitToEta;
0348         else if (ieta > -18 && ieta < 0)
0349           x = (ieta * 5 + 2.5) * EBDetId::crystalUnitToEta;
0350       } else if (btype_ == binning::kProjPhi)
0351         x = phi(ttid);
0352     }
0353 
0354     int bin(me->getTH1()->FindBin(x));
0355     return me->getBinContent(bin);
0356   }
0357 
0358   double MESetProjection::getBinError(EcalDQMSetupObjects const edso, DetId const &_id, int) const {
0359     if (!active_)
0360       return 0.;
0361 
0362     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0363     checkME_(iME);
0364 
0365     MonitorElement *me(mes_[iME]);
0366 
0367     if (isEndcapTTId(_id)) {
0368       EcalTrigTowerDetId ttid(_id);
0369       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(ttid));
0370       if (btype_ == binning::kProjEta) {
0371         int bin(me->getTH1()->FindBin(eta(EEDetId(ids[0]), edso.geometry)));
0372         return me->getBinError(bin);
0373       } else if (btype_ == binning::kProjPhi) {
0374         int bin(me->getTH1()->FindBin(phi(EEDetId(ids[0]))));
0375         return me->getBinError(bin);
0376       }
0377       return 0.;
0378     }
0379 
0380     double x(0.);
0381     int subdet(_id.subdetId());
0382     if (subdet == EcalBarrel) {
0383       EBDetId ebid(_id);
0384       if (btype_ == binning::kProjEta)
0385         x = eta(ebid, edso.geometry);
0386       else if (btype_ == binning::kProjPhi)
0387         x = phi(ebid);
0388     } else if (subdet == EcalEndcap) {
0389       if (btype_ == binning::kProjEta)
0390         x = eta(EEDetId(_id), edso.geometry);
0391       else if (btype_ == binning::kProjPhi)
0392         x = phi(EEDetId(_id));
0393     } else if (subdet == EcalTriggerTower) {
0394       EcalTrigTowerDetId ttid(_id);
0395       if (btype_ == binning::kProjEta) {
0396         int ieta(ttid.ieta());
0397         if (ieta < 18 && ieta > 0)
0398           x = (ieta * 5 - 2.5) * EBDetId::crystalUnitToEta;
0399         else if (ieta > -18 && ieta < 0)
0400           x = (ieta * 5 + 2.5) * EBDetId::crystalUnitToEta;
0401       } else if (btype_ == binning::kProjPhi)
0402         x = phi(ttid);
0403     }
0404 
0405     int bin(me->getTH1()->FindBin(x));
0406     return me->getBinError(bin);
0407   }
0408 
0409   double MESetProjection::getBinEntries(EcalDQMSetupObjects const edso, DetId const &_id, int) const {
0410     if (!active_)
0411       return 0.;
0412 
0413     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0414     checkME_(iME);
0415 
0416     MonitorElement *me(mes_[iME]);
0417 
0418     if (isEndcapTTId(_id)) {
0419       EcalTrigTowerDetId ttid(_id);
0420       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(ttid));
0421       if (btype_ == binning::kProjEta) {
0422         int bin(me->getTH1()->FindBin(eta(EEDetId(ids[0]), edso.geometry)));
0423         return me->getBinEntries(bin);
0424       } else if (btype_ == binning::kProjPhi) {
0425         int bin(me->getTH1()->FindBin(phi(EEDetId(ids[0]))));
0426         return me->getBinEntries(bin);
0427       }
0428       return 0.;
0429     }
0430 
0431     double x(0.);
0432     int subdet(_id.subdetId());
0433     if (subdet == EcalBarrel) {
0434       EBDetId ebid(_id);
0435       if (btype_ == binning::kProjEta)
0436         x = eta(ebid, edso.geometry);
0437       else if (btype_ == binning::kProjPhi)
0438         x = phi(ebid);
0439     } else if (subdet == EcalEndcap) {
0440       if (btype_ == binning::kProjEta)
0441         x = eta(EEDetId(_id), edso.geometry);
0442       else if (btype_ == binning::kProjPhi)
0443         x = phi(EEDetId(_id));
0444     } else if (subdet == EcalTriggerTower) {
0445       EcalTrigTowerDetId ttid(_id);
0446       if (btype_ == binning::kProjEta) {
0447         int ieta(ttid.ieta());
0448         if (ieta < 18 && ieta > 0)
0449           x = (ieta * 5 - 2.5) * EBDetId::crystalUnitToEta;
0450         else if (ieta > -18 && ieta < 0)
0451           x = (ieta * 5 + 2.5) * EBDetId::crystalUnitToEta;
0452       } else if (btype_ == binning::kProjPhi)
0453         x = phi(ttid);
0454     }
0455 
0456     int bin(me->getTH1()->FindBin(x));
0457     return me->getBinEntries(bin);
0458   }
0459 
0460 }  // namespace ecaldqm