CMS 3D CMS Logo

TnPEfficiencyClient.cc
Go to the documentation of this file.
1 /*
2  * \file TnPEfficiencyClient.cc
3  *
4  * \author L. Lunerti - INFN Bologna
5  *
6  */
7 
9 
11 
16 
18 
20 public:
22  ~TnPEfficiencyClient() override;
23 
24 protected:
25  void beginRun(const edm::Run&, const edm::EventSetup&) override;
27 
30  edm::LuminosityBlock const&,
31  edm::EventSetup const&) override;
32 
34  inline std::string topFolder() const { return subsystem + "/Segment_TnP/"; };
35 
36 private:
37  std::map<std::string, MonitorElement*> effHistos;
38  std::vector<std::string> passNfailHistoNames;
40 };
41 
43  : passNfailHistoNames(pSet.getUntrackedParameter<std::vector<std::string>>("histoNames")),
44  subsystem(pSet.getUntrackedParameter<std::string>("subsystem")) {
45  edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: Constructor called";
46 };
47 
49  edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: Constructor called";
50 };
51 
53 
55  DQMStore::IGetter& igetter,
56  edm::LuminosityBlock const& lumiSeg,
57  edm::EventSetup const& setup) {
58  edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: endluminosityBlock";
59 }
60 
62  edm::LogVerbatim("DQMOffline|MuonDPG|TnPEfficiencyClient") << "TnPEfficiencyClient: endRun";
63 
64  std::string outFolder = "Task";
65 
66  ibooker.setCurrentFolder(topFolder() + outFolder + "/");
67  std::string baseFolder = topFolder() + outFolder + "/";
68 
69  TH1::SetDefaultSumw2(kTRUE);
70 
71  for (const auto& s : passNfailHistoNames) {
72  TH1::SetDefaultSumw2(kTRUE);
73 
74  std::string passHistoName = s.substr(0, s.find(':'));
75  std::string failHistoName = s.substr(s.find(':') + 1, s.length());
76 
77  std::string histoName_pass = baseFolder + passHistoName;
78  std::string histoName_fail = baseFolder + failHistoName;
79 
80  MonitorElement* me_pass = igetter.get(histoName_pass);
81  MonitorElement* me_fail = igetter.get(histoName_fail);
82 
83  int fir = passHistoName.find('_');
84  int sec = passHistoName.find('_', fir + 1);
85  std::string chName = passHistoName.substr(0, fir);
86  std::string specifier = passHistoName.substr(sec + 1);
87  std::string effHistoName = chName + "_chamberEff_" + specifier;
88 
89  if (!me_pass || !me_fail) {
90  edm::LogWarning("TnPEfficiencyClient") << "Monitor Element not available" << std::endl;
91  return;
92  }
93 
94  //1D histos
95  if ((int)me_pass->kind() == DQMNet::DQM_PROP_TYPE_TH1F && (int)me_fail->kind() == DQMNet::DQM_PROP_TYPE_TH1F) {
96  if (!(me_pass->getTH1F()) || !(me_fail->getTH1F())) {
97  edm::LogWarning("TnPEfficiencyClient") << "Monitor Element not available" << std::endl;
98  return;
99  }
100 
101  TH1F* h1_pass = me_pass->getTH1F();
102  TH1F* h1_fail = me_fail->getTH1F();
103 
104  const int nBinX_pass = h1_pass->GetNbinsX();
105  const int nBinX_fail = h1_fail->GetNbinsX();
106 
107  if (nBinX_pass != nBinX_fail) {
108  edm::LogWarning("TnPEfficiencyClient")
109  << "Histograms with different number of bins: unable to compute the ratio" << std::endl;
110  return;
111  }
112 
113  TH1F* h1_den = (TH1F*)h1_pass->Clone();
114  TH1F* h1_num = (TH1F*)h1_pass->Clone();
115  h1_den->Sumw2();
116  h1_num->Sumw2();
117  h1_den->Add(h1_fail);
118 
119  h1_num->Divide(h1_den);
120  TH1F* h1_ratio = (TH1F*)h1_num->Clone();
121 
122  effHistos[effHistoName] = ibooker.book1D(effHistoName, h1_ratio);
123  effHistos[effHistoName]->setTitle(effHistoName);
124  effHistos[effHistoName]->setAxisTitle("Efficiency", 2);
125  }
126 
127  //2D histos
128  if ((int)me_pass->kind() == DQMNet::DQM_PROP_TYPE_TH2F && (int)me_fail->kind() == DQMNet::DQM_PROP_TYPE_TH2F) {
129  if (!(me_pass->getTH2F()) || !(me_fail->getTH2F())) {
130  edm::LogWarning("TnPEfficiencyClient")
131  << "Monitor Element not available: unable to compute the ratio" << std::endl;
132  return;
133  }
134 
135  TH2F* h2_pass = me_pass->getTH2F();
136  TH2F* h2_fail = me_fail->getTH2F();
137 
138  const int nBinX_pass = h2_pass->GetNbinsX();
139  const int nBinX_fail = h2_fail->GetNbinsX();
140  const int nBinY_pass = h2_pass->GetNbinsY();
141  const int nBinY_fail = h2_fail->GetNbinsY();
142 
143  if ((nBinX_pass != nBinX_fail) || (nBinY_pass != nBinY_fail)) {
144  edm::LogWarning("TnPEfficiencyClient")
145  << "Histograms with different number of bins: unable to compute the ratio" << std::endl;
146  return;
147  }
148 
149  TH2F* h2_den = (TH2F*)h2_pass->Clone();
150  TH2F* h2_num = (TH2F*)h2_pass->Clone();
151  h2_den->Sumw2();
152  h2_num->Sumw2();
153  h2_den->Add(h2_fail);
154 
155  h2_num->Divide(h2_den);
156  TH2F* h2_ratio = (TH2F*)h2_num->Clone();
157 
158  effHistos[effHistoName] = ibooker.book2D(effHistoName, h2_ratio);
159  effHistos[effHistoName]->setTitle(effHistoName);
160  effHistos[effHistoName]->setAxisTitle("Efficiency", 3);
161  }
162  }
163 
164  return;
165 }
166 
Log< level::Info, true > LogVerbatim
std::map< std::string, MonitorElement * > effHistos
std::string topFolder() const
Return the top folder.
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Kind kind() const
Get the type of the monitor element.
static const uint32_t DQM_PROP_TYPE_TH1F
Definition: DQMNet.h:34
virtual TH2F * getTH2F() const
std::vector< std::string > passNfailHistoNames
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
TnPEfficiencyClient(const edm::ParameterSet &pSet)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
virtual TH1F * getTH1F() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45
static const uint32_t DQM_PROP_TYPE_TH2F
Definition: DQMNet.h:38