EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFParticle_MVA.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFParticle_MVA.cc
1 /**********************************/
2 /* Program to arrange, init, */
3 /* and calc an MVA response */
4 /* Cameron Dean, LANL, 06/15/20 */
5 /**********************************/
6 #include "KFParticle_MVA.h"
7 #include "KFParticle_Tools.h"
8 
9 #include <KFPVertex.h>
10 #include <KFParticle.h>
11 
12 #include <map>
13 
15 
16 std::tuple<TMVA::Reader *, std::vector<Float_t>> KFParticle_MVA::initMVA()
17 {
18  TMVA::Tools::Instance(); //Start TMVA
19  TMVA::Reader *reader = new TMVA::Reader("!Color:!Silent");
20 
21  std::vector<Float_t> reader_floats;
22 
23  for (unsigned int i = 0; i < nMVApars; ++i)
24  {
25  reader_floats.push_back(0);
26  reader->AddVariable(m_mva_variable_list[i].c_str(), &reader_floats[i]);
27  }
28  reader->BookMVA(method.c_str(), m_mva_path.c_str());
29 
30  return make_tuple(reader, reader_floats);
31 }
32 
33 Float_t KFParticle_MVA::evaluateMVA(TMVA::Reader *reader, std::vector<Float_t> reader_floats, KFParticle particle, KFPVertex vertex)
34 {
35  KFParticle kfpvertex(vertex);
36  std::map<std::string, float> possibleVariables =
37  {
38  {"motherIPchi2", particle.GetDeviationFromVertex(kfpvertex)},
39  {"motherFDchi2", kfpTools.flightDistanceChi2(particle, vertex)}};
40 
41  for (unsigned int iPar = 0; iPar < nMVApars; ++iPar) reader_floats[iPar] = possibleVariables.find(m_mva_variable_list[iPar])->second;
42 
43  return (Float_t) reader->EvaluateMVA(method.c_str());
44 }