14 #include <TEfficiency.h>
41 edm::LogInfo(
"EmDQMPostProcessor") <<
"Cannot create DQMStore instance\n";
55 std::string shortReferenceName;
57 shortReferenceName =
"RECO";
59 shortReferenceName =
"gen";
83 std::vector<std::string> subdirectories = dqm->
getSubdirs();
89 std::vector<std::string> postfixes;
90 postfixes.push_back(
"");
91 postfixes.push_back(
"_RECO_matched");
96 postfixes.push_back(
"_MC_matched");
98 std::vector<TProfile *> allElePaths;
103 for(std::vector<std::string>::iterator
dir = subdirectories.begin() ;
dir!= subdirectories.end(); ++
dir) {
104 if (
dir->find(
"HLT_Ele") != std::string::npos ||
dir->find(
"HLT_DoubleEle") != std::string::npos ||
dir->find(
"HLT_TripleEle") != std::string::npos) ++nEle;
105 else if (
dir->find(
"HLT_Photon") != std::string::npos ||
dir->find(
"HLT_DoublePhoton") != std::string::npos) ++nPhoton;
108 std::vector<TProfile *> allPhotonPaths;
109 for(std::vector<std::string>::iterator postfix=postfixes.begin(); postfix!=postfixes.end();postfix++){
118 std::string histoName =
"efficiency_by_step" + *postfix;
119 std::string baseName =
"total_eff" + *postfix;
121 std::string allEleHistoName =
"EfficiencyByPath_Ele" + *postfix;
122 std::string allEleHistoLabel =
"Efficiency_for_each_validated_electron_path" + *postfix;
123 allElePaths.push_back(
new TProfile(allEleHistoName.c_str(), allEleHistoLabel.c_str(), nEle, 0., (double)nEle, 0., 1.2));
124 std::string allPhotonHistoName =
"EfficiencyByPath_Photon" + *postfix;
125 std::string allPhotonHistoLabel =
"Efficiency_for_each_validated_photon_path" + *postfix;
126 allPhotonPaths.push_back(
new TProfile(allPhotonHistoName.c_str(), allPhotonHistoLabel.c_str(), nPhoton, 0., (double)nPhoton, 0., 1.2));
128 for(std::vector<std::string>::iterator
dir = subdirectories.begin();
dir!= subdirectories.end();
dir++) {
132 if (basehist ==
NULL)
142 TProfile*
total = dqm->
bookProfile(histoName,histoName,basehist->GetXaxis()->GetNbins(),basehist->GetXaxis()->GetXmin(),basehist->GetXaxis()->GetXmax(),0.,1.2)->
getTProfile();
143 total->GetXaxis()->SetBinLabel(1,basehist->GetXaxis()->GetBinLabel(1));
151 double errorh=0,errorl=0,
error=0;
153 for(
int bin= total->GetNbinsX()-2 ;
bin > 1 ;
bin--){
158 if(basehist->GetBinContent(
bin-1) != 0){
159 Efficiency( (
int)basehist->GetBinContent(
bin), (int)basehist->GetBinContent(
bin-1), 0.683,
value, errorl, errorh );
160 error = value-errorl>errorh-value ? value-errorl : errorh-
value;
162 total->SetBinContent(
bin, value );
163 total->SetBinEntries(
bin, 1 );
165 total->GetXaxis()->SetBinLabel(
bin,basehist->GetXaxis()->GetBinLabel(
bin));
169 if(basehist->GetBinContent(basehist->GetNbinsX()) !=0 ){
170 Efficiency( (
int)basehist->GetBinContent(1), (int)basehist->GetBinContent(basehist->GetNbinsX()), 0.683, value, errorl, errorh );
171 error= value-errorl>errorh-value ? value-errorl : errorh-
value;
175 total->SetBinContent(1,value);
176 total->SetBinEntries(1, 1 );
180 if(basehist->GetBinContent(basehist->GetNbinsX()) !=0 ){
181 Efficiency( (
int)basehist->GetBinContent(basehist->GetNbinsX()-2), (
int)basehist->GetBinContent(basehist->GetNbinsX()), 0.683, value, errorl, errorh );
182 error= value-errorl>errorh-value ? value-errorl : errorh-
value;
186 total->SetBinContent(total->GetNbinsX(),
value);
187 total->SetBinEntries(total->GetNbinsX(),1);
188 total->SetBinError(total->GetNbinsX(),
sqrt(value*value+error*error));
189 total->GetXaxis()->SetBinLabel(total->GetNbinsX(),(
"total efficiency rel. " + shortReferenceName).c_str());
192 if(basehist->GetBinContent(1) !=0 ){
193 Efficiency( (
int)basehist->GetBinContent(basehist->GetNbinsX()-2), (
int)basehist->GetBinContent(1), 0.683,
value, errorl, errorh );
194 error= value-errorl > errorh-value ? value-errorl : errorh-
value;
198 total->SetBinContent(total->GetNbinsX()-1,
value);
199 total->SetBinError(total->GetNbinsX()-1,
sqrt(value*value+error*error));
200 total->SetBinEntries(total->GetNbinsX()-1,1);
201 total->GetXaxis()->SetBinLabel(total->GetNbinsX()-1,
"total efficiency rel. L1");
210 varNames.push_back(
"et");
211 varNames.push_back(
"eta");
215 std::string filterName2;
216 std::string denomName;
223 filterName2= total->GetXaxis()->GetBinLabel(1);
226 for(std::vector<std::string>::iterator var = varNames.begin(); var != varNames.end() ; var++){
228 numName = dqm->
pwd() +
"/" + filterName2 + *var + *postfix;
231 genName = dqm->
pwd() +
"/reco_" + *var ;
233 genName = dqm->
pwd() +
"/gen_" + *var ;
236 if(!
dividehistos(dqm,numName,genName,
"efficiency_"+filterName2+
"_vs_"+*var +*postfix,*var,
"eff. of"+filterName2+
" vs "+*var +*postfix))
242 filterName = total->GetXaxis()->GetBinLabel(
filter);
243 filterName2= total->GetXaxis()->GetBinLabel(
filter+1);
246 for(std::vector<std::string>::iterator var = varNames.begin(); var != varNames.end() ; var++){
247 numName = dqm->
pwd() +
"/" + filterName2 + *var + *postfix;
248 denomName = dqm->
pwd() +
"/" + filterName + *var + *postfix;
251 std::string
temp = *postfix;
252 if (
filter==total->GetNbinsX()-3 && temp.find(
"matched")!=std::string::npos) {
254 genName = dqm->
pwd() +
"/reco_" + *var;
256 genName = dqm->
pwd() +
"/gen_" + *var;
258 if(!
dividehistos(dqm,numName,genName,
"final_eff_vs_"+*var,*var,
"Efficiency Compared to " + shortReferenceName +
" vs "+*var))
262 if(!
dividehistos(dqm,numName,denomName,
"efficiency_"+filterName2+
"_vs_"+*var +*postfix,*var,
"efficiency_"+filterName2+
"_vs_"+*var + *postfix))
271 std::string trigName =
dir->substr(
dir->rfind(
"/") + 1);
272 trigName = trigName.replace(trigName.rfind(
"_DQM"),4,
"");
273 double totCont = total->GetBinContent(total->GetNbinsX());
274 double totErr = total->GetBinError(total->GetNbinsX());
275 if (trigName.find(
"HLT_Ele") != std::string::npos || trigName.find(
"HLT_DoubleEle") != std::string::npos || trigName.find(
"HLT_TripleEle") != std::string::npos) {
276 allElePaths.back()->SetBinContent(elePos, totCont);
277 allElePaths.back()->SetBinEntries(elePos, 1);
278 allElePaths.back()->SetBinError(elePos,
sqrt(totCont * totCont + totErr * totErr));
279 allElePaths.back()->GetXaxis()->SetBinLabel(elePos, trigName.c_str());
282 else if (trigName.find(
"HLT_Photon") != std::string::npos || trigName.find(
"HLT_DoublePhoton") != std::string::npos) {
283 allPhotonPaths.back()->SetBinContent(photonPos, totCont);
284 allPhotonPaths.back()->SetBinEntries(photonPos, 1);
285 allPhotonPaths.back()->SetBinError(photonPos,
sqrt(totCont * totCont + totErr * totErr));
286 allPhotonPaths.back()->GetXaxis()->SetBinLabel(photonPos, trigName.c_str());
292 allElePaths.pop_back();
293 allPhotonPaths.pop_back();
296 allElePaths.back()->GetXaxis()->SetLabelSize(0.03);
297 allPhotonPaths.back()->GetXaxis()->SetLabelSize(0.03);
316 edm::LogWarning(
"EmDQMPostProcessor") <<
"numerator histogram " << numName <<
" does not exist";
319 edm::LogWarning(
"EmDQMPostProcessor") <<
"denominator histogram " << denomName <<
" does not exist";
323 if(!num || !denom)
return 0;
328 TProfile*
out = dqm->
bookProfile(outName,titel,num->GetXaxis()->GetNbins(),num->GetXaxis()->GetXmin(),num->GetXaxis()->GetXmax(),0.,1.2)->
getTProfile();
329 out->GetXaxis()->SetTitle(label.c_str());
330 out->SetYTitle(
"Efficiency");
331 out->SetOption(
"PE");
332 out->SetLineColor(2);
333 out->SetLineWidth(2);
334 out->SetMarkerStyle(20);
335 out->SetMarkerSize(0.8);
336 out->SetStats(kFALSE);
337 for(
int i=1;
i<=num->GetNbinsX();
i++){
339 Efficiency( (
int)num->GetBinContent(
i), (int)denom->GetBinContent(
i), 0.683,
e, low, high );
340 double err = e-low>high-e ? e-low : high-
e;
342 out->SetBinContent(
i, e );
343 out->SetBinEntries(
i, 1 );
344 out->SetBinError(
i,
sqrt(e*e+err*err) );
356 if (monElement !=
NULL)
376 mode = passing / ((double) total);
384 lowerBound = TEfficiency::Wilson(total, passing, level,
false);
385 upperBound = TEfficiency::Wilson(total, passing, level,
true);
T getUntrackedParameter(std::string const &, T const &) const
TProfile * getTProfile(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
std::vector< std::string > getSubdirs(void) const
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
void cd(void)
go to top directory (ie. root)
#define DEFINE_FWK_MODULE(type)
void endRun(edm::Run const &, edm::EventSetup const &)
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
EmDQMPostProcessor(const edm::ParameterSet &pset)
bool dirExists(const std::string &path) const
true if directory exists
TH1F * getTH1F(void) const
TProfile * getTProfile(void) const
void goUp(void)
equivalent to "cd .."
TH1F * getHistogram(DQMStore *dqm, const std::string &histoPath)
static void Efficiency(int passing, int total, double level, double &mode, double &lowerBound, double &upperBound)
const std::string & pwd(void) const
TProfile * dividehistos(DQMStore *dqm, const std::string &num, const std::string &denom, const std::string &out, const std::string &label, const std::string &titel="")