Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
#include "DQM/EcalCommon/interface/MESetEcal.h"

#include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
#include "DQM/EcalCommon/interface/MESetUtils.h"

#include <limits>
#include <sstream>

namespace ecaldqm {
  MESetEcal::MESetEcal(std::string const &_fullPath,
                       binning::ObjectType _otype,
                       binning::BinningType _btype,
                       MonitorElement::Kind _kind,
                       unsigned _logicalDimensions,
                       binning::AxisSpecs const *_xaxis /* = 0*/,
                       binning::AxisSpecs const *_yaxis /* = 0*/,
                       binning::AxisSpecs const *_zaxis /* = 0*/)
      : MESet(_fullPath, _otype, _btype, _kind),
        logicalDimensions_(_logicalDimensions),
        xaxis_(_xaxis ? new binning::AxisSpecs(*_xaxis) : nullptr),
        yaxis_(_yaxis ? new binning::AxisSpecs(*_yaxis) : nullptr),
        zaxis_(_zaxis ? new binning::AxisSpecs(*_zaxis) : nullptr) {
    if (btype_ == binning::kUser && ((logicalDimensions_ > 0 && !xaxis_) || (logicalDimensions_ > 1 && !yaxis_)))
      throw_("Need axis specifications");
  }

  MESetEcal::MESetEcal(MESetEcal const &_orig)
      : MESet(_orig),
        logicalDimensions_(_orig.logicalDimensions_),
        xaxis_(_orig.xaxis_ ? new binning::AxisSpecs(*_orig.xaxis_) : nullptr),
        yaxis_(_orig.yaxis_ ? new binning::AxisSpecs(*_orig.yaxis_) : nullptr),
        zaxis_(_orig.zaxis_ ? new binning::AxisSpecs(*_orig.zaxis_) : nullptr) {}

  MESetEcal::~MESetEcal() {
    delete xaxis_;
    delete yaxis_;
    delete zaxis_;
  }

  MESet &MESetEcal::operator=(MESet const &_rhs) {
    delete xaxis_;
    delete yaxis_;
    delete zaxis_;
    xaxis_ = nullptr;
    yaxis_ = nullptr;
    zaxis_ = nullptr;

    MESetEcal const *pRhs(dynamic_cast<MESetEcal const *>(&_rhs));
    if (pRhs) {
      logicalDimensions_ = pRhs->logicalDimensions_;
      if (pRhs->xaxis_)
        xaxis_ = new binning::AxisSpecs(*pRhs->xaxis_);
      if (pRhs->yaxis_)
        yaxis_ = new binning::AxisSpecs(*pRhs->yaxis_);
      if (pRhs->zaxis_)
        zaxis_ = new binning::AxisSpecs(*pRhs->zaxis_);
    }
    return MESet::operator=(_rhs);
  }

  MESet *MESetEcal::clone(std::string const &_path /* = ""*/) const {
    std::string path(path_);
    if (!_path.empty())
      path_ = _path;
    MESet *copy(new MESetEcal(*this));
    path_ = path;
    return copy;
  }

