AliRoot Core  3dc7879 (3dc7879)
AliNDFunctionInterface Namespace Reference

Interface to N-dimensional functional representations (THn and TMVA) More...

Functions

template<typename T >
vector< T > add_to_vector (vector< T > &z, T v)
 generic variadic function - to get it from boost in the future More...
 
template<typename T , typename... Args>
vector< T > add_to_vector (vector< T > &z, T v, Args...args)
 
template<typename T , typename... Args>
vector< T > make_vector (T v, Args...args)
 Variadic function to create an vector (boost implementation ) More...
 
Double_t GetInterpolationLinear (THn *his, Double_t *xyz, Int_t verbose)
 Linear interpolation of the bin content. More...
 
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) More...
 
Double_t GetInterpolationLinear (Int_t index, Double_t *xyz, Int_t verbose)
 
Double_t GetDeltaInterpolationLinear (Int_t index, Double_t *xyz, Int_t dIndex, Int_t verbose)
 
Double_t GetInterpolationLinear (const char *name, Double_t *xyz, Int_t verbose)
 
template<typename T , typename... Args>
EvalTHnLinear (int id, T v, Args...args)
 
void registerDefaultMVAMethods ()
 map of registered TMVA regression methods More...
 
void registerFactory (std::string factory, std::string content)
 example registering default methods () More...
 
void registerMethod (std::string method, std::string content, TMVA::Types::EMVA id)
 
Int_t FitMVAClassification (const char *output, const char *inputTrees, const char *cuts, const char *variableList, const char *methodList, const char *factoryString="")
 
Int_t FitMVARegression (const char *output, TTree *tree, const char *varFit, TCut cut, const char *variables, const char *methods, const char *factoryString="")
 MVA Classification. More...
 
TMVA::MethodBase * LoadMVAReader (Int_t id, const char *inputFile, const char *method, const char *dir)
 new MVA Regression More...
 
Int_t LoadMVAReaderArray (Int_t id, const char *inputFile, const char *methodMask, const char *dirMask)
 
Int_t AppendMethodToArray (Int_t index, TMVA::MethodBase *method)
 Register TMVA method to the array at index Not assumed to be used by users. More...
 
Double_t EvalMVAStatArray (int id, int statType, vector< float > point)
 Append method into array of methods - used e.g for bootstrap statistics. More...
 
template<typename T , typename... Args>
EvalMVA (int id, T v, Args...args)
 Evaluate statistic. More...
 
template<typename T , typename... Args>
EvalMVAClasification (int id, T v, Args...args)
 variadic function evaluating MVA More...
 
template<typename T , typename... Args>
EvalMVAStat (int id, int statType, T v, Args...args)
 variadic function evaluating MVA More...
 

Variables

Int_t fVerbose =0
 
std::map< int, THn * > hnMapArrayInt
 
std::map< std::string, THn * > hnMapArrayName
 
map< int, TMVA::MethodBase * > readerMethodBase
 TMVA interface. More...
 
map< int, TObjArray * > readerMethodBaseArray
 map of registered TMVA::MethodBase More...
 
map< std::string, std::string > regressionMethodSetting
 map of registered array of TMVA::MethodBase - used to define TMVA statistics (Mean, Median, RMS, quantile) More...
 
map< std::string, std::string > FactorySetting
 map of registered TMVA regression methods More...
 
map< std::string, TMVA::Types::EMVA > regressionMethodID
 map of registered TMVA regression methods More...
 

Detailed Description

Interface to N-dimensional functional representations (THn and TMVA)

Authors
Marian Ivanov maria.nosp@m.n.iv.nosp@m.anov@.nosp@m.cern.nosp@m..ch see example usage in

Function Documentation

template<typename T >
vector< T > AliNDFunctionInterface::add_to_vector ( vector< T > &  z,
v 
)

generic variadic function - to get it from boost in the future

Helper function to create std vector in variadic function.

verbosity

Definition at line 58 of file AliNDFunctionInterface.h.

template<typename T , typename... Args>
vector< T > AliNDFunctionInterface::add_to_vector ( vector< T > &  z,
v,
Args...  args 
)

Definition at line 59 of file AliNDFunctionInterface.h.

Int_t AliNDFunctionInterface::AppendMethodToArray ( Int_t  index,
TMVA::MethodBase *  method 
)

Register TMVA method to the array at index Not assumed to be used by users.

Parameters
index- registered array index
method- pointer to the method
Returns

