32 enum { kLoose, kMedium, kTight, kCustom };
39 if ( discriminatorOption_string ==
"loose" ) discriminatorOption_ = kLoose;
40 else if ( discriminatorOption_string ==
"medium" ) discriminatorOption_ = kMedium;
41 else if ( discriminatorOption_string ==
"tight" ) discriminatorOption_ = kTight;
42 else if ( discriminatorOption_string ==
"custom" ) discriminatorOption_ = kCustom;
44 <<
" Invalid Configuration parameter 'discriminatorOption' = " << discriminatorOption_string <<
" !!\n";
46 maxNumberOfMatches_ = cfg.
exists(
"maxNumberOfMatches") ? cfg.
getParameter<
int>(
"maxNumberOfMatches"): 0;
47 doCaloMuonVeto_ = cfg.
exists(
"doCaloMuonVeto") ? cfg.
getParameter<
bool>(
"doCaloMuonVeto"):
false;
48 maxNumberOfHitsLast2Stations_ = cfg.
exists(
"maxNumberOfHitsLast2Stations") ? cfg.
getParameter<
int>(
"maxNumberOfHitsLast2Stations"): 0;
49 if ( cfg.
exists(
"srcMuons") ) {
51 Muons_token = consumes<reco::MuonCollection>(srcMuons_);
53 dRmuonMatchLimitedToJetArea_ = cfg.
getParameter<
bool>(
"dRmuonMatchLimitedToJetArea");
54 minPtMatchedMuon_ = cfg.
getParameter<
double>(
"minPtMatchedMuon");
56 typedef std::vector<int>
vint;
57 maskMatchesDT_ = cfg.
getParameter<vint>(
"maskMatchesDT");
58 maskMatchesCSC_ = cfg.
getParameter<vint>(
"maskMatchesCSC");
59 maskMatchesRPC_ = cfg.
getParameter<vint>(
"maskMatchesRPC");
67 ~PFRecoTauDiscriminationAgainstMuon2() {}
75 int discriminatorOption_;
77 int maxNumberOfMatches_;
79 int maxNumberOfHitsLast2Stations_;
84 bool dRmuonMatchLimitedToJetArea_;
85 double minPtMatchedMuon_;
86 std::vector<int> maskMatchesDT_;
87 std::vector<int> maskMatchesCSC_;
88 std::vector<int> maskMatchesRPC_;
89 std::vector<int> maskHitsDT_;
90 std::vector<int> maskHitsCSC_;
91 std::vector<int> maskHitsRPC_;
92 mutable int numWarnings_;
99 if ( srcMuons_.label() !=
"" ) {
106 void countHits(
const reco::Muon&
muon, std::vector<int>& numHitsDT, std::vector<int>& numHitsCSC, std::vector<int>& numHitsRPC)
112 if ( hit == 0 )
break;
115 if ( muonStation >= 0 && muonStation < 4 ) {
125 std::string format_vint(
const std::vector<int>& vi)
127 std::ostringstream os;
130 for (
unsigned iEntry = 0; iEntry <
numEntries; ++iEntry ) {
132 if ( iEntry < (numEntries - 1) ) os <<
", ";
138 void countMatches(
const reco::Muon& muon, std::vector<int>& numMatchesDT, std::vector<int>& numMatchesCSC, std::vector<int>& numMatchesRPC)
140 const std::vector<reco::MuonChamberMatch>& muonSegments = muon.
matches();
141 for ( std::vector<reco::MuonChamberMatch>::const_iterator muonSegment = muonSegments.begin();
142 muonSegment != muonSegments.end(); ++muonSegment ) {
143 if ( muonSegment->segmentMatches.empty() )
continue;
144 int muonDetector = muonSegment->detector();
145 int muonStation = muonSegment->station() - 1;
146 assert(muonStation >= 0 && muonStation <= 3);
157 edm::LogPrint(
"PFTauAgainstMuon2") <<
"<PFRecoTauDiscriminationAgainstMuon2::discriminate>:" ;
159 edm::LogPrint(
"PFTauAgainstMuon2") <<
"tau #" << pfTau.
key() <<
": Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi() ;
162 std::vector<int> numMatchesDT(4);
163 std::vector<int> numMatchesCSC(4);
164 std::vector<int> numMatchesRPC(4);
165 std::vector<int> numHitsDT(4);
166 std::vector<int> numHitsCSC(4);
167 std::vector<int> numHitsRPC(4);
168 for (
int iStation = 0; iStation < 4; ++iStation ) {
169 numMatchesDT[iStation] = 0;
170 numMatchesCSC[iStation] = 0;
171 numMatchesRPC[iStation] = 0;
172 numHitsDT[iStation] = 0;
173 numHitsCSC[iStation] = 0;
174 numHitsRPC[iStation] = 0;
181 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
" has muonRef." ;
182 countMatches(*muonRef, numMatchesDT, numMatchesCSC, numMatchesRPC);
183 countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
187 if ( srcMuons_.label() !=
"" ) {
189 for (
size_t idxMuon = 0; idxMuon <
numMuons; ++idxMuon ) {
191 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
"muon #" << muon.key() <<
": Pt = " << muon->
pt() <<
", eta = " << muon->
eta() <<
", phi = " << muon->
phi() ;
192 if ( !(muon->
pt() > minPtMatchedMuon_) ) {
193 if ( verbosity_ ){
edm::LogPrint(
"PFTauAgainstMuon2") <<
" fails Pt cut --> skipping it." ;}
196 if ( pfLeadChargedHadron.
isNonnull() && pfLeadChargedHadron->muonRef().
isNonnull() && muon == pfLeadChargedHadron->muonRef() ) {
197 if ( verbosity_ ){
edm::LogPrint(
"PFTauAgainstMuon2") <<
" matches muonRef of tau --> skipping it." ;}
201 double dRmatch = dRmuonMatch_;
202 if ( dRmuonMatchLimitedToJetArea_ ) {
204 if ( pfTau->jetRef().
isNonnull() ) jetArea = pfTau->jetRef()->jetArea();
205 if ( jetArea > 0. ) {
208 if ( numWarnings_ < maxWarnings_ ) {
210 <<
"Jet associated to Tau: Pt = " << pfTau->pt() <<
", eta = " << pfTau->eta() <<
", phi = " << pfTau->phi() <<
" has area = " << jetArea <<
" !!" ;
216 if ( dR < dRmatch ) {
217 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
" overlaps with tau, dR = " <<
dR ;
218 countMatches(*muon, numMatchesDT, numMatchesCSC, numMatchesRPC);
219 countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC);
224 int numStationsWithMatches = 0;
225 for (
int iStation = 0; iStation < 4; ++iStation ) {
226 if ( numMatchesDT[iStation] > 0 && !maskMatchesDT_[iStation] ) ++numStationsWithMatches;
227 if ( numMatchesCSC[iStation] > 0 && !maskMatchesCSC_[iStation] ) ++numStationsWithMatches;
228 if ( numMatchesRPC[iStation] > 0 && !maskMatchesRPC_[iStation] ) ++numStationsWithMatches;
231 int numLast2StationsWithHits = 0;
232 for (
int iStation = 2; iStation < 4; ++iStation ) {
233 if ( numHitsDT[iStation] > 0 && !maskHitsDT_[iStation] ) ++numLast2StationsWithHits;
234 if ( numHitsCSC[iStation] > 0 && !maskHitsCSC_[iStation] ) ++numLast2StationsWithHits;
235 if ( numHitsRPC[iStation] > 0 && !maskHitsRPC_[iStation] ) ++numLast2StationsWithHits;
239 edm::LogPrint(
"PFTauAgainstMuon2") <<
"numMatchesDT = " << format_vint(numMatchesDT) ;
240 edm::LogPrint(
"PFTauAgainstMuon2") <<
"numMatchesCSC = " << format_vint(numMatchesCSC) ;
241 edm::LogPrint(
"PFTauAgainstMuon2") <<
"numMatchesRPC = " << format_vint(numMatchesRPC) ;
242 edm::LogPrint(
"PFTauAgainstMuon2") <<
" --> numStationsWithMatches = " << numStationsWithMatches ;
243 edm::LogPrint(
"PFTauAgainstMuon2") <<
"numHitsDT = " << format_vint(numHitsDT) ;
244 edm::LogPrint(
"PFTauAgainstMuon2") <<
"numHitsCSC = " << format_vint(numHitsCSC) ;
245 edm::LogPrint(
"PFTauAgainstMuon2") <<
"numHitsRPC = " << format_vint(numHitsRPC) ;
246 edm::LogPrint(
"PFTauAgainstMuon2") <<
" --> numLast2StationsWithHits = " << numLast2StationsWithHits ;
249 bool passesCaloMuonVeto =
true;
251 double energyECALplusHCAL = pfLeadChargedHadron->ecalEnergy() + pfLeadChargedHadron->hcalEnergy();
253 if ( pfLeadChargedHadron->trackRef().
isNonnull() ) {
254 edm::LogPrint(
"PFTauAgainstMuon2") <<
"decayMode = " << pfTau->decayMode() <<
", energy(ECAL+HCAL) = " << energyECALplusHCAL <<
", leadPFChargedHadronP = " << pfLeadChargedHadron->trackRef()->p() ;
255 }
else if ( pfLeadChargedHadron->gsfTrackRef().
isNonnull() ) {
256 edm::LogPrint(
"PFTauAgainstMuon2") <<
"decayMode = " << pfTau->decayMode() <<
", energy(ECAL+HCAL) = " << energyECALplusHCAL <<
", leadPFChargedHadronP = " << pfLeadChargedHadron->gsfTrackRef()->p() ;
260 if ( pfLeadChargedHadron->trackRef().
isNonnull() ) leadTrack = pfLeadChargedHadron->trackRef().
get();
261 else if ( pfLeadChargedHadron->gsfTrackRef().
isNonnull() ) leadTrack = pfLeadChargedHadron->gsfTrackRef().
get();
262 if ( pfTau->decayMode() == 0 && leadTrack && energyECALplusHCAL < (hop_*leadTrack->
p()) ) passesCaloMuonVeto =
false;
265 double discriminatorValue = 0.;
266 if ( discriminatorOption_ == kLoose && numStationsWithMatches <= maxNumberOfMatches_ ) discriminatorValue = 1.;
267 else if ( discriminatorOption_ == kMedium && numStationsWithMatches <= maxNumberOfMatches_ && numLast2StationsWithHits <= maxNumberOfHitsLast2Stations_ ) discriminatorValue = 1.;
268 else if ( discriminatorOption_ == kTight && numStationsWithMatches <= maxNumberOfMatches_ && numLast2StationsWithHits <= maxNumberOfHitsLast2Stations_ && passesCaloMuonVeto ) discriminatorValue = 1.;
269 else if ( discriminatorOption_ == kCustom ) {
271 if ( maxNumberOfMatches_ >= 0 && numStationsWithMatches > maxNumberOfMatches_ ) pass =
false;
272 if ( maxNumberOfHitsLast2Stations_ >= 0 && numLast2StationsWithHits > maxNumberOfHitsLast2Stations_ ) pass =
false;
273 if ( doCaloMuonVeto_ && !passesCaloMuonVeto ) pass =
false;
274 discriminatorValue = pass ? 1.: 0.;
276 if ( verbosity_ )
edm::LogPrint(
"PFTauAgainstMuon2") <<
"--> returning discriminatorValue = " << discriminatorValue ;
278 return discriminatorValue;
double p() const
momentum vector magnitude
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
virtual float pt() const
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
virtual float phi() const
momentum azimuthal angle
T const * get() const
Returns C++ pointer to the item.
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual double discriminate(const TauRef &tau) const =0
key_type key() const
Accessor for product key.
static bool muonCSCHitFilter(uint16_t pattern)
static uint32_t getHitType(uint16_t pattern)
virtual float eta() const
momentum pseudorapidity
Long64_t numEntries(TFile *hdl, std::string const &trname)
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
bool isNonnull() const
Checks for non-null.
double deltaR(double eta1, double eta2, double phi1, double phi2)
static bool muonHitFilter(uint16_t pattern)
std::vector< MuonChamberMatch > & matches()
get muon matching information
static bool muonDTHitFilter(uint16_t pattern)
static uint16_t getMuonStation(uint16_t pattern)
Muon station (1-4). Only valid for muon patterns, of course. only for patterns from muon...
uint16_t getHitPattern(HitCategory category, int position) const
static bool muonRPCHitFilter(uint16_t pattern)
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
virtual void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup)
int numberOfHits(HitCategory category) const