39 enum { kLoose, kMedium, kTight, kCustom };
46 if ( discriminatorOption_string ==
"loose" ) discriminatorOption_ = kLoose;
47 else if ( discriminatorOption_string ==
"medium" ) discriminatorOption_ = kMedium;
48 else if ( discriminatorOption_string ==
"tight" ) discriminatorOption_ = kTight;
49 else if ( discriminatorOption_string ==
"custom" ) discriminatorOption_ = kCustom;
51 <<
" Invalid Configuration parameter 'discriminatorOption' = " << discriminatorOption_string <<
" !!\n";
53 maxNumberOfMatches_ = cfg.
getParameter<
int>(
"maxNumberOfMatches");
54 doCaloMuonVeto_ = cfg.
getParameter<
bool>(
"doCaloMuonVeto");
55 maxNumberOfHitsLast2Stations_ = cfg.
getParameter<
int>(
"maxNumberOfHitsLast2Stations");
57 Muons_token = consumes<reco::MuonCollection>(srcMuons_);
59 dRmuonMatchLimitedToJetArea_ = cfg.
getParameter<
bool>(
"dRmuonMatchLimitedToJetArea");
60 minPtMatchedMuon_ = cfg.
getParameter<
double>(
"minPtMatchedMuon");
61 typedef std::vector<int>
vint;
62 maskMatchesDT_ = cfg.
getParameter<vint>(
"maskMatchesDT");
63 maskMatchesCSC_ = cfg.
getParameter<vint>(
"maskMatchesCSC");
64 maskMatchesRPC_ = cfg.
getParameter<vint>(
"maskMatchesRPC");
72 ~PFRecoTauDiscriminationAgainstMuon2()
override {}
82 int discriminatorOption_;
84 int maxNumberOfMatches_;
86 int maxNumberOfHitsLast2Stations_;
91 bool dRmuonMatchLimitedToJetArea_;
92 double minPtMatchedMuon_;
93 std::vector<int> maskMatchesDT_;
94 std::vector<int> maskMatchesCSC_;
95 std::vector<int> maskMatchesRPC_;
96 std::vector<int> maskHitsDT_;
97 std::vector<int> maskHitsCSC_;
98 std::vector<int> maskHitsRPC_;
99 mutable int numWarnings_;
106 if ( !srcMuons_.label().empty() ) {
114 edm::LogPrint(
"PFTauAgainstMuon2") <<
"<PFRecoTauDiscriminationAgainstMuon2::discriminate>:" ;
116 edm::LogPrint(
"PFTauAgainstMuon2") <<
"tau #" << pfTau.
key() <<
": Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi() ;
119 std::vector<int> numMatchesDT(4);
120 std::vector<int> numMatchesCSC(4);
121 std::vector<int> numMatchesRPC(4);
122 std::vector<int> numHitsDT(4);
123 std::vector<int> numHitsCSC(4);
124 std::vector<int> numHitsRPC(4);
125 for (
int iStation = 0; iStation < 4; ++iStation ) {
126 numMatchesDT[iStation] = 0;
127 numMatchesCSC[iStation] = 0;
128 numMatchesRPC[iStation] = 0;
129 numHitsDT[iStation] = 0;
130 numHitsCSC[iStation] = 0;
131 numHitsRPC[iStation] = 0;
138 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
" has muonRef." ;
144 if ( !srcMuons_.label().empty() ) {
145 size_t numMuons = muons_->size();
146 for (
size_t idxMuon = 0; idxMuon < numMuons; ++idxMuon ) {
148 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
"muon #" <<
muon.key() <<
": Pt = " <<
muon->pt() <<
", eta = " <<
muon->eta() <<
", phi = " <<
muon->phi() ;
149 if ( !(
muon->pt() > minPtMatchedMuon_) ) {
150 if ( verbosity_ ){
edm::LogPrint(
"PFTauAgainstMuon2") <<
" fails Pt cut --> skipping it." ;}
155 if (muonRef.
isNonnull() &&
muon == pfLeadChargedHadron->muonRef() ) {
156 if ( verbosity_ ) {
edm::LogPrint(
"PFTauAgainstMuon2") <<
" matches muonRef of tau --> skipping it."; }
162 if ( dRmuonMatchLimitedToJetArea_ ) {
164 if ( pfTau->jetRef().
isNonnull() ) jetArea = pfTau->jetRef()->jetArea();
165 if ( jetArea > 0. ) {
168 if ( numWarnings_ < maxWarnings_ ) {
169 edm::LogInfo(
"PFRecoTauDiscriminationAgainstMuon2::discriminate")
170 <<
"Jet associated to Tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi() <<
" has area = " << jetArea <<
" !!" ;
176 if ( dR < dRmatch ) {
177 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
" overlaps with tau, dR = " << dR ;
184 int numStationsWithMatches = 0;
185 for (
int iStation = 0; iStation < 4; ++iStation ) {
186 if ( numMatchesDT[iStation] > 0 && !maskMatchesDT_[iStation] ) ++numStationsWithMatches;
187 if ( numMatchesCSC[iStation] > 0 && !maskMatchesCSC_[iStation] ) ++numStationsWithMatches;
188 if ( numMatchesRPC[iStation] > 0 && !maskMatchesRPC_[iStation] ) ++numStationsWithMatches;
191 int numLast2StationsWithHits = 0;
192 for (
int iStation = 2; iStation < 4; ++iStation ) {
193 if ( numHitsDT[iStation] > 0 && !maskHitsDT_[iStation] ) ++numLast2StationsWithHits;
194 if ( numHitsCSC[iStation] > 0 && !maskHitsCSC_[iStation] ) ++numLast2StationsWithHits;
195 if ( numHitsRPC[iStation] > 0 && !maskHitsRPC_[iStation] ) ++numLast2StationsWithHits;
202 edm::LogPrint(
"PFTauAgainstMuon2") <<
" --> numStationsWithMatches = " << numStationsWithMatches ;
206 edm::LogPrint(
"PFTauAgainstMuon2") <<
" --> numLast2StationsWithHits = " << numLast2StationsWithHits ;
209 bool passesCaloMuonVeto =
true;
211 double energyECALplusHCAL = pfLeadChargedHadron->ecalEnergy() + pfLeadChargedHadron->hcalEnergy();
213 if ( pfLeadChargedHadron->trackRef().
isNonnull() ) {
214 edm::LogPrint(
"PFTauAgainstMuon2") <<
"decayMode = " << pfTau->decayMode() <<
", energy(ECAL+HCAL) = " << energyECALplusHCAL <<
", leadPFChargedHadronP = " << pfLeadChargedHadron->trackRef()->p() ;
215 }
else if ( pfLeadChargedHadron->gsfTrackRef().
isNonnull() ) {
216 edm::LogPrint(
"PFTauAgainstMuon2") <<
"decayMode = " << pfTau->decayMode() <<
", energy(ECAL+HCAL) = " << energyECALplusHCAL <<
", leadPFChargedHadronP = " << pfLeadChargedHadron->gsfTrackRef()->p() ;
220 if ( pfLeadChargedHadron->trackRef().
isNonnull() )
221 leadTrack = pfLeadChargedHadron->trackRef().
get();
222 else if ( pfLeadChargedHadron->gsfTrackRef().
isNonnull() )
223 leadTrack = pfLeadChargedHadron->gsfTrackRef().
get();
224 if ( pfTau->decayMode() == 0 && leadTrack && energyECALplusHCAL < (hop_*leadTrack->
p()) )
225 passesCaloMuonVeto =
false;
228 double discriminatorValue = 0.;
229 if ( discriminatorOption_ == kLoose && numStationsWithMatches <= maxNumberOfMatches_ ) discriminatorValue = 1.;
230 else if ( discriminatorOption_ == kMedium && numStationsWithMatches <= maxNumberOfMatches_ && numLast2StationsWithHits <= maxNumberOfHitsLast2Stations_ ) discriminatorValue = 1.;
231 else if ( discriminatorOption_ == kTight && numStationsWithMatches <= maxNumberOfMatches_ && numLast2StationsWithHits <= maxNumberOfHitsLast2Stations_ && passesCaloMuonVeto ) discriminatorValue = 1.;
232 else if ( discriminatorOption_ == kCustom ) {
234 if ( maxNumberOfMatches_ >= 0 && numStationsWithMatches > maxNumberOfMatches_ ) pass =
false;
235 if ( maxNumberOfHitsLast2Stations_ >= 0 && numLast2StationsWithHits > maxNumberOfHitsLast2Stations_ ) pass =
false;
236 if ( doCaloMuonVeto_ && !passesCaloMuonVeto ) pass =
false;
237 discriminatorValue = pass ? 1.: 0.;
239 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
"--> returning discriminatorValue = " << discriminatorValue ;
241 return discriminatorValue;
250 desc.
add<std::vector<int>>(
"maskHitsRPC", {
256 desc.
add<
int>(
"maxNumberOfHitsLast2Stations", 0);
257 desc.
add<std::vector<int>>(
"maskMatchesRPC", {
263 desc.
add<std::vector<int>>(
"maskMatchesCSC", {
269 desc.
add<std::vector<int>>(
"maskHitsCSC", {
276 desc.
add<
int>(
"verbosity", 0);
277 desc.
add<std::vector<int>>(
"maskMatchesDT", {
283 desc.
add<
double>(
"minPtMatchedMuon", 5.0);
284 desc.add<
bool>(
"dRmuonMatchLimitedToJetArea",
false);
290 psd1.
add<
double>(
"cut");
308 desc.
add<std::vector<int>>(
"maskHitsDT", {
314 desc.add<
double>(
"HoPMin", 0.2);
315 desc.add<
int>(
"maxNumberOfMatches", 0);
316 desc.add<
std::string>(
"discriminatorOption",
"loose");
317 desc.add<
double>(
"dRmuonMatch", 0.3);
319 desc.add<
bool>(
"doCaloMuonVeto",
false);
320 descriptions.add(
"pfRecoTauDiscriminationAgainstMuon2", desc);
double p() const
momentum vector magnitude
T getParameter(std::string const &) const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
T const * get() const
Returns C++ pointer to the item.
void countMatches(const reco::Muon &muon, std::vector< int > &numMatchesDT, std::vector< int > &numMatchesCSC, std::vector< int > &numMatchesRPC)
key_type key() const
Accessor for product key.
#define DEFINE_FWK_MODULE(type)
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
virtual double discriminate(const TauRef &tau) const =0
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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)