AliRoot Core  ee782a0 (ee782a0)
AliNDFunctionInterface.h
Go to the documentation of this file.
1 #ifndef AliNDFunctionInterface_H
2 #define AliNDFunctionInterface_H
3 
9 
10 #include <map>
11 class TGraph;
12 class TH1;
13 class TTreeSRedirector;
14 class THn;
15 class TObjArray;
16 
17 namespace AliNDFunctionInterface {
18  Int_t fVerbose=0;
19  template<typename T> vector<T> add_to_vector(vector<T> &z, T v);
21  template<typename T, typename... Args> vector<T> add_to_vector(vector<T> &z, T v, Args... args);
22  template<typename T, typename... Args> vector<T> make_vector(T v, Args... args);
24  std::map<int, THn*> hnMapArrayInt;
25  std::map<std::string, THn*> hnMapArrayName;
26  // THn interpolation interface
27  Double_t GetInterpolationLinear(THn * his, Double_t *xyz, Int_t verbose);
28  Double_t GetDeltaInterpolationLinear(THn * his, Double_t *xyz, Int_t dIndex, Int_t verbose);
29  // Global function interface
30  Double_t GetInterpolationLinear(Int_t index, Double_t *xyz, Int_t verbose){return GetInterpolationLinear(hnMapArrayInt[index], xyz,verbose);}
31  Double_t GetDeltaInterpolationLinear(Int_t index, Double_t *xyz, Int_t dIndex, Int_t verbose) {
32  return GetDeltaInterpolationLinear(hnMapArrayInt[index], xyz, dIndex, verbose);
33  }
34  Double_t GetInterpolationLinear(const char *name, Double_t *xyz, Int_t verbose){return GetInterpolationLinear(hnMapArrayName[name], xyz,verbose);}
35  template<typename T, typename... Args> T EvalTHnLinear(int id, T v, Args... args);
36  map<int, TMVA::MethodBase *> readerMethodBase;
38  map<int, TObjArray* > readerMethodBaseArray;
39  map<std::string, std::string> regressionMethodSetting;
40  map<std::string, TMVA::Types::EMVA> regressionMethodID;
42  void registerMethod(std::string method, std::string content, TMVA::Types::EMVA id){regressionMethodSetting[method]=content; regressionMethodID[method]=id;}
43  Int_t FitMVA(TTree *tree, const char *varFit, TCut cut, const char * variableList, const char *methodList, const char *weights=NULL, Int_t index=-1);
44  TMVA::MethodBase * LoadMVAReader(Int_t id, const char * inputFile, const char *method, const char *dir);
45  Int_t LoadMVAReaderArray(Int_t id, const char * inputFile, const char *methodMask, const char *dirMask);
46  Int_t AppendMethodToArray(Int_t index, TMVA::MethodBase * method);
47  Double_t EvalMVAStatArray(int id, int statType, vector<float> point);
48  template<typename T, typename... Args> T EvalMVA(int id, T v, Args... args);
49  template<typename T, typename... Args> T EvalMVAStat(int id, int statType, T v, Args... args);
50 
51 };
52 
53 
55 template<typename T> vector<T> AliNDFunctionInterface::add_to_vector(vector<T> &z, T v) {z.push_back(v); return z;}
56 template<typename T, typename... Args> vector<T> AliNDFunctionInterface::add_to_vector(vector<T> &z, T v, Args... args) {
57  z.push_back(v);return add_to_vector<T>(z, args...);
58 }
70 template<typename T, typename... Args> vector<T> AliNDFunctionInterface::make_vector(T v, Args... args) {
71  vector<T> z; z.push_back(v); return add_to_vector<T>(z, args...);
72 }
73 
88 template<typename T, typename... Args> T AliNDFunctionInterface::EvalTHnLinear(int id, T v, Args... args){
89  auto a = make_vector<double>(v, args...);
90  THn *his = hnMapArrayInt[id];
91  if (his!=NULL) return GetInterpolationLinear(his, a.data(), 0);
92  return 0;
93 };
94 
95 
111 template<typename T, typename... Args> T AliNDFunctionInterface::EvalMVA(int id, T v, Args... args){
112  auto a = make_vector<float>(v, args...);
113  TMVA::Event event = TMVA::Event(a,a.size());
114  TMVA::MethodBase * method= readerMethodBase[id];
115  if (method==NULL) return 0;
116  return method->GetRegressionValues(&event)[0];
117 };
118 
119 
136 template<typename T, typename... Args> T AliNDFunctionInterface::EvalMVAStat(int id, int statType, T v, Args... args) {
137  auto a = make_vector<float>(v, args...);
138  return EvalMVAStatArray(id,statType,a);
139 };
140 
141 #endif
142 
map< int, TMVA::MethodBase * > readerMethodBase
TMVA interface.
map< std::string, TMVA::Types::EMVA > regressionMethodID
map of registered TMVA regression methods
Int_t AppendMethodToArray(Int_t index, TMVA::MethodBase *method)
Register TMVA method to the array at index Not assumed to be used by users.
#define TObjArray
Double_t GetDeltaInterpolationLinear(THn *his, Double_t *xyz, Int_t dIndex, Int_t verbose)
Linear interpolation of the numerical derivative dV/dx (V(i+1)-V(i-1))/(2(delta) ...
Double_t GetInterpolationLinear(THn *his, Double_t *xyz, Int_t verbose)
Linear interpolation of the bin content.
vector< T > add_to_vector(vector< T > &z, T v)
generic variadic function - to get it from boost in the future
T EvalMVAStat(int id, int statType, T v, Args...args)
variadic function evaluating MVA
TTree * tree
Interface to Ndimension functional representations (THn and TMVA)
map< std::string, std::string > regressionMethodSetting
map of registered array of TMVA::MethodBase - used to define TMVA statistics (Mean, Median, RMS, quantiles)
Int_t LoadMVAReaderArray(Int_t id, const char *inputFile, const char *methodMask, const char *dirMask)
T EvalMVA(int id, T v, Args...args)
Evaluate statistic.
T EvalTHnLinear(int id, T v, Args...args)
TMVA::MethodBase * LoadMVAReader(Int_t id, const char *inputFile, const char *method, const char *dir)
MVA regression.
void registerMethod(std::string method, std::string content, TMVA::Types::EMVA id)
example registering default methods ()
map< int, TObjArray * > readerMethodBaseArray
map of registered TMVA::MethodBase
TCut cut
Definition: MakeGlobalFit.C:75
std::map< std::string, THn * > hnMapArrayName
void registerDefaultMVAMethods()
map of registered TMVA regression methods
std::map< int, THn * > hnMapArrayInt
vector< T > make_vector(T v, Args...args)
Variadic function to create an vector (boost implementation )
Double_t EvalMVAStatArray(int id, int statType, vector< float > point)
Append method into array of methods - used e.g for bootstrap statistics.
Int_t FitMVA(TTree *tree, const char *varFit, TCut cut, const char *variableList, const char *methodList, const char *weights=NULL, Int_t index=-1)