52 <<
" Failed to find File = " << inputFileName <<
" !!\n";
58 throw cms::Exception(
"PATTauDiscriminationByIsolationMVARun2::loadMVA")
59 <<
" Failed to load MVA = " << mvaName.data() <<
" from file = " << inputFileName.
fullPath().data() <<
" !!\n";
61 inputFilesToDelete.push_back(inputFile);
85 loadMVAfromDB_ = cfg.
exists(
"loadMVAfromDB") ? cfg.
getParameter<
bool>(
"loadMVAfromDB") :
false;
86 if ( !loadMVAfromDB_ ) {
87 if(cfg.
exists(
"inputFileName")){
89 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
92 if ( mvaOpt_string ==
"oldDMwoLT" ) mvaOpt_ = kOldDMwoLT;
93 else if ( mvaOpt_string ==
"oldDMwLT" ) mvaOpt_ = kOldDMwLT;
94 else if ( mvaOpt_string ==
"newDMwoLT" ) mvaOpt_ = kNewDMwoLT;
95 else if ( mvaOpt_string ==
"newDMwLT" ) mvaOpt_ = kNewDMwLT;
96 else if ( mvaOpt_string ==
"DBoldDMwLT" ) mvaOpt_ = kDBoldDMwLT;
97 else if ( mvaOpt_string ==
"DBnewDMwLT" ) mvaOpt_ = kDBnewDMwLT;
98 else if ( mvaOpt_string ==
"PWoldDMwLT" ) mvaOpt_ = kPWoldDMwLT;
99 else if ( mvaOpt_string ==
"PWnewDMwLT" ) mvaOpt_ = kPWnewDMwLT;
100 else throw cms::Exception(
"PATTauDiscriminationByMVAIsolationRun2")
101 <<
" Invalid Configuration Parameter 'mvaOpt' = " << mvaOpt_string <<
" !!\n";
103 if ( mvaOpt_ == kOldDMwoLT || mvaOpt_ == kNewDMwoLT ) mvaInput_ =
new float[6];
104 else if ( mvaOpt_ == kOldDMwLT || mvaOpt_ == kNewDMwLT ) mvaInput_ =
new float[12];
105 else if ( mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kDBnewDMwLT ||
106 mvaOpt_ == kPWoldDMwLT || mvaOpt_ == kPWnewDMwLT) mvaInput_ =
new float[23];
115 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
118 produces<pat::PATTauDiscriminator>(
"category");
123 double discriminate(
const TauRef&)
const;
129 if(!loadMVAfromDB_)
delete mvaReader_;
131 for ( std::vector<TFile*>::iterator it = inputFilesToDelete_.begin();
132 it != inputFilesToDelete_.end(); ++it ) {
145 enum { kOldDMwoLT, kOldDMwLT, kNewDMwoLT, kNewDMwLT, kDBoldDMwLT, kDBnewDMwLT,
kPWoldDMwLT, kPWnewDMwLT };
166 if ( loadMVAfromDB_ ) {
169 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
181 category_output_->setValue(tauIndex_, category);
184 if ( tau->leadChargedHadrCand().
isNull() )
return 0.;
186 int tauDecayMode = tau->decayMode();
188 if ( ((mvaOpt_ == kOldDMwoLT || mvaOpt_ == kOldDMwLT || mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kPWoldDMwLT) && (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 10)) ||
189 ((mvaOpt_ == kNewDMwoLT || mvaOpt_ == kNewDMwLT || mvaOpt_ == kDBnewDMwLT || mvaOpt_ == kPWnewDMwLT) && (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 5 || tauDecayMode == 6 || tauDecayMode == 10)) ) {
197 float decayDistX = tau->flightLength().x();
198 float decayDistY = tau->flightLength().y();
199 float decayDistZ = tau->flightLength().z();
200 float decayDistMag =
std::sqrt(decayDistX*decayDistX + decayDistY*decayDistY + decayDistZ*decayDistZ);
204 float nPhoton = (float)clusterVariables_.tau_n_photons_total(*tau);
205 float ptWeightedDetaStrip = clusterVariables_.tau_pt_weighted_deta_strip(*tau, tauDecayMode);
206 float ptWeightedDphiStrip = clusterVariables_.tau_pt_weighted_dphi_strip(*tau, tauDecayMode);
207 float ptWeightedDrSignal = clusterVariables_.tau_pt_weighted_dr_signal(*tau, tauDecayMode);
208 float ptWeightedDrIsolation = clusterVariables_.tau_pt_weighted_dr_iso(*tau, tauDecayMode);
210 float leadingTrackChi2 = tau->leadingTrackNormChi2();
211 float eRatio = clusterVariables_.tau_Eratio(*tau);
213 if ( mvaOpt_ == kOldDMwoLT || mvaOpt_ == kNewDMwoLT ) {
215 mvaInput_[1] = std::fabs((
float)tau->eta());
217 mvaInput_[3] =
std::log(
std::max((
float)1.
e-2, neutralIsoPtSum - (
float)0.125*puCorrPtSum));
219 mvaInput_[5] = tauDecayMode;
220 }
else if ( mvaOpt_ == kOldDMwLT || mvaOpt_ == kNewDMwLT ) {
222 mvaInput_[1] = std::fabs((
float)tau->eta());
224 mvaInput_[3] =
std::log(
std::max((
float)1.
e-2, neutralIsoPtSum - (
float)0.125*puCorrPtSum));
226 mvaInput_[5] = tauDecayMode;
227 mvaInput_[6] =
TMath::Sign((
float)+1., tau->dxy());
229 mvaInput_[8] =
std::min((
float)10., std::fabs(tau->dxy_Sig()));
230 mvaInput_[9] = ( tau->hasSecondaryVertex() ) ? 1. : 0.;
232 mvaInput_[11] =
std::min((
float)10., tau->flightLengthSig());
233 }
else if ( mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kDBnewDMwLT ) {
235 mvaInput_[1] = std::fabs(tau->eta());
240 mvaInput_[6] = tauDecayMode;
241 mvaInput_[7] =
std::min((
float)30., nPhoton);
242 mvaInput_[8] =
std::min((
float)0.5, ptWeightedDetaStrip);
243 mvaInput_[9] =
std::min((
float)0.5, ptWeightedDphiStrip);
244 mvaInput_[10] =
std::min((
float)0.5, ptWeightedDrSignal);
245 mvaInput_[11] =
std::min((
float)0.5, ptWeightedDrIsolation);
246 mvaInput_[12] =
std::min((
float)100., leadingTrackChi2);
247 mvaInput_[13] =
std::min((
float)1., eRatio);
248 mvaInput_[14] =
TMath::Sign((
float)+1., tau->dxy());
250 mvaInput_[16] =
std::min((
float)10., std::fabs(tau->dxy_Sig()));
251 mvaInput_[17] =
TMath::Sign((
float)+1., tau->ip3d());
253 mvaInput_[19] =
std::min((
float)10., std::fabs(tau->ip3d_Sig()));
254 mvaInput_[20] = ( tau->hasSecondaryVertex() ) ? 1. : 0.;
256 mvaInput_[22] =
std::min((
float)10., tau->flightLengthSig());
257 }
else if ( mvaOpt_ == kPWoldDMwLT || mvaOpt_ == kPWnewDMwLT ) {
259 mvaInput_[1] = std::fabs(tau->eta());
264 mvaInput_[6] = tauDecayMode;
265 mvaInput_[7] =
std::min((
float)30., nPhoton);
266 mvaInput_[8] =
std::min((
float)0.5, ptWeightedDetaStrip);
267 mvaInput_[9] =
std::min((
float)0.5, ptWeightedDphiStrip);
268 mvaInput_[10] =
std::min((
float)0.5, ptWeightedDrSignal);
269 mvaInput_[11] =
std::min((
float)0.5, ptWeightedDrIsolation);
270 mvaInput_[12] =
std::min((
float)100., leadingTrackChi2);
271 mvaInput_[13] =
std::min((
float)1., eRatio);
272 mvaInput_[14] =
TMath::Sign((
float)+1., tau->dxy());
273 mvaInput_[15] =
std::sqrt(std::fabs(
std::min((
float)1., std::fabs(tau->dxy()))));
274 mvaInput_[16] =
std::min((
float)10., std::fabs(tau->dxy_Sig()));
275 mvaInput_[17] =
TMath::Sign((
float)+1., tau->ip3d());
276 mvaInput_[18] =
std::sqrt(std::fabs(
std::min((
float)1., std::fabs(tau->ip3d()))));
277 mvaInput_[19] =
std::min((
float)10., std::fabs(tau->ip3d_Sig()));
278 mvaInput_[20] = ( tau->hasSecondaryVertex() ) ? 1. : 0.;
280 mvaInput_[22] =
std::min((
float)10., tau->flightLengthSig());
283 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
285 edm::LogPrint(
"PATTauDiscByMVAIsolRun2") <<
"<PATTauDiscriminationByMVAIsolationRun2::discriminate>:";
286 edm::LogPrint(
"PATTauDiscByMVAIsolRun2") <<
" tau: Pt = " << tau->pt() <<
", eta = " << tau->eta();
287 edm::LogPrint(
"PATTauDiscByMVAIsolRun2") <<
" isolation: charged = " << chargedIsoPtSum <<
", neutral = " << neutralIsoPtSum <<
", PUcorr = " <<
puCorrPtSum;
288 edm::LogPrint(
"PATTauDiscByMVAIsolRun2") <<
" decay mode = " << tauDecayMode;
289 edm::LogPrint(
"PATTauDiscByMVAIsolRun2") <<
" impact parameter: distance = " << tau->dxy() <<
", significance = " << tau->dxy_Sig();
290 edm::LogPrint(
"PATTauDiscByMVAIsolRun2") <<
" has decay vertex = " << tau->hasSecondaryVertex() <<
":"
291 <<
" distance = " << decayDistMag <<
", significance = " << tau->flightLengthSig();
292 edm::LogPrint(
"PATTauDiscByMVAIsolRun2") <<
"--> mvaValue = " << mvaValue;
T getParameter(std::string const &) const
std::string footprintCorrection_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::string photonPtSumOutsideSignalCone_
edm::RefProd< TauCollection > TauRefProd
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
edm::FileInPath inputFileName_
PATTauDiscriminationByMVAIsolationRun2(const edm::ParameterSet &cfg)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
~PATTauDiscriminationByMVAIsolationRun2()
void endEvent(edm::Event &)
void beginEvent(const edm::Event &, const edm::EventSetup &)
TauIdMVAAuxiliaries clusterVariables_
const GBRForest * mvaReader_
bool isNull() const
Checks for null.
LocationCode location() const
Where was the file found?
std::unique_ptr< pat::PATTauDiscriminator > category_output_
T const * product() const
std::string neutralIsoPtSums_
double discriminate(const TauRef &) const
tuple footprintCorrection
tuple photonPtSumOutsideSignalCone
std::vector< TFile * > inputFilesToDelete_
std::string chargedIsoPtSums_
std::string fullPath() const
edm::Handle< TauCollection > taus_
std::string puCorrPtSums_