44 <<
" Failed to find File = " << inputFileName <<
" !!\n";
50 throw cms::Exception(
"PFRecoTauDiscriminationByIsolationMVA2::loadMVA")
51 <<
" Failed to load MVA = " << mvaName.data() <<
" from file = " << inputFileName.
fullPath().data() <<
" !!\n";
53 inputFilesToDelete.push_back(inputFile);
77 loadMVAfromDB_ = cfg.
exists(
"loadMVAfromDB") ? cfg.
getParameter<
bool>(
"loadMVAfromDB") :
false;
78 if ( !loadMVAfromDB_ ) {
79 if(cfg.
exists(
"inputFileName")){
81 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
84 if ( mvaOpt_string ==
"oldDMwoLT" ) mvaOpt_ = kOldDMwoLT;
85 else if ( mvaOpt_string ==
"oldDMwLT" ) mvaOpt_ = kOldDMwLT;
86 else if ( mvaOpt_string ==
"newDMwoLT" ) mvaOpt_ = kNewDMwoLT;
87 else if ( mvaOpt_string ==
"newDMwLT" ) mvaOpt_ = kNewDMwLT;
88 else if ( mvaOpt_string ==
"DBoldDMwLT" ) mvaOpt_ = kDBoldDMwLT;
89 else if ( mvaOpt_string ==
"DBnewDMwLT" ) mvaOpt_ = kDBnewDMwLT;
90 else if ( mvaOpt_string ==
"PWoldDMwLT" ) mvaOpt_ = kPWoldDMwLT;
91 else if ( mvaOpt_string ==
"PWnewDMwLT" ) mvaOpt_ = kPWnewDMwLT;
92 else throw cms::Exception(
"PFRecoTauDiscriminationByMVAIsolationRun2")
93 <<
" Invalid Configuration Parameter 'mvaOpt' = " << mvaOpt_string <<
" !!\n";
95 if ( mvaOpt_ == kOldDMwoLT || mvaOpt_ == kNewDMwoLT ) mvaInput_ =
new float[6];
96 else if ( mvaOpt_ == kOldDMwLT || mvaOpt_ == kNewDMwLT ) mvaInput_ =
new float[12];
97 else if ( mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kDBnewDMwLT ||
98 mvaOpt_ == kPWoldDMwLT || mvaOpt_ == kPWnewDMwLT) mvaInput_ =
new float[23];
101 TauTransverseImpactParameters_token = consumes<PFTauTIPAssociationByRef>(cfg.
getParameter<
edm::InputTag>(
"srcTauTransverseImpactParameters"));
106 PhotonPtSumOutsideSignalCone_token = consumes<reco::PFTauDiscriminator>(cfg.
getParameter<
edm::InputTag>(
"srcPhotonPtSumOutsideSignalCone"));
107 FootprintCorrection_token = consumes<reco::PFTauDiscriminator>(cfg.
getParameter<
edm::InputTag>(
"srcFootprintCorrection"));
109 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
112 produces<PFTauDiscriminator>(
"category");
117 double discriminate(
const PFTauRef&)
const;
123 if(!loadMVAfromDB_)
delete mvaReader_;
125 for ( std::vector<TFile*>::iterator it = inputFilesToDelete_.begin();
126 it != inputFilesToDelete_.end(); ++it ) {
139 enum { kOldDMwoLT, kOldDMwLT, kNewDMwoLT, kNewDMwLT, kDBoldDMwLT, kDBnewDMwLT,
kPWoldDMwLT, kPWnewDMwLT };
169 if ( loadMVAfromDB_ ) {
172 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
176 evt.
getByToken(TauTransverseImpactParameters_token, tauLifetimeInfos);
178 evt.
getByToken(ChargedIsoPtSum_token, chargedIsoPtSums_);
179 evt.
getByToken(NeutralIsoPtSum_token, neutralIsoPtSums_);
180 evt.
getByToken(PUcorrPtSum_token, puCorrPtSums_);
181 evt.
getByToken(PhotonPtSumOutsideSignalCone_token, photonPtSumOutsideSignalCone_);
182 evt.
getByToken(FootprintCorrection_token, footprintCorrection_);
192 category_output_->setValue(tauIndex_, category);
195 if ( tau->leadPFChargedHadrCand().
isNull() )
return 0.;
197 int tauDecayMode = tau->decayMode();
199 if ( ((mvaOpt_ == kOldDMwoLT || mvaOpt_ == kOldDMwLT || mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kPWoldDMwLT) && (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 10)) ||
200 ((mvaOpt_ == kNewDMwoLT || mvaOpt_ == kNewDMwLT || mvaOpt_ == kDBnewDMwLT || mvaOpt_ == kPWnewDMwLT) && (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 5 || tauDecayMode == 6 || tauDecayMode == 10)) ) {
213 double decayDistMag =
std::sqrt(decayDistX*decayDistX + decayDistY*decayDistY + decayDistZ*decayDistZ);
215 double nPhoton = double(tau_n_photons_total(*tau));
216 double ptWeightedDetaStrip = tau_pt_weighted_deta_strip(*tau, tauDecayMode);
217 double ptWeightedDphiStrip = tau_pt_weighted_dphi_strip(*tau, tauDecayMode);
218 double ptWeightedDrSignal = tau_pt_weighted_dr_signal(*tau, tauDecayMode);
219 double ptWeightedDrIsolation = tau_pt_weighted_dr_iso(*tau, tauDecayMode);
220 double leadingTrackChi2 = tau_leadTrackChi2(*tau);
221 double eRatio = tau_Eratio(*tau);
223 if ( mvaOpt_ == kOldDMwoLT || mvaOpt_ == kNewDMwoLT ) {
225 mvaInput_[1] = std::fabs(tau->eta());
229 mvaInput_[5] = tauDecayMode;
230 }
else if ( mvaOpt_ == kOldDMwLT || mvaOpt_ == kNewDMwLT ) {
232 mvaInput_[1] = std::fabs(tau->eta());
236 mvaInput_[5] = tauDecayMode;
243 }
else if ( mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kDBnewDMwLT ) {
245 mvaInput_[1] = std::fabs(tau->eta());
250 mvaInput_[6] = tauDecayMode;
251 mvaInput_[7] =
std::min(30., nPhoton);
252 mvaInput_[8] =
std::min(0.5, ptWeightedDetaStrip);
253 mvaInput_[9] =
std::min(0.5, ptWeightedDphiStrip);
254 mvaInput_[10] =
std::min(0.5, ptWeightedDrSignal);
255 mvaInput_[11] =
std::min(0.5, ptWeightedDrIsolation);
256 mvaInput_[12] =
std::min(100., leadingTrackChi2);
257 mvaInput_[13] =
std::min(1., eRatio);
267 }
else if ( mvaOpt_ == kPWoldDMwLT || mvaOpt_ == kPWnewDMwLT ) {
269 mvaInput_[1] = std::fabs(tau->eta());
274 mvaInput_[6] = tauDecayMode;
275 mvaInput_[7] =
std::min(30., nPhoton);
276 mvaInput_[8] =
std::min(0.5, ptWeightedDetaStrip);
277 mvaInput_[9] =
std::min(0.5, ptWeightedDphiStrip);
278 mvaInput_[10] =
std::min(0.5, ptWeightedDrSignal);
279 mvaInput_[11] =
std::min(0.5, ptWeightedDrIsolation);
280 mvaInput_[12] =
std::min(100., leadingTrackChi2);
281 mvaInput_[13] =
std::min(1., eRatio);
293 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
295 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
"<PFRecoTauDiscriminationByMVAIsolationRun2::discriminate>:";
296 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" tau: Pt = " << tau->pt() <<
", eta = " << tau->eta();
297 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" isolation: charged = " << chargedIsoPtSum <<
", neutral = " << neutralIsoPtSum <<
", PUcorr = " <<
puCorrPtSum;
298 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" decay mode = " << tauDecayMode;
299 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" impact parameter: distance = " << tauLifetimeInfo.
dxy() <<
", significance = " << tauLifetimeInfo.
dxy_Sig();
301 <<
" distance = " << decayDistMag <<
", significance = " << tauLifetimeInfo.
flightLengthSig();
302 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
"--> mvaValue = " << mvaValue;
313 evt.
put(category_output_,
"category");
T getParameter(std::string const &) const
bool hasSecondaryVertex() const
edm::RefProd< TauCollection > TauRefProd
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > PFTauTIPAssociationByRef
#define DEFINE_FWK_MODULE(type)
edm::EDGetTokenT< reco::PFTauDiscriminator > NeutralIsoPtSum_token
edm::Handle< PFTauTIPAssociationByRef > tauLifetimeInfos
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void endEvent(edm::Event &)
edm::Handle< reco::PFTauDiscriminator > chargedIsoPtSums_
edm::Handle< TauCollection > taus_
edm::EDGetTokenT< reco::PFTauDiscriminator > PhotonPtSumOutsideSignalCone_token
edm::Handle< reco::PFTauDiscriminator > neutralIsoPtSums_
edm::EDGetTokenT< reco::PFTauDiscriminator > FootprintCorrection_token
double flightLengthSig() const
const Vector & flightLength() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
edm::EDGetTokenT< PFTauTIPAssociationByRef > TauTransverseImpactParameters_token
std::auto_ptr< PFTauDiscriminator > category_output_
edm::FileInPath inputFileName_
bool isNull() const
Checks for null.
edm::Handle< reco::PFTauDiscriminator > puCorrPtSums_
const GBRForest * mvaReader_
LocationCode location() const
Where was the file found?
T const * product() const
edm::EDGetTokenT< reco::PFTauDiscriminator > ChargedIsoPtSum_token
edm::Handle< reco::PFTauDiscriminator > footprintCorrection_
tuple footprintCorrection
tuple photonPtSumOutsideSignalCone
double discriminate(const PFTauRef &) const
PFRecoTauDiscriminationByMVAIsolationRun2(const edm::ParameterSet &cfg)
std::string fullPath() const
edm::Handle< reco::PFTauDiscriminator > photonPtSumOutsideSignalCone_
std::vector< TFile * > inputFilesToDelete_
~PFRecoTauDiscriminationByMVAIsolationRun2()
void beginEvent(const edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< reco::PFTauDiscriminator > PUcorrPtSum_token