29 : fMethodname(
"BDTG method"), fisInitialized(kFALSE), fMVAType(kTrig), fUseBinnedVersion(kTRUE), fNMVABins(0) {
45 std::vector<std::string> tempWeightFileVector;
46 tempWeightFileVector.push_back(weightsfile);
53 Bool_t useBinnedVersion,
54 std::vector<std::string> weightsfiles) {
70 UInt_t ExpectedNBins = 0;
92 <<
" does not equal to weightsfiles.size() = " << weightsfiles.size() << std::endl;
101 TMVA::Reader* tmpTMVAReader =
new TMVA::Reader(
"!Color:!Silent:Error");
102 tmpTMVAReader->SetVerbose(kTRUE);
122 tmpTMVAReader->AddVariable(
"R9", &
fMVAVar_R9);
129 if (
i == 2 ||
i == 5)
136 tmpTMVAReader->AddVariable(
"d0", &
fMVAVar_d0);
140 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
161 tmpTMVAReader->AddVariable(
"R9", &
fMVAVar_R9);
170 if (
i == 2 ||
i == 5)
177 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
198 tmpTMVAReader->AddVariable(
"R9", &
fMVAVar_R9);
205 if (
i == 2 ||
i == 5)
212 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
232 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
253 tmpTMVAReader->AddVariable(
"R9", &
fMVAVar_R9);
260 if (
i == 2 ||
i == 5) {
268 tmpTMVAReader->AddVariable(
"d0", &
fMVAVar_d0);
290 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
311 tmpTMVAReader->AddVariable(
"R9", &
fMVAVar_R9);
318 if (
i == 2 ||
i == 5) {
326 tmpTMVAReader->AddVariable(
"d0", &
fMVAVar_d0);
349 tmpTMVAReader->AddSpectator(
"pt", &
fMVAVar_pt);
353 if ((
fMethodname ==
"BDT") && (weightsfiles[
i].rfind(
".xml.gz") == weightsfiles[
i].length() - strlen(
".xml.gz"))) {
354 gzFile
file = gzopen(weightsfiles[
i].c_str(),
"rb");
355 if (
file ==
nullptr) {
356 std::cout <<
"Error opening gzip file associated to " << weightsfiles[
i] << std::endl;
357 throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
359 std::vector<char>
data;
360 data.reserve(1024 * 1024 * 10);
361 unsigned int bufflen = 32 * 1024;
362 char* buff = reinterpret_cast<char*>(malloc(bufflen));
363 if (buff ==
nullptr) {
364 std::cout <<
"Error creating buffer for " << weightsfiles[
i] << std::endl;
366 throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
369 while ((
read = gzread(
file, buff, bufflen)) != 0) {
371 std::cout <<
"Error reading gzip file associated to " << weightsfiles[
i] <<
": " << gzerror(
file, &
read)
375 throw cms::Exception(
"Configuration",
"Error reading zipped XML file");
379 if (gzclose(
file) != Z_OK) {
380 std::cout <<
"Error closing gzip file associated to " << weightsfiles[
i] << std::endl;
383 data.push_back(
'\0');
384 fTMVAMethod.push_back(dynamic_cast<TMVA::MethodBase*>(tmpTMVAReader->BookMVA(TMVA::Types::kBDT, &
data[0])));
392 <<
"Load weights file : " << weightsfiles[
i] << std::endl;
395 std::cout <<
"Electron ID MVA Completed\n";
401 unsigned int bin = 0;
404 if (
pt < 10 && fabs(
eta) < 1.479)
406 if (
pt < 10 && fabs(
eta) >= 1.479)
408 if (
pt >= 10 && fabs(
eta) < 1.479)
410 if (
pt >= 10 && fabs(
eta) >= 1.479)
416 if (
pt < 10 && fabs(
eta) < 0.8)
418 if (
pt < 10 && fabs(
eta) >= 0.8 && fabs(
eta) < 1.479)
420 if (
pt < 10 && fabs(
eta) >= 1.479)
422 if (
pt >= 10 && fabs(
eta) < 0.8)
424 if (
pt >= 10 && fabs(
eta) >= 0.8 && fabs(
eta) < 1.479)
426 if (
pt >= 10 && fabs(
eta) >= 1.479)
434 if (
pt < 20 && fabs(
eta) < 0.8)
436 if (
pt < 20 && fabs(
eta) >= 0.8 && fabs(
eta) < 1.479)
438 if (
pt < 20 && fabs(
eta) >= 1.479)
440 if (
pt >= 20 && fabs(
eta) < 0.8)
442 if (
pt >= 20 && fabs(
eta) >= 0.8 && fabs(
eta) < 1.479)
444 if (
pt >= 20 && fabs(
eta) >= 1.479)
465 Double_t OneMinusE1x5E5x5,
472 Double_t PreShowerOverRaw,
480 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
485 std::cout <<
"Error: This method should be called for kTrig MVA only" << std::endl;
517 Double_t
mva = -9999;
561 Double_t PreShowerOverRaw,
566 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
571 std::cout <<
"Error: This method should be called for kTrigNoIP MVA only" << std::endl;
602 Double_t
mva = -9999;
639 Double_t OneMinusE1x5E5x5,
646 Double_t PreShowerOverRaw,
652 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
657 std::cout <<
"Error: This method should be called for kNonTrig MVA only" << std::endl;
687 Double_t
mva = -9999;
722 Double_t OneMinusE1x5E5x5,
728 Double_t PreShowerOverRaw,
731 Double_t ChargedIso_DR0p0To0p1,
732 Double_t ChargedIso_DR0p1To0p2,
733 Double_t ChargedIso_DR0p2To0p3,
734 Double_t ChargedIso_DR0p3To0p4,
735 Double_t ChargedIso_DR0p4To0p5,
736 Double_t GammaIso_DR0p0To0p1,
737 Double_t GammaIso_DR0p1To0p2,
738 Double_t GammaIso_DR0p2To0p3,
739 Double_t GammaIso_DR0p3To0p4,
740 Double_t GammaIso_DR0p4To0p5,
741 Double_t NeutralHadronIso_DR0p0To0p1,
742 Double_t NeutralHadronIso_DR0p1To0p2,
743 Double_t NeutralHadronIso_DR0p2To0p3,
744 Double_t NeutralHadronIso_DR0p3To0p4,
745 Double_t NeutralHadronIso_DR0p4To0p5,
751 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
799 Double_t
mva = -9999;
816 <<
" ChargedIso_DR0p0To0p1 " << ChargedIso_DR0p0To0p1 <<
" ChargedIso_DR0p1To0p2 "
817 << ChargedIso_DR0p1To0p2 <<
" ChargedIso_DR0p2To0p3 " << ChargedIso_DR0p2To0p3
818 <<
" ChargedIso_DR0p3To0p4 " << ChargedIso_DR0p3To0p4 <<
" ChargedIso_DR0p4To0p5 "
819 << ChargedIso_DR0p4To0p5 <<
" GammaIso_DR0p0To0p1 " << GammaIso_DR0p0To0p1 <<
" GammaIso_DR0p1To0p2 "
820 << GammaIso_DR0p1To0p2 <<
" GammaIso_DR0p2To0p3 " << GammaIso_DR0p2To0p3 <<
" GammaIso_DR0p3To0p4 "
821 << GammaIso_DR0p3To0p4 <<
" GammaIso_DR0p4To0p5 " << GammaIso_DR0p4To0p5
822 <<
" NeutralHadronIso_DR0p0To0p1 " << NeutralHadronIso_DR0p0To0p1 <<
" NeutralHadronIso_DR0p1To0p2 "
823 << NeutralHadronIso_DR0p1To0p2 <<
" NeutralHadronIso_DR0p2To0p3 " << NeutralHadronIso_DR0p2To0p3
824 <<
" NeutralHadronIso_DR0p3To0p4 " << NeutralHadronIso_DR0p3To0p4 <<
" NeutralHadronIso_DR0p4To0p5 "
838 Double_t ChargedIso_DR0p0To0p1,
839 Double_t ChargedIso_DR0p1To0p2,
840 Double_t ChargedIso_DR0p2To0p3,
841 Double_t ChargedIso_DR0p3To0p4,
842 Double_t ChargedIso_DR0p4To0p5,
843 Double_t GammaIso_DR0p0To0p1,
844 Double_t GammaIso_DR0p1To0p2,
845 Double_t GammaIso_DR0p2To0p3,
846 Double_t GammaIso_DR0p3To0p4,
847 Double_t GammaIso_DR0p4To0p5,
848 Double_t NeutralHadronIso_DR0p0To0p1,
849 Double_t NeutralHadronIso_DR0p1To0p2,
850 Double_t NeutralHadronIso_DR0p2To0p3,
851 Double_t NeutralHadronIso_DR0p3To0p4,
852 Double_t NeutralHadronIso_DR0p4To0p5,
855 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
960 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
965 std::cout <<
"Error: This method should be called for kTrig or kNonTrig MVA only" << std::endl;
969 bool validKF =
false;
977 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
979 (validKF) ? myTrackRef->numberOfValidHits() : -1.;
989 const auto& vCov = myEcalCluster.localCovariances(*(ele.
superCluster()->seed()));
1026 const double gsfsign = ((-ele.
gsfTrack()->dxy(
vertex.position())) >= 0) ? 1. : -1.;
1031 double ip3d = gsfsign * ip3dpv.second.value();
1032 double ip3derr = ip3dpv.second.error();
1041 Double_t
mva = -9999;
1072 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
1077 std::cout <<
"Error: This method should be called for kTrigNoIP MVA only" << std::endl;
1081 bool validKF =
false;
1089 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
1099 const auto& vCov = myEcalCluster.localCovariances(*(ele.
superCluster()->seed()));
1125 Double_t
mva = -9999;
1158 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
1162 bool validKF =
false;
1170 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
1186 : ((ele.
e5x5()) != 0. ? 1. - (ele.
e1x5() / ele.
e5x5()) : -1.);
1220 const double gsfsign = ((-ele.
gsfTrack()->dxy(
vertex.position())) >= 0) ? 1. : -1.;
1223 double ip3d = gsfsign * ele.
dB();
1224 double ip3derr = ele.
edB();
1236 Double_t
mva = -9999;
1269 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
1274 std::cout <<
"Error: This method should be called for kTrigNoIP mva only" << std::endl;
1278 bool validKF =
false;
1286 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
1319 Double_t
mva = -9999;
1357 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
1368 Double_t tmpChargedIso_DR0p0To0p1 = 0;
1369 Double_t tmpChargedIso_DR0p1To0p2 = 0;
1370 Double_t tmpChargedIso_DR0p2To0p3 = 0;
1371 Double_t tmpChargedIso_DR0p3To0p4 = 0;
1372 Double_t tmpChargedIso_DR0p4To0p5 = 0;
1373 Double_t tmpGammaIso_DR0p0To0p1 = 0;
1374 Double_t tmpGammaIso_DR0p1To0p2 = 0;
1375 Double_t tmpGammaIso_DR0p2To0p3 = 0;
1376 Double_t tmpGammaIso_DR0p3To0p4 = 0;
1377 Double_t tmpGammaIso_DR0p4To0p5 = 0;
1378 Double_t tmpNeutralHadronIso_DR0p0To0p1 = 0;
1379 Double_t tmpNeutralHadronIso_DR0p1To0p2 = 0;
1380 Double_t tmpNeutralHadronIso_DR0p2To0p3 = 0;
1381 Double_t tmpNeutralHadronIso_DR0p3To0p4 = 0;
1382 Double_t tmpNeutralHadronIso_DR0p4To0p5 = 0;
1384 double electronTrackZ = 0;
1407 Bool_t IsLeptonFootprint = kFALSE;
1411 for (reco::GsfElectronCollection::const_iterator iE = IdentifiedElectrons.begin();
1412 iE != IdentifiedElectrons.end();
1415 if (iP->gsfTrackRef().isNonnull() && iE->gsfTrack().isNonnull() &&
1417 IsLeptonFootprint = kTRUE;
1418 if (iP->trackRef().isNonnull() && iE->closestCtfTrackRef().isNonnull() &&
1420 IsLeptonFootprint = kTRUE;
1423 double tmpDR =
sqrt(
pow(iP->eta() - iE->eta(), 2) +
pow(acos(
cos(iP->phi() - iE->phi())), 2));
1424 if (iP->trackRef().isNonnull() && fabs(iE->superCluster()->eta()) >= 1.479 && tmpDR < 0.015)
1425 IsLeptonFootprint = kTRUE;
1427 IsLeptonFootprint = kTRUE;
1429 for (reco::MuonCollection::const_iterator iM = IdentifiedMuons.begin(); iM != IdentifiedMuons.end(); ++iM) {
1431 if (iP->trackRef().isNonnull() && iM->innerTrack().isNonnull() &&
1433 IsLeptonFootprint = kTRUE;
1436 double tmpDR =
sqrt(
pow(iP->eta() - iM->eta(), 2) +
pow(acos(
cos(iP->phi() - iM->phi())), 2));
1437 if (iP->trackRef().isNonnull() && tmpDR < 0.01)
1438 IsLeptonFootprint = kTRUE;
1441 if (!IsLeptonFootprint) {
1442 Bool_t passVeto = kTRUE;
1444 if (iP->trackRef().isNonnull()) {
1445 if (!(fabs(iP->trackRef()->dz(
vertex.position()) - electronTrackZ) < 0.2))
1459 tmpChargedIso_DR0p0To0p1 += iP->pt();
1460 if (
dr >= 0.1 &&
dr < 0.2)
1461 tmpChargedIso_DR0p1To0p2 += iP->pt();
1462 if (
dr >= 0.2 &&
dr < 0.3)
1463 tmpChargedIso_DR0p2To0p3 += iP->pt();
1464 if (
dr >= 0.3 &&
dr < 0.4)
1465 tmpChargedIso_DR0p3To0p4 += iP->pt();
1466 if (
dr >= 0.4 &&
dr < 0.5)
1467 tmpChargedIso_DR0p4To0p5 += iP->pt();
1479 tmpGammaIso_DR0p0To0p1 += iP->pt();
1480 if (
dr >= 0.1 &&
dr < 0.2)
1481 tmpGammaIso_DR0p1To0p2 += iP->pt();
1482 if (
dr >= 0.2 &&
dr < 0.3)
1483 tmpGammaIso_DR0p2To0p3 += iP->pt();
1484 if (
dr >= 0.3 &&
dr < 0.4)
1485 tmpGammaIso_DR0p3To0p4 += iP->pt();
1486 if (
dr >= 0.4 &&
dr < 0.5)
1487 tmpGammaIso_DR0p4To0p5 += iP->pt();
1493 tmpNeutralHadronIso_DR0p0To0p1 += iP->pt();
1494 if (
dr >= 0.1 &&
dr < 0.2)
1495 tmpNeutralHadronIso_DR0p1To0p2 += iP->pt();
1496 if (
dr >= 0.2 &&
dr < 0.3)
1497 tmpNeutralHadronIso_DR0p2To0p3 += iP->pt();
1498 if (
dr >= 0.3 &&
dr < 0.4)
1499 tmpNeutralHadronIso_DR0p3To0p4 += iP->pt();
1500 if (
dr >= 0.4 &&
dr < 0.5)
1501 tmpNeutralHadronIso_DR0p4To0p5 += iP->pt();
1590 Double_t
mva = -9999;
1628 std::cout <<
"Error: EGammaMvaEleEstimator not properly initialized.\n";
1632 bool validKF =
false;
1642 fMVAVar_kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
1644 (validKF) ? myTrackRef->numberOfValidHits() : -1.;
1657 const auto& vCov = myEcalCluster.localCovariances(*(ele.
superCluster()->seed()));
1698 const double gsfsign = ((-ele.
gsfTrack()->dxy(
vertex.position())) >= 0) ? 1. : -1.;
1703 double ip3d = gsfsign * ip3dpv.second.value();
1704 double ip3derr = ip3dpv.second.error();
1714 Double_t tmpChargedIso_DR0p0To0p1 = 0;
1715 Double_t tmpChargedIso_DR0p1To0p2 = 0;
1716 Double_t tmpChargedIso_DR0p2To0p3 = 0;
1717 Double_t tmpChargedIso_DR0p3To0p4 = 0;
1718 Double_t tmpChargedIso_DR0p4To0p5 = 0;
1719 Double_t tmpGammaIso_DR0p0To0p1 = 0;
1720 Double_t tmpGammaIso_DR0p1To0p2 = 0;
1721 Double_t tmpGammaIso_DR0p2To0p3 = 0;
1722 Double_t tmpGammaIso_DR0p3To0p4 = 0;
1723 Double_t tmpGammaIso_DR0p4To0p5 = 0;
1724 Double_t tmpNeutralHadronIso_DR0p0To0p1 = 0;
1725 Double_t tmpNeutralHadronIso_DR0p1To0p2 = 0;
1726 Double_t tmpNeutralHadronIso_DR0p2To0p3 = 0;
1727 Double_t tmpNeutralHadronIso_DR0p3To0p4 = 0;
1728 Double_t tmpNeutralHadronIso_DR0p4To0p5 = 0;
1733 Bool_t passVeto = kTRUE;
1735 if (iP->trackRef().isNonnull()) {
1750 tmpChargedIso_DR0p0To0p1 += iP->pt();
1751 if (
dr >= 0.1 &&
dr < 0.2)
1752 tmpChargedIso_DR0p1To0p2 += iP->pt();
1753 if (
dr >= 0.2 &&
dr < 0.3)
1754 tmpChargedIso_DR0p2To0p3 += iP->pt();
1755 if (
dr >= 0.3 &&
dr < 0.4)
1756 tmpChargedIso_DR0p3To0p4 += iP->pt();
1757 if (
dr >= 0.4 &&
dr < 0.5)
1758 tmpChargedIso_DR0p4To0p5 += iP->pt();
1770 tmpGammaIso_DR0p0To0p1 += iP->pt();
1771 if (
dr >= 0.1 &&
dr < 0.2)
1772 tmpGammaIso_DR0p1To0p2 += iP->pt();
1773 if (
dr >= 0.2 &&
dr < 0.3)
1774 tmpGammaIso_DR0p2To0p3 += iP->pt();
1775 if (
dr >= 0.3 &&
dr < 0.4)
1776 tmpGammaIso_DR0p3To0p4 += iP->pt();
1777 if (
dr >= 0.4 &&
dr < 0.5)
1778 tmpGammaIso_DR0p4To0p5 += iP->pt();
1784 tmpNeutralHadronIso_DR0p0To0p1 += iP->pt();
1785 if (
dr >= 0.1 &&
dr < 0.2)
1786 tmpNeutralHadronIso_DR0p1To0p2 += iP->pt();
1787 if (
dr >= 0.2 &&
dr < 0.3)
1788 tmpNeutralHadronIso_DR0p2To0p3 += iP->pt();
1789 if (
dr >= 0.3 &&
dr < 0.4)
1790 tmpNeutralHadronIso_DR0p3To0p4 += iP->pt();
1791 if (
dr >= 0.4 &&
dr < 0.5)
1792 tmpNeutralHadronIso_DR0p4To0p5 += iP->pt();
1894 Double_t
mva = -9999;
1920 std::cout <<
"Rho : " << Rho << std::endl;