46 <<
" Failed to find File = " << inputFileName <<
" !!\n";
52 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
53 <<
" Failed to load MVA = " << mvaName.data() <<
" from file = " << inputFileName.
fullPath().data() <<
" !!\n";
55 inputFilesToDelete.push_back(inputFile);
73 moduleLabel_(cfg.getParameter<
std::
string>(
"@module_label")),
78 loadMVAfromDB_ = cfg.
getParameter<
bool>(
"loadMVAfromDB");
79 if ( !loadMVAfromDB_ ) {
82 mvaInput_ =
new float[11];
85 Muons_token=consumes<reco::MuonCollection>(srcMuons_);
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 ) {
127 std::unique_ptr<PFTauDiscriminator> category_output_;
129 std::vector<TFile*> inputFilesToDelete_;
137 if ( loadMVAfromDB_ ) {
140 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
152 void countHits(
const reco::Muon&
muon, std::vector<int>& numHitsDT, std::vector<int>& numHitsCSC, std::vector<int>& numHitsRPC)
158 if ( hit == 0 )
break;
161 if ( muonStation >= 0 && muonStation < 4 ) {
175 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"<PFRecoTauDiscriminationAgainstMuonMVA::discriminate>:";
176 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
" moduleLabel = " << moduleLabel_;
181 category_output_->setValue(tauIndex_, category);
184 if ( tau->leadPFChargedHadrCand().
isNull() )
return 0.;
187 double tauCaloEnECAL = 0.;
188 double tauCaloEnHCAL = 0.;
189 const std::vector<reco::PFCandidatePtr>& tauSignalPFCands = tau->signalPFCands();
190 for ( std::vector<reco::PFCandidatePtr>::const_iterator tauSignalPFCand = tauSignalPFCands.begin();
191 tauSignalPFCand != tauSignalPFCands.end(); ++tauSignalPFCand ) {
192 tauCaloEnECAL += (*tauSignalPFCand)->ecalEnergy();
193 tauCaloEnHCAL += (*tauSignalPFCand)->hcalEnergy();
195 mvaInput_[1] = TMath::Sqrt(
TMath::Max(0., tauCaloEnECAL));
196 mvaInput_[2] = TMath::Sqrt(
TMath::Max(0., tauCaloEnHCAL));
197 mvaInput_[3] = tau->leadPFChargedHadrCand()->pt()/
TMath::Max(1.,Double_t(tau->pt()));
198 mvaInput_[4] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->ecalEnergy()));
199 mvaInput_[5] = TMath::Sqrt(
TMath::Max(0., tau->leadPFChargedHadrCand()->hcalEnergy()));
201 std::vector<int> numHitsDT(4);
202 std::vector<int> numHitsCSC(4);
203 std::vector<int> numHitsRPC(4);
204 for (
int iStation = 0; iStation < 4; ++iStation ) {
205 numHitsDT[iStation] = 0;
206 numHitsCSC[iStation] = 0;
207 numHitsRPC[iStation] = 0;
209 if ( tau->leadPFChargedHadrCand().
isNonnull() ) {
210 reco::MuonRef muonRef = tau->leadPFChargedHadrCand()->muonRef();
213 countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
216 size_t numMuons = muons_->size();
217 for (
size_t idxMuon = 0; idxMuon < numMuons; ++idxMuon ) {
219 if ( tau->leadPFChargedHadrCand().
isNonnull() && tau->leadPFChargedHadrCand()->muonRef().
isNonnull() && muon == tau->leadPFChargedHadrCand()->muonRef() ) {
222 double dR =
deltaR(muon->
p4(), tau->p4());
223 if ( dR < dRmuonMatch_ ) {
225 countHits(*muon, numHitsDT, numHitsCSC, numHitsRPC);
228 mvaInput_[6] = numMatches;
229 mvaInput_[7] = numHitsDT[0] + numHitsCSC[0] + numHitsRPC[0];
230 mvaInput_[8] = numHitsDT[1] + numHitsCSC[1] + numHitsRPC[1];
231 mvaInput_[9] = numHitsDT[2] + numHitsCSC[2] + numHitsRPC[2];
232 mvaInput_[10] = numHitsDT[3] + numHitsCSC[3] + numHitsRPC[3];
234 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
236 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"mvaValue = " << mvaValue;
253 desc.
add<
double>(
"mvaMin", 0.0);
254 desc.add<
std::string>(
"mvaName",
"againstMuonMVA");
256 desc.add<
int>(
"verbosity", 0);
257 desc.add<
bool>(
"returnMVA",
true);
259 desc.add<
bool>(
"loadMVAfromDB",
true);
265 psd1.
add<
double>(
"cut");
271 desc.
add<
double>(
"dRmuonMatch", 0.3);
273 descriptions.add(
"pfRecoTauDiscriminationAgainstMuonMVA", desc);
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
edm::RefProd< TauCollection > TauRefProd
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
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
const LorentzVector & p4() const final
four-momentum Lorentz vector
LocationCode location() const
Where was the file found?
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isNull() const
Checks for null.
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static bool muonHitFilter(uint16_t pattern)
virtual double discriminate(const TauRef &tau) const =0
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)
virtual void endEvent(edm::Event &)