Belle II Software  release-08-01-10
ROOTDataset Class Reference

Proivdes a dataset from a ROOT file This is the usually used dataset providing training data to the mva methods. More...

#include <Dataset.h>

Inheritance diagram for ROOTDataset:
Collaboration diagram for ROOTDataset:

Public Member Functions

 ROOTDataset (const GeneralOptions &_general_options)
 Creates a new ROOTDataset. More...
 
virtual unsigned int getNumberOfFeatures () const override
 Returns the number of features in this dataset.
 
virtual unsigned int getNumberOfSpectators () const override
 Returns the number of features in this dataset.
 
virtual unsigned int getNumberOfEvents () const override
 Returns the number of events in this dataset.
 
virtual void loadEvent (unsigned int event) override
 Load the event number iEvent from the TTree. More...
 
virtual std::vector< float > getFeature (unsigned int iFeature) override
 Returns all values of one feature in a std::vector<float> More...
 
virtual std::vector< float > getWeights () override
 Returns all values of of the weights in a std::vector<float>
 
virtual std::vector< float > getSpectator (unsigned int iSpectator) override
 Returns all values of one spectator in a std::vector<float> More...
 
virtual ~ROOTDataset ()
 Virtual destructor.
 
virtual float getSignalFraction ()
 Returns the signal fraction of the whole sample.
 
virtual unsigned int getFeatureIndex (const std::string &feature)
 Return index of feature with the given name. More...
 
virtual unsigned int getSpectatorIndex (const std::string &spectator)
 Return index of spectator with the given name. More...
 
virtual std::vector< float > getTargets ()
 Returns all targets.
 
virtual std::vector< bool > getSignals ()
 Returns all is Signals.
 

Public Attributes

GeneralOptions m_general_options
 GeneralOptions passed to this dataset.
 
std::vector< float > m_input
 Contains all feature values of the currently loaded event.
 
std::vector< float > m_spectators
 Contains all spectators values of the currently loaded event.
 
float m_weight
 Contains the weight of the currently loaded event.
 
float m_target
 Contains the target value of the currently loaded event.
 
bool m_isSignal
 Defines if the currently loaded event is signal or background.
 

Protected Types

typedef std::variant< double, float, int, bool > RootDatasetVarVariant
 Typedef for variable types supported by the mva ROOTDataset, can be one of double, float, int or bool in std::variant.
 

Protected Attributes

TChain * m_tree = nullptr
 Pointer to the TChain containing the data.
 
std::vector< RootDatasetVarVariantm_input_variant
 Contains all feature values of the currently loaded event.
 
std::vector< RootDatasetVarVariantm_spectators_variant
 Contains all spectators values of the currently loaded event.
 
RootDatasetVarVariant m_weight_variant
 Contains the weight of the currently loaded event.
 
RootDatasetVarVariant m_target_variant
 Contains the target value of the currently loaded event.
 

Private Member Functions

template<class T >
std::vector< float > getVectorFromTTree (const std::string &variableType, const std::string &branchName, T &memberVariableTarget)
 Returns all values for a specified variableType and branchName. More...
 
std::vector< float > getVectorFromTTreeVariant (const std::string &variableType, const std::string &branchName, RootDatasetVarVariant &memberVariableTarget)
 Returns all values for a specified variableType and branchName. More...
 
void setRootInputType ()
 Tries to infer the data-type of the spectator and feature variables in a root file.
 
template<class T >
void setScalarVariableAddress (const std::string &variableType, const std::string &variableName, T &variableTarget)
 sets the branch address for a scalar variable to a given target More...
 
void setScalarVariableAddressVariant (const std::string &variableType, const std::string &variableName, RootDatasetVarVariant &variableTarget)
 sets the branch address for a scalar variable to a given target More...
 
template<class T >
void setVectorVariableAddress (const std::string &variableType, const std::vector< std::string > &variableName, T &variableTargets)
 sets the branch address for a vector variable to a given target More...
 
void setVectorVariableAddressVariant (const std::string &variableType, const std::vector< std::string > &variableName, std::vector< RootDatasetVarVariant > &varVariantTargets)
 sets the branch address for a vector of VarVariant to a given target More...
 
void setTargetRootInputType ()
 Determines the data type of the target variable and sets it to m_target_data_type.
 
void setBranchAddresses ()
 Sets the branch addresses of all features, weight and target again.
 
bool checkForBranch (TTree *, const std::string &) const
 Checks if the given branchname exists in the TTree. More...
 
float castVarVariantToFloat (RootDatasetVarVariant &) const
 Casts a VarVariant which can contain <double,int,bool,float> to float. More...
 
void initialiseVarVariantType (const std::string, RootDatasetVarVariant &)
 Initialises the VarVariant. More...
 
void initialiseVarVariantForBranch (const std::string, RootDatasetVarVariant &)
 Infers the type (double,float,int,bool) from the TTree and initialises the VarVariant with the correct type. More...
 

Detailed Description

Proivdes a dataset from a ROOT file This is the usually used dataset providing training data to the mva methods.

Definition at line 349 of file Dataset.h.

Constructor & Destructor Documentation

◆ ROOTDataset()

ROOTDataset ( const GeneralOptions _general_options)
explicit

Creates a new ROOTDataset.

Parameters
_general_optionsdefines the rootfile, treename, branches, ...

Definition at line 316 of file Dataset.cc.

Member Function Documentation

◆ castVarVariantToFloat()

float castVarVariantToFloat ( RootDatasetVarVariant variant) const
private

