CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EmDQMPostProcessor.cc
Go to the documentation of this file.
2 
7 
8 
9 #include <iostream>
10 #include <string.h>
11 #include <iomanip>
12 #include <fstream>
13 #include <math.h>
14 
15 
17 {
18  subDir_ = pset.getUntrackedParameter<std::string>("subDir");
19 }
20 
22 {
24  // setup DQM stor //
26 
27  DQMStore * dqm = 0;
28  dqm = edm::Service<DQMStore>().operator->();
29 
30  if ( ! dqm ) {
31  edm::LogInfo("EmDQMPostProcessor") << "Cannot create DQMStore instance\n";
32  return;
33  }
34 
35 
36  //go to the directory to be processed
37  if(dqm->dirExists(subDir_)) dqm->cd(subDir_);
38  else {
39  edm::LogWarning("EmDQMPostProcessor") << "cannot find directory: " << subDir_ << " , skipping";
40  return;
41  }
42 
44  //loop over all triggers/samples//
46 
47  std::vector<std::string> subdirectories = dqm->getSubdirs();
48  for(std::vector<std::string>::iterator dir = subdirectories.begin() ;dir!= subdirectories.end(); dir++ ){
49  dqm->cd(*dir);
50 
51 
53  // Do everything twice: once for mc-matched histos, //
54  // once for unmatched histos //
56 
57  std::vector<std::string> postfixes;
58  std::string tmpstring=""; //unmatched histos
59  postfixes.push_back(tmpstring);
60  tmpstring="_MC_matched";
61  postfixes.push_back(tmpstring);
62 
63  for(std::vector<std::string>::iterator postfix=postfixes.begin(); postfix!=postfixes.end();postfix++){
64 
66  // computer per-event efficiencies //
68 
69  std::string histoName="efficiency_by_step"+ *postfix;
70  std::string baseName = "total_eff"+ *postfix;
71  MonitorElement* total = dqm->book1D(histoName.c_str(),dqm->get(dqm->pwd() + "/" + baseName)->getTH1F());
72  total->setTitle(histoName);
73 
74  // std::vector<std::string> mes = dqm->getMEs();
75  // for(std::vector<std::string>::iterator me = mes.begin() ;me!= mes.end(); me++ )
76  // std::cout <<*me <<std::endl;
77  // std::cout <<std::endl;
78 
79  float value=0;
80  float error=0;
81  //compute stepwise total efficiencies
82  for(int bin= total->getNbinsX()-2 ; bin > 1 ; bin--){
83  value=0;
84  error=0;
85  if(total->getBinContent(bin-1) != 0){
86  value = total->getBinContent(bin)/total->getBinContent(bin-1) ;
87  error = sqrt(value*(1-value)/total->getBinContent(bin-1));
88  }
89  total->setBinContent(bin,value);
90  total->setBinError(bin,error);
91  }
92 
93  //set first bin to L1 efficiency
94  if(total->getBinContent(total->getNbinsX()) !=0 ){
95  value = total->getBinContent(1)/total->getBinContent(total->getNbinsX()) ;
96  error = sqrt(value*(1-value)/total->getBinContent(total->getNbinsX()));
97  }else{
98  value=0;error=0;
99  }
100  total->setBinContent(1,value);
101  total->setBinError(1,error);
102 
103  //total efficiency relative to gen
104  if(total->getBinContent(total->getNbinsX()) !=0 ){
105  value = dqm->get(dqm->pwd() + "/" + baseName)->getBinContent(total->getNbinsX()-2)/total->getBinContent(total->getNbinsX()) ;
106  error = sqrt(value*(1-value)/total->getBinContent(total->getNbinsX()));
107  }else{
108  value=0;error=0;
109  }
110  total->setBinContent(total->getNbinsX(),value);
111  total->setBinError(total->getNbinsX(),error);
112  total->setBinLabel(total->getNbinsX(),"total efficiency rel. gen");
113 
114  //total efficiency relative to L1
115  if(total->getBinContent(total->getNbinsX()) !=0 ){
116  value = dqm->get(dqm->pwd() + "/" + baseName)->getBinContent(total->getNbinsX()-2)/dqm->get(dqm->pwd() + "/" + baseName)->getBinContent(1) ;
117  error = sqrt(value*(1-value)/dqm->get(dqm->pwd() + "/" + baseName)->getBinContent(1));
118  }else{
119  value=0;error=0;
120  }
121  total->setBinContent(total->getNbinsX()-1,value);
122  total->setBinError(total->getNbinsX()-1,error);
123  total->setBinLabel(total->getNbinsX()-1,"total efficiency rel. L1");
124 
125  total->getTH1F()->SetMaximum(1.2);
126  total->getTH1F()->SetMinimum(0);
127 
129  // compute per-object efficiencies //
131  MonitorElement *eff, *num, *denom, *genPlot, *effVsGen, *effL1VsGen;
132  std::vector<std::string> varNames;
133  varNames.push_back("eta");
134  varNames.push_back("phi");
135  varNames.push_back("et");
136 
137  std::string filterName;
138  std::string filterName2;
139  std::string denomName;
140  std::string numName;
141 
142  // Get the gen-level plots
143  std::string genName;
144 
145  // Get the L1 over gen filter first
146  filterName2= total->getTH1F()->GetXaxis()->GetBinLabel(1);
147 
148  //loop over variables (eta/phi/et)
149  for(std::vector<std::string>::iterator var = varNames.begin(); var != varNames.end() ; var++){
150  numName = dqm->pwd() + "/" + filterName2 + *var + *postfix;
151  genName = dqm->pwd() + "/gen_" + *var ;
152  num = dqm->get(numName);
153  genPlot = dqm->get(genName);
154  effL1VsGen = dqm->book1D("efficiency_"+filterName2+"_vs_"+*var +*postfix, dqm->get(numName)->getTH1F());
155 
156  // Check if histograms actually exist
157  if(!num || !genPlot) break;
158 
159  // Make sure we are able to book new element
160  if (!dqm) break;
161 
162  // Create the efficiency plot
163  effL1VsGen->setTitle("efficiency_"+filterName2+"_vs_"+*var + *postfix);
164  effL1VsGen->getTH1F()->SetMaximum(1.2);
165  effL1VsGen->getTH1F()->SetMinimum(0);
166  effL1VsGen->getTH1F()->GetXaxis()->SetTitle(var->c_str());
167  effL1VsGen->getTH1F()->Divide(num->getTH1F(),genPlot->getTH1F(),1,1,"b" );
168  }
169 
170  // get the filter names from the bin-labels of the master-histogram
171  for (int filter=1; filter < total->getNbinsX()-2; filter++) {
172  filterName = total->getTH1F()->GetXaxis()->GetBinLabel(filter);
173  filterName2= total->getTH1F()->GetXaxis()->GetBinLabel(filter+1);
174 
175  //loop over variables (eta/et)
176  for(std::vector<std::string>::iterator var = varNames.begin(); var != varNames.end() ; var++){
177  numName = dqm->pwd() + "/" + filterName2 + *var + *postfix;
178  denomName = dqm->pwd() + "/" + filterName + *var + *postfix;
179  num = dqm->get(numName);
180  denom = dqm->get(denomName);
181 
182  // Check if histograms actually exist
183  if(!num || !denom) break;
184 
185  // Make sure we are able to book new element
186  if (!dqm) break;
187 
188  // Is this the last filter? Book efficiency vs gen level
189  std::string temp = *postfix;
190  if (filter==total->getNbinsX()-3 && temp.find("matched")!=std::string::npos) {
191  genName = dqm->pwd() + "/gen_" + *var;
192  genPlot = dqm->get(genName);
193  effVsGen = dqm->book1D("final_eff_vs_"+*var, dqm->get(genName)->getTH1F());
194  if (!dqm) break;
195 
196  effVsGen->setTitle("Efficiency Compared to Gen vs "+*var);
197  effVsGen->getTH1F()->SetMaximum(1.2); effVsGen->getTH1F()->SetMinimum(0.0);
198  effVsGen->getTH1F()->GetXaxis()->SetTitle(var->c_str());
199  effVsGen->getTH1F()->Divide(num->getTH1F(),genPlot->getTH1F(),1,1,"b" );
200  }
201 
202  eff = dqm->book1D("efficiency_"+filterName2+"_vs_"+*var +*postfix, dqm->get(numName)->getTH1F());
203 
204  // Make sure we were able to book new element
205  if (!dqm) break;
206 
207  // Create the efficiency plot
208  /* num->getTH1F()->Sumw2();
209  denom->getTH1F()->Sumw2();
210  eff->getTH1F()->Sumw2(); */
211 
212  eff->setTitle("efficiency_"+filterName2+"_vs_"+*var + *postfix);
213  eff->getTH1F()->SetMaximum(1.2);
214  eff->getTH1F()->SetMinimum(0);
215  eff->getTH1F()->GetXaxis()->SetTitle(var->c_str());
216  eff->getTH1F()->Divide(num->getTH1F(),denom->getTH1F(),1,1,"b" );
217  }
218  }
219  }
220  dqm->goUp();
221  }
222 
223 }
T getUntrackedParameter(std::string const &, T const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1221
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:519
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:214
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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 endRun(edm::Run const &, edm::EventSetup const &)
T sqrt(T t)
Definition: SSEVec.h:28
TH1F * getTH1F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
tuple pset
Definition: CrabTask.py:85
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1270
EmDQMPostProcessor(const edm::ParameterSet &pset)
void setTitle(const std::string &title)
set (ie. change) histogram/profile title
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:301
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
TH1F * getTH1F(void) const
long long int num
Definition: procUtils.cc:71
double getBinContent(int binx) const
get content of bin (1-D)
int getNbinsX(void) const
get # of bins in X-axis
void goUp(void)
equivalent to &quot;cd ..&quot;
Definition: DQMStore.cc:248
dbl *** dir
Definition: mlp_gen.cc:35
Definition: Run.h:31
const std::string & pwd(void) const
Definition: DQMStore.cc:209