Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalCommon/interface/MESetNonObject.h"
0002 
0003 namespace ecaldqm {
0004   MESetNonObject::MESetNonObject(std::string const &_fullPath,
0005                                  binning::ObjectType _otype,
0006                                  binning::BinningType _btype,
0007                                  MonitorElement::Kind _kind,
0008                                  binning::AxisSpecs const *_xaxis /* = 0*/,
0009                                  binning::AxisSpecs const *_yaxis /* = 0*/,
0010                                  binning::AxisSpecs const *_zaxis /* = 0*/)
0011       : MESet(_fullPath, _otype, _btype, _kind),
0012         xaxis_(_xaxis ? new binning::AxisSpecs(*_xaxis) : nullptr),
0013         yaxis_(_yaxis ? new binning::AxisSpecs(*_yaxis) : nullptr),
0014         zaxis_(_zaxis ? new binning::AxisSpecs(*_zaxis) : nullptr) {}
0015 
0016   MESetNonObject::MESetNonObject(MESetNonObject const &_orig)
0017       : MESet(_orig),
0018         xaxis_(_orig.xaxis_ ? new binning::AxisSpecs(*_orig.xaxis_) : nullptr),
0019         yaxis_(_orig.yaxis_ ? new binning::AxisSpecs(*_orig.yaxis_) : nullptr),
0020         zaxis_(_orig.zaxis_ ? new binning::AxisSpecs(*_orig.zaxis_) : nullptr) {}
0021 
0022   MESetNonObject::~MESetNonObject() {
0023     delete xaxis_;
0024     delete yaxis_;
0025     delete zaxis_;
0026   }
0027 
0028   MESet &MESetNonObject::operator=(MESet const &_rhs) {
0029     delete xaxis_;
0030     delete yaxis_;
0031     delete zaxis_;
0032     xaxis_ = nullptr;
0033     yaxis_ = nullptr;
0034     zaxis_ = nullptr;
0035 
0036     MESetNonObject const *pRhs(dynamic_cast<MESetNonObject const *>(&_rhs));
0037     if (pRhs) {
0038       if (pRhs->xaxis_)
0039         xaxis_ = new binning::AxisSpecs(*pRhs->xaxis_);
0040       if (pRhs->yaxis_)
0041         yaxis_ = new binning::AxisSpecs(*pRhs->yaxis_);
0042       if (pRhs->zaxis_)
0043         zaxis_ = new binning::AxisSpecs(*pRhs->zaxis_);
0044     }
0045     return MESet::operator=(_rhs);
0046   }
0047 
0048   MESet *MESetNonObject::clone(std::string const &_path /* = ""*/) const {
0049     std::string path(path_);
0050     if (!_path.empty())
0051       path_ = _path;
0052     MESet *copy(new MESetNonObject(*this));
0053     path_ = path;
0054     return copy;
0055   }
0056 
0057   void MESetNonObject::book(DQMStore::IBooker &_ibooker, EcalElectronicsMapping const *electronicsMap) {
0058     using namespace std;
0059 
0060     clear();
0061 
0062     if (path_.find('%') != string::npos)
0063       throw_("book() called with incompletely formed path");
0064 
0065     size_t slashPos(path_.find_last_of('/'));
0066     string name(path_.substr(slashPos + 1));
0067     _ibooker.setCurrentFolder(path_.substr(0, slashPos));
0068     auto oldscope = MonitorElementData::Scope::RUN;
0069     if (lumiFlag_)
0070       oldscope = _ibooker.setScope(MonitorElementData::Scope::LUMI);
0071 
0072     MonitorElement *me(nullptr);
0073 
0074     switch (kind_) {
0075       case MonitorElement::Kind::REAL:
0076         me = _ibooker.bookFloat(name);
0077         break;
0078 
0079       case MonitorElement::Kind::TH1F: {
0080         if (!xaxis_)
0081           throw_("No xaxis found for MESetNonObject");
0082 
0083         if (xaxis_->edges.empty())
0084           me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high);
0085         else
0086           me = _ibooker.book1D(name, name, xaxis_->nbins, &(xaxis_->edges[0]));
0087       } break;
0088 
0089       case MonitorElement::Kind::TPROFILE: {
0090         if (!xaxis_)
0091           throw_("No xaxis found for MESetNonObject");
0092 
0093         double ylow, yhigh;
0094         if (!yaxis_) {
0095           ylow = -numeric_limits<double>::max();
0096           yhigh = numeric_limits<double>::max();
0097         } else {
0098           ylow = yaxis_->low;
0099           yhigh = yaxis_->high;
0100         }
0101         if (xaxis_->edges.empty()) {
0102           me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, "");
0103         } else {
0104           // DQMStore bookProfile interface uses double* for bin edges
0105           double *edges(new double[xaxis_->nbins + 1]);
0106           std::copy(xaxis_->edges.begin(), xaxis_->edges.end(), edges);
0107           me = _ibooker.bookProfile(name, name, xaxis_->nbins, edges, ylow, yhigh, "");
0108           delete[] edges;
0109         }
0110       } break;
0111 
0112       case MonitorElement::Kind::TH2F: {
0113         if (!xaxis_ || !yaxis_)
0114           throw_("No x/yaxis found for MESetNonObject");
0115 
0116         if (xaxis_->edges.empty() && yaxis_->edges.empty())  // unlike MESetEcal, if either of X or Y is not set as
0117                                                              // variable, binning will be fixed
0118           me = _ibooker.book2D(
0119               name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high);
0120         else
0121           me = _ibooker.book2D(name, name, xaxis_->nbins, &(xaxis_->edges[0]), yaxis_->nbins, &(yaxis_->edges[0]));
0122       } break;
0123 
0124       case MonitorElement::Kind::TPROFILE2D: {
0125         if (!xaxis_ || !yaxis_)
0126           throw_("No x/yaxis found for MESetNonObject");
0127         if (!(xaxis_->edges.empty() && yaxis_->edges.empty()))
0128           throw_("Variable bin size for 2D profile not implemented");
0129 
0130         double high(0.), low(0.);
0131         if (zaxis_) {
0132           low = zaxis_->low;
0133           high = zaxis_->high;
0134         } else {
0135           low = -numeric_limits<double>::max();
0136           high = numeric_limits<double>::max();
0137         }
0138 
0139         me = _ibooker.bookProfile2D(name,
0140                                     name,
0141                                     xaxis_->nbins,
0142                                     xaxis_->low,
0143                                     xaxis_->high,
0144                                     yaxis_->nbins,
0145                                     yaxis_->low,
0146                                     yaxis_->high,
0147                                     low,
0148                                     high,
0149                                     "");
0150       } break;
0151 
0152       default:
0153         throw_("Unsupported MonitorElement kind");
0154     }
0155 
0156     if (xaxis_) {
0157       me->setAxisTitle(xaxis_->title, 1);
0158       if (!xaxis_->labels.empty()) {
0159         for (int iBin(1); iBin <= xaxis_->nbins; ++iBin)
0160           me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1);
0161       }
0162     }
0163     if (yaxis_) {
0164       me->setAxisTitle(yaxis_->title, 2);
0165       if (!yaxis_->labels.empty()) {
0166         for (int iBin(1); iBin <= yaxis_->nbins; ++iBin)
0167           me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2);
0168       }
0169     }
0170     if (zaxis_) {
0171       me->setAxisTitle(zaxis_->title, 3);
0172       if (!zaxis_->labels.empty()) {
0173         for (int iBin(1); iBin <= zaxis_->nbins; ++iBin)
0174           me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3);
0175       }
0176     }
0177 
0178     if (lumiFlag_)
0179       _ibooker.setScope(oldscope);
0180 
0181     mes_.push_back(me);
0182 
0183     active_ = true;
0184   }
0185 
0186   bool MESetNonObject::retrieve(EcalElectronicsMapping const *electronicsMap,
0187                                 DQMStore::IGetter &_igetter,
0188                                 std::string *_failedPath /* = 0*/) const {
0189     mes_.clear();
0190 
0191     MonitorElement *me(_igetter.get(path_));
0192     if (!me) {
0193       if (_failedPath)
0194         *_failedPath = path_;
0195       return false;
0196     }
0197 
0198     mes_.push_back(me);
0199 
0200     active_ = true;
0201     return true;
0202   }
0203 
0204   void MESetNonObject::fill(EcalDQMSetupObjects const edso, double _x, double _wy /* = 1.*/, double _w /* = 1.*/) {
0205     if (!active_)
0206       return;
0207 
0208     if (mes_.empty() || !mes_[0])
0209       return;
0210 
0211     switch (kind_) {
0212       case MonitorElement::Kind::REAL:
0213         mes_[0]->Fill(_x);
0214         break;
0215       case MonitorElement::Kind::TH1F:
0216       case MonitorElement::Kind::TPROFILE:
0217         mes_[0]->Fill(_x, _wy);
0218         break;
0219       case MonitorElement::Kind::TH2F:
0220       case MonitorElement::Kind::TPROFILE2D:
0221         mes_[0]->Fill(_x, _wy, _w);
0222         break;
0223       default:
0224         break;
0225     }
0226   }
0227 
0228   void MESetNonObject::setBinContent(EcalDQMSetupObjects const edso, int _bin, double _content) {
0229     if (!active_)
0230       return;
0231     if (kind_ == MonitorElement::Kind::REAL)
0232       return;
0233 
0234     if (mes_.empty() || !mes_[0])
0235       return;
0236 
0237     mes_[0]->setBinContent(_bin, _content);
0238   }
0239 
0240   void MESetNonObject::setBinError(EcalDQMSetupObjects const edso, int _bin, double _error) {
0241     if (!active_)
0242       return;
0243     if (kind_ == MonitorElement::Kind::REAL)
0244       return;
0245 
0246     if (mes_.empty() || !mes_[0])
0247       return;
0248 
0249     mes_[0]->setBinError(_bin, _error);
0250   }
0251 
0252   void MESetNonObject::setBinEntries(EcalDQMSetupObjects const edso, int _bin, double _entries) {
0253     if (!active_)
0254       return;
0255     if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
0256       return;
0257 
0258     if (mes_.empty() || !mes_[0])
0259       return;
0260 
0261     mes_[0]->setBinEntries(_bin, _entries);
0262   }
0263 
0264   double MESetNonObject::getBinContent(EcalDQMSetupObjects const edso, int _bin, int) const {
0265     if (!active_)
0266       return 0.;
0267     if (kind_ == MonitorElement::Kind::REAL)
0268       return 0.;
0269 
0270     if (mes_.empty() || !mes_[0])
0271       return 0.;
0272 
0273     return mes_[0]->getBinContent(_bin);
0274   }
0275 
0276   double MESetNonObject::getFloatValue() const {
0277     if (kind_ == MonitorElement::Kind::REAL)
0278       return mes_[0]->getFloatValue();
0279     else
0280       return 0.;
0281   }
0282 
0283   double MESetNonObject::getBinError(EcalDQMSetupObjects const edso, int _bin, int) const {
0284     if (!active_)
0285       return 0.;
0286     if (kind_ == MonitorElement::Kind::REAL)
0287       return 0.;
0288 
0289     if (mes_.empty() || !mes_[0])
0290       return 0.;
0291 
0292     return mes_[0]->getBinError(_bin);
0293   }
0294 
0295   double MESetNonObject::getBinEntries(EcalDQMSetupObjects const edso, int _bin, int) const {
0296     if (!active_)
0297       return 0.;
0298     if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
0299       return 0.;
0300 
0301     if (mes_.empty() || !mes_[0])
0302       return 0.;
0303 
0304     return mes_[0]->getBinEntries(_bin);
0305   }
0306 
0307   int MESetNonObject::findBin(EcalDQMSetupObjects const edso, double _x, double _y /* = 0.*/) const {
0308     if (!active_)
0309       return 0;
0310 
0311     if (mes_.empty() || !mes_[0])
0312       return 0;
0313 
0314     if (kind_ == MonitorElement::Kind::TH1F || kind_ == MonitorElement::Kind::TPROFILE)
0315       return mes_[0]->getTH1()->FindBin(_x);
0316     else if (kind_ == MonitorElement::Kind::TH2F || kind_ == MonitorElement::Kind::TPROFILE2D)
0317       return mes_[0]->getTH1()->FindBin(_x, _y);
0318     else
0319       return 0;
0320   }
0321 
0322   bool MESetNonObject::isVariableBinning() const {
0323     return (xaxis_ && (!xaxis_->edges.empty())) || (yaxis_ && (!yaxis_->edges.empty())) ||
0324            (zaxis_ && (!zaxis_->edges.empty()));
0325   }
0326 }  // namespace ecaldqm