CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/Egamma/src/HLTEgammaL1MatchFilterRegional.cc

Go to the documentation of this file.
00001 
00009 #include "HLTrigger/Egamma/interface/HLTEgammaL1MatchFilterRegional.h"
00010 
00011 //#include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00012 
00013 #include "DataFormats/Common/interface/Handle.h"
00014 
00015 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00016 
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 
00019 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00020 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
00021 
00022 
00023 
00024 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
00025 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
00026 
00027 #include "FWCore/Framework/interface/ESHandle.h"
00028 #include "FWCore/Framework/interface/EventSetup.h"
00029 
00030 #define TWOPI 6.283185308
00031 //
00032 // constructors and destructor
00033 //
00034 HLTEgammaL1MatchFilterRegional::HLTEgammaL1MatchFilterRegional(const edm::ParameterSet& iConfig)
00035 {
00036    candIsolatedTag_ = iConfig.getParameter< edm::InputTag > ("candIsolatedTag");
00037    l1IsolatedTag_ = iConfig.getParameter< edm::InputTag > ("l1IsolatedTag");
00038    candNonIsolatedTag_ = iConfig.getParameter< edm::InputTag > ("candNonIsolatedTag");
00039    l1NonIsolatedTag_ = iConfig.getParameter< edm::InputTag > ("l1NonIsolatedTag");
00040    L1SeedFilterTag_ = iConfig.getParameter< edm::InputTag > ("L1SeedFilterTag");
00041    ncandcut_  = iConfig.getParameter<int> ("ncandcut");
00042    doIsolated_   = iConfig.getParameter<bool>("doIsolated");
00043 
00044 
00045    region_eta_size_      = iConfig.getParameter<double> ("region_eta_size");
00046    region_eta_size_ecap_ = iConfig.getParameter<double> ("region_eta_size_ecap");
00047    region_phi_size_      = iConfig.getParameter<double> ("region_phi_size");
00048    barrel_end_           = iConfig.getParameter<double> ("barrel_end");   
00049    endcap_end_           = iConfig.getParameter<double> ("endcap_end");   
00050 
00051    //register your products
00052    produces<trigger::TriggerFilterObjectWithRefs>();
00053 }
00054 
00055 HLTEgammaL1MatchFilterRegional::~HLTEgammaL1MatchFilterRegional(){}
00056 
00057 
00058 // ------------ method called to produce the data  ------------
00059 bool
00060 HLTEgammaL1MatchFilterRegional::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00061 {
00062   // std::cout <<"runnr "<<iEvent.id().run()<<" event "<<iEvent.id().event()<<std::endl;
00063   using namespace trigger;
00064   using namespace l1extra;
00065   //using namespace std;
00066   std::auto_ptr<trigger::TriggerFilterObjectWithRefs> filterobject (new trigger::TriggerFilterObjectWithRefs(path(),module()));
00067 
00068   edm::Ref<reco::RecoEcalCandidateCollection> ref;
00069 
00070   // Get the CaloGeometry
00071   edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
00072   iSetup.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
00073 
00074 
00075   // look at all candidates,  check cuts and add to filter object
00076   int n(0);
00077 
00078   // Get the recoEcalCandidates
00079   edm::Handle<reco::RecoEcalCandidateCollection> recoIsolecalcands;
00080   iEvent.getByLabel(candIsolatedTag_,recoIsolecalcands);
00081 
00082 
00083   edm::Handle<trigger::TriggerFilterObjectWithRefs> L1SeedOutput;
00084 
00085   iEvent.getByLabel (L1SeedFilterTag_,L1SeedOutput);
00086 
00087   std::vector<l1extra::L1EmParticleRef > l1EGIso;       
00088   L1SeedOutput->getObjects(TriggerL1IsoEG, l1EGIso);
00089   
00090   std::vector<l1extra::L1EmParticleRef > l1EGNonIso;       
00091   L1SeedOutput->getObjects(TriggerL1NoIsoEG, l1EGNonIso);
00092 
00093   
00094   for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand= recoIsolecalcands->begin(); recoecalcand!=recoIsolecalcands->end(); recoecalcand++) {
00095 
00096   
00097     if(fabs(recoecalcand->eta()) < endcap_end_){
00098       //SC should be inside the ECAL fiducial volume
00099 
00100       bool matchedSCIso = matchedToL1Cand(l1EGIso,recoecalcand->eta(),recoecalcand->phi());
00101 
00102       //now due to SC cleaning given preference to isolated candiates, 
00103       //if there is an isolated and nonisolated L1 cand in the same eta/phi bin
00104       //the corresponding SC will be only in the isolated SC collection
00105       //so if we are !doIsolated_, we need to run over the nonisol L1 collection as well 
00106       bool matchedSCNonIso=false;
00107       if(!doIsolated_){
00108         matchedSCNonIso =  matchedToL1Cand(l1EGNonIso,recoecalcand->eta(),recoecalcand->phi());
00109       }
00110        
00111 
00112       if(matchedSCIso || matchedSCNonIso) {
00113         n++;
00114 
00115         ref = edm::Ref<reco::RecoEcalCandidateCollection>(recoIsolecalcands, distance(recoIsolecalcands->begin(),recoecalcand) );       
00116         filterobject->addObject(TriggerCluster, ref);
00117       }//end  matched check
00118 
00119     }//end endcap fiduical check
00120     
00121   }//end loop over all isolated RecoEcalCandidates
00122   
00123 
00124   if(!doIsolated_) {
00125     edm::Handle<reco::RecoEcalCandidateCollection> recoNonIsolecalcands;
00126     iEvent.getByLabel(candNonIsolatedTag_,recoNonIsolecalcands);
00127     
00128     for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand= recoNonIsolecalcands->begin(); recoecalcand!=recoNonIsolecalcands->end(); recoecalcand++) {
00129       if(fabs(recoecalcand->eta()) < endcap_end_){
00130         bool matchedSCNonIso =  matchedToL1Cand(l1EGNonIso,recoecalcand->eta(),recoecalcand->phi());
00131         
00132         if(matchedSCNonIso) {
00133           n++;
00134           ref = edm::Ref<reco::RecoEcalCandidateCollection>(recoNonIsolecalcands, distance(recoNonIsolecalcands->begin(),recoecalcand) );       
00135           filterobject->addObject(TriggerCluster, ref);
00136         }//end  matched check
00137         
00138       }//end endcap fiduical check
00139       
00140     }//end loop over all isolated RecoEcalCandidates
00141   }//end doIsolatedCheck
00142   
00143 
00144   // filter decision
00145   bool accept(n>=ncandcut_);
00146   
00147   // put filter object into the Event
00148   iEvent.put(filterobject);
00149   
00150   // if(!accept)std::cout <<"FAILING FILTER"<<std::endl;
00151 
00152   return accept;
00153 }
00154 
00155 
00156 bool 
00157 HLTEgammaL1MatchFilterRegional::matchedToL1Cand(const std::vector<l1extra::L1EmParticleRef >& l1Cands,const float scEta,const float scPhi) 
00158 {
00159   for (unsigned int i=0; i<l1Cands.size(); i++) {
00160     //ORCA matching method
00161     double etaBinLow  = 0.;
00162     double etaBinHigh = 0.;     
00163     if(fabs(scEta) < barrel_end_){
00164       etaBinLow = l1Cands[i]->eta() - region_eta_size_/2.;
00165       etaBinHigh = etaBinLow + region_eta_size_;
00166     }
00167     else{
00168       etaBinLow = l1Cands[i]->eta() - region_eta_size_ecap_/2.;
00169       etaBinHigh = etaBinLow + region_eta_size_ecap_;
00170     }
00171     
00172     float deltaphi=fabs(scPhi -l1Cands[i]->phi());
00173     if(deltaphi>TWOPI) deltaphi-=TWOPI;
00174     if(deltaphi>TWOPI/2.) deltaphi=TWOPI-deltaphi;
00175     
00176     if(scEta < etaBinHigh && scEta > etaBinLow && deltaphi <region_phi_size_/2. )  {
00177       return true;
00178     }
00179   }
00180   return false;
00181 }