CMS 3D CMS Logo

EmDQMPostProcessor.cc

Go to the documentation of this file.
00001 
00002 #include "HLTriggerOffline/Egamma/interface/EmDQMPostProcessor.h"
00003 
00004 #include "DQMServices/Core/interface/DQMStore.h"
00005 #include "DQMServices/Core/interface/MonitorElement.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 
00009 
00010 #include <iostream>
00011 #include <string.h>
00012 #include <iomanip>
00013 #include<fstream>
00014 #include <math.h>
00015 
00016 
00017 EmDQMPostProcessor::EmDQMPostProcessor(const edm::ParameterSet& pset)
00018 {
00019   subDir_ = pset.getUntrackedParameter<std::string>("subDir");
00020 }
00021 
00022 void EmDQMPostProcessor::endRun(edm::Run const& run, edm::EventSetup const& es)
00023 {
00025   // setup DQM stor               //
00027   
00028   DQMStore * dqm = 0;
00029   dqm = edm::Service<DQMStore>().operator->();
00030 
00031   if ( ! dqm ) {
00032     edm::LogInfo("EmDQMPostProcessor") << "Cannot create DQMStore instance\n";
00033     return;
00034   }
00035 
00036 
00037   //go to the directory to be processed
00038   if(dqm->dirExists(subDir_)) dqm->cd(subDir_);
00039   else {
00040     edm::LogWarning("EmDQMPostProcessor") << "cannot find directory: " << subDir_ << " , skipping";
00041     return;
00042   }
00043 
00045   //loop over all triggers/samples//
00047 
00048   std::vector<std::string> subdirectories = dqm->getSubdirs();
00049   for(std::vector<std::string>::iterator dir = subdirectories.begin() ;dir!= subdirectories.end(); dir++ ){
00050     dqm->cd(*dir);
00051 
00053     // computer per-event efficiencies //
00055 
00056     MonitorElement* total = dqm->book1D("efficiency by step",dqm->get(dqm->pwd() + "/total eff")->getTH1F());
00057     total->setTitle("efficiency by step");
00058 
00059 //     std::vector<std::string> mes = dqm->getMEs();
00060 //     for(std::vector<std::string>::iterator me = mes.begin() ;me!= mes.end(); me++ )
00061 //       std::cout <<*me <<std::endl;
00062 //     std::cout <<std::endl;
00063 
00064     float value=0;
00065     float error=0;    
00066     //compute stepwise total efficiencies 
00067     for(int bin= total->getNbinsX()-2 ; bin > 1  ; bin--){
00068       value=0;
00069       error=0;
00070       if(total->getBinContent(bin-1) != 0){
00071         value = total->getBinContent(bin)/total->getBinContent(bin-1) ;
00072         error = sqrt(value*(1-value)/total->getBinContent(bin-1));
00073       }
00074       total->setBinContent(bin,value);
00075       total->setBinError(bin,error);
00076     }
00077     
00078     //set first bin to L1 efficiency
00079     if(total->getBinContent(total->getNbinsX()) !=0 ){
00080         value = total->getBinContent(1)/total->getBinContent(total->getNbinsX()) ;
00081         error = sqrt(value*(1-value)/total->getBinContent(total->getNbinsX()));
00082     }else{
00083       value=0;error=0;
00084     }
00085     total->setBinContent(1,value);
00086     total->setBinError(1,error);
00087     
00088     //total efficiency relative to gen
00089     if(total->getBinContent(total->getNbinsX()) !=0 ){
00090         value = dqm->get(dqm->pwd() + "/total eff")->getBinContent(total->getNbinsX()-2)/total->getBinContent(total->getNbinsX()) ;
00091         error = sqrt(value*(1-value)/total->getBinContent(total->getNbinsX()));
00092     }else{
00093       value=0;error=0;
00094     }
00095     total->setBinContent(total->getNbinsX(),value);
00096     total->setBinError(total->getNbinsX(),error);
00097     total->setBinLabel(total->getNbinsX(),"total efficiency rel. gen");
00098 
00099     //total efficiency relative to L1
00100     if(total->getBinContent(total->getNbinsX()) !=0 ){
00101         value = dqm->get(dqm->pwd() + "/total eff")->getBinContent(total->getNbinsX()-2)/dqm->get(dqm->pwd() + "/total eff")->getBinContent(1) ;
00102         error = sqrt(value*(1-value)/dqm->get(dqm->pwd() + "/total eff")->getBinContent(1));
00103     }else{
00104       value=0;error=0;
00105     }
00106     total->setBinContent(total->getNbinsX()-1,value);
00107     total->setBinError(total->getNbinsX()-1,error);
00108     total->setBinLabel(total->getNbinsX()-1,"total efficiency rel. L1");
00109 
00110     total->getTH1F()->SetMaximum(1.2);
00111     total->getTH1F()->SetMinimum(0);
00112 
00114     // compute per-object efficiencies       //
00116     MonitorElement *eff,*num,*denom;
00117     std::vector<std::string> varnames; varnames.push_back("eta"); varnames.push_back("et");
00118     std::string filtername;      
00119     std::string filtername2;
00120     std::string denomname;
00121     std::string numname;
00122     // get the filter names from the bin-labels of the master-histogram
00123     for(int filter=1;filter < total->getNbinsX()-2; filter++){
00124       filtername = total->getTH1F()->GetXaxis()->GetBinLabel(filter);
00125       filtername2= total->getTH1F()->GetXaxis()->GetBinLabel(filter+1);
00126 
00127       //loop over variables (eta/et)
00128       for(std::vector<std::string>::iterator var = varnames.begin(); var != varnames.end() ; var++){
00129         numname  = dqm->pwd() + "/"+ filtername2 + *var;
00130         denomname= dqm->pwd() + "/"+ filtername + *var;
00131         num   =dqm->get(numname);
00132         denom =dqm->get(denomname);
00133         if(!num || !denom) break; // dont try to devide if the histos aren't there
00134         eff = dqm->book1D("efficiency "+filtername2+" vs "+*var,dqm->get(numname)->getTH1F());
00135         if(!dqm) break; // couldnt create new element => don't fill it;
00136         eff->setTitle("efficiency "+filtername2+"vs "+*var);
00137         eff->getTH1F()->SetMaximum(1.2);
00138         eff->getTH1F()->SetMinimum(0);
00139         eff->getTH1F()->GetXaxis()->SetTitle(var->c_str());
00140         eff->getTH1F()->Divide(num->getTH1F(),denom->getTH1F(),1,1,"b" );
00141       }
00142     }
00143 
00144     dqm->goUp();
00145   }
00146   
00147 }
00148 DEFINE_FWK_MODULE(EmDQMPostProcessor);

Generated on Tue Jun 9 17:38:02 2009 for CMSSW by  doxygen 1.5.4