10 #include "TMVA/Config.h"
22 m_BDTVarKey(Def::
NONE)
28 ATH_MSG_DEBUG(
"Initializing DecoratePromptLeptonImproved...");
47 ATH_CHECK(m_primaryVertexKey.initialize());
48 ATH_CHECK(m_clusterContainerKey.initialize());
55 ATH_MSG_DEBUG(
"Number of int vars to read: " << m_stringIntVars.size());
56 ATH_MSG_DEBUG(
"Number of float vars to read: " << m_stringFloatVars.size());
59 m_vars = std::make_unique<Prompt::VarHolder>();
64 m_intVars = m_vars->readVectorVars(m_stringIntVars);
65 m_floatVars = m_vars->readVectorVars(m_stringFloatVars);
67 m_allVars.insert(m_allVars.end(), m_intVars .begin(), m_intVars .end());
68 m_allVars.insert(m_allVars.end(), m_floatVars.begin(), m_floatVars.end());
70 m_varTMVA.resize(m_allVars.size());
76 m_BDTVarKey = m_vars->registerDynamicVar(m_BDTName);
79 ATH_MSG_ERROR(
"Failed to create key for BDT name=" << m_BDTName);
80 return StatusCode::FAILURE;
91 initializeConstAccessors();
102 return StatusCode::SUCCESS;
114 ATH_MSG_INFO(
"Real time: " << m_timerAll.RealTime() <<
"\t CPU time: " << m_timerAll.CpuTime());
121 return StatusCode::SUCCESS;
142 <<
"\n\t\t\t Size of vertex container: " << vertices ->
size()
143 <<
"\n\t\t\t Size of track jet container: " << trackJets->
size()
144 <<
"\n-----------------------------------------------------------------");
158 if(m_leptonsName ==
"Electrons") {
166 decorateElec(*elec, *trackJets, *
clusters, primaryVertex);
168 }
else if(m_leptonsName ==
"Muons") {
176 decorateMuon(*
muon, *trackJets, primaryVertex);
181 return StatusCode::FAILURE;
184 return StatusCode::SUCCESS;
194 m_TMVAReader = std::make_unique<TMVA::Reader>();
196 for(
unsigned i = 0;
i < m_allVars.size(); ++
i) {
197 m_TMVAReader->AddVariable(m_vars->asStr(m_allVars.at(
i)), &m_varTMVA[
i]);
204 + m_configFileVersion
205 +
"/TMVAClassification_" + m_methodTitleMVA +
".weights.xml");
207 if(!m_configPathOverride.empty()) {
209 fullPathToFile = m_configPathOverride;
212 ATH_MSG_INFO(
"TMVA configuration file: " + fullPathToFile);
218 if(fullPathToFile ==
"") {
223 m_TMVAReader->BookMVA(m_methodTitleMVA.toString(), fullPathToFile);
239 if(!m_shortMap.insert(shortDecoratorMap::value_type(
var, shortDecorator)).second) {
240 ATH_MSG_ERROR(
"Instantiation of Decorator class failed for short decorator map for var: " << m_vars->asStr(
var));
241 return StatusCode::FAILURE;
251 if(!m_floatMap.insert(floatDecoratorMap::value_type(
var, floatDecorator)).second) {
252 ATH_MSG_ERROR(
"Instantiation of Decorator class failed for float decorator map for var: " << m_vars->asStr(
var));
253 return StatusCode::FAILURE;
261 ATH_MSG_ERROR(
"Failed to add variable: " << m_vars->asStr(m_BDTVarKey));
262 return StatusCode::FAILURE;
265 for(
const std::string &evar: m_extraDecoratorFloatVars) {
266 const Def::Var ekey = m_vars->registerDynamicVar(evar);
269 ATH_MSG_ERROR(
"Failed to create key for variable name=" << evar);
270 return StatusCode::FAILURE;
273 if(m_floatMap.find(ekey) != m_floatMap.end()) {
280 return StatusCode::FAILURE;
284 for(
const std::string &evar: m_extraDecoratorShortVars) {
285 const Def::Var ekey = m_vars->registerDynamicVar(evar);
288 ATH_MSG_ERROR(
"Failed to create key for variable name=" << evar);
289 return StatusCode::FAILURE;
292 if(m_shortMap.find(ekey) != m_shortMap.end()) {
299 return StatusCode::FAILURE;
306 for(
const std::string &vvar: m_vetoDecoratorFloatVars) {
307 const Def::Var vkey = m_vars->registerDynamicVar(vvar);
310 ATH_MSG_ERROR(
"Failed to create key for variable name=" << vvar);
311 return StatusCode::FAILURE;
316 if(iter != m_floatMap.end()) {
317 ATH_MSG_DEBUG(
"Remove the variable from the veto-list, name=" << vvar);
318 m_floatMap.erase(iter);
322 for(
const std::string &vvar: m_vetoDecoratorShortVars) {
323 const Def::Var vkey = m_vars->registerDynamicVar(vvar);
326 ATH_MSG_ERROR(
"Failed to create key for variable name=" << vvar);
327 return StatusCode::FAILURE;
332 if(iter != m_shortMap.end()) {
333 ATH_MSG_DEBUG(
"Remove the variable from the veto-list, name=" << vvar);
334 m_shortMap.erase(iter);
339 ATH_MSG_DEBUG(
"Added " << m_shortMap.size() <<
" short decorators");
340 ATH_MSG_DEBUG(
"Added " << m_floatMap.size() <<
" float decorators");
343 if(m_leptonPtBinsVector.size() < 2) {
344 ATH_MSG_ERROR(
"Invalid PtBins size=" << m_leptonPtBinsVector.size());
345 return StatusCode::FAILURE;
348 std::unique_ptr<double []> PtBins = std::make_unique<double []>(m_leptonPtBinsVector.size());
350 for(
unsigned i = 0;
i < m_leptonPtBinsVector.size();
i++) {
351 PtBins[
i] = m_leptonPtBinsVector[
i];
354 m_leptonPtBinHist = std::make_unique<TH1D>(
"PtBin",
"PtBin", m_leptonPtBinsVector.size() - 1, PtBins.get());
356 return StatusCode::SUCCESS;
365 m_accessCalIsolation30 = std::make_unique<AccessFloat> (
"topoetcone30");
366 m_accessTrackIsolation30 = std::make_unique<AccessFloat> (
"ptvarcone30");
367 m_accessTrackIsolation30TTVA = std::make_unique<AccessFloat> (
"ptvarcone30_Nonprompt_All_MaxWeightTTVA_pt500");
369 m_accessDeepSecondaryVertex = std::make_unique<AccessVertex>(m_vertexLinkName);
374 m_accessMuonCalE = std::make_unique<AccessFloat> (
"calE");
375 m_accessMuonParamEnergyLoss = std::make_unique<AccessFloat> (
"ParamEnergyLoss");
380 for(
const std::string &
name: m_accessorRNNVars) {
407 std::pair<double, const xAOD::Jet*>
match = findTrackJet(
electron, trackJets);
429 fillVarDefault(vars);
455 std::pair<double, const xAOD::Jet*>
match = findTrackJet(
muon, trackJets);
461 getMuonAnpVariables(
muon, vars, primaryVertex);
466 getMutualVariables(
muon, *
match.second,
muon.primaryTrackParticle(), vars);
477 fillVarDefault(vars);
485 decorateAuxLepton(
muon, vars);
506 const double deta = elec_calEta - cluster->eta();
508 const double dr = std::sqrt(deta*deta + dphi*dphi);
510 if(
dr < m_elecMinCalErelConeSize) {
511 sumCoreEt_large += cluster->pt();
523 const double Topoetcone30rel = accessIsolation(*m_accessCalIsolation30, elec);
524 const double Ptvarcone30rel = accessIsolation(*m_accessTrackIsolation30, elec);
532 std::vector<double> goodVertexNdistLong;
534 if(m_accessDeepSecondaryVertex->isAvailable(elec)) {
535 std::vector<ElementLink<xAOD::VertexContainer> > vtxLinks = (*m_accessDeepSecondaryVertex)(elec);
538 if(!vtxLink.isValid()) {
547 if(fitProb < m_vertexMinChiSquaredProb) {
551 const double theta = std::acos(getVertexCosThetaWithLepDir(elec, vtx, primaryVertex));
553 if (theta < m_vertexMinThetaBarrElec && std::fabs(elec.
eta()) <= m_vertexBarrEcapAbsEtaAt)
continue;
554 else if (theta < m_vertexMinThetaEcapElec && std::fabs(elec.
eta()) > m_vertexBarrEcapAbsEtaAt)
continue;
556 const double vertex_ndist_long = getVertexLongitudinalNormDist(elec, vtx, primaryVertex);
558 goodVertexNdistLong.push_back(vertex_ndist_long);
562 ATH_MSG_WARNING(
"VertexContainer : " << m_vertexLinkName <<
" not found for the electron");
565 double best_vertex_ndist_long = 0.0;
567 if(goodVertexNdistLong.size() > 0) {
568 std::sort(goodVertexNdistLong.begin(), goodVertexNdistLong.end());
569 best_vertex_ndist_long = goodVertexNdistLong.back();
586 double calE = -99.0, peloss = -99.0, caloClusterERel = -99.0;
588 if(
muon.clusterLink().isValid()) {
591 if(m_accessMuonCalE->isAvailable(*cluster) && m_accessMuonParamEnergyLoss->isAvailable(
muon)) {
592 calE = (*m_accessMuonCalE)(*cluster);
593 peloss = (*m_accessMuonParamEnergyLoss)(
muon);
595 caloClusterERel = calE/peloss;
598 ATH_MSG_WARNING(
"Muon calE or ParamEnergyLoss not found in auxiliary store");
608 const double ptvarcone30TightTTVAPt500rel = accessIsolation(*m_accessTrackIsolation30TTVA,
muon);
616 std::vector<double> goodVertexNdistLong;
618 if(m_accessDeepSecondaryVertex->isAvailable(
muon)) {
619 std::vector<ElementLink<xAOD::VertexContainer> > vtxLinks = (*m_accessDeepSecondaryVertex)(
muon);
620 goodVertexNdistLong.reserve(vtxLinks.size());
623 if(!vtxLink.isValid()) {
632 if(fitProb > m_vertexMinChiSquaredProb) {
633 const double vertex_ndist_long = getVertexLongitudinalNormDist(
muon, vtx, primaryVertex);
635 goodVertexNdistLong.push_back(vertex_ndist_long);
640 ATH_MSG_WARNING(
"VertexContainer : " << m_vertexLinkName <<
" not found for the muon");
643 double best_vertex_ndist_long = 0.0;
645 if(goodVertexNdistLong.size() > 0) {
646 std::sort(goodVertexNdistLong.begin(), goodVertexNdistLong.end());
647 best_vertex_ndist_long = goodVertexNdistLong.back();
668 if(
particle.pt() > 0.0 && track_jet.
pt() > 0.0) {
674 const double angle =
particle.p4().Vect().Angle(track_jet.
p4().Vect());
690 for(floatAccessorMap::value_type &
acc: m_accessRNNMap) {
704 const double xmax = m_leptonPtBinHist->GetXaxis()->GetXmax();
705 const double xmin = m_leptonPtBinHist->GetXaxis()->GetXmin();
710 curr_bin = m_leptonPtBinHist->FindBin(lepPt);
712 else if (!(lepPt <
xmax)) {
713 curr_bin = m_leptonPtBinHist->GetNbinsX();
715 else if (!(lepPt >
xmin)) {
722 ATH_MSG_DEBUG(
"getMutualVariables - lepPt = " << lepPt <<
", MVAXBin = " << curr_bin);
730 double isolation = -99., isolationrel = -99.;
740 isolationrel = isolation /
particle.pt();
752 for(
unsigned i = 0;
i < m_allVars.size(); ++
i) {
755 if(!vars.
getVar(m_allVars.at(
i), m_varTMVA[
i])) {
756 ATH_MSG_WARNING(
"Missing input variable: " << m_vars->asStr(m_allVars.at(
i)));
763 float bdt_weight = m_TMVAReader->EvaluateMVA(m_methodTitleMVA.toString());
766 vars.
addVar(m_BDTVarKey, bdt_weight);
769 ATH_MSG_WARNING(
"addVarsToTMVA - invalid Def::Var key for " << m_BDTName);
779 for(
const floatDecoratorMap::value_type &dec: m_floatMap) {
780 vars.
addVar(dec.first, -99.0);
783 for(
const shortDecoratorMap::value_type &dec: m_shortMap) {
784 vars.
addVar(dec.first, -99.0);
797 for(shortDecoratorMap::value_type &dec: m_shortMap) {
813 for(floatDecoratorMap::value_type &dec: m_floatMap) {
836 std::pair<double, const xAOD::Jet*>
match(mindr, minjet);
839 const double dr =
part.p4().DeltaR(
jet->p4());
841 if(!minjet ||
dr < mindr) {
844 match = std::make_pair(mindr, minjet);
849 if(minjet && mindr < m_maxLepTrackJetDR) {
854 return std::make_pair(10., minjet);
867 if(!secondaryVertex || !primaryVertex) {
868 ATH_MSG_WARNING(
"getVertexLongitudinalNormDist - invalid pointer of lepton/secondaryVertex/primaryVertex");
873 float normDist_SVPV = 0.0;
876 ATH_MSG_WARNING(
"getVertexLongitudinalNormDist - missing \"normDistToPriVtx\"");
879 double cos_theta = getVertexCosThetaWithLepDir(lepton, secondaryVertex, primaryVertex);
881 return normDist_SVPV*cos_theta;
892 if(!secondaryVertex || !primaryVertex) {
893 ATH_MSG_WARNING(
"GetVertexThetaWithLepDir - invalid pointer of lepton/secondaryVertex/primaryVertex");
899 const TVector3 sv_to_pv_t3 = TVector3(sv_to_pv_v3.x(), sv_to_pv_v3.y(), sv_to_pv_v3.z());
900 const TVector3 lepton_dirt = lepton.
p4().Vect();
902 const double cos_theta = sv_to_pv_t3.Unit()*lepton_dirt.Unit();