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 
19 
21 
22 #include <string>
23 
24 namespace {
25 using namespace reco;
26 
27 template<class TauType, class TauDiscriminator>
28 class TauDiscriminationAgainstMuon final : public TauDiscriminationProducerBase<TauType, TauDiscriminator>
29 {
30  public:
31  // setup framework types for this tautype
32  typedef std::vector<TauType> TauCollection;
34 
35  explicit TauDiscriminationAgainstMuon(const edm::ParameterSet&);
36  ~TauDiscriminationAgainstMuon() override {}
37 
38  // called at the beginning of every event
39  void beginEvent(const edm::Event&, const edm::EventSetup&) override;
40 
41  double discriminate(const TauRef&) const override;
42 
43  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
44 
45  private:
46  bool evaluateMuonVeto(const reco::Muon&) const;
47 
48  edm::InputTag muonSource_;
50  double dRmatch_;
51 
52  enum { kNoSegMatch, kTwoDCut, kMerePresence, kCombined };
53  int discriminatorOption_;
54 
55  double coeffCaloComp_;
56  double coeffSegmComp_;
57  double muonCompCut_;
58 };
59 
60 template<class TauType, class TauDiscriminator>
61 TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::TauDiscriminationAgainstMuon(const edm::ParameterSet& cfg)
62  : TauDiscriminationProducerBase<TauType, TauDiscriminator>(cfg)
63 {
64  muonSource_ = cfg.getParameter<edm::InputTag>("muonSource");
65  dRmatch_ = cfg.getParameter<double>("dRmatch");
66 
67  std::string discriminatorOption_string = cfg.getParameter<std::string>("discriminatorOption");
68  if ( discriminatorOption_string == "noSegMatch" ) discriminatorOption_ = kNoSegMatch;
69  else if ( discriminatorOption_string == "twoDCut" ) discriminatorOption_ = kTwoDCut;
70  else if ( discriminatorOption_string == "merePresence" ) discriminatorOption_ = kMerePresence;
71  else if ( discriminatorOption_string == "combined" ) discriminatorOption_ = kCombined;
72  else {
73  throw edm::Exception(edm::errors::UnimplementedFeature) << " Invalid Discriminator Option! Please check cfi file \n";
74  }
75 
76  coeffCaloComp_ = cfg.getParameter<double>("caloCompCoefficient");
77  coeffSegmComp_ = cfg.getParameter<double>("segmCompCoefficient");
78  muonCompCut_ = cfg.getParameter<double>("muonCompCut");
79 }
80 
81 template<class TauType, class TauDiscriminator>
82 void TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::beginEvent(const edm::Event& evt, const edm::EventSetup& evtSetup)
83 {
84  evt.getByLabel(muonSource_, muons_);
85 }
86 
87 template<class TauType, class TauDiscriminator>
88 bool TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::evaluateMuonVeto(const reco::Muon& muon) const
89 {
90  bool decision = true;
91 
92  if ( discriminatorOption_ == kNoSegMatch ) {
93  if ( muon.numberOfMatches() > 0 ) decision = false;
94  } else if ( discriminatorOption_ == kTwoDCut ) {
95  double segmComp = muon::segmentCompatibility(muon);
96  double caloComp = muon.caloCompatibility();
97  if ( (coeffCaloComp_*segmComp + coeffSegmComp_*caloComp) > muonCompCut_ ) decision = false;
98  } else if ( discriminatorOption_ == kMerePresence ) {
99  decision = false;
100  } else if ( discriminatorOption_ == kCombined ) { // testing purpose only
101  unsigned int muonType = 0;
102  if ( muon.isGlobalMuon() ) muonType = 1;
103  else if ( muon.isCaloMuon() ) muonType = 2;
104  else if ( muon.isTrackerMuon() ) muonType = 3;
105 
106  bool eta_veto = ( fabs(muon.eta()) > 2.3 || (fabs(muon.eta()) > 1.4 && fabs(muon.eta()) < 1.6) ) ? true : false;
107  bool phi_veto = ( muon.phi() < 0.1 && muon.phi() > -0.1 ) ? true : false;
108 
109  if ( muonType != 1 || muon.numberOfMatches() > 0 || eta_veto || phi_veto ) decision = false;
110  }
111 
112  return decision;
113 }
114 
115 template<class TauType, class TauDiscriminator>
116 double TauDiscriminationAgainstMuon<TauType, TauDiscriminator>::discriminate(const TauRef& tau) const
117 {
118  bool decision = true;
119 
120  for ( reco::MuonCollection::const_iterator muon = muons_->begin();
121  muon != muons_->end(); ++muon ) {
122  if ( reco::deltaR(muon->p4(), tau->p4()) < dRmatch_ ) decision &= evaluateMuonVeto(*muon);
123  }
124 
125  return (decision ? 1. : 0.);
126 }
127 }
128 
129 template<class TauType, class TauDiscriminator>
131 //CaloRecoTauDiscriminationAgainstMuon::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
132  // caloRecoTauDiscriminationAgainstMuon
134  desc.add<edm::InputTag>("CaloTauProducer", edm::InputTag("caloRecoTauProducer"));
135  desc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
136  desc.add<double>("muonCompCut", 0.0);
137  desc.add<double>("segmCompCoefficient", 0.5);
138  desc.add<double>("dRmatch", 0.5);
139  {
141  psd0.add<std::string>("BooleanOperator", "and");
142  {
144  psd1.add<double>("cut");
145  psd1.add<edm::InputTag>("Producer");
146  psd0.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
147  }
148  desc.add<edm::ParameterSetDescription>("Prediscriminants", psd0);
149  }
150  desc.add<std::string>("discriminatorOption", "noSegMatch");
151  desc.add<double>("caloCompCoefficient", 0.5);
152  descriptions.add("caloRecoTauDiscriminationAgainstMuon", desc);
153 }
154 
156 
157 //typedef TauDiscriminationAgainstMuon<PFTau, PFTauDiscriminator> PFRecoTauDiscriminationAgainstMuon;
158 typedef TauDiscriminationAgainstMuon<CaloTau, CaloTauDiscriminator> CaloRecoTauDiscriminationAgainstMuon;
159 
160 //DEFINE_FWK_MODULE(PFRecoTauDiscriminationAgainstMuon);
161 DEFINE_FWK_MODULE(CaloRecoTauDiscriminationAgainstMuon);
T getParameter(std::string const &) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
double eta() const final
momentum pseudorapidity
edm::Ref< TauBxCollection > TauRef
Definition: Tau.h:13
std::vector< Tau > TauCollection
Definition: Tau.h:37
TauDiscriminationAgainstMuon< CaloTau, CaloTauDiscriminator > CaloRecoTauDiscriminationAgainstMuon
bool isTrackerMuon() const override
Definition: Muon.h:292
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool isGlobalMuon() const override
Definition: Muon.h:291
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
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
fixed size matrix
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
bool isCaloMuon() const override
Definition: Muon.h:294
double phi() const final
momentum azimuthal angle
float caloCompatibility() const
Definition: Muon.h:154