Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-10 02:54:04

0001 /**
0002  * \file L1TEfficiencyHarvesting.cc
0003  *
0004  * \author J. Pela, C. Battilana
0005  *
0006  */
0007 
0008 // L1TMonitor includes
0009 #include "DQMOffline/L1Trigger/interface/L1TEfficiencyHarvesting.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 
0012 using namespace edm;
0013 using namespace std;
0014 
0015 namespace dqmoffline {
0016   namespace l1t {
0017     L1TEfficiencyPlotHandler::L1TEfficiencyPlotHandler(const ParameterSet &ps, std::string plotName)
0018         : numeratorDir_(ps.getUntrackedParameter<std::string>("numeratorDir")),
0019           denominatorDir_(ps.getUntrackedParameter<std::string>("denominatorDir", numeratorDir_)),
0020           outputDir_(ps.getUntrackedParameter<std::string>("outputDir", numeratorDir_)),
0021           plotName_(plotName),
0022           numeratorSuffix_(ps.getUntrackedParameter<std::string>("numeratorSuffix", "Num")),
0023           denominatorSuffix_(ps.getUntrackedParameter<std::string>("denominatorSuffix", "Den")),
0024           h_efficiency_() {}
0025 
0026     L1TEfficiencyPlotHandler::L1TEfficiencyPlotHandler(const L1TEfficiencyPlotHandler &handler)
0027         : numeratorDir_(handler.numeratorDir_),
0028           denominatorDir_(handler.denominatorDir_),
0029           outputDir_(handler.outputDir_),
0030           plotName_(handler.plotName_),
0031           numeratorSuffix_(handler.numeratorSuffix_),
0032           denominatorSuffix_(handler.denominatorSuffix_),
0033           h_efficiency_(handler.h_efficiency_) {}
0034 
0035     void L1TEfficiencyPlotHandler::book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) {
0036       edm::LogInfo("L1TEfficiencyPlotHandler")
0037           << "Booking efficiency histogram for " << outputDir_ << " and " << plotName_ << endl;
0038 
0039       std::string numeratorName = numeratorDir_ + "/" + plotName_ + numeratorSuffix_;
0040       std::string denominatorName = denominatorDir_ + "/" + plotName_ + denominatorSuffix_;
0041       MonitorElement *num = igetter.get(numeratorName);
0042       MonitorElement *den = igetter.get(denominatorName);
0043 
0044       if (!num || !den) {
0045         edm::LogWarning("L1TEfficiencyPlotHandler") << (!num && !den ? numeratorName + " && " + denominatorName
0046                                                         : !num       ? numeratorName
0047                                                                      : denominatorName)
0048                                                     << " not gettable. Quitting booking" << endl;
0049         return;
0050       }
0051 
0052       TH1 *numH = num->getTH1();
0053       TH1 *denH = den->getTH1();
0054 
0055       if (!numH || !denH) {
0056         edm::LogWarning("L1TEfficiencyPlotHandler") << (!numH && !denH ? numeratorName + " && " + denominatorName
0057                                                         : !num         ? numeratorName
0058                                                                        : denominatorName)
0059                                                     << " is not TH1F. Quitting booking" << endl;
0060 
0061         return;
0062       }
0063 
0064       if (numH->GetNbinsX() != denH->GetNbinsX()) {
0065         edm::LogWarning("L1TEfficiencyPlotHandler") << " # X bins in " << numeratorName << " and " << denominatorName
0066                                                     << " are different. Quitting booking" << endl;
0067         return;
0068       }
0069 
0070       MonitorElement::Kind kind = num->kind();
0071       bool is1D = kind == MonitorElement::Kind::TH1F || kind == MonitorElement::Kind::TH1D;
0072       bool is2D = kind == MonitorElement::Kind::TH2F || kind == MonitorElement::Kind::TH2D;
0073 
0074       if (is2D) {
0075         if (numH->GetNbinsY() != denH->GetNbinsY()) {
0076           edm::LogWarning("L1TEfficiencyPlotHandler") << " # Y bins in " << numeratorName << " and " << denominatorName
0077                                                       << " are different. Quitting booking" << endl;
0078           return;
0079         }
0080       }
0081 
0082       ibooker.setCurrentFolder(outputDir_);
0083       if (is1D) {
0084         h_efficiency_ = ibooker.book1D(plotName_, den->getTH1F());
0085       } else if (is2D) {
0086         h_efficiency_ = ibooker.book2D(plotName_, den->getTH2F());
0087       }
0088       h_efficiency_->setEfficiencyFlag();
0089     }
0090 
0091     void L1TEfficiencyPlotHandler::computeEfficiency(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) {
0092       if (!h_efficiency_)
0093         return;
0094 
0095       edm::LogInfo("L1TEfficiencyPlotHandler") << " Computing efficiency for " << plotName_ << endl;
0096 
0097       MonitorElement *num = igetter.get(numeratorDir_ + "/" + plotName_ + numeratorSuffix_);
0098       MonitorElement *den = igetter.get(denominatorDir_ + "/" + plotName_ + denominatorSuffix_);
0099 
0100       TH1 *numH = num->getTH1();
0101       TH1 *denH = den->getTH1();
0102       TH1 *effH = h_efficiency_->getTH1();
0103 
0104       effH->Divide(numH, denH, 1.0, 1.0, "B");
0105     }
0106 
0107     //___________DQM_analyzer_class________________________________________
0108     L1TEfficiencyHarvesting::L1TEfficiencyHarvesting(const ParameterSet &ps)
0109         : verbose_(ps.getUntrackedParameter<bool>("verbose")), plotHandlers_() {
0110       if (verbose_) {
0111         edm::LogInfo("L1TEfficiencyHarvesting") << "____________ Storage initialization ____________ " << endl;
0112       }
0113 
0114       for (const auto &plotConfig : ps.getUntrackedParameter<std::vector<edm::ParameterSet>>("plotCfgs")) {
0115         vector<string> plots = plotConfig.getUntrackedParameter<vector<string>>("plots");
0116         for (const auto &plot : plots) {
0117           plotHandlers_.push_back(L1TEfficiencyPlotHandler(plotConfig, plot));
0118         }
0119       }
0120     }
0121 
0122     //_____________________________________________________________________
0123     L1TEfficiencyHarvesting::~L1TEfficiencyHarvesting() {}
0124 
0125     //_____________________________________________________________________
0126     void L1TEfficiencyHarvesting::dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) {
0127       if (verbose_) {
0128         edm::LogInfo("L1TEfficiencyHarvesting") << "Called endRun." << endl;
0129       }
0130 
0131       for (auto plotHandler : plotHandlers_) {
0132         plotHandler.book(ibooker, igetter);
0133         plotHandler.computeEfficiency(ibooker, igetter);
0134       }
0135     }
0136 
0137     //define this as a plug-in
0138     DEFINE_FWK_MODULE(L1TEfficiencyHarvesting);
0139   }  // namespace l1t
0140 }  // namespace dqmoffline