File indexing completed on 2024-04-06 12:18:26
0001 #include <cmath>
0002
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "DataFormats/Common/interface/Ref.h"
0005 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0006 #include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
0007 #include "DataFormats/Math/interface/deltaR.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0012
0013 #include "HLT2L1TkMuonL1TkMuonMuRefDR.h"
0014
0015
0016
0017
0018 HLT2L1TkMuonL1TkMuonMuRefDR::HLT2L1TkMuonL1TkMuonMuRefDR(const edm::ParameterSet& iConfig)
0019 : HLTFilter(iConfig),
0020 originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0021 originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0022 inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0023 inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0024 inputToken1_(consumes<trigger::TriggerFilterObjectWithRefs>(inputTag1_)),
0025 inputToken2_(consumes<trigger::TriggerFilterObjectWithRefs>(inputTag2_)),
0026 minDR_(iConfig.getParameter<double>("MinDR")),
0027 min_N_(iConfig.getParameter<int>("MinN")),
0028 same_(inputTag1_.encode() == inputTag2_.encode()) {}
0029
0030 HLT2L1TkMuonL1TkMuonMuRefDR::~HLT2L1TkMuonL1TkMuonMuRefDR() {}
0031
0032 void HLT2L1TkMuonL1TkMuonMuRefDR::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0033 edm::ParameterSetDescription desc;
0034 makeHLTFilterDescription(desc);
0035 std::vector<edm::InputTag> originTag1(1, edm::InputTag("hltOriginal1"));
0036 std::vector<edm::InputTag> originTag2(1, edm::InputTag("hltOriginal2"));
0037 desc.add<std::vector<edm::InputTag>>("originTag1", originTag1);
0038 desc.add<std::vector<edm::InputTag>>("originTag2", originTag2);
0039 desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0040 desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0041 desc.add<double>("MinDR", -1.0);
0042 desc.add<int>("MinN", 1);
0043
0044 descriptions.add("hlt2L1TkMuonL1TkMuonMuRefDR", desc);
0045 }
0046
0047 bool HLT2L1TkMuonL1TkMuonMuRefDR::getCollections(edm::Event& iEvent,
0048 std::vector<l1t::TrackerMuonRef>& coll1,
0049 std::vector<l1t::TrackerMuonRef>& coll2,
0050 trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0051 edm::Handle<trigger::TriggerFilterObjectWithRefs> handle1, handle2;
0052 if (iEvent.getByToken(inputToken1_, handle1) and iEvent.getByToken(inputToken2_, handle2)) {
0053
0054 handle1->getObjects(trigger::TriggerObjectType::TriggerL1TkMu, coll1);
0055 handle2->getObjects(trigger::TriggerObjectType::TriggerL1TkMu, coll2);
0056 const trigger::size_type n1(coll1.size());
0057 const trigger::size_type n2(coll2.size());
0058
0059 if (saveTags()) {
0060 edm::InputTag tagOld;
0061 for (unsigned int i = 0; i < originTag1_.size(); ++i) {
0062 filterproduct.addCollectionTag(originTag1_[i]);
0063 }
0064 tagOld = edm::InputTag();
0065 for (trigger::size_type i1 = 0; i1 != n1; ++i1) {
0066 const edm::ProductID pid(coll1[i1].id());
0067 const std::string& label(iEvent.getProvenance(pid).moduleLabel());
0068 const std::string& instance(iEvent.getProvenance(pid).productInstanceName());
0069 const std::string& process(iEvent.getProvenance(pid).processName());
0070 edm::InputTag tagNew(edm::InputTag(label, instance, process));
0071 if (tagOld.encode() != tagNew.encode()) {
0072 filterproduct.addCollectionTag(tagNew);
0073 tagOld = tagNew;
0074 }
0075 }
0076 for (unsigned int i = 0; i < originTag2_.size(); ++i) {
0077 filterproduct.addCollectionTag(originTag2_[i]);
0078 }
0079 tagOld = edm::InputTag();
0080 for (trigger::size_type i2 = 0; i2 != n2; ++i2) {
0081 const edm::ProductID pid(coll2[i2].id());
0082 const std::string& label(iEvent.getProvenance(pid).moduleLabel());
0083 const std::string& instance(iEvent.getProvenance(pid).productInstanceName());
0084 const std::string& process(iEvent.getProvenance(pid).processName());
0085 edm::InputTag tagNew(edm::InputTag(label, instance, process));
0086 if (tagOld.encode() != tagNew.encode()) {
0087 filterproduct.addCollectionTag(tagNew);
0088 tagOld = tagNew;
0089 }
0090 }
0091 }
0092
0093 return true;
0094 } else
0095 return false;
0096 }
0097
0098 bool HLT2L1TkMuonL1TkMuonMuRefDR::computeDR(edm::Event& iEvent,
0099 l1t::TrackerMuonRef& r1,
0100 l1t::TrackerMuonRef& r2) const {
0101 if (minDR_ < 0.)
0102 return true;
0103
0104 return (reco::deltaR2(r1->phEta(), r1->phPhi(), r2->phEta(), r2->phPhi()) > minDR_ * minDR_);
0105 }
0106
0107
0108 bool HLT2L1TkMuonL1TkMuonMuRefDR::hltFilter(edm::Event& iEvent,
0109 const edm::EventSetup& iSetup,
0110 trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0111
0112
0113
0114 bool accept(false);
0115
0116 std::vector<l1t::TrackerMuonRef> coll1;
0117 std::vector<l1t::TrackerMuonRef> coll2;
0118
0119 if (getCollections(iEvent, coll1, coll2, filterproduct)) {
0120 int n(0);
0121 l1t::TrackerMuonRef r1;
0122 l1t::TrackerMuonRef r2;
0123
0124 for (unsigned int i1 = 0; i1 != coll1.size(); i1++) {
0125 r1 = coll1[i1];
0126 unsigned int I(0);
0127 if (same_) {
0128 I = i1 + 1;
0129 }
0130 for (unsigned int i2 = I; i2 != coll2.size(); i2++) {
0131 r2 = coll2[i2];
0132
0133 if (!computeDR(iEvent, r1, r2))
0134 continue;
0135
0136 n++;
0137 filterproduct.addObject(trigger::TriggerObjectType::TriggerL1TkMu, r1);
0138 filterproduct.addObject(trigger::TriggerObjectType::TriggerL1TkMu, r2);
0139 }
0140 }
0141
0142 accept = accept || (n >= min_N_);
0143 }
0144
0145 return accept;
0146 }
0147
0148 DEFINE_FWK_MODULE(HLT2L1TkMuonL1TkMuonMuRefDR);