CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQM/HLTEvF/plugins/HLTMonPhotonClient.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDAnalyzer.h"
00002 #include "DataFormats/Common/interface/Handle.h"
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "DQM/HLTEvF/interface/HLTMonPhotonClient.h"
00008 #include "DataFormats/Common/interface/RefToBase.h"
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 
00012 using namespace edm;
00013 
00014 HLTMonPhotonClient::HLTMonPhotonClient(const edm::ParameterSet& iConfig)
00015 {
00016   
00017   LogDebug("HLTMonPhotonClient") << "constructor...." ;
00018   
00019   logFile_.open("HLTMonPhotonClient.log");
00020   
00021   dbe = NULL;
00022   if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
00023     dbe = Service < DQMStore > ().operator->();
00024     dbe->setVerbose(0);
00025   }
00026   
00027   outputFile_ =
00028     iConfig.getUntrackedParameter <std::string>("outputFile", "");
00029   if (outputFile_.size() != 0) {
00030     LogInfo("HLTMonPhotonClient") << "Photon Trigger Monitoring histograms will be saved to " 
00031                               << outputFile_ ;
00032   }
00033   else {
00034     outputFile_ = "PhotonDQM.root";
00035   }
00036   
00037   bool disable =
00038     iConfig.getUntrackedParameter < bool > ("disableROOToutput", false);
00039   if (disable) {
00040     outputFile_ = "";
00041   }
00042   
00043   sourcetag_=iConfig.getParameter<edm::InputTag>("SourceTag");
00044 
00045   theHLTCollectionLabels = iConfig.getParameter<std::vector<edm::InputTag> >("theHLTCollectionLabels");
00046   
00047   dirname_="HLT/HLTMonPhoton/"+iConfig.getParameter<std::string>("@module_label");
00048   sourcedirname_="HLT/HLTMonPhoton/"+sourcetag_.label();
00049   
00050   if (dbe != NULL) {
00051     dbe->setCurrentFolder(dirname_);
00052   }
00053   
00054 }
00055 
00056 
00057 HLTMonPhotonClient::~HLTMonPhotonClient()
00058 {
00059  
00060    // do anything here that needs to be done at desctruction time
00061    // (e.g. close files, deallocate resources etc.)
00062 
00063 }
00064 
00065 
00066 //
00067 // member functions
00068 //
00069 
00070 // ------------ method called to for each event  ------------
00071 void
00072 HLTMonPhotonClient::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00073 {
00074   TH1F* refhisto = eventCounter->getTH1F();
00075   if(refhisto->GetBinContent(1) != 0){
00076     //    relFilterEff->setBinContent(6,refhisto->GetBinContent(5)/refhisto->GetBinContent(2));
00077     //    cumFilterEff->setBinContent(5,refhisto->GetBinContent(5)/refhisto->GetBinContent(1));
00078     cumFilterEff->setBinContent(4,refhisto->GetBinContent(4)/refhisto->GetBinContent(1));
00079     cumFilterEff->setBinContent(3,refhisto->GetBinContent(3)/refhisto->GetBinContent(1));
00080     cumFilterEff->setBinContent(2,refhisto->GetBinContent(2)/refhisto->GetBinContent(1));
00081   }else{
00082     relFilterEff->setBinContent(6,0);
00083     cumFilterEff->setBinContent(5,0);
00084     cumFilterEff->setBinContent(4,0);
00085     cumFilterEff->setBinContent(3,0);
00086     cumFilterEff->setBinContent(2,0);
00087   }
00088   for(int i = 0; i<4; i++){
00089     if(refhisto->GetBinContent(4-i) != 0){
00090       relFilterEff->setBinContent(5-i,refhisto->GetBinContent(5-i)/refhisto->GetBinContent(4-i));
00091     }else{
00092       relFilterEff->setBinContent(5-i,0);
00093     }
00094   }
00095   if(refhisto->GetBinContent(1) != 0){
00096     relFilterEff->setBinContent(1,refhisto->GetBinContent(1)/refhisto->GetBinContent(1));
00097     cumFilterEff->setBinContent(2,refhisto->GetBinContent(2)/refhisto->GetBinContent(1));
00098     cumFilterEff->setBinContent(1,refhisto->GetBinContent(1)/refhisto->GetBinContent(1));
00099   }else{
00100     relFilterEff->setBinContent(1,0);
00101     cumFilterEff->setBinContent(2,0);
00102     cumFilterEff->setBinContent(1,0);
00103   }
00104   
00105   TH1F* num;
00106   TH1F* denom;
00107 
00108   for(int i=0; i<3; i++){   
00109     denom = pixelhistosEt[0]->getTH1F();
00110     num = pixelhistosEt[i+1]->getTH1F();
00111     for(int j=1; j <= pixelhistosEtOut[i]->getNbinsX();j++ ){
00112       if(denom->GetBinContent(j)!=0){
00113         pixelhistosEtOut[i]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
00114       }
00115       else{
00116         pixelhistosEtOut[i]->setBinContent(j,0.);
00117       }
00118     }
00119     denom = pixelhistosEta[0]->getTH1F();
00120     num = pixelhistosEta[i+1]->getTH1F();  
00121     for(int j=1; j <= pixelhistosEtaOut[i]->getNbinsX();j++ ){
00122       if(denom->GetBinContent(j)!=0)
00123         pixelhistosEtaOut[i]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
00124       else
00125         pixelhistosEtaOut[i]->setBinContent(j,0.);
00126     }
00127     denom = pixelhistosPhi[0]->getTH1F();
00128     num = pixelhistosPhi[i+1]->getTH1F();  
00129     for(int j=1; j <= pixelhistosPhiOut[i]->getNbinsX();j++ ){
00130       if(denom->GetBinContent(j)!=0)
00131         pixelhistosPhiOut[i]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
00132       else
00133         pixelhistosPhiOut[i]->setBinContent(j,0.);
00134     }
00135   }
00136 
00137   denom = pixelhistosEt[0]->getTH1F();
00138   num = pixelhistosEt[3]->getTH1F();
00139   for(int j=1; j <= pixelhistosEtOut[3]->getNbinsX();j++ ){
00140     if(denom->GetBinContent(j)!=0){
00141       pixelhistosEtOut[3]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
00142     }
00143     else{
00144       pixelhistosEtOut[3]->setBinContent(j,0.);
00145     }
00146   }
00147 
00148   denom = pixelhistosEta[0]->getTH1F();
00149   num = pixelhistosEta[3]->getTH1F();
00150   for(int j=1; j <= pixelhistosEtaOut[3]->getNbinsX();j++ ){
00151     if(denom->GetBinContent(j)!=0){
00152       pixelhistosEtaOut[3]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
00153     }
00154     else{
00155       pixelhistosEtaOut[3]->setBinContent(j,0.);
00156     }
00157   }
00158 
00159   denom = pixelhistosPhi[0]->getTH1F();
00160   num = pixelhistosPhi[3]->getTH1F();
00161   for(int j=1; j <= pixelhistosPhiOut[3]->getNbinsX();j++ ){
00162     if(denom->GetBinContent(j)!=0){
00163       pixelhistosPhiOut[3]->setBinContent(j,num->GetBinContent(j)/denom->GetBinContent(j));
00164     }
00165     else{
00166       pixelhistosPhiOut[3]->setBinContent(j,0.);
00167     }
00168   }   
00169   
00170 }
00171 
00172 
00173 // ------------ method called once each job just before starting event loop  ------------
00174 void 
00175 HLTMonPhotonClient::beginJob()
00176 {
00177   
00178   DQMStore *dbe = 0;
00179   dbe = Service < DQMStore > ().operator->();
00180   
00181   if (dbe) {
00182     dbe->setCurrentFolder(dirname_);
00183     dbe->rmdir(dirname_);
00184   }
00185     
00186   if (dbe) {
00187     dbe->setCurrentFolder(dirname_);
00188 
00189     std::string tmpname = "";
00190       
00191     for(int i = 0; i<4; i++){
00192       LogInfo("HLTMonPhotonClient") << "loop iteration: "<<i ;
00193       tmpname = sourcedirname_ + "/" + theHLTCollectionLabels[i].label() + " Eta Dist";
00194       pixelhistosEta[i]=dbe->get(tmpname);
00195       tmpname = sourcedirname_ + "/" + theHLTCollectionLabels[i].label() + " Et Dist";
00196       pixelhistosEt[i]=dbe->get(tmpname);
00197       tmpname = sourcedirname_ + "/" + theHLTCollectionLabels[i].label() + " Phi Dist";
00198       pixelhistosPhi[i]=dbe->get(tmpname);
00199     }
00200 
00201     TH1F* refhist;
00202     int nBins;
00203     double xMin;
00204     double xMax;
00205 
00206     refhist = pixelhistosEt[0]->getTH1F();
00207     nBins = refhist->GetNbinsX();
00208     xMin = refhist->GetXaxis()->GetXmin();
00209     xMax = refhist->GetXaxis()->GetXmax();
00210     pixelhistosEtOut[0]  =dbe->book1D("EcalIsol Eff vs Et","EcalIsol Eff vs Et",nBins,xMin,xMax);
00211     pixelhistosEtOut[1]  =dbe->book1D("HcalIsol Eff vs Et","HcalIsol Eff vs Et",nBins,xMin,xMax);
00212     pixelhistosEtOut[2]  =dbe->book1D("Track Isol Eff vs Et","Track Isol Eff vs Et",nBins,xMin,xMax);
00213     pixelhistosEtOut[3]  =dbe->book1D("Total Eff vs Et","Total Eff vs Et",nBins,xMin,xMax);
00214 
00215     refhist = pixelhistosEta[0]->getTH1F();
00216     nBins = refhist->GetNbinsX();
00217     xMin = refhist->GetXaxis()->GetXmin();
00218     xMax = refhist->GetXaxis()->GetXmax();
00219     pixelhistosEtaOut[0] =dbe->book1D("EcalIsol Eff vs Eta","EcalIsol Eff vs Eta",nBins,xMin,xMax);
00220     pixelhistosEtaOut[1] =dbe->book1D("HcalIsol Eff vs Eta","HcalIsol Eff vs Eta",nBins,xMin,xMax);
00221     pixelhistosEtaOut[2] =dbe->book1D("Track Isol Eff vs Eta","Track Isol Eff vs Eta",nBins,xMin,xMax);
00222     pixelhistosEtaOut[3] =dbe->book1D("Total Eff vs Eta","Total Eff vs Eta",nBins,xMin,xMax);
00223 
00224     refhist = pixelhistosPhi[0]->getTH1F();
00225     nBins = refhist->GetNbinsX();
00226     xMin = refhist->GetXaxis()->GetXmin();
00227     xMax = refhist->GetXaxis()->GetXmax();
00228     pixelhistosPhiOut[0] =dbe->book1D("EcalIsol Eff vs Phi","EcalIsol Eff vs Phi",nBins,xMin,xMax);
00229     pixelhistosPhiOut[1] =dbe->book1D("HcalIsol Eff vs Phi","HcalIsol Eff vs Phi",nBins,xMin,xMax);
00230     pixelhistosPhiOut[2] =dbe->book1D("Track Isol Eff vs Phi","Track Isol Eff vs Phi",nBins,xMin,xMax);
00231     pixelhistosPhiOut[3] =dbe->book1D("Total Eff vs Phi","Total Eff vs Phi",nBins,xMin,xMax);
00232 
00233     tmpname = sourcedirname_ + "/Evts Passing Filters";    
00234     eventCounter = dbe->get(tmpname);
00235 
00236     relFilterEff = dbe->book1D("Relative Filter Effs","Relative Filter Effs",5,0,5);
00237     relFilterEff->setBinLabel(1,"HLTIsoEtFilterEff");
00238     relFilterEff->setBinLabel(2,"HLTIsoEcalIsolEff");
00239     relFilterEff->setBinLabel(3,"HLTIsoHcalIsolEff");
00240     relFilterEff->setBinLabel(4,"HLTIsoTrackIsolEff");
00241     //    relFilterEff->setBinLabel(5,"FIXME");
00242     //    relFilterEff->setBinLabel(6,"FIXME");
00243 
00244     cumFilterEff = dbe->book1D("Cumulative Filter Effs","Cumulative Filter Effs",5,0,5);
00245     cumFilterEff->setBinLabel(1,"HLTIsoEtFilterEff");
00246     cumFilterEff->setBinLabel(2,"HLTIsoEcalIsolEff");
00247     cumFilterEff->setBinLabel(3,"HLTIsoHcalIsolEff");
00248     cumFilterEff->setBinLabel(4,"HLTIsoTrackIsolEff");
00249     //    cumFilterEff->setBinLabel(5,"TrackIsolEff");
00250 
00251   } // end "if(dbe)"
00252 }
00253 
00254 // ------------ method called once each job just after ending the event loop  ------------
00255 void 
00256 HLTMonPhotonClient::endJob() {
00257 
00258 //     std::cout << "HLTMonPhotonClient: end job...." << std::endl;
00259  
00260    if (outputFile_.size() != 0 && dbe)
00261      dbe->save(outputFile_);
00262  
00263    return;
00264 }
00265 
00266 DEFINE_FWK_MODULE(HLTMonPhotonClient);