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 }
PFRecoTauDiscriminationAgainstMuonConfigSet::kCustom
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
ctppsCommonDQMSource_cfi.verbosity
verbosity
Definition: ctppsCommonDQMSource_cfi.py:14
Muon.h
MessageLogger.h
muon
Definition: MuonCocktails.h:17
reco::TrackBase::p
double p() const
momentum vector magnitude
Definition: TrackBase.h:631
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
RecoTauMuonTools.h
PFRecoTauDiscriminationAgainstMuon2Helper.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
HLT_FULL_cff.maskHitsCSC
maskHitsCSC
Definition: HLT_FULL_cff.py:35635
edm::Handle< reco::MuonCollection >
PFRecoTauDiscriminationAgainstMuonConfigSet
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:7
PFRecoTauDiscriminationAgainstMuon2Helper::energyECALplusHCAL_
double energyECALplusHCAL_
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:25
HLT_FULL_cff.maskMatchesDT
maskMatchesDT
Definition: HLT_FULL_cff.py:35638
edm::Ref< PFTauCollection >
reco::tau::format_vint
std::string format_vint(const std::vector< int > &vi)
Definition: RecoTauMuonTools.cc:33
config
Definition: config.py:1
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
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11725
MuonSelectors.h
MuonFwd.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HLT_FULL_cff.maskHitsDT
maskHitsDT
Definition: HLT_FULL_cff.py:35642
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
HLT_FULL_cff.dRmuonMatchLimitedToJetArea
dRmuonMatchLimitedToJetArea
Definition: HLT_FULL_cff.py:35640
PFRecoTauDiscriminationAgainstMuonConfigSet::kMedium
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
deltaR.h
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:171
PFRecoTauDiscriminationAgainstMuon2Helper::leadTrack_
const reco::Track * leadTrack_
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:27
GsfTrack.h
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
HitPattern.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Ptr< PFCandidate >
HLT_FULL_cff.minPtMatchedMuon
minPtMatchedMuon
Definition: HLT_FULL_cff.py:35639
PFRecoTauDiscriminationAgainstMuonConfigSet::kTight
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
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:21
HLT_FULL_cff.dRmuonMatch
dRmuonMatch
Definition: HLT_FULL_cff.py:35646
PFRecoTauDiscriminationAgainstMuon2Helper::pfLeadChargedHadron_
const reco::PFCandidatePtr & pfLeadChargedHadron_
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:26
PFRecoTauDiscriminationAgainstMuon2Helper::numLast2StationsWithHits_
int numLast2StationsWithHits_
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:29
PFRecoTauDiscriminationAgainstMuonConfigSet::kLoose
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:8
PFTau.h
PFRecoTauDiscriminationAgainstMuon2Helper::numStationsWithMatches_
int numStationsWithMatches_
Definition: PFRecoTauDiscriminationAgainstMuon2Helper.h:28
HLT_FULL_cff.maskMatchesRPC
maskMatchesRPC
Definition: HLT_FULL_cff.py:35633
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
HLT_FULL_cff.maskMatchesCSC
maskMatchesCSC
Definition: HLT_FULL_cff.py:35634
Exception.h
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_FULL_cff.maskHitsRPC
maskHitsRPC
Definition: HLT_FULL_cff.py:35631
MuonChamberMatch.h