File indexing completed on 2025-08-06 08:17:47
0001
0002
0003
0004
0005
0006 #include "KFParticle_MVA.h"
0007 #include "KFParticle_Tools.h"
0008
0009 #include <KFParticle.h>
0010
0011 #include <TMVA/Reader.h> // for Reader
0012 #include <TMVA/Tools.h> // for Tools
0013
0014 #include <algorithm> // for max
0015 #include <map>
0016 #include <memory> // for allocator_traits<>::value_type
0017 #include <utility> // for pair
0018
0019 KFParticle_Tools kfpTools;
0020
0021 std::tuple<TMVA::Reader *, std::vector<Float_t>> KFParticle_MVA::initMVA()
0022 {
0023 TMVA::Tools::Instance();
0024 TMVA::Reader *reader = new TMVA::Reader("!Color:!Silent");
0025
0026 std::vector<Float_t> reader_floats;
0027
0028 for (unsigned int i = 0; i < nMVApars; ++i)
0029 {
0030 reader_floats.push_back(0);
0031 reader->AddVariable(m_mva_variable_list[i].c_str(), &reader_floats[i]);
0032 }
0033 reader->BookMVA(method.c_str(), m_mva_path.c_str());
0034
0035 return make_tuple(reader, reader_floats);
0036 }
0037
0038 Float_t KFParticle_MVA::evaluateMVA(TMVA::Reader *reader, std::vector<Float_t> reader_floats, const KFParticle &particle, const KFPVertex &vertex)
0039 {
0040 KFParticle kfpvertex(vertex);
0041 std::map<std::string, float> possibleVariables =
0042 {
0043 {"motherIPchi2", particle.GetDeviationFromVertex(kfpvertex)},
0044 {"motherFDchi2", kfpTools.flightDistanceChi2(particle, vertex)}};
0045
0046 for (unsigned int iPar = 0; iPar < nMVApars; ++iPar)
0047 {
0048 reader_floats[iPar] = possibleVariables.find(m_mva_variable_list[iPar])->second;
0049 }
0050
0051 return (Float_t) reader->EvaluateMVA(method.c_str());
0052 }