43 std::vector<TFile*>& inputFilesToDelete) {
45 throw cms::Exception(
"PFRecoTauDiscriminationByIsolationMVA2::loadMVA")
52 throw cms::Exception(
"PFRecoTauDiscriminationByIsolationMVA2::loadMVA")
53 <<
" Failed to load MVA = " <<
mvaName.data() <<
" from file = " <<
inputFileName.fullPath().data()
66 moduleLabel_(
cfg.getParameter<
std::
string>(
"@module_label")),
70 loadMVAfromDB_ =
cfg.getParameter<
bool>(
"loadMVAfromDB");
71 if (!loadMVAfromDB_) {
77 if (mvaOpt_string ==
"oldDMwoLT")
79 else if (mvaOpt_string ==
"oldDMwLT")
81 else if (mvaOpt_string ==
"newDMwoLT")
83 else if (mvaOpt_string ==
"newDMwLT")
87 <<
" Invalid Configuration Parameter 'mvaOpt' = " << mvaOpt_string <<
" !!\n";
90 mvaInput_ =
new float[6];
92 mvaInput_ =
new float[12];
96 tauTransverseImpactParameters_token_ =
97 consumes<PFTauTIPAssociationByRef>(
cfg.getParameter<
edm::InputTag>(
"srcTauTransverseImpactParameters"));
99 basicTauDiscriminators_token_ =
100 consumes<reco::TauDiscriminatorContainer>(
cfg.getParameter<
edm::InputTag>(
"srcBasicTauDiscriminators"));
101 chargedIsoPtSum_index_ =
cfg.getParameter<
int>(
"srcChargedIsoPtSumIndex");
102 neutralIsoPtSum_index_ =
cfg.getParameter<
int>(
"srcNeutralIsoPtSumIndex");
103 pucorrPtSum_index_ =
cfg.getParameter<
int>(
"srcPUcorrPtSumIndex");
105 verbosity_ =
cfg.getParameter<
int>(
"verbosity");
116 for (std::vector<TFile*>::iterator
it = inputFilesToDelete_.begin();
it != inputFilesToDelete_.end(); ++
it) {
155 if (loadMVAfromDB_) {
156 mvaReader_ = &es.
getData(mvaToken_);
158 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
162 evt.
getByToken(tauTransverseImpactParameters_token_, tauLifetimeInfos_);
164 evt.
getByToken(basicTauDiscriminators_token_, basicTauDiscriminators_);
172 result.rawValues = {-1., 0.};
175 if (
tau->leadChargedHadrCand().isNull())
178 int tauDecayMode =
tau->decayMode();
181 (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 10)) ||
183 (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 5 || tauDecayMode == 6 ||
184 tauDecayMode == 10))) {
185 double chargedIsoPtSum = (*basicTauDiscriminators_)[
tau].rawValues.at(chargedIsoPtSum_index_);
186 double neutralIsoPtSum = (*basicTauDiscriminators_)[
tau].rawValues.at(neutralIsoPtSum_index_);
187 double puCorrPtSum = (*basicTauDiscriminators_)[
tau].rawValues.at(pucorrPtSum_index_);
194 double decayDistMag = TMath::Sqrt(decayDistX * decayDistX + decayDistY * decayDistY + decayDistZ * decayDistZ);
197 mvaInput_[0] = TMath::Log(
TMath::Max(1., Double_t(
tau->pt())));
198 mvaInput_[1] = TMath::Abs(
tau->eta());
199 mvaInput_[2] = TMath::Log(
TMath::Max(1.
e-2, chargedIsoPtSum));
200 mvaInput_[3] = TMath::Log(
TMath::Max(1.
e-2, neutralIsoPtSum - 0.125 * puCorrPtSum));
201 mvaInput_[4] = TMath::Log(
TMath::Max(1.
e-2, puCorrPtSum));
202 mvaInput_[5] = tauDecayMode;
204 mvaInput_[0] = TMath::Log(
TMath::Max(1., Double_t(
tau->pt())));
205 mvaInput_[1] = TMath::Abs(
tau->eta());
206 mvaInput_[2] = TMath::Log(
TMath::Max(1.
e-2, chargedIsoPtSum));
207 mvaInput_[3] = TMath::Log(
TMath::Max(1.
e-2, neutralIsoPtSum - 0.125 * puCorrPtSum));
208 mvaInput_[4] = TMath::Log(
TMath::Max(1.
e-2, puCorrPtSum));
209 mvaInput_[5] = tauDecayMode;
210 mvaInput_[6] = TMath::Sign(+1., tauLifetimeInfo.
dxy());
211 mvaInput_[7] = TMath::Sqrt(TMath::Abs(
TMath::Min(1., tauLifetimeInfo.
dxy())));
214 mvaInput_[10] = TMath::Sqrt(decayDistMag);
218 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
220 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
"<PFRecoTauDiscriminationByIsolationMVA2::discriminate>:";
221 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" tau: Pt = " <<
tau->pt() <<
", eta = " <<
tau->eta();
222 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" isolation: charged = " << chargedIsoPtSum
223 <<
", neutral = " << neutralIsoPtSum <<
", PUcorr = " << puCorrPtSum;
224 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" decay mode = " << tauDecayMode;
225 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" impact parameter: distance = " << tauLifetimeInfo.
dxy()
226 <<
", significance = " << tauLifetimeInfo.
dxy_Sig();
229 <<
" distance = " << decayDistMag <<
", significance = " << tauLifetimeInfo.
flightLengthSig();
230 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
"--> mvaValue = " << mvaValue;
232 result.rawValues.at(0) = mvaValue;
242 desc.add<
bool>(
"loadMVAfromDB");
248 desc.add<
int>(
"srcChargedIsoPtSumIndex");
249 desc.add<
int>(
"srcNeutralIsoPtSumIndex");
250 desc.add<
int>(
"srcPUcorrPtSumIndex");
251 desc.add<
int>(
"verbosity", 0);
253 fillProducerDescriptions(
desc);
255 descriptions.
add(
"pfRecoTauDiscriminationByIsolationMVA2",
desc);
int neutralIsoPtSum_index_
int chargedIsoPtSum_index_
void beginEvent(const edm::Event &, const edm::EventSetup &) override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const Vector & flightLength() const
bool hasSecondaryVertex() const
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_
edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > PFTauTIPAssociationByRef
edm::Handle< PFTauTIPAssociationByRef > tauLifetimeInfos_
double flightLengthSig() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< PFTauTIPAssociationByRef > tauTransverseImpactParameters_token_
edm::Handle< TauCollection > taus_
const GBRForest * mvaReader_
PFRecoTauDiscriminationByIsolationMVA2(const edm::ParameterSet &cfg)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::Handle< reco::TauDiscriminatorContainer > basicTauDiscriminators_
std::vector< TFile * > inputFilesToDelete_
#define DEFINE_FWK_MODULE(type)
Log< level::Warning, true > LogPrint
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::FileInPath inputFileName_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_token_
~PFRecoTauDiscriminationByIsolationMVA2() override
reco::SingleTauDiscriminatorContainer discriminate(const PFTauRef &) const override