Casts a VarVariant which can contain <double,int,bool,float> to float.

Parameters
variantthe VarVariant to cast

Definition at line 376 of file Dataset.cc.

◆ checkForBranch()

bool checkForBranch ( TTree *  tree,
const std::string &  branchname 
) const
private

Checks if the given branchname exists in the TTree.

Parameters
tree
branchname

Definition at line 507 of file Dataset.cc.

◆ getFeature()

std::vector< float > getFeature ( unsigned int  iFeature)
overridevirtual

Returns all values of one feature in a std::vector<float>

Parameters
iFeaturethe position of the feature to return

Reimplemented from Dataset.

Definition at line 429 of file Dataset.cc.

◆ getFeatureIndex()

unsigned int getFeatureIndex ( const std::string &  feature)
virtualinherited

Return index of feature with the given name.

Parameters
featurename of the feature

Definition at line 50 of file Dataset.cc.

◆ getSpectator()

std::vector< float > getSpectator ( unsigned int  iSpectator)
overridevirtual

Returns all values of one spectator in a std::vector<float>

Parameters
iSpectatorthe position of the spectator to return

Reimplemented from Dataset.

Definition at line 440 of file Dataset.cc.

◆ getSpectatorIndex()

unsigned int getSpectatorIndex ( const std::string &  spectator)
virtualinherited

Return index of spectator with the given name.

Parameters
spectatorname of the spectator

Definition at line 62 of file Dataset.cc.

◆ getVectorFromTTree()

std::vector< float > getVectorFromTTree ( const std::string &  variableType,
const std::string &  branchName,
T &  memberVariableTarget 
)
private

Returns all values for a specified variableType and branchName.

The values are read from a root file. The type is inferred from the given memberVariableTarget name.

Template Parameters
Ttype memberVariable of this class which has to be updated (float, double)
Parameters
variableTypedefines {feature, weights, spectator, target}
branchNamename of the branch to read
memberVariableTargetvariable the branch address from the root file is set to
Returns
filled vector from a branch, converted to float

Definition at line 474 of file Dataset.cc.

◆ getVectorFromTTreeVariant()

std::vector< float > getVectorFromTTreeVariant ( const std::string &  variableType,
const std::string &  branchName,
RootDatasetVarVariant memberVariableTarget 
)
private

Returns all values for a specified variableType and branchName.

The values are read from a root file. The type is inferred from the given memberVariableTarget name.

Parameters
variableTypedefines {feature, weights, spectator, target}
branchNamename of the branch to read
memberVariableTargetvariable the branch address from the root file is set to
Returns
filled vector from a branch, converted to float

Definition at line 458 of file Dataset.cc.

◆ initialiseVarVariantForBranch()

void initialiseVarVariantForBranch ( const std::string  branch_name,
RootDatasetVarVariant varVariantTarget 
)
private

Infers the type (double,float,int,bool) from the TTree and initialises the VarVariant with the correct type.

Parameters
branch_namebranch name in the datafile
varVariantTargetvariant to initialise

Definition at line 615 of file Dataset.cc.

◆ initialiseVarVariantType()

void initialiseVarVariantType ( const std::string  type,
RootDatasetVarVariant varVariantTarget 
)
private

Initialises the VarVariant.

Parameters
typedefines which alternative to use for the variant {Double_t, Float_t, Int_t, Bool_t}
varVariantTargetvariant to initialise.

Definition at line 598 of file Dataset.cc.

◆ loadEvent()

void loadEvent ( unsigned int  event)
overridevirtual

Load the event number iEvent from the TTree.

Parameters
eventevent number to load

Implements Dataset.

Definition at line 391 of file Dataset.cc.

◆ setScalarVariableAddress()

void setScalarVariableAddress ( const std::string &  variableType,
const std::string &  variableName,
T &  variableTarget 
)
private

sets the branch address for a scalar variable to a given target

Template Parameters
Ttarget type (float, double)
Parameters
variableTypedefines {feature, weights, spectator, target}
variableNamename of the variable, usually defined in general_options
variableTargetvariable, the address is set to

Definition at line 515 of file Dataset.cc.

◆ setScalarVariableAddressVariant()

void setScalarVariableAddressVariant ( const std::string &  variableType,
const std::string &  variableName,
RootDatasetVarVariant variableTarget 
)
private

sets the branch address for a scalar variable to a given target

Parameters
variableTypedefines {feature, weights, spectator, target}
variableNamename of the variable, usually defined in general_options
variableTargetvariable, the address is set to

Definition at line 536 of file Dataset.cc.

◆ setVectorVariableAddress()

void setVectorVariableAddress ( const std::string &  variableType,
const std::vector< std::string > &  variableName,
T &  variableTargets 
)
private

sets the branch address for a vector variable to a given target

Template Parameters
Ttarget type (std::vector<float>, std::vector<double>)
Parameters
variableTypedefines {feature, weights, spectator, target}
variableNamenames of the variable, usually defined in general_options
variableTargetsvariables, the address is set to

Definition at line 552 of file Dataset.cc.

◆ setVectorVariableAddressVariant()

void setVectorVariableAddressVariant ( const std::string &  variableType,
const std::vector< std::string > &  variableName,
std::vector< RootDatasetVarVariant > &  varVariantTargets 
)
private

sets the branch address for a vector of VarVariant to a given target

Parameters
variableTypedefines {feature, weights, spectator, target}
variableNamenames of the variable, usually defined in general_options
varVariantTargetsvariables, the address is set to

Definition at line 560 of file Dataset.cc.


The documentation for this class was generated from the following files: