43 std::vector<TFile*>& inputFilesToDelete) {
45 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
52 throw cms::Exception(
"PFRecoTauDiscriminationAgainstMuonMVA::loadMVA")
53 <<
" Failed to load MVA = " <<
mvaName.data() <<
" from file = " <<
inputFileName.fullPath().data()
65 moduleLabel_(
cfg.getParameter<
std::
string>(
"@module_label")),
69 loadMVAfromDB_ =
cfg.getParameter<
bool>(
"loadMVAfromDB");
70 if (!loadMVAfromDB_) {
75 mvaInput_ =
new float[11];
78 Muons_token = consumes<reco::MuonCollection>(srcMuons_);
79 dRmuonMatch_ =
cfg.getParameter<
double>(
"dRmuonMatch");
81 verbosity_ =
cfg.getParameter<
int>(
"verbosity");
92 for (std::vector<TFile*>::iterator it = inputFilesToDelete_.begin(); it != inputFilesToDelete_.end(); ++it) {
116 std::vector<TFile*> inputFilesToDelete_;
123 if (loadMVAfromDB_) {
124 mvaReader_ = &es.
getData(mvaToken_);
126 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
137 std::vector<int>& numHitsDT,
138 std::vector<int>& numHitsCSC,
139 std::vector<int>& numHitsRPC) {
140 if (
muon.outerTrack().isNonnull()) {
149 if (muonStation >= 0 && muonStation < 4) {
151 ++numHitsDT[muonStation];
153 ++numHitsCSC[muonStation];
155 ++numHitsRPC[muonStation];
165 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
"<PFRecoTauDiscriminationAgainstMuonMVA::discriminate>:";
166 edm::LogPrint(
"PFTauAgainstMuonMVA") <<
" moduleLabel = " << moduleLabel_;
171 result.rawValues = {-1., 0.};
174 if (
tau->leadPFChargedHadrCand().isNull())
177 mvaInput_[0] = TMath::Abs(
tau->eta());
178 double tauCaloEnECAL = 0.;
179 double tauCaloEnHCAL = 0.;
180 const std::vector<reco::PFCandidatePtr>& tauSignalPFCands =
tau->signalPFCands();
181 for (std::vector<reco::PFCandidatePtr>::const_iterator tauSignalPFCand = tauSignalPFCands.begin();
182 tauSignalPFCand != tauSignalPFCands.end();
184 tauCaloEnECAL += (*tauSignalPFCand)->ecalEnergy();
185 tauCaloEnHCAL += (*tauSignalPFCand)->hcalEnergy();
187 mvaInput_[1] = TMath::Sqrt(
TMath::Max(0., tauCaloEnECAL));
188 mvaInput_[2] = TMath::Sqrt(
TMath::Max(0., tauCaloEnHCAL));
189 mvaInput_[3] =
tau->leadPFChargedHadrCand()->pt() /
TMath::Max(1., Double_t(
tau->pt()));
190 mvaInput_[4] = TMath::Sqrt(
TMath::Max(0.,
tau->leadPFChargedHadrCand()->ecalEnergy()));
191 mvaInput_[5] = TMath::Sqrt(
TMath::Max(0.,
tau->leadPFChargedHadrCand()->hcalEnergy()));
193 std::vector<int> numHitsDT(4);
194 std::vector<int> numHitsCSC(4);
195 std::vector<int> numHitsRPC(4);
196 for (
int iStation = 0; iStation < 4; ++iStation) {
197 numHitsDT[iStation] = 0;
198 numHitsCSC[iStation] = 0;
199 numHitsRPC[iStation] = 0;
201 if (
tau->leadPFChargedHadrCand().isNonnull()) {
205 countHits(*muonRef, numHitsDT, numHitsCSC, numHitsRPC);
209 for (
size_t idxMuon = 0; idxMuon <
numMuons; ++idxMuon) {
211 if (
tau->leadPFChargedHadrCand().isNonnull() &&
tau->leadPFChargedHadrCand()->muonRef().isNonnull() &&
212 muon ==
tau->leadPFChargedHadrCand()->muonRef()) {
216 if (
dR < dRmuonMatch_) {
221 mvaInput_[6] = numMatches;
222 mvaInput_[7] = numHitsDT[0] + numHitsCSC[0] + numHitsRPC[0];
223 mvaInput_[8] = numHitsDT[1] + numHitsCSC[1] + numHitsRPC[1];
224 mvaInput_[9] = numHitsDT[2] + numHitsCSC[2] + numHitsRPC[2];
225 mvaInput_[10] = numHitsDT[3] + numHitsCSC[3] + numHitsRPC[3];
227 result.rawValues.at(0) = mvaReader_->GetClassifier(mvaInput_);
231 return result.rawValues.at(0);
238 desc.add<
double>(
"mvaMin", 0.0);
241 desc.add<
int>(
"verbosity", 0);
242 desc.add<
bool>(
"returnMVA",
true);
244 desc.add<
bool>(
"loadMVAfromDB",
true);
250 psd1.
add<
double>(
"cut");
256 desc.add<
double>(
"dRmuonMatch", 0.3);
258 descriptions.add(
"pfRecoTauDiscriminationAgainstMuonMVA",
desc);
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
int numberOfAllHits(HitCategory category) const
bool isNonnull() const
Checks for non-null.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual TauDiscriminatorDataType discriminate(const TauRef &tau) const =0
static bool muonCSCHitFilter(uint16_t pattern)
static uint32_t getHitType(uint16_t pattern)
virtual void beginEvent(const edm::Event &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
bool getData(T &iHolder) const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Warning, true > LogPrint
uint16_t getHitPattern(HitCategory category, int position) const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static bool muonHitFilter(uint16_t pattern)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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...
static bool muonRPCHitFilter(uint16_t pattern)
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)