Definition at line 471 of file AliNDFunctionInterface.cxx.

Referenced by LoadMVAReaderArray(), and registerMethod().

template<typename T , typename... Args>
T AliNDFunctionInterface::EvalMVA ( int  id,
v,
Args...  args 
)

Evaluate statistic.

Variadic function to evaluate MVA regression method registered using method ID.

Template Parameters
T
Args
Parameters
id
v
args
Returns

Example usage:

  • usage in TTreeFormula. e.g calculate and visualize second derivative of regression
    MVAInput->Draw("AliNDFunctionInterface::EvalMVA(0,fraction,Z,0)-(AliNDFunctionInterface::EvalMVA(0,fraction,Z-1,0)+AliNDFunctionInterface::EvalMVA(0,fraction,Z+1,0))*0.5:Z","Z>2&&fraction>5","");

some optional verbosity needed

Definition at line 114 of file AliNDFunctionInterface.h.

Referenced by registerMethod().

template<typename T , typename... Args>
T AliNDFunctionInterface::EvalMVAClasification ( int  id,
v,
Args...  args 
)

variadic function evaluating MVA

some optional verbosity needed

Definition at line 122 of file AliNDFunctionInterface.h.

Referenced by registerMethod().

template<typename T , typename... Args>
T AliNDFunctionInterface::EvalMVAStat ( int  id,
int  statType,
v,
Args...  args 
)

variadic function evaluating MVA

Template variadic function - Evaluate statistic on top of array (readerMethodBaseArray;) of MVA methods To use the method - array o TMVA methods should be registered before using LoadMVAReaderArray or AppendMethodToArray

Template Parameters
T- template type - be default float
Args-
Parameters
id- id of the registered array to evaluate
statType- type of statistic (0-mean, 1-median, 2-rms)
v-
args
Returns

Example usage:

  • compare mean and median statistic of array 2
    MVAInput->Draw("AliNDFunctionInterface::EvalMVAStat(2,0,interactionRate, bz0, qmaxQASum, qmaxQASumR):AliNDFunctionInterface::EvalMVAStat(2,1,interactionRate, bz0, qmaxQASum, qmaxQASumR)","run==QA.EVS.run","");

variadic function evaluating MVA array stat

Definition at line 147 of file AliNDFunctionInterface.h.

Referenced by registerMethod().

Double_t AliNDFunctionInterface::EvalMVAStatArray ( int  id,
int  statType,
vector< float >  point 
)

Append method into array of methods - used e.g for bootstrap statistics.

Return statistic variable using array of MVA methods

Parameters
id- id of the TMVA method array
statType- type of the statistic (mean, median, rms, TODO cumulant)
point- point to evaluate
Returns
- requested statistic

TODO:

TODO - for the moment in evaluation we assume only one variable

  • using the DNN or MLP we should start to support vectors TODO - extend statistic list

some optional verbosity needed

Definition at line 491 of file AliNDFunctionInterface.cxx.

Referenced by EvalMVAStat(), and registerMethod().

template<typename T , typename... Args>
T AliNDFunctionInterface::EvalTHnLinear ( int  id,
v,
Args...  args 
)

Variadic function to linearly interpolate THn

Template Parameters
T- template type
Args- list of arguments
Parameters
id- id of the function (e.g using hash of the name)
v
args
Returns
interpolated value

Example usage:

Definition at line 91 of file AliNDFunctionInterface.h.

Referenced by GetInterpolationLinear().

Int_t AliNDFunctionInterface::FitMVAClassification ( const char *  output,
const char *  inputTrees,
const char *  cuts,
const char *  variables,
const char *  methods,
const char *  factoryString = "" 
)

FitMVAClassification - TODO add documentation and test

Parameters
output
inputTrees
cuts
variables
methods
factoryString
Returns

Write ascii weight files to root file

Definition at line 138 of file AliNDFunctionInterface.cxx.

Referenced by registerMethod().

Int_t AliNDFunctionInterface::FitMVARegression ( const char *  output,
TTree *  tree,
const char *  varFit,
TCut  cut,
const char *  variables,
const char *  methods,
const char *  factoryString = "" 
)

MVA Classification.

FitMVARegression wrapper = Do TMVA regression and save weights into output root file

Parameters
output- output path <file>#directory/
  • output file is opened in update mode - in case key (directory) exist - fit should failed - data are not written (currently it failed)
