CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/HLTriggerOffline/Top/interface/TopHLTDQMHelper.h

Go to the documentation of this file.
00001 #ifndef TOPHLTDQMHELPERS
00002 #define TOPHLTDQMHELPERS
00003 
00004 #include <string>
00005 #include <vector>
00006 //#include <math>
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Common/interface/TriggerNames.h"
00009 #include "DataFormats/Common/interface/TriggerResults.h"
00010 #include "DataFormats/VertexReco/interface/Vertex.h"
00011 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00012 /*Originally from DQM/Physics package, written by Roger Wolf and Jeremy Andrea*/
00022 inline bool 
00023 acceptHLT(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::string& triggerPath)
00024 {
00025   bool passed=false;
00026   const edm::TriggerNames& triggerNames = event.triggerNames(triggerTable);
00027   for(unsigned int i=0; i<triggerNames.triggerNames().size(); ++i){
00028     if(triggerNames.triggerNames()[i] == triggerPath) {
00029       if(triggerTable.accept(i)){
00030         passed=true;
00031         break;
00032       }
00033     }
00034   }
00035   return passed;
00036 }
00037 
00038 inline bool 
00039 acceptHLT(const edm::Event& event, const edm::TriggerResults& triggerTable, const std::vector<std::string>& triggerPaths)
00040 {
00041   bool passed=false;
00042   for(unsigned int j=0; j<triggerPaths.size(); ++j){
00043     if(acceptHLT(event, triggerTable, triggerPaths[j])){
00044       passed=true;
00045       break;
00046     }
00047   }
00048   return passed;
00049 }
00050 
00051 
00052 #include "DataFormats/JetReco/interface/Jet.h"
00053 #include "FWCore/Framework/interface/EventSetup.h"
00054 
00055 #include "DataFormats/METReco/interface/CaloMET.h"
00067 class CalculateHLT {
00068  public:
00070   CalculateHLT(int maxNJets, double wMass);
00072   ~CalculateHLT(){};
00073      
00075   double massWBoson(const std::vector<reco::Jet>& jets);
00077   double massTopQuark(const std::vector<reco::Jet>& jets); 
00079 /*  double tmassWBoson(const T& mu, const reco::CaloMET& met, const reco::Jet& b);
00081   double tmassTopQuark(const T& mu, const reco::CaloMET& met, const reco::Jet& b);
00083   double masslb(const T& mu, const reco::CaloMET& met, const reco::Jet& b);*/
00084 
00086   double tmassWBoson(reco::RecoCandidate* mu, const reco::MET& met, const reco::Jet& b);
00088   double tmassTopQuark(reco::RecoCandidate* mu, const reco::MET& met, const reco::Jet& b);
00090   double masslb(reco::RecoCandidate* mu, const reco::MET& met, const reco::Jet& b);
00091   
00092  private:
00096   void operator()(const std::vector<reco::Jet>& jets);
00097   void operator()(const reco::Jet& bJet, reco::RecoCandidate* lepton, const reco::MET& met);
00098  private:
00100   bool failed_;
00102   int maxNJets_;
00104   double wMass_;
00106   double massWBoson_;
00108   double massTopQuark_;
00110   double tmassWBoson_;
00112   double tmassTopQuark_;
00114   double mlb_;
00115 
00116 
00117 };
00118 
00119 
00120 #include "DataFormats/JetReco/interface/JetID.h"
00121 #include "DataFormats/JetReco/interface/PFJet.h"
00122 #include "DataFormats/JetReco/interface/CaloJet.h"
00123 #include "DataFormats/BTauReco/interface/JetTag.h"
00124 #include "DataFormats/Common/interface/ValueMap.h"
00125 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00126 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
00127 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00128 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00129 #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
00130 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00131 
00172 template <typename Object> 
00173 class SelectionStepHLT {
00174 public:
00176   SelectionStepHLT(const edm::ParameterSet& cfg);
00178   ~SelectionStepHLT(){};
00179 
00181   bool select(const edm::Event& event);
00183   bool select(const edm::Event& event, const edm::EventSetup& setup); 
00184   bool selectVertex(const edm::Event& event);
00185 private:
00187   edm::InputTag src_;
00189   int min_, max_; 
00191   edm::InputTag electronId_;
00202   int eidPattern_;
00204   std::string jetCorrector_;
00206   edm::InputTag btagLabel_;
00208   double btagWorkingPoint_;
00210   edm::InputTag jetIDLabel_;
00211 
00212   edm::InputTag pvs_; 
00213 
00215   StringCutObjectSelector<Object> select_;
00217   StringCutObjectSelector<reco::JetID>* jetIDSelect_;
00218 };
00219 
00221 template <typename Object> 
00222 SelectionStepHLT<Object>::SelectionStepHLT(const edm::ParameterSet& cfg) :
00223   src_( cfg.getParameter<edm::InputTag>( "src"   )),
00224   select_( cfg.getParameter<std::string>("select")),
00225   jetIDSelect_(0)
00226 {
00227   // construct min/max if the corresponding params
00228   // exist otherwise they are initialized with -1
00229   cfg.exists("min") ? min_= cfg.getParameter<int>("min") : min_= -1;
00230   cfg.exists("max") ? max_= cfg.getParameter<int>("max") : max_= -1;
00231   // read electron extras if they exist
00232   if(cfg.existsAs<edm::ParameterSet>("electronId")){ 
00233     edm::ParameterSet elecId=cfg.getParameter<edm::ParameterSet>("electronId");
00234     electronId_= elecId.getParameter<edm::InputTag>("src");
00235     eidPattern_= elecId.getParameter<int>("pattern");
00236   }
00237   // read jet corrector label if it exists
00238   if(cfg.exists("jetCorrector")){ jetCorrector_= cfg.getParameter<std::string>("jetCorrector"); }
00239   // read btag information if it exists
00240   if(cfg.existsAs<edm::ParameterSet>("jetBTagger")){
00241     edm::ParameterSet jetBTagger=cfg.getParameter<edm::ParameterSet>("jetBTagger");
00242     btagLabel_=jetBTagger.getParameter<edm::InputTag>("label");
00243     btagWorkingPoint_=jetBTagger.getParameter<double>("workingPoint");
00244   }
00245   // read jetID information if it exists
00246   if(cfg.existsAs<edm::ParameterSet>("jetID")){
00247     edm::ParameterSet jetID=cfg.getParameter<edm::ParameterSet>("jetID");
00248     jetIDLabel_ =jetID.getParameter<edm::InputTag>("label");
00249     jetIDSelect_= new StringCutObjectSelector<reco::JetID>(jetID.getParameter<std::string>("select"));
00250   }
00251 }
00252 
00254 template <typename Object> 
00255 bool SelectionStepHLT<Object>::select(const edm::Event& event)
00256 {
00257   // fetch input collection
00258   edm::Handle<edm::View<Object> > src; 
00259   if( !event.getByLabel(src_, src) ) return false;
00260 
00261   // load electronId value map if configured such
00262   edm::Handle<edm::ValueMap<float> > electronId;
00263   if(!electronId_.label().empty()) {
00264     if( !event.getByLabel(electronId_, electronId) ) return false;
00265   }
00266 
00267   // determine multiplicity of selected objects
00268   int n=0;
00269   for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00270     // special treatment for electrons
00271     if(dynamic_cast<const reco::GsfElectron*>(&*obj)){
00272       unsigned int idx = obj-src->begin();
00273       if( electronId_.label().empty() ? true : ((int)(*electronId)[src->refAt(idx)] & eidPattern_) ){   
00274         if(select_(*obj))++n;
00275       }
00276     }
00277     // normal treatment
00278     else{
00279       if(select_(*obj))++n;
00280     }
00281   }
00282   bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00283   return (min_<0 && max_<0) ? (n>0):accept;
00284 }
00285 template <typename Object> 
00286 bool SelectionStepHLT<Object>::selectVertex(const edm::Event& event)
00287 {
00288   // fetch input collection
00289   edm::Handle<edm::View<Object> > src; 
00290   if( !event.getByLabel(src_, src) ) return false;
00291 
00292   // load electronId value map if configured such
00293   edm::Handle<edm::ValueMap<float> > electronId;
00294   if(!electronId_.label().empty()) {
00295     if( !event.getByLabel(electronId_, electronId) ) return false;
00296   }
00297 
00298   // determine multiplicity of selected objects
00299   int n=0;
00300   for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00301    
00302       if(select_(*obj))++n;
00303   }
00304   bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00305   return (min_<0 && max_<0) ? (n>0):accept;
00306 }
00307 
00309 template <typename Object> 
00310 bool SelectionStepHLT<Object>::select(const edm::Event& event, const edm::EventSetup& setup)
00311 {
00312   // fetch input collection
00313   edm::Handle<edm::View<Object> > src; 
00314   if( !event.getByLabel(src_, src) ) return false;
00315 
00316   // load btag collection if configured such
00317   // NOTE that the JetTagCollection needs an
00318   // edm::View to reco::Jets; we have to add
00319   // another Handle bjets for this purpose
00320   edm::Handle<edm::View<reco::Jet> > bjets; 
00321   edm::Handle<reco::JetTagCollection> btagger;
00322   edm::Handle<edm::View<reco::Vertex> > pvertex; 
00323   if(!btagLabel_.label().empty()){ 
00324     if( !event.getByLabel(src_, bjets) ) return false;
00325     if( !event.getByLabel(btagLabel_, btagger) ) return false;
00326     if( !event.getByLabel(pvs_, pvertex) ) return false;
00327   }
00328 
00329   // load jetID value map if configured such 
00330   edm::Handle<reco::JetIDValueMap> jetID;
00331   if(jetIDSelect_){
00332     if( !event.getByLabel(jetIDLabel_, jetID) ) return false;
00333 
00334   }
00335 
00336   // load jet corrector if configured such
00337   const JetCorrector* corrector=0;
00338   if(!jetCorrector_.empty()){
00339     // check whether a jet correcto is in the event setup or not
00340     if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
00341       corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
00342     }
00343     else{
00344       edm::LogVerbatim( "TopDQMHelpers" ) 
00345         << "\n"
00346         << "------------------------------------------------------------------------------------- \n"
00347         << " No JetCorrectionsRecord available from EventSetup:                                   \n" 
00348         << "  - Jets will not be corrected.                                                       \n"
00349         << "  - If you want to change this add the following lines to your cfg file               \n"
00350         << "                                                                                      \n"
00351         << "  ## load jet corrections                                                             \n"
00352         << "  process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
00353         << "  process.prefer(\"ak5CaloL2L3\")                                                     \n"
00354         << "                                                                                      \n"
00355         << "------------------------------------------------------------------------------------- \n";
00356     }
00357   }
00358   // determine multiplicity of selected objects
00359   int n=0;
00360   for(typename edm::View<Object>::const_iterator obj=src->begin(); obj!=src->end(); ++obj){
00361     // check for chosen btag discriminator to be above the 
00362     // corresponding working point if configured such 
00363     unsigned int idx = obj-src->begin();
00364     if( btagLabel_.label().empty() ? true : (*btagger)[bjets->refAt(idx)]>btagWorkingPoint_ ){   
00365       bool passedJetID=true;
00366       // check jetID for calo jets
00367       if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(src->refAt(idx).get())){
00368         passedJetID=(*jetIDSelect_)((*jetID)[src->refAt(idx)]);
00369       }
00370       if(passedJetID){
00371         // scale jet energy if configured such
00372         Object jet=*obj; jet.scaleEnergy(corrector ? corrector->correction(*obj) : 1.);
00373         if(select_(jet))++n;
00374       }
00375     }
00376   }
00377   bool accept=(min_>=0 ? n>=min_:true) && (max_>=0 ? n<=max_:true);
00378   return (min_<0 && max_<0) ? (n>0):accept;
00379 }
00380 
00381 #endif