Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:05

0001 
0002 /** \class PFRecoTauDiscriminationAgainstMuon2Container
0003  *
0004  * Compute tau Id. discriminator against muons.
0005  * 
0006  * \author Christian Veelken, LLR
0007  *
0008  */
0009 
0010 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
0011 
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 
0014 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0015 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0016 
0017 #include "DataFormats/MuonReco/interface/Muon.h"
0018 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0019 #include "DataFormats/MuonReco/interface/MuonChamberMatch.h"
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0022 #include "DataFormats/TrackReco/interface/HitPattern.h"
0023 #include "DataFormats/TrackReco/interface/Track.h"
0024 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0025 #include "DataFormats/Math/interface/deltaR.h"
0026 
0027 #include "RecoTauTag/RecoTau/interface/RecoTauMuonTools.h"
0028 #include "RecoTauTag/RecoTau/plugins/PFRecoTauDiscriminationAgainstMuon2Helper.h"
0029 
0030 #include <vector>
0031 #include <string>
0032 #include <iostream>
0033 #include <atomic>
0034 
0035 namespace {
0036 
0037   class PFRecoTauDiscriminationAgainstMuon2Container final : public PFTauDiscriminationContainerProducerBase {
0038   public:
0039     explicit PFRecoTauDiscriminationAgainstMuon2Container(const edm::ParameterSet& cfg)
0040         : PFTauDiscriminationContainerProducerBase(cfg), moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
0041       auto const wpDefs = cfg.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
0042       // check content of discriminatorOption and add as enum to avoid string comparison per event
0043       for (auto& wpDefsEntry : wpDefs) {
0044         std::string discriminatorOption_string = wpDefsEntry.getParameter<std::string>("discriminatorOption");
0045         int discOption;
0046         if (discriminatorOption_string == "loose")
0047           discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kLoose;
0048         else if (discriminatorOption_string == "medium")
0049           discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kMedium;
0050         else if (discriminatorOption_string == "tight")
0051           discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kTight;
0052         else if (discriminatorOption_string == "custom")
0053           discOption = PFRecoTauDiscriminationAgainstMuonConfigSet::kCustom;
0054         else
0055           throw edm::Exception(edm::errors::UnimplementedFeature)
0056               << " Invalid Configuration parameter 'discriminatorOption' = " << discriminatorOption_string << " !!\n";
0057         wpDefs_.push_back(
0058             PFRecoTauDiscriminationAgainstMuonConfigSet(discOption,
0059                                                         wpDefsEntry.getParameter<double>("HoPMin"),
0060                                                         wpDefsEntry.getParameter<int>("maxNumberOfMatches"),
0061                                                         wpDefsEntry.getParameter<bool>("doCaloMuonVeto"),
0062                                                         wpDefsEntry.getParameter<int>("maxNumberOfHitsLast2Stations")));
0063       }
0064       srcMuons_ = cfg.getParameter<edm::InputTag>("srcMuons");
0065       muons_token = consumes<reco::MuonCollection>(srcMuons_);
0066       dRmuonMatch_ = cfg.getParameter<double>("dRmuonMatch");
0067       dRmuonMatchLimitedToJetArea_ = cfg.getParameter<bool>("dRmuonMatchLimitedToJetArea");
0068       minPtMatchedMuon_ = cfg.getParameter<double>("minPtMatchedMuon");
0069       typedef std::vector<int> vint;
0070       maskMatchesDT_ = cfg.getParameter<vint>("maskMatchesDT");
0071       maskMatchesCSC_ = cfg.getParameter<vint>("maskMatchesCSC");
0072       maskMatchesRPC_ = cfg.getParameter<vint>("maskMatchesRPC");
0073       maskHitsDT_ = cfg.getParameter<vint>("maskHitsDT");
0074       maskHitsCSC_ = cfg.getParameter<vint>("maskHitsCSC");
0075       maskHitsRPC_ = cfg.getParameter<vint>("maskHitsRPC");
0076       verbosity_ = cfg.getParameter<int>("verbosity");
0077     }
0078     ~PFRecoTauDiscriminationAgainstMuon2Container() override {}
0079 
0080     void beginEvent(const edm::Event&, const edm::EventSetup&) override;
0081 
0082     reco::SingleTauDiscriminatorContainer discriminate(const reco::PFTauRef&) const override;
0083 
0084     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0085 
0086   private:
0087     std::string moduleLabel_;
0088     std::vector<PFRecoTauDiscriminationAgainstMuonConfigSet> wpDefs_;
0089     edm::InputTag srcMuons_;
0090     edm::Handle<reco::MuonCollection> muons_;
0091     edm::EDGetTokenT<reco::MuonCollection> muons_token;
0092     double dRmuonMatch_;
0093     bool dRmuonMatchLimitedToJetArea_;
0094     double minPtMatchedMuon_;
0095     std::vector<int> maskMatchesDT_;
0096     std::vector<int> maskMatchesCSC_;
0097     std::vector<int> maskMatchesRPC_;
0098     std::vector<int> maskHitsDT_;
0099     std::vector<int> maskHitsCSC_;
0100     std::vector<int> maskHitsRPC_;
0101     static std::atomic<unsigned int> numWarnings_;
0102     static constexpr unsigned int maxWarnings_ = 3;
0103     int verbosity_;
0104   };
0105 
0106   std::atomic<unsigned int> PFRecoTauDiscriminationAgainstMuon2Container::numWarnings_{0};
0107 
0108   void PFRecoTauDiscriminationAgainstMuon2Container::beginEvent(const edm::Event& evt, const edm::EventSetup& es) {
0109     if (!srcMuons_.label().empty()) {
0110       evt.getByToken(muons_token, muons_);
0111     }
0112   }
0113 
0114   reco::SingleTauDiscriminatorContainer PFRecoTauDiscriminationAgainstMuon2Container::discriminate(
0115       const reco::PFTauRef& pfTau) const {
0116     const reco::PFCandidatePtr& pfCand = pfTau->leadPFChargedHadrCand();
0117     auto helper = PFRecoTauDiscriminationAgainstMuon2Helper(verbosity_,
0118                                                             moduleLabel_,
0119                                                             srcMuons_.label().empty(),
0120                                                             minPtMatchedMuon_,
0121                                                             dRmuonMatch_,
0122                                                             dRmuonMatchLimitedToJetArea_,
0123                                                             numWarnings_,
0124                                                             maxWarnings_,
0125                                                             maskMatchesDT_,
0126                                                             maskMatchesCSC_,
0127                                                             maskMatchesRPC_,
0128                                                             maskHitsDT_,
0129                                                             maskHitsCSC_,
0130                                                             maskHitsRPC_,
0131                                                             muons_,
0132                                                             pfTau,
0133                                                             pfCand);
0134 
0135     reco::SingleTauDiscriminatorContainer result;
0136     for (auto const& wpDefsEntry : wpDefs_) {
0137       result.workingPoints.push_back(helper.eval(wpDefsEntry, pfTau));
0138       if (verbosity_)
0139         edm::LogPrint("PFTauAgainstMuon2") << "--> returning discriminatorValue = " << result.workingPoints.back();
0140     }
0141     return result;
0142   }
0143 
0144 }  // namespace
0145 
0146 void PFRecoTauDiscriminationAgainstMuon2Container::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0147   // pfRecoTauDiscriminationAgainstMuon2Container
0148   edm::ParameterSetDescription desc;
0149   desc.add<std::vector<int>>("maskHitsRPC",
0150                              {
0151                                  0,
0152                                  0,
0153                                  0,
0154                                  0,
0155                              });
0156   desc.add<std::vector<int>>("maskMatchesRPC",
0157                              {
0158                                  0,
0159                                  0,
0160                                  0,
0161                                  0,
0162                              });
0163   desc.add<std::vector<int>>("maskMatchesCSC",
0164                              {
0165                                  1,
0166                                  0,
0167                                  0,
0168                                  0,
0169                              })
0170       ->setComment(
0171           "flags to mask/unmask DT, CSC and RPC chambers in individual muon stations. Segments and hits that are "
0172           "present in that muon station are ignored in case the 'mask' is set to 1. Per default only the innermost CSC "
0173           "chamber is ignored, as it is affected by spurious hits in high pile-up events.");
0174   desc.add<std::vector<int>>("maskHitsCSC",
0175                              {
0176                                  0,
0177                                  0,
0178                                  0,
0179                                  0,
0180                              });
0181   desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
0182   desc.add<int>("verbosity", 0);
0183   desc.add<std::vector<int>>("maskMatchesDT",
0184                              {
0185                                  0,
0186                                  0,
0187                                  0,
0188                                  0,
0189                              });
0190   desc.add<double>("minPtMatchedMuon", 5.0);
0191   desc.add<bool>("dRmuonMatchLimitedToJetArea", false);
0192   {
0193     edm::ParameterSetDescription psd0;
0194     psd0.add<std::string>("BooleanOperator", "and");
0195     {
0196       edm::ParameterSetDescription psd1;
0197       psd1.add<double>("cut", 0.5);
0198       psd1.add<edm::InputTag>("Producer", edm::InputTag("pfRecoTauDiscriminationByLeadingTrackFinding"));
0199       psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);  // optional with default?
0200     }
0201     // Prediscriminants can be
0202     // Prediscriminants = noPrediscriminants,
0203     // as in RecoTauTag/Configuration/python/HPSPFTaus_cff.py
0204     //
0205     // and the definition is:
0206     // RecoTauTag/RecoTau/python/TauDiscriminatorTools.py
0207     // # Require no prediscriminants
0208     // noPrediscriminants = cms.PSet(
0209     //       BooleanOperator = cms.string("and"),
0210     //       )
0211     // -- so this is the minimum required definition
0212     // otherwise it inserts the leadTrack with Producer = InpuTag(...) and does not find the corresponding output during the run
0213     desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
0214   }
0215   desc.add<std::vector<int>>("maskHitsDT",
0216                              {
0217                                  0,
0218                                  0,
0219                                  0,
0220                                  0,
0221                              });
0222   desc.add<double>("dRmuonMatch", 0.3);
0223   desc.add<edm::InputTag>("srcMuons", edm::InputTag("muons"))
0224       ->setComment("optional collection of muons to check for overlap with taus");
0225 
0226   edm::ParameterSetDescription desc_wp;
0227   desc_wp.add<std::string>("IDname");
0228   desc_wp.add<std::string>("discriminatorOption")
0229       ->setComment("available options are: 'loose', 'medium', 'tight' and 'custom'");
0230   desc_wp.add<double>("HoPMin");
0231   desc_wp.add<int>("maxNumberOfMatches")
0232       ->setComment("negative value would turn off this cut in case of 'custom' discriminator");
0233   desc_wp.add<bool>("doCaloMuonVeto");
0234   desc_wp.add<int>("maxNumberOfHitsLast2Stations")
0235       ->setComment("negative value would turn off this cut in case of 'custom' discriminator");
0236   edm::ParameterSet pset_wp;
0237   pset_wp.addParameter<std::string>("IDname", "pfRecoTauDiscriminationAgainstMuon2Container");
0238   pset_wp.addParameter<std::string>("discriminatorOption", "loose");
0239   pset_wp.addParameter<double>("HoPMin", 0.2);
0240   pset_wp.addParameter<int>("maxNumberOfMatches", 0);
0241   pset_wp.addParameter<bool>("doCaloMuonVeto", false);
0242   pset_wp.addParameter<int>("maxNumberOfHitsLast2Stations", 0);
0243   std::vector<edm::ParameterSet> vpsd_wp;
0244   vpsd_wp.push_back(pset_wp);
0245   desc.addVPSet("IDWPdefinitions", desc_wp, vpsd_wp);
0246   //add empty raw value config to simplify subsequent provenance searches
0247   desc.addVPSet("IDdefinitions", edm::ParameterSetDescription(), {});
0248 
0249   descriptions.add("pfRecoTauDiscriminationAgainstMuon2Container", desc);
0250 }
0251 
0252 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon2Container);