CMS 3D CMS Logo

L1TStage2RatioClient.cc
Go to the documentation of this file.
2 
4  monitorDir_(ps.getUntrackedParameter<std::string>("monitorDir")),
5  inputNum_(ps.getUntrackedParameter<std::string>("inputNum")),
6  inputDen_(ps.getUntrackedParameter<std::string>("inputDen")),
7  ratioName_(ps.getUntrackedParameter<std::string>("ratioName")),
8  ratioTitle_(ps.getUntrackedParameter<std::string>("ratioTitle")),
9  yAxisTitle_(ps.getUntrackedParameter<std::string>("yAxisTitle")),
10  binomialErr_(ps.getUntrackedParameter<bool>("binomialErr")),
11  ignoreBin_(ps.getUntrackedParameter<std::vector<int>>("ignoreBin")),
12  ratioME_(nullptr)
13 {
14 }
15 
17 
19 {
21  desc.addUntracked<std::string>("monitorDir", "")->setComment("Target directory in the DQM file. Will be created if not existing.");
22  desc.addUntracked<std::string>("inputNum", "")->setComment("Path to numerator histogram.");
23  desc.addUntracked<std::string>("inputDen", "")->setComment("Path to denominator histogram.");
24  desc.addUntracked<std::string>("ratioName", "ratio")->setComment("Ratio plot name.");
25  desc.addUntracked<std::string>("ratioTitle", "ratio")->setComment("Ratio plot title.");
26  desc.addUntracked<std::string>("yAxisTitle", "")->setComment("Title of y axis.");
27  desc.addUntracked<bool>("binomialErr", "true")->setComment("Compute binomial errors.");
28  desc.addUntracked<std::vector<int>>("ignoreBin", std::vector<int>())->setComment("List of bins to ignore. Will set their ratio to 0.");
29  descriptions.add("l1TStage2RatioClient", desc);
30 }
31 
33 {
34  book(ibooker, igetter);
35  processHistograms(igetter);
36 }
37 
39 {
40  // Book when called the first time. Otherwise reset the ratio histogram.
41  if (ratioME_ == nullptr) {
43 
44  // get the axis range from the numerator histogram
45  const MonitorElement* numME_ = igetter.get(inputNum_);
46  if (numME_) {
47  TH1F *hNum = numME_->getTH1F();
48 
49  ratioME_ = ibooker.book1D(ratioName_, ratioTitle_, hNum->GetNbinsX(), hNum->GetXaxis()->GetXmin(), hNum->GetXaxis()->GetXmax());
52  }
53  } else {
54  ratioME_->Reset();
55  }
56 }
57 
59 {
60  const MonitorElement* numME_ = igetter.get(inputNum_);
61  const MonitorElement* denME_ = igetter.get(inputDen_);
62 
63  if (numME_ && denME_) {
64  TH1F *hNum = numME_->getTH1F();
65  TH1F *hDen = dynamic_cast<TH1F *>(denME_->getTH1F()->Clone("den"));
66 
67  TH1F *hRatio = ratioME_->getTH1F();
68 
69  // Set the axis labels the same as the numerator histogram to be able to divide
70  if (hNum->GetXaxis()->IsAlphanumeric()) {
71  for (int i = 1; i <= hNum->GetNbinsX(); ++i) {
72  hDen->GetXaxis()->SetBinLabel(i, hNum->GetXaxis()->GetBinLabel(i));
73  hRatio->GetXaxis()->SetBinLabel(i, hNum->GetXaxis()->GetBinLabel(i));
74  }
75  }
76 
77  std::string errOption;
78  if (binomialErr_) {
79  errOption = "B";
80  }
81 
82  hRatio->Divide(hNum, hDen, 1, 1, errOption.c_str());
83 
84  // Set the ratio to 0 for those bins that need to be ignored
85  for (const int & bin : ignoreBin_) {
86  if (bin > 0 && bin <= hRatio->GetNbinsX()) {
87  hRatio->SetBinContent(bin, 0.0);
88  hRatio->GetXaxis()->SetBinLabel(bin, "Ignored");
89  }
90  }
91 
92  delete hDen;
93  }
94 }
95 
97  book(ibooker, igetter);
98  processHistograms(igetter);
99 }
100 
void setComment(std::string const &value)
std::vector< int > ignoreBin_
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
TH1F * getTH1F() const
#define nullptr
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
void setEfficiencyFlag()
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void Reset()
reset ME (ie. contents, errors, etc)
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
void processHistograms(DQMStore::IGetter &igetter)
bin
set the eta bin as selection string.
L1TStage2RatioClient(const edm::ParameterSet &)
MonitorElement * ratioME_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)