CMS 3D CMS Logo

TauDiscriminationAgainstMuon.cc
Go to the documentation of this file.
1 
2 /*
3  * class TauDiscriminationAgainstMuon
4  * created : July 09 2010
5  * revised :
6  * Authors : Sho Maruyama, Christian Veelken (UC Davis)
7  */
8 
10 
13 
16 
18 
19 #include <string>
20 
21 namespace {
22 using namespace reco;
23 
24 template<class TauType, class TauDiscriminator>
25 class TauDiscriminationAgainstMuon final : public TauDiscriminationProducerBase<TauType, TauDiscriminator>
26 {
27  public:
28  // setup framework types for this tautype
29  typedef std::vector<TauType> TauCollection;
31 
32  explicit TauDiscriminationAgainstMuon(const edm::ParameterSet&);
33  ~TauDiscriminationAgainstMuon() override {}
34 
35  // called at the beginning of every event
36  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
37 
38  double discriminate(const TauRef&) const override;
39 
40  private:
41  bool evaluateMuonVeto(const reco::Muon&) const;
42 
43  edm::InputTag muonSource_;
45  double dRmatch_;
46 
47  enum { kNoSegMatch, kTwoDCut, kMerePresence, kCombined };
48  int discriminatorOption_;
49 
50  double coeffCaloComp_;
51  double coeffSegmComp_;
52  double muonCompCut_;
53 };
54 
55 template<class TauType, class TauDiscriminator>
56 TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::TauDiscriminationAgainstMuon(const edm::ParameterSet& cfg)
57  : TauDiscriminationProducerBase<TauType, TauDiscriminator>(cfg)
58 {
59  //if ( cfg.exists("muonSource") ) muonSource_ = cfg.getParameter<edm::InputTag>("muonSource");
60  muonSource_ = cfg.getParameter<edm::InputTag>("muonSource");
61  dRmatch_ = ( cfg.exists("dRmatch") ) ? cfg.getParameter<double>("dRmatch") : 0.5;
62 
63  std::string discriminatorOption_string = cfg.getParameter<std::string>("discriminatorOption");
64  if ( discriminatorOption_string == "noSegMatch" ) discriminatorOption_ = kNoSegMatch;
65  else if ( discriminatorOption_string == "twoDCut" ) discriminatorOption_ = kTwoDCut;
66  else if ( discriminatorOption_string == "merePresence" ) discriminatorOption_ = kMerePresence;
67  else if ( discriminatorOption_string == "combined" ) discriminatorOption_ = kCombined;
68  else {
69  throw edm::Exception(edm::errors::UnimplementedFeature) << " Invalid Discriminator Option! Please check cfi file \n";
70  }
71 
72  coeffCaloComp_ = cfg.getParameter<double>("caloCompCoefficient");
73  coeffSegmComp_ = cfg.getParameter<double>("segmCompCoefficient");
74  muonCompCut_ = cfg.getParameter<double>("muonCompCut");
75 }
76 
77 template<class TauType, class TauDiscriminator>
78 void TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup)
79 {
80  evt.getByLabel(muonSource_, muons_);
81 }
82 
83 template<class TauType, class TauDiscriminator>
84 bool TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::evaluateMuonVeto(const reco::Muon& muon) const
85 {
86  bool decision = true;
87 
88  if ( discriminatorOption_ == kNoSegMatch ) {
89  if ( muon.numberOfMatches() > 0 ) decision = false;
90  } else if ( discriminatorOption_ == kTwoDCut ) {
91  double segmComp = muon::segmentCompatibility(muon);
92  double caloComp = muon.caloCompatibility();
93  if ( (coeffCaloComp_*segmComp + coeffSegmComp_*caloComp) > muonCompCut_ ) decision = false;
94  } else if ( discriminatorOption_ == kMerePresence ) {
95  decision = false;
96  } else if ( discriminatorOption_ == kCombined ) { // testing purpose only
97  unsigned int muonType = 0;
98  if ( muon.isGlobalMuon() ) muonType = 1;
99  else if ( muon.isCaloMuon() ) muonType = 2;
100  else if ( muon.isTrackerMuon() ) muonType = 3;
101 
102  bool eta_veto = ( fabs(muon.eta()) > 2.3 || (fabs(muon.eta()) > 1.4 && fabs(muon.eta()) < 1.6) ) ? true : false;
103  bool phi_veto = ( muon.phi() < 0.1 && muon.phi() > -0.1 ) ? true : false;
104 
105  if ( muonType != 1 || muon.numberOfMatches() > 0 || eta_veto || phi_veto ) decision = false;
106  }
107 
108  return decision;
109 }
110 
111 template<class TauType, class TauDiscriminator>
112 double TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::discriminate(const TauRef& tau) const
113 {
114  bool decision = true;
115 
116  for ( reco::MuonCollection::const_iterator muon = muons_->begin();
117  muon != muons_->end(); ++muon ) {
118  if ( reco::deltaR(muon->p4(), tau->p4()) < dRmatch_ ) decision &= evaluateMuonVeto(*muon);
119  }
120 
121  return (decision ? 1. : 0.);
122 }
123 }
124 
126 
127 //typedef TauDiscriminationAgainstMuon<PFTau, PFTauDiscriminator> PFRecoTauDiscriminationAgainstMuon;
128 typedef TauDiscriminationAgainstMuon<CaloTau, CaloTauDiscriminator> CaloRecoTauDiscriminationAgainstMuon;
129 
130 //DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon);
131 DEFINE_FWK_MODULE(CaloRecoTauDiscriminationAgainstMuon);
T getParameter(std::string const &) const
double eta() const final
momentum pseudorapidity
edm::Ref< TauBxCollection > TauRef
Definition: Tau.h:13
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< Tau > TauCollection
Definition: Tau.h:36
TauDiscriminationAgainstMuon< CaloTau, CaloTauDiscriminator > CaloRecoTauDiscriminationAgainstMuon
bool isTrackerMuon() const override
Definition: Muon.h:277
int numberOfMatches(unsigned int type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
bool isGlobalMuon() const override
Definition: Muon.h:276
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:146
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
fixed size matrix
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
bool isCaloMuon() const override
Definition: Muon.h:279
double phi() const final
momentum azimuthal angle
float caloCompatibility() const
Definition: Muon.h:154