#ifndef ROOT_TMVA_DataSetFactory
#define ROOT_TMVA_DataSetFactory
#include <vector>
#include <stdlib.h>
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TTree
#include "TTree.h"
#endif
#ifndef ROOT_TCut
#include "TCut.h"
#endif
#ifndef ROOT_TTreeFormula
#include "TTreeFormula.h"
#endif
#ifndef ROOT_TMatrixDfwd
#include "TMatrixDfwd.h"
#endif
#ifndef ROOT_TPrincipal
#include "TPrincipal.h"
#endif
#ifndef ROOT_TRandom3
#include "TRandom3.h"
#endif
#ifndef ROOT_TMVA_Types
#include "TMVA/Types.h"
#endif
#ifndef ROOT_TMVA_VariableInfo
#include "TMVA/VariableInfo.h"
#endif
#ifndef ROOT_TMVA_Event
#include "TMVA/Event.h"
#endif
namespace TMVA {
class DataSet;
class DataSetInfo;
class DataInputHandler;
class TreeInfo;
class MsgLogger;
class RandomGenerator {
public:
RandomGenerator( UInt_t seed ){
fRandom.SetSeed( seed );
}
UInt_t operator() ( UInt_t n ) {
return fRandom.Integer(n);
}
private:
TRandom3 fRandom;
};
template<class T>
struct DeleteFunctor_t
{
DeleteFunctor_t& operator()(const T* p) {
delete p;
return *this;
}
};
template<class T>
DeleteFunctor_t<const T> DeleteFunctor()
{
return DeleteFunctor_t<const T>();
}
template< typename T >
class Increment {
T value;
public:
Increment( T start ) : value( start ){ }
T operator()() {
return value++;
}
};
template <typename F>
class null_t
{
private:
public:
typedef F argument_type;
F operator()(const F& argF) const
{
return argF;
}
};
template <typename F>
inline null_t<F> null() {
return null_t<F>();
}
template <typename F, typename G, typename H>
class compose_binary_t : public std::binary_function<typename G::argument_type,
typename H::argument_type,
typename F::result_type>
{
private:
const F& f;
const G& g;
const H& h;
public:
compose_binary_t(const F& _f, const G& _g, const H& _h) : f(_f), g(_g), h(_h)
{
}
typename F::result_type operator()(const typename G::argument_type& argG,
const typename H::argument_type& argH) const
{
return f(g(argG),h(argH));
}
};
template <typename F, typename G, typename H>
inline compose_binary_t<F,G,H> compose_binary(const F& _f, const G& _g, const H& _h) {
return compose_binary_t<F,G,H>(_f,_g,_h);
}
template <typename F, typename G>
class compose_unary_t : public std::unary_function<typename G::argument_type,
typename F::result_type>
{
private:
const F& f;
const G& g;
public:
compose_unary_t(const F& _f, const G& _g) : f(_f), g(_g)
{
}
typename F::result_type operator()(const typename G::argument_type& argG) const
{
return f(g(argG));
}
};
template <typename F, typename G>
inline compose_unary_t<F,G> compose_unary(const F& _f, const G& _g) {
return compose_unary_t<F,G>(_f,_g);
}
class DataSetFactory:public TObject {
typedef std::vector<Event* > EventVector;
typedef std::vector< EventVector > EventVectorOfClasses;
typedef std::map<Types::ETreeType, EventVectorOfClasses > EventVectorOfClassesOfTreeType;
typedef std::map<Types::ETreeType, EventVector > EventVectorOfTreeType;
typedef std::vector< Double_t > ValuePerClass;
typedef std::map<Types::ETreeType, ValuePerClass > ValuePerClassOfTreeType;
class EventStats {
public:
Int_t nTrainingEventsRequested;
Int_t nTestingEventsRequested;
Float_t TrainTestSplitRequested;
Int_t nInitialEvents;
Int_t nEvBeforeCut;
Int_t nEvAfterCut;
Float_t nWeEvBeforeCut;
Float_t nWeEvAfterCut;
Double_t nNegWeights;
Float_t* varAvLength;
EventStats():
nTrainingEventsRequested(0),
nTestingEventsRequested(0),
TrainTestSplitRequested(0),
nInitialEvents(0),
nEvBeforeCut(0),
nEvAfterCut(0),
nWeEvBeforeCut(0),
nWeEvAfterCut(0),
nNegWeights(0),
varAvLength(0)
{}
~EventStats() { delete[] varAvLength; }
Float_t cutScaling() const { return Float_t(nEvAfterCut)/nEvBeforeCut; }
};
typedef std::vector< int > NumberPerClass;
typedef std::vector< EventStats > EvtStatsPerClass;
public:
~DataSetFactory();
DataSetFactory();
DataSet* CreateDataSet( DataSetInfo &, DataInputHandler& );
protected:
DataSet* BuildInitialDataSet( DataSetInfo&, TMVA::DataInputHandler& );
DataSet* BuildDynamicDataSet( DataSetInfo& );
void BuildEventVector ( DataSetInfo& dsi,
DataInputHandler& dataInput,
EventVectorOfClassesOfTreeType& eventsmap,
EvtStatsPerClass& eventCounts);
DataSet* MixEvents ( DataSetInfo& dsi,
EventVectorOfClassesOfTreeType& eventsmap,
EvtStatsPerClass& eventCounts,
const TString& splitMode,
const TString& mixMode,
const TString& normMode,
UInt_t splitSeed);
void RenormEvents ( DataSetInfo& dsi,
EventVectorOfClassesOfTreeType& eventsmap,
const EvtStatsPerClass& eventCounts,
const TString& normMode );
void InitOptions ( DataSetInfo& dsi,
EvtStatsPerClass& eventsmap,
TString& normMode, UInt_t& splitSeed,
TString& splitMode, TString& mixMode);
TMatrixD* CalcCorrelationMatrix( DataSet*, const UInt_t classNumber );
TMatrixD* CalcCovarianceMatrix ( DataSet*, const UInt_t classNumber );
void CalcMinMax ( DataSet*, DataSetInfo& dsi );
void ResetBranchAndEventAddresses( TTree* );
void ResetCurrentTree() { fCurrentTree = 0; }
void ChangeToNewTree( TreeInfo&, const DataSetInfo & );
Bool_t CheckTTreeFormula( TTreeFormula* ttf, const TString& expression, Bool_t& hasDollar );
Bool_t Verbose() { return fVerbose; }
Bool_t fVerbose;
TString fVerboseLevel;
Bool_t fScaleWithPreselEff;
TTree* fCurrentTree;
UInt_t fCurrentEvtIdx;
std::vector<TTreeFormula*> fInputFormulas;
std::vector<TTreeFormula*> fTargetFormulas;
std::vector<TTreeFormula*> fCutFormulas;
std::vector<TTreeFormula*> fWeightFormula;
std::vector<TTreeFormula*> fSpectatorFormulas;
MsgLogger* fLogger;
MsgLogger& Log() const { return *fLogger; }
public:
ClassDef(DataSetFactory,1);
};
}
#endif