CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQMOffline/Trigger/src/HLTTauDQMSummaryPlotter.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/HLTTauDQMSummaryPlotter.h"
00002 
00003 HLTTauDQMSummaryPlotter::HLTTauDQMSummaryPlotter( const edm::ParameterSet& ps, std::string dqmBaseFolder ) {
00004     //Initialize Plotter
00005     name_ = "HLTTauDQMSummaryPlotter";
00006     
00007     //Process PSet
00008     try {
00009         triggerTag_      = ps.getUntrackedParameter<std::string>("DQMFolder");
00010         triggerTagAlias_ = ps.getUntrackedParameter<std::string>("Alias","");
00011         type_            = ps.getUntrackedParameter<std::string>("ConfigType");
00012         dqmBaseFolder_   = dqmBaseFolder;
00013         validity_        = true;
00014     } catch ( cms::Exception &e ) {
00015         edm::LogInfo("HLTTauDQMSummaryPlotter::HLTTauDQMSummaryPlotter") << e.what() << std::endl;
00016         validity_ = false;
00017         return;
00018     }
00019     
00020     if (store_) {
00021         //Path Summary 
00022         if ( type_ == "Path" ) {
00023             bookTriggerBitEfficiencyHistos(triggerTag(),"MatchedTriggerBits");
00024         }
00025         
00026         //Lite Path Summary 
00027         if ( type_ == "LitePath" ) {
00028             bookEfficiencyHisto(triggerTag(),"PathEfficiency","MatchedPathTriggerBits");
00029             bookEfficiencyHisto(triggerTag(),"TrigTauEtEff","EfficiencyHelpers/TrigTauEtEffNum");
00030             bookEfficiencyHisto(triggerTag(),"TrigTauEtaEff","EfficiencyHelpers/TrigTauEtaEffNum");
00031             bookEfficiencyHisto(triggerTag(),"TrigTauPhiEff","EfficiencyHelpers/TrigTauPhiEffNum");
00032         }
00033         
00034         //L1 Summary
00035         if ( type_ == "L1" ) {
00036             bookEfficiencyHisto(triggerTag(),"L1TauEtEff","EfficiencyHelpers/L1TauEtEffNum");
00037             bookEfficiencyHisto(triggerTag(),"L1TauEtaEff","EfficiencyHelpers/L1TauEtaEffNum");
00038             bookEfficiencyHisto(triggerTag(),"L1TauPhiEff","EfficiencyHelpers/L1TauPhiEffNum");
00039             
00040             bookEfficiencyHisto(triggerTag(),"L1JetEtEff","EfficiencyHelpers/L1JetEtEffNum");
00041             bookEfficiencyHisto(triggerTag(),"L1JetEtaEff","EfficiencyHelpers/L1JetEtaEffNum");
00042             bookEfficiencyHisto(triggerTag(),"L1JetPhiEff","EfficiencyHelpers/L1JetPhiEffNum");
00043             
00044             bookEfficiencyHisto(triggerTag(),"L1SingleTauEff","L1LeadTauEt");
00045             bookEfficiencyHisto(triggerTag(),"L1DoubleTauEff","L1SecondTauEt");
00046         }
00047         
00048         //L2 Summary
00049         if ( type_ == "Calo" ) {
00050             bookEfficiencyHisto(triggerTag(),"L2RecoTauEtEff","EfficiencyHelpers/L2RecoTauEtEffNum");
00051             bookEfficiencyHisto(triggerTag(),"L2RecoTauEtaEff","EfficiencyHelpers/L2RecoTauEtaEffNum");
00052             bookEfficiencyHisto(triggerTag(),"L2RecoTauPhiEff","EfficiencyHelpers/L2RecoTauPhiEffNum");
00053             
00054             bookEfficiencyHisto(triggerTag(),"L2IsoTauEtEff","EfficiencyHelpers/L2IsoTauEtEffNum");
00055             bookEfficiencyHisto(triggerTag(),"L2IsoTauEtaEff","EfficiencyHelpers/L2IsoTauEtaEffNum");
00056             bookEfficiencyHisto(triggerTag(),"L2IsoTauPhiEff","EfficiencyHelpers/L2IsoTauPhiEffNum");
00057         }
00058         
00059         //L25/3 Summary
00060         if ( type_ == "Track" ) {
00061             bookEfficiencyHisto(triggerTag(),"L25TauEtEff","L25TauEtEffNum");
00062             bookEfficiencyHisto(triggerTag(),"L25TauEtaEff","L25TauEtaEffNum");
00063             bookEfficiencyHisto(triggerTag(),"L25TauPhiEff","L25TauPhiEffNum");
00064             bookEfficiencyHisto(triggerTag(),"L3TauEtEff","L3TauEtEffNum");
00065             bookEfficiencyHisto(triggerTag(),"L3TauEtaEff","L3TauEtaEffNum");
00066             bookEfficiencyHisto(triggerTag(),"L3TauPhiEff","L3TauPhiEffNum");
00067         }
00068     }
00069 }
00070 
00071 HLTTauDQMSummaryPlotter::~HLTTauDQMSummaryPlotter() {
00072 }
00073 
00074 void HLTTauDQMSummaryPlotter::plot() {
00075     if (store_) {
00076         //Path Summary 
00077         if ( type_ == "Path" ) {
00078             plotTriggerBitEfficiencyHistos(triggerTag(),"MatchedTriggerBits");
00079         }
00080         
00081         //Lite Path Summary 
00082         if ( type_ == "LitePath" ) {
00083             plotEfficiencyHisto(triggerTag(),"PathEfficiency","MatchedPathTriggerBits","RefEvents");
00084             plotEfficiencyHisto(triggerTag(),"TrigTauEtEff","EfficiencyHelpers/TrigTauEtEffNum","EfficiencyHelpers/TrigTauEtEffDenom");
00085             plotEfficiencyHisto(triggerTag(),"TrigTauEtaEff","EfficiencyHelpers/TrigTauEtaEffNum","EfficiencyHelpers/TrigTauEtaEffDenom");
00086             plotEfficiencyHisto(triggerTag(),"TrigTauPhiEff","EfficiencyHelpers/TrigTauPhiEffNum","EfficiencyHelpers/TrigTauPhiEffDenom");
00087         }
00088         
00089         //L1 Summary
00090         if ( type_ == "L1" ) {
00091             plotEfficiencyHisto(triggerTag(),"L1TauEtEff","EfficiencyHelpers/L1TauEtEffNum","EfficiencyHelpers/L1TauEtEffDenom");
00092             plotEfficiencyHisto(triggerTag(),"L1TauEtaEff","EfficiencyHelpers/L1TauEtaEffNum","EfficiencyHelpers/L1TauEtaEffDenom");
00093             plotEfficiencyHisto(triggerTag(),"L1TauPhiEff","EfficiencyHelpers/L1TauPhiEffNum","EfficiencyHelpers/L1TauPhiEffDenom");
00094             
00095             plotEfficiencyHisto(triggerTag(),"L1JetEtEff","EfficiencyHelpers/L1JetEtEffNum","EfficiencyHelpers/L1JetEtEffDenom");
00096             plotEfficiencyHisto(triggerTag(),"L1JetEtaEff","EfficiencyHelpers/L1JetEtaEffNum","EfficiencyHelpers/L1JetEtaEffDenom");
00097             plotEfficiencyHisto(triggerTag(),"L1JetPhiEff","EfficiencyHelpers/L1JetPhiEffNum","EfficiencyHelpers/L1JetPhiEffDenom");
00098             
00099             plotEfficiencyHisto(triggerTag(),"L1ElectronEtEff","EfficiencyHelpers/L1ElectronEtEffNum","EfficiencyHelpers/L1ElectronEtEffDenom");
00100             plotEfficiencyHisto(triggerTag(),"L1ElectronEtaEff","EfficiencyHelpers/L1ElectronEtaEffNum","EfficiencyHelpers/L1ElectronEtaEffDenom");
00101             plotEfficiencyHisto(triggerTag(),"L1ElectronPhiEff","EfficiencyHelpers/L1ElectronPhiEffNum","EfficiencyHelpers/L1ElectronPhiEffDenom");
00102             
00103             plotEfficiencyHisto(triggerTag(),"L1MuonEtEff","EfficiencyHelpers/L1MuonEtEffNum","EfficiencyHelpers/L1MuonEtEffDenom");
00104             plotEfficiencyHisto(triggerTag(),"L1MuonEtaEff","EfficiencyHelpers/L1MuonEtaEffNum","EfficiencyHelpers/L1MuonEtaEffDenom");
00105             plotEfficiencyHisto(triggerTag(),"L1MuonPhiEff","EfficiencyHelpers/L1MuonPhiEffNum","EfficiencyHelpers/L1MuonPhiEffDenom");
00106             
00107             plotIntegratedEffHisto(triggerTag(),"L1SingleTauEff","L1LeadTauEt","InputEvents",1);
00108             plotIntegratedEffHisto(triggerTag(),"L1DoubleTauEff","L1SecondTauEt","InputEvents",2);
00109         }
00110         
00111         //L2 Summary
00112         if ( type_ == "Calo" ) {
00113             plotEfficiencyHisto(triggerTag(),"L2RecoTauEtEff","EfficiencyHelpers/L2RecoTauEtEffNum","EfficiencyHelpers/L2RecoTauEtEffDenom");
00114             plotEfficiencyHisto(triggerTag(),"L2RecoTauEtaEff","EfficiencyHelpers/L2RecoTauEtaEffNum","EfficiencyHelpers/L2RecoTauEtaEffDenom");
00115             plotEfficiencyHisto(triggerTag(),"L2RecoTauPhiEff","EfficiencyHelpers/L2RecoTauPhiEffNum","EfficiencyHelpers/L2RecoTauPhiEffDenom");
00116             
00117             plotEfficiencyHisto(triggerTag(),"L2IsoTauEtEff","EfficiencyHelpers/L2IsoTauEtEffNum","EfficiencyHelpers/L2IsoTauEtEffDenom");
00118             plotEfficiencyHisto(triggerTag(),"L2IsoTauEtaEff","EfficiencyHelpers/L2IsoTauEtaEffNum","EfficiencyHelpers/L2IsoTauEtaEffDenom");
00119             plotEfficiencyHisto(triggerTag(),"L2IsoTauPhiEff","EfficiencyHelpers/L2IsoTauPhiEffNum","EfficiencyHelpers/L2IsoTauPhiEffDenom");
00120         }
00121         
00122         //L25/3 Summary
00123         if ( type_ == "Track" ) {
00124             plotEfficiencyHisto(triggerTag(),"L25TauEtEff","L25TauEtEffNum","L25TauEtEffDenom");
00125             plotEfficiencyHisto(triggerTag(),"L25TauEtaEff","L25TauEtaEffNum","L25TauEtaEffDenom");
00126             plotEfficiencyHisto(triggerTag(),"L25TauPhiEff","L25TauPhiEffNum","L25TauPhiEffDenom");
00127             plotEfficiencyHisto(triggerTag(),"L3TauEtEff","L3TauEtEffNum","L3TauEtEffDenom");
00128             plotEfficiencyHisto(triggerTag(),"L3TauEtaEff","L3TauEtaEffNum","L3TauEtaEffDenom");
00129             plotEfficiencyHisto(triggerTag(),"L3TauPhiEff","L3TauPhiEffNum","L3TauPhiEffDenom");
00130         }
00131     }
00132 }      
00133 
00134 void HLTTauDQMSummaryPlotter::bookEfficiencyHisto( std::string folder, std::string name, std::string hist1 ) {
00135     if ( store_->dirExists(folder) ) {
00136         store_->setCurrentFolder(folder);
00137         
00138         MonitorElement * effnum = store_->get(folder+"/"+hist1);
00139         
00140         if ( effnum ) {            
00141             MonitorElement *tmp = store_->bookProfile(name,name,effnum->getTH1F()->GetNbinsX(),effnum->getTH1F()->GetXaxis()->GetXmin(),effnum->getTH1F()->GetXaxis()->GetXmax(),105,0,1.05);
00142             
00143             tmp->setTitle(name);
00144         }
00145     }
00146 }
00147 
00148 void HLTTauDQMSummaryPlotter::plotEfficiencyHisto( std::string folder, std::string name, std::string hist1, std::string hist2 ) {
00149     if ( store_->dirExists(folder) ) {
00150         store_->setCurrentFolder(folder);
00151         
00152         MonitorElement * effnum = store_->get(folder+"/"+hist1);
00153         MonitorElement * effdenom = store_->get(folder+"/"+hist2);
00154         MonitorElement * eff = store_->get(folder+"/"+name);
00155         
00156         if ( effnum && effdenom && eff ) {            
00157             for ( int i = 1; i <= effnum->getTH1F()->GetNbinsX(); ++i ) {
00158                 double efficiency = calcEfficiency(effnum->getTH1F()->GetBinContent(i),effdenom->getTH1F()->GetBinContent(i)).first;
00159                 double err = calcEfficiency(effnum->getTH1F()->GetBinContent(i),effdenom->getTH1F()->GetBinContent(i)).second;
00160                 eff->getTProfile()->SetBinContent(i,efficiency);
00161                 eff->getTProfile()->SetBinEntries(i,1);
00162                 eff->getTProfile()->SetBinError(i,sqrt(efficiency*efficiency+err*err));
00163             }
00164         }
00165     }
00166 }
00167 
00168 void HLTTauDQMSummaryPlotter::plotIntegratedEffHisto( std::string folder, std::string name, std::string refHisto, std::string evCount, int bin ) {
00169     if ( store_->dirExists(folder) ) {
00170         store_->setCurrentFolder(folder);
00171         
00172         MonitorElement * refH = store_->get(folder+"/"+refHisto);
00173         MonitorElement * evC = store_->get(folder+"/"+evCount);
00174         MonitorElement * eff = store_->get(folder+"/"+name);
00175         
00176         if ( refH && evC && eff ) {
00177             TH1F *histo = refH->getTH1F();
00178             float nGenerated = evC->getTH1F()->GetBinContent(bin);
00179             // Assuming that the histogram is incremented with weight=1 for each event
00180             // this function integrates the histogram contents above every bin and stores it
00181             // in that bin.  The result is plot of integral rate versus threshold plot.
00182             int nbins = histo->GetNbinsX();
00183             double integral = histo->GetBinContent(nbins+1);  // Initialize to overflow
00184             if (nGenerated<=0.0) nGenerated=1.0;
00185             for ( int i = nbins; i >= 1; i-- ) {
00186                 double thisBin = histo->GetBinContent(i);
00187                 integral += thisBin;
00188                 double integralEff;
00189                 double integralError;
00190                 integralEff = (integral / nGenerated);
00191                 eff->getTProfile()->SetBinContent(i, integralEff);
00192                 eff->getTProfile()->SetBinEntries(i, 1);
00193                 // error
00194                 integralError = (sqrt(integral) / nGenerated);
00195                 
00196                 eff->getTProfile()->SetBinError(i, sqrt(integralEff*integralEff+integralError*integralError));
00197             }
00198         }
00199     }
00200 }
00201 
00202 void HLTTauDQMSummaryPlotter::bookTriggerBitEfficiencyHistos( std::string folder, std::string histo ) {
00203     if ( store_->dirExists(folder) ) {
00204         store_->setCurrentFolder(folder);
00205         
00206         MonitorElement * eff = store_->get(folder+"/"+histo);
00207         
00208         if ( eff ) {
00209             store_->bookProfile("EfficiencyRefInput","Efficiency with Matching",eff->getNbinsX()-1,0,eff->getNbinsX()-1,100,0,1);
00210             store_->bookProfile("EfficiencyRefL1","Efficiency with Matching Ref to L1",eff->getNbinsX()-2,0,eff->getNbinsX()-2,100,0,1);
00211             store_->bookProfile("EfficiencyRefPrevious","Efficiency with Matching Ref to Previous",eff->getNbinsX()-1,0,eff->getNbinsX()-1,100,0,1);
00212         }
00213     }
00214 }
00215 
00216 void HLTTauDQMSummaryPlotter::plotTriggerBitEfficiencyHistos( std::string folder, std::string histo ) {
00217     if ( store_->dirExists(folder) ) {
00218         store_->setCurrentFolder(folder);
00219         MonitorElement * eff = store_->get(folder+"/"+histo);
00220         MonitorElement * effRefTruth = store_->get(folder+"/EfficiencyRefInput");
00221         MonitorElement * effRefL1 = store_->get(folder+"/EfficiencyRefL1");
00222         MonitorElement * effRefPrevious = store_->get(folder+"/EfficiencyRefPrevious");
00223         
00224         if ( eff && effRefTruth && effRefL1 && effRefPrevious ) {
00225             //Calculate efficiencies with ref to matched objects
00226             for ( int i = 2; i <= eff->getNbinsX(); ++i ) {
00227                 double efficiency = calcEfficiency(eff->getBinContent(i),eff->getBinContent(1)).first;
00228                 double err = calcEfficiency(eff->getBinContent(i),eff->getBinContent(1)).second;
00229                 
00230                 effRefTruth->getTProfile()->SetBinContent(i-1,efficiency);
00231                 effRefTruth->getTProfile()->SetBinEntries(i-1,1);
00232                 effRefTruth->getTProfile()->SetBinError(i-1,sqrt(efficiency*efficiency+err*err));
00233                 effRefTruth->setBinLabel(i-1,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00234                 
00235             }
00236             //Calculate efficiencies with ref to L1
00237             for ( int i = 3; i <= eff->getNbinsX(); ++i ) {
00238                 double efficiency = calcEfficiency(eff->getBinContent(i),eff->getBinContent(2)).first;
00239                 double err = calcEfficiency(eff->getBinContent(i),eff->getBinContent(2)).second;
00240                 
00241                 effRefL1->getTProfile()->SetBinContent(i-2,efficiency);
00242                 effRefL1->getTProfile()->SetBinEntries(i-2,1);
00243                 effRefL1->getTProfile()->SetBinError(i-2,sqrt(efficiency*efficiency+err*err));
00244                 effRefL1->setBinLabel(i-2,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00245             }
00246             //Calculate efficiencies with ref to previous
00247             for ( int i = 2; i <= eff->getNbinsX(); ++i ) {
00248                 double efficiency = calcEfficiency(eff->getBinContent(i),eff->getBinContent(i-1)).first;
00249                 double err = calcEfficiency(eff->getBinContent(i),eff->getBinContent(i-1)).second;
00250                 
00251                 effRefPrevious->getTProfile()->SetBinContent(i-1,efficiency);
00252                 effRefPrevious->getTProfile()->SetBinEntries(i-1,1);
00253                 effRefPrevious->getTProfile()->SetBinError(i-1,sqrt(efficiency*efficiency+err*err));
00254                 effRefPrevious->setBinLabel(i-1,eff->getTH1F()->GetXaxis()->GetBinLabel(i));
00255             }
00256         }
00257     }
00258 }
00259 
00260 std::pair<double,double> HLTTauDQMSummaryPlotter::calcEfficiency( float num, float denom ) {
00261     if ( denom != 0.0 ) {
00262         return std::pair<double,double>(num/denom,sqrt(num/denom*(1.0-num/denom)/denom));
00263     }
00264     return std::pair<double,double>(0.0,0.0);
00265 }