File indexing completed on 2021-03-17 23:26:19
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 ,
0009 binning::AxisSpecs const *_yaxis ,
0010 binning::AxisSpecs const *_zaxis )
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)
0084 me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->edges);
0085 else
0086 me = _ibooker.book1D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high);
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) {
0102
0103 double *edges(new double[xaxis_->nbins + 1]);
0104 std::copy(xaxis_->edges, xaxis_->edges + xaxis_->nbins + 1, edges);
0105 me = _ibooker.bookProfile(name, name, xaxis_->nbins, edges, ylow, yhigh, "");
0106 delete[] edges;
0107 } else
0108 me = _ibooker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, "");
0109 } break;
0110
0111 case MonitorElement::Kind::TH2F: {
0112 if (!xaxis_ || !yaxis_)
0113 throw_("No x/yaxis found for MESetNonObject");
0114
0115 if (!xaxis_->edges || !yaxis_->edges)
0116
0117 me = _ibooker.book2D(
0118 name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high);
0119 else
0120 me = _ibooker.book2D(name, name, xaxis_->nbins, xaxis_->edges, yaxis_->nbins, yaxis_->edges);
0121 } break;
0122
0123 case MonitorElement::Kind::TPROFILE2D: {
0124 if (!xaxis_ || !yaxis_)
0125 throw_("No x/yaxis found for MESetNonObject");
0126 if (xaxis_->edges || yaxis_->edges)
0127 throw_("Variable bin size for 2D profile not implemented");
0128
0129 double high(0.), low(0.);
0130 if (zaxis_) {
0131 low = zaxis_->low;
0132 high = zaxis_->high;
0133 } else {
0134 low = -numeric_limits<double>::max();
0135 high = numeric_limits<double>::max();
0136 }
0137
0138 me = _ibooker.bookProfile2D(name,
0139 name,
0140 xaxis_->nbins,
0141 xaxis_->low,
0142 xaxis_->high,
0143 yaxis_->nbins,
0144 yaxis_->low,
0145 yaxis_->high,
0146 low,
0147 high,
0148 "");
0149 } break;
0150
0151 default:
0152 throw_("Unsupported MonitorElement kind");
0153 }
0154
0155 if (xaxis_) {
0156 me->setAxisTitle(xaxis_->title, 1);
0157 if (xaxis_->labels) {
0158 for (int iBin(1); iBin <= xaxis_->nbins; ++iBin)
0159 me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1);
0160 }
0161 }
0162 if (yaxis_) {
0163 me->setAxisTitle(yaxis_->title, 2);
0164 if (yaxis_->labels) {
0165 for (int iBin(1); iBin <= yaxis_->nbins; ++iBin)
0166 me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2);
0167 }
0168 }
0169 if (zaxis_) {
0170 me->setAxisTitle(zaxis_->title, 3);
0171 if (zaxis_->labels) {
0172 for (int iBin(1); iBin <= zaxis_->nbins; ++iBin)
0173 me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3);
0174 }
0175 }
0176
0177 if (lumiFlag_)
0178 _ibooker.setScope(oldscope);
0179
0180 mes_.push_back(me);
0181
0182 active_ = true;
0183 }
0184
0185 bool MESetNonObject::retrieve(EcalElectronicsMapping const *electronicsMap,
0186 DQMStore::IGetter &_igetter,
0187 std::string *_failedPath ) const {
0188 mes_.clear();
0189
0190 MonitorElement *me(_igetter.get(path_));
0191 if (!me) {
0192 if (_failedPath)
0193 *_failedPath = path_;
0194 return false;
0195 }
0196
0197 mes_.push_back(me);
0198
0199 active_ = true;
0200 return true;
0201 }
0202
0203 void MESetNonObject::fill(EcalDQMSetupObjects const edso, double _x, double _wy , double _w ) {
0204 if (!active_)
0205 return;
0206
0207 if (mes_.empty() || !mes_[0])
0208 return;
0209
0210 switch (kind_) {
0211 case MonitorElement::Kind::REAL:
0212 mes_[0]->Fill(_x);
0213 break;
0214 case MonitorElement::Kind::TH1F:
0215 case MonitorElement::Kind::TPROFILE:
0216 mes_[0]->Fill(_x, _wy);
0217 break;
0218 case MonitorElement::Kind::TH2F:
0219 case MonitorElement::Kind::TPROFILE2D:
0220 mes_[0]->Fill(_x, _wy, _w);
0221 break;
0222 default:
0223 break;
0224 }
0225 }
0226
0227 void MESetNonObject::setBinContent(EcalDQMSetupObjects const edso, int _bin, double _content) {
0228 if (!active_)
0229 return;
0230 if (kind_ == MonitorElement::Kind::REAL)
0231 return;
0232
0233 if (mes_.empty() || !mes_[0])
0234 return;
0235
0236 mes_[0]->setBinContent(_bin, _content);
0237 }
0238
0239 void MESetNonObject::setBinError(EcalDQMSetupObjects const edso, int _bin, double _error) {
0240 if (!active_)
0241 return;
0242 if (kind_ == MonitorElement::Kind::REAL)
0243 return;
0244
0245 if (mes_.empty() || !mes_[0])
0246 return;
0247
0248 mes_[0]->setBinError(_bin, _error);
0249 }
0250
0251 void MESetNonObject::setBinEntries(EcalDQMSetupObjects const edso, int _bin, double _entries) {
0252 if (!active_)
0253 return;
0254 if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
0255 return;
0256
0257 if (mes_.empty() || !mes_[0])
0258 return;
0259
0260 mes_[0]->setBinEntries(_bin, _entries);
0261 }
0262
0263 double MESetNonObject::getBinContent(EcalDQMSetupObjects const edso, int _bin, int) const {
0264 if (!active_)
0265 return 0.;
0266 if (kind_ == MonitorElement::Kind::REAL)
0267 return 0.;
0268
0269 if (mes_.empty() || !mes_[0])
0270 return 0.;
0271
0272 return mes_[0]->getBinContent(_bin);
0273 }
0274
0275 double MESetNonObject::getFloatValue() const {
0276 if (kind_ == MonitorElement::Kind::REAL)
0277 return mes_[0]->getFloatValue();
0278 else
0279 return 0.;
0280 }
0281
0282 double MESetNonObject::getBinError(EcalDQMSetupObjects const edso, int _bin, int) const {
0283 if (!active_)
0284 return 0.;
0285 if (kind_ == MonitorElement::Kind::REAL)
0286 return 0.;
0287
0288 if (mes_.empty() || !mes_[0])
0289 return 0.;
0290
0291 return mes_[0]->getBinError(_bin);
0292 }
0293
0294 double MESetNonObject::getBinEntries(EcalDQMSetupObjects const edso, int _bin, int) const {
0295 if (!active_)
0296 return 0.;
0297 if (kind_ != MonitorElement::Kind::TPROFILE && kind_ != MonitorElement::Kind::TPROFILE2D)
0298 return 0.;
0299
0300 if (mes_.empty() || !mes_[0])
0301 return 0.;
0302
0303 return mes_[0]->getBinEntries(_bin);
0304 }
0305
0306 int MESetNonObject::findBin(EcalDQMSetupObjects const edso, double _x, double _y ) const {
0307 if (!active_)
0308 return 0;
0309
0310 if (mes_.empty() || !mes_[0])
0311 return 0;
0312
0313 if (kind_ == MonitorElement::Kind::TH1F || kind_ == MonitorElement::Kind::TPROFILE)
0314 return mes_[0]->getTH1()->FindBin(_x);
0315 else if (kind_ == MonitorElement::Kind::TH2F || kind_ == MonitorElement::Kind::TPROFILE2D)
0316 return mes_[0]->getTH1()->FindBin(_x, _y);
0317 else
0318 return 0;
0319 }
0320
0321 bool MESetNonObject::isVariableBinning() const {
0322 return (xaxis_ && xaxis_->edges) || (yaxis_ && yaxis_->edges) || (zaxis_ && zaxis_->edges);
0323 }
0324 }