CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/HLTriggerOffline/Top/src/TopHLTDiLeptonOfflineDQM.h

Go to the documentation of this file.
00001 #ifndef TOPDILEPTONOFFLINEDQM
00002 #define TOPDILEPTONOFFLINEDQM
00003 
00004 #include <string>
00005 #include <vector>
00006 
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "DQMServices/Core/interface/DQMStore.h"
00009 #include "DQMServices/Core/interface/MonitorElement.h"
00010 
00011 #include "DataFormats/Math/interface/deltaR.h"
00012 #include "DataFormats/JetReco/interface/Jet.h"
00013 #include "HLTriggerOffline/Top/interface/TopHLTDQMHelper.h"
00014 #include "DataFormats/MuonReco/interface/Muon.h"
00015 #include "DataFormats/Common/interface/ValueMap.h"
00016 #include "DataFormats/METReco/interface/CaloMET.h"
00017 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00018 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00019 /*Originally from DQM/Physics by R. Wolf and J. Andrea*/
00020 
00038 namespace TopDiLeptonOffline {
00039 
00040   class MonitorEnsemble {
00041   public:
00043     enum Level{ STANDARD, VERBOSE, DEBUG };
00046     typedef reco::LeafCandidate::LorentzVector LorentzVector;
00048     enum DecayChannel{ NONE, DIMUON, DIELEC, ELECMU };
00049     
00050   public:
00052     MonitorEnsemble(const char* label, const edm::ParameterSet& cfg);
00054     ~MonitorEnsemble(){};
00055     
00057     void book(std::string directory);
00059     void fill(const edm::Event& event, const edm::EventSetup& setup);
00060 
00061   private:
00064     std::string monitorPath(const std::string& label) const { return label.substr(label.find(':')+1); };  
00067     std::string selectionPath(const std::string& label) const { return label.substr(0, label.find(':')); };  
00069     DecayChannel decayChannel(const std::vector<const reco::Muon*>& muons, const std::vector<const reco::GsfElectron*>& elecs) const;
00070 
00072     void loggerBinLabels(std::string hist);
00074     void triggerBinLabels(std::string channel, const std::vector<std::string> labels);
00076     void fill(const edm::Event& event, const edm::TriggerResults& triggerTable, std::string channel, const std::vector<std::string> labels) const;
00077 
00079     bool booked(const std::string histName) const { return hists_.find(histName.c_str())!=hists_.end(); };
00081     void fill(const std::string histName, double value) const { if(booked(histName.c_str())) hists_.find(histName.c_str())->second->Fill(value); };
00083     void fill(const std::string histName, double xValue, double yValue) const { if(booked(histName.c_str())) hists_.find(histName.c_str())->second->Fill(xValue, yValue); };
00085     void fill(const std::string histName, double xValue, double yValue, double zValue) const { if(booked(histName.c_str())) hists_.find(histName.c_str())->second->Fill(xValue, yValue, zValue); };
00086 
00087   private:
00089     Level verbosity_;
00091     std::string label_;
00093     edm::InputTag elecs_, muons_, jets_; 
00095     std::vector<edm::InputTag> mets_;
00096 
00098     edm::InputTag triggerTable_;
00101     std::vector<std::string> elecMuPaths_;
00103     std::vector<std::string> diMuonPaths_;
00104 
00106     edm::InputTag electronId_;
00117     int eidPattern_;
00119     StringCutObjectSelector<reco::GsfElectron>* elecIso_;
00121     StringCutObjectSelector<reco::GsfElectron>* elecSelect_;
00122 
00124     StringCutObjectSelector<reco::Muon>* muonIso_;
00126     StringCutObjectSelector<reco::Muon>* muonSelect_;
00127 
00129     std::string jetCorrector_;
00131     edm::InputTag jetIDLabel_;
00133     StringCutObjectSelector<reco::JetID>* jetIDSelect_;
00136     std::string jetSelect_;
00138     double lowerEdge_, upperEdge_;
00139 
00141     int elecMuLogged_, diMuonLogged_, diElecLogged_;
00143     DQMStore* store_;
00145     std::map<std::string,MonitorElement*> hists_;
00146   };
00147 
00148   inline void 
00149   MonitorEnsemble::loggerBinLabels(std::string hist)
00150   {
00151     // set axes titles for selected events
00152     hists_[hist.c_str()]->getTH1()->SetOption("TEXT");
00153     hists_[hist.c_str()]->setBinLabel( 1 , "Run"             , 1);
00154     hists_[hist.c_str()]->setBinLabel( 2 , "Block"           , 1);
00155     hists_[hist.c_str()]->setBinLabel( 3 , "Event"           , 1);
00156     hists_[hist.c_str()]->setBinLabel( 6 , "pt_{L2L3}(jet1)" , 1);
00157     hists_[hist.c_str()]->setBinLabel( 7 , "pt_{L2L3}(jet2)" , 1);
00158     hists_[hist.c_str()]->setBinLabel( 8 , "MET_{Calo}"      , 1);
00159     hists_[hist.c_str()]->setAxisTitle("logged evts"         , 2);
00160 
00161     if(hist=="diMuonLogger_"){
00162       hists_[hist.c_str()]->setBinLabel( 4 , "pt(muon)" , 1);
00163       hists_[hist.c_str()]->setBinLabel( 5 , "pt(muon)" , 1);
00164     }
00165     if(hist=="diElecLogger_"){
00166       hists_[hist.c_str()]->setBinLabel( 4 , "pt(elec)" , 1);
00167       hists_[hist.c_str()]->setBinLabel( 5 , "pt(elec)" , 1);
00168     }
00169     if(hist=="elecMuLogger_"){
00170       hists_[hist.c_str()]->setBinLabel( 4 , "pt(elec)" , 1);
00171       hists_[hist.c_str()]->setBinLabel( 5 , "pt(muon)" , 1);
00172     }
00173   }
00174 
00175   inline void 
00176   MonitorEnsemble::triggerBinLabels(std::string channel, const std::vector<std::string> labels)
00177   {
00178     for(unsigned int idx=0; idx<labels.size(); ++idx){
00179       hists_[(channel+"Mon_").c_str()]->setBinLabel( idx+1, "["+monitorPath(labels[idx])+"]", 1);
00180       hists_[(channel+"Eff_").c_str()]->setBinLabel( idx+1, "["+selectionPath(labels[idx])+"]|["+monitorPath(labels[idx])+"]", 1);
00181     }
00182   }
00183 
00184   inline void 
00185   MonitorEnsemble::fill(const edm::Event& event, const edm::TriggerResults& triggerTable, std::string channel, const std::vector<std::string> labels) const
00186   {
00187     for(unsigned int idx=0; idx<labels.size(); ++idx){
00188       if( acceptHLT(event, triggerTable, monitorPath(labels[idx])) ){
00189         fill((channel+"Mon_").c_str(), idx+0.5 );
00190         // take care to fill triggerMon_ before evts is being called
00191         int evts = hists_.find((channel+"Mon_").c_str())->second->getBinContent(idx+1);
00192         double value = hists_.find((channel+"Eff_").c_str())->second->getBinContent(idx+1);
00193         fill((channel+"Eff_").c_str(), idx+0.5, 1./evts*(acceptHLT(event, triggerTable, selectionPath(labels[idx]))-value));
00194       }
00195     }
00196   }
00197   
00198   inline MonitorEnsemble::DecayChannel
00199   MonitorEnsemble::decayChannel(const std::vector<const reco::Muon*>& muons, const std::vector<const reco::GsfElectron*>& elecs) const 
00200   {
00201     DecayChannel type=NONE;
00202     if( muons.size()>1 ){ type=DIMUON; } else if( elecs.size()>1 ){ type=DIELEC; } else if( !elecs.empty() && !muons.empty() ){ type=ELECMU; }
00203     return type;
00204   } 
00205   
00206 }
00207 
00208 #include <utility>
00209 
00210 #include "FWCore/Framework/interface/EDAnalyzer.h"
00211 #include "FWCore/Framework/interface/Frameworkfwd.h"
00212 #include "FWCore/ServiceRegistry/interface/Service.h"
00213 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00214 
00215 #include "FWCore/Common/interface/TriggerNames.h"
00216 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00217 #include "DataFormats/VertexReco/interface/Vertex.h"
00218 #include "DataFormats/Common/interface/TriggerResults.h"
00219   
00245 
00246 //using TopDiLeptonOffline::MonitorEnsemble;
00247 
00248 class TopHLTDiLeptonOfflineDQM : public edm::EDAnalyzer  {
00249  public: 
00251   TopHLTDiLeptonOfflineDQM(const edm::ParameterSet& cfg);
00253   ~TopHLTDiLeptonOfflineDQM(){ 
00254     if( beamspotSelect_ ) delete beamspotSelect_; 
00255     if( vertexSelect_ ) delete vertexSelect_;
00256   }
00257   
00259   virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
00260     
00261  private:
00264   std::string objectType(const std::string& label) { return label.substr(0, label.find(':')); };  
00267   std::string selectionStep(const std::string& label) { return label.substr(label.find(':')+1); };  
00268 
00269  private:
00271   edm::InputTag triggerTable_;
00273   std::vector<std::string> triggerPaths_;
00275   edm::InputTag vertex_;
00277   StringCutObjectSelector<reco::Vertex>* vertexSelect_;
00279   edm::InputTag beamspot_;
00281   StringCutObjectSelector<reco::BeamSpot>* beamspotSelect_;
00282 
00285   std::vector<std::string> selectionOrder_;
00291     std::map<std::string, std::pair<edm::ParameterSet, TopDiLeptonOffline::MonitorEnsemble*> > selection_;
00292 };
00293 
00294 #endif