CMS 3D CMS Logo

PFRecoTauDiscriminationAgainstMuon2Helper.cc
Go to the documentation of this file.
2 
12 
16 
17 #include <iostream>
18 
20 
22  const bool& verbosity,
23  const std::string& moduleLabel,
24  const bool srcMuons_label_empty,
25  const double& minPtMatchedMuon,
26  const double& dRmuonMatch,
27  const bool& dRmuonMatchLimitedToJetArea,
28  std::atomic<unsigned int>& numWarnings,
29  const unsigned int& maxWarnings,
30  const std::vector<int>& maskMatchesDT,
31  const std::vector<int>& maskMatchesCSC,
32  const std::vector<int>& maskMatchesRPC,
33  const std::vector<int>& maskHitsDT,
34  const std::vector<int>& maskHitsCSC,
35  const std::vector<int>& maskHitsRPC,
37  const reco::PFTauRef& pfTau,
38  const reco::PFCandidatePtr& pfCand)
39  : pfLeadChargedHadron_{pfCand} {
40  if (verbosity) {
41  edm::LogPrint("PFTauAgainstMuon2") << "<PFRecoTauDiscriminationAgainstMuon2Container::discriminate>:";
42  edm::LogPrint("PFTauAgainstMuon2") << " moduleLabel = " << moduleLabel;
43  edm::LogPrint("PFTauAgainstMuon2") << "tau #" << pfTau.key() << ": Pt = " << pfTau->pt()
44  << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi();
45  }
46 
47  std::vector<int> numMatchesDT(4);
48  std::vector<int> numMatchesCSC(4);
49  std::vector<int> numMatchesRPC(4);
50  std::vector<int> numHitsDT(4);
51  std::vector<int> numHitsCSC(4);
52  std::vector<int> numHitsRPC(4);
53  for (int iStation = 0; iStation < 4; ++iStation) {
54  numMatchesDT[iStation] = 0;
55  numMatchesCSC[iStation] = 0;
56  numMatchesRPC[iStation] = 0;
57  numHitsDT[iStation] = 0;
58  numHitsCSC[iStation] = 0;
59  numHitsRPC[iStation] = 0;
60  }
61 
62  //pfLeadChargedHadron_ = pfTau->leadPFChargedHadrCand();
63  if (pfLeadChargedHadron_.isNonnull()) {
64  reco::MuonRef muonRef = pfLeadChargedHadron_->muonRef();
65  if (muonRef.isNonnull()) {
66  if (verbosity)
67  edm::LogPrint("PFTauAgainstMuon2") << " has muonRef.";
68  reco::tau::countMatches(*muonRef, numMatchesDT, numMatchesCSC, numMatchesRPC);
69  reco::tau::countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
70  }
71  }
72 
73  if (!srcMuons_label_empty) {
74  size_t numMuons = muons->size();
75  for (size_t idxMuon = 0; idxMuon < numMuons; ++idxMuon) {
76  reco::MuonRef muon(muons, idxMuon);
77  if (verbosity)
78  edm::LogPrint("PFTauAgainstMuon2") << "muon #" << muon.key() << ": Pt = " << muon->pt()
79  << ", eta = " << muon->eta() << ", phi = " << muon->phi();
80  if (!(muon->pt() > minPtMatchedMuon)) {
81  if (verbosity) {
82  edm::LogPrint("PFTauAgainstMuon2") << " fails Pt cut --> skipping it.";
83  }
84  continue;
85  }
86  if (pfLeadChargedHadron_.isNonnull()) {
87  reco::MuonRef muonRef = pfLeadChargedHadron_->muonRef();
88  if (muonRef.isNonnull() && muon == pfLeadChargedHadron_->muonRef()) {
89  if (verbosity) {
90  edm::LogPrint("PFTauAgainstMuon2") << " matches muonRef of tau --> skipping it.";
91  }
92  continue;
93  }
94  }
95  double dR = deltaR(muon->p4(), pfTau->p4());
96  double dRmatch = dRmuonMatch;
98  double jetArea = 0.;
99  if (pfTau->jetRef().isNonnull())
100  jetArea = pfTau->jetRef()->jetArea();
101  if (jetArea > 0.) {
102  dRmatch = std::min(dRmatch, std::sqrt(jetArea / M_PI));
103  } else {
104  if (numWarnings < maxWarnings) {
105  edm::LogInfo("PFRecoTauDiscriminationAgainstMuon2Container::discriminate")
106  << "Jet associated to Tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta()
107  << ", phi = " << pfTau->phi() << " has area = " << jetArea << " !!";
108  ++numWarnings;
109  }
110  dRmatch = 0.1;
111  }
112  }
113  if (dR < dRmatch) {
114  if (verbosity)
115  edm::LogPrint("PFTauAgainstMuon2") << " overlaps with tau, dR = " << dR;
116  reco::tau::countMatches(*muon, numMatchesDT, numMatchesCSC, numMatchesRPC);
117  reco::tau::countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC);
118  }
119  }
120  }
121 
122  for (int iStation = 0; iStation < 4; ++iStation) {
123  if (numMatchesDT[iStation] > 0 && !maskMatchesDT[iStation])
124  ++numStationsWithMatches_;
125  if (numMatchesCSC[iStation] > 0 && !maskMatchesCSC[iStation])
126  ++numStationsWithMatches_;
127  if (numMatchesRPC[iStation] > 0 && !maskMatchesRPC[iStation])
128  ++numStationsWithMatches_;
129  }
130 
131  for (int iStation = 2; iStation < 4; ++iStation) {
132  if (numHitsDT[iStation] > 0 && !maskHitsDT[iStation])
133  ++numLast2StationsWithHits_;
134  if (numHitsCSC[iStation] > 0 && !maskHitsCSC[iStation])
135  ++numLast2StationsWithHits_;
136  if (numHitsRPC[iStation] > 0 && !maskHitsRPC[iStation])
137  ++numLast2StationsWithHits_;
138  }
139 
140  if (verbosity) {
141  edm::LogPrint("PFTauAgainstMuon2") << "numMatchesDT = " << format_vint(numMatchesDT);
142  edm::LogPrint("PFTauAgainstMuon2") << "numMatchesCSC = " << format_vint(numMatchesCSC);
143  edm::LogPrint("PFTauAgainstMuon2") << "numMatchesRPC = " << format_vint(numMatchesRPC);
144  edm::LogPrint("PFTauAgainstMuon2") << " --> numStationsWithMatches_ = " << numStationsWithMatches_;
145  edm::LogPrint("PFTauAgainstMuon2") << "numHitsDT = " << format_vint(numHitsDT);
146  edm::LogPrint("PFTauAgainstMuon2") << "numHitsCSC = " << format_vint(numHitsCSC);
147  edm::LogPrint("PFTauAgainstMuon2") << "numHitsRPC = " << format_vint(numHitsRPC);
148  edm::LogPrint("PFTauAgainstMuon2") << " --> numLast2StationsWithHits_ = " << numLast2StationsWithHits_;
149  }
150 
151  if (pfLeadChargedHadron_.isNonnull()) {
152  energyECALplusHCAL_ = pfLeadChargedHadron_->ecalEnergy() + pfLeadChargedHadron_->hcalEnergy();
153  if (verbosity) {
154  if (pfLeadChargedHadron_->trackRef().isNonnull()) {
155  edm::LogPrint("PFTauAgainstMuon2")
156  << "decayMode = " << pfTau->decayMode() << ", energy(ECAL+HCAL) = " << energyECALplusHCAL_
157  << ", leadPFChargedHadronP = " << pfLeadChargedHadron_->trackRef()->p();
158  } else if (pfLeadChargedHadron_->gsfTrackRef().isNonnull()) {
159  edm::LogPrint("PFTauAgainstMuon2")
160  << "decayMode = " << pfTau->decayMode() << ", energy(ECAL+HCAL) = " << energyECALplusHCAL_
161  << ", leadPFChargedHadronP = " << pfLeadChargedHadron_->gsfTrackRef()->p();
162  }
163  }
164  if (pfLeadChargedHadron_->trackRef().isNonnull())
165  leadTrack_ = pfLeadChargedHadron_->trackRef().get();
166  else if (pfLeadChargedHadron_->gsfTrackRef().isNonnull())
167  leadTrack_ = pfLeadChargedHadron_->gsfTrackRef().get();
168  }
169 }
170 
172  const reco::PFTauRef& pfTau) const {
173  bool passesCaloMuonVeto = true;
175  if (pfTau->decayMode() == 0 && leadTrack_ && energyECALplusHCAL_ < (config.hop * leadTrack_->p()))
176  passesCaloMuonVeto = false;
177  }
178 
179  bool discriminatorValue = false;
180  if (config.discriminatorOption == PFRecoTauDiscriminationAgainstMuonConfigSet::kLoose &&
181  numStationsWithMatches_ <= config.maxNumberOfMatches)
182  discriminatorValue = true;
183  else if (config.discriminatorOption == PFRecoTauDiscriminationAgainstMuonConfigSet::kMedium &&
184  numStationsWithMatches_ <= config.maxNumberOfMatches &&
185  numLast2StationsWithHits_ <= config.maxNumberOfHitsLast2Stations)
186  discriminatorValue = true;
187  else if (config.discriminatorOption == PFRecoTauDiscriminationAgainstMuonConfigSet::kTight &&
188  numStationsWithMatches_ <= config.maxNumberOfMatches &&
189  numLast2StationsWithHits_ <= config.maxNumberOfHitsLast2Stations && passesCaloMuonVeto)
190  discriminatorValue = true;
191  else if (config.discriminatorOption == PFRecoTauDiscriminationAgainstMuonConfigSet::kCustom) {
192  discriminatorValue = true;
193  if (config.maxNumberOfMatches >= 0 && numStationsWithMatches_ > config.maxNumberOfMatches)
194  discriminatorValue = false;
195  if (config.maxNumberOfHitsLast2Stations >= 0 && numLast2StationsWithHits_ > config.maxNumberOfHitsLast2Stations)
196  discriminatorValue = false;
197  if (config.doCaloMuonVeto && !passesCaloMuonVeto)
198  discriminatorValue = false;
199  }
200  return discriminatorValue;
201 }
double p() const
momentum vector magnitude
Definition: TrackBase.h:631
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
Definition: config.py:1
void countMatches(const reco::Muon &muon, std::vector< int > &numMatchesDT, std::vector< int > &numMatchesCSC, std::vector< int > &numMatchesRPC)
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
bool eval(const PFRecoTauDiscriminationAgainstMuonConfigSet &, const reco::PFTauRef &) const
T sqrt(T t)
Definition: SSEVec.h:19
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
Log< level::Warning, true > LogPrint
#define M_PI
const int verbosity
Log< level::Info, false > LogInfo
std::string format_vint(const std::vector< int > &vi)
PFRecoTauDiscriminationAgainstMuon2Helper(const bool &, const std::string &, const bool, const double &, const double &, const bool &, std::atomic< unsigned int > &, const unsigned int &, const std::vector< int > &, const std::vector< int > &, const std::vector< int > &, const std::vector< int > &, const std::vector< int > &, const std::vector< int > &, const edm::Handle< reco::MuonCollection > &, const reco::PFTauRef &, const reco::PFCandidatePtr &)
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)