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
#include "DQM/EcalCommon/interface/MESetNonObject.h"

namespace ecaldqm {
  MESetNonObject::MESetNonObject(std::string const &_fullPath,
                                 binning::ObjectType _otype,
                                 binning::BinningType _btype,
                                 MonitorElement::Kind _kind,
                                 binning::AxisSpecs const *_xaxis /* = 0*/,
                                 binning::AxisSpecs const *_yaxis /* = 0*/,
                                 binning::AxisSpecs const *_zaxis /* = 0*/)
      : MESet(_fullPath, _otype, _btype, _kind),
        xaxis_(_xaxis ? new binning::AxisSpecs(*_xaxis) : nullptr),
        yaxis_(_yaxis ? new binning::AxisSpecs(*_yaxis) : nullptr),
        zaxis_(_zaxis ? new binning::AxisSpecs(*_zaxis) : nullptr) {}

  MESetNonObject::MESetNonObject(MESetNonObject const &_orig)
      : MESet(_orig),
        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) {}

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

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

    MESetNonObject const *pRhs(dynamic_cast<MESetNonObject const *>(&_rhs));
    if (pRhs) {
      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 *MESetNonObject::clone(std::string const &_path /* = ""*/) const {
    std::string path(path_);
    if (!_path.empty())
      path_ = _path;
    MESet *copy(new MESetNonObject(*this));
    path_ = path;
    return copy;
  }

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

    clear();

    if (path_.find('%') != string::npos)
      throw_("book() called with incompletely formed path");

    size_t slashPos(path_.find_last_of('/'));
    string name(path_.substr(slashPos + 1));
    _ibooker.setCurrentFolder(path_.substr(0, slashPos));
    auto oldscope = MonitorElementData::Scope::RUN;
    if (lumiFlag_)
      oldscope = _ibooker.setScope(MonitorElementData::Scope::LUMI);

    MonitorElement *me(nullptr);

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

      case MonitorElement::Kind::TH1F: {
        if (!xaxis_)
          throw_("No xaxis found for MESetNonObject");

        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_)
          throw_("No xaxis found for MESetNonObject");

        double ylow, yhigh;
        if (!yaxis_) {
          ylow = -numeric_limits<double>::max();
          yhigh = numeric_limits<double>::max();
        } else {
          ylow = yaxis_->low;
          yhigh = yaxis_->high;
        }
        if (xaxis_->edges.empty()) {
          me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, "");
        } 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, ylow, yhigh, "");
          delete[] edges;
        }
      } break;

      case MonitorElement::Kind::TH2F: {
        if (!xaxis_ || !yaxis_)
          throw_("No x/yaxis found for MESetNonObject");

        if (xaxis_->edges.empty() && yaxis_->edges.empty())  // unlike MESetEcal, if either of X or Y is not set as
                                                             // variable, binning will be fixed
          me = _ibooker.book2D(
              name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high);
        else
          me = _ibooker.book2D(name, name, xaxis_->nbins, &(xaxis_->edges[0]), yaxis_->nbins, &(yaxis_->edges[0]));
      } break;

      case MonitorElement::Kind::TPROFILE2D: {
        if (!xaxis_ || !yaxis_)
          throw_("No x/yaxis found for MESetNonObject");
        if (!(xaxis_->edges.empty() && yaxis_->edges.empty()))
          throw_("Variable bin size for 2D profile not implemented");

        double high(0.), low(0.);
        if (zaxis_) {
          low = zaxis_->low;
          high = zaxis_->high;
        } else {
          low = -numeric_limits<double>::max();
          high = numeric_limits<double>::max();
        }

        me = _ibooker.bookProfile2D(name,
                                    name,
                                    xaxis_->nbins,
                                    xaxis_->low,
                                    xaxis_->high,
                                    yaxis_->nbins,
                                    yaxis_->low,
                                    yaxis_->high,
                                    low,
                                    high,
                                    "");
      } break;

      default:
        throw_("Unsupported MonitorElement kind");
    }

    if (xaxis_) {
      me->setAxisTitle(xaxis_->title, 1);
      if (!xaxis_->labels.empty()) {
        for (int iBin(1); iBin <= xaxis_->nbins; ++iBin)
          me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1);
      }
    }
    if (yaxis_) {
      me->setAxisTitle(yaxis_->title, 2);
      if (!yaxis_->labels.empty()) {
        for (int iBin(1); iBin <= yaxis_->nbins; ++iBin)
          me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2);
      }
    }
    if (zaxis_) {
      me->setAxisTitle(zaxis_->title, 3);
      if (!zaxis_->labels.empty()) {
        for (int iBin(1); iBin <= zaxis_->nbins; ++iBin)
          me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3);
      }
    }

    if (lumiFlag_)
      _ibooker.setScope(oldscope);

    mes_.push_back(me);

    active_ = true;
  }

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

    MonitorElement *me(_igetter.get(path_));
    if (!me) {
      if (_failedPath)
        *_failedPath = path_;
      return false;
    }

    mes_.push_back(me);

    active_ = true;
    return true;
  }

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

    if (mes_.empty() || !mes_[0])
      return;

    switch (kind_) {
      case MonitorElement::Kind::REAL:
        mes_[0]->Fill(_x);
        break;
      case MonitorElement::Kind::TH1F:
      case MonitorElement::Kind::TPROFILE:
        mes_[0]->Fill(_x, _wy);
        break;
      case MonitorElement::Kind::TH2F:
      case MonitorElement::Kind::TPROFILE2D:
        mes_[0]->Fill(_x, _wy, _w);
        break;
      default:
        break;
    }
  }

  void MESetNonObject::setBinContent(EcalDQMSetupObjects const edso, int _bin, double _content) {
    if (!active_)
      return;
    if (kind_ == MonitorElement::Kind::REAL)
      return;

    if (mes_.empty() || !mes_[0])
      return;

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

  void MESetNonObject::setBinError(EcalDQMSetupObjects const edso, int _bin, double _error) {
    if (!active_)
      return;
    if (kind_ == MonitorElement::Kind::REAL)
      return;

    if (mes_.empty() || !mes_[0])
      return;

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

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

    if (mes_.empty() || !mes_[0])
      return;

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

  double MESetNonObject::getBinContent(EcalDQMSetupObjects const edso, int _bin, int) const {
    if (!active_)
      return 0.;
    if (kind_ == MonitorElement::Kind::REAL)
      return 0.;

    if (mes_.empty() || !mes_[0])
      return 0.;

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

  double MESetNonObject::getFloatValue() const {
    if (kind_ == MonitorElement::Kind::REAL)
      return mes_[0]->getFloatValue();
    else
      return 0.;
  }

  double MESetNonObject::getBinError(EcalDQMSetupObjects const edso, int _bin, int) const {
    if (!active_)
      return 0.;
    if (kind_ == MonitorElement::Kind::REAL)
      return 0.;

    if (mes_.empty() || !mes_[0])
      return 0.;

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

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

    if (mes_.empty() || !mes_[0])
      return 0.;

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

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

    if (mes_.empty() || !mes_[0])
      return 0;

    if (kind_ == MonitorElement::Kind::TH1F || kind_ == MonitorElement::Kind::TPROFILE)
      return mes_[0]->getTH1()->FindBin(_x);
    else if (kind_ == MonitorElement::Kind::TH2F || kind_ == MonitorElement::Kind::TPROFILE2D)
      return mes_[0]->getTH1()->FindBin(_x, _y);
    else
      return 0;
  }

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