tree- input tree
varFit- variable to fit (for the moment 1)
cut- cut formula
variables- : separated list of explanatory variables
methods- : separated list of the regression methods (have to be registered before)
factoryString- factory string (e.g specifying number of training and test samples). Factory string to be registered before. If empty default used

- Fit parameters will be saved in the output destination - return value 0 in case of success Example usage in test macro ( QAtrendingFitExample.C function makeMVAFits() and makeMVABootstrapMI() ), e.g:

TString output="TMVA_RegressionOutput.root#";
for (Int_t iBoot=0; iBoot<nRegression; iBoot++) {
AliNDFunctionInterface::FitMVARegression(output+"resolutionMIP"+iBoot,treeCache, "resolutionMIP", "interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR", "BDTRF25_8:BDTRF12_16:KNN", "");
AliNDFunctionInterface::FitMVARegression(output+"meanMIPeleR"+iBoot,treeCache, "meanMIPeleR", "interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR", "BDTRF25_8:BDTRF12_16:KNN","");
AliNDFunctionInterface::FitMVARegression(output+"tpcItsMatchA"+iBoot,treeCache, "tpcItsMatchA", "interactionRate>0", "interactionRate:bz0:qmaxQASum:qmaxQASumR", "BDTRF25_8:BDTRF12_16:KNN","");
}

Algorithm:

  • 0. Declare Factory
  • 1.) Declare DataLoader

TODO check existence - validity of variable - in case of error - exit with error message

  • 3.) Setup DataSet
  • 4.) Book regression methods from the methods list
  • 5.) Train all methods
  • 6.) Write ascii weight files to root file
  • 7.) Evaluate all MVAs using the set of test events /// TODO - make an option
  • 8.) Evaluate and compare performance of all configured MVAs /// TODO - make an option
  • Save the output

Definition at line 272 of file AliNDFunctionInterface.cxx.

Referenced by makeMVABootstrapMI(), and registerMethod().

Double_t AliNDFunctionInterface::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)

Parameters
his
xyz
dIndex
verbose
Returns

Definition at line 85 of file AliNDFunctionInterface.cxx.

Referenced by GetDeltaInterpolationLinear().

Double_t AliNDFunctionInterface::GetDeltaInterpolationLinear ( Int_t  index,
Double_t *  xyz,
Int_t  dIndex,
Int_t  verbose 
)

Definition at line 31 of file AliNDFunctionInterface.h.

Double_t AliNDFunctionInterface::GetInterpolationLinear ( THn *  his,
Double_t *  xyz,
Int_t  verbose 
)

Linear interpolation of the bin content.

Parameters
his- input N-dimensional histogram to interpolate
xyz- NDimensional point where to interpolate
verbose- verbosity flag
Returns

Definition at line 52 of file AliNDFunctionInterface.cxx.

Referenced by EvalTHnLinear(), and GetInterpolationLinear().

Double_t AliNDFunctionInterface::GetInterpolationLinear ( Int_t  index,
Double_t *  xyz,
Int_t  verbose 
)

Definition at line 30 of file AliNDFunctionInterface.h.

Double_t AliNDFunctionInterface::GetInterpolationLinear ( const char *  name,
Double_t *  xyz,
Int_t  verbose 
)

Definition at line 34 of file AliNDFunctionInterface.h.

TMVA::MethodBase * AliNDFunctionInterface::LoadMVAReader ( Int_t  id,
const char *  inputFile,
const char *  method,
const char *  dir 
)

new MVA Regression

Load MVA regression object and register it in the map of available readers fr evaluation in TFormula Current ION of TMVA does not allow standard persistence in root file Way around: Writing - ASCII files are stored as TSting in the root file Reading - String written as ASCII file and read back by TMVA::Reader

Parameters
id- regression method ID (using e.g. hash value)
inputFile- input file (e.g TMVA_RegressionOutput.root)
method- method name (e.g MLP)
dir- directory usually coding regression variable with dir_ prefix (e.g. dir_meanMIPele)
Returns
- error code

TODOs:

  • TODO - ASK TMVA team to implement standard IO
  • TODO - ASK TMVA team to disable requirement to set variable addresses or find switch to make it

Example usage (see also QAtrendingFitExample.C loadMVAReaders()):

AliNDFunctionInterface::LoadMVAReader(0,"TMVA_RegressionOutput.root","BDTRF25_8","resolutionMIP0");
AliNDFunctionInterface::LoadMVAReader(1,"TMVA_RegressionOutput.root","BDTRF12_16","resolutionMIP0");
AliNDFunctionInterface::LoadMVAReader(2,"TMVA_RegressionOutput.root","KNN","resolutionMIP0");
}

