36 struct PFRecoTauDiscriminationAgainstMuonSimpleConfigSet {
37 PFRecoTauDiscriminationAgainstMuonSimpleConfigSet(
double hop,
int mNOM,
bool doCMV,
int mNHL2S,
int mNSTA,
int mNRPC)
56 auto const wpDefs =
cfg.getParameter<std::vector<edm::ParameterSet>>(
"IDWPdefinitions");
57 for (
auto& wpDef : wpDefs) {
59 PFRecoTauDiscriminationAgainstMuonSimpleConfigSet(wpDef.getParameter<
double>(
"HoPMin"),
60 wpDef.getParameter<
int>(
"maxNumberOfMatches"),
61 wpDef.getParameter<
bool>(
"doCaloMuonVeto"),
62 wpDef.getParameter<
int>(
"maxNumberOfHitsLast2Stations"),
63 wpDef.getParameter<
int>(
"maxNumberOfSTAMuons"),
64 wpDef.getParameter<
int>(
"maxNumberOfRPCMuons")));
67 muons_token = consumes<pat::MuonCollection>(srcPatMuons_);
68 dRmuonMatch_ =
cfg.getParameter<
double>(
"dRmuonMatch");
69 dRmuonMatchLimitedToJetArea_ =
cfg.getParameter<
bool>(
"dRmuonMatchLimitedToJetArea");
70 minPtMatchedMuon_ =
cfg.getParameter<
double>(
"minPtMatchedMuon");
71 typedef std::vector<int>
vint;
72 maskMatchesDT_ =
cfg.getParameter<
vint>(
"maskMatchesDT");
73 maskMatchesCSC_ =
cfg.getParameter<
vint>(
"maskMatchesCSC");
74 maskMatchesRPC_ =
cfg.getParameter<
vint>(
"maskMatchesRPC");
75 maskHitsDT_ =
cfg.getParameter<
vint>(
"maskHitsDT");
76 maskHitsCSC_ =
cfg.getParameter<
vint>(
"maskHitsCSC");
77 maskHitsRPC_ =
cfg.getParameter<
vint>(
"maskHitsRPC");
78 verbosity_ =
cfg.getParameter<
int>(
"verbosity");
80 ~PFRecoTauDiscriminationAgainstMuonSimple()
override {}
90 std::vector<PFRecoTauDiscriminationAgainstMuonSimpleConfigSet> wpDefs_;
95 bool dRmuonMatchLimitedToJetArea_;
96 double minPtMatchedMuon_;
97 std::vector<int> maskMatchesDT_;
98 std::vector<int> maskMatchesCSC_;
99 std::vector<int> maskMatchesRPC_;
100 std::vector<int> maskHitsDT_;
101 std::vector<int> maskHitsCSC_;
102 std::vector<int> maskHitsRPC_;
104 static std::atomic<unsigned int> numWarnings_;
105 static constexpr unsigned int maxWarnings_ = 3;
109 std::atomic<unsigned int> PFRecoTauDiscriminationAgainstMuonSimple::numWarnings_{0};
118 edm::LogPrint(
"PFTauAgainstMuonSimple") <<
"<PFRecoTauDiscriminationAgainstMuonSimple::discriminate>:";
119 edm::LogPrint(
"PFTauAgainstMuonSimple") <<
" moduleLabel = " << moduleLabel_;
121 <<
"tau #" << pfTau.
key() <<
": Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta()
122 <<
", phi = " << pfTau->phi() <<
", decay mode = " << pfTau->decayMode();
127 double caloEnergyFraction = 99;
130 if (pCand !=
nullptr) {
136 <<
"decayMode = " << pfTau->decayMode() <<
", caloEnergy(ECAL+HCAL)Fraction = " << caloEnergyFraction
137 <<
", leadPFChargedHadronP = " << pCand->
p() <<
", leadPFChargedHadron pdgId = " << pCand->
pdgId();
142 std::vector<const pat::Muon*> muonsToCheck;
144 for (
size_t idxMuon = 0; idxMuon <
numMuons; ++idxMuon) {
149 <<
", eta = " <<
muon->eta() <<
", phi = " <<
muon->phi();
151 for (
size_t iCand = 0; iCand <
muon->numberOfSourceCandidatePtrs(); ++iCand) {
154 srcCand.
key() == pfLeadChargedHadron.
key()) {
155 muonsToCheck.push_back(
muon.get());
158 edm::LogPrint(
"PFTauAgainstMuonSimple") <<
" tau has muonRef.";
165 if (!(
muon->pt() > minPtMatchedMuon_)) {
167 edm::LogPrint(
"PFTauAgainstMuonSimple") <<
" fails Pt cut --> skipping it.";
172 double dRmatch = dRmuonMatch_;
173 if (dRmuonMatchLimitedToJetArea_) {
176 jetArea = pfTau->jetRef()->jetArea();
180 if (numWarnings_ < maxWarnings_) {
181 edm::LogInfo(
"PFRecoTauDiscriminationAgainstMuonSimple::discriminate")
182 <<
"Jet associated to Tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta()
183 <<
", phi = " << pfTau->phi() <<
" has area = " << jetArea <<
" !!";
186 dRmatch = pfTau->signalConeSize();
188 dRmatch =
std::max(dRmatch, pfTau->signalConeSize());
191 edm::LogPrint(
"PFTauAgainstMuonSimple") <<
" overlaps with tau, dR = " <<
dR;
192 muonsToCheck.push_back(
muon.get());
197 std::vector<int> numMatchesDT(4);
198 std::vector<int> numMatchesCSC(4);
199 std::vector<int> numMatchesRPC(4);
200 std::vector<int> numHitsDT(4);
201 std::vector<int> numHitsCSC(4);
202 std::vector<int> numHitsRPC(4);
204 for (
int iStation = 0; iStation < 4; ++iStation) {
205 numMatchesDT[iStation] = 0;
206 numMatchesCSC[iStation] = 0;
207 numMatchesRPC[iStation] = 0;
208 numHitsDT[iStation] = 0;
209 numHitsCSC[iStation] = 0;
210 numHitsRPC[iStation] = 0;
212 int numSTAMuons = 0, numRPCMuons = 0;
213 int numStationsWithMatches = 0;
214 int numLast2StationsWithHits = 0;
215 if (verbosity_ && !muonsToCheck.empty())
216 edm::LogPrint(
"PFTauAgainstMuonSimple") <<
"Muons to check (" << muonsToCheck.size() <<
"):";
218 for (
const auto&
mu : muonsToCheck) {
219 if (
mu->isStandAloneMuon())
221 if (
mu->muonID(
"RPCMuLoose"))
224 for (
int iStation = 0; iStation < 4; ++iStation) {
225 if (numMatchesDT[iStation] > 0 && !maskMatchesDT_[iStation])
226 ++numStationsWithMatches;
227 if (numMatchesCSC[iStation] > 0 && !maskMatchesCSC_[iStation])
228 ++numStationsWithMatches;
229 if (numMatchesRPC[iStation] > 0 && !maskMatchesRPC_[iStation])
230 ++numStationsWithMatches;
233 for (
int iStation = 2; iStation < 4; ++iStation) {
234 if (numHitsDT[iStation] > 0 && !maskHitsDT_[iStation])
235 ++numLast2StationsWithHits;
236 if (numHitsCSC[iStation] > 0 && !maskHitsCSC_[iStation])
237 ++numLast2StationsWithHits;
238 if (numHitsRPC[iStation] > 0 && !maskHitsRPC_[iStation])
239 ++numLast2StationsWithHits;
243 <<
"\t" << iMu <<
": Pt = " <<
mu->pt() <<
", eta = " <<
mu->eta() <<
", phi = " <<
mu->phi() <<
"\n\t" 244 <<
" isSTA: " <<
mu->isStandAloneMuon() <<
", isRPCLoose: " <<
mu->muonID(
"RPCMuLoose")
245 <<
"\n\t numMatchesDT = " <<
format_vint(numMatchesDT)
246 <<
"\n\t numMatchesCSC = " <<
format_vint(numMatchesCSC)
247 <<
"\n\t numMatchesRPC = " <<
format_vint(numMatchesRPC)
248 <<
"\n\t --> numStationsWithMatches = " << numStationsWithMatches
251 <<
"\n\t --> numLast2StationsWithHits = " << numLast2StationsWithHits;
256 for (
auto const& wpDef : wpDefs_) {
257 bool discriminatorValue =
true;
258 if (wpDef.maxNumberOfMatches >= 0 && numStationsWithMatches > wpDef.maxNumberOfMatches)
259 discriminatorValue =
false;
260 if (wpDef.maxNumberOfHitsLast2Stations >= 0 && numLast2StationsWithHits > wpDef.maxNumberOfHitsLast2Stations)
261 discriminatorValue =
false;
262 if (wpDef.maxNumberOfSTAMuons >= 0 && numSTAMuons > wpDef.maxNumberOfSTAMuons) {
263 discriminatorValue =
false;
265 if (wpDef.maxNumberOfRPCMuons >= 0 && numRPCMuons > wpDef.maxNumberOfRPCMuons) {
266 discriminatorValue =
false;
268 bool passesCaloMuonVeto =
true;
269 if (pfTau->decayMode() == 0 && caloEnergyFraction < wpDef.hop) {
270 passesCaloMuonVeto =
false;
272 if (wpDef.doCaloMuonVeto && !passesCaloMuonVeto) {
273 discriminatorValue =
false;
275 result.workingPoints.push_back(discriminatorValue);
277 edm::LogPrint(
"PFTauAgainstMuonSimple") <<
"--> returning discriminatorValue = " <<
result.workingPoints.back();
291 psd1.
add<
double>(
"cut");
312 desc_wp.
add<
double>(
"HoPMin");
313 desc_wp.
add<
int>(
"maxNumberOfMatches")->setComment(
"negative value would turn off this cut");
314 desc_wp.
add<
bool>(
"doCaloMuonVeto");
315 desc_wp.
add<
int>(
"maxNumberOfHitsLast2Stations")->setComment(
"negative value would turn off this cut");
316 desc_wp.
add<
int>(
"maxNumberOfSTAMuons")->setComment(
"negative value would turn off this cut");
317 desc_wp.
add<
int>(
"maxNumberOfRPCMuons")->setComment(
"negative value would turn off this cut");
321 pset_wp.addParameter<
int>(
"maxNumberOfMatches", 1);
322 pset_wp.addParameter<
bool>(
"doCaloMuonVeto",
true);
323 pset_wp.addParameter<
int>(
"maxNumberOfHitsLast2Stations", -1);
324 pset_wp.addParameter<
int>(
"maxNumberOfSTAMuons", -1);
325 pset_wp.addParameter<
int>(
"maxNumberOfRPCMuons", -1);
326 std::vector<edm::ParameterSet> vpsd_wp;
327 vpsd_wp.push_back(pset_wp);
328 desc.addVPSet(
"IDWPdefinitions", desc_wp, vpsd_wp);
334 desc.add<
double>(
"dRmuonMatch", 0.3);
335 desc.add<
bool>(
"dRmuonMatchLimitedToJetArea",
false);
336 desc.add<
double>(
"minPtMatchedMuon", 5.0);
337 desc.add<std::vector<int>>(
"maskMatchesDT", {0, 0, 0, 0});
338 desc.add<std::vector<int>>(
"maskMatchesCSC", {1, 0, 0, 0})
340 "flags to mask/unmask DT, CSC and RPC chambers in individual muon stations. Segments and hits that are " 341 "present in that muon station are ignored in case the 'mask' is set to 1. Per default only the innermost " 343 "chamber is ignored, as it is affected by spurious hits in high pile-up events.");
344 desc.add<std::vector<int>>(
"maskMatchesRPC", {0, 0, 0, 0});
345 desc.add<std::vector<int>>(
"maskHitsDT", {0, 0, 0, 0});
346 desc.add<std::vector<int>>(
"maskHitsCSC", {0, 0, 0, 0});
347 desc.add<std::vector<int>>(
"maskHitsRPC", {0, 0, 0, 0});
348 desc.add<
int>(
"verbosity", 0);
349 descriptions.
add(
"pfRecoTauDiscriminationAgainstMuonSimple",
desc);
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ProductID id() const
Accessor for product ID.
double p() const
momentum vector magnitude
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void countMatches(const reco::Muon &muon, std::vector< int > &numMatchesDT, std::vector< int > &numMatchesCSC, std::vector< int > &numMatchesRPC)
float caloFraction() const
Set the fraction of ECAL+HCAL energy over candidate energy.
virtual TauDiscriminatorDataType discriminate(const TauRef &tau) const =0
int pdgId() const override
PDG identifier.
key_type key() const
Accessor for product key.
double p() const override
magnitude of momentum vector
bool isNonnull() const
Checks for non-null.
void addParameter(std::string const &name, T const &value)
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Warning, true > LogPrint
T const * get() const
Returns C++ pointer to the item.
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
Log< level::Info, false > LogInfo
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
maxNumberOfHitsLast2Stations
void add(std::string const &label, ParameterSetDescription const &psetDescription)
double energy() const override
energy
std::string format_vint(const std::vector< int > &vi)
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.