16 using namespace antiElecIDMVA6_blocks;
24 track = pfCandidate->
muonRef()->innerTrack().
get();
26 track = pfCandidate->
muonRef()->globalTrack().
get();
28 track = pfCandidate->
muonRef()->outerTrack().
get();
35 template <
class TauType,
class ElectronType>
37 : isInitialized_(
false),
38 mva_NoEleMatch_woGwoGSF_BL_(nullptr),
39 mva_NoEleMatch_wGwoGSF_BL_(nullptr),
40 mva_woGwGSF_BL_(nullptr),
41 mva_wGwGSF_BL_(nullptr),
42 mva_NoEleMatch_woGwoGSF_EC_(nullptr),
43 mva_NoEleMatch_wGwoGSF_EC_(nullptr),
44 mva_woGwGSF_EC_(nullptr),
45 mva_wGwGSF_EC_(nullptr),
46 mva_NoEleMatch_woGwoGSF_VFEC_(nullptr),
47 mva_NoEleMatch_wGwoGSF_VFEC_(nullptr),
48 mva_woGwGSF_VFEC_(nullptr),
49 mva_wGwGSF_VFEC_(nullptr),
50 isPhase2_(cfg.getParameter<bool>(
"isPhase2")),
52 verbosity_(cfg.getParameter<int>(
"verbosity")) {
55 if (cfg.
exists(
"inputFileName")) {
59 <<
"Requested to load tau MVA input from ROOT file but no file provided in cfg file";
129 template <
class TauType,
class ElectronType>
131 if (!loadMVAfromDB_) {
132 delete mva_NoEleMatch_woGwoGSF_BL_;
133 delete mva_NoEleMatch_wGwoGSF_BL_;
134 delete mva_woGwGSF_BL_;
135 delete mva_wGwGSF_BL_;
136 delete mva_NoEleMatch_woGwoGSF_EC_;
137 delete mva_NoEleMatch_wGwoGSF_EC_;
138 delete mva_woGwGSF_EC_;
139 delete mva_wGwGSF_EC_;
141 delete mva_NoEleMatch_woGwoGSF_VFEC_;
142 delete mva_NoEleMatch_wGwoGSF_VFEC_;
143 delete mva_woGwGSF_VFEC_;
144 delete mva_wGwGSF_VFEC_;
148 for (std::vector<TFile*>::iterator it = inputFilesToDelete_.begin(); it != inputFilesToDelete_.end(); ++it) {
157 throw cms::Exception(
"PFRecoTauDiscriminationAgainstElectronMVA6::loadMVA")
158 <<
" Failed to load MVA = " << mvaName.data() <<
" from file "
165 template <
class TauType,
class ElectronType>
167 if (!isInitialized_) {
168 if (loadMVAfromDB_) {
169 mva_NoEleMatch_woGwoGSF_BL_ = &es.
getData(mvaToken_NoEleMatch_woGwoGSF_BL_);
170 mva_NoEleMatch_wGwoGSF_BL_ = &es.
getData(mvaToken_NoEleMatch_wGwoGSF_BL_);
171 mva_woGwGSF_BL_ = &es.
getData(mvaToken_woGwGSF_BL_);
172 mva_wGwGSF_BL_ = &es.
getData(mvaToken_wGwGSF_BL_);
173 mva_NoEleMatch_woGwoGSF_EC_ = &es.
getData(mvaToken_NoEleMatch_woGwoGSF_EC_);
174 mva_NoEleMatch_wGwoGSF_EC_ = &es.
getData(mvaToken_NoEleMatch_wGwoGSF_EC_);
175 mva_woGwGSF_EC_ = &es.
getData(mvaToken_woGwGSF_EC_);
176 mva_wGwGSF_EC_ = &es.
getData(mvaToken_wGwGSF_EC_);
178 mva_NoEleMatch_woGwoGSF_VFEC_ = &es.
getData(mvaToken_NoEleMatch_woGwoGSF_VFEC_);
179 mva_NoEleMatch_wGwoGSF_VFEC_ = &es.
getData(mvaToken_NoEleMatch_wGwoGSF_VFEC_);
180 mva_woGwGSF_VFEC_ = &es.
getData(mvaToken_woGwGSF_VFEC_);
181 mva_wGwGSF_VFEC_ = &es.
getData(mvaToken_wGwGSF_VFEC_);
185 throw cms::Exception(
"PFRecoTauDiscriminationAgainstElectronMVA6::loadMVA")
186 <<
" Failed to find File = " << inputFileName_ <<
" !!\n";
187 TFile* inputFile =
new TFile(inputFileName_.fullPath().data());
189 mva_NoEleMatch_woGwoGSF_BL_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_woGwoGSF_BL_);
190 mva_NoEleMatch_wGwoGSF_BL_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_wGwoGSF_BL_);
191 mva_woGwGSF_BL_ = loadMVAfromFile(inputFile, mvaName_woGwGSF_BL_);
192 mva_wGwGSF_BL_ = loadMVAfromFile(inputFile, mvaName_wGwGSF_BL_);
193 mva_NoEleMatch_woGwoGSF_EC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_woGwoGSF_EC_);
194 mva_NoEleMatch_wGwoGSF_EC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_wGwoGSF_EC_);
195 mva_woGwGSF_EC_ = loadMVAfromFile(inputFile, mvaName_woGwGSF_EC_);
196 mva_wGwGSF_EC_ = loadMVAfromFile(inputFile, mvaName_wGwGSF_EC_);
198 mva_NoEleMatch_woGwoGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_woGwoGSF_VFEC_);
199 mva_NoEleMatch_wGwoGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_NoEleMatch_wGwoGSF_VFEC_);
200 mva_woGwGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_woGwGSF_VFEC_);
201 mva_wGwGSF_VFEC_ = loadMVAfromFile(inputFile, mvaName_wGwGSF_VFEC_);
203 inputFilesToDelete_.push_back(inputFile);
205 isInitialized_ =
true;
207 positionAtECalEntrance_.beginEvent(es);
210 for (
const auto& eId_token : electronIds_tokens_) {
211 electronIds_[eId_token.first] = evt.
getHandle(eId_token.second);
216 template <
class TauType,
class ElectronType>
234 dEta2 += (pt_i * eta_i * eta_i);
235 dPhi2 += (pt_i * phi_i * phi_i);
239 if (tauVars.
pt > 0.) {
262 dEta2 += (pt_i * eta_i * eta_i);
263 dPhi2 += (pt_i * phi_i * phi_i);
267 if (tauVars.
pt > 0.) {
278 return mvaValue(tauVars, tauGammaMoms, elecVars);
280 return mvaValuePhase2(tauVars, tauGammaMoms, elecVars);
284 template <
class TauType,
class ElectronType>
288 if (!isInitialized_) {
289 throw cms::Exception(
"ClassNotInitialized") <<
" AntiElectronMVA6 not properly initialized !!\n";
292 double mvaValue = -99.;
294 float elecDeltaPinPoutOverPin = (elecVars.
pIn > 0.0) ? (
std::abs(elecVars.
pIn - elecVars.
pOut) / elecVars.
pIn) : 1.0;
295 float elecEecalOverPout = (elecVars.
pOut > 0.0) ? (elecVars.
eEcal / elecVars.
pOut) : 20.0;
296 float elecNumHitsDiffOverSum =
308 var_NoEleMatch_woGwoGSF_Barrel_[4] = tauVars.
emFraction;
311 var_NoEleMatch_woGwoGSF_Barrel_[7] = tauVars.
visMassIn;
312 var_NoEleMatch_woGwoGSF_Barrel_[8] = tauVars.
dCrackEta;
313 var_NoEleMatch_woGwoGSF_Barrel_[9] = tauVars.
dCrackPhi;
314 mvaValue = mva_NoEleMatch_woGwoGSF_BL_->GetClassifier(var_NoEleMatch_woGwoGSF_Barrel_.data());
320 var_NoEleMatch_woGwoGSF_Endcap_[4] = tauVars.
emFraction;
323 var_NoEleMatch_woGwoGSF_Endcap_[7] = tauVars.
visMassIn;
324 var_NoEleMatch_woGwoGSF_Endcap_[8] = tauVars.
dCrackEta;
325 mvaValue = mva_NoEleMatch_woGwoGSF_EC_->GetClassifier(var_NoEleMatch_woGwoGSF_Endcap_.data());
334 var_NoEleMatch_wGwoGSF_Barrel_[4] = tauVars.
emFraction;
339 var_NoEleMatch_wGwoGSF_Barrel_[9] = tauVars.
visMassIn;
340 var_NoEleMatch_wGwoGSF_Barrel_[10] = tauGammaMoms.
gammaEtaMomIn;
342 var_NoEleMatch_wGwoGSF_Barrel_[12] = tauGammaMoms.
gammaPhiMomIn;
344 var_NoEleMatch_wGwoGSF_Barrel_[14] = tauGammaMoms.
gammaEnFracIn;
346 var_NoEleMatch_wGwoGSF_Barrel_[16] = tauVars.
dCrackEta;
347 var_NoEleMatch_wGwoGSF_Barrel_[17] = tauVars.
dCrackPhi;
348 mvaValue = mva_NoEleMatch_wGwoGSF_BL_->GetClassifier(var_NoEleMatch_wGwoGSF_Barrel_.data());
354 var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.
emFraction;
359 var_NoEleMatch_wGwoGSF_Endcap_[9] = tauVars.
visMassIn;
360 var_NoEleMatch_wGwoGSF_Endcap_[10] = tauGammaMoms.
gammaEtaMomIn;
362 var_NoEleMatch_wGwoGSF_Endcap_[12] = tauGammaMoms.
gammaPhiMomIn;
364 var_NoEleMatch_wGwoGSF_Endcap_[14] = tauGammaMoms.
gammaEnFracIn;
366 var_NoEleMatch_wGwoGSF_Endcap_[16] = tauVars.
dCrackEta;
367 mvaValue = mva_NoEleMatch_wGwoGSF_EC_->GetClassifier(var_NoEleMatch_wGwoGSF_Endcap_.data());
376 var_woGwGSF_Barrel_[5] = elecNumHitsDiffOverSum;
378 var_woGwGSF_Barrel_[7] =
std::min(elecDeltaPinPoutOverPin, 1.
f);
379 var_woGwGSF_Barrel_[8] =
std::min(elecEecalOverPout, 20.
f);
380 var_woGwGSF_Barrel_[9] = elecVars.
deltaEta;
381 var_woGwGSF_Barrel_[10] = elecVars.
deltaPhi;
392 var_woGwGSF_Barrel_[21] = tauVars.
visMassIn;
393 var_woGwGSF_Barrel_[22] = tauVars.
dCrackEta;
394 var_woGwGSF_Barrel_[23] = tauVars.
dCrackPhi;
395 mvaValue = mva_woGwGSF_BL_->GetClassifier(var_woGwGSF_Barrel_.data());
402 var_woGwGSF_Endcap_[5] = elecNumHitsDiffOverSum;
404 var_woGwGSF_Endcap_[7] =
std::min(elecDeltaPinPoutOverPin, 1.
f);
405 var_woGwGSF_Endcap_[8] =
std::min(elecEecalOverPout, 20.
f);
406 var_woGwGSF_Endcap_[9] = elecVars.
deltaEta;
407 var_woGwGSF_Endcap_[10] = elecVars.
deltaPhi;
418 var_woGwGSF_Endcap_[21] = tauVars.
visMassIn;
419 var_woGwGSF_Endcap_[22] = tauVars.
dCrackEta;
420 mvaValue = mva_woGwGSF_EC_->GetClassifier(var_woGwGSF_Endcap_.data());
429 var_wGwGSF_Barrel_[5] = elecNumHitsDiffOverSum;
431 var_wGwGSF_Barrel_[7] =
std::min(elecDeltaPinPoutOverPin, 1.
f);
432 var_wGwGSF_Barrel_[8] =
std::min(elecEecalOverPout, 20.
f);
433 var_wGwGSF_Barrel_[9] = elecVars.
deltaEta;
434 var_wGwGSF_Barrel_[10] = elecVars.
deltaPhi;
447 var_wGwGSF_Barrel_[23] = tauVars.
visMassIn;
454 var_wGwGSF_Barrel_[30] = tauVars.
dCrackEta;
455 var_wGwGSF_Barrel_[31] = tauVars.
dCrackPhi;
456 mvaValue = mva_wGwGSF_BL_->GetClassifier(var_wGwGSF_Barrel_.data());
463 var_wGwGSF_Endcap_[5] = elecNumHitsDiffOverSum;
465 var_wGwGSF_Endcap_[7] =
std::min(elecDeltaPinPoutOverPin, 1.
f);
466 var_wGwGSF_Endcap_[8] =
std::min(elecEecalOverPout, 20.
f);
467 var_wGwGSF_Endcap_[9] = elecVars.
deltaEta;
468 var_wGwGSF_Endcap_[10] = elecVars.
deltaPhi;
481 var_wGwGSF_Endcap_[23] = tauVars.
visMassIn;
488 var_wGwGSF_Endcap_[30] = tauVars.
dCrackEta;
489 mvaValue = mva_wGwGSF_EC_->GetClassifier(var_wGwGSF_Endcap_.data());
495 template <
class TauType,
class ElectronType>
499 if (!isInitialized_) {
500 throw cms::Exception(
"ClassNotInitialized") <<
" AntiElectronMVA6 not properly initialized !!\n";
503 double mvaValue = -99.;
510 float elecDeltaPinPoutOverPin = (elecVars.
pIn > 0.0) ? (
std::abs(elecVars.
pIn - elecVars.
pOut) / elecVars.
pIn) : 1.0;
511 float elecEecalOverPout = (elecVars.
pOut > 0.0) ? (elecVars.
eEcal / elecVars.
pOut) : 20.0;
512 float elecNumHitsDiffOverSum =
521 var_NoEleMatch_woGwoGSF_Barrel_[2] = tauVars.
emFraction;
524 var_NoEleMatch_woGwoGSF_Barrel_[5] = tauVars.
visMassIn;
525 var_NoEleMatch_woGwoGSF_Barrel_[6] = tauVars.
dCrackEta;
528 mvaValue = mva_NoEleMatch_woGwoGSF_BL_->GetClassifier(var_NoEleMatch_woGwoGSF_Barrel_.data());
532 var_NoEleMatch_woGwoGSF_Endcap_[2] = tauVars.
visMassIn;
533 var_NoEleMatch_woGwoGSF_Endcap_[3] = tauVars.
dCrackEta;
536 mvaValue = mva_NoEleMatch_woGwoGSF_EC_->GetClassifier(var_NoEleMatch_woGwoGSF_Endcap_.data());
540 var_NoEleMatch_woGwoGSF_VFEndcap_[2] = tauVars.
visMassIn;
541 var_NoEleMatch_woGwoGSF_VFEndcap_[3] = tauVars.
dCrackEta;
544 mvaValue = mva_NoEleMatch_woGwoGSF_VFEC_->GetClassifier(var_NoEleMatch_woGwoGSF_VFEndcap_.data());
550 var_NoEleMatch_wGwoGSF_Barrel_[2] = tauVars.
emFraction;
555 var_NoEleMatch_wGwoGSF_Barrel_[7] = tauVars.
visMassIn;
556 var_NoEleMatch_wGwoGSF_Barrel_[7] = tauGammaMoms.
gammaEtaMomIn;
558 var_NoEleMatch_wGwoGSF_Barrel_[10] = tauGammaMoms.
gammaPhiMomIn;
560 var_NoEleMatch_wGwoGSF_Barrel_[12] = tauGammaMoms.
gammaEnFracIn;
562 var_NoEleMatch_wGwoGSF_Barrel_[14] = tauVars.
dCrackEta;
565 mvaValue = mva_NoEleMatch_wGwoGSF_BL_->GetClassifier(var_NoEleMatch_wGwoGSF_Barrel_.data());
571 var_NoEleMatch_wGwoGSF_Endcap_[4] = tauVars.
visMassIn;
572 var_NoEleMatch_wGwoGSF_Endcap_[5] = tauGammaMoms.
gammaEtaMomIn;
574 var_NoEleMatch_wGwoGSF_Endcap_[7] = tauGammaMoms.
gammaPhiMomIn;
576 var_NoEleMatch_wGwoGSF_Endcap_[9] = tauGammaMoms.
gammaEnFracIn;
578 var_NoEleMatch_wGwoGSF_Endcap_[11] = tauVars.
dCrackEta;
581 mvaValue = mva_NoEleMatch_wGwoGSF_EC_->GetClassifier(var_NoEleMatch_wGwoGSF_Endcap_.data());
587 var_NoEleMatch_wGwoGSF_VFEndcap_[4] = tauVars.
visMassIn;
588 var_NoEleMatch_wGwoGSF_VFEndcap_[5] = tauGammaMoms.
gammaEtaMomIn;
589 var_NoEleMatch_wGwoGSF_VFEndcap_[6] = tauGammaMoms.
gammaEtaMomOut;
590 var_NoEleMatch_wGwoGSF_VFEndcap_[7] = tauGammaMoms.
gammaPhiMomIn;
591 var_NoEleMatch_wGwoGSF_VFEndcap_[8] = tauGammaMoms.
gammaPhiMomOut;
592 var_NoEleMatch_wGwoGSF_VFEndcap_[9] = tauGammaMoms.
gammaEnFracIn;
593 var_NoEleMatch_wGwoGSF_VFEndcap_[10] = tauGammaMoms.
gammaEnFracOut;
594 var_NoEleMatch_wGwoGSF_VFEndcap_[11] = tauVars.
dCrackEta;
597 mvaValue = mva_NoEleMatch_wGwoGSF_VFEC_->GetClassifier(var_NoEleMatch_wGwoGSF_VFEndcap_.data());
605 var_woGwGSF_Barrel_[4] = elecNumHitsDiffOverSum;
607 var_woGwGSF_Barrel_[6] =
std::min(elecDeltaPinPoutOverPin, 1.
f);
608 var_woGwGSF_Barrel_[7] =
std::min(elecEecalOverPout, 20.
f);
617 var_woGwGSF_Barrel_[16] = tauVars.
visMassIn;
618 var_woGwGSF_Barrel_[17] = tauVars.
dCrackEta;
621 var_woGwGSF_Barrel_[20] = elecVars.
deltaEta;
622 var_woGwGSF_Barrel_[21] = elecVars.
deltaPhi;
625 var_woGwGSF_Barrel_[24] = elecVars.
r9;
628 mvaValue = mva_woGwGSF_BL_->GetClassifier(var_woGwGSF_Barrel_.data());
634 var_woGwGSF_Endcap_[4] = elecNumHitsDiffOverSum;
636 var_woGwGSF_Endcap_[6] = elecVars.
eEcal;
639 var_woGwGSF_Endcap_[9] = tauVars.
visMassIn;
640 var_woGwGSF_Endcap_[10] = tauVars.
dCrackEta;
656 var_woGwGSF_Endcap_[26] = elecVars.
deltaEta;
657 var_woGwGSF_Endcap_[27] = elecVars.
deltaPhi;
661 mvaValue = mva_woGwGSF_EC_->GetClassifier(var_woGwGSF_Endcap_.data());
664 var_woGwGSF_VFEndcap_[1] = elecVars.
gsfNumHits;
667 var_woGwGSF_VFEndcap_[4] = elecNumHitsDiffOverSum;
669 var_woGwGSF_VFEndcap_[6] = elecVars.
eEcal;
672 var_woGwGSF_VFEndcap_[9] = tauVars.
visMassIn;
673 var_woGwGSF_VFEndcap_[10] = tauVars.
dCrackEta;
690 var_woGwGSF_VFEndcap_[27] = elecVars.
deltaEta;
691 var_woGwGSF_VFEndcap_[28] = elecVars.
deltaPhi;
695 mvaValue = mva_woGwGSF_VFEC_->GetClassifier(var_woGwGSF_VFEndcap_.data());
703 var_wGwGSF_Barrel_[4] = elecNumHitsDiffOverSum;
705 var_wGwGSF_Barrel_[6] =
std::min(elecDeltaPinPoutOverPin, 1.
f);
706 var_wGwGSF_Barrel_[7] =
std::min(elecEecalOverPout, 20.
f);
717 var_wGwGSF_Barrel_[18] = tauVars.
visMassIn;
724 var_wGwGSF_Barrel_[25] = tauVars.
dCrackEta;
727 var_wGwGSF_Barrel_[28] = elecVars.
deltaEta;
728 var_wGwGSF_Barrel_[29] = elecVars.
deltaPhi;
735 mvaValue = mva_wGwGSF_BL_->GetClassifier(var_wGwGSF_Barrel_.data());
741 var_wGwGSF_Endcap_[4] = elecNumHitsDiffOverSum;
743 var_wGwGSF_Endcap_[6] = elecVars.
eEcal;
748 var_wGwGSF_Endcap_[11] = tauVars.
visMassIn;
755 var_wGwGSF_Endcap_[18] = tauVars.
dCrackEta;
770 var_wGwGSF_Endcap_[33] = elecVars.
deltaEta;
771 var_wGwGSF_Endcap_[34] = elecVars.
deltaPhi;
775 mvaValue = mva_wGwGSF_EC_->GetClassifier(var_wGwGSF_Endcap_.data());
778 var_wGwGSF_VFEndcap_[1] = elecVars.
gsfNumHits;
781 var_wGwGSF_VFEndcap_[4] = elecNumHitsDiffOverSum;
783 var_wGwGSF_VFEndcap_[6] = elecVars.
eEcal;
788 var_wGwGSF_VFEndcap_[11] = tauVars.
visMassIn;
795 var_wGwGSF_VFEndcap_[18] = tauVars.
dCrackEta;
812 var_wGwGSF_VFEndcap_[35] = elecVars.
deltaEta;
813 var_wGwGSF_VFEndcap_[36] = elecVars.
deltaPhi;
817 mvaValue = mva_wGwGSF_VFEC_->GetClassifier(var_wGwGSF_VFEndcap_.data());
823 template <
class TauType,
class ElectronType>
834 return mvaValue(tauVars, tauGammaVecs, elecVars);
837 template <
class TauType,
class ElectronType>
847 return mvaValue(tauVars, tauGammaVecs, elecVars);
850 template <
class TauType,
class ElectronType>
854 tauVars = getTauVarsTypeSpecific(theTau);
857 <<
"Unsupported TauType used. You must use either reco::PFTau or pat::Tau.";
859 tauVars.
pt = theTau.pt();
863 float signalrad = std::clamp(3.0 /
std::max(1.0, theTau.pt()), 0.05, 0.10);
864 for (
const auto& gamma : theTau.signalGammaCands()) {
865 float dR =
deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4());
867 if (dR < signalrad) {
868 pfGammaSum += gamma->p4();
871 for (
const auto& charged : theTau.signalChargedHadrCands()) {
872 float dR =
deltaR(charged->p4(), theTau.leadChargedHadrCand()->p4());
874 if (dR < signalrad) {
875 pfChargedSum += charged->p4();
881 if (theTau.leadChargedHadrCand().isNonnull()) {
884 if (packedLeadChCand !=
nullptr) {
900 template <
class TauType,
class ElectronType>
904 float signalrad = std::clamp(3.0 /
std::max(1.0, theTau.pt()), 0.05, 0.10);
905 for (
const auto& gamma : theTau.signalGammaCands()) {
906 float dR =
deltaR(gamma->p4(), theTau.leadChargedHadrCand()->p4());
908 if (dR < signalrad) {
909 tauGammaVecs.
gammasdEtaInSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta());
910 tauGammaVecs.
gammasdPhiInSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi());
915 tauGammaVecs.
gammasdEtaOutSigCone.push_back(gamma->eta() - theTau.leadChargedHadrCand()->eta());
916 tauGammaVecs.
gammasdPhiOutSigCone.push_back(gamma->phi() - theTau.leadChargedHadrCand()->phi());
923 template <
class TauType,
class ElectronType>
927 elecVars.
eta = theEleRef->eta();
928 elecVars.
phi = theEleRef->phi();
932 float elecEgamma = 0.;
937 pfCluster != pfSuperCluster->clustersEnd();
939 double pfClusterEn = (*pfCluster)->energy();
940 if (pfCluster == pfSuperCluster->clustersBegin())
941 elecEe += pfClusterEn;
943 elecEgamma += pfClusterEn;
951 elecVars.
r9 = theEleRef->r9();
955 elecVars.
pIn =
std::sqrt(theEleRef->trackMomentumAtVtx().Mag2());
956 elecVars.
pOut =
std::sqrt(theEleRef->trackMomentumOut().Mag2());
957 elecVars.
eTotOverPin = (elecVars.
pIn > 0.0) ? ((elecEe + elecEgamma) / elecVars.
pIn) : -0.1;
958 elecVars.
eEcal = theEleRef->ecalEnergy();
960 elecVars.
deltaEta = theEleRef->deltaEtaSeedClusterTrackAtCalo();
961 elecVars.
deltaPhi = theEleRef->deltaPhiSeedClusterTrackAtCalo();
963 elecVars.
deltaEta = theEleRef->deltaEtaEleClusterTrackAtCalo();
964 elecVars.
deltaPhi = theEleRef->deltaPhiEleClusterTrackAtCalo();
976 elecVars.
chi2NormGSF = theEleRef->gsfTrack()->normalizedChi2();
977 elecVars.
gsfNumHits = theEleRef->gsfTrack()->numberOfValidHits();
978 if (theEleRef->gsfTrack()->pt() > 0.) {
979 elecVars.
gsfTrackResol = theEleRef->gsfTrack()->ptError() / theEleRef->gsfTrack()->pt();
987 if (theEleRef->closestCtfTrackRef().
isNonnull()) {
988 elecVars.
chi2NormKF = theEleRef->closestCtfTrackRef()->normalizedChi2();
989 elecVars.
kfNumHits = theEleRef->closestCtfTrackRef()->numberOfValidHits();
993 if (isPhase2_ && !theEleRef->isEB()) {
995 getElecVarsHGCalTypeSpecific(theEleRef, elecVars);
998 <<
"Unsupported ElectronType used. You must use either reco::GsfElectron or pat::Electron.";
1004 template <
class TauType,
class ElectronType>
1015 std::array<double, 18> fill_cPhi() {
1016 constexpr
double pi =
M_PI;
1017 std::array<double, 18> cPhi;
1020 for (
unsigned iCrack = 1; iCrack <= 17; ++iCrack) {
1021 cPhi[iCrack] = cPhi[0] - 2. * iCrack * pi / 18;
1026 const std::array<double, 18> cPhi = fill_cPhi();
1030 template <
class TauType,
class ElectronType>
1034 constexpr
double pi =
M_PI;
1037 constexpr
double delta_cPhi = 0.00638;
1039 double retVal = 99.;
1041 if (eta >= -1.47464 && eta <= 1.47464) {
1052 if (phi >= -pi && phi <= pi) {
1054 if (phi < cPhi[17] || phi >= cPhi[0]) {
1057 retVal = minimum(phi - cPhi[0], phi - cPhi[17] - 2. * pi);
1061 unsigned iCrack = 16;
1063 if (phi < cPhi[iCrack]) {
1064 retVal = minimum(phi - cPhi[iCrack + 1], phi - cPhi[iCrack]);
1081 template <
class TauType,
class ElectronType>
1086 double cracks[5] = {0., 4.44747e-01, 7.92824e-01, 1.14090e+00, 1.47464e+00};
1088 double retVal = 99.;
1090 for (
int iCrack = 0; iCrack < 5; ++iCrack) {
1091 double d = minimum(eta - cracks[iCrack], eta + cracks[iCrack]);
1101 template <
class TauType,
class ElectronType>
1107 tauVars.
phi = theTau.
phi();
1109 if (!usePhiAtEcalEntranceExtrapolation_) {
1112 float etaAtECal = 0.;
1113 float phiAtECal = 0.;
1114 bool success = energyWeightedEtaAndPhiAtECal(theTau, etaAtECal, phiAtECal);
1116 tauVars.
phi = phiAtECal;
1121 if (
std::abs(theTau.
eta()) >= ecalBarrelEndcapEtaBorder_) {
1129 float phiAtECal = 0.;
1130 float etaAtECal = 0.;
1131 success = energyWeightedEtaAndPhiAtECal(theTau, etaAtECal, phiAtECal);
1151 template <
class TauType,
class ElectronType>
1157 float sumEtaTimesEnergy = 0.;
1158 float sumPhiTimesEnergy = 0.;
1159 float sumEnergy = 0.;
1160 tauVars.
phi = theTau.
phi();
1162 bool isFromPFCands =
1165 for (
const auto& candidate : theTau.
signalCands()) {
1166 float etaAtECalEntrance = candidate->eta();
1167 float phiAtECalEntrance = candidate->phi();
1169 if (isFromPFCands) {
1172 if (!usePhiAtEcalEntranceExtrapolation_) {
1178 phiAtECalEntrance = posAtECal.phi();
1181 track = getTrackFromPFCand(pfCandidate);
1186 etaAtECalEntrance = posAtECal.eta();
1187 phiAtECalEntrance = posAtECal.phi();
1189 track = candidate->bestTrack();
1191 if (track !=
nullptr) {
1197 sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy();
1198 sumPhiTimesEnergy += phiAtECalEntrance * candidate->energy();
1199 sumEnergy += candidate->energy();
1201 if (sumEnergy > 0.) {
1203 tauVars.
phi = sumPhiTimesEnergy / sumEnergy;
1207 for (
const auto& candidate : theTau.
signalCands()) {
1208 float etaAtECalEntrance = candidate->eta();
1210 if (isFromPFCands) {
1213 if (
std::abs(theTau.
eta()) >= ecalBarrelEndcapEtaBorder_) {
1217 etaAtECalEntrance = posAtECal.eta();
1220 track = getTrackFromPFCand(pfCandidate);
1225 etaAtECalEntrance = posAtECal.eta();
1227 track = candidate->bestTrack();
1229 if (track !=
nullptr) {
1235 sumEtaTimesEnergy += etaAtECalEntrance * candidate->energy();
1236 sumEnergy += candidate->energy();
1238 if (sumEnergy > 0.) {
1241 if (isFromPFCands) {
1249 if (patLeadCandiate !=
nullptr) {
1257 if (isFromPFCands) {
1265 if (patLeadCandiate !=
nullptr) {
1269 (1. - patLeadCandiate->
hcalFraction()) / patLeadCandiate->
p();
1278 template <
class TauType,
class ElectronType>
1282 if (!(electronIds_.find(
"hgcElectronID:sigmaUU") != electronIds_.end() &&
1283 electronIds_.at(
"hgcElectronID:sigmaUU").isValid()))
1286 elecVars.
hgcalSigmaUU = (*electronIds_.at(
"hgcElectronID:sigmaUU"))[theEleRef];
1287 elecVars.
hgcalSigmaVV = (*electronIds_.at(
"hgcElectronID:sigmaVV"))[theEleRef];
1288 elecVars.
hgcalSigmaEE = (*electronIds_.at(
"hgcElectronID:sigmaEE"))[theEleRef];
1289 elecVars.
hgcalSigmaPP = (*electronIds_.at(
"hgcElectronID:sigmaPP"))[theEleRef];
1290 elecVars.
hgcalNLayers = (*electronIds_.at(
"hgcElectronID:nLayers"))[theEleRef];
1291 elecVars.
hgcalFirstLayer = (*electronIds_.at(
"hgcElectronID:firstLayer"))[theEleRef];
1292 elecVars.
hgcalLastLayer = (*electronIds_.at(
"hgcElectronID:lastLayer"))[theEleRef];
1293 elecVars.
hgcalLayerEfrac10 = (*electronIds_.at(
"hgcElectronID:layerEfrac10"))[theEleRef];
1294 elecVars.
hgcalLayerEfrac90 = (*electronIds_.at(
"hgcElectronID:layerEfrac90"))[theEleRef];
1295 elecVars.
hgcalEcEnergyEE = (*electronIds_.at(
"hgcElectronID:ecEnergyEE"))[theEleRef];
1296 elecVars.
hgcalEcEnergyFH = (*electronIds_.at(
"hgcElectronID:ecEnergyFH"))[theEleRef];
1297 elecVars.
hgcalMeasuredDepth = (*electronIds_.at(
"hgcElectronID:measuredDepth"))[theEleRef];
1298 elecVars.
hgcalExpectedDepth = (*electronIds_.at(
"hgcElectronID:expectedDepth"))[theEleRef];
1299 elecVars.
hgcalExpectedSigma = (*electronIds_.at(
"hgcElectronID:expectedSigma"))[theEleRef];
1304 template <
class TauType,
class ElectronType>
1308 if (!theEleRef->hasUserFloat(
"hgcElectronID:sigmaUU"))
1311 elecVars.
hgcalSigmaUU = theEleRef->userFloat(
"hgcElectronID:sigmaUU");
1312 elecVars.
hgcalSigmaVV = theEleRef->userFloat(
"hgcElectronID:sigmaVV");
1313 elecVars.
hgcalSigmaEE = theEleRef->userFloat(
"hgcElectronID:sigmaEE");
1314 elecVars.
hgcalSigmaPP = theEleRef->userFloat(
"hgcElectronID:sigmaPP");
1315 elecVars.
hgcalNLayers = theEleRef->userFloat(
"hgcElectronID:nLayers");
1316 elecVars.
hgcalFirstLayer = theEleRef->userFloat(
"hgcElectronID:firstLayer");
1317 elecVars.
hgcalLastLayer = theEleRef->userFloat(
"hgcElectronID:lastLayer");
1318 elecVars.
hgcalLayerEfrac10 = theEleRef->userFloat(
"hgcElectronID:layerEfrac10");
1319 elecVars.
hgcalLayerEfrac90 = theEleRef->userFloat(
"hgcElectronID:layerEfrac90");
1320 elecVars.
hgcalEcEnergyEE = theEleRef->userFloat(
"hgcElectronID:ecEnergyEE");
1321 elecVars.
hgcalEcEnergyFH = theEleRef->userFloat(
"hgcElectronID:ecEnergyFH");
1328 template <
class TauType,
class ElectronType>
1334 float sumEnergy = 0.;
1335 for (
const auto& candidate : theTau.
signalCands()) {
1336 float etaAtECalEntrance = candidate->eta();
1337 float phiAtECalEntrance = candidate->phi();
1341 etaAtECalEntrance = posAtECal.eta();
1342 phiAtECalEntrance = posAtECal.phi();
1344 eta += etaAtECalEntrance * candidate->energy();
1345 phi += phiAtECalEntrance * candidate->energy();
1346 sumEnergy += candidate->energy();
1348 if (sumEnergy > 0.) {
1349 eta = eta / sumEnergy;
1350 phi = phi / sumEnergy;
1355 return (sumEnergy > 0.);
std::vector< float > var_NoEleMatch_wGwoGSF_Barrel_
double ecalEnergy() const
return corrected Ecal energy
double minimum(double a, double b)
std::string mvaName_wGwGSF_BL_
std::vector< float > var_wGwGSF_Endcap_
std::vector< float > var_wGwGSF_VFEndcap_
static std::vector< std::string > checklist log
bool isNonnull() const
Checks for non-null.
antiElecIDMVA6_blocks::TauVars getTauVars(const TauType &theTau)
std::vector< float > gammasdPhiInSigCone
float hcalEnergyLeadChargedHadrCand() const
return hcal energy from LeadChargedHadrCand
float hcalFraction() const
float superClusterEtaWidth
T const * get() const
Returns C++ pointer to the item.
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_NoEleMatch_wGwoGSF_EC_
antiElecIDMVA6_blocks::TauVars getTauVarsTypeSpecific(const reco::PFTau &theTau)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::vector< float > gammasdEtaInSigCone
std::string mvaName_NoEleMatch_woGwoGSF_VFEC_
reco::CandidatePtrVector signalCands() const
std::vector< float > gammasPtOutSigCone
int pdgId() const override
PDG identifier.
const math::XYZPointF & positionAtECALEntrance() const
std::vector< float > var_NoEleMatch_woGwoGSF_Endcap_
reco::TrackRef trackRef() const
bool getData(T &iHolder) const
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_NoEleMatch_wGwoGSF_VFEC_
double p() const override
magnitude of momentum vector
float eSeedClusterOverPout
std::string mvaName_NoEleMatch_wGwoGSF_BL_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
void getElecVarsHGCalTypeSpecific(const reco::GsfElectronRef &theEleRef, antiElecIDMVA6_blocks::ElecVars &elecVars)
float leadPFChargedHadrEoP
float leadChargedPFCandEtaAtEcalEntrance
double p() const final
magnitude of momentum vector
std::string mvaName_NoEleMatch_wGwoGSF_EC_
const CandidatePtr & leadChargedHadrCand() const
double pt() const
track transverse momentum
std::vector< float > var_wGwGSF_Barrel_
float leadPFChargedHadrHoP
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_wGwGSF_BL_
std::vector< float > gammasdPhiOutSigCone
std::string mvaName_wGwGSF_VFEC_
float ecalEnergyLeadChargedHadrCand() const
Abs< T >::type abs(const T &t)
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_NoEleMatch_woGwoGSF_BL_
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_woGwGSF_BL_
std::string mvaName_NoEleMatch_wGwoGSF_VFEC_
std::vector< float > var_woGwGSF_Endcap_
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_wGwGSF_EC_
T const * get() const
Returns C++ pointer to the item.
float phiAtEcalEntrance() const
return phiAtEcalEntrance
const reco::CandidatePtr leadChargedHadrCand() const
float caloFraction() const
Set the fraction of ECAL+HCAL energy over candidate energy.
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_woGwGSF_VFEC_
std::vector< float > var_NoEleMatch_woGwoGSF_Barrel_
Analysis-level tau class.
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_NoEleMatch_wGwoGSF_BL_
int signalPFGammaCandsOut
reco::MuonRef muonRef() const
bool isNonnull() const
Checks for non-null.
double mvaValue(const antiElecIDMVA6_blocks::TauVars &tauVars, const antiElecIDMVA6_blocks::TauGammaVecs &tauGammaVecs, const antiElecIDMVA6_blocks::ElecVars &elecVars)
antiElecIDMVA6_blocks::TauGammaVecs getTauGammaVecs(const TauType &theTau)
float ptLeadChargedCand() const
return pt from LeadChargedCand
std::vector< float > gammasdEtaOutSigCone
std::map< std::string, edm::EDGetTokenT< edm::ValueMap< float > > > electronIds_tokens_
std::pair< int, edm::FunctionWithDict > OK
bool energyWeightedEtaAndPhiAtECal(const pat::Tau &theTau, float &eta, float &phi)
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_woGwGSF_EC_
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_NoEleMatch_woGwoGSF_EC_
std::string mvaName_woGwGSF_VFEC_
float hgcalDepthCompatibility
T getParameter(std::string const &) const
const CandidatePtr & leadCand() const
std::vector< float > var_NoEleMatch_wGwoGSF_VFEndcap_
double dCrackEta(double eta)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
float emFraction_MVA() const
return emFraction_MVA
antiElecIDMVA6_blocks::ElecVars getElecVars(const ElectronRef &theEleRef)
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_wGwGSF_VFEC_
std::vector< float > gammasPtInSigCone
Particle reconstructed by the particle flow algorithm.
std::vector< float > var_NoEleMatch_wGwoGSF_Endcap_
double mvaValuePhase2(const antiElecIDMVA6_blocks::TauVars &tauVars, const antiElecIDMVA6_blocks::TauGammaMoms &tauGammaMoms, const antiElecIDMVA6_blocks::ElecVars &elecVars)
edm::FileInPath inputFileName_
float leadChargedPFCandPt
double energy() const override
energy
reco::GsfTrackRef gsfTrackRef() const
double hcalEnergy() const
return corrected Hcal energy
std::string mvaName_wGwGSF_EC_
math::XYZPoint Point
point in the space
std::map< std::string, edm::Handle< edm::ValueMap< float > > > electronIds_
std::string mvaName_NoEleMatch_woGwoGSF_EC_
float etaAtEcalEntrance() const
return etaAtEcalEntrance
float etaAtEcalEntranceLeadChargedCand() const
return etaAtEcalEntrance from LeadChargedCand
float superClusterPhiWidth
const std::vector< reco::CandidatePtr > & signalCands() const
Candidates in signal region.
std::vector< float > var_woGwGSF_Barrel_
std::string mvaName_woGwGSF_EC_
std::string mvaName_woGwGSF_BL_
double phi() const final
momentum azimuthal angle
edm::ESGetToken< GBRForest, GBRWrapperRcd > mvaToken_NoEleMatch_woGwoGSF_VFEC_
AntiElectronIDMVA6(const edm::ParameterSet &, edm::ConsumesCollector &&)
bool usePhiAtEcalEntranceExtrapolation_
void beginEvent(const edm::Event &, const edm::EventSetup &)
double dCrackPhi(double phi, double eta)
std::vector< float > var_NoEleMatch_woGwoGSF_VFEndcap_
std::vector< float > var_woGwGSF_VFEndcap_
double eta() const final
momentum pseudorapidity
std::string mvaName_NoEleMatch_woGwoGSF_BL_