Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:01

0001 #include "DQM/L1TMonitorClient/interface/L1TStage2RatioClient.h"
0002 
0003 L1TStage2RatioClient::L1TStage2RatioClient(const edm::ParameterSet& ps)
0004     : monitorDir_(ps.getUntrackedParameter<std::string>("monitorDir")),
0005       inputNum_(ps.getUntrackedParameter<std::string>("inputNum")),
0006       inputDen_(ps.getUntrackedParameter<std::string>("inputDen")),
0007       ratioName_(ps.getUntrackedParameter<std::string>("ratioName")),
0008       ratioTitle_(ps.getUntrackedParameter<std::string>("ratioTitle")),
0009       yAxisTitle_(ps.getUntrackedParameter<std::string>("yAxisTitle")),
0010       binomialErr_(ps.getUntrackedParameter<bool>("binomialErr")),
0011       ignoreBin_(ps.getUntrackedParameter<std::vector<int>>("ignoreBin")),
0012       ratioME_(nullptr) {}
0013 
0014 L1TStage2RatioClient::~L1TStage2RatioClient() {}
0015 
0016 void L1TStage2RatioClient::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0017   edm::ParameterSetDescription desc;
0018   desc.addUntracked<std::string>("monitorDir", "")
0019       ->setComment("Target directory in the DQM file. Will be created if not existing.");
0020   desc.addUntracked<std::string>("inputNum", "")->setComment("Path to numerator histogram.");
0021   desc.addUntracked<std::string>("inputDen", "")->setComment("Path to denominator histogram.");
0022   desc.addUntracked<std::string>("ratioName", "ratio")->setComment("Ratio plot name.");
0023   desc.addUntracked<std::string>("ratioTitle", "ratio")->setComment("Ratio plot title.");
0024   desc.addUntracked<std::string>("yAxisTitle", "")->setComment("Title of y axis.");
0025   desc.addUntracked<bool>("binomialErr", "true")->setComment("Compute binomial errors.");
0026   desc.addUntracked<std::vector<int>>("ignoreBin", std::vector<int>())
0027       ->setComment("List of bins to ignore. Will set their ratio to 0.");
0028   descriptions.add("l1TStage2RatioClient", desc);
0029 }
0030 
0031 void L1TStage2RatioClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0032                                                  DQMStore::IGetter& igetter,
0033                                                  const edm::LuminosityBlock& lumiSeg,
0034                                                  const edm::EventSetup& c) {
0035   book(ibooker, igetter);
0036   processHistograms(igetter);
0037 }
0038 
0039 void L1TStage2RatioClient::book(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0040   // Book when called the first time. Otherwise reset the ratio histogram.
0041   if (ratioME_ == nullptr) {
0042     ibooker.setCurrentFolder(monitorDir_);
0043 
0044     // get the axis range from the numerator histogram
0045     const MonitorElement* numME_ = igetter.get(inputNum_);
0046     if (numME_) {
0047       TH1F* hNum = numME_->getTH1F();
0048 
0049       ratioME_ = ibooker.book1D(
0050           ratioName_, ratioTitle_, hNum->GetNbinsX(), hNum->GetXaxis()->GetXmin(), hNum->GetXaxis()->GetXmax());
0051       ratioME_->setEfficiencyFlag();
0052       ratioME_->setAxisTitle(yAxisTitle_, 2);
0053     }
0054   } else {
0055     ratioME_->Reset();
0056   }
0057 }
0058 
0059 void L1TStage2RatioClient::processHistograms(DQMStore::IGetter& igetter) {
0060   const MonitorElement* numME_ = igetter.get(inputNum_);
0061   const MonitorElement* denME_ = igetter.get(inputDen_);
0062 
0063   if (numME_ && denME_) {
0064     TH1F* hNum = numME_->getTH1F();
0065     TH1F* hDen = dynamic_cast<TH1F*>(denME_->getTH1F()->Clone("den"));
0066 
0067     TH1F* hRatio = ratioME_->getTH1F();
0068 
0069     // Set the axis labels the same as the numerator histogram to be able to divide
0070     if (hNum->GetXaxis()->IsAlphanumeric()) {
0071       for (int i = 1; i <= hNum->GetNbinsX(); ++i) {
0072         hDen->GetXaxis()->SetBinLabel(i, hNum->GetXaxis()->GetBinLabel(i));
0073         hRatio->GetXaxis()->SetBinLabel(i, hNum->GetXaxis()->GetBinLabel(i));
0074       }
0075     }
0076 
0077     std::string errOption;
0078     if (binomialErr_) {
0079       errOption = "B";
0080     }
0081 
0082     hRatio->Divide(hNum, hDen, 1, 1, errOption.c_str());
0083 
0084     // Set the ratio to 0 for those bins that need to be ignored
0085     for (const int& bin : ignoreBin_) {
0086       if (bin > 0 && bin <= hRatio->GetNbinsX()) {
0087         hRatio->SetBinContent(bin, 0.0);
0088         hRatio->GetXaxis()->SetBinLabel(bin, "Ignored");
0089       }
0090     }
0091 
0092     delete hDen;
0093   }
0094 }
0095 
0096 void L1TStage2RatioClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0097   book(ibooker, igetter);
0098   processHistograms(igetter);
0099 }