TODO check existence - validity of variable - in case of error - exit with error message

write weight from the root file to txt files as it is expected by reader

Definition at line 371 of file AliNDFunctionInterface.cxx.

Referenced by LoadMVAReaderArray(), loadMVAReaders(), and registerMethod().

Int_t AliNDFunctionInterface::LoadMVAReaderArray ( Int_t  id,
const char *  inputFile,
const char *  methodMask,
const char *  dirMask 
)

Load array of the MVA reader and register it in the AliNDFunctionInterface method array maps ( readerMethodBaseArray) Method arrays could be later use for the TMVA array evaluation ()

Parameters
id
inputFile
methodMask
dirMask
Returns
error code - 0 mean OK

Example usage in (see also QAtrendingFitExample.C loadMVAReadersBootstrap())

AliNDFunctionInterface::LoadMVAReaderArray(0,"TMVA_RegressionOutput.root","BDTRF12_16",".*resolutionMIP");
AliNDFunctionInterface::LoadMVAReaderArray(1,"TMVA_RegressionOutput.root","BDTRF25_8",".*resolutionMIP");
AliNDFunctionInterface::LoadMVAReaderArray(2,"TMVA_RegressionOutput.root","KNN",".*resolutionMIP");
}

Definition at line 436 of file AliNDFunctionInterface.cxx.

Referenced by loadMVAReadersBootstrap(), and registerMethod().

template<typename T , typename... Args>
vector< T > AliNDFunctionInterface::make_vector ( v,
Args...  args 
)

Variadic function to create an vector (boost implementation )

Template Parameters
T- template type
Args- list of arguments
Parameters
v
args
Returns

Example usage: to create vector of integers to create vector with 3 integers

auto a = AliNDFunctionInterface::make_vector<int>(1, 1, 3);

Definition at line 73 of file AliNDFunctionInterface.h.

void AliNDFunctionInterface::registerDefaultMVAMethods ( )

map of registered TMVA regression methods

Register example MVA methods.

Definition at line 510 of file AliNDFunctionInterface.cxx.

void AliNDFunctionInterface::registerFactory ( std::string  factory,
std::string  content 
)

example registering default methods ()

Definition at line 43 of file AliNDFunctionInterface.h.

void AliNDFunctionInterface::registerMethod ( std::string  method,
std::string  content,
TMVA::Types::EMVA  id 
)

Definition at line 44 of file AliNDFunctionInterface.h.

Referenced by registerDefaultMVAMethods(), and RegisterFitters().

Variable Documentation

map<std::string, std::string> AliNDFunctionInterface::FactorySetting

map of registered TMVA regression methods

Definition at line 40 of file AliNDFunctionInterface.h.

Referenced by FitMVAClassification(), and FitMVARegression().

Int_t AliNDFunctionInterface::fVerbose =0
std::map<int, THn*> AliNDFunctionInterface::hnMapArrayInt

Definition at line 24 of file AliNDFunctionInterface.h.

Referenced by EvalTHnLinear().

std::map<std::string, THn*> AliNDFunctionInterface::hnMapArrayName

Definition at line 25 of file AliNDFunctionInterface.h.

map<int, TMVA::MethodBase *> AliNDFunctionInterface::readerMethodBase

TMVA interface.

variadic function evaluating THn

Definition at line 37 of file AliNDFunctionInterface.h.

Referenced by EvalMVA(), EvalMVAClasification(), GetInterpolationLinear(), and LoadMVAReader().

map<int, TObjArray* > AliNDFunctionInterface::readerMethodBaseArray

map of registered TMVA::MethodBase

Definition at line 38 of file AliNDFunctionInterface.h.

Referenced by AppendMethodToArray(), and EvalMVAStatArray().

map<std::string, TMVA::Types::EMVA> AliNDFunctionInterface::regressionMethodID

map of registered TMVA regression methods

Definition at line 41 of file AliNDFunctionInterface.h.

Referenced by FitMVAClassification(), and FitMVARegression().

map<std::string, std::string> AliNDFunctionInterface::regressionMethodSetting

map of registered array of TMVA::MethodBase - used to define TMVA statistics (Mean, Median, RMS, quantile)

Definition at line 39 of file AliNDFunctionInterface.h.

Referenced by FitMVAClassification(), and FitMVARegression().