CMS 3D CMS Logo

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