Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-01-24 04:56:39

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<std::vector<l1t::P2GTAlgoBlock>>(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 std::vector<l1t::P2GTAlgoBlock>& algos = iEvent.get(algoBlockToken_);
0398 
0399   if (!algos.empty()) {
0400     for (const l1t::P2GTAlgoBlock& algo : algos) {
0401       if (algo.algoName() == l1GTAlgoName1_ && algo.decisionBeforeBxMaskAndPrescale()) {
0402         const l1t::P2GTCandidateVectorRef& objects = algo.trigObjects();
0403         for (const l1t::P2GTCandidateRef& obj : objects) {
0404           if ((triggerType1_ == trigger::TriggerObjectType::TriggerL1TkMu && obj->isMuon()) ||
0405               (triggerType1_ == trigger::TriggerObjectType::TriggerL1TkEle && obj->isElectron()) ||
0406               (triggerType1_ == trigger::TriggerObjectType::TriggerL1TkEm && obj->isPhoton())) {
0407             coll1.push_back(obj);
0408           }
0409         }
0410       }
0411       if (algo.algoName() == l1GTAlgoName2_ && algo.decisionBeforeBxMaskAndPrescale()) {
0412         const l1t::P2GTCandidateVectorRef& objects = algo.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 
0424   if (!coll1.empty() && !coll2.empty()) {
0425     const trigger::size_type n1(coll1.size());
0426     const trigger::size_type n2(coll2.size());
0427 
0428     if (saveTags()) {
0429       edm::InputTag tagOld;
0430       for (unsigned int i = 0; i < originTag1_.size(); ++i) {
0431         filterproduct.addCollectionTag(originTag1_[i]);
0432       }
0433       tagOld = edm::InputTag();
0434       for (trigger::size_type i1 = 0; i1 != n1; ++i1) {
0435         const edm::ProductID pid(coll1[i1].id());
0436         const auto& prov = iEvent.getStableProvenance(pid);
0437         const std::string& label(prov.moduleLabel());
0438         const std::string& instance(prov.productInstanceName());
0439         const std::string& process(prov.processName());
0440         edm::InputTag tagNew(edm::InputTag(label, instance, process));
0441         if (tagOld.encode() != tagNew.encode()) {
0442           filterproduct.addCollectionTag(tagNew);
0443           tagOld = tagNew;
0444         }
0445       }
0446       for (unsigned int i = 0; i < originTag2_.size(); ++i) {
0447         filterproduct.addCollectionTag(originTag2_[i]);
0448       }
0449       tagOld = edm::InputTag();
0450       for (trigger::size_type i2 = 0; i2 != n2; ++i2) {
0451         const edm::ProductID pid(coll2[i2].id());
0452         const auto& prov = iEvent.getStableProvenance(pid);
0453         const std::string& label(prov.moduleLabel());
0454         const std::string& instance(prov.productInstanceName());
0455         const std::string& process(prov.processName());
0456         edm::InputTag tagNew(edm::InputTag(label, instance, process));
0457         if (tagOld.encode() != tagNew.encode()) {
0458           filterproduct.addCollectionTag(tagNew);
0459           tagOld = tagNew;
0460         }
0461       }
0462     }
0463 
0464     return true;
0465   } else
0466     return false;
0467 }
0468 
0469 template <typename T1, typename T2>
0470 bool HLTDoubletDZ<T1, T2>::haveSameSuperCluster(T1 const& c1, T2 const& c2) const {
0471   return (c1.superCluster().isNonnull() and c2.superCluster().isNonnull() and (c1.superCluster() == c2.superCluster()));
0472 }
0473 
0474 template <>
0475 bool HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::haveSameSuperCluster(l1t::TrackerMuon const&,
0476                                                                             l1t::TrackerMuon const&) const {
0477   return false;
0478 }
0479 
0480 template <>
0481 bool HLTDoubletDZ<l1t::PFTau, l1t::PFTau>::haveSameSuperCluster(l1t::PFTau const&, l1t::PFTau const&) const {
0482   return false;
0483 }
0484 
0485 template <>
0486 bool HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::haveSameSuperCluster(l1t::HPSPFTau const&,
0487                                                                       l1t::HPSPFTau const&) const {
0488   return false;
0489 }
0490 
0491 template <typename C1, typename C2>
0492 bool HLTDoubletDZ<C1, C2>::passCutMinDeltaR(C1 const& c1, C2 const& c2) const {
0493   return (minDR_ < 0 or reco::deltaR2(c1, c2) >= minDR2_);
0494 }
0495 
0496 template <>
0497 bool HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::passCutMinDeltaR(l1t::P2GTCandidate const& c1,
0498                                                                             l1t::P2GTCandidate const& c2) const {
0499   return (minDR_ < 0 or reco::deltaR2(c1, c2) > minDR2_);
0500 }
0501 
0502 template <>
0503 bool HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::passCutMinDeltaR(l1t::TrackerMuon const& m1,
0504                                                                         l1t::TrackerMuon const& m2) const {
0505   return (minDR_ < 0 or reco::deltaR2(m1.phEta(), m1.phPhi(), m2.phEta(), m2.phPhi()) >= minDR2_);
0506 }
0507 
0508 namespace {
0509 
0510   double getCandidateVZ(reco::RecoChargedCandidate const& cand, bool& isValidVZ, int const minPixHitsForValidVZ) {
0511     if (minPixHitsForValidVZ > 0) {
0512       auto const track = cand.track();
0513       if (not(track.isNonnull() and track.isAvailable() and
0514               track->hitPattern().numberOfValidPixelHits() >= minPixHitsForValidVZ)) {
0515         isValidVZ = false;
0516         return 0;
0517       }
0518     }
0519 
0520     isValidVZ = true;
0521     return cand.vz();
0522   }
0523 
0524   double getCandidateVZ(reco::RecoEcalCandidate const& cand,
0525                         bool& isValidVZ,
0526                         int const minPixHitsForValidVZ,
0527                         reco::ElectronCollection const& electrons) {
0528     reco::Electron const* elec_ptr = nullptr;
0529     for (auto const& elec : electrons) {
0530       if (elec.superCluster() == cand.superCluster()) {
0531         elec_ptr = &elec;
0532       }
0533     }
0534 
0535     if (elec_ptr == nullptr) {
0536       // IMPROVE, kept for backward compatibility
0537       isValidVZ = true;
0538       return 0;  // equivalent to 'reco::Electron e1; return e1.vz();'
0539     }
0540 
0541     if (minPixHitsForValidVZ > 0) {
0542       auto const track = elec_ptr->gsfTrack();
0543       if (not(track.isNonnull() and track.isAvailable() and
0544               track->hitPattern().numberOfValidPixelHits() >= minPixHitsForValidVZ)) {
0545         isValidVZ = false;
0546         return 0;
0547       }
0548     }
0549 
0550     isValidVZ = true;
0551     return elec_ptr->vz();
0552   }
0553 
0554   double getCandidateVZ(l1t::HPSPFTau const& cand, bool& isValidVZ) {
0555     auto const& leadChargedPFCand = cand.leadChargedPFCand();
0556     if (leadChargedPFCand.isNonnull() and leadChargedPFCand.isAvailable()) {
0557       auto const& pfTrack = leadChargedPFCand->pfTrack();
0558       if (pfTrack.isNonnull() and pfTrack.isAvailable()) {
0559         isValidVZ = true;
0560         return pfTrack->vertex().z();
0561       }
0562     }
0563 
0564     isValidVZ = false;
0565     return 0;
0566   }
0567 
0568 }  // namespace
0569 
0570 template <typename T1, typename T2>
0571 bool HLTDoubletDZ<T1, T2>::computeDZ(edm::Event const&, T1 const& c1, T2 const& c2) const {
0572   return ((std::abs(c1.vz() - c2.vz()) <= maxDZ_) and passCutMinDeltaR(c1, c2));
0573 }
0574 
0575 template <>
0576 bool HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::computeDZ(edm::Event const& iEvent,
0577                                                                      l1t::P2GTCandidate const& c1,
0578                                                                      l1t::P2GTCandidate const& c2) const {
0579   if (maxDZ_ > 0 && std::abs(c1.vz() - c2.vz()) > maxDZ_) {
0580     return false;
0581   }
0582 
0583   if (not passCutMinDeltaR(c1, c2)) {
0584     return false;
0585   }
0586 
0587   return true;
0588 }
0589 
0590 template <>
0591 bool HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoChargedCandidate>::computeDZ(
0592     edm::Event const& iEvent, reco::RecoEcalCandidate const& c1, reco::RecoChargedCandidate const& c2) const {
0593   if (not passCutMinDeltaR(c1, c2))
0594     return false;
0595 
0596   bool hasValidVZ2 = false;
0597   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_);
0598   if (not hasValidVZ2)
0599     return true;
0600 
0601   bool hasValidVZ1 = false;
0602   auto const& electrons = iEvent.get(electronToken_);
0603   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_, electrons);
0604   if (not hasValidVZ1)
0605     return true;
0606 
0607   return (std::abs(vz1 - vz2) <= maxDZ_);
0608 }
0609 
0610 template <>
0611 bool HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoEcalCandidate>::computeDZ(
0612     edm::Event const& iEvent, reco::RecoChargedCandidate const& c1, reco::RecoEcalCandidate const& c2) const {
0613   if (not passCutMinDeltaR(c1, c2))
0614     return false;
0615 
0616   bool hasValidVZ1 = false;
0617   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_);
0618   if (not hasValidVZ1)
0619     return true;
0620 
0621   bool hasValidVZ2 = false;
0622   auto const& electrons = iEvent.get(electronToken_);
0623   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_, electrons);
0624   if (not hasValidVZ2)
0625     return true;
0626 
0627   return (std::abs(vz1 - vz2) <= maxDZ_);
0628 }
0629 
0630 template <>
0631 bool HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoEcalCandidate>::computeDZ(
0632     edm::Event const& iEvent, reco::RecoEcalCandidate const& c1, reco::RecoEcalCandidate const& c2) const {
0633   if (not passCutMinDeltaR(c1, c2))
0634     return false;
0635 
0636   auto const& electrons = iEvent.get(electronToken_);
0637 
0638   bool hasValidVZ1 = false;
0639   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_, electrons);
0640   if (not hasValidVZ1)
0641     return true;
0642 
0643   bool hasValidVZ2 = false;
0644   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_, electrons);
0645   if (not hasValidVZ2)
0646     return true;
0647 
0648   return (std::abs(vz1 - vz2) <= maxDZ_);
0649 }
0650 
0651 template <>
0652 bool HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoChargedCandidate>::computeDZ(
0653     edm::Event const& iEvent, reco::RecoChargedCandidate const& c1, reco::RecoChargedCandidate const& c2) const {
0654   if (not passCutMinDeltaR(c1, c2))
0655     return false;
0656 
0657   bool hasValidVZ1 = false;
0658   auto const vz1 = getCandidateVZ(c1, hasValidVZ1, minPixHitsForDZ_);
0659   if (not hasValidVZ1)
0660     return true;
0661 
0662   bool hasValidVZ2 = false;
0663   auto const vz2 = getCandidateVZ(c2, hasValidVZ2, minPixHitsForDZ_);
0664   if (not hasValidVZ2)
0665     return true;
0666 
0667   return (std::abs(vz1 - vz2) <= maxDZ_);
0668 }
0669 
0670 template <>
0671 bool HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>::computeDZ(edm::Event const& iEvent,
0672                                                                  l1t::TrackerMuon const& c1,
0673                                                                  l1t::TrackerMuon const& c2) const {
0674   return ((std::abs(c1.phZ0() - c2.phZ0()) <= maxDZ_) and passCutMinDeltaR(c1, c2));
0675 }
0676 
0677 template <>
0678 bool HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::computeDZ(edm::Event const& iEvent,
0679                                                            l1t::HPSPFTau const& c1,
0680                                                            l1t::HPSPFTau const& c2) const {
0681   if (not passCutMinDeltaR(c1, c2))
0682     return false;
0683 
0684   bool hasValidVZ1 = false;
0685   auto const vz1 = getCandidateVZ(c1, hasValidVZ1);
0686   if (not hasValidVZ1)
0687     return false;
0688 
0689   bool hasValidVZ2 = false;
0690   auto const vz2 = getCandidateVZ(c2, hasValidVZ2);
0691   if (not hasValidVZ2)
0692     return false;
0693 
0694   return (std::abs(vz1 - vz2) <= maxDZ_);
0695 }
0696 
0697 template <typename T1, typename T2>
0698 bool HLTDoubletDZ<T1, T2>::hltFilter(edm::Event& iEvent,
0699                                      edm::EventSetup const& iSetup,
0700                                      trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0701   // All HLT filters must create and fill an HLT filter object,
0702   // recording any reconstructed physics objects satisfying (or not)
0703   // this HLT filter, and place it in the Event.
0704   std::vector<T1Ref> coll1;
0705   std::vector<T2Ref> coll2;
0706 
0707   if (getCollections(iEvent, coll1, coll2, filterproduct)) {
0708     int n(0);
0709     T1Ref r1;
0710     T2Ref r2;
0711 
0712     for (unsigned int i1 = 0; i1 < coll1.size(); ++i1) {
0713       r1 = coll1[i1];
0714       unsigned int const I = same_ ? i1 + 1 : 0;
0715       for (unsigned int i2 = I; i2 < coll2.size(); ++i2) {
0716         r2 = coll2[i2];
0717 
0718         if (checkSC_ and haveSameSuperCluster(*r1, *r2)) {
0719           continue;
0720         }
0721 
0722         if (not computeDZ(iEvent, *r1, *r2)) {
0723           continue;
0724         }
0725 
0726         n++;
0727         filterproduct.addObject(triggerType1_, r1);
0728         filterproduct.addObject(triggerType2_, r2);
0729       }
0730     }
0731 
0732     return (n >= min_N_);
0733   }
0734 
0735   return false;
0736 }
0737 
0738 template <>
0739 bool HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>::hltFilter(
0740     edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0741   // All HLT filters must create and fill an HLT filter object,
0742   // recording any reconstructed physics objects satisfying (or not)
0743   // this HLT filter, and place it in the Event.
0744   bool accept(false);
0745 
0746   std::vector<l1t::P2GTCandidateRef> coll1;
0747   std::vector<l1t::P2GTCandidateRef> coll2;
0748 
0749   if (getCollections(iEvent, coll1, coll2, filterproduct)) {
0750     int n(0);
0751     l1t::P2GTCandidateRef r1;
0752     l1t::P2GTCandidateRef r2;
0753 
0754     for (unsigned int i1 = 0; i1 != coll1.size(); i1++) {
0755       r1 = coll1[i1];
0756       unsigned int I(0);
0757       if (same_) {
0758         I = i1 + 1;
0759       }
0760       for (unsigned int i2 = I; i2 != coll2.size(); i2++) {
0761         r2 = coll2[i2];
0762 
0763         if (!computeDZ(iEvent, *r1, *r2))
0764           continue;
0765 
0766         n++;
0767         filterproduct.addObject(triggerType1_, r1);
0768         filterproduct.addObject(triggerType2_, r2);
0769       }
0770     }
0771 
0772     accept = accept || (n >= min_N_);
0773   }
0774   return accept;
0775 }
0776 
0777 using HLT2ElectronElectronDZ = HLTDoubletDZ<reco::Electron, reco::Electron>;
0778 using HLT2MuonMuonDZ = HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoChargedCandidate>;
0779 using HLT2ElectronMuonDZ = HLTDoubletDZ<reco::Electron, reco::RecoChargedCandidate>;
0780 using HLT2PhotonPhotonDZ = HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoEcalCandidate>;
0781 using HLT2MuonPhotonDZ = HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoEcalCandidate>;
0782 using HLT2PhotonMuonDZ = HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoChargedCandidate>;
0783 using HLT2L1TkMuonL1TkMuonDZ = HLTDoubletDZ<l1t::TrackerMuon, l1t::TrackerMuon>;
0784 using HLT2L1PFTauL1PFTauDZ = HLTDoubletDZ<l1t::PFTau, l1t::PFTau>;
0785 using HLT2L1HPSPFTauL1HPSPFTauDZ = HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>;
0786 using HLT2L1P2GTCandL1P2GTCandDZ = HLTDoubletDZ<l1t::P2GTCandidate, l1t::P2GTCandidate>;
0787 
0788 #include "FWCore/Framework/interface/MakerMacros.h"
0789 DEFINE_FWK_MODULE(HLT2ElectronElectronDZ);
0790 DEFINE_FWK_MODULE(HLT2MuonMuonDZ);
0791 DEFINE_FWK_MODULE(HLT2ElectronMuonDZ);
0792 DEFINE_FWK_MODULE(HLT2PhotonPhotonDZ);
0793 DEFINE_FWK_MODULE(HLT2PhotonMuonDZ);
0794 DEFINE_FWK_MODULE(HLT2MuonPhotonDZ);
0795 DEFINE_FWK_MODULE(HLT2L1TkMuonL1TkMuonDZ);
0796 DEFINE_FWK_MODULE(HLT2L1PFTauL1PFTauDZ);
0797 DEFINE_FWK_MODULE(HLT2L1HPSPFTauL1HPSPFTauDZ);
0798 DEFINE_FWK_MODULE(HLT2L1P2GTCandL1P2GTCandDZ);