CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 
00009 #include "HLTrigger/Egamma/interface/HLTEgammaL1MatchFilterPairs.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 
00020 
00021 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
00022 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
00023 
00024 #include "FWCore/Framework/interface/ESHandle.h"
00025 #include "FWCore/Framework/interface/EventSetup.h"
00026 
00027 #include <vector>
00028 
00029 #define TWOPI 6.283185308
00030 //
00031 // constructors and destructor
00032 //
00033 HLTEgammaL1MatchFilterPairs::HLTEgammaL1MatchFilterPairs(const edm::ParameterSet& iConfig)
00034 {
00035    candIsolatedTag_ = iConfig.getParameter< edm::InputTag > ("candIsolatedTag");
00036    l1IsolatedTag_ = iConfig.getParameter< edm::InputTag > ("l1IsolatedTag");
00037    candNonIsolatedTag_ = iConfig.getParameter< edm::InputTag > ("candNonIsolatedTag");
00038    l1NonIsolatedTag_ = iConfig.getParameter< edm::InputTag > ("l1NonIsolatedTag");
00039    L1SeedFilterTag_ = iConfig.getParameter< edm::InputTag > ("L1SeedFilterTag");
00040  
00041    AlsoNonIsolatedFirst_ = iConfig.getParameter<bool>("AlsoNonIsolatedFirst");
00042    AlsoNonIsolatedSecond_  = iConfig.getParameter<bool>("AlsoNonIsolatedSecond");
00043  
00044    region_eta_size_      = iConfig.getParameter<double> ("region_eta_size");
00045    region_eta_size_ecap_ = iConfig.getParameter<double> ("region_eta_size_ecap");
00046    region_phi_size_      = iConfig.getParameter<double> ("region_phi_size");
00047    barrel_end_           = iConfig.getParameter<double> ("barrel_end");   
00048    endcap_end_           = iConfig.getParameter<double> ("endcap_end");   
00049 
00050    //register your products
00051    produces<trigger::TriggerFilterObjectWithRefs>();
00052 }
00053 
00054 HLTEgammaL1MatchFilterPairs::~HLTEgammaL1MatchFilterPairs(){}
00055 
00056 
00057 // ------------ method called to produce the data  ------------
00058 bool
00059 HLTEgammaL1MatchFilterPairs::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00060 {
00061 
00062   using namespace trigger;
00063   using namespace l1extra;
00064   std::auto_ptr<trigger::TriggerFilterObjectWithRefs> filterobject (new trigger::TriggerFilterObjectWithRefs(path(),module()));
00065   std::vector < std::pair< edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> > > thePairs;
00066   
00067   edm::Handle<reco::RecoEcalCandidateCollection> recoIsolecalcands;
00068   iEvent.getByLabel(candIsolatedTag_,recoIsolecalcands);
00069   edm::Handle<reco::RecoEcalCandidateCollection> recoNonIsolecalcands;
00070   iEvent.getByLabel(candNonIsolatedTag_,recoNonIsolecalcands);
00071 
00072   // create pairs <L1Iso,L1Iso> and optionally <L1Iso, L1NonIso>
00073    for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand1= recoIsolecalcands->begin(); recoecalcand1!=recoIsolecalcands->end(); recoecalcand1++) {
00074      edm::Ref<reco::RecoEcalCandidateCollection> ref1 =  edm::Ref<reco::RecoEcalCandidateCollection>(recoIsolecalcands, distance(recoIsolecalcands->begin(),recoecalcand1) );
00075        for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand2= recoIsolecalcands->begin(); recoecalcand2!=recoIsolecalcands->end(); recoecalcand2++) {
00076          edm::Ref<reco::RecoEcalCandidateCollection> ref2 =  edm::Ref<reco::RecoEcalCandidateCollection>(recoIsolecalcands, distance(recoIsolecalcands->begin(),recoecalcand2) );
00077          if( &(*ref1) != &(*ref2) ) {thePairs.push_back(std::pair< edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> > (ref1,ref2) );}
00078        }
00079        if (AlsoNonIsolatedSecond_){
00080          for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand2= recoNonIsolecalcands->begin(); recoecalcand2!=recoNonIsolecalcands->end(); recoecalcand2++) {
00081            edm::Ref<reco::RecoEcalCandidateCollection> ref2 =  edm::Ref<reco::RecoEcalCandidateCollection>(recoNonIsolecalcands, distance(recoNonIsolecalcands->begin(),recoecalcand2) );
00082            if( &(*ref1) != &(*ref2) ) {thePairs.push_back(std::pair< edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> > (ref1,ref2) );}
00083          }
00084        }
00085    }
00086   
00087 
00088   // create pairs <L1NonIso,L1Iso> and optionally <L1NonIso, L1NonIso>
00089    if (AlsoNonIsolatedFirst_){
00090      for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand1= recoNonIsolecalcands->begin(); recoecalcand1!=recoNonIsolecalcands->end(); recoecalcand1++) {
00091        edm::Ref<reco::RecoEcalCandidateCollection> ref1 =  edm::Ref<reco::RecoEcalCandidateCollection>(recoNonIsolecalcands, distance(recoNonIsolecalcands->begin(),recoecalcand1) );
00092        for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand2= recoIsolecalcands->begin(); recoecalcand2!=recoIsolecalcands->end(); recoecalcand2++) {
00093          edm::Ref<reco::RecoEcalCandidateCollection> ref2 =  edm::Ref<reco::RecoEcalCandidateCollection>(recoIsolecalcands, distance(recoIsolecalcands->begin(),recoecalcand2) );
00094          if( &(*ref1) != &(*ref2) ) {thePairs.push_back(std::pair< edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> > (ref1,ref2) );}
00095        }
00096        if (AlsoNonIsolatedSecond_){
00097          for (reco::RecoEcalCandidateCollection::const_iterator recoecalcand2= recoNonIsolecalcands->begin(); recoecalcand2!=recoNonIsolecalcands->end(); recoecalcand2++) {
00098            edm::Ref<reco::RecoEcalCandidateCollection> ref2 =  edm::Ref<reco::RecoEcalCandidateCollection>(recoNonIsolecalcands, distance(recoNonIsolecalcands->begin(),recoecalcand2) );
00099            if( &(*ref1) != &(*ref2) ) {thePairs.push_back(std::pair< edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> > (ref1,ref2) );}
00100          }
00101        }
00102      }
00103    }
00104 
00105 
00106    // Get the CaloGeometry
00107   edm::ESHandle<L1CaloGeometry> l1CaloGeom ;
00108   iSetup.get<L1CaloGeometryRecord>().get(l1CaloGeom) ;
00109 
00110 
00111   // look at all candidates,  check cuts and add to filter object
00112   int n(0);
00113 
00114   edm::Handle<trigger::TriggerFilterObjectWithRefs> L1SeedOutput;
00115   iEvent.getByLabel (L1SeedFilterTag_,L1SeedOutput);
00116 
00117   std::vector<l1extra::L1EmParticleRef > l1EGIso;       
00118   L1SeedOutput->getObjects(TriggerL1IsoEG, l1EGIso);
00119   std::vector<l1extra::L1EmParticleRef > l1EGNonIso;       
00120   L1SeedOutput->getObjects(TriggerL1NoIsoEG, l1EGNonIso);
00121 
00122 //   std::cout<<"L1EGIso size: "<<l1EGIso.size()<<std::endl;
00123 //   for (unsigned int i=0; i<l1EGIso.size(); i++){std::cout<<"L1EGIso Et Eta phi: "<<l1EGIso[i]->et()<<" "<<l1EGIso[i]->eta()<<" "<<l1EGIso[i]->phi()<<std::endl;}
00124 //   std::cout<<"L1EGNonIso size: "<<l1EGNonIso.size()<<std::endl;
00125 //   for (unsigned int i=0; i<l1EGNonIso.size(); i++){std::cout<<"L1EGNonIso Et Eta phi: "<<l1EGNonIso[i]->et()<<" "<<l1EGNonIso[i]->eta()<<" "<<l1EGNonIso[i]->phi()<<std::endl;}
00126 //   std::cout<<"Lpair vector size: "<<thePairs.size()<<std::endl;
00127   
00128   std::vector < std::pair< edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> > >::iterator  pairsIt;
00129   for (pairsIt = thePairs.begin(); pairsIt != thePairs.end(); pairsIt++){
00130 //      edm::Ref<reco::RecoEcalCandidateCollection> r1 = pairsIt->first;
00131 //      edm::Ref<reco::RecoEcalCandidateCollection> r2 = pairsIt->second;
00132 //      std::cout<<"1) Et Eta phi: "<<r1->et()<<" "<<r1->eta()<<" "<<r1->phi()<<" 2) Et eta phi: "<<r2->et()<<" "<<r2->eta()<<" "<<r2->phi()<<std::endl;
00133     
00134     if ( CheckL1Matching(pairsIt->first,l1EGIso,l1EGNonIso) && CheckL1Matching(pairsIt->second,l1EGIso,l1EGNonIso) ){
00135       filterobject->addObject(TriggerCluster, pairsIt->first);
00136       filterobject->addObject(TriggerCluster, pairsIt->second);
00137       n++;
00138     } 
00139   }
00140 
00141 
00142   //  std::cout<<"#####################################################"<<std::endl;
00143   // filter decision
00144   bool accept(n>=1);
00145   
00146   // put filter object into the Event
00147   iEvent.put(filterobject);
00148   
00149   return accept;
00150 }
00151 
00152 bool HLTEgammaL1MatchFilterPairs::CheckL1Matching(edm::Ref<reco::RecoEcalCandidateCollection>ref,std::vector<l1extra::L1EmParticleRef >& l1EGIso,std::vector<l1extra::L1EmParticleRef >& l1EGNonIso){
00153 
00154   for (unsigned int i=0; i<l1EGIso.size(); i++) {
00155     //ORCA matching method
00156     double etaBinLow  = 0.;
00157     double etaBinHigh = 0.;     
00158     if(fabs(ref->eta()) < barrel_end_){
00159       etaBinLow = l1EGIso[i]->eta() - region_eta_size_/2.;
00160       etaBinHigh = etaBinLow + region_eta_size_;
00161     }
00162     else{
00163       etaBinLow = l1EGIso[i]->eta() - region_eta_size_ecap_/2.;
00164       etaBinHigh = etaBinLow + region_eta_size_ecap_;
00165     }
00166 
00167     float deltaphi=fabs(ref->phi() -l1EGIso[i]->phi());
00168     if(deltaphi>TWOPI) deltaphi-=TWOPI;
00169     if(deltaphi>TWOPI/2.) deltaphi=TWOPI-deltaphi;
00170 
00171     if(ref->eta() < etaBinHigh && ref->eta() > etaBinLow && deltaphi <region_phi_size_/2. )  {return true;}
00172 
00173   }
00174 
00175   for (unsigned int i=0; i<l1EGNonIso.size(); i++) {
00176     //ORCA matching method
00177     double etaBinLow  = 0.;
00178     double etaBinHigh = 0.;     
00179     if(fabs(ref->eta()) < barrel_end_){
00180       etaBinLow = l1EGNonIso[i]->eta() - region_eta_size_/2.;
00181       etaBinHigh = etaBinLow + region_eta_size_;
00182     }
00183     else{
00184       etaBinLow = l1EGNonIso[i]->eta() - region_eta_size_ecap_/2.;
00185       etaBinHigh = etaBinLow + region_eta_size_ecap_;
00186     }
00187 
00188     float deltaphi=fabs(ref->phi() - l1EGNonIso[i]->phi());
00189     if(deltaphi>TWOPI) deltaphi-=TWOPI;
00190     if(deltaphi>TWOPI/2.) deltaphi=TWOPI-deltaphi;
00191 
00192     if(ref->eta() < etaBinHigh && ref->eta() > etaBinLow && deltaphi <region_phi_size_/2. )  {return true;}
00193         
00194   }
00195 
00196   return false;
00197 }