CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/HLTEvF/src/HLTTauDQMSummaryPlotter.cc

Go to the documentation of this file.
00001 #include "DQM/HLTEvF/interface/HLTTauDQMSummaryPlotter.h"
00002 #include <math.h>
00003 HLTTauDQMSummaryPlotter::HLTTauDQMSummaryPlotter(const edm::ParameterSet& iConfig):
00004   L1Folder_(iConfig.getParameter<std::vector<std::string> >("L1Dirs")),
00005   caloFolder_(iConfig.getParameter<std::vector<std::string> >("caloDirs")),
00006   trackFolder_(iConfig.getParameter<std::vector<std::string> >("trackDirs")),
00007   pathFolder_(iConfig.getParameter<std::vector< std::string> >("pathDirs")),
00008   litePathFolder_(iConfig.getParameter<std::vector< std::string> >("pathSummaryDirs"))
00009 
00010 {
00011   dbe = 0;
00012   dbe = edm::Service<DQMStore>().operator->();
00013 
00014   if (dbe) {
00015 
00016     //Path Summary 
00017     for(size_t i=0;i<pathFolder_.size();++i)
00018     if(pathFolder_[i].size()>0)
00019       {
00020         bookTriggerBitEfficiencyHistos(pathFolder_[i],"MatchedTriggerBits",dbe);
00021       }
00022 
00023     //Lite Path Summary 
00024     for(size_t i=0;i<litePathFolder_.size();++i)
00025     if(litePathFolder_[i].size()>0)
00026       {
00027         bookEfficiencyHisto(litePathFolder_[i],"PathEfficiency","MatchedPathTriggerBits",dbe);
00028         bookEfficiencyHisto(litePathFolder_[i],"TrigTauEtEff","TrigTauEtEffNum",dbe);
00029         bookEfficiencyHisto(litePathFolder_[i],"TrigTauEtaEff","TrigTauEtaEffNum",dbe);
00030         bookEfficiencyHisto(litePathFolder_[i],"TrigTauPhiEff","TrigTauPhiEffNum",dbe);
00031       }
00032 
00033     //L1 Summary
00034     for(size_t i=0;i<L1Folder_.size();++i)
00035     if(L1Folder_[i].size()>0)
00036       {
00037         bookEfficiencyHisto(L1Folder_[i],"L1TauEtEff","EfficiencyHelpers/L1TauEtEffNum",dbe);
00038         bookEfficiencyHisto(L1Folder_[i],"L1TauEtaEff","EfficiencyHelpers/L1TauEtaEffNum",dbe);
00039         bookEfficiencyHisto(L1Folder_[i],"L1TauPhiEff","EfficiencyHelpers/L1TauPhiEffNum",dbe);
00040 
00041         bookEfficiencyHisto(L1Folder_[i],"L1JetEtEff","EfficiencyHelpers/L1JetEtEffNum",dbe);
00042         bookEfficiencyHisto(L1Folder_[i],"L1JetEtaEff","EfficiencyHelpers/L1JetEtaEffNum",dbe);
00043         bookEfficiencyHisto(L1Folder_[i],"L1JetPhiEff","EfficiencyHelpers/L1JetPhiEffNum",dbe);
00044 
00045         bookEfficiencyHisto(L1Folder_[i],"L1SingleTauEff","L1LeadTauEt",dbe);
00046         bookEfficiencyHisto(L1Folder_[i],"L1DoubleTauEff","L1SecondTauEt",dbe);
00047 
00048       }
00049 
00050 
00051     //L2 Summary
00052     for(size_t i=0;i<caloFolder_.size();++i)
00053     if(caloFolder_[i].size()>0)
00054       {
00055         bookEfficiencyHisto(caloFolder_[i],"L2RecoTauEtEff","EfficiencyHelpers/L2RecoTauEtEffNum",dbe);
00056         bookEfficiencyHisto(caloFolder_[i],"L2RecoTauEtaEff","EfficiencyHelpers/L2RecoTauEtaEffNum",dbe);
00057         bookEfficiencyHisto(caloFolder_[i],"L2RecoTauPhiEff","EfficiencyHelpers/L2RecoTauPhiEffNum",dbe);
00058 
00059         bookEfficiencyHisto(caloFolder_[i],"L2IsoTauEtEff","EfficiencyHelpers/L2IsoTauEtEffNum",dbe);
00060         bookEfficiencyHisto(caloFolder_[i],"L2IsoTauEtaEff","EfficiencyHelpers/L2IsoTauEtaEffNum",dbe);
00061         bookEfficiencyHisto(caloFolder_[i],"L2IsoTauPhiEff","EfficiencyHelpers/L2IsoTauPhiEffNum",dbe);
00062       }
00063 
00064     //L25/3 Summary
00065     for(size_t i=0;i<trackFolder_.size();++i)
00066     if(trackFolder_[i].size()>0)
00067       {
00068         bookEfficiencyHisto(trackFolder_[i],"L25TauEtEff","L25TauEtEffNum",dbe);
00069         bookEfficiencyHisto(trackFolder_[i],"L25TauEtaEff","L25TauEtaEffNum",dbe);
00070         bookEfficiencyHisto(trackFolder_[i],"L25TauPhiEff","L25TauPhiEffNum",dbe);
00071         bookEfficiencyHisto(trackFolder_[i],"L3TauEtEff","L3TauEtEffNum",dbe);
00072         bookEfficiencyHisto(trackFolder_[i],"L3TauEtaEff","L3TauEtaEffNum",dbe);
00073         bookEfficiencyHisto(trackFolder_[i],"L3TauPhiEff","L3TauPhiEffNum",dbe);
00074       }
00075   }
00076 
00077   
00078 }
00079 
00080 HLTTauDQMSummaryPlotter::~HLTTauDQMSummaryPlotter() {}
00081 
00082 
00083 void 
00084 HLTTauDQMSummaryPlotter::plot()
00085 {
00086   if (dbe) {
00087 
00088     //Path Summary
00089     for(size_t i=0;i<pathFolder_.size();++i)
00090     if(pathFolder_[i].size()>0)
00091       {
00092         plotTriggerBitEfficiencyHistos(pathFolder_[i],"MatchedTriggerBits",dbe);
00093       }
00094 
00095 
00096     //Lite Path Summary 
00097     for(size_t i=0;i<litePathFolder_.size();++i)
00098     if(litePathFolder_[i].size()>0)
00099       {
00100         plotEfficiencyHisto(litePathFolder_[i],"PathEfficiency","MatchedPathTriggerBits","RefEvents",dbe);
00101         plotEfficiencyHisto(litePathFolder_[i],"TrigTauEtEff","TrigTauEtEffNum","TrigTauEtEffDenom",dbe);
00102         plotEfficiencyHisto(litePathFolder_[i],"TrigTauEtaEff","TrigTauEtaEffNum","TrigTauEtaEffDenom",dbe);
00103         plotEfficiencyHisto(litePathFolder_[i],"TrigTauPhiEff","TrigTauPhiEffNum","TrigTauPhiEffDenom",dbe);
00104       }
00105 
00106     //L1 Summary
00107     for(size_t i=0;i<L1Folder_.size();++i)
00108     if(L1Folder_[i].size()>0)
00109       {
00110         plotEfficiencyHisto(L1Folder_[i],"L1TauEtEff","EfficiencyHelpers/L1TauEtEffNum","EfficiencyHelpers/L1TauEtEffDenom",dbe);
00111         plotEfficiencyHisto(L1Folder_[i],"L1TauEtaEff","EfficiencyHelpers/L1TauEtaEffNum","EfficiencyHelpers/L1TauEtaEffDenom",dbe);
00112         plotEfficiencyHisto(L1Folder_[i],"L1TauPhiEff","EfficiencyHelpers/L1TauPhiEffNum","EfficiencyHelpers/L1TauPhiEffDenom",dbe);
00113 
00114         plotEfficiencyHisto(L1Folder_[i],"L1JetEtEff","EfficiencyHelpers/L1JetEtEffNum","EfficiencyHelpers/L1JetEtEffDenom",dbe);
00115         plotEfficiencyHisto(L1Folder_[i],"L1JetEtaEff","EfficiencyHelpers/L1JetEtaEffNum","EfficiencyHelpers/L1JetEtaEffDenom",dbe);
00116         plotEfficiencyHisto(L1Folder_[i],"L1JetPhiEff","EfficiencyHelpers/L1JetPhiEffNum","EfficiencyHelpers/L1JetPhiEffDenom",dbe);
00117 
00118         plotEfficiencyHisto(L1Folder_[i],"L1ElectronEtEff","EfficiencyHelpers/L1ElectronEtEffNum","EfficiencyHelpers/L1ElectronEtEffDenom",dbe);
00119         plotEfficiencyHisto(L1Folder_[i],"L1ElectronEtaEff","EfficiencyHelpers/L1ElectronEtaEffNum","EfficiencyHelpers/L1ElectronEtaEffDenom",dbe);
00120         plotEfficiencyHisto(L1Folder_[i],"L1ElectronPhiEff","EfficiencyHelpers/L1ElectronPhiEffNum","EfficiencyHelpers/L1ElectronPhiEffDenom",dbe);
00121 
00122         plotEfficiencyHisto(L1Folder_[i],"L1MuonEtEff","EfficiencyHelpers/L1MuonEtEffNum","EfficiencyHelpers/L1MuonEtEffDenom",dbe);
00123         plotEfficiencyHisto(L1Folder_[i],"L1MuonEtaEff","EfficiencyHelpers/L1MuonEtaEffNum","EfficiencyHelpers/L1MuonEtaEffDenom",dbe);
00124         plotEfficiencyHisto(L1Folder_[i],"L1MuonPhiEff","EfficiencyHelpers/L1MuonPhiEffNum","EfficiencyHelpers/L1MuonPhiEffDenom",dbe);
00125 
00126         plotIntegratedEffHisto(L1Folder_[i],"L1SingleTauEff","L1LeadTauEt","InputEvents",1,dbe);
00127         plotIntegratedEffHisto(L1Folder_[i],"L1DoubleTauEff","L1SecondTauEt","InputEvents",2,dbe);
00128       }
00129 
00130     //L2 Summary
00131     for(size_t i=0;i<caloFolder_.size();++i)
00132     if(caloFolder_[i].size()>0)
00133       {
00134         plotEfficiencyHisto(caloFolder_[i],"L2RecoTauEtEff","EfficiencyHelpers/L2RecoTauEtEffNum","EfficiencyHelpers/L2RecoTauEtEffDenom",dbe);
00135         plotEfficiencyHisto(caloFolder_[i],"L2RecoTauEtaEff","EfficiencyHelpers/L2RecoTauEtaEffNum","EfficiencyHelpers/L2RecoTauEtaEffDenom",dbe);
00136         plotEfficiencyHisto(caloFolder_[i],"L2RecoTauPhiEff","EfficiencyHelpers/L2RecoTauPhiEffNum","EfficiencyHelpers/L2RecoTauPhiEffDenom",dbe);
00137 
00138         plotEfficiencyHisto(caloFolder_[i],"L2IsoTauEtEff","EfficiencyHelpers/L2IsoTauEtEffNum","EfficiencyHelpers/L2IsoTauEtEffDenom",dbe);
00139         plotEfficiencyHisto(caloFolder_[i],"L2IsoTauEtaEff","EfficiencyHelpers/L2IsoTauEtaEffNum","EfficiencyHelpers/L2IsoTauEtaEffDenom",dbe);
00140         plotEfficiencyHisto(caloFolder_[i],"L2IsoTauPhiEff","EfficiencyHelpers/L2IsoTauPhiEffNum","EfficiencyHelpers/L2IsoTauPhiEffDenom",dbe);
00141       }
00142 
00143 
00144     //L25/3 Summary
00145     for(size_t i=0;i<trackFolder_.size();++i)
00146     if(trackFolder_[i].size()>0)
00147       {
00148         plotEfficiencyHisto(trackFolder_[i],"L25TauEtEff","L25TauEtEffNum","L25TauEtEffDenom",dbe);
00149         plotEfficiencyHisto(trackFolder_[i],"L25TauEtaEff","L25TauEtaEffNum","L25TauEtaEffDenom",dbe);
00150         plotEfficiencyHisto(trackFolder_[i],"L25TauPhiEff","L25TauPhiEffNum","L25TauPhiEffDenom",dbe);
00151         plotEfficiencyHisto(trackFolder_[i],"L3TauEtEff","L3TauEtEffNum","L3TauEtEffDenom",dbe);
00152         plotEfficiencyHisto(trackFolder_[i],"L3TauEtaEff","L3TauEtaEffNum","L3TauEtaEffDenom",dbe);
00153         plotEfficiencyHisto(trackFolder_[i],"L3TauPhiEff","L3TauPhiEffNum","L3TauPhiEffDenom",dbe);
00154 
00155       }
00156   }
00157 }      
00158 
00159 
00160 
00161 void 
00162 HLTTauDQMSummaryPlotter::bookEfficiencyHisto(std::string folder,std::string name,std::string hist1,DQMStore* dbe)
00163 {
00164   if(dbe->dirExists(folder))
00165   {
00166     MonitorElement * effnum = dbe->get(folder+"/"+hist1);
00167     
00168     if(effnum)
00169       {
00170         dbe->setCurrentFolder(folder);
00171         MonitorElement *tmp = dbe->bookProfile(name,name,effnum->getTH1F()->GetNbinsX(),effnum->getTH1F()->GetXaxis()->GetXmin(),effnum->getTH1F()->GetXaxis()->GetXmax(),105,0,1.05);
00172 
00173         tmp->setTitle(name);
00174       }
00175   }
00176 }
00177 
00178 
00179 
00180 
00181 void 
00182 HLTTauDQMSummaryPlotter::plotEfficiencyHisto(std::string folder,std::string name,std::string hist1,std::string hist2,DQMStore* dbe)
00183 {
00184   if(dbe->dirExists(folder))
00185   {
00186     MonitorElement * effnum = dbe->get(folder+"/"+hist1);
00187     MonitorElement * effdenom = dbe->get(folder+"/"+hist2);
00188     MonitorElement * eff = dbe->get(folder+"/"+name);
00189     
00190     if(effnum && effdenom && eff )
00191       {
00192         //      dbe->setCurrentFolder(folder);
00193         for( int i=1;i<=effnum->getTH1F()->GetNbinsX();++i)
00194           {
00195             std::vector<double> efficiency =calcEfficiency(effnum->getTH1F()->GetBinContent(i),effdenom->getTH1F()->GetBinContent(i));
00196             eff->getTProfile()->SetBinContent(i,efficiency[0]);
00197             eff->getTProfile()->SetBinEntries(i,1);
00198             eff->getTProfile()->SetBinError(i,sqrt(efficiency[0]*efficiency[0]+efficiency[1]*efficiency[1]));
00199           }
00200       }
00201 
00202   }
00203 }
00204 
00205 
00206 void
00207 HLTTauDQMSummaryPlotter::plotIntegratedEffHisto(std::string folder,std::string name,std::string refHisto,std::string evCount,int bin,DQMStore * dbe)
00208 {
00209   if(dbe->dirExists(folder))
00210     {
00211       MonitorElement * refH = dbe->get(folder+"/"+refHisto);
00212       MonitorElement * evC  = dbe->get(folder+"/"+evCount);
00213       MonitorElement * eff = dbe->get(folder+"/"+name);
00214 
00215       if(refH && evC && eff)
00216         {
00217           TH1F *histo = refH->getTH1F();
00218           float nGenerated = evC->getTH1F()->GetBinContent(bin);
00219           // Assuming that the histogram is incremented with weight=1 for each event
00220           // this function integrates the histogram contents above every bin and stores it
00221           // in that bin.  The result is plot of integral rate versus threshold plot.
00222           int nbins = histo->GetNbinsX();
00223           double integral = histo->GetBinContent(nbins+1);  // Initialize to overflow
00224           if (nGenerated<=0.0)  {
00225             nGenerated=1.0;
00226           }
00227           for(int i = nbins; i >= 1; i--)
00228             {
00229               double thisBin = histo->GetBinContent(i);
00230               integral += thisBin;
00231               double integralEff;
00232               double integralError;
00233               integralEff = (integral / nGenerated);
00234               eff->getTProfile()->SetBinContent(i, integralEff);
00235               eff->getTProfile()->SetBinEntries(i, 1);
00236               // error
00237               integralError = (sqrt(integral) / nGenerated);
00238 
00239               eff->getTProfile()->SetBinError(i, sqrt(integralEff*integralEff+integralError*integralError));
00240             }
00241         }
00242     }
00243 }
00244 
00245 
00246 
00247 void 
00248 HLTTauDQMSummaryPlotter::bookTriggerBitEfficiencyHistos(std::string folder,std::string histo,DQMStore* dbe)
00249 {
00250   if(dbe->dirExists(folder))
00251   {
00252     dbe->setCurrentFolder(folder);
00253     MonitorElement* eff = dbe->get(folder+"/"+histo);
00254     dbe->bookProfile("EfficiencyRefInput","Efficiency with Matching",eff->getNbinsX()-1,0,eff->getNbinsX()-1,100,0,1);
00255     dbe->bookProfile("EfficiencyRefL1","Efficiency with Matching Ref to L1",eff->getNbinsX()-2,0,eff->getNbinsX()-2,100,0,1);
00256     dbe->bookProfile("EfficiencyRefPrevious","Efficiency with Matching Ref To previous",eff->getNbinsX()-1,0,eff->getNbinsX()-1,100,0,1);
00257 
00258   }
00259 
00260 }
00261 
00262 
00263 void 
00264 HLTTauDQMSummaryPlotter::plotTriggerBitEfficiencyHistos(std::string folder,std::string histo,DQMStore* dbe)
00265 {
00266   if(dbe->dirExists(folder))
00267   {
00268     dbe->setCurrentFolder(folder);
00269     MonitorElement* eff = dbe->get(folder+"/"+histo);
00270     MonitorElement * effRefTruth = dbe->get(folder+"/EfficiencyRefInput");
00271     MonitorElement * effRefL1 = dbe->get(folder+"/EfficiencyRefL1");
00272     MonitorElement * effRefPrevious = dbe->get(folder+"/EfficiencyRefPrevious");
00273    
00274 
00275     if(eff)
00276       {
00277         //Calculate Efficiencies with ref to Matched Objects
00278         for(int i =2;i<=eff->getNbinsX();++i)
00279           {
00280             double efficiency = calcEfficiency(eff->getBinContent(i),eff->getBinContent(1))[0];
00281             double err = calcEfficiency(eff->getBinContent(i),eff->getBinContent(1))[1];
00282 
00283             effRefTruth->getTProfile()->SetBinContent(i-1,efficiency);
00284             effRefTruth->getTProfile()->SetBinEntries(i-1,1);
00285             effRefTruth->getTProfile()->SetBinError(i-1,sqrt(efficiency*efficiency+err*err));
00286             effRefTruth->setBinLabel(i-1,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00287 
00288           }
00289         //Calculate Efficiencies with ref to L1
00290         for(int i =3;i<=eff->getNbinsX();++i)
00291           {
00292             double efficiency = calcEfficiency(eff->getBinContent(i),eff->getBinContent(2))[0];
00293             double err = calcEfficiency(eff->getBinContent(i),eff->getBinContent(2))[1];
00294 
00295             effRefL1->getTProfile()->SetBinContent(i-2,efficiency);
00296             effRefL1->getTProfile()->SetBinEntries(i-2,1);
00297             effRefL1->getTProfile()->SetBinError(i-2,sqrt(efficiency*efficiency+err*err));
00298             effRefL1->setBinLabel(i-2,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00299           }
00300 
00301         //Calculate Efficiencies with ref to previous
00302         for(int i = 2;i<=eff->getNbinsX();++i)
00303           {
00304             double efficiency = calcEfficiency(eff->getBinContent(i),eff->getBinContent(i-1))[0];
00305             double err = calcEfficiency(eff->getBinContent(i),eff->getBinContent(i-1))[1];
00306 
00307             effRefPrevious->getTProfile()->SetBinContent(i-1,efficiency);
00308             effRefPrevious->getTProfile()->SetBinEntries(i-1,1);
00309             effRefPrevious->getTProfile()->SetBinError(i-1,sqrt(efficiency*efficiency+err*err));
00310             effRefPrevious->setBinLabel(i-1,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00311           }
00312       }
00313   }
00314 }
00315 
00316 
00317 std::vector<double>
00318 HLTTauDQMSummaryPlotter::calcEfficiency(float num,float denom)
00319 {
00320   std::vector<double> a;
00321   if(denom==0)
00322     {
00323       a.push_back(0.);
00324       a.push_back(0.);
00325     }
00326   else
00327     {    
00328       a.push_back(num/denom);
00329       a.push_back(sqrt(a[0]*(1-a[0])/(denom)));
00330     }
00331   return a;
00332 }