CMS 3D CMS Logo

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