Analysis Software
Documentation for sPHENIX simulation 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 <TMVA/Reader.h> // for Reader
13 #include <TMVA/Tools.h> // for Tools
14 
15 #include <algorithm> // for max
16 #include <map>
17 #include <memory> // for allocator_traits<>::value_type
18 #include <utility> // for pair
19 
21 
22 std::tuple<TMVA::Reader *, std::vector<Float_t>> KFParticle_MVA::initMVA()
23 {
24  TMVA::Tools::Instance(); // Start TMVA
25  TMVA::Reader *reader = new TMVA::Reader("!Color:!Silent");
26 
27  std::vector<Float_t> reader_floats;
28 
29  for (unsigned int i = 0; i < nMVApars; ++i)
30  {
31  reader_floats.push_back(0);
32  reader->AddVariable(m_mva_variable_list[i].c_str(), &reader_floats[i]);
33  }
34  reader->BookMVA(method.c_str(), m_mva_path.c_str());
35 
36  return make_tuple(reader, reader_floats);
37 }
38 
39 Float_t KFParticle_MVA::evaluateMVA(TMVA::Reader *reader, std::vector<Float_t> reader_floats, const KFParticle &particle, const KFPVertex &vertex)
40 {
41  KFParticle kfpvertex(vertex);
42  std::map<std::string, float> possibleVariables =
43  {
44  {"motherIPchi2", particle.GetDeviationFromVertex(kfpvertex)},
45  {"motherFDchi2", kfpTools.flightDistanceChi2(particle, vertex)}};
46 
47  for (unsigned int iPar = 0; iPar < nMVApars; ++iPar)
48  {
49  reader_floats[iPar] = possibleVariables.find(m_mva_variable_list[iPar])->second;
50  }
51 
52  return (Float_t) reader->EvaluateMVA(method.c_str());
53 }