Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-25 23:59:49

0001 /** \class HLTEgammaL1MatchFilterPairs
0002  *
0003  *
0004  *  \author Monica Vazquez Acosta (CERN)
0005  *
0006  */
0007 #include "HLTEgammaL1MatchFilterPairs.h"
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 
0015 #include <vector>
0016 #include <cmath>
0017 
0018 #define TWOPI 2 * M_PI
0019 //
0020 // constructors and destructor
0021 //
0022 HLTEgammaL1MatchFilterPairs::HLTEgammaL1MatchFilterPairs(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) {
0023   candIsolatedTag_ = iConfig.getParameter<edm::InputTag>("candIsolatedTag");
0024   l1IsolatedTag_ = iConfig.getParameter<edm::InputTag>("l1IsolatedTag");
0025   candNonIsolatedTag_ = iConfig.getParameter<edm::InputTag>("candNonIsolatedTag");
0026   l1NonIsolatedTag_ = iConfig.getParameter<edm::InputTag>("l1NonIsolatedTag");
0027   L1SeedFilterTag_ = iConfig.getParameter<edm::InputTag>("L1SeedFilterTag");
0028 
0029   AlsoNonIsolatedFirst_ = iConfig.getParameter<bool>("AlsoNonIsolatedFirst");
0030   AlsoNonIsolatedSecond_ = iConfig.getParameter<bool>("AlsoNonIsolatedSecond");
0031 
0032   region_eta_size_ = iConfig.getParameter<double>("region_eta_size");
0033   region_eta_size_ecap_ = iConfig.getParameter<double>("region_eta_size_ecap");
0034   region_phi_size_ = iConfig.getParameter<double>("region_phi_size");
0035   barrel_end_ = iConfig.getParameter<double>("barrel_end");
0036   endcap_end_ = iConfig.getParameter<double>("endcap_end");
0037 
0038   candIsolatedToken_ = consumes<reco::RecoEcalCandidateCollection>(candIsolatedTag_);
0039   candNonIsolatedToken_ = consumes<reco::RecoEcalCandidateCollection>(candNonIsolatedTag_);
0040   L1SeedFilterToken_ = consumes<trigger::TriggerFilterObjectWithRefs>(L1SeedFilterTag_);
0041 }
0042 
0043 HLTEgammaL1MatchFilterPairs::~HLTEgammaL1MatchFilterPairs() = default;
0044 
0045 void HLTEgammaL1MatchFilterPairs::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0046   edm::ParameterSetDescription desc;
0047   makeHLTFilterDescription(desc);
0048   desc.add<edm::InputTag>("candIsolatedTag", edm::InputTag("hltRecoIsolatedEcalCandidate"));
0049   desc.add<edm::InputTag>("l1IsolatedTag", edm::InputTag("l1extraParticles", "Isolated"));
0050   desc.add<edm::InputTag>("candNonIsolatedTag", edm::InputTag("hltRecoNonIsolatedEcalCandidate"));
0051   desc.add<edm::InputTag>("l1NonIsolatedTag", edm::InputTag("l1extraParticles", "NonIsolated"));
0052   desc.add<edm::InputTag>("L1SeedFilterTag", edm::InputTag("theL1SeedFilter"));
0053   desc.add<bool>("AlsoNonIsolatedFirst", false);
0054   desc.add<bool>("AlsoNonIsolatedSecond", false);
0055   desc.add<double>("region_eta_size", 0.522);
0056   desc.add<double>("region_eta_size_ecap", 1.0);
0057   desc.add<double>("region_phi_size", 1.044);
0058   desc.add<double>("barrel_end", 1.4791);
0059   desc.add<double>("endcap_end", 2.65);
0060   descriptions.add("hltEgammaL1MatchFilterPairs", desc);
0061 }
0062 
0063 // ------------ method called to produce the data  ------------
0064 bool HLTEgammaL1MatchFilterPairs::hltFilter(edm::Event& iEvent,
0065                                             const edm::EventSetup& iSetup,
0066                                             trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0067   using namespace trigger;
0068   using namespace l1extra;
0069   std::vector<std::pair<edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> > >
0070       thePairs;
0071 
0072   edm::Handle<reco::RecoEcalCandidateCollection> recoIsolecalcands;
0073   iEvent.getByToken(candIsolatedToken_, recoIsolecalcands);
0074   edm::Handle<reco::RecoEcalCandidateCollection> recoNonIsolecalcands;
0075   iEvent.getByToken(candNonIsolatedToken_, recoNonIsolecalcands);
0076 
0077   // create pairs <L1Iso,L1Iso> and optionally <L1Iso, L1NonIso>
0078   for (auto recoecalcand1 = recoIsolecalcands->begin(); recoecalcand1 != recoIsolecalcands->end(); recoecalcand1++) {
0079     edm::Ref<reco::RecoEcalCandidateCollection> ref1 = edm::Ref<reco::RecoEcalCandidateCollection>(
0080         recoIsolecalcands, distance(recoIsolecalcands->begin(), recoecalcand1));
0081     for (auto recoecalcand2 = recoIsolecalcands->begin(); recoecalcand2 != recoIsolecalcands->end(); recoecalcand2++) {
0082       edm::Ref<reco::RecoEcalCandidateCollection> ref2 = edm::Ref<reco::RecoEcalCandidateCollection>(
0083           recoIsolecalcands, distance(recoIsolecalcands->begin(), recoecalcand2));
0084       if (&(*ref1) != &(*ref2)) {
0085         thePairs.push_back(
0086             std::pair<edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> >(ref1,
0087                                                                                                                  ref2));
0088       }
0089     }
0090     if (AlsoNonIsolatedSecond_) {
0091       for (auto recoecalcand2 = recoNonIsolecalcands->begin(); recoecalcand2 != recoNonIsolecalcands->end();
0092            recoecalcand2++) {
0093         edm::Ref<reco::RecoEcalCandidateCollection> ref2 = edm::Ref<reco::RecoEcalCandidateCollection>(
0094             recoNonIsolecalcands, distance(recoNonIsolecalcands->begin(), recoecalcand2));
0095         if (&(*ref1) != &(*ref2)) {
0096           thePairs.push_back(
0097               std::pair<edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> >(
0098                   ref1, ref2));
0099         }
0100       }
0101     }
0102   }
0103 
0104   // create pairs <L1NonIso,L1Iso> and optionally <L1NonIso, L1NonIso>
0105   if (AlsoNonIsolatedFirst_) {
0106     for (auto recoecalcand1 = recoNonIsolecalcands->begin(); recoecalcand1 != recoNonIsolecalcands->end();
0107          recoecalcand1++) {
0108       edm::Ref<reco::RecoEcalCandidateCollection> ref1 = edm::Ref<reco::RecoEcalCandidateCollection>(
0109           recoNonIsolecalcands, distance(recoNonIsolecalcands->begin(), recoecalcand1));
0110       for (auto recoecalcand2 = recoIsolecalcands->begin(); recoecalcand2 != recoIsolecalcands->end();
0111            recoecalcand2++) {
0112         edm::Ref<reco::RecoEcalCandidateCollection> ref2 = edm::Ref<reco::RecoEcalCandidateCollection>(
0113             recoIsolecalcands, distance(recoIsolecalcands->begin(), recoecalcand2));
0114         if (&(*ref1) != &(*ref2)) {
0115           thePairs.push_back(
0116               std::pair<edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> >(
0117                   ref1, ref2));
0118         }
0119       }
0120       if (AlsoNonIsolatedSecond_) {
0121         for (auto recoecalcand2 = recoNonIsolecalcands->begin(); recoecalcand2 != recoNonIsolecalcands->end();
0122              recoecalcand2++) {
0123           edm::Ref<reco::RecoEcalCandidateCollection> ref2 = edm::Ref<reco::RecoEcalCandidateCollection>(
0124               recoNonIsolecalcands, distance(recoNonIsolecalcands->begin(), recoecalcand2));
0125           if (&(*ref1) != &(*ref2)) {
0126             thePairs.push_back(
0127                 std::pair<edm::Ref<reco::RecoEcalCandidateCollection>, edm::Ref<reco::RecoEcalCandidateCollection> >(
0128                     ref1, ref2));
0129           }
0130         }
0131       }
0132     }
0133   }
0134 
0135   // look at all candidates,  check cuts and add to filter object
0136   int n(0);
0137 
0138   edm::Handle<trigger::TriggerFilterObjectWithRefs> L1SeedOutput;
0139   iEvent.getByToken(L1SeedFilterToken_, L1SeedOutput);
0140 
0141   std::vector<l1extra::L1EmParticleRef> l1EGIso;
0142   L1SeedOutput->getObjects(TriggerL1IsoEG, l1EGIso);
0143   std::vector<l1extra::L1EmParticleRef> l1EGNonIso;
0144   L1SeedOutput->getObjects(TriggerL1NoIsoEG, l1EGNonIso);
0145 
0146   //   std::cout<<"L1EGIso size: "<<l1EGIso.size()<<std::endl;
0147   //   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;}
0148   //   std::cout<<"L1EGNonIso size: "<<l1EGNonIso.size()<<std::endl;
0149   //   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;}
0150   //   std::cout<<"Lpair vector size: "<<thePairs.size()<<std::endl;
0151 
0152   std::vector<std::pair<edm::Ref<reco::RecoEcalCandidateCollection>,
0153                         edm::Ref<reco::RecoEcalCandidateCollection> > >::iterator pairsIt;
0154   for (pairsIt = thePairs.begin(); pairsIt != thePairs.end(); pairsIt++) {
0155     //      edm::Ref<reco::RecoEcalCandidateCollection> r1 = pairsIt->first;
0156     //      edm::Ref<reco::RecoEcalCandidateCollection> r2 = pairsIt->second;
0157     //      std::cout<<"1) Et Eta phi: "<<r1->et()<<" "<<r1->eta()<<" "<<r1->phi()<<" 2) Et eta phi: "<<r2->et()<<" "<<r2->eta()<<" "<<r2->phi()<<std::endl;
0158 
0159     if (CheckL1Matching(pairsIt->first, l1EGIso, l1EGNonIso) && CheckL1Matching(pairsIt->second, l1EGIso, l1EGNonIso)) {
0160       filterproduct.addObject(TriggerCluster, pairsIt->first);
0161       filterproduct.addObject(TriggerCluster, pairsIt->second);
0162       n++;
0163     }
0164   }
0165 
0166   //  std::cout<<"#####################################################"<<std::endl;
0167   // filter decision
0168   bool accept(n >= 1);
0169 
0170   return accept;
0171 }
0172 
0173 bool HLTEgammaL1MatchFilterPairs::CheckL1Matching(edm::Ref<reco::RecoEcalCandidateCollection> ref,
0174                                                   std::vector<l1extra::L1EmParticleRef>& l1EGIso,
0175                                                   std::vector<l1extra::L1EmParticleRef>& l1EGNonIso) const {
0176   for (auto& i : l1EGIso) {
0177     //ORCA matching method
0178     double etaBinLow = 0.;
0179     double etaBinHigh = 0.;
0180     if (fabs(ref->eta()) < barrel_end_) {
0181       etaBinLow = i->eta() - region_eta_size_ / 2.;
0182       etaBinHigh = etaBinLow + region_eta_size_;
0183     } else {
0184       etaBinLow = i->eta() - region_eta_size_ecap_ / 2.;
0185       etaBinHigh = etaBinLow + region_eta_size_ecap_;
0186     }
0187 
0188     float deltaphi = fabs(ref->phi() - i->phi());
0189     if (deltaphi > TWOPI)
0190       deltaphi -= TWOPI;
0191     if (deltaphi > M_PI)
0192       deltaphi = TWOPI - deltaphi;
0193 
0194     if (ref->eta() < etaBinHigh && ref->eta() > etaBinLow && deltaphi < region_phi_size_ / 2.) {
0195       return true;
0196     }
0197   }
0198 
0199   for (auto& i : l1EGNonIso) {
0200     //ORCA matching method
0201     double etaBinLow = 0.;
0202     double etaBinHigh = 0.;
0203     if (fabs(ref->eta()) < barrel_end_) {
0204       etaBinLow = i->eta() - region_eta_size_ / 2.;
0205       etaBinHigh = etaBinLow + region_eta_size_;
0206     } else {
0207       etaBinLow = i->eta() - region_eta_size_ecap_ / 2.;
0208       etaBinHigh = etaBinLow + region_eta_size_ecap_;
0209     }
0210 
0211     float deltaphi = fabs(ref->phi() - i->phi());
0212     if (deltaphi > TWOPI)
0213       deltaphi -= TWOPI;
0214     if (deltaphi > M_PI)
0215       deltaphi = TWOPI - deltaphi;
0216 
0217     if (ref->eta() < etaBinHigh && ref->eta() > etaBinLow && deltaphi < region_phi_size_ / 2.) {
0218       return true;
0219     }
0220   }
0221 
0222   return false;
0223 }
0224 
0225 // declare this class as a framework plugin
0226 #include "FWCore/Framework/interface/MakerMacros.h"
0227 DEFINE_FWK_MODULE(HLTEgammaL1MatchFilterPairs);