Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-03 04:17:59

0001 #include "HLTDoubletDZ.h"
0002 
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "DataFormats/EgammaCandidates/interface/Electron.h"
0005 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0006 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0007 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0008 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
0009 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateFwd.h"
0010 #include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
0011 #include "DataFormats/L1TParticleFlow/interface/HPSPFTau.h"
0012 #include "DataFormats/L1TParticleFlow/interface/HPSPFTauFwd.h"
0013 #include "DataFormats/L1TParticleFlow/interface/PFTau.h"
0014 #include "DataFormats/Math/interface/deltaR.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0019 
0020 #include <cmath>
0021 
0022 template <typename T1, typename T2>
0023 HLTDoubletDZ<T1, T2>::HLTDoubletDZ(edm::ParameterSet const& iConfig)
0024     : HLTFilter(iConfig),
0025       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0026       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0027       inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0028       inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0029       inputToken1_(consumes(inputTag1_)),
0030       inputToken2_(consumes(inputTag2_)),
0031       electronToken_(edm::EDGetTokenT<reco::ElectronCollection>()),
0032       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0033       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0034       minDR_(iConfig.getParameter<double>("MinDR")),
0035       minDR2_(minDR_ * minDR_),
0036       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0037       min_N_(iConfig.getParameter<int>("MinN")),
0038       minPixHitsForDZ_(iConfig.getParameter<int>("MinPixHitsForDZ")),
0039       checkSC_(iConfig.getParameter<bool>("checkSC")),
0040       same_(inputTag1_.encode() == inputTag2_.encode())  // same collections to be compared?
0041 {}
0042 
0043 template <>
0044 HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
0045     : HLTFilter(iConfig),
0046       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0047       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0048       electronToken_(edm::EDGetTokenT<reco::ElectronCollection>()),
0049       l1GTAlgoBlockTag_(iConfig.template getParameter<edm::InputTag>("l1GTAlgoBlockTag")),
0050       algoBlockToken_(consumes<l1t::P2GTAlgoBlockMap>(l1GTAlgoBlockTag_)),
0051       l1GTAlgoName1_(iConfig.template getParameter<std::string>("l1GTAlgoName1")),
0052       l1GTAlgoName2_(iConfig.template getParameter<std::string>("l1GTAlgoName2")),
0053       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0054       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0055       minDR_(iConfig.getParameter<double>("MinDR")),
0056       minDR2_(minDR_ * minDR_),
0057       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0058       min_N_(iConfig.getParameter<int>("MinN")),
0059       minPixHitsForDZ_(iConfig.getParameter<int>("MinPixHitsForDZ")),
0060       checkSC_(iConfig.getParameter<bool>("checkSC")),
0061       same_(l1GTAlgoName1_ == l1GTAlgoName2_)  // same collections to be compared?
0062 {}
0063 
0064 template <>
0065 HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoEcalCandidate>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
0066     : HLTFilter(iConfig),
0067       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0068       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0069       inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0070       inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0071       inputToken1_(consumes(inputTag1_)),
0072       inputToken2_(consumes(inputTag2_)),
0073       electronToken_(consumes(iConfig.getParameter<edm::InputTag>("electronTag"))),
0074       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0075       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0076       minDR_(iConfig.getParameter<double>("MinDR")),
0077       minDR2_(minDR_ * minDR_),
0078       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0079       min_N_(iConfig.getParameter<int>("MinN")),
0080       minPixHitsForDZ_(iConfig.getParameter<int>("MinPixHitsForDZ")),
0081       checkSC_(iConfig.getParameter<bool>("checkSC")),
0082       same_(inputTag1_.encode() == inputTag2_.encode())  // same collections to be compared?
0083 {}
0084 
0085 template <>
0086 HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoEcalCandidate>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
0087     : HLTFilter(iConfig),
0088       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0089       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0090       inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0091       inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0092       inputToken1_(consumes(inputTag1_)),
0093       inputToken2_(consumes(inputTag2_)),
0094       electronToken_(consumes(iConfig.getParameter<edm::InputTag>("electronTag"))),
0095       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0096       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0097       minDR_(iConfig.getParameter<double>("MinDR")),
0098       minDR2_(minDR_ * minDR_),
0099       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0100       min_N_(iConfig.getParameter<int>("MinN")),
0101       minPixHitsForDZ_(iConfig.getParameter<int>("MinPixHitsForDZ")),
0102       checkSC_(iConfig.getParameter<bool>("checkSC")),
0103       same_(inputTag1_.encode() == inputTag2_.encode())  // same collections to be compared?
0104 {}
0105 
0106 template <>
0107 HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoChargedCandidate>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
0108     : HLTFilter(iConfig),
0109       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0110       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0111       inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0112       inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0113       inputToken1_(consumes(inputTag1_)),
0114       inputToken2_(consumes(inputTag2_)),
0115       electronToken_(consumes(iConfig.getParameter<edm::InputTag>("electronTag"))),
0116       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0117       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0118       minDR_(iConfig.getParameter<double>("MinDR")),
0119       minDR2_(minDR_ * minDR_),
0120       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0121       min_N_(iConfig.getParameter<int>("MinN")),
0122       minPixHitsForDZ_(iConfig.getParameter<int>("MinPixHitsForDZ")),
0123       checkSC_(iConfig.getParameter<bool>("checkSC")),
0124       same_(inputTag1_.encode() == inputTag2_.encode())  // same collections to be compared?
0125 {}
0126 
0127 template <>
0128 HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
0129     : HLTFilter(iConfig),
0130       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0131       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0132       inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0133       inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0134       inputToken1_(consumes(inputTag1_)),
0135       inputToken2_(consumes(inputTag2_)),
0136       electronToken_(edm::EDGetTokenT<reco::ElectronCollection>()),
0137       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0138       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0139       minDR_(iConfig.getParameter<double>("MinDR")),
0140       minDR2_(minDR_ * minDR_),
0141       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0142       min_N_(iConfig.getParameter<int>("MinN")),
0143       minPixHitsForDZ_(0),
0144       checkSC_(false),
0145       same_(inputTag1_.encode() == inputTag2_.encode())  // same collections to be compared?
0146 {}
0147 
0148 template <>
0149 HLTDoubletDZ<l1t::PFTau, l1t::PFTau>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
0150     : HLTFilter(iConfig),
0151       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0152       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0153       inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0154       inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0155       inputToken1_(consumes(inputTag1_)),
0156       inputToken2_(consumes(inputTag2_)),
0157       electronToken_(edm::EDGetTokenT<reco::ElectronCollection>()),
0158       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0159       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0160       minDR_(iConfig.getParameter<double>("MinDR")),
0161       minDR2_(minDR_ * minDR_),
0162       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0163       min_N_(iConfig.getParameter<int>("MinN")),
0164       minPixHitsForDZ_(0),
0165       checkSC_(false),
0166       same_(inputTag1_.encode() == inputTag2_.encode())  // same collections to be compared?
0167 {}
0168 
0169 template <>
0170 HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
0171     : HLTFilter(iConfig),
0172       originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
0173       originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
0174       inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
0175       inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
0176       inputToken1_(consumes(inputTag1_)),
0177       inputToken2_(consumes(inputTag2_)),
0178       electronToken_(edm::EDGetTokenT<reco::ElectronCollection>()),
0179       triggerType1_(iConfig.getParameter<int>("triggerType1")),
0180       triggerType2_(iConfig.getParameter<int>("triggerType2")),
0181       minDR_(iConfig.getParameter<double>("MinDR")),
0182       minDR2_(minDR_ * minDR_),
0183       maxDZ_(iConfig.getParameter<double>("MaxDZ")),
0184       min_N_(iConfig.getParameter<int>("MinN")),
0185       minPixHitsForDZ_(0),
0186       checkSC_(false),
0187       same_(inputTag1_.encode() == inputTag2_.encode())  // same collections to be compared?
0188 {}
0189 
0190 template <>
0191 void HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::fillDescriptions(
0192     edm::ConfigurationDescriptions& descriptions) {
0193   edm::ParameterSetDescription desc;
0194   makeHLTFilterDescription(desc);
0195   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0196   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0197   desc.add<edm::InputTag>("l1GTAlgoBlockTag", edm::InputTag("l1tGTAlgoBlockProducer"));
0198   desc.add<std::string>("l1GTAlgoName1", "");
0199   desc.add<std::string>("l1GTAlgoName2", "");
0200   desc.add<int>("triggerType1", 0);
0201   desc.add<int>("triggerType2", 0);
0202   desc.add<double>("MinDR", -1.0);
0203   desc.add<double>("MaxDZ", 0.2);
0204   desc.add<int>("MinPixHitsForDZ", 0);
0205   desc.add<bool>("checkSC", false);
0206   desc.add<int>("MinN", 1);
0207   descriptions.addWithDefaultLabel(desc);
0208 }
0209 
0210 template <typename T1, typename T2>
0211 void HLTDoubletDZ<T1, T2>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0212   edm::ParameterSetDescription desc;
0213   makeHLTFilterDescription(desc);
0214   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0215   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0216   desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0217   desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0218   desc.add<int>("triggerType1", 0);
0219   desc.add<int>("triggerType2", 0);
0220   desc.add<double>("MinDR", -1.0);
0221   desc.add<double>("MaxDZ", 0.2);
0222   desc.add<int>("MinN", 1);
0223   desc.add<int>("MinPixHitsForDZ", 0);
0224   desc.add<bool>("checkSC", false);
0225   descriptions.addWithDefaultLabel(desc);
0226 }
0227 
0228 template <>
0229 void HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoEcalCandidate>::fillDescriptions(
0230     edm::ConfigurationDescriptions& descriptions) {
0231   edm::ParameterSetDescription desc;
0232   makeHLTFilterDescription(desc);
0233   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0234   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0235   desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0236   desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0237   desc.add<edm::InputTag>("electronTag", edm::InputTag("electronTag"));
0238   desc.add<int>("triggerType1", 0);
0239   desc.add<int>("triggerType2", 0);
0240   desc.add<double>("MinDR", -1.0);
0241   desc.add<double>("MaxDZ", 0.2);
0242   desc.add<int>("MinN", 1);
0243   desc.add<int>("MinPixHitsForDZ", 0);
0244   desc.add<bool>("checkSC", false);
0245   descriptions.addWithDefaultLabel(desc);
0246 }
0247 
0248 template <>
0249 void HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoEcalCandidate>::fillDescriptions(
0250     edm::ConfigurationDescriptions& descriptions) {
0251   edm::ParameterSetDescription desc;
0252   makeHLTFilterDescription(desc);
0253   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0254   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0255   desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0256   desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0257   desc.add<edm::InputTag>("electronTag", edm::InputTag("electronTag"));
0258   desc.add<int>("triggerType1", 0);
0259   desc.add<int>("triggerType2", 0);
0260   desc.add<double>("MinDR", -1.0);
0261   desc.add<double>("MaxDZ", 0.2);
0262   desc.add<int>("MinN", 1);
0263   desc.add<int>("MinPixHitsForDZ", 0);
0264   desc.add<bool>("checkSC", false);
0265   descriptions.addWithDefaultLabel(desc);
0266 }
0267 
0268 template <>
0269 void HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoChargedCandidate>::fillDescriptions(
0270     edm::ConfigurationDescriptions& descriptions) {
0271   edm::ParameterSetDescription desc;
0272   makeHLTFilterDescription(desc);
0273   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0274   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0275   desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0276   desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0277   desc.add<edm::InputTag>("electronTag", edm::InputTag("electronTag"));
0278   desc.add<int>("triggerType1", 0);
0279   desc.add<int>("triggerType2", 0);
0280   desc.add<double>("MinDR", -1.0);
0281   desc.add<double>("MaxDZ", 0.2);
0282   desc.add<int>("MinN", 1);
0283   desc.add<int>("MinPixHitsForDZ", 0);
0284   desc.add<bool>("checkSC", false);
0285   descriptions.addWithDefaultLabel(desc);
0286 }
0287 
0288 template <>
0289 void HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0290   edm::ParameterSetDescription desc;
0291   makeHLTFilterDescription(desc);
0292   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0293   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0294   desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0295   desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0296   desc.add<int>("triggerType1", 0);
0297   desc.add<int>("triggerType2", 0);
0298   desc.add<double>("MinDR", -1.0);
0299   desc.add<double>("MaxDZ", 0.2);
0300   desc.add<int>("MinN", 1);
0301   descriptions.addWithDefaultLabel(desc);
0302 }
0303 
0304 template <>
0305 void HLTDoubletDZ<l1t::PFTau, l1t::PFTau>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0306   edm::ParameterSetDescription desc;
0307   makeHLTFilterDescription(desc);
0308   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0309   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0310   desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0311   desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0312   desc.add<int>("triggerType1", 0);
0313   desc.add<int>("triggerType2", 0);
0314   desc.add<double>("MinDR", -1.0);
0315   desc.add<double>("MaxDZ", 0.2);
0316   desc.add<int>("MinN", 1);
0317   descriptions.addWithDefaultLabel(desc);
0318 }
0319 
0320 template <>
0321 void HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0322   edm::ParameterSetDescription desc;
0323   makeHLTFilterDescription(desc);
0324   desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
0325   desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
0326   desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
0327   desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
0328   desc.add<int>("triggerType1", 0);
0329   desc.add<int>("triggerType2", 0);
0330   desc.add<double>("MinDR", -1.0);
0331   desc.add<double>("MaxDZ", 0.2);
0332   desc.add<int>("MinN", 1);
0333   descriptions.addWithDefaultLabel(desc);
0334 }
0335 
0336 template <typename T1, typename T2>
0337 bool HLTDoubletDZ<T1, T2>::getCollections(edm::Event const& iEvent,
0338                                           std::vector<T1Ref>& coll1,
0339                                           std::vector<T2Ref>& coll2,
0340                                           trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0341   edm::Handle<trigger::TriggerFilterObjectWithRefs> handle1, handle2;
0342   if (iEvent.getByToken(inputToken1_, handle1) and iEvent.getByToken(inputToken2_, handle2)) {
0343     // get hold of pre-filtered object collections
0344     handle1->getObjects(triggerType1_, coll1);
0345     handle2->getObjects(triggerType2_, coll2);
0346     const trigger::size_type n1(coll1.size());
0347     const trigger::size_type n2(coll2.size());
0348 
0349     if (saveTags()) {
0350       edm::InputTag tagOld;
0351       for (unsigned int i = 0; i < originTag1_.size(); ++i) {
0352         filterproduct.addCollectionTag(originTag1_[i]);
0353       }
0354       tagOld = edm::InputTag();
0355       for (trigger::size_type i1 = 0; i1 != n1; ++i1) {
0356         const edm::ProductID pid(coll1[i1].id());
0357         const auto& prov = iEvent.getStableProvenance(pid);
0358         const std::string& label(prov.moduleLabel());
0359         const std::string& instance(prov.productInstanceName());
0360         const std::string& process(prov.processName());
0361         edm::InputTag tagNew(edm::InputTag(label, instance, process));
0362         if (tagOld.encode() != tagNew.encode()) {
0363           filterproduct.addCollectionTag(tagNew);
0364           tagOld = tagNew;
0365         }
0366       }
0367       for (unsigned int i = 0; i < originTag2_.size(); ++i) {
0368         filterproduct.addCollectionTag(originTag2_[i]);
0369       }
0370       tagOld = edm::InputTag();
0371       for (trigger::size_type i2 = 0; i2 != n2; ++i2) {
0372         const edm::ProductID pid(coll2[i2].id());
0373         const auto& prov = iEvent.getStableProvenance(pid);
0374         const std::string& label(prov.moduleLabel());
0375         const std::string& instance(prov.productInstanceName());
0376         const std::string& process(prov.processName());
0377         edm::InputTag tagNew(edm::InputTag(label, instance, process));
0378         if (tagOld.encode() != tagNew.encode()) {
0379           filterproduct.addCollectionTag(tagNew);
0380           tagOld = tagNew;
0381         }
0382       }
0383     }
0384 
0385     return true;
0386   }
0387 
0388   return false;
0389 }
0390 
0391 template <>
0392 bool HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::getCollections(
0393     edm::Event const& iEvent,
0394     std::vector<l1t::P2GTCandidateRef>& coll1,
0395     std::vector<l1t::P2GTCandidateRef>& coll2,
0396     trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0397   const l1t::P2GTAlgoBlockMap& algos = iEvent.get(algoBlockToken_);
0398 
0399   if (!algos.empty()) {
0400     if (algos.count(l1GTAlgoName1_) > 0 && algos.at(l1GTAlgoName1_).decisionBeforeBxMaskAndPrescale()) {
0401       const l1t::P2GTCandidateVectorRef& objects = algos.at(l1GTAlgoName1_).trigObjects();
0402       for (const l1t::P2GTCandidateRef& obj : objects) {
0403         if ((triggerType1_ == trigger::TriggerObjectType::TriggerL1TkMu && obj->isMuon()) ||
0404             (triggerType1_ == trigger::TriggerObjectType::TriggerL1TkEle && obj->isElectron()) ||
0405             (triggerType1_ == trigger::TriggerObjectType::TriggerL1TkEm && obj->isPhoton())) {
0406           coll1.push_back(obj);
0407         }
0408       }
0409     }
0410 
0411     if (algos.count(l1GTAlgoName2_) > 0 && algos.at(l1GTAlgoName2_).decisionBeforeBxMaskAndPrescale()) {
0412       const l1t::P2GTCandidateVectorRef& objects = algos.at(l1GTAlgoName2_).trigObjects();
0413       for (const l1t::P2GTCandidateRef& obj : objects) {
0414         if ((triggerType2_ == trigger::TriggerObjectType::TriggerL1TkMu && obj->isMuon()) ||
0415             (triggerType2_ == trigger::TriggerObjectType::TriggerL1TkEle && obj->isElectron()) ||
0416             (triggerType2_ == trigger::TriggerObjectType::TriggerL1TkEm && obj->isPhoton())) {
0417           coll2.push_back(obj);
0418         }
0419       }
0420     }
0421   }
0422 
0423   if (!coll1.empty() && !coll2.empty()) {
0424     const trigger::size_type n1(coll1.size());
0425     const trigger::size_type n2(coll2.size());
0426 
0427     if (saveTags()) {
0428       edm::InputTag tagOld;
0429       for (unsigned int i = 0; i < originTag1_.size(); ++i) {
0430         filterproduct.addCollectionTag(originTag1_[i]);
0431       }
0432       tagOld = edm::InputTag();
0433       for (trigger::size_type i1 = 0; i1 != n1; ++i1) {
0434         const edm::ProductID pid(coll1[i1].id());
0435         const auto& prov = iEvent.getStableProvenance(pid);
0436         const std::string& label(prov.moduleLabel());
0437         const std::string& instance(prov.productInstanceName());
0438         const std::string& process(prov.processName());
0439         edm::InputTag tagNew(edm::InputTag(label, instance, process));
0440         if (tagOld.encode() != tagNew.encode()) {
0441           filterproduct.addCollectionTag(tagNew);
0442           tagOld = tagNew;
0443         }
0444       }
0445       for (unsigned int i = 0; i < originTag2_.size(); ++i) {
0446         filterproduct.addCollectionTag(originTag2_[i]);
0447       }
0448       tagOld = edm::InputTag();
0449       for (trigger::size_type i2 = 0; i2 != n2; ++i2) {
0450         const edm::ProductID pid(coll2[i2].id());
0451         const auto& prov = iEvent.getStableProvenance(pid);
0452         const std::string& label(prov.moduleLabel());
0453         const std::string& instance(prov.productInstanceName());
0454         const std::string& process(prov.processName());
0455         edm::InputTag tagNew(edm::InputTag(label, instance, process));
0456         if (tagOld.encode() != tagNew.encode()) {
0457           filterproduct.addCollectionTag(tagNew);
0458           tagOld = tagNew;
0459         }
0460       }
0461     }
0462 
0463     return true;
0464   } else
0465     return false;
0466 }
0467 
0468 template <typename T1, typename T2>
0469 bool HLTDoubletDZ<T1, T2>::haveSameSuperCluster(T1 const& c1, T2 const& c2) const {
0470   return (c1.superCluster().isNonnull() and c2.superCluster().isNonnull() and (c1.superCluster() == c2.superCluster()));
0471 }
0472 
0473 template <>
0474 bool HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::haveSameSuperCluster(l1t::TrackerMuon const&,
0475                                                                             l1t::TrackerMuon const&) const {
0476   return false;
0477 }
0478 
0479 template <>
0480 bool HLTDoubletDZ<l1t::PFTau, l1t::PFTau>::haveSameSuperCluster(l1t::PFTau const&, l1t::PFTau const&) const {
0481   return false;
0482 }
0483 
0484 template <>
0485 bool HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::haveSameSuperCluster(l1t::HPSPFTau const&,
0486                                                                       l1t::HPSPFTau const&) const {
0487   return false;
0488 }
0489 
0490 template <typename C1, typename C2>
0491 bool HLTDoubletDZ<C1, C2>::passCutMinDeltaR(C1 const& c1, C2 const& c2) const {
0492   return (minDR_ < 0 or reco::deltaR2(c1, c2) >= minDR2_);
0493 }
0494 
0495 template <>
0496 bool HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::passCutMinDeltaR(l1t::P2GTCandidate const& c1,
0497                                                                             l1t::P2GTCandidate const& c2) const {
0498   return (minDR_ < 0 or reco::deltaR2(c1, c2) > minDR2_);
0499 }
0500 
0501 template <>
0502 bool HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::passCutMinDeltaR(l1t::TrackerMuon const& m1,
0503                                                                         l1t::TrackerMuon const& m2) const {
0504   return (minDR_ < 0 or reco::deltaR2(m1.phEta(), m1.phPhi(), m2.phEta(), m2.phPhi()) >= minDR2_);
0505 }
0506 
0507 namespace {
0508 
0509   double getCandidateVZ(reco::RecoChargedCandidate const& cand, bool& isValidVZ, int const minPixHitsForValidVZ) {
0510     if (minPixHitsForValidVZ > 0) {
0511       auto const track = cand.track();
0512       if (not(track.isNonnull() and track.isAvailable() and
0513               track->hitPattern().numberOfValidPixelHits() >= minPixHitsForValidVZ)) {
0514         isValidVZ = false;
0515         return 0;
0516       }
0517     }
0518 
0519     isValidVZ = true;
0520     return cand.vz();
0521   }
0522 
0523   double getCandidateVZ(reco::RecoEcalCandidate const& cand,
0524                         bool& isValidVZ,
0525                         int const minPixHitsForValidVZ,
0526                         reco::ElectronCollection const& electrons) {
0527     reco::Electron const* elec_ptr = nullptr;
0528     for (auto const& elec : electrons) {
0529       if (elec.superCluster() == cand.superCluster()) {
0530         elec_ptr = &elec;
0531       }
0532     }
0533 
0534     if (elec_ptr == nullptr) {
0535       // IMPROVE, kept for backward compatibility
0536       isValidVZ = true;
0537       return 0;  // equivalent to 'reco::Electron e1; return e1.vz();'
0538     }
0539 
0540     if (minPixHitsForValidVZ > 0) {
0541       auto const track = elec_ptr->gsfTrack();
0542       if (not(track.isNonnull() and track.isAvailable() and
0543               track->hitPattern().numberOfValidPixelHits() >= minPixHitsForValidVZ)) {
0544         isValidVZ = false;
0545         return 0;
0546       }
0547     }
0548 
0549     isValidVZ = true;
0550     return elec_ptr->vz();
0551   }
0552 
0553   double getCandidateVZ(l1t::HPSPFTau const& cand, bool& isValidVZ) {
0554     auto const& leadChargedPFCand = cand.leadChargedPFCand();
0555     if (leadChargedPFCand.isNonnull() and leadChargedPFCand.isAvailable()) {
0556       auto const& pfTrack = leadChargedPFCand->pfTrack();
0557       if (pfTrack.isNonnull() and pfTrack.isAvailable()) {
0558         isValidVZ = true;
0559         return pfTrack->vertex().z();
0560       }
0561     }
0562 
0563     isValidVZ = false;
0564     return 0;
0565   }
0566 
0567 }  // namespace
0568 
0569 template <typename T1, typename T2>
0570 bool HLTDoubletDZ<T1, T2>::computeDZ(edm::Event const&, T1 const& c1, T2 const& c2) const {
0571   return ((std::abs(c1.vz() - c2.vz()) <= maxDZ_) and passCutMinDeltaR(c1, c2));
0572 }
0573 
0574 template <>
0575 bool HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::computeDZ(edm::Event const& iEvent,
0576                                                                      l1t::P2GTCandidate const& c1,
0577                                                                      l1t::P2GTCandidate const& c2) const {
0578   if (maxDZ_ > 0 && std::abs(c1.vz() - c2.vz()) > maxDZ_) {
0579     return false;
0580   }
0581 
0582   if (not passCutMinDeltaR(c1, c2)) {
0583     return false;
0584   }
0585 
0586   return true;
0587 }
0588 
0589 template <>
0590 bool HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoChargedCandidate>::computeDZ(
0591     edm::Event const& iEvent, reco::RecoEcalCandidate const& c1, reco::RecoChargedCandidate const& c2) const {
0592   if (not passCutMinDeltaR(c1, c2))
0593     return false;
0594 
0595   bool hasValidVZ2 = false;
0596   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_);
0597   if (not hasValidVZ2)
0598     return true;
0599 
0600   bool hasValidVZ1 = false;
0601   auto const& electrons = iEvent.get(electronToken_);
0602   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_, electrons);
0603   if (not hasValidVZ1)
0604     return true;
0605 
0606   return (std::abs(vz1 - vz2) <= maxDZ_);
0607 }
0608 
0609 template <>
0610 bool HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoEcalCandidate>::computeDZ(
0611     edm::Event const& iEvent, reco::RecoChargedCandidate const& c1, reco::RecoEcalCandidate const& c2) const {
0612   if (not passCutMinDeltaR(c1, c2))
0613     return false;
0614 
0615   bool hasValidVZ1 = false;
0616   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_);
0617   if (not hasValidVZ1)
0618     return true;
0619 
0620   bool hasValidVZ2 = false;
0621   auto const& electrons = iEvent.get(electronToken_);
0622   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_, electrons);
0623   if (not hasValidVZ2)
0624     return true;
0625 
0626   return (std::abs(vz1 - vz2) <= maxDZ_);
0627 }
0628 
0629 template <>
0630 bool HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoEcalCandidate>::computeDZ(
0631     edm::Event const& iEvent, reco::RecoEcalCandidate const& c1, reco::RecoEcalCandidate const& c2) const {
0632   if (not passCutMinDeltaR(c1, c2))
0633     return false;
0634 
0635   auto const& electrons = iEvent.get(electronToken_);
0636 
0637   bool hasValidVZ1 = false;
0638   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_, electrons);
0639   if (not hasValidVZ1)
0640     return true;
0641 
0642   bool hasValidVZ2 = false;
0643   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_, electrons);
0644   if (not hasValidVZ2)
0645     return true;
0646 
0647   return (std::abs(vz1 - vz2) <= maxDZ_);
0648 }
0649 
0650 template <>
0651 bool HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoChargedCandidate>::computeDZ(
0652     edm::Event const& iEvent, reco::RecoChargedCandidate const& c1, reco::RecoChargedCandidate const& c2) const {
0653   if (not passCutMinDeltaR(c1, c2))
0654     return false;
0655 
0656   bool hasValidVZ1 = false;
0657   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_);
0658   if (not hasValidVZ1)
0659     return true;
0660 
0661   bool hasValidVZ2 = false;
0662   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_);
0663   if (not hasValidVZ2)
0664     return true;
0665 
0666   return (std::abs(vz1 - vz2) <= maxDZ_);
0667 }
0668 
0669 template <>
0670 bool HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::computeDZ(edm::Event const& iEvent,
0671                                                                  l1t::TrackerMuon const& c1,
0672                                                                  l1t::TrackerMuon const& c2) const {
0673   return ((std::abs(c1.phZ0() - c2.phZ0()) <= maxDZ_) and passCutMinDeltaR(c1, c2));
0674 }
0675 
0676 template <>
0677 bool HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::computeDZ(edm::Event const& iEvent,
0678                                                            l1t::HPSPFTau const& c1,
0679                                                            l1t::HPSPFTau const& c2) const {
0680   if (not passCutMinDeltaR(c1, c2))
0681     return false;
0682 
0683   bool hasValidVZ1 = false;
0684   auto const vz1 = getCandidateVZ(c1, hasValidVZ1);
0685   if (not hasValidVZ1)
0686     return false;
0687 
0688   bool hasValidVZ2 = false;
0689   auto const vz2 = getCandidateVZ(c2, hasValidVZ2);
0690   if (not hasValidVZ2)
0691     return false;
0692 
0693   return (std::abs(vz1 - vz2) <= maxDZ_);
0694 }
0695 
0696 template <typename T1, typename T2>
0697 bool HLTDoubletDZ<T1, T2>::hltFilter(edm::Event& iEvent,
0698                                      edm::EventSetup const& iSetup,
0699                                      trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0700   // All HLT filters must create and fill an HLT filter object,
0701   // recording any reconstructed physics objects satisfying (or not)
0702   // this HLT filter, and place it in the Event.
0703   std::vector<T1Ref> coll1;
0704   std::vector<T2Ref> coll2;
0705 
0706   if (getCollections(iEvent, coll1, coll2, filterproduct)) {
0707     int n(0);
0708     T1Ref r1;
0709     T2Ref r2;
0710 
0711     for (unsigned int i1 = 0; i1 < coll1.size(); ++i1) {
0712       r1 = coll1[i1];
0713       unsigned int const I = same_ ? i1 + 1 : 0;
0714       for (unsigned int i2 = I; i2 < coll2.size(); ++i2) {
0715         r2 = coll2[i2];
0716 
0717         if (checkSC_ and haveSameSuperCluster(*r1, *r2)) {
0718           continue;
0719         }
0720 
0721         if (not computeDZ(iEvent, *r1, *r2)) {
0722           continue;
0723         }
0724 
0725         n++;
0726         filterproduct.addObject(triggerType1_, r1);
0727         filterproduct.addObject(triggerType2_, r2);
0728       }
0729     }
0730 
0731     return (n >= min_N_);
0732   }
0733 
0734   return false;
0735 }
0736 
0737 template <>
0738 bool HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::hltFilter(
0739     edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0740   // All HLT filters must create and fill an HLT filter object,
0741   // recording any reconstructed physics objects satisfying (or not)
0742   // this HLT filter, and place it in the Event.
0743   bool accept(false);
0744 
0745   std::vector<l1t::P2GTCandidateRef> coll1;
0746   std::vector<l1t::P2GTCandidateRef> coll2;
0747 
0748   if (getCollections(iEvent, coll1, coll2, filterproduct)) {
0749     int n(0);
0750     l1t::P2GTCandidateRef r1;
0751     l1t::P2GTCandidateRef r2;
0752 
0753     for (unsigned int i1 = 0; i1 != coll1.size(); i1++) {
0754       r1 = coll1[i1];
0755       unsigned int I(0);
0756       if (same_) {
0757         I = i1 + 1;
0758       }
0759       for (unsigned int i2 = I; i2 != coll2.size(); i2++) {
0760         r2 = coll2[i2];
0761 
0762         if (!computeDZ(iEvent, *r1, *r2))
0763           continue;
0764 
0765         n++;
0766         filterproduct.addObject(triggerType1_, r1);
0767         filterproduct.addObject(triggerType2_, r2);
0768       }
0769     }
0770 
0771     accept = accept || (n >= min_N_);
0772   }
0773   return accept;
0774 }
0775 
0776 using HLT2ElectronElectronDZ = HLTDoubletDZ<reco::Electron, reco::Electron>;
0777 using HLT2MuonMuonDZ = HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoChargedCandidate>;
0778 using HLT2ElectronMuonDZ = HLTDoubletDZ<reco::Electron, reco::RecoChargedCandidate>;
0779 using HLT2PhotonPhotonDZ = HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoEcalCandidate>;
0780 using HLT2MuonPhotonDZ = HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoEcalCandidate>;
0781 using HLT2PhotonMuonDZ = HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoChargedCandidate>;
0782 using HLT2L1TkMuonL1TkMuonDZ = HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>;
0783 using HLT2L1PFTauL1PFTauDZ = HLTDoubletDZ<l1t::PFTau, l1t::PFTau>;
0784 using HLT2L1HPSPFTauL1HPSPFTauDZ = HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>;
0785 using HLT2L1P2GTCandL1P2GTCandDZ = HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>;
0786 
0787 #include "FWCore/Framework/interface/MakerMacros.h"
0788 DEFINE_FWK_MODULE(HLT2ElectronElectronDZ);
0789 DEFINE_FWK_MODULE(HLT2MuonMuonDZ);
0790 DEFINE_FWK_MODULE(HLT2ElectronMuonDZ);
0791 DEFINE_FWK_MODULE(HLT2PhotonPhotonDZ);
0792 DEFINE_FWK_MODULE(HLT2PhotonMuonDZ);
0793 DEFINE_FWK_MODULE(HLT2MuonPhotonDZ);
0794 DEFINE_FWK_MODULE(HLT2L1TkMuonL1TkMuonDZ);
0795 DEFINE_FWK_MODULE(HLT2L1PFTauL1PFTauDZ);
0796 DEFINE_FWK_MODULE(HLT2L1HPSPFTauL1HPSPFTauDZ);
0797 DEFINE_FWK_MODULE(HLT2L1P2GTCandL1P2GTCandDZ);