CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMOffline/Trigger/src/TopElectronHLTOfflineClient.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Trigger/interface/TopElectronHLTOfflineClient.h"
00002 
00003 
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013 
00014 
00015 TopElectronHLTOfflineClient::TopElectronHLTOfflineClient(const edm::ParameterSet& iConfig) : dbe_(NULL)
00016 {
00017         dbe_ = edm::Service<DQMStore>().operator->();
00018         
00019         if (!dbe_) 
00020         {
00021                 edm::LogError("TopElectronHLTOfflineClient") << "unable to get DQMStore service, upshot is no client histograms will be made";
00022         }
00023         
00024         if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) 
00025         {
00026                 if (dbe_) dbe_->setVerbose(0);
00027         }
00028         
00029         dirName_=iConfig.getParameter<std::string>("DQMDirName");
00030         
00031         if (dbe_)
00032                 dbe_->setCurrentFolder(dirName_);
00033 
00034         hltTag_ = iConfig.getParameter<std::string>("hltTag");
00035         
00036         electronIdNames_ = iConfig.getParameter<std::vector<std::string> >("electronIdNames");
00037         superTriggerNames_ = iConfig.getParameter<std::vector<std::string> >("superTriggerNames");
00038         electronTriggerNames_ = iConfig.getParameter<std::vector<std::string> >("electronTriggerNames");
00039         addExtraId_ = iConfig.getParameter<bool>("addExtraId");
00040 
00041         runClientEndLumiBlock_ = iConfig.getParameter<bool>("runClientEndLumiBlock");
00042         runClientEndRun_ = iConfig.getParameter<bool>("runClientEndRun");
00043         runClientEndJob_ = iConfig.getParameter<bool>("runClientEndJob");
00044 
00045 }
00046 
00047 
00048 TopElectronHLTOfflineClient::~TopElectronHLTOfflineClient()
00049 { 
00050 }
00051 
00052 void TopElectronHLTOfflineClient::beginJob()
00053 {
00054         //compose the ME names we need
00055         
00056         // Eta regions
00057         std::vector<std::string> regions;
00058         regions.push_back("EB");
00059         regions.push_back("EE");
00060         
00061         // Electron IDs, including own extra ID
00062         std::vector<std::string> eleIdNames;
00063         for (size_t i = 0; i < electronIdNames_.size(); ++i)
00064         {
00065                 eleIdNames.push_back(electronIdNames_[i]);
00066                 if (addExtraId_)
00067                         eleIdNames.push_back(electronIdNames_[i]+"extraId");
00068         }
00069         
00070         std::vector<std::string> vars;
00071         vars.push_back("_et");
00072         vars.push_back("_eta");
00073         vars.push_back("_phi");
00074         vars.push_back("_isolEm");
00075         vars.push_back("_isolHad");
00076         vars.push_back("_minDeltaR");
00077         vars.push_back("_global_n30jets");
00078         vars.push_back("_global_sumEt");
00079         vars.push_back("_gsftrack_etaError");
00080         vars.push_back("_gsftrack_phiError");
00081         vars.push_back("_gsftrack_numberOfValidHits");
00082         vars.push_back("_gsftrack_dzPV");
00083         
00084         
00085         for (size_t i = 0; i < eleIdNames.size(); ++i)
00086                 for (size_t j = 0; j < regions.size(); ++j)
00087                         for (size_t k = 0; k < vars.size(); ++k)
00088                                 for (size_t l = 0; l < superTriggerNames_.size(); ++l)
00089                                 {
00090                                         superMeNames_.push_back("ele_"+superTriggerNames_[l]+"_"+regions[j]+"_"+eleIdNames[i]+vars[k] );
00091                                         for (size_t m = 0; m < electronTriggerNames_.size(); ++m)
00092                                         {
00093                                                 eleMeNames_.push_back("ele_"+superTriggerNames_[l]+"_"+electronTriggerNames_[m] +"_"+regions[j]+"_"+eleIdNames[i]+vars[k]);
00094                                         }
00095                                 }
00096 
00097         
00098 
00099 }
00100 
00101 void TopElectronHLTOfflineClient::endJob() 
00102 {
00103         if(runClientEndJob_)
00104                 runClient_();
00105 }
00106 
00107 void TopElectronHLTOfflineClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00108 {
00109 }
00110 
00111 
00112 void TopElectronHLTOfflineClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00113 {
00114         if(runClientEndRun_)
00115                 runClient_();
00116 }
00117 
00118 //dummy analysis function
00119 void TopElectronHLTOfflineClient::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00120 {
00121 }
00122 
00123 void TopElectronHLTOfflineClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c)
00124 { 
00125         if(runClientEndLumiBlock_)
00126                 runClient_();
00127 }
00128 
00129 void TopElectronHLTOfflineClient::runClient_()
00130 {
00131         if (!dbe_) return; //we dont have the DQMStore so we cant do anything
00132         dbe_->setCurrentFolder(dirName_);
00133         
00134         size_t k = 0;
00135         for (size_t i = 0; i < superMeNames_.size(); ++i)
00136         {
00137                 for (size_t j = 0; j < electronTriggerNames_.size(); ++j)
00138                 {
00139                         if (k >= eleMeNames_.size())
00140                                 continue;
00141                         createSingleEffHists(superMeNames_[i], eleMeNames_[k], eleMeNames_[k]+"_eff");
00142                         ++k;
00143                 }
00144         }
00145         superTriggerNames_.size();
00146         electronTriggerNames_.size();
00147 
00148 
00149 }
00150 
00151 void TopElectronHLTOfflineClient::createSingleEffHists(const std::string& denomName, const std::string& nomName, const std::string& effName)
00152 { 
00153         MonitorElement* denom = dbe_->get(dirName_+"/"+denomName);
00154         
00155         MonitorElement* nom = dbe_->get(dirName_+"/"+nomName);
00156         if(nom!=NULL && denom!=NULL)
00157         {
00158 
00159                 makeEffMonElemFromPassAndAll(effName, nom, denom);       
00160         }
00161 }
00162 
00163         
00164 MonitorElement* TopElectronHLTOfflineClient::makeEffMonElemFromPassAndAll(const std::string& name, const MonitorElement* pass, const MonitorElement* all)
00165 {
00166         TH1F* passHist = pass->getTH1F();
00167         if(passHist->GetSumw2N()==0) 
00168                 passHist->Sumw2();
00169         TH1F* allHist = all->getTH1F();
00170         if(allHist->GetSumw2N()==0)
00171                 allHist->Sumw2();
00172         
00173         TH1F* effHist = (TH1F*) passHist->Clone(name.c_str());
00174         effHist->Divide(passHist,allHist,1,1,"B");
00175 
00176         MonitorElement* eff = dbe_->get(dirName_+"/"+name);
00177         if(eff==NULL)
00178         {
00179                 eff= dbe_->book1D(name,effHist);
00180         }
00181         else
00182         { //I was having problems with collating the histograms, hence why I'm just reseting the histogram value
00183                 *eff->getTH1F()=*effHist; 
00184                 delete effHist;
00185         }
00186         return eff;
00187 }