File indexing completed on 2024-04-06 12:27:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
0011 #include "RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2Helper.h"
0012
0013 #include "FWCore/Utilities/interface/Exception.h"
0014
0015 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0016 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0017
0018 #include "DataFormats/MuonReco/interface/Muon.h"
0019 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0020 #include "DataFormats/MuonReco/interface/MuonChamberMatch.h"
0021 #include "DataFormats/Common/interface/Handle.h"
0022 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0023 #include "DataFormats/TrackReco/interface/HitPattern.h"
0024 #include "DataFormats/TrackReco/interface/Track.h"
0025 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0026 #include "DataFormats/Math/interface/deltaR.h"
0027
0028 #include "RecoTauTag/RecoTau/interface/RecoTauMuonTools.h"
0029
0030 #include <vector>
0031 #include <string>
0032 #include <iostream>
0033 #include <atomic>
0034
0035 namespace {
0036
0037 class PFRecoTauDiscriminationAgainstMuon2 final : public PFTauDiscriminationProducerBase {
0038 public:
0039 explicit PFRecoTauDiscriminationAgainstMuon2(const edm::ParameterSet& cfg)
0040 : PFTauDiscriminationProducerBase(cfg), moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
0041 std::string discriminatorOption_string = cfg.getParameter<std::string>("discriminatorOption");
0042 int discOption;
0043 if (discriminatorOption_string == "loose")
0044 discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kLoose;
0045 else if (discriminatorOption_string == "medium")
0046 discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kMedium;
0047 else if (discriminatorOption_string == "tight")
0048 discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kTight;
0049 else if (discriminatorOption_string == "custom")
0050 discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kCustom;
0051 else
0052 throw edm::Exception(edm::errors::UnimplementedFeature)
0053 << " Invalid Configuration parameter 'discriminatorOption' = " << discriminatorOption_string << " !!\n";
0054 wpDef_ = std::make_unique<PFRecoTauDiscriminationAgainstMuonConfigSet>(
0055 discOption,
0056 cfg.getParameter<double>("HoPMin"),
0057 cfg.getParameter<int>("maxNumberOfMatches"),
0058 cfg.getParameter<bool>("doCaloMuonVeto"),
0059 cfg.getParameter<int>("maxNumberOfHitsLast2Stations"));
0060 srcMuons_ = cfg.getParameter<edm::InputTag>("srcMuons");
0061 Muons_token = consumes<reco::MuonCollection>(srcMuons_);
0062 dRmuonMatch_ = cfg.getParameter<double>("dRmuonMatch");
0063 dRmuonMatchLimitedToJetArea_ = cfg.getParameter<bool>("dRmuonMatchLimitedToJetArea");
0064 minPtMatchedMuon_ = cfg.getParameter<double>("minPtMatchedMuon");
0065 typedef std::vector<int> vint;
0066 maskMatchesDT_ = cfg.getParameter<vint>("maskMatchesDT");
0067 maskMatchesCSC_ = cfg.getParameter<vint>("maskMatchesCSC");
0068 maskMatchesRPC_ = cfg.getParameter<vint>("maskMatchesRPC");
0069 maskHitsDT_ = cfg.getParameter<vint>("maskHitsDT");
0070 maskHitsCSC_ = cfg.getParameter<vint>("maskHitsCSC");
0071 maskHitsRPC_ = cfg.getParameter<vint>("maskHitsRPC");
0072 verbosity_ = cfg.getParameter<int>("verbosity");
0073 }
0074 ~PFRecoTauDiscriminationAgainstMuon2() override {}
0075
0076 void beginEvent(const edm::Event&, const edm::EventSetup&) override;
0077
0078 double discriminate(const reco::PFTauRef&) const override;
0079
0080 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0081
0082 private:
0083 std::string moduleLabel_;
0084 std::unique_ptr<PFRecoTauDiscriminationAgainstMuonConfigSet> wpDef_;
0085 edm::InputTag srcMuons_;
0086 edm::Handle<reco::MuonCollection> muons_;
0087 edm::EDGetTokenT<reco::MuonCollection> Muons_token;
0088 double dRmuonMatch_;
0089 bool dRmuonMatchLimitedToJetArea_;
0090 double minPtMatchedMuon_;
0091 std::vector<int> maskMatchesDT_;
0092 std::vector<int> maskMatchesCSC_;
0093 std::vector<int> maskMatchesRPC_;
0094 std::vector<int> maskHitsDT_;
0095 std::vector<int> maskHitsCSC_;
0096 std::vector<int> maskHitsRPC_;
0097 static std::atomic<unsigned int> numWarnings_;
0098 static constexpr unsigned int maxWarnings_ = 3;
0099 int verbosity_;
0100 };
0101
0102 std::atomic<unsigned int> PFRecoTauDiscriminationAgainstMuon2::numWarnings_{0};
0103
0104 void PFRecoTauDiscriminationAgainstMuon2::beginEvent(const edm::Event& evt, const edm::EventSetup& es) {
0105 if (!srcMuons_.label().empty()) {
0106 evt.getByToken(Muons_token, muons_);
0107 }
0108 }
0109
0110 double PFRecoTauDiscriminationAgainstMuon2::discriminate(const reco::PFTauRef& pfTau) const {
0111 const reco::PFCandidatePtr& pfCand = pfTau->leadPFChargedHadrCand();
0112 auto helper = PFRecoTauDiscriminationAgainstMuon2Helper(verbosity_,
0113 moduleLabel_,
0114 srcMuons_.label().empty(),
0115 minPtMatchedMuon_,
0116 dRmuonMatch_,
0117 dRmuonMatchLimitedToJetArea_,
0118 numWarnings_,
0119 maxWarnings_,
0120 maskMatchesDT_,
0121 maskMatchesCSC_,
0122 maskMatchesRPC_,
0123 maskHitsDT_,
0124 maskHitsCSC_,
0125 maskHitsRPC_,
0126 muons_,
0127 pfTau,
0128 pfCand);
0129 double discriminatorValue = helper.eval(*wpDef_, pfTau);
0130 if (verbosity_)
0131 edm::LogPrint("PFTauAgainstMuon2") << "--> returning discriminatorValue = " << discriminatorValue;
0132 return discriminatorValue;
0133 }
0134
0135 }
0136
0137 void PFRecoTauDiscriminationAgainstMuon2::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0138
0139 edm::ParameterSetDescription desc;
0140 desc.add<std::vector<int>>("maskHitsRPC",
0141 {
0142 0,
0143 0,
0144 0,
0145 0,
0146 });
0147 desc.add<int>("maxNumberOfHitsLast2Stations", 0);
0148 desc.add<std::vector<int>>("maskMatchesRPC",
0149 {
0150 0,
0151 0,
0152 0,
0153 0,
0154 });
0155 desc.add<std::vector<int>>("maskMatchesCSC",
0156 {
0157 1,
0158 0,
0159 0,
0160 0,
0161 });
0162 desc.add<std::vector<int>>("maskHitsCSC",
0163 {
0164 0,
0165 0,
0166 0,
0167 0,
0168 });
0169 desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
0170 desc.add<int>("verbosity", 0);
0171 desc.add<std::vector<int>>("maskMatchesDT",
0172 {
0173 0,
0174 0,
0175 0,
0176 0,
0177 });
0178 desc.add<double>("minPtMatchedMuon", 5.0);
0179 desc.add<bool>("dRmuonMatchLimitedToJetArea", false);
0180 {
0181 edm::ParameterSetDescription psd0;
0182 psd0.add<std::string>("BooleanOperator", "and");
0183 {
0184 edm::ParameterSetDescription psd1;
0185 psd1.add<double>("cut");
0186 psd1.add<edm::InputTag>("Producer");
0187 psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
0188 }
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
0202 }
0203 desc.add<std::vector<int>>("maskHitsDT",
0204 {
0205 0,
0206 0,
0207 0,
0208 0,
0209 });
0210 desc.add<double>("HoPMin", 0.2);
0211 desc.add<int>("maxNumberOfMatches", 0);
0212 desc.add<std::string>("discriminatorOption", "loose");
0213 desc.add<double>("dRmuonMatch", 0.3);
0214 desc.add<edm::InputTag>("srcMuons", edm::InputTag("muons"));
0215 desc.add<bool>("doCaloMuonVeto", false);
0216 descriptions.add("pfRecoTauDiscriminationAgainstMuon2", desc);
0217 }
0218
0219 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon2);