CMS 3D CMS Logo

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