Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalCommon/interface/MESetDet2D.h"
0002 
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 
0005 namespace ecaldqm {
0006   MESetDet2D::MESetDet2D(std::string const &_fullPath,
0007                          binning::ObjectType _otype,
0008                          binning::BinningType _btype,
0009                          MonitorElement::Kind _kind,
0010                          binning::AxisSpecs const *_zaxis /* = 0*/)
0011       : MESetEcal(_fullPath, _otype, _btype, _kind, 2, nullptr, nullptr, _zaxis) {
0012     switch (kind_) {
0013       case MonitorElement::Kind::TH2F:
0014       case MonitorElement::Kind::TPROFILE2D:
0015         break;
0016       default:
0017         throw_("Unsupported MonitorElement kind");
0018     }
0019   }
0020 
0021   MESetDet2D::MESetDet2D(MESetDet2D const &_orig) : MESetEcal(_orig) {}
0022 
0023   MESetDet2D::~MESetDet2D() {}
0024 
0025   MESet *MESetDet2D::clone(std::string const &_path /* = ""*/) const {
0026     std::string path(path_);
0027     if (!_path.empty())
0028       path_ = _path;
0029     MESet *copy(new MESetDet2D(*this));
0030     path_ = path;
0031     return copy;
0032   }
0033 
0034   void MESetDet2D::book(DQMStore::IBooker &_ibooker, const EcalElectronicsMapping *electronicsMap) {
0035     MESetEcal::book(_ibooker, electronicsMap);
0036 
0037     if (btype_ == binning::kCrystal) {
0038       for (unsigned iME(0); iME < mes_.size(); iME++) {
0039         MonitorElement *me(mes_[iME]);
0040 
0041         binning::ObjectType actualObject(binning::getObject(otype_, iME));
0042         if (actualObject == binning::kMEM) {
0043           for (int iBin(1); iBin <= me->getNbinsX(); ++iBin)
0044             me->setBinLabel(iBin, binning::channelName(electronicsMap, memDCCId(iBin - 1)));
0045         }
0046         if (actualObject == binning::kEBMEM) {
0047           for (int iBin(1); iBin <= me->getNbinsX(); ++iBin)
0048             me->setBinLabel(iBin, binning::channelName(electronicsMap, iBin + kEBmLow));
0049         }
0050         if (actualObject == binning::kEEMEM) {
0051           for (int iBin(1); iBin <= me->getNbinsX() / 2; ++iBin) {
0052             me->setBinLabel(iBin, binning::channelName(electronicsMap, memDCCId(iBin - 1)));
0053             me->setBinLabel(iBin + me->getNbinsX() / 2, binning::channelName(electronicsMap, memDCCId(iBin + 39)));
0054           }
0055         }
0056       }
0057     } else if (btype_ == binning::kDCC) {
0058       for (unsigned iME(0); iME < mes_.size(); iME++) {
0059         MonitorElement *me(mes_[iME]);
0060 
0061         binning::ObjectType actualObject(binning::getObject(otype_, iME));
0062         if (actualObject == binning::kEcal) {
0063           me->setBinLabel(1, "EE", 2);
0064           me->setBinLabel(6, "EE", 2);
0065           me->setBinLabel(3, "EB", 2);
0066           me->setBinLabel(5, "EB", 2);
0067         }
0068       }
0069     }
0070 
0071     // To avoid the ambiguity between "content == 0 because the mean is 0" and
0072     // "content == 0 because the entry is 0" RenderPlugin must be configured
0073     // accordingly
0074     if (!batchMode_ && kind_ == MonitorElement::Kind::TPROFILE2D)
0075       resetAll(0., 0., -1.);
0076   }
0077 
0078   void MESetDet2D::fill(EcalDQMSetupObjects const edso, DetId const &_id, double _w /* = 1.*/, double, double) {
0079     if (!active_)
0080       return;
0081 
0082     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0083     checkME_(iME);
0084 
0085     binning::ObjectType obj(binning::getObject(otype_, iME));
0086 
0087     int bin;
0088 
0089     if (btype_ == binning::kRCT) {
0090       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0091       fill_(iME, bin, _w);
0092     } else {
0093       if (isEndcapTTId(_id)) {
0094         std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0095         unsigned nId(ids.size());
0096         for (unsigned iId(0); iId < nId; iId++) {
0097           bin = binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[iId]);
0098           fill_(iME, bin, _w);
0099         }
0100       } else {
0101         bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0102         fill_(iME, bin, _w);
0103       }
0104     }
0105   }
0106 
0107   void MESetDet2D::fill(
0108       EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, double _w /* = 1.*/, double, double) {
0109     if (!active_)
0110       return;
0111 
0112     unsigned iME(0);
0113     if (btype_ == binning::kPseudoStrip)
0114       iME = binning::findPlotIndex(edso.electronicsMap, otype_, _id.dccId(), binning::kPseudoStrip);
0115     else
0116       iME = binning::findPlotIndex(edso.electronicsMap, otype_, _id);
0117     checkME_(iME);
0118 
0119     binning::ObjectType obj(binning::getObject(otype_, iME));
0120 
0121     int bin;
0122 
0123     if (btype_ == binning::kPseudoStrip) {
0124       EcalElectronicsId stid(_id);
0125       std::vector<DetId> ids(
0126           edso.electronicsMap->pseudoStripConstituents(stid.dccId(), stid.towerId(), stid.stripId()));
0127       unsigned nId(ids.size());
0128       for (unsigned iId(0); iId < nId; iId++) {
0129         bin = binning::findBin2D(edso.electronicsMap, obj, btype_, ids[iId]);
0130         fill_(iME, bin, _w);
0131       }
0132     } else {
0133       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0134       fill_(iME, bin, _w);
0135     }
0136   }
0137 
0138   void MESetDet2D::fill(EcalDQMSetupObjects const edso, int _dcctccid, double _w /* = 1.*/, double, double) {
0139     if (!active_)
0140       return;
0141 
0142     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid));
0143     checkME_(iME);
0144 
0145     binning::ObjectType obj(binning::getObject(otype_, iME));
0146 
0147     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _dcctccid));
0148     fill_(iME, bin, _w);
0149   }
0150 
0151   void MESetDet2D::setBinContent(EcalDQMSetupObjects const edso, DetId const &_id, double _content) {
0152     if (!active_)
0153       return;
0154 
0155     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0156     checkME_(iME);
0157 
0158     binning::ObjectType obj(binning::getObject(otype_, iME));
0159 
0160     int bin;
0161 
0162     if (isEndcapTTId(_id)) {
0163       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0164       unsigned nId(ids.size());
0165       for (unsigned iId(0); iId < nId; iId++) {
0166         bin = binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[iId]);
0167         mes_[iME]->setBinContent(bin, _content);
0168       }
0169     } else {
0170       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0171       mes_[iME]->setBinContent(bin, _content);
0172     }
0173   }
0174 
0175   void MESetDet2D::setBinContent(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, double _content) {
0176     if (!active_)
0177       return;
0178 
0179     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0180     checkME_(iME);
0181 
0182     binning::ObjectType obj(binning::getObject(otype_, iME));
0183 
0184     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _id));
0185     mes_[iME]->setBinContent(bin, _content);
0186   }
0187 
0188   void MESetDet2D::setBinContent(EcalDQMSetupObjects const edso, int _dcctccid, double _content) {
0189     if (!active_)
0190       return;
0191 
0192     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid));
0193     checkME_(iME);
0194 
0195     binning::ObjectType obj(binning::getObject(otype_, iME));
0196 
0197     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _dcctccid));
0198     mes_[iME]->setBinContent(bin, _content);
0199   }
0200 
0201   void MESetDet2D::setBinError(EcalDQMSetupObjects const edso, DetId const &_id, double _error) {
0202     if (!active_)
0203       return;
0204 
0205     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0206     checkME_(iME);
0207 
0208     binning::ObjectType obj(binning::getObject(otype_, iME));
0209 
0210     int bin;
0211 
0212     if (isEndcapTTId(_id)) {
0213       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0214       unsigned nId(ids.size());
0215       for (unsigned iId(0); iId < nId; iId++) {
0216         bin = binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[iId]);
0217         mes_[iME]->setBinError(bin, _error);
0218       }
0219     } else {
0220       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0221       mes_[iME]->setBinError(bin, _error);
0222     }
0223   }
0224 
0225   void MESetDet2D::setBinError(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, double _error) {
0226     if (!active_)
0227       return;
0228 
0229     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0230     checkME_(iME);
0231 
0232     binning::ObjectType obj(binning::getObject(otype_, iME));
0233 
0234     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _id));
0235     mes_[iME]->setBinError(bin, _error);
0236   }
0237 
0238   void MESetDet2D::setBinError(EcalDQMSetupObjects const edso, int _dcctccid, double _error) {
0239     if (!active_)
0240       return;
0241 
0242     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid));
0243     checkME_(iME);
0244 
0245     binning::ObjectType obj(binning::getObject(otype_, iME));
0246 
0247     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _dcctccid));
0248     mes_[iME]->setBinError(bin, _error);
0249   }
0250 
0251   void MESetDet2D::setBinEntries(EcalDQMSetupObjects const edso, DetId const &_id, double _entries) {
0252     if (!active_)
0253       return;
0254     if (kind_ != MonitorElement::Kind::TPROFILE2D)
0255       return;
0256 
0257     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0258     checkME_(iME);
0259 
0260     binning::ObjectType obj(binning::getObject(otype_, iME));
0261 
0262     int bin;
0263 
0264     if (isEndcapTTId(_id)) {
0265       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0266       unsigned nId(ids.size());
0267       for (unsigned iId(0); iId < nId; iId++) {
0268         bin = binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[iId]);
0269         mes_[iME]->setBinEntries(bin, _entries);
0270       }
0271     } else {
0272       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0273       mes_[iME]->setBinEntries(bin, _entries);
0274     }
0275   }
0276 
0277   void MESetDet2D::setBinEntries(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, double _entries) {
0278     if (!active_)
0279       return;
0280     if (kind_ != MonitorElement::Kind::TPROFILE2D)
0281       return;
0282 
0283     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0284     checkME_(iME);
0285 
0286     binning::ObjectType obj(binning::getObject(otype_, iME));
0287 
0288     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _id));
0289     mes_[iME]->setBinEntries(bin, _entries);
0290   }
0291 
0292   void MESetDet2D::setBinEntries(EcalDQMSetupObjects const edso, int _dcctccid, double _entries) {
0293     if (!active_)
0294       return;
0295 
0296     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid));
0297     checkME_(iME);
0298 
0299     binning::ObjectType obj(binning::getObject(otype_, iME));
0300 
0301     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _dcctccid));
0302     mes_[iME]->setBinEntries(bin, _entries);
0303   }
0304 
0305   double MESetDet2D::getBinContent(EcalDQMSetupObjects const edso, DetId const &_id, int) const {
0306     if (!active_)
0307       return 0.;
0308 
0309     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0310     checkME_(iME);
0311 
0312     binning::ObjectType obj(binning::getObject(otype_, iME));
0313 
0314     int bin;
0315 
0316     if (isEndcapTTId(_id)) {
0317       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0318       bin = binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[0]);
0319     } else {
0320       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0321     }
0322 
0323     return mes_[iME]->getBinContent(bin);
0324   }
0325 
0326   double MESetDet2D::getBinContent(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, int) const {
0327     if (!active_)
0328       return 0.;
0329 
0330     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0331     checkME_(iME);
0332 
0333     binning::ObjectType obj(binning::getObject(otype_, iME));
0334 
0335     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _id));
0336 
0337     return mes_[iME]->getBinContent(bin);
0338   }
0339 
0340   double MESetDet2D::getBinContent(EcalDQMSetupObjects const edso, int _dcctccid, int) const {
0341     if (!active_)
0342       return 0.;
0343 
0344     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid));
0345     checkME_(iME);
0346 
0347     binning::ObjectType obj(binning::getObject(otype_, iME));
0348 
0349     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _dcctccid));
0350 
0351     return mes_[iME]->getBinContent(bin);
0352   }
0353 
0354   double MESetDet2D::getBinError(EcalDQMSetupObjects const edso, DetId const &_id, int) const {
0355     if (!active_)
0356       return 0.;
0357 
0358     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0359     checkME_(iME);
0360 
0361     binning::ObjectType obj(binning::getObject(otype_, iME));
0362 
0363     int bin;
0364 
0365     if (isEndcapTTId(_id)) {
0366       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0367       bin = binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[0]);
0368     } else {
0369       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0370     }
0371 
0372     return mes_[iME]->getBinError(bin);
0373   }
0374 
0375   double MESetDet2D::getBinError(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, int) const {
0376     if (!active_)
0377       return 0.;
0378 
0379     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0380     checkME_(iME);
0381 
0382     binning::ObjectType obj(binning::getObject(otype_, iME));
0383 
0384     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _id));
0385 
0386     return mes_[iME]->getBinError(bin);
0387   }
0388 
0389   double MESetDet2D::getBinError(EcalDQMSetupObjects const edso, int _dcctccid, int) const {
0390     if (!active_)
0391       return 0.;
0392 
0393     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid));
0394     checkME_(iME);
0395 
0396     binning::ObjectType obj(binning::getObject(otype_, iME));
0397 
0398     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _dcctccid));
0399 
0400     return mes_[iME]->getBinError(bin);
0401   }
0402 
0403   double MESetDet2D::getBinEntries(EcalDQMSetupObjects const edso, DetId const &_id, int) const {
0404     if (!active_)
0405       return 0.;
0406     if (kind_ != MonitorElement::Kind::TPROFILE2D)
0407       return 0.;
0408 
0409     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0410     checkME_(iME);
0411 
0412     binning::ObjectType obj(binning::getObject(otype_, iME));
0413 
0414     int bin;
0415 
0416     if (isEndcapTTId(_id)) {
0417       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0418       bin = binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[0]);
0419     } else {
0420       bin = binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0421     }
0422 
0423     double entries(mes_[iME]->getBinEntries(bin));
0424     if (entries < 0.)
0425       return 0.;
0426     else
0427       return entries;
0428   }
0429 
0430   double MESetDet2D::getBinEntries(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, int) const {
0431     if (!active_)
0432       return 0.;
0433     if (kind_ != MonitorElement::Kind::TPROFILE2D)
0434       return 0.;
0435 
0436     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0437     checkME_(iME);
0438 
0439     binning::ObjectType obj(binning::getObject(otype_, iME));
0440 
0441     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _id));
0442 
0443     double entries(mes_[iME]->getBinEntries(bin));
0444     if (entries < 0.)
0445       return 0.;
0446     else
0447       return entries;
0448   }
0449 
0450   double MESetDet2D::getBinEntries(EcalDQMSetupObjects const edso, int _dcctccid, int) const {
0451     if (!active_)
0452       return 0.;
0453 
0454     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid));
0455     checkME_(iME);
0456 
0457     binning::ObjectType obj(binning::getObject(otype_, iME));
0458 
0459     int bin(binning::findBin2D(edso.electronicsMap, obj, btype_, _dcctccid));
0460 
0461     double entries(mes_[iME]->getBinEntries(bin));
0462     if (entries < 0.)
0463       return 0.;
0464     else
0465       return entries;
0466   }
0467 
0468   int MESetDet2D::findBin(EcalDQMSetupObjects const edso, DetId const &_id) const {
0469     if (!active_)
0470       return 0;
0471 
0472     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0473     checkME_(iME);
0474 
0475     binning::ObjectType obj(binning::getObject(otype_, iME));
0476 
0477     if (isEndcapTTId(_id)) {
0478       std::vector<DetId> ids(edso.trigtowerMap->constituentsOf(EcalTrigTowerDetId(_id)));
0479       return binning::findBin2D(edso.electronicsMap, obj, binning::kTriggerTower, ids[0]);
0480     } else
0481       return binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0482   }
0483 
0484   int MESetDet2D::findBin(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id) const {
0485     if (!active_)
0486       return 0;
0487 
0488     unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
0489     checkME_(iME);
0490 
0491     binning::ObjectType obj(binning::getObject(otype_, iME));
0492 
0493     return binning::findBin2D(edso.electronicsMap, obj, btype_, _id);
0494   }
0495 
0496   void MESetDet2D::reset(EcalElectronicsMapping const *electronicsMap,
0497                          double _content /* = 0.*/,
0498                          double _err /* = 0.*/,
0499                          double _entries /* = 0.*/) {
0500     unsigned nME(binning::getNObjects(otype_));
0501 
0502     bool isProfile(kind_ == MonitorElement::Kind::TPROFILE2D);
0503 
0504     for (unsigned iME(0); iME < nME; iME++) {
0505       MonitorElement *me(mes_[iME]);
0506 
0507       binning::ObjectType obj(binning::getObject(otype_, iME));
0508 
0509       int nbinsX(me->getTH1()->GetNbinsX());
0510       int nbinsY(me->getTH1()->GetNbinsY());
0511       for (int ix(1); ix <= nbinsX; ix++) {
0512         for (int iy(1); iy <= nbinsY; iy++) {
0513           int bin((nbinsX + 2) * iy + ix);
0514           if (!binning::isValidIdBin(electronicsMap, obj, btype_, iME, bin))
0515             continue;
0516           me->setBinContent(bin, _content);
0517           me->setBinError(bin, _err);
0518           if (isProfile)
0519             me->setBinEntries(bin, _entries);
0520         }
0521       }
0522     }
0523   }
0524 
0525   void MESetDet2D::fill_(unsigned _iME, int _bin, double _w) {
0526     if (kind_ == MonitorElement::Kind::TPROFILE2D) {
0527       MonitorElement *me(mes_.at(_iME));
0528       if (me->getBinEntries(_bin) < 0.) {
0529         me->setBinContent(_bin, 0.);
0530         me->setBinEntries(_bin, 0.);
0531         me->getTProfile2D()->SetEntries(me->getTProfile2D()->GetEntries() + 1.);
0532       }
0533     }
0534 
0535     MESet::fill_(_iME, _bin, _w);
0536   }
0537 
0538   void MESetDet2D::fill_(unsigned _iME, int _bin, double _y, double _w) {
0539     if (kind_ == MonitorElement::Kind::TPROFILE2D) {
0540       MonitorElement *me(mes_.at(_iME));
0541       if (me->getBinEntries(_bin) < 0.) {
0542         me->setBinContent(_bin, 0.);
0543         me->setBinEntries(_bin, 0.);
0544         me->getTProfile2D()->SetEntries(me->getTProfile2D()->GetEntries() + 1.);
0545       }
0546     }
0547 
0548     MESet::fill_(_iME, _bin, _y, _w);
0549   }
0550 
0551   void MESetDet2D::fill_(unsigned _iME, double _x, double _wy, double _w) {
0552     if (kind_ == MonitorElement::Kind::TPROFILE2D) {
0553       MonitorElement *me(mes_.at(_iME));
0554       int bin(me->getTProfile2D()->FindBin(_x, _wy));
0555       if (me->getBinEntries(bin) < 0.) {
0556         me->setBinContent(bin, 0.);
0557         me->setBinEntries(bin, 0.);
0558         me->getTProfile2D()->SetEntries(me->getTProfile2D()->GetEntries() + 1.);
0559       }
0560     }
0561 
0562     MESet::fill_(_iME, _x, _wy, _w);
0563   }
0564 }  // namespace ecaldqm