  void MESetEcal::book(DQMStore::IBooker &_ibooker, EcalElectronicsMapping const *electronicsMap) {
    using namespace std;

    auto oldscope = MonitorElementData::Scope::RUN;
    if (lumiFlag_)
      oldscope = _ibooker.setScope(MonitorElementData::Scope::LUMI);

    clear();

    vector<string> mePaths(generatePaths(electronicsMap));

    for (unsigned iME(0); iME < mePaths.size(); iME++) {
      string &path(mePaths[iME]);
      if (path.find('%') != string::npos)
        throw_("book() called with incompletely formed path [" + path + "]");

      binning::ObjectType actualObject(binning::getObject(otype_, iME));

      binning::AxisSpecs xaxis, yaxis, zaxis;

      bool isHistogram(logicalDimensions_ > 0);
      bool isMap(logicalDimensions_ > 1);

      if (isHistogram) {
        if (xaxis_)
          xaxis = *xaxis_;
        if (yaxis_)
          yaxis = *yaxis_;
        if (zaxis_)
          zaxis = *zaxis_;

        if (xaxis.nbins == 0) {  // uses preset
          binning::AxisSpecs xdef(binning::getBinning(electronicsMap, actualObject, btype_, isMap, 1, iME));
          if (!xaxis.labels.empty() || !xaxis.title.empty()) {  // PSet specifies title / label only
            std::vector<string> labels(xaxis.labels);
            std::string title(xaxis.title);
            xaxis = xdef;
            xaxis.labels = labels;
            xaxis.title = title;
          } else
            xaxis = xdef;
        }

        if (isMap && yaxis.nbins == 0) {
          binning::AxisSpecs ydef(binning::getBinning(electronicsMap, actualObject, btype_, isMap, 2, iME));
          if (!yaxis.labels.empty() || !yaxis.title.empty()) {  // PSet specifies title / label only
            std::vector<string> labels(yaxis.labels);
            std::string title(yaxis.title);
            yaxis = ydef;
            yaxis.labels = labels;
            yaxis.title = title;
          } else
            yaxis = ydef;
        }

        if (yaxis.high - yaxis.low < 1.e-10) {
          yaxis.low = -numeric_limits<double>::max();
          yaxis.high = numeric_limits<double>::max();
        }

        if (zaxis.high - zaxis.low < 1.e-10) {
          zaxis.low = -numeric_limits<double>::max();
          zaxis.high = numeric_limits<double>::max();
        }
      }

      size_t slashPos(path.find_last_of('/'));
      string name(path.substr(slashPos + 1));
      _ibooker.cd();
      _ibooker.setCurrentFolder(path.substr(0, slashPos));

      MonitorElement *me(nullptr);

      switch (kind_) {
        case MonitorElement::Kind::REAL:
          me = _ibooker.bookFloat(name);

          break;

        case MonitorElement::Kind::TH1F:
          if (xaxis.edges.empty())
            me = _ibooker.book1D(name, name, xaxis.nbins, xaxis.low, xaxis.high);
          else
            me = _ibooker.book1D(name, name, xaxis.nbins, &(xaxis.edges[0]));

          break;

        case MonitorElement::Kind::TPROFILE:
          if (xaxis.edges.empty()) {
            me = _ibooker.bookProfile(name, name, xaxis.nbins, xaxis.low, xaxis.high, yaxis.low, yaxis.high, "");
          } else {
            // DQMStore bookProfile interface uses double* for bin edges
            double *edges(new double[xaxis.nbins + 1]);
            std::copy(xaxis.edges.begin(), xaxis.edges.end(), edges);
            me = _ibooker.bookProfile(name, name, xaxis.nbins, edges, yaxis.low, yaxis.high, "");
            delete[] edges;
          }

          break;

        case MonitorElement::Kind::TH2F:
          if (xaxis.edges.empty() && yaxis.edges.empty()) {
            me = _ibooker.book2D(name, name, xaxis.nbins, xaxis.low, xaxis.high, yaxis.nbins, yaxis.low, yaxis.high);
          } else {
            binning::AxisSpecs *specs[] = {&xaxis, &yaxis};
            for (int iSpec(0); iSpec < 2; iSpec++) {
              if (specs[iSpec]->edges.empty()) {
                specs[iSpec]->edges = std::vector<float>(specs[iSpec]->nbins + 1);
                int nbins(specs[iSpec]->nbins);
                double low(specs[iSpec]->low), high(specs[iSpec]->high);
                for (int i(0); i < nbins + 1; i++)
                  specs[iSpec]->edges[i] = low + (high - low) / nbins * i;
              }
            }
            me = _ibooker.book2D(name, name, xaxis.nbins, &(xaxis.edges[0]), yaxis.nbins, &(yaxis.edges[0]));
          }

          break;

        case MonitorElement::Kind::TPROFILE2D:
          if (!zaxis.edges.empty()) {
            zaxis.low = zaxis.edges[0];
            zaxis.high = zaxis.edges[zaxis.nbins];
          }
          if (!(xaxis.edges.empty() && yaxis.edges.empty()))
            throw_("Variable bin size for 2D profile not implemented");
          me = _ibooker.bookProfile2D(name,
                                      name,
                                      xaxis.nbins,
                                      xaxis.low,
                                      xaxis.high,
                                      yaxis.nbins,
                                      yaxis.low,
                                      yaxis.high,
                                      zaxis.low,
                                      zaxis.high,
                                      "");

          break;

        default:
          break;
      }

      if (!me)
        throw_("ME could not be booked");

      if (isHistogram) {
        me->setAxisTitle(xaxis.title, 1);
        me->setAxisTitle(yaxis.title, 2);
        if (isMap)
          me->setAxisTitle(zaxis.title, 3);

        if (!xaxis.labels.empty()) {
          for (int iBin(1); iBin <= xaxis.nbins; ++iBin)
            me->setBinLabel(iBin, xaxis.labels[iBin - 1], 1);
        }
        if (!yaxis.labels.empty()) {
          for (int iBin(1); iBin <= yaxis.nbins; ++iBin)
            me->setBinLabel(iBin, yaxis.labels[iBin - 1], 2);
        }
        if (!zaxis.labels.empty()) {
          for (int iBin(1); iBin <= zaxis.nbins; ++iBin)
            me->setBinLabel(iBin, zaxis.labels[iBin - 1], 3);
        }

        /* FIX: In ROOT 6.0.12 bit 20 is used by ROOT (bit 19 was already in use
      in 6.0.x). Talking with the ROOT team, users should never use SetBit for
      their own purpose since those bits are reserved for ROOT internally. See
      https://github.com/cms-sw/cmssw/issues/21423 for some alternative ways of
      attaching additional information to a TH1

      // For plot tagging in RenderPlugin; default values are 1 for both
      // bits 19 - 23 are free in TH1::fBits
      // can only pack object + logical dimensions into 5 bits (4 bits for
      object, 1 bit for dim (1 -> dim >= 2))
      me->getTH1()->SetBit(uint32_t(actualObject + 1) << 20);
      if(isMap) me->getTH1()->SetBit(0x1 << 19);
      */

        // The render plugin requires some metadata in order to set the correct
        // rendering for each plot. The original solution was to use bits number
        // 19 to 23 in TH1::fBits, but these were meant for ROOT's internal usage
        // and eventually started breaking things, see:
        // https://github.com/cms-sw/cmssw/issues/21423 The current solution is to
        // use the UniqueID field in the parent TObject, which is expected to work
        // if there is no TRef pointing to the TObject.

        // To check that indeed there is no such TRef, one can use
        // TestBit(kIsReferenced), e.g. std::cout << "Need to set unique ID at
        // path = " << path << "; for this path, TestBit(kIsReferenced) is: " <<
        // (me->getTH1()->TestBit(kIsReferenced)? "true": "false") << std::endl;
        // // should always output false for the solution to work

        // Originally, bit 19 in TH1::fBits was set to isMap, while bits 20-23
        // contained (actualObject+1). The idea is to make sure that both these
        // variables are easily recoverable in the render plugin, as in this
        // solution, where isMap is the last bit.
        me->getTH1()->SetUniqueID(uint32_t(2 * (actualObject + 1) + (isMap ? 1 : 0)));
      }

      mes_.push_back(me);
    }

    if (lumiFlag_)
      _ibooker.setScope(oldscope);

    active_ = true;
  }

