Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /* 
0002  * class PFRecoTauDiscriminationAgainstMuon
0003  * created : May 07 2008,
0004  * revised : always,
0005  * Authors : Sho Maruyama,M.Bachtis
0006  */
0007 
0008 #include <FWCore/ParameterSet/interface/ConfigurationDescriptions.h>
0009 #include <FWCore/ParameterSet/interface/ParameterSetDescription.h>
0010 
0011 #include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"
0012 
0013 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0014 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0015 #include "DataFormats/JetReco/interface/PFJet.h"
0016 
0017 #include <string>
0018 
0019 using namespace reco;
0020 
0021 class PFRecoTauDiscriminationAgainstMuon : public PFTauDiscriminationProducerBase {
0022 public:
0023   explicit PFRecoTauDiscriminationAgainstMuon(const edm::ParameterSet& iConfig)
0024       : PFTauDiscriminationProducerBase(iConfig) {
0025     discriminatorOption_ = iConfig.getParameter<std::string>("discriminatorOption");
0026     hop_ = iConfig.getParameter<double>("HoPMin");
0027     a = iConfig.getParameter<double>("a");
0028     b = iConfig.getParameter<double>("b");
0029     c = iConfig.getParameter<double>("c");
0030     maxNumberOfMatches_ = iConfig.getParameter<int>("maxNumberOfMatches");
0031     checkNumMatches_ = iConfig.getParameter<bool>("checkNumMatches");
0032   }
0033 
0034   ~PFRecoTauDiscriminationAgainstMuon() override {}
0035 
0036   double discriminate(const PFTauRef& pfTau) const override;
0037 
0038   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0039 
0040 private:
0041   std::string discriminatorOption_;
0042   double hop_;
0043   double a;
0044   double b;
0045   double c;
0046   int maxNumberOfMatches_;
0047   bool checkNumMatches_;
0048 };
0049 
0050 double PFRecoTauDiscriminationAgainstMuon::discriminate(const PFTauRef& thePFTauRef) const {
0051   bool decision = true;
0052 
0053   if (thePFTauRef->hasMuonReference()) {
0054     MuonRef muonref = thePFTauRef->leadPFChargedHadrCand()->muonRef();
0055     if (discriminatorOption_ == "noSegMatch") {
0056       if (muonref->numberOfMatches() > maxNumberOfMatches_)
0057         decision = false;
0058     } else if (discriminatorOption_ == "twoDCut") {
0059       double seg = muon::segmentCompatibility(*muonref);
0060       double calo = muonref->caloCompatibility();
0061       double border = calo * a + seg * b + c;
0062       if (border > 0)
0063         decision = false;
0064     } else if (discriminatorOption_ == "merePresence") {
0065       decision = false;
0066     } else if (discriminatorOption_ == "combined") {  // testing purpose only
0067       unsigned int muType = 0;
0068       if (muonref->isGlobalMuon())
0069         muType = 1;
0070       else if (muonref->isCaloMuon())
0071         muType = 2;
0072       else if (muonref->isTrackerMuon())
0073         muType = 3;
0074       float muonEnergyFraction = 0.;
0075       const reco::PFJet* pfJetPtr = dynamic_cast<const reco::PFJet*>(thePFTauRef->pfTauTagInfoRef()->pfjetRef().get());
0076       if (pfJetPtr) {
0077         muonEnergyFraction = pfJetPtr->chargedMuEnergyFraction();
0078       } else
0079         throw cms::Exception("Type Mismatch") << "The PFTau was not made from PFJets, and this outdated algorithm was "
0080                                                  "not updated to cope with PFTaus made from other Jets.\n";
0081       bool eta_veto = false;
0082       bool phi_veto = false;
0083       if (fabs(muonref->eta()) > 2.3 || (fabs(muonref->eta()) > 1.4 && fabs(muonref->eta()) < 1.6))
0084         eta_veto = true;
0085       if (muonref->phi() < 0.1 && muonref->phi() > -0.1)
0086         phi_veto = true;
0087       if (muType != 1 || muonref->numberOfMatches() > 0 || eta_veto || phi_veto || muonEnergyFraction > 0.9)
0088         decision = false;  // as place holder
0089     } else if (discriminatorOption_ == "noAllArbitrated" || discriminatorOption_ == "noAllArbitratedWithHOP") {
0090       if (checkNumMatches_ && muonref->numberOfMatches() > maxNumberOfMatches_)
0091         decision = false;
0092       if (muon::isGoodMuon(*muonref, muon::AllArbitrated))
0093         decision = false;
0094     } else if (discriminatorOption_ == "HOP") {
0095       decision = true;  // only calo. muon cut requested: keep all tau candidates, regardless of signals in muon system
0096     } else {
0097       throw edm::Exception(edm::errors::UnimplementedFeature)
0098           << " Invalid Discriminator option = " << discriminatorOption_ << " --> please check cfi file !!\n";
0099     }
0100   }  // valid muon ref
0101 
0102   // Additional calo. muon cut: veto one prongs compatible with MIP signature
0103   if (discriminatorOption_ == "HOP" || discriminatorOption_ == "noAllArbitratedWithHOP") {
0104     if (thePFTauRef->leadPFChargedHadrCand().isNonnull()) {
0105       double muonCaloEn =
0106           thePFTauRef->leadPFChargedHadrCand()->hcalEnergy() + thePFTauRef->leadPFChargedHadrCand()->ecalEnergy();
0107       if (thePFTauRef->decayMode() == 0 && muonCaloEn < (hop_ * thePFTauRef->leadPFChargedHadrCand()->p()))
0108         decision = false;
0109     }
0110   }
0111 
0112   return (decision ? 1. : 0.);
0113 }
0114 
0115 void PFRecoTauDiscriminationAgainstMuon::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0116   // pfRecoTauDiscriminationAgainstMuon
0117   edm::ParameterSetDescription desc;
0118   desc.add<double>("a", 0.5);
0119   desc.add<double>("c", 0.0);
0120   desc.add<double>("b", 0.5);
0121   desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
0122   {
0123     edm::ParameterSetDescription psd0;
0124     psd0.add<std::string>("BooleanOperator", "and");
0125     {
0126       edm::ParameterSetDescription psd1;
0127       psd1.add<double>("cut");
0128       psd1.add<edm::InputTag>("Producer");
0129       psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
0130     }
0131     desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
0132   }
0133   desc.add<std::string>("discriminatorOption", "noSegMatch");
0134   desc.add<double>("HoPMin", 0.2);
0135   desc.add<int>("maxNumberOfMatches", 0);
0136   desc.add<bool>("checkNumMatches", false);
0137   descriptions.add("pfRecoTauDiscriminationAgainstMuon", desc);
0138 }
0139 
0140 DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon);