00001 #include "DQM/EcalCommon/interface/MESet.h"
00002
00003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00004
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/Utilities/interface/Exception.h"
00007
00008 #include "TString.h"
00009 #include "TPRegexp.h"
00010
00011 namespace ecaldqm
00012 {
00013 BinService const* MESet::binService_(0);
00014 DQMStore* MESet::dqmStore_(0);
00015
00016 MESet::MESet(std::string const& _fullpath, MEData const& _data, bool _readOnly) :
00017 mes_(0),
00018 dir_(_fullpath.substr(0, _fullpath.find_last_of('/'))),
00019 name_(_fullpath.substr(_fullpath.find_last_of('/') + 1)),
00020 data_(&_data),
00021 active_(false),
00022 readOnly_(_readOnly)
00023 {
00024 if (!binService_) {
00025 binService_ = &(*(edm::Service<EcalDQMBinningService>()));
00026 if(!binService_)
00027 throw cms::Exception("Service") << "EcalDQMBinningService not found" << std::endl;
00028 }
00029
00030 if (!dqmStore_) {
00031 dqmStore_ = &(*(edm::Service<DQMStore>()));
00032 if(!dqmStore_)
00033 throw cms::Exception("Service") << "DQMStore not found" << std::endl;
00034 }
00035
00036
00037 if(_fullpath.size() == 0)
00038 throw cms::Exception("InvalidConfiguration") << "MonitorElement path empty";
00039 }
00040
00041 MESet::~MESet()
00042 {
00043 }
00044
00045 void
00046 MESet::book()
00047 {
00048 clear();
00049 active_ = true;
00050 }
00051
00052 bool
00053 MESet::retrieve() const
00054 {
00055 return false;
00056 }
00057
00058 void
00059 MESet::clear() const
00060 {
00061 active_ = false;
00062 mes_.clear();
00063 }
00064
00065 void
00066 MESet::setAxisTitle(std::string const& _title, int _axis)
00067 {
00068 for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr)
00069 (*meItr)->setAxisTitle(_title, _axis);
00070 }
00071
00072 void
00073 MESet::setBinLabel(unsigned _offset, int _bin, std::string const& _label, int _axis)
00074 {
00075 if(_offset == unsigned(-1)){
00076 for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr)
00077 (*meItr)->setBinLabel(_bin, _label, _axis);
00078
00079 return;
00080 }
00081
00082 if(_offset >= mes_.size() || !mes_[_offset]) return;
00083 mes_[_offset]->setBinLabel(_bin, _label, _axis);
00084 }
00085
00086 void
00087 MESet::reset(double _content, double _err, double _entries)
00088 {
00089 resetAll(_content, _err, _entries);
00090 }
00091
00092 void
00093 MESet::resetAll(double _content, double _err, double _entries)
00094 {
00095 if(data_->kind == MonitorElement::DQM_KIND_REAL){
00096 for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr)
00097 (*meItr)->Fill(_content);
00098 return;
00099 }
00100
00101 bool simple(true);
00102 if(_content != 0. || _err != 0. || _entries != 0.) simple = false;
00103
00104 for(std::vector<MonitorElement*>::iterator meItr(mes_.begin()); meItr != mes_.end(); ++meItr){
00105 TH1* h((*meItr)->getTH1());
00106 h->Reset();
00107 if(simple) continue;
00108
00109 int nbinsX(h->GetNbinsX());
00110 int nbinsY(h->GetNbinsY());
00111 double entries(0.);
00112 for(int ix(1); ix <= nbinsX; ix++){
00113 for(int iy(1); iy <= nbinsY; iy++){
00114 int bin(h->GetBin(ix, iy));
00115 h->SetBinContent(bin, _content);
00116 h->SetBinError(bin, _err);
00117 if(data_->kind == MonitorElement::DQM_KIND_TPROFILE){
00118 static_cast<TProfile*>(h)->SetBinEntries(bin, _entries);
00119 entries += _entries;
00120 }
00121 else if(data_->kind == MonitorElement::DQM_KIND_TPROFILE2D){
00122 static_cast<TProfile2D*>(h)->SetBinEntries(bin, _entries);
00123 entries += _entries;
00124 }
00125 }
00126 }
00127 if(entries == 0.) entries = _entries;
00128 h->SetEntries(_entries);
00129 }
00130 }
00131
00132 void
00133 MESet::fill(DetId const&, double, double, double)
00134 {
00135 }
00136
00137 void
00138 MESet::fill(EcalElectronicsId const& _id, double _wx,double _wy, double _w)
00139 {
00140 fill(getElectronicsMap()->getDetId(_id), _wx, _wy, _w);
00141 }
00142
00143 void
00144 MESet::fill(unsigned _dcctccid, double _wx, double _wy, double _w)
00145 {
00146 }
00147
00148 void
00149 MESet::fill(double, double, double)
00150 {
00151 }
00152
00153 void
00154 MESet::setBinContent(DetId const&, double, double)
00155 {
00156 }
00157
00158 void
00159 MESet::setBinContent(EcalElectronicsId const& _id, double _content, double _err)
00160 {
00161 setBinContent(getElectronicsMap()->getDetId(_id), _content, _err);
00162 }
00163
00164 void
00165 MESet::setBinContent(unsigned, double, double)
00166 {
00167 }
00168
00169 void
00170 MESet::setBinEntries(DetId const&, double)
00171 {
00172 }
00173
00174 void
00175 MESet::setBinEntries(EcalElectronicsId const& _id, double _entries)
00176 {
00177 setBinEntries(getElectronicsMap()->getDetId(_id), _entries);
00178 }
00179
00180 void
00181 MESet::setBinEntries(unsigned, double)
00182 {
00183 }
00184
00185 double
00186 MESet::getBinContent(DetId const&, int) const
00187 {
00188 return 0.;
00189 }
00190
00191 double
00192 MESet::getBinContent(EcalElectronicsId const& _id, int _bin) const
00193 {
00194 return getBinContent(getElectronicsMap()->getDetId(_id), _bin);
00195 }
00196
00197 double
00198 MESet::getBinContent(unsigned, int) const
00199 {
00200 return 0.;
00201 }
00202
00203 double
00204 MESet::getBinError(DetId const&, int) const
00205 {
00206 return 0.;
00207 }
00208
00209 double
00210 MESet::getBinError(EcalElectronicsId const& _id, int _bin) const
00211 {
00212 return getBinError(getElectronicsMap()->getDetId(_id), _bin);
00213 }
00214
00215 double
00216 MESet::getBinError(unsigned, int) const
00217 {
00218 return 0.;
00219 }
00220
00221 double
00222 MESet::getBinEntries(DetId const&, int) const
00223 {
00224 return 0.;
00225 }
00226
00227 double
00228 MESet::getBinEntries(EcalElectronicsId const& _id, int _bin) const
00229 {
00230 return getBinEntries(getElectronicsMap()->getDetId(_id), _bin);
00231 }
00232
00233 double
00234 MESet::getBinEntries(unsigned, int) const
00235 {
00236 return 0.;
00237 }
00238
00239 void
00240 MESet::name(std::map<std::string, std::string> const& _replacements) const
00241 {
00242 TString dir(dir_);
00243 TString name(name_);
00244
00245 for(std::map<std::string, std::string>::const_iterator repItr(_replacements.begin()); repItr != _replacements.end(); ++repItr){
00246
00247 TString pattern("\\%\\(");
00248 pattern += repItr->first;
00249 pattern += "\\)s";
00250
00251 TPRegexp re(pattern);
00252
00253 re.Substitute(dir, repItr->second, "g");
00254 re.Substitute(name, repItr->second, "g");
00255 }
00256
00257 dir_ = dir.Data();
00258 name_ = name.Data();
00259 }
00260
00261 void
00262 MESet::fill_(unsigned _index, int _bin, double _w)
00263 {
00264 MonitorElement* me(mes_.at(_index));
00265
00266 TH1* h(me->getTH1());
00267
00268 int nbinsX(h->GetNbinsX());
00269
00270 double x(h->GetXaxis()->GetBinCenter((_bin - 1) % nbinsX + 1));
00271
00272 if((data_->kind < MonitorElement::DQM_KIND_TH2F && data_->kind >= MonitorElement::DQM_KIND_TH1F) || data_->kind == MonitorElement::DQM_KIND_TPROFILE) {
00273 me->Fill(x, _w);
00274 return;
00275 }
00276
00277 double y(h->GetYaxis()->GetBinCenter((_bin - 1) / nbinsX + 1));
00278
00279 me->Fill(x, y, _w);
00280 }
00281
00282 void
00283 MESet::fill_(unsigned _offset, double _x, double _wy, double _w)
00284 {
00285 if(data_->kind == MonitorElement::DQM_KIND_REAL)
00286 mes_.at(_offset)->Fill(_x);
00287 else if(data_->kind < MonitorElement::DQM_KIND_TH2F || data_->kind == MonitorElement::DQM_KIND_TPROFILE)
00288 mes_.at(_offset)->Fill(_x, _wy);
00289 else
00290 mes_.at(_offset)->Fill(_x, _wy, _w);
00291 }
00292
00293 void
00294 MESet::setBinContent_(unsigned _index, int _bin, double _content, double _err)
00295 {
00296 MonitorElement* me(mes_.at(_index));
00297
00298 if(data_->kind < MonitorElement::DQM_KIND_TH2F || data_->kind == MonitorElement::DQM_KIND_TPROFILE){
00299 me->setBinContent(_bin, _content);
00300 me->setBinError(_bin, _err);
00301 }
00302 else{
00303 TH1* h(me->getTH1());
00304 int nbinsX(h->GetNbinsX());
00305 int ix((_bin - 1) % nbinsX + 1);
00306 int iy((_bin - 1) / nbinsX + 1);
00307 me->setBinContent(ix, iy, _content);
00308 me->setBinError(ix, iy, _err);
00309 }
00310 }
00311
00312 void
00313 MESet::setBinEntries_(unsigned _index, int _bin, double _entries)
00314 {
00315 MonitorElement* me(mes_.at(_index));
00316
00317 if(data_->kind == MonitorElement::DQM_KIND_TPROFILE){
00318 me->setBinEntries(_bin, _entries);
00319 }
00320 else if(data_->kind == MonitorElement::DQM_KIND_TPROFILE2D){
00321 TH1* h(me->getTH1());
00322 int nbinsX(h->GetNbinsX());
00323 int ix((_bin - 1) % nbinsX + 1);
00324 int iy((_bin - 1) / nbinsX + 1);
00325 me->setBinEntries(h->GetBin(ix, iy), _entries);
00326 }
00327 }
00328
00329 double
00330 MESet::getBinContent_(unsigned _index, int _bin) const
00331 {
00332 MonitorElement* me(mes_.at(_index));
00333
00334 if(data_->kind < MonitorElement::DQM_KIND_TH2F || data_->kind == MonitorElement::DQM_KIND_TPROFILE)
00335 return me->getBinContent(_bin);
00336 else{
00337 TH1* h(me->getTH1());
00338 int nbinsX(h->GetNbinsX());
00339 int ix((_bin - 1) % nbinsX + 1);
00340 int iy((_bin - 1) / nbinsX + 1);
00341 return h->GetBinContent(ix, iy);
00342 }
00343 }
00344
00345 double
00346 MESet::getBinError_(unsigned _index, int _bin) const
00347 {
00348 MonitorElement* me(mes_.at(_index));
00349
00350 if(data_->kind < MonitorElement::DQM_KIND_TH2F || data_->kind == MonitorElement::DQM_KIND_TPROFILE)
00351 return me->getBinError(_bin);
00352 else{
00353 TH1* h(me->getTH1());
00354 int nbinsX(h->GetNbinsX());
00355 int ix((_bin - 1) % nbinsX + 1);
00356 int iy((_bin - 1) / nbinsX + 1);
00357 return h->GetBinError(ix, iy);
00358 }
00359 }
00360
00361 double
00362 MESet::getBinEntries_(unsigned _index, int _bin) const
00363 {
00364 MonitorElement* me(mes_.at(_index));
00365
00366 switch(data_->kind){
00367 case MonitorElement::DQM_KIND_TH1F:
00368 return me->getBinContent(_bin);
00369 case MonitorElement::DQM_KIND_TPROFILE:
00370 return me->getBinEntries(_bin);
00371 case MonitorElement::DQM_KIND_TH2F:
00372 {
00373 TH1* h(me->getTH1());
00374 int nbinsX(h->GetNbinsX());
00375 int ix((_bin - 1) % nbinsX + 1);
00376 int iy((_bin - 1) / nbinsX + 1);
00377 int bin(h->GetBin(ix, iy));
00378 return me->getBinContent(bin);
00379 }
00380 case MonitorElement::DQM_KIND_TPROFILE2D:
00381 {
00382 TH1* h(me->getTH1());
00383 int nbinsX(h->GetNbinsX());
00384 int ix((_bin - 1) % nbinsX + 1);
00385 int iy((_bin - 1) / nbinsX + 1);
00386 int bin(h->GetBin(ix, iy));
00387 return me->getBinEntries(bin);
00388 }
00389 default:
00390 return 0.;
00391 }
00392 }
00393
00394 }