  bool MESetEcal::retrieve(EcalElectronicsMapping const *electronicsMap,
                           DQMStore::IGetter &_igetter,
                           std::string *_failedPath /* = 0*/) const {
    clear();

    std::vector<std::string> mePaths(generatePaths(electronicsMap));
    if (mePaths.empty()) {
      if (_failedPath)
        _failedPath->clear();
      return false;
    }

    for (unsigned iME(0); iME < mePaths.size(); iME++) {
      std::string &path(mePaths[iME]);
      if (path.find('%') != std::string::npos)
        throw_("retrieve() called with incompletely formed path [" + path + "]");

      MonitorElement *me(_igetter.get(path));
      if (me)
        mes_.push_back(me);
      else {
        clear();
        if (_failedPath)
          *_failedPath = path;
        return false;
      }
    }

    active_ = true;
    return true;
  }

  void MESetEcal::fill(EcalDQMSetupObjects const edso,
                       DetId const &_id,
                       double _x /* = 1.*/,
                       double _wy /* = 1.*/,
                       double _w /* = 1.*/) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    fill_(iME, _x, _wy, _w);
  }

  void MESetEcal::fill(EcalDQMSetupObjects const edso,
                       EcalElectronicsId const &_id,
                       double _x /* = 1.*/,
                       double _wy /* = 1.*/,
                       double _w /* = 1.*/) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    fill_(iME, _x, _wy, _w);
  }

  void MESetEcal::fill(
      EcalDQMSetupObjects const edso, int _dcctccid, double _x /* = 1.*/, double _wy /* = 1.*/, double _w /* = 1.*/) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    fill_(iME, _x, _wy, _w);
  }

  void MESetEcal::fill(EcalDQMSetupObjects const edso, double _x, double _wy /* = 1.*/, double _w /* = 1.*/) {
    if (!active_)
      return;

    if (mes_.size() != 1)
      return;

    fill_(0, _x, _wy, _w);
  }

  void MESetEcal::setBinContent(EcalDQMSetupObjects const edso, DetId const &_id, int _bin, double _content) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    mes_[iME]->setBinContent(_bin, _content);
  }

  void MESetEcal::setBinContent(EcalDQMSetupObjects const edso,
                                EcalElectronicsId const &_id,
                                int _bin,
                                double _content) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    mes_[iME]->setBinContent(_bin, _content);
  }

  void MESetEcal::setBinContent(EcalDQMSetupObjects const edso, int _dcctccid, int _bin, double _content) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    mes_[iME]->setBinContent(_bin, _content);
  }

  void MESetEcal::setBinError(EcalDQMSetupObjects const edso, DetId const &_id, int _bin, double _error) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    mes_[iME]->setBinError(_bin, _error);
  }

  void MESetEcal::setBinError(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, int _bin, double _error) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    mes_[iME]->setBinError(_bin, _error);
  }

  void MESetEcal::setBinError(EcalDQMSetupObjects const edso, int _dcctccid, int _bin, double _error) {
    if (!active_)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    mes_[iME]->setBinError(_bin, _error);
  }

  void MESetEcal::setBinEntries(EcalDQMSetupObjects const edso, DetId const &_id, int _bin, double _entries) {
    if (!active_)
      return;
    if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    mes_[iME]->setBinEntries(_bin, _entries);
  }

  void MESetEcal::setBinEntries(EcalDQMSetupObjects const edso,
                                EcalElectronicsId const &_id,
                                int _bin,
                                double _entries) {
    if (!active_)
      return;
    if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    mes_[iME]->setBinEntries(_bin, _entries);
  }

  void MESetEcal::setBinEntries(EcalDQMSetupObjects const edso, int _dcctccid, int _bin, double _entries) {
    if (!active_)
      return;
    if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
      return;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    mes_[iME]->setBinEntries(_bin, _entries);
  }

  double MESetEcal::getBinContent(EcalDQMSetupObjects const edso, DetId const &_id, int _bin) const {
    if (!active_)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getBinContent(_bin);
  }

  double MESetEcal::getBinContent(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, int _bin) const {
    if (!active_)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getBinContent(_bin);
  }

  double MESetEcal::getBinContent(EcalDQMSetupObjects const edso, int _dcctccid, int _bin) const {
    if (!active_)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    return mes_[iME]->getBinContent(_bin);
  }

  double MESetEcal::getBinError(EcalDQMSetupObjects const edso, DetId const &_id, int _bin) const {
    if (!active_)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getBinError(_bin);
  }

  double MESetEcal::getBinError(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, int _bin) const {
    if (!active_)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getBinError(_bin);
  }

  double MESetEcal::getBinError(EcalDQMSetupObjects const edso, int _dcctccid, int _bin) const {
    if (!active_)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    return mes_[iME]->getBinError(_bin);
  }

  double MESetEcal::getBinEntries(EcalDQMSetupObjects const edso, DetId const &_id, int _bin) const {
    if (!active_)
      return 0.;
    if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getBinEntries(_bin);
  }

  double MESetEcal::getBinEntries(EcalDQMSetupObjects const edso, EcalElectronicsId const &_id, int _bin) const {
    if (!active_)
      return 0.;
    if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getBinEntries(_bin);
  }

  double MESetEcal::getBinEntries(EcalDQMSetupObjects const edso, int _dcctccid, int _bin) const {
    if (!active_)
      return 0.;
    if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
      return 0.;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    return mes_[iME]->getBinEntries(_bin);
  }

  int MESetEcal::findBin(EcalDQMSetupObjects const edso, DetId const &_id, double _x, double _y /* = 0.*/) const {
    if (!active_)
      return -1;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getTH1()->FindBin(_x, _y);
  }

  int MESetEcal::findBin(EcalDQMSetupObjects const edso,
                         EcalElectronicsId const &_id,
                         double _x,
                         double _y /* = 0.*/) const {
    if (!active_)
      return -1;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _id));
    checkME_(iME);

    return mes_[iME]->getTH1()->FindBin(_x, _y);
  }

  int MESetEcal::findBin(EcalDQMSetupObjects const edso, int _dcctccid, double _x, double _y /* = 0.*/) const {
    if (!active_)
      return -1;

    unsigned iME(binning::findPlotIndex(edso.electronicsMap, otype_, _dcctccid, btype_));
    checkME_(iME);

    return mes_[iME]->getTH1()->FindBin(_x, _y);
  }

  bool MESetEcal::isVariableBinning() const {
    return (xaxis_ && !xaxis_->edges.empty()) || (yaxis_ && !yaxis_->edges.empty()) ||
           (zaxis_ && !zaxis_->edges.empty());
  }

  std::vector<std::string> MESetEcal::generatePaths(EcalElectronicsMapping const *electronicsMap) const {
    using namespace std;

    vector<string> paths(0);

    unsigned nME(binning::getNObjects(otype_));

    for (unsigned iME(0); iME < nME; iME++) {
      binning::ObjectType obj(binning::getObject(otype_, iME));

      string path(path_);
      map<string, string> replacements;

      switch (obj) {
        case binning::kEB:
        case binning::kEBMEM:
          replacements["subdet"] = "EcalBarrel";
          replacements["prefix"] = "EB";
          replacements["suffix"] = "";
          replacements["subdetshort"] = "EB";
          replacements["subdetshortsig"] = "EB";
          replacements["supercrystal"] = "trigger tower";
          break;
        case binning::kEE:
        case binning::kEEMEM:
          replacements["subdet"] = "EcalEndcap";
          replacements["prefix"] = "EE";
          replacements["subdetshort"] = "EE";
          replacements["subdetshortsig"] = "EE";
          replacements["supercrystal"] = "super crystal";
          break;
        case binning::kEEm:
          replacements["subdet"] = "EcalEndcap";
          replacements["prefix"] = "EE";
          replacements["suffix"] = " EE -";
          replacements["subdetshort"] = "EE";
          replacements["subdetshortsig"] = "EEM";
          replacements["supercrystal"] = "super crystal";
          break;
        case binning::kEEp:
          replacements["subdet"] = "EcalEndcap";
          replacements["prefix"] = "EE";
          replacements["suffix"] = " EE +";
          replacements["subdetshort"] = "EE";
          replacements["subdetshortsig"] = "EEP";
          replacements["supercrystal"] = "super crystal";
          break;
        case binning::kSM:
          if (iME <= kEEmHigh || iME >= kEEpLow) {
            replacements["subdet"] = "EcalEndcap";
            replacements["prefix"] = "EE";
            replacements["supercrystal"] = "super crystal";
          } else {
            replacements["subdet"] = "EcalBarrel";
            replacements["prefix"] = "EB";
            replacements["supercrystal"] = "trigger tower";
          }
          replacements["sm"] = binning::channelName(electronicsMap, iME + 1);
          break;
        case binning::kEBSM:
          replacements["subdet"] = "EcalBarrel";
          replacements["prefix"] = "EB";
          replacements["sm"] = binning::channelName(electronicsMap, iME + kEBmLow + 1);
          replacements["supercrystal"] = "trigger tower";
          break;
        case binning::kEESM:
          replacements["subdet"] = "EcalEndcap";
          replacements["prefix"] = "EE";
          replacements["sm"] = binning::channelName(electronicsMap, iME <= kEEmHigh ? iME + 1 : iME + 37);
          replacements["supercrystal"] = "super crystal";
          break;
        case binning::kSMMEM: {
          unsigned iDCC(memDCCId(iME) - 1);
          // dccId(unsigned) skips DCCs without MEM
          if (iDCC <= kEEmHigh || iDCC >= kEEpLow) {
            replacements["subdet"] = "EcalEndcap";
            replacements["prefix"] = "EE";
          } else {
            replacements["subdet"] = "EcalBarrel";
            replacements["prefix"] = "EB";
          }
          replacements["sm"] = binning::channelName(electronicsMap, iDCC + 1);
        } break;
        case binning::kEBSMMEM: {
          unsigned iDCC(memDCCId(iME + 4) - 1);
          replacements["subdet"] = "EcalBarrel";
          replacements["prefix"] = "EB";
          replacements["sm"] = binning::channelName(electronicsMap, iDCC + 1);
        } break;
        case binning::kEESMMEM: {
          unsigned iDCC(memDCCId(iME < 4 ? iME : iME + 36) - 1);
          replacements["subdet"] = "EcalEndcap";
          replacements["prefix"] = "EE";
          replacements["sm"] = binning::channelName(electronicsMap, iDCC + 1);
        }
        default:
          break;
      }

      paths.push_back(formPath(replacements));
    }

    return paths;
  }
}  // namespace ecaldqm