41 <<
" Failed to find File = " << inputFileName <<
" !!\n";
47 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
48 <<
" Failed to load MVA = " << mvaName.data() <<
" from file = " << inputFileName.
fullPath().data() <<
" !!\n";
50 inputFilesToDelete.push_back(inputFile);
67 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
70 mvaInput_ =
new float[11];
73 Muons_token=consumes<reco::MuonCollection>(srcMuons_);
76 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
79 produces<PFTauDiscriminator>(
"category");
84 double discriminate(
const PFTauRef&);
92 for ( std::vector<TFile*>::iterator it = inputFilesToDelete_.begin();
93 it != inputFilesToDelete_.end(); ++it ) {
134 void countHits(
const reco::Muon&
muon, std::vector<int>& numHitsDT, std::vector<int>& numHitsCSC, std::vector<int>& numHitsRPC)
138 for (
int iHit = 0; iHit < muonHitPattern.
numberOfHits(); ++iHit ) {
140 if ( hit == 0 )
break;
143 if ( muonStation >= 0 && muonStation < 4 ) {
157 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"<PFRecoTauDiscriminationAgainstMuonMVA::discriminate>:" ;
159 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
" mvaMin = " << mvaMin_ ;
164 category_output_->setValue(tauIndex_, category);
168 if ( tau->leadPFChargedHadrCand().
isNull() )
return 0.;
170 mvaInput_[0] = TMath::Abs(tau->eta());
171 double tauCaloEnECAL = 0.;
172 double tauCaloEnHCAL = 0.;
173 const std::vector<reco::PFCandidatePtr>& tauSignalPFCands = tau->signalPFCands();
174 for ( std::vector<reco::PFCandidatePtr>::const_iterator tauSignalPFCand = tauSignalPFCands.begin();
175 tauSignalPFCand != tauSignalPFCands.end(); ++tauSignalPFCand ) {
176 tauCaloEnECAL += (*tauSignalPFCand)->ecalEnergy();
177 tauCaloEnHCAL += (*tauSignalPFCand)->hcalEnergy();
179 mvaInput_[1] = TMath::Sqrt(
TMath::Max(0., tauCaloEnECAL));
180 mvaInput_[2] = TMath::Sqrt(
TMath::Max(0., tauCaloEnHCAL));
181 mvaInput_[3] = tau->leadPFChargedHadrCand()->pt()/
TMath::Max(1.,Double_t(tau->pt()));
182 mvaInput_[4] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->ecalEnergy()));
183 mvaInput_[5] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->hcalEnergy()));
185 std::vector<int> numHitsDT(4);
186 std::vector<int> numHitsCSC(4);
187 std::vector<int> numHitsRPC(4);
188 for (
int iStation = 0; iStation < 4; ++iStation ) {
189 numHitsDT[iStation] = 0;
190 numHitsCSC[iStation] = 0;
191 numHitsRPC[iStation] = 0;
193 if ( tau->leadPFChargedHadrCand().
isNonnull() ) {
194 reco::MuonRef muonRef = tau->leadPFChargedHadrCand()->muonRef();
197 countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
201 for (
size_t idxMuon = 0; idxMuon <
numMuons; ++idxMuon ) {
203 if ( tau->leadPFChargedHadrCand().
isNonnull() && tau->leadPFChargedHadrCand()->muonRef().
isNonnull() && muon == tau->leadPFChargedHadrCand()->muonRef() ) {
206 double dR =
deltaR(muon->p4(), tau->p4());
207 if ( dR < dRmuonMatch_ ) {
209 countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC);
212 mvaInput_[6] = numMatches;
213 mvaInput_[7] = numHitsDT[0] + numHitsCSC[0] + numHitsRPC[0];
214 mvaInput_[8] = numHitsDT[1] + numHitsCSC[1] + numHitsRPC[1];
215 mvaInput_[9] = numHitsDT[2] + numHitsCSC[2] + numHitsRPC[2];
216 mvaInput_[10] = numHitsDT[3] + numHitsCSC[3] + numHitsRPC[3];
218 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
220 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"mvaValue = " << mvaValue ;
227 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"--> retVal = " << retVal ;
230 retVal = ( mvaValue > mvaMin_ ) ? 1. : 0.;
232 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"--> retVal = " << retVal <<
": discriminator = ";
233 if ( retVal > 0.5 )
edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"PASSED." ;
243 evt.
put(category_output_,
"category");
~PFRecoTauDiscriminationAgainstMuonMVA()
void endEvent(edm::Event &)
T getParameter(std::string const &) const
double discriminate(const PFTauRef &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
static bool muonDTHitFilter(uint32_t pattern)
std::auto_ptr< PFTauDiscriminator > category_output_
edm::EDGetTokenT< reco::MuonCollection > Muons_token
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static uint32_t getHitType(uint32_t pattern)
static uint32_t getMuonStation(uint32_t pattern)
Muon station (1-4). Only valid for muon patterns, of course.
const GBRForest * mvaReader_
void beginEvent(const edm::Event &, const edm::EventSetup &)
static bool muonHitFilter(uint32_t pattern)
bool isNonnull() const
Checks for non-null.
bool isNull() const
Checks for null.
edm::Handle< reco::MuonCollection > muons_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static bool muonRPCHitFilter(uint32_t pattern)
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
edm::Handle< TauCollection > taus_
LocationCode location() const
Where was the file found?
PFRecoTauDiscriminationAgainstMuonMVA(const edm::ParameterSet &cfg)
static bool muonCSCHitFilter(uint32_t pattern)
edm::FileInPath inputFileName_
std::string fullPath() const
uint32_t getHitPattern(int position) const
std::vector< TFile * > inputFilesToDelete_