CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/JetMET/src/HLTExclDiJetFilter.cc

Go to the documentation of this file.
00001 
00008 #include "HLTrigger/JetMET/interface/HLTExclDiJetFilter.h"
00009 
00010 #include "DataFormats/Common/interface/Handle.h"
00011 
00012 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00013 
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 
00016 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00017 
00018 #include "FWCore/Framework/interface/ESHandle.h"
00019 #include "FWCore/Framework/interface/EventSetup.h"
00020 
00021 //#include "DataFormats/Math/interface/deltaPhi.h"
00022 #include <cmath>
00023 
00024 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00025 
00026 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00027 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00028 #include "FWCore/Utilities/interface/InputTag.h"
00029 
00030 //
00031 // constructors and destructor
00032 //
00033 HLTExclDiJetFilter::HLTExclDiJetFilter(const edm::ParameterSet& iConfig)
00034 {
00035    inputJetTag_ = iConfig.getParameter< edm::InputTag > ("inputJetTag");
00036    saveTag_     = iConfig.getUntrackedParameter<bool>("saveTag");
00037    minPtJet_    = iConfig.getParameter<double> ("minPtJet"); 
00038    minHFe_      = iConfig.getParameter<double> ("minHFe"); 
00039    HF_OR_       = iConfig.getParameter<bool> ("HF_OR"); 
00040    //register your products
00041    produces<trigger::TriggerFilterObjectWithRefs>();
00042 }
00043 
00044 HLTExclDiJetFilter::~HLTExclDiJetFilter(){}
00045 
00046 void
00047 HLTExclDiJetFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00048   edm::ParameterSetDescription desc;
00049   desc.add<edm::InputTag>("inputJetTag",edm::InputTag("hltMCJetCorJetIcone5HF07"));
00050   desc.addUntracked<bool>("saveTag",false);
00051   desc.add<double>("minPtJet",30.0);
00052   desc.add<double>("minHFe",50.0);
00053   desc.add<bool>("HF_OR",false);
00054   descriptions.add("hltExclDiJetFilter",desc);
00055 }
00056 
00057 // ------------ method called to produce the data  ------------
00058 bool
00059 HLTExclDiJetFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00060 {
00061   using namespace std;
00062   using namespace edm;
00063   using namespace reco;
00064   using namespace trigger;
00065 
00066 
00067   // The filter object
00068   auto_ptr<trigger::TriggerFilterObjectWithRefs> 
00069     filterobject (new trigger::TriggerFilterObjectWithRefs(path(),module()));
00070   if (saveTag_) filterobject->addCollectionTag(inputJetTag_);
00071 
00072   Handle<CaloJetCollection> recocalojets;
00073   iEvent.getByLabel(inputJetTag_,recocalojets);
00074 
00075   // look at all candidates,  check cuts and add to filter object
00076     int n(0);
00077 
00078     double ptjet1=0., ptjet2=0.;  
00079     double phijet1=0., phijet2=0.;
00080 
00081   if(recocalojets->size() > 1){
00082     // events with two or more jets
00083 
00084     int countjets =0;
00085 
00086     CaloJetRef JetRef1,JetRef2;
00087 
00088     for (CaloJetCollection::const_iterator recocalojet = recocalojets->begin(); 
00089          recocalojet<=(recocalojets->begin()+1); ++recocalojet) {
00090       
00091       if(countjets==0) {
00092         ptjet1 = recocalojet->pt();
00093         phijet1 = recocalojet->phi();
00094 
00095         JetRef1 = CaloJetRef(recocalojets,distance(recocalojets->begin(),recocalojet));
00096       }
00097       if(countjets==1) {
00098         ptjet2 = recocalojet->pt();
00099         phijet2 = recocalojet->phi(); 
00100 
00101         JetRef2 = CaloJetRef(recocalojets,distance(recocalojets->begin(),recocalojet));
00102       }
00103 
00104       ++countjets;
00105     }
00106 
00107     if(ptjet1>minPtJet_ && ptjet2>minPtJet_ ){
00108       double Dphi=fabs(phijet1-phijet2);
00109       if(Dphi>M_PI) Dphi=2.0*M_PI-Dphi;
00110     if(Dphi>0.5*M_PI) {
00111        filterobject->addObject(TriggerJet,JetRef1);
00112        filterobject->addObject(TriggerJet,JetRef2);
00113        ++n;
00114     }
00115     }
00116 
00117   } // events with two or more jets
00118 
00119 // calotowers
00120 
00121   bool hf_accept=false; 
00122 
00123   if(n>0) {
00124      double ehfp(0.);
00125      double ehfm(0.);
00126 
00127      Handle<CaloTowerCollection> o;
00128      iEvent.getByLabel("hltTowerMakerForAll",o);
00129 //     if( o.isValid()) {
00130       for( CaloTowerCollection::const_iterator cc = o->begin(); cc != o->end(); ++cc ) {
00131        if(fabs(cc->ieta())>28 && cc->energy()<4.0) continue;
00132         if(cc->ieta()>28)  ehfp+=cc->energy();  // HF+ energy
00133         if(cc->ieta()<-28) ehfm+=cc->energy();  // HF- energy
00134       }
00135  //    }
00136 
00137      bool hf_accept_and  = (ehfp<minHFe_) && (ehfm<minHFe_);
00138      bool hf_accept_or  = (ehfp<minHFe_) || (ehfm<minHFe_);
00139 
00140      hf_accept = HF_OR_ ? hf_accept_or : hf_accept_and;
00141 
00142   } // n>0
00143 
00144 
00146   
00147 // filter decision
00148   bool accept(n>0 && hf_accept);
00149 
00150   // put filter object into the Event
00151   iEvent.put(filterobject);
00152   
00153   return accept;
00154 }