43 <<
" Failed to find File = " << inputFileName <<
" !!\n";
49 throw cms::Exception(
"PFRecoTauDiscriminationByIsolationMVA2::loadMVA")
50 <<
" Failed to load MVA = " << mvaName.data() <<
" from file = " << inputFileName.
fullPath().data() <<
" !!\n";
52 inputFilesToDelete.push_back(inputFile);
70 moduleLabel_(cfg.getParameter<
std::
string>(
"@module_label")),
76 loadMVAfromDB_ = cfg.
exists(
"loadMVAfromDB") ? cfg.
getParameter<
bool>(
"loadMVAfromDB") :
false;
77 if ( !loadMVAfromDB_ ) {
78 if(cfg.
exists(
"inputFileName")){
80 }
else throw cms::Exception(
"MVA input not defined") <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
83 if ( mvaOpt_string ==
"oldDMwoLT" ) mvaOpt_ = kOldDMwoLT;
84 else if ( mvaOpt_string ==
"oldDMwLT" ) mvaOpt_ = kOldDMwLT;
85 else if ( mvaOpt_string ==
"newDMwoLT" ) mvaOpt_ = kNewDMwoLT;
86 else if ( mvaOpt_string ==
"newDMwLT" ) mvaOpt_ = kNewDMwLT;
87 else if ( mvaOpt_string ==
"DBoldDMwLT" ) mvaOpt_ = kDBoldDMwLT;
88 else if ( mvaOpt_string ==
"DBnewDMwLT" ) mvaOpt_ = kDBnewDMwLT;
89 else if ( mvaOpt_string ==
"PWoldDMwLT" ) mvaOpt_ = kPWoldDMwLT;
90 else if ( mvaOpt_string ==
"PWnewDMwLT" ) mvaOpt_ = kPWnewDMwLT;
91 else if ( mvaOpt_string ==
"DBoldDMwLTwGJ" ) mvaOpt_ = kDBoldDMwLTwGJ;
92 else if ( mvaOpt_string ==
"DBnewDMwLTwGJ" ) mvaOpt_ = kDBnewDMwLTwGJ;
93 else throw cms::Exception(
"PFRecoTauDiscriminationByMVAIsolationRun2")
94 <<
" Invalid Configuration Parameter 'mvaOpt' = " << mvaOpt_string <<
" !!\n";
96 if ( mvaOpt_ == kOldDMwoLT || mvaOpt_ == kNewDMwoLT ) mvaInput_ =
new float[6];
97 else if ( mvaOpt_ == kOldDMwLT || mvaOpt_ == kNewDMwLT ) mvaInput_ =
new float[12];
98 else if ( mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kDBnewDMwLT ||
99 mvaOpt_ == kPWoldDMwLT || mvaOpt_ == kPWnewDMwLT ||
100 mvaOpt_ == kDBoldDMwLTwGJ || mvaOpt_ == kDBnewDMwLTwGJ) mvaInput_ =
new float[23];
103 TauTransverseImpactParameters_token = consumes<PFTauTIPAssociationByRef>(cfg.
getParameter<
edm::InputTag>(
"srcTauTransverseImpactParameters"));
108 PhotonPtSumOutsideSignalCone_token = consumes<reco::PFTauDiscriminator>(cfg.
getParameter<
edm::InputTag>(
"srcPhotonPtSumOutsideSignalCone"));
109 FootprintCorrection_token = consumes<reco::PFTauDiscriminator>(cfg.
getParameter<
edm::InputTag>(
"srcFootprintCorrection"));
111 verbosity_ = ( cfg.
exists(
"verbosity") ) ?
114 produces<PFTauDiscriminator>(
"category");
119 double discriminate(
const PFTauRef&)
const;
125 if(!loadMVAfromDB_)
delete mvaReader_;
127 for ( std::vector<TFile*>::iterator it = inputFilesToDelete_.begin();
128 it != inputFilesToDelete_.end(); ++it ) {
141 enum { kOldDMwoLT, kOldDMwLT, kNewDMwoLT, kNewDMwLT, kDBoldDMwLT, kDBnewDMwLT,
kPWoldDMwLT, kPWnewDMwLT, kDBoldDMwLTwGJ, kDBnewDMwLTwGJ };
172 if ( loadMVAfromDB_ ) {
175 mvaReader_ = loadMVAfromFile(inputFileName_, mvaName_, inputFilesToDelete_);
179 evt.
getByToken(TauTransverseImpactParameters_token, tauLifetimeInfos);
181 evt.
getByToken(ChargedIsoPtSum_token, chargedIsoPtSums_);
182 evt.
getByToken(NeutralIsoPtSum_token, neutralIsoPtSums_);
183 evt.
getByToken(PUcorrPtSum_token, puCorrPtSums_);
184 evt.
getByToken(PhotonPtSumOutsideSignalCone_token, photonPtSumOutsideSignalCone_);
185 evt.
getByToken(FootprintCorrection_token, footprintCorrection_);
195 category_output_->setValue(tauIndex_, category);
198 if ( tau->leadPFChargedHadrCand().
isNull() )
return 0.;
200 int tauDecayMode = tau->decayMode();
202 if ( ((mvaOpt_ == kOldDMwoLT || mvaOpt_ == kOldDMwLT || mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kPWoldDMwLT || mvaOpt_ == kDBoldDMwLTwGJ)
203 && (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 10))
205 ((mvaOpt_ == kNewDMwoLT || mvaOpt_ == kNewDMwLT || mvaOpt_ == kDBnewDMwLT || mvaOpt_ == kPWnewDMwLT || mvaOpt_ == kDBnewDMwLTwGJ)
206 && (tauDecayMode == 0 || tauDecayMode == 1 || tauDecayMode == 2 || tauDecayMode == 5 || tauDecayMode == 6 || tauDecayMode == 10 || tauDecayMode == 11))
220 float decayDistMag =
std::sqrt(decayDistX*decayDistX + decayDistY*decayDistY + decayDistZ*decayDistZ);
222 float nPhoton = (
float)clusterVariables_.tau_n_photons_total(*tau);
223 float ptWeightedDetaStrip = clusterVariables_.tau_pt_weighted_deta_strip(*tau, tauDecayMode);
224 float ptWeightedDphiStrip = clusterVariables_.tau_pt_weighted_dphi_strip(*tau, tauDecayMode);
225 float ptWeightedDrSignal = clusterVariables_.tau_pt_weighted_dr_signal(*tau, tauDecayMode);
226 float ptWeightedDrIsolation = clusterVariables_.tau_pt_weighted_dr_iso(*tau, tauDecayMode);
227 float leadingTrackChi2 = clusterVariables_.tau_leadTrackChi2(*tau);
228 float eRatio = clusterVariables_.tau_Eratio(*tau);
231 float gjAngleDiff = -999;
232 if ( tauDecayMode == 10 ) {
233 double mTau = 1.77682;
234 double mAOne = tau->p4().M();
235 double pAOneMag = tau->p();
236 double argumentThetaGJmax = (
std::pow(mTau,2) -
std::pow(mAOne,2) ) / ( 2 * mTau * pAOneMag );
237 double argumentThetaGJmeasured = ( tau->p4().px() * decayDistX + tau->p4().py() * decayDistY + tau->p4().pz() * decayDistZ ) / ( pAOneMag * decayDistMag );
238 if (
std::abs(argumentThetaGJmax) <= 1. &&
std::abs(argumentThetaGJmeasured) <= 1. ) {
239 double thetaGJmax = std::asin( argumentThetaGJmax );
240 double thetaGJmeasured = std::acos( argumentThetaGJmeasured );
241 gjAngleDiff = thetaGJmeasured - thetaGJmax;
245 if ( mvaOpt_ == kOldDMwoLT || mvaOpt_ == kNewDMwoLT ) {
247 mvaInput_[1] =
std::abs((
float)tau->eta());
251 mvaInput_[5] = tauDecayMode;
252 }
else if ( mvaOpt_ == kOldDMwLT || mvaOpt_ == kNewDMwLT ) {
254 mvaInput_[1] =
std::abs((
float)tau->eta());
258 mvaInput_[5] = tauDecayMode;
259 mvaInput_[6] = std::copysign(+1.
f, (
float)tauLifetimeInfo.
dxy());
265 }
else if ( mvaOpt_ == kDBoldDMwLT || mvaOpt_ == kDBnewDMwLT ) {
267 mvaInput_[1] =
std::abs((
float)tau->eta());
272 mvaInput_[6] = tauDecayMode;
274 mvaInput_[8] =
std::min(0.5
f, ptWeightedDetaStrip);
275 mvaInput_[9] =
std::min(0.5
f, ptWeightedDphiStrip);
276 mvaInput_[10] =
std::min(0.5
f, ptWeightedDrSignal);
277 mvaInput_[11] =
std::min(0.5
f, ptWeightedDrIsolation);
278 mvaInput_[12] =
std::min(100.
f, leadingTrackChi2);
280 mvaInput_[14] = std::copysign(+1.
f, (
float)tauLifetimeInfo.
dxy());
283 mvaInput_[17] = std::copysign(+1.
f, (
float)tauLifetimeInfo.
ip3d());
289 }
else if ( mvaOpt_ == kPWoldDMwLT || mvaOpt_ == kPWnewDMwLT ) {
291 mvaInput_[1] =
std::abs((
float)tau->eta());
296 mvaInput_[6] = tauDecayMode;
298 mvaInput_[8] =
std::min(0.5
f, ptWeightedDetaStrip);
299 mvaInput_[9] =
std::min(0.5
f, ptWeightedDphiStrip);
300 mvaInput_[10] =
std::min(0.5
f, ptWeightedDrSignal);
301 mvaInput_[11] =
std::min(0.5
f, ptWeightedDrIsolation);
302 mvaInput_[12] =
std::min(100.
f, leadingTrackChi2);
304 mvaInput_[14] = std::copysign(+1.
f, (
float)tauLifetimeInfo.
dxy());
307 mvaInput_[17] = std::copysign(+1.
f, (
float)tauLifetimeInfo.
ip3d());
313 }
else if ( mvaOpt_ == kDBoldDMwLTwGJ || mvaOpt_ == kDBnewDMwLTwGJ ) {
315 mvaInput_[1] =
std::abs((
float)tau->eta());
320 mvaInput_[6] = tauDecayMode;
322 mvaInput_[8] =
std::min(0.5
f, ptWeightedDetaStrip);
323 mvaInput_[9] =
std::min(0.5
f, ptWeightedDphiStrip);
324 mvaInput_[10] =
std::min(0.5
f, ptWeightedDrSignal);
325 mvaInput_[11] =
std::min(0.5
f, ptWeightedDrIsolation);
327 mvaInput_[13] = std::copysign(+1.
f, (
float)tauLifetimeInfo.
dxy());
330 mvaInput_[16] = std::copysign(+1.
f, (
float)tauLifetimeInfo.
ip3d());
336 mvaInput_[22] =
std::max(-1.
f, gjAngleDiff);
339 double mvaValue = mvaReader_->GetClassifier(mvaInput_);
341 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
"<PFRecoTauDiscriminationByMVAIsolationRun2::discriminate>:";
342 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" tau: Pt = " << tau->pt() <<
", eta = " << tau->eta();
343 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" isolation: charged = " << chargedIsoPtSum <<
", neutral = " << neutralIsoPtSum <<
", PUcorr = " <<
puCorrPtSum;
344 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" decay mode = " << tauDecayMode;
345 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
" impact parameter: distance = " << tauLifetimeInfo.
dxy() <<
", significance = " << tauLifetimeInfo.
dxy_Sig();
347 <<
" distance = " << decayDistMag <<
", significance = " << tauLifetimeInfo.
flightLengthSig();
348 edm::LogPrint(
"PFTauDiscByMVAIsol2") <<
"--> mvaValue = " << mvaValue;
T getParameter(std::string const &) const
bool hasSecondaryVertex() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
edm::RefProd< TauCollection > TauRefProd
TauIdMVAAuxiliaries clusterVariables_
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
edm::EDGetTokenT< PFTauTIPAssociationByRef > TauTransverseImpactParameters_token
Abs< T >::type abs(const T &t)
edm::FileInPath inputFileName_
LocationCode location() const
Where was the file found?
bool isNull() const
Checks for null.
photonPtSumOutsideSignalCone
edm::Handle< reco::PFTauDiscriminator > puCorrPtSums_
const GBRForest * mvaReader_
edm::EDGetTokenT< reco::PFTauDiscriminator > ChargedIsoPtSum_token
edm::Handle< reco::PFTauDiscriminator > footprintCorrection_
double discriminate(const PFTauRef &) const
std::string fullPath() const
PFRecoTauDiscriminationByMVAIsolationRun2(const edm::ParameterSet &cfg)
edm::Handle< reco::PFTauDiscriminator > photonPtSumOutsideSignalCone_
std::unique_ptr< PFTauDiscriminator > category_output_
T const * product() const
std::vector< TFile * > inputFilesToDelete_
Power< A, B >::type pow(const A &a, const B &b)
~PFRecoTauDiscriminationByMVAIsolationRun2()
void beginEvent(const edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< reco::PFTauDiscriminator > PUcorrPtSum_token