CMS 3D CMS Logo

HltSusyExoPostProcessor.cc
Go to the documentation of this file.
2 
8 
9 #include "TH1.h"
10 #include "TProfile.h"
11 #include <cmath>
12 #include <cstring>
13 #include <fstream>
14 #include <iomanip>
15 #include <iostream>
16 
17 using namespace std;
18 using namespace edm;
19 
21  : subDir_(pset.getUntrackedParameter<std::string>("subDir", std::string("HLT/SusyExo"))),
22  mcFlag(pset.getUntrackedParameter<bool>("mc_flag", true)),
23  reco_parametersets(pset.getParameter<VParameterSet>("reco_parametersets")),
24  mc_parametersets(pset.getParameter<VParameterSet>("mc_parametersets")) {
25  for (unsigned int i = 0; i < reco_parametersets.size(); ++i) {
26  reco_dirs.push_back(reco_parametersets[i].getParameter<string>("name"));
27  }
28  for (unsigned int i = 0; i < mc_parametersets.size(); ++i) {
29  mc_dirs.push_back(mc_parametersets[i].getParameter<string>("name"));
30  }
31 }
32 
34  LogDebug("HltSusyExoPostProcessor") << "Start dqmEndJob";
35 
36  // go to the directory to be processed
37  if (iGetter_.dirExists(subDir_))
38  iGetter_.cd(subDir_);
39  else {
40  edm::LogWarning("HltSusyExoPostProcessor") << "cannot find directory: " << subDir_ << " , skipping";
41  return;
42  }
43 
44  LogDebug("HltSusyExoPostProcessor") << "DQMStore cd";
45 
46  // --- set the names in the dbe folders ---
47  std::string triggerBitsDir = "/TriggerBits";
48  std::string recoSelBitsDir = "/RecoSelection";
49  std::string mcSelBitsDir = "/McSelection";
50  std::string byEventDir = "/By_Event";
51  std::string byMuonDir = "/By_Muon";
52 
53  // get the number of bins of the MonitorElements (valid for all the
54  // MonitorElements, independently of selection on the final state) we take the
55  // number of bins from the MonitorElements of the source, and we subtract one
56  // because the last bin was reserved for the Total number of events
57  int nL1bins = (iGetter_.get(iBooker_.pwd() + triggerBitsDir + "/L1Bits")->getNbinsX());
58  int nHltbins = (iGetter_.get(iBooker_.pwd() + triggerBitsDir + "/HltBits")->getNbinsX());
59 
60  std::vector<int> L1placement;
61  for (int i = 0; i < nL1bins - 1 * mcFlag; ++i)
62  L1placement.push_back(6);
63  std::vector<int> Hltplacement;
64  for (int i = 0; i < nHltbins - 1 * mcFlag; ++i)
65  Hltplacement.push_back(7);
66  int L1bins[7];
67  for (unsigned int i = 0; i < sizeof(L1bins) / sizeof(L1bins[0]); ++i)
68  L1bins[i] = 0;
69  int Hltbins[8];
70  for (unsigned int i = 0; i < sizeof(Hltbins) / sizeof(Hltbins[0]); ++i)
71  Hltbins[i] = 0;
72  string L1search[8] = {"Mu", "EG", "Jet", "ET", "TauJet", "X", ""};
73  string L1search3 = "HTT", L1search6 = "Bias";
74  string Hltsearch[8] = {"Mu", "Ele", "Jet", "Photon", "MET", "Tau", "X", ""};
75  string Hltsearch4 = "HT", Hltsearch5 = "BTag", Hltsearch6_1 = "EG", Hltsearch6_2 = "ET", Hltsearch7_1 = "Bias",
76  Hltsearch7_2 = "AlCa";
77 
78  LogDebug("HltSusyExoPostProcessor") << "number of L1 bins = " << nL1bins << " number of HLT bins = " << nHltbins;
79  double value = 0;
80  double error = 0;
81 
82  // Calculate the efficiencies for histos without any selection
83  iGetter_.setCurrentFolder(subDir_ + triggerBitsDir);
84  TH1F *hL1Paths = iGetter_.get(subDir_ + triggerBitsDir + "/L1Paths")->getTH1F();
85  MonitorElement *hL1EffBeforeCuts = bookEffMEProfileFromTH1(hL1Paths, "Eff", iBooker_);
86  TH1F *hHltPaths = iGetter_.get(subDir_ + triggerBitsDir + "/HltPaths")->getTH1F();
87  MonitorElement *hHltEffBeforeCuts = bookEffMEProfileFromTH1(hHltPaths, "Eff", iBooker_);
88 
89  LogDebug("HltSusyExoPostProcessor") << "MonitorElements booked";
90 
91  // get the total number of events
92  float nTotalBeforeCuts = -1;
93  int reference_bin = -1;
94  if (mcFlag) {
95  nTotalBeforeCuts = iGetter_.get(subDir_ + triggerBitsDir + "/L1Bits")->getBinContent(nL1bins);
96  reference_bin = nL1bins;
97  } else {
98  for (int i = 0; i < nHltbins; ++i) {
99  string triggername = ((TProfile *)hHltEffBeforeCuts->getTProfile())->GetXaxis()->GetBinLabel(i + 1);
100  string eff_search = "HLT_ZeroBias";
101  if (triggername.find(eff_search) != string::npos && triggername.size() == eff_search.size()) {
102  nTotalBeforeCuts = ((TProfile *)hHltEffBeforeCuts->getTProfile())->GetBinContent(i + 1);
103  reference_bin = i + 1;
104  break;
105  }
106  }
107  if (nTotalBeforeCuts == -1) {
108  nTotalBeforeCuts = iGetter_.get(subDir_ + triggerBitsDir + "/L1Bits")->getBinContent(nL1bins);
109  reference_bin = nHltbins;
110  }
111  }
112  LogDebug("HltSusyExoPostProcessor") << "Total number of events = " << nTotalBeforeCuts;
113 
114  // fill the eff histo
115  for (int i = 0; i < nL1bins - 1 * mcFlag; i++) {
116  value =
117  (double)iGetter_.get(subDir_ + triggerBitsDir + "/L1Paths")->getBinContent(i + 1) / (double)nTotalBeforeCuts;
118  error = sqrt(value * (1 - value) / (double)nTotalBeforeCuts);
119  hL1EffBeforeCuts->setBinContent(i + 1, value);
120  hL1EffBeforeCuts->setBinEntries(i + 1, 1);
121  hL1EffBeforeCuts->setBinError(i + 1, error);
122  // if(i!=nL1bins)
123  // {
124  string triggername = ((TProfile *)hL1EffBeforeCuts->getTProfile())->GetXaxis()->GetBinLabel(i + 1);
125  if (triggername.find(L1search6) == string::npos) {
126  for (unsigned int j = 0; j < sizeof(L1search) / sizeof(L1search[0]) - 2; ++j) {
127  if (triggername.find(L1search[j]) != string::npos || (j == 3 && triggername.find(L1search3) != string::npos)) {
128  if (L1placement[i] == 6)
129  L1placement[i] = j;
130  else if (L1placement[i] == 2 && j == 4)
131  L1placement[i] = 4;
132  else
133  L1placement[i] = 5;
134  } else if (triggername.empty() || triggername.find("Total") != string::npos)
135  L1placement[i] = -1;
136  }
137  }
138  }
139 
140  for (unsigned int i = 0; i < L1placement.size(); ++i)
141  if (L1placement[i] != -1)
142  ++L1bins[L1placement[i]];
143 
144  for (int i = 0; i < nHltbins - 1 * mcFlag; i++) {
145  value =
146  (double)iGetter_.get(subDir_ + triggerBitsDir + "/HltPaths")->getBinContent(i + 1) / (double)nTotalBeforeCuts;
147  error = sqrt(value * (1 - value) / (double)nTotalBeforeCuts);
148  hHltEffBeforeCuts->setBinContent(i + 1, value);
149  hHltEffBeforeCuts->setBinEntries(i + 1, 1);
150  hHltEffBeforeCuts->setBinError(i + 1, error);
151  // if(i!=nHltbins)
152  // {
153  string triggername = ((TProfile *)hHltEffBeforeCuts->getTProfile())->GetXaxis()->GetBinLabel(i + 1);
154  if (triggername.find(Hltsearch7_1) == string::npos && triggername.find(Hltsearch7_2) == string::npos) {
155  for (unsigned int j = 0; j < sizeof(Hltsearch) / sizeof(Hltsearch[0]) - 2; ++j) {
156  if (triggername.find(Hltsearch[j]) != string::npos ||
157  (j == 4 && triggername.find(Hltsearch4) != string::npos) ||
158  (j == 5 && triggername.find(Hltsearch5) != string::npos)) {
159  if (Hltplacement[i] == 7)
160  Hltplacement[i] = j;
161  else if (triggername.find(Hltsearch5) != string::npos)
162  Hltplacement[i] = 5;
163  else
164  Hltplacement[i] = 6;
165  } else if (triggername.empty() || triggername.find("Total") != string::npos)
166  Hltplacement[i] = -1;
167  }
168  if (Hltplacement[i] >= 0 && Hltplacement[i] <= 5 &&
169  (triggername.find(Hltsearch6_1) != string::npos ||
170  (triggername.find(Hltsearch6_2) != string::npos && Hltplacement[i] != 4)))
171  Hltplacement[i] = 6;
172  }
173  }
174 
175  for (unsigned int i = 0; i < Hltplacement.size(); ++i)
176  if (Hltplacement[i] != -1)
177  ++Hltbins[Hltplacement[i]];
178 
179  LogDebug("HltSusyExoPostProcessor") << "MonitorElements filled";
180 
181  // Create the sorted histograms
182  iBooker_.setCurrentFolder(subDir_ + triggerBitsDir);
183  MonitorElement *hL1EffSorted[7] = {
184  iBooker_.bookProfile("L1_Mu", new TProfile("L1_Mu", "Efficiencies of L1 Muon Triggers", L1bins[0], 0, L1bins[0])),
185  iBooker_.bookProfile("L1_EG", new TProfile("L1_EG", "Efficiencies of L1 EG Triggers", L1bins[1], 0, L1bins[1])),
186  iBooker_.bookProfile("L1_Jet",
187  new TProfile("L1_Jet", "Efficiencies of L1 Jet Triggers", L1bins[2], 0, L1bins[2])),
188  iBooker_.bookProfile(
189  "L1_ETM_ETT_HTT",
190  new TProfile("L1_ETM_ETT_HTT", "Efficiencies of L1 ETM, ETT, and HTT Triggers", L1bins[3], 0, L1bins[3])),
191  iBooker_.bookProfile("L1_TauJet",
192  new TProfile("L1_TauJet", "Efficiencies of L1 TauJet Triggers", L1bins[4], 0, L1bins[4])),
193  iBooker_.bookProfile("L1_XTrigger",
194  new TProfile("L1_XTrigger", "Efficiencies of L1 Cross Triggers", L1bins[5], 0, L1bins[5])),
195  iBooker_.bookProfile(
196  "L1_Overflow", new TProfile("L1_Overflow", "Efficiencies of L1 Unsorted Triggers", L1bins[6], 0, L1bins[6]))};
197 
198  MonitorElement *hHltEffSorted[8] = {
199  iBooker_.bookProfile("Hlt_Mu",
200  new TProfile("Hlt_Mu", "Efficiencies of HL Muon Triggers", Hltbins[0], 0, Hltbins[0])),
201  iBooker_.bookProfile("Hlt_Ele",
202  new TProfile("Hlt_Ele", "Efficiencies of HL Electron Triggers", Hltbins[1], 0, Hltbins[1])),
203  iBooker_.bookProfile("Hlt_Jet",
204  new TProfile("Hlt_Jet", "Efficiencies of HL Jet Triggers", Hltbins[2], 0, Hltbins[2], "s")),
205  iBooker_.bookProfile("Hlt_Photon",
206  new TProfile("Hlt_Photon", "Efficiencies of HL Photon Triggers", Hltbins[3], 0, Hltbins[3])),
207  iBooker_.bookProfile(
208  "Hlt_MET_HT",
209  new TProfile("Hlt_MET_HT", "Efficiencies of HL MET and HT Triggers", Hltbins[4], 0, Hltbins[4])),
210  iBooker_.bookProfile(
211  "Hlt_Tau_BTag",
212  new TProfile("Hlt_Tau_Btag", "Efficiencies of HL Tau and BTag Triggers", Hltbins[5], 0, Hltbins[5])),
213  iBooker_.bookProfile(
214  "Hlt_XTrigger", new TProfile("Hlt_XTrigger", "Efficiencies of HL Cross Triggers", Hltbins[6], 0, Hltbins[6])),
215  iBooker_.bookProfile(
216  "Hlt_Overflow",
217  new TProfile("Hlt_Overflow", "Efficiencies of HL Unsorted Triggers", Hltbins[7], 0, Hltbins[7]))};
218 
219  int L1bincounter[8];
220  for (unsigned int i = 0; i < sizeof(L1bincounter) / sizeof(L1bincounter[0]); ++i)
221  L1bincounter[i] = 0;
222  int Hltbincounter[8];
223  for (unsigned int i = 0; i < sizeof(Hltbincounter) / sizeof(Hltbincounter[0]); ++i)
224  Hltbincounter[i] = 0;
225  TProfile *hL1_ = (TProfile *)hL1EffBeforeCuts->getTProfile();
226  TProfile *hHlt_ = (TProfile *)hHltEffBeforeCuts->getTProfile();
227  // for(int i = 0; i<hHlt_->GetXaxis()->GetNbins(); i++) cout <<
228  // "hHLT_->GetBinError(" << i << ") = " << hHlt_->GetBinError(i+1) << endl;
229  for (unsigned int i = 0; i < L1placement.size(); ++i) {
230  if (L1placement[i] != -1) {
231  hL1EffSorted[L1placement[i]]->setBinLabel(L1bincounter[L1placement[i]] + 1, hL1_->GetXaxis()->GetBinLabel(i + 1));
232  hL1EffSorted[L1placement[i]]->setBinContent(L1bincounter[L1placement[i]] + 1, hL1_->GetBinContent(i + 1));
233  hL1EffSorted[L1placement[i]]->setBinEntries(L1bincounter[L1placement[i]] + 1, 1);
234  hL1EffSorted[L1placement[i]]->setBinError(L1bincounter[L1placement[i]] + 1, hL1_->GetBinError(i + 1));
235  ++L1bincounter[L1placement[i]];
236  }
237  }
238  for (unsigned int i = 0; i < Hltplacement.size(); ++i) {
239  if (Hltplacement[i] != -1) {
240  hHltEffSorted[Hltplacement[i]]->setBinLabel(Hltbincounter[Hltplacement[i]] + 1,
241  hHlt_->GetXaxis()->GetBinLabel(i + 1));
242  hHltEffSorted[Hltplacement[i]]->setBinContent(Hltbincounter[Hltplacement[i]] + 1, hHlt_->GetBinContent(i + 1));
243  hHltEffSorted[Hltplacement[i]]->setBinEntries(Hltbincounter[Hltplacement[i]] + 1, 1);
244  hHltEffSorted[Hltplacement[i]]->setBinError(Hltbincounter[Hltplacement[i]] + 1, hHlt_->GetBinError(i + 1));
245  ++Hltbincounter[Hltplacement[i]];
246  }
247  }
248 
249  for (unsigned int i = 0; i < mc_dirs.size(); ++i) {
250  // Calculate the efficiencies for histos after MC selection
251  iGetter_.setCurrentFolder(subDir_ + mcSelBitsDir + "/" + mc_dirs[i]);
252  // book the MonitorElements for the efficiencies
253  char set_name_L1[256], set_name_Hlt[256];
254  sprintf(set_name_L1, "L1Eff_%s", mc_dirs[i].c_str());
255  sprintf(set_name_Hlt, "HltEff_%s", mc_dirs[i].c_str());
256  MonitorElement *hL1EffAfterMcCuts = bookEffMEProfileFromTH1(
257  iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Paths_" + mc_dirs[i])->getTH1F(),
258  (std::string)set_name_L1,
259  iBooker_);
260  hL1EffAfterMcCuts->setTitle("L1 Efficiencies for " + mc_dirs[i] + " selection");
261  MonitorElement *hHltEffAfterMcCuts = bookEffMEProfileFromTH1(
262  iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltPaths_" + mc_dirs[i])->getTH1F(),
263  (std::string)set_name_Hlt,
264  iBooker_);
265  hHltEffAfterMcCuts->setTitle("HLT Efficiencies for " + mc_dirs[i] + " selection");
266 
267  LogDebug("HltSusyExoPostProcessor") << "MonitorElements for " << mc_dirs[i] << " selection booked";
268 
269  // get the total number of events
270  float nTotalAfterMcCuts;
271  if (mcFlag)
272  nTotalAfterMcCuts =
273  iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Bits_" + mc_dirs[i])->getBinContent(nL1bins);
274  else
275  nTotalAfterMcCuts = iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltBits_" + mc_dirs[i])
276  ->getBinContent(reference_bin);
277 
278  LogDebug("HltSusyExoPostProcessor") << "Total number of events = " << nTotalAfterMcCuts;
279 
280  MonitorElement *hL1EffSorted_mc[7];
281  MonitorElement *hHltEffSorted_mc[8];
282  char buffer1[256], buffer2[256];
283  string L1_nametags[7] = {"Mu", "EG", "Jet", "ETM_ETT_HTT", "TauJet", "XTrigger", "Overflow"};
284  string L1_titletags[7] = {"Muon", "EG", "Jet", "ETM, ETT, and HTT", "TauJet", "Cross", "Unsorted"};
285  string Hlt_nametags[8] = {"Mu", "Ele", "Jet", "Photon", "MET_HT", "Tau_BTag", "XTrigger", "Overflow"};
286  string Hlt_titletags[8] = {"Muon", "Electron", "Jet", "Photon", "MET and HT", "Tau and BTag", "Cross", "Unsorted"};
287  for (unsigned int j = 0; j < sizeof(hL1EffSorted_mc) / sizeof(hL1EffSorted_mc[0]); ++j) {
288  sprintf(buffer1, "L1_%s_%s", mc_dirs[i].c_str(), L1_nametags[j].c_str());
289  sprintf(buffer2, "Efficiencies of L1 %s Triggers for %s Selection", L1_titletags[j].c_str(), mc_dirs[i].c_str());
290  hL1EffSorted_mc[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, L1bins[j], 0, L1bins[j]));
291  }
292  for (unsigned int j = 0; j < sizeof(hHltEffSorted_mc) / sizeof(hHltEffSorted_mc[0]); ++j) {
293  sprintf(buffer1, "Hlt_%s_%s", mc_dirs[i].c_str(), Hlt_nametags[j].c_str());
294  sprintf(buffer2, "Efficiencies of HL %s Triggers for %s Selection", Hlt_titletags[j].c_str(), mc_dirs[i].c_str());
295  hHltEffSorted_mc[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, Hltbins[j], 0, Hltbins[j]));
296  }
297 
298  // fill the eff histo
299  int L1bincounter_mc[8];
300  for (unsigned int j = 0; j < sizeof(L1bincounter_mc) / sizeof(L1bincounter_mc[0]); ++j)
301  L1bincounter_mc[j] = 0;
302  int Hltbincounter_mc[8];
303  for (unsigned int j = 0; j < sizeof(Hltbincounter_mc) / sizeof(Hltbincounter_mc[0]); ++j)
304  Hltbincounter_mc[j] = 0;
305  TProfile *hL1_mc = (TProfile *)hL1EffAfterMcCuts->getTProfile();
306  TProfile *hHlt_mc = (TProfile *)hHltEffAfterMcCuts->getTProfile();
307  for (unsigned int j = 0; j < L1placement.size(); j++) {
308  value = nTotalAfterMcCuts
309  ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Paths_" + mc_dirs[i])
310  ->getBinContent(j + 1) /
311  nTotalAfterMcCuts
312  : 0;
313  error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
314  hL1EffAfterMcCuts->setBinContent(j + 1, value);
315  hL1EffAfterMcCuts->setBinEntries(j + 1, 1);
316  hL1EffAfterMcCuts->setBinError(j + 1, error);
317  if (L1placement[j] != -1) {
318  hL1EffSorted_mc[L1placement[j]]->setBinLabel(L1bincounter_mc[L1placement[j]] + 1,
319  hL1_mc->GetXaxis()->GetBinLabel(j + 1));
320  hL1EffSorted_mc[L1placement[j]]->setBinContent(L1bincounter_mc[L1placement[j]] + 1,
321  hL1_mc->GetBinContent(j + 1));
322  hL1EffSorted_mc[L1placement[j]]->setBinEntries(L1bincounter_mc[L1placement[j]] + 1, 1);
323  hL1EffSorted_mc[L1placement[j]]->setBinError(L1bincounter_mc[L1placement[j]] + 1, hL1_mc->GetBinError(j + 1));
324  ++L1bincounter_mc[L1placement[j]];
325  }
326  }
327  if (nL1bins != int(L1placement.size())) {
328  value = nTotalAfterMcCuts
329  ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/L1Paths_" + mc_dirs[i])
330  ->getBinContent(nL1bins) /
331  nTotalAfterMcCuts
332  : 0;
333  error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
334  hL1EffAfterMcCuts->setBinContent(nL1bins, value);
335  hL1EffAfterMcCuts->setBinEntries(nL1bins, 1);
336  hL1EffAfterMcCuts->setBinError(nL1bins, error);
337  }
338  for (unsigned int j = 0; j < Hltplacement.size(); j++) {
339  value = nTotalAfterMcCuts
340  ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltPaths_" + mc_dirs[i])
341  ->getBinContent(j + 1) /
342  nTotalAfterMcCuts
343  : 0;
344  error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
345  hHltEffAfterMcCuts->setBinContent(j + 1, value);
346  hHltEffAfterMcCuts->setBinEntries(j + 1, 1);
347  hHltEffAfterMcCuts->setBinError(j + 1, error);
348  if (Hltplacement[j] != -1) {
349  hHltEffSorted_mc[Hltplacement[j]]->setBinLabel(Hltbincounter_mc[Hltplacement[j]] + 1,
350  hHlt_mc->GetXaxis()->GetBinLabel(j + 1));
351  hHltEffSorted_mc[Hltplacement[j]]->setBinContent(Hltbincounter_mc[Hltplacement[j]] + 1,
352  hHlt_mc->GetBinContent(j + 1));
353  hHltEffSorted_mc[Hltplacement[j]]->setBinEntries(Hltbincounter_mc[Hltplacement[j]] + 1, 1);
354  hHltEffSorted_mc[Hltplacement[j]]->setBinError(Hltbincounter_mc[Hltplacement[j]] + 1,
355  hHlt_mc->GetBinError(j + 1));
356  ++Hltbincounter_mc[Hltplacement[j]];
357  }
358  }
359  if (nHltbins != int(Hltplacement.size())) {
360  value = nTotalAfterMcCuts
361  ? (float)iGetter_.get(subDir_ + mcSelBitsDir + "/" + mc_dirs[i] + "/HltPaths_" + mc_dirs[i])
362  ->getBinContent(nHltbins) /
363  nTotalAfterMcCuts
364  : 0;
365  error = nTotalAfterMcCuts ? sqrt(value * (1 - value) / nTotalAfterMcCuts) : 0;
366  hHltEffAfterMcCuts->setBinContent(nHltbins, value);
367  hHltEffAfterMcCuts->setBinEntries(nHltbins, 1);
368  hHltEffAfterMcCuts->setBinError(nHltbins, error);
369  }
370  LogDebug("HltSusyExoPostProcessor") << "MonitorElements filled for " << mc_dirs[i] << " selection";
371  }
372 
373  for (unsigned int i = 0; i < reco_dirs.size(); ++i) {
374  // Calculate the efficiencies for histos after RECO selection
375  iGetter_.setCurrentFolder(subDir_ + recoSelBitsDir + "/" + reco_dirs[i]);
376  // book the MonitorElements for the efficiencies
377  char set_name_L1[256], set_name_Hlt[256];
378  sprintf(set_name_L1, "L1Eff_%s", reco_dirs[i].c_str());
379  sprintf(set_name_Hlt, "HltEff_%s", reco_dirs[i].c_str());
380  MonitorElement *hL1EffAfterRecoCuts = bookEffMEProfileFromTH1(
381  iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Paths_" + reco_dirs[i])->getTH1F(),
382  (std::string)set_name_L1,
383  iBooker_);
384  hL1EffAfterRecoCuts->setTitle("L1 Efficiencies for " + reco_dirs[i] + " selection");
385  MonitorElement *hHltEffAfterRecoCuts = bookEffMEProfileFromTH1(
386  iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltPaths_" + reco_dirs[i])->getTH1F(),
387  (std::string)set_name_Hlt,
388  iBooker_);
389  hHltEffAfterRecoCuts->setTitle("HLT Efficiencies for " + reco_dirs[i] + " selection");
390 
391  LogDebug("HltSusyExoPostProcessor") << "MonitorElements for " << reco_dirs[i] << " selection booked";
392 
393  // get the total number of events
394  float nTotalAfterRecoCuts;
395  if (mcFlag)
396  nTotalAfterRecoCuts = iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Bits_" + reco_dirs[i])
397  ->getBinContent(nL1bins);
398  else
399  nTotalAfterRecoCuts = iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltBits_" + reco_dirs[i])
400  ->getBinContent(reference_bin);
401 
402  LogDebug("HltSusyExoPostProcessor") << "Total number of events = " << nTotalAfterRecoCuts;
403 
404  MonitorElement *hL1EffSorted_reco[7];
405  MonitorElement *hHltEffSorted_reco[8];
406  char buffer1[256], buffer2[256];
407  string L1_nametags[7] = {"Mu", "EG", "Jet", "ETM_ETT_HTT", "TauJet", "XTrigger", "Overflow"};
408  string L1_titletags[7] = {"Muon", "EG", "Jet", "ETM, ETT, and HTT", "TauJet", "Cross", "Unsorted"};
409  string Hlt_nametags[8] = {"Mu", "Ele", "Jet", "Photon", "MET_HT", "Tau_BTag", "XTrigger", "Overflow"};
410  string Hlt_titletags[8] = {"Muon", "Electron", "Jet", "Photon", "MET and HT", "Tau and BTag", "Cross", "Unsorted"};
411  for (unsigned int j = 0; j < sizeof(hL1EffSorted_reco) / sizeof(hL1EffSorted_reco[0]); ++j) {
412  sprintf(buffer1, "L1_%s_%s", reco_dirs[i].c_str(), L1_nametags[j].c_str());
413  sprintf(
414  buffer2, "Efficiencies of L1 %s Triggers for %s Selection", L1_titletags[j].c_str(), reco_dirs[i].c_str());
415  hL1EffSorted_reco[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, L1bins[j], 0, L1bins[j]));
416  }
417  for (unsigned int j = 0; j < sizeof(hHltEffSorted_reco) / sizeof(hHltEffSorted_reco[0]); ++j) {
418  sprintf(buffer1, "Hlt_%s_%s", reco_dirs[i].c_str(), Hlt_nametags[j].c_str());
419  sprintf(
420  buffer2, "Efficiencies of HL %s Triggers for %s Selection", Hlt_titletags[j].c_str(), reco_dirs[i].c_str());
421  hHltEffSorted_reco[j] = iBooker_.bookProfile(buffer1, new TProfile(buffer1, buffer2, Hltbins[j], 0, Hltbins[j]));
422  }
423 
424  // fill the eff histo
425  int L1bincounter_reco[8];
426  for (unsigned int j = 0; j < sizeof(L1bincounter_reco) / sizeof(L1bincounter_reco[0]); ++j)
427  L1bincounter_reco[j] = 0;
428  int Hltbincounter_reco[8];
429  for (unsigned int j = 0; j < sizeof(Hltbincounter_reco) / sizeof(Hltbincounter_reco[0]); ++j)
430  Hltbincounter_reco[j] = 0;
431  TProfile *hL1_reco = (TProfile *)hL1EffAfterRecoCuts->getTProfile();
432  TProfile *hHlt_reco = (TProfile *)hHltEffAfterRecoCuts->getTProfile();
433  for (unsigned int j = 0; j < L1placement.size(); j++) {
434  value = nTotalAfterRecoCuts
435  ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Paths_" + reco_dirs[i])
436  ->getBinContent(j + 1) /
437  nTotalAfterRecoCuts
438  : 0;
439  error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
440  hL1EffAfterRecoCuts->setBinContent(j + 1, value);
441  hL1EffAfterRecoCuts->setBinEntries(j + 1, 1);
442  hL1EffAfterRecoCuts->setBinError(j + 1, error);
443  if (L1placement[j] != -1) {
444  hL1EffSorted_reco[L1placement[j]]->setBinLabel(L1bincounter_reco[L1placement[j]] + 1,
445  hL1_reco->GetXaxis()->GetBinLabel(j + 1));
446  hL1EffSorted_reco[L1placement[j]]->setBinContent(L1bincounter_reco[L1placement[j]] + 1,
447  hL1_reco->GetBinContent(j + 1));
448  hL1EffSorted_reco[L1placement[j]]->setBinEntries(L1bincounter_reco[L1placement[j]] + 1, 1);
449  hL1EffSorted_reco[L1placement[j]]->setBinError(L1bincounter_reco[L1placement[j]] + 1,
450  hL1_reco->GetBinError(j + 1));
451  ++L1bincounter_reco[L1placement[j]];
452  }
453  }
454  if (nL1bins != int(L1placement.size())) {
455  value = nTotalAfterRecoCuts
456  ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/L1Paths_" + reco_dirs[i])
457  ->getBinContent(nL1bins) /
458  nTotalAfterRecoCuts
459  : 0;
460  error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
461  hL1EffAfterRecoCuts->setBinContent(nL1bins, value);
462  hL1EffAfterRecoCuts->setBinEntries(nL1bins, 1);
463  hL1EffAfterRecoCuts->setBinError(nL1bins, error);
464  }
465  for (unsigned int j = 0; j < Hltplacement.size(); j++) {
466  value = nTotalAfterRecoCuts
467  ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltPaths_" + reco_dirs[i])
468  ->getBinContent(j + 1) /
469  nTotalAfterRecoCuts
470  : 0;
471  error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
472  hHltEffAfterRecoCuts->setBinContent(j + 1, value);
473  hHltEffAfterRecoCuts->setBinEntries(j + 1, 1);
474  hHltEffAfterRecoCuts->setBinError(j + 1, error);
475  if (Hltplacement[j] != -1) {
476  hHltEffSorted_reco[Hltplacement[j]]->setBinLabel(Hltbincounter_reco[Hltplacement[j]] + 1,
477  hHlt_reco->GetXaxis()->GetBinLabel(j + 1));
478  hHltEffSorted_reco[Hltplacement[j]]->setBinContent(Hltbincounter_reco[Hltplacement[j]] + 1,
479  hHlt_reco->GetBinContent(j + 1));
480  hHltEffSorted_reco[Hltplacement[j]]->setBinEntries(Hltbincounter_reco[Hltplacement[j]] + 1, 1);
481  hHltEffSorted_reco[Hltplacement[j]]->setBinError(Hltbincounter_reco[Hltplacement[j]] + 1,
482  hHlt_reco->GetBinError(j + 1));
483  ++Hltbincounter_reco[Hltplacement[j]];
484  }
485  }
486  if (nHltbins != int(Hltplacement.size())) {
487  value = nTotalAfterRecoCuts
488  ? (float)iGetter_.get(subDir_ + recoSelBitsDir + "/" + reco_dirs[i] + "/HltPaths_" + reco_dirs[i])
489  ->getBinContent(nHltbins) /
490  nTotalAfterRecoCuts
491  : 0;
492  error = nTotalAfterRecoCuts ? sqrt(value * (1 - value) / nTotalAfterRecoCuts) : 0;
493  hHltEffAfterRecoCuts->setBinContent(nHltbins, value);
494  hHltEffAfterRecoCuts->setBinEntries(nHltbins, 1);
495  hHltEffAfterRecoCuts->setBinError(nHltbins, error);
496  }
497  LogDebug("HltSusyExoPostProcessor") << "MonitorElements filled";
498  }
499 
500  int pt_bins = 100, eta_bins = 100;
501  double pt_floor = 0., pt_ceiling = 200., eta_floor = -3.5, eta_ceiling = 3.5;
502  iBooker_.setCurrentFolder(subDir_ + byEventDir);
503  MonitorElement *hPt_1_ByEvent = iBooker_.book1D(
504  "Pt_1_ByEvent", "Turn on as a Function of P_{t}, |Eta|<1.2, By Event", pt_bins, pt_floor, pt_ceiling);
505  MonitorElement *hEta_1_ByEvent = iBooker_.book1D(
506  "Eta_1_ByEvent", "Efficiency as a Function of Eta, P_{t}>0, By Event", eta_bins, eta_floor, eta_ceiling);
507  MonitorElement *hPt_2_ByEvent = iBooker_.book1D(
508  "Pt_2_ByEvent", "Turn on as a Function of P_{t}, 1.2<|Eta|<2.1, By Event", pt_bins, pt_floor, pt_ceiling);
509  MonitorElement *hEta_2_ByEvent = iBooker_.book1D(
510  "Eta_2_ByEvent", "Efficiency as a Function of Eta, P_{t}>10, By Event", eta_bins, eta_floor, eta_ceiling);
511  MonitorElement *hPt_3_ByEvent = iBooker_.book1D(
512  "Pt_3_ByEvent", "Turn on as a Function of P_{t}, |Eta|>2.1, By Event", pt_bins, pt_floor, pt_ceiling);
513  MonitorElement *hEta_3_ByEvent = iBooker_.book1D(
514  "Eta_3_ByEvent", "Efficiency as a Function of Eta, P_{t}>20, By Event", eta_bins, eta_floor, eta_ceiling);
515  iBooker_.setCurrentFolder(subDir_ + byMuonDir);
516  MonitorElement *hPt_1_ByMuon = iBooker_.book1D(
517  "Pt_1_ByMuon", "Turn on as a Function of P_{t}, |Eta|<1.2, By Muon", pt_bins, pt_floor, pt_ceiling);
518  MonitorElement *hEta_1_ByMuon = iBooker_.book1D(
519  "Eta_1_ByMuon", "Efficiency as a Function of Eta, P_{t}>0, By Muon", eta_bins, eta_floor, eta_ceiling);
520  MonitorElement *hPt_2_ByMuon = iBooker_.book1D(
521  "Pt_2_ByMuon", "Turn on as a Function of P_{t}, 1.2<|Eta|<2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
522  MonitorElement *hEta_2_ByMuon = iBooker_.book1D(
523  "Eta_2_ByMuon", "Efficiency as a Function of Eta, P_{t}>10, By Muon", eta_bins, eta_floor, eta_ceiling);
524  MonitorElement *hPt_3_ByMuon = iBooker_.book1D(
525  "Pt_3_ByMuon", "Turn on as a Function of P_{t}, |Eta|>2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
526  MonitorElement *hEta_3_ByMuon = iBooker_.book1D(
527  "Eta_3_ByMuon", "Efficiency as a Function of Eta, P_{t}>20, By Muon", eta_bins, eta_floor, eta_ceiling);
528 
529  for (int i = 1; i <= hPt_1_ByEvent->getNbinsX(); ++i) {
530  double n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonPt_1_ByEvent")->getBinContent(i);
531  double n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonPt_1_ByEvent")->getBinContent(i);
532  double value = (n2 != 0 ? n1 / n2 : 0);
533  double error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
534  hPt_1_ByEvent->setBinContent(i, value);
535  hPt_1_ByEvent->setBinError(i, error);
536 
537  n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonPt_2_ByEvent")->getBinContent(i);
538  n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonPt_2_ByEvent")->getBinContent(i);
539  value = (n2 != 0 ? n1 / n2 : 0);
540  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
541  hPt_2_ByEvent->setBinContent(i, value);
542  hPt_2_ByEvent->setBinError(i, error);
543 
544  n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonPt_3_ByEvent")->getBinContent(i);
545  n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonPt_3_ByEvent")->getBinContent(i);
546  value = (n2 != 0 ? n1 / n2 : 0);
547  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
548  hPt_3_ByEvent->setBinContent(i, value);
549  hPt_3_ByEvent->setBinError(i, error);
550 
551  n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonPt_1_ByMuon")->getBinContent(i);
552  n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonPt_1_ByMuon")->getBinContent(i);
553  value = (n2 != 0 ? n1 / n2 : 0);
554  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
555  hPt_1_ByMuon->setBinContent(i, value);
556  hPt_1_ByMuon->setBinError(i, error);
557 
558  n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonPt_2_ByMuon")->getBinContent(i);
559  n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonPt_2_ByMuon")->getBinContent(i);
560  value = (n2 != 0 ? n1 / n2 : 0);
561  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
562  hPt_2_ByMuon->setBinContent(i, value);
563  hPt_2_ByMuon->setBinError(i, error);
564 
565  n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonPt_3_ByMuon")->getBinContent(i);
566  n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonPt_3_ByMuon")->getBinContent(i);
567  value = (n2 != 0 ? n1 / n2 : 0);
568  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
569  hPt_3_ByMuon->setBinContent(i, value);
570  hPt_3_ByMuon->setBinError(i, error);
571  }
572 
573  for (int i = 1; i <= hEta_1_ByEvent->getNbinsX(); ++i) {
574  double n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonEta_1_ByEvent")->getBinContent(i);
575  double n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonEta_1_ByEvent")->getBinContent(i);
576  double value = (n2 != 0 ? n1 / n2 : 0);
577  double error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
578  hEta_1_ByEvent->setBinContent(i, value);
579  hEta_1_ByEvent->setBinError(i, error);
580 
581  n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonEta_2_ByEvent")->getBinContent(i);
582  n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonEta_2_ByEvent")->getBinContent(i);
583  value = (n2 != 0 ? n1 / n2 : 0);
584  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
585  hEta_2_ByEvent->setBinContent(i, value);
586  hEta_2_ByEvent->setBinError(i, error);
587 
588  n1 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadAssocRecoMuonEta_3_ByEvent")->getBinContent(i);
589  n2 = (double)iGetter_.get(subDir_ + byEventDir + "/LeadRecoMuonEta_3_ByEvent")->getBinContent(i);
590  value = (n2 != 0 ? n1 / n2 : 0);
591  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
592  hEta_3_ByEvent->setBinContent(i, value);
593  hEta_3_ByEvent->setBinError(i, error);
594 
595  n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonEta_1_ByMuon")->getBinContent(i);
596  n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonEta_1_ByMuon")->getBinContent(i);
597  value = (n2 != 0 ? n1 / n2 : 0);
598  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
599  hEta_1_ByMuon->setBinContent(i, value);
600  hEta_1_ByMuon->setBinError(i, error);
601 
602  n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonEta_2_ByMuon")->getBinContent(i);
603  n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonEta_2_ByMuon")->getBinContent(i);
604  value = (n2 != 0 ? n1 / n2 : 0);
605  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
606  hEta_2_ByMuon->setBinContent(i, value);
607  hEta_2_ByMuon->setBinError(i, error);
608 
609  n1 = (double)iGetter_.get(subDir_ + byMuonDir + "/AssocRecoMuonEta_3_ByMuon")->getBinContent(i);
610  n2 = (double)iGetter_.get(subDir_ + byMuonDir + "/RecoMuonEta_3_ByMuon")->getBinContent(i);
611  value = (n2 != 0 ? n1 / n2 : 0);
612  error = (n2 != 0 ? sqrt(value * (1 - value) / n2) : 0);
613  hEta_3_ByMuon->setBinContent(i, value);
614  hEta_3_ByMuon->setBinError(i, error);
615  }
616 }
617 
620  DQMStore::IBooker &iBooker_) {
621  MonitorElement *myEffME;
622  if (name == "Eff") {
623  myEffME = iBooker_.bookProfile((std::string)("Eff_" + ((std::string)histo->GetName())),
624  ((std::string)histo->GetTitle()),
625  histo->GetXaxis()->GetNbins(),
626  histo->GetXaxis()->GetXmin(),
627  histo->GetXaxis()->GetXmax(),
628  100,
629  0,
630  1,
631  "");
632  } else {
633  myEffME = iBooker_.bookProfile(name,
634  new TProfile(name.c_str(),
635  histo->GetTitle(),
636  histo->GetXaxis()->GetNbins(),
637  histo->GetXaxis()->GetXmin(),
638  histo->GetXaxis()->GetXmax()));
639  }
640  for (int i = 0; i < histo->GetXaxis()->GetNbins(); i++) {
641  myEffME->setBinLabel(i + 1, histo->GetXaxis()->GetBinLabel(i + 1), 1);
642  }
643  return myEffME;
644 }
645 
#define LogDebug(id)
TProfile * getTProfile() const
std::vector< std::string > mc_dirs
void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
TH1F * getTH1F() const
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:361
std::vector< edm::ParameterSet > mc_parametersets
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
T sqrt(T t)
Definition: SSEVec.h:18
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
HltSusyExoPostProcessor(const edm::ParameterSet &pset)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
Definition: value.py:1
std::vector< edm::ParameterSet > reco_parametersets
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
void setTitle(const std::string &title)
set (ie. change) histogram/profile title
std::vector< std::string > reco_dirs
std::string const & pwd()
Definition: DQMStore.cc:278
bool dirExists(std::string const &path)
Definition: DQMStore.cc:343
MonitorElement * bookEffMEProfileFromTH1(TH1F *, std::string, DQMStore::IBooker &)
double getBinContent(int binx) const
get content of bin (1-D)
HLT enums.
int getNbinsX() const
get # of bins in X-axis
void setBinEntries(int bin, double nentries)
set # of bin entries (to be used for profiles)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override