43 <<
" Failed to find File = " << inputFileName <<
" !!\n";
49 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
50 <<
" Failed to load MVA = " << mvaName.data() <<
" from file = " << inputFileName.
fullPath().data() <<
" !!\n";
52 inputFilesToDelete.push_back(inputFile);
70 moduleLabel_(cfg.getParameter<
std::
string>(
"@module_label")),
75 loadMVAfromDB_ = cfg.
exists(
"loadMVAfromDB") ? cfg.
getParameter<
bool>(
"loadMVAfromDB") :
false;
76 if ( !loadMVAfromDB_ ) {
77 if(cfg.
exists(
"inputFileName")){
79 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
81 mvaInput_ =
new float[11];
84 Muons_token=consumes<reco::MuonCollection>(srcMuons_);
87 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
90 produces<PFTauDiscriminator>(
"category");
95 double discriminate(
const PFTauRef&)
const override;
101 if ( !loadMVAfromDB_ )
delete mvaReader_;
103 for ( std::vector<TFile*>::iterator it = inputFilesToDelete_.begin();
104 it != inputFilesToDelete_.end(); ++it ) {
125 std::unique_ptr<PFTauDiscriminator> category_output_;
127 std::vector<TFile*> inputFilesToDelete_;
135 if ( loadMVAfromDB_ ) {
138 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
150 void countHits(
const reco::Muon&
muon, std::vector<int>& numHitsDT, std::vector<int>& numHitsCSC, std::vector<int>& numHitsRPC)
156 if ( hit == 0 )
break;
159 if ( muonStation >= 0 && muonStation < 4 ) {
173 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"<PFRecoTauDiscriminationAgainstMuonMVA::discriminate>:";
174 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
" moduleLabel = " << moduleLabel_;
179 category_output_->setValue(tauIndex_, category);
182 if ( tau->leadPFChargedHadrCand().
isNull() )
return 0.;
185 double tauCaloEnECAL = 0.;
186 double tauCaloEnHCAL = 0.;
187 const std::vector<reco::PFCandidatePtr>& tauSignalPFCands = tau->signalPFCands();
188 for ( std::vector<reco::PFCandidatePtr>::const_iterator tauSignalPFCand = tauSignalPFCands.begin();
189 tauSignalPFCand != tauSignalPFCands.end(); ++tauSignalPFCand ) {
190 tauCaloEnECAL += (*tauSignalPFCand)->ecalEnergy();
191 tauCaloEnHCAL += (*tauSignalPFCand)->hcalEnergy();
193 mvaInput_[1] = TMath::Sqrt(
TMath::Max(0., tauCaloEnECAL));
194 mvaInput_[2] = TMath::Sqrt(
TMath::Max(0., tauCaloEnHCAL));
195 mvaInput_[3] = tau->leadPFChargedHadrCand()->pt()/
TMath::Max(1.,Double_t(tau->pt()));
196 mvaInput_[4] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->ecalEnergy()));
197 mvaInput_[5] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->hcalEnergy()));
199 std::vector<int> numHitsDT(4);
200 std::vector<int> numHitsCSC(4);
201 std::vector<int> numHitsRPC(4);
202 for (
int iStation = 0; iStation < 4; ++iStation ) {
203 numHitsDT[iStation] = 0;
204 numHitsCSC[iStation] = 0;
205 numHitsRPC[iStation] = 0;
207 if ( tau->leadPFChargedHadrCand().
isNonnull() ) {
208 reco::MuonRef muonRef = tau->leadPFChargedHadrCand()->muonRef();
211 countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
214 size_t numMuons = muons_->size();
215 for (
size_t idxMuon = 0; idxMuon < numMuons; ++idxMuon ) {
217 if ( tau->leadPFChargedHadrCand().
isNonnull() && tau->leadPFChargedHadrCand()->muonRef().
isNonnull() && muon == tau->leadPFChargedHadrCand()->muonRef() ) {
221 if ( dR < dRmuonMatch_ ) {
223 countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC);
226 mvaInput_[6] = numMatches;
227 mvaInput_[7] = numHitsDT[0] + numHitsCSC[0] + numHitsRPC[0];
228 mvaInput_[8] = numHitsDT[1] + numHitsCSC[1] + numHitsRPC[1];
229 mvaInput_[9] = numHitsDT[2] + numHitsCSC[2] + numHitsRPC[2];
230 mvaInput_[10] = numHitsDT[3] + numHitsCSC[3] + numHitsRPC[3];
232 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
234 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"mvaValue = " << mvaValue;
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::RefProd< TauCollection > TauRefProd
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
static bool muonCSCHitFilter(uint16_t pattern)
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
static uint32_t getHitType(uint16_t pattern)
int numberOfAllHits(HitCategory category) const
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
const LorentzVector & p4() const final
four-momentum Lorentz vector
LocationCode location() const
Where was the file found?
bool isNull() const
Checks for null.
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
static bool muonHitFilter(uint16_t pattern)
virtual double discriminate(const TauRef &tau) const =0
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
static bool muonDTHitFilter(uint16_t pattern)
std::string fullPath() const
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)
T const * product() const
virtual void endEvent(edm::Event &)