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);
75 loadMVAfromDB_ = cfg.
exists(
"loadMVAfromDB") ? cfg.
getParameter<
bool>(
"loadMVAfromDB") :
false;
76 if ( !loadMVAfromDB_ ) {
79 mvaInput_ =
new float[11];
82 Muons_token=consumes<reco::MuonCollection>(srcMuons_);
85 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
88 produces<PFTauDiscriminator>(
"category");
93 double discriminate(
const PFTauRef&)
const;
99 if ( !loadMVAfromDB_ )
delete mvaReader_;
101 for ( std::vector<TFile*>::iterator it = inputFilesToDelete_.begin();
102 it != inputFilesToDelete_.end(); ++it ) {
123 std::auto_ptr<PFTauDiscriminator> category_output_;
125 std::vector<TFile*> inputFilesToDelete_;
133 if ( loadMVAfromDB_ ) {
136 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
148 void countHits(
const reco::Muon&
muon, std::vector<int>& numHitsDT, std::vector<int>& numHitsCSC, std::vector<int>& numHitsRPC)
154 if ( hit == 0 )
break;
157 if ( muonStation >= 0 && muonStation < 4 ) {
171 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"<PFRecoTauDiscriminationAgainstMuonMVA::discriminate>:";
177 category_output_->setValue(tauIndex_, category);
180 if ( tau->leadPFChargedHadrCand().
isNull() )
return 0.;
182 mvaInput_[0] = TMath::Abs(tau->eta());
183 double tauCaloEnECAL = 0.;
184 double tauCaloEnHCAL = 0.;
185 const std::vector<reco::PFCandidatePtr>& tauSignalPFCands = tau->signalPFCands();
186 for ( std::vector<reco::PFCandidatePtr>::const_iterator tauSignalPFCand = tauSignalPFCands.begin();
187 tauSignalPFCand != tauSignalPFCands.end(); ++tauSignalPFCand ) {
188 tauCaloEnECAL += (*tauSignalPFCand)->ecalEnergy();
189 tauCaloEnHCAL += (*tauSignalPFCand)->hcalEnergy();
191 mvaInput_[1] = TMath::Sqrt(
TMath::Max(0., tauCaloEnECAL));
192 mvaInput_[2] = TMath::Sqrt(
TMath::Max(0., tauCaloEnHCAL));
193 mvaInput_[3] = tau->leadPFChargedHadrCand()->pt()/
TMath::Max(1.,Double_t(tau->pt()));
194 mvaInput_[4] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->ecalEnergy()));
195 mvaInput_[5] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->hcalEnergy()));
197 std::vector<int> numHitsDT(4);
198 std::vector<int> numHitsCSC(4);
199 std::vector<int> numHitsRPC(4);
200 for (
int iStation = 0; iStation < 4; ++iStation ) {
201 numHitsDT[iStation] = 0;
202 numHitsCSC[iStation] = 0;
203 numHitsRPC[iStation] = 0;
205 if ( tau->leadPFChargedHadrCand().
isNonnull() ) {
206 reco::MuonRef muonRef = tau->leadPFChargedHadrCand()->muonRef();
209 countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
213 for (
size_t idxMuon = 0; idxMuon <
numMuons; ++idxMuon ) {
215 if ( tau->leadPFChargedHadrCand().
isNonnull() && tau->leadPFChargedHadrCand()->muonRef().
isNonnull() && muon == tau->leadPFChargedHadrCand()->muonRef() ) {
219 if ( dR < dRmuonMatch_ ) {
221 countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC);
224 mvaInput_[6] = numMatches;
225 mvaInput_[7] = numHitsDT[0] + numHitsCSC[0] + numHitsRPC[0];
226 mvaInput_[8] = numHitsDT[1] + numHitsCSC[1] + numHitsRPC[1];
227 mvaInput_[9] = numHitsDT[2] + numHitsCSC[2] + numHitsRPC[2];
228 mvaInput_[10] = numHitsDT[3] + numHitsCSC[3] + numHitsRPC[3];
230 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
232 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"mvaValue = " << mvaValue;
240 evt.
put(category_output_,
"category");
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual double discriminate(const TauRef &tau) const =0
virtual void endEvent(edm::Event &evt)
static bool muonCSCHitFilter(uint16_t pattern)
static uint32_t getHitType(uint16_t pattern)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
bool isNull() const
Checks for null.
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
static bool muonHitFilter(uint16_t pattern)
LocationCode location() const
Where was the file found?
T const * product() const
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...
std::string fullPath() const
uint16_t getHitPattern(HitCategory category, int position) const
static bool muonRPCHitFilter(uint16_t pattern)
virtual void beginEvent(const edm::Event &evt, const edm::EventSetup &evtSetup)
int numberOfHits(HitCategory category) const