 |
Belle II Software
release-05-02-19
|
13 #ifndef INCLUDE_GUARD_BELLE2_MVA_DATASET_HEADER
14 #define INCLUDE_GUARD_BELLE2_MVA_DATASET_HEADER
16 #include <mva/interface/Options.h>
77 virtual void loadEvent(
unsigned int iEvent) = 0;
100 virtual std::vector<float>
getFeature(
unsigned int iFeature);
106 virtual std::vector<float>
getSpectator(
unsigned int iSpectator);
147 const std::vector<float>& spectators = std::vector<float>());
173 virtual std::vector<float>
getFeature(
unsigned int iFeature)
override {
return std::vector<float> {
m_input[iFeature]}; }
179 virtual std::vector<float>
getSpectator(
unsigned int iSpectator)
override {
return std::vector<float> {
m_spectators[iSpectator]}; }
198 const std::vector<std::vector<float>>& spectators,
199 const std::vector<float>& targets = {},
const std::vector<float>& weights = {});
219 virtual void loadEvent(
unsigned int iEvent)
override;
264 virtual void loadEvent(
unsigned int iEvent)
override;
270 virtual std::vector<float>
getFeature(
unsigned int iFeature)
override;
276 virtual std::vector<float>
getSpectator(
unsigned int iSpectator)
override;
280 std::vector<unsigned int>
282 std::vector<unsigned int>
284 std::vector<unsigned int>
324 virtual void loadEvent(
unsigned int iEvent)
override;
330 virtual std::vector<float>
getFeature(
unsigned int iFeature)
override;
336 virtual std::vector<float>
getSpectator(
unsigned int iSpectator)
override;
380 virtual void loadEvent(
unsigned int event)
override;
386 virtual std::vector<float>
getFeature(
unsigned int iFeature)
override;
391 virtual std::vector<float>
getWeights()
override;
397 virtual std::vector<float>
getSpectator(
unsigned int iSpectator)
override;
409 std::vector<float>
getVectorFromTTree(std::string& variableType, std::string& branchName, T& memberVariableTarget);
virtual void loadEvent(unsigned int iEvent) override
Load the event number iEvent from the wrapped dataset.
TChain * m_tree
Pointer to the TChain containing the data.
virtual std::vector< float > getFeature(unsigned int iFeature) override
Returns all values of one feature in a std::vector<float>
Wraps the data of a multiple event into a Dataset.
SingleDataset(const GeneralOptions &general_options, const std::vector< float > &input, float target=1.0, const std::vector< float > &spectators=std::vector< float >())
Constructs a new SingleDataset.
GeneralOptions m_general_options
GeneralOptions passed to this dataset.
bool m_use_event_indices
Use only a subset of the wrapped dataset events.
virtual std::vector< float > getSpectator(unsigned int iSpectator) override
Returns all values (in this case only one) of one spectator in a std::vector<float>
virtual unsigned int getNumberOfEvents() const override
Returns the number of events in this dataset which is always one.
Abstract base class of all Datasets given to the MVA interface The current event can always be access...
virtual ~Dataset()=default
Virtual default destructor.
unsigned int m_max_events
Maximum number of events to process, 0 means all.
virtual std::vector< float > getFeature(unsigned int iFeature) override
Returns all values of one feature in a std::vector<float> of the wrapped dataset.
virtual unsigned int getNumberOfFeatures() const =0
Returns the number of features in this dataset.
virtual void loadEvent(unsigned int iEvent)=0
Load the event number iEvent.
Dataset & m_background_dataset
Reference to the wrapped dataset containing background events.
virtual std::vector< float > getFeature(unsigned int iFeature)
Returns all values of one feature in a std::vector<float>
virtual unsigned int getNumberOfEvents() const override
Returns the number of events in the wrapped dataset.
bool m_isDoubleInputType
Defines the expected datatype in the ROOT file.
virtual unsigned int getNumberOfEvents() const override
Returns the number of events in this dataset.
virtual std::vector< float > getSpectator(unsigned int iSpectator)
Returns all values of one spectator in a std::vector<float>
ROOTDataset(const GeneralOptions &_general_options)
Creates a new ROOTDataset.
std::vector< unsigned int > m_spectator_indices
Mapping from the position of a spectator in the given subset to its position in the wrapped dataset.
std::vector< double > m_spectators_double
Contains all spectators values of the currently loaded event.
virtual std::vector< float > getWeights()
Returns all weights.
void setVectorVariableAddress(std::string &variableType, std::vector< std::string > &variableName, T &variableTargets)
sets the branch address for a vector variable to a given target
virtual void loadEvent(unsigned int event) override
Load the event number iEvent from the TTree.
std::vector< std::vector< float > > m_spectator_matrix
Spectator matrix.
virtual unsigned int getNumberOfFeatures() const override
Returns the number of features in this dataset, so the size of the given subset of the variables.
virtual unsigned int getNumberOfSpectators() const =0
Returns the number of spectators in this dataset.
virtual std::vector< float > getWeights() override
Returns all values of of the weights in a std::vector<float>
SubDataset(const GeneralOptions &general_options, const std::vector< bool > &events, Dataset &dataset)
Constructs a new SubDataset holding a reference to the wrapped Dataset.
virtual unsigned int getNumberOfSpectators() const override
Returns the number of spectators in this dataset.
std::vector< unsigned int > m_event_indices
Mapping from the position of a event in the given subset to its position in the wrapped dataset.
std::vector< float > m_targets
target vector
std::vector< unsigned int > m_feature_indices
Mapping from the position of a feature in the given subset to its position in the wrapped dataset.
virtual std::vector< bool > getSignals()
Returns all is Signals.
virtual void loadEvent(unsigned int) override
Does nothing in the case of a single dataset, because the only event is already loaded.
void setScalarVariableAddress(std::string &variableType, std::string &variableName, T &variableTarget)
sets the branch address for a scalar variable to a given target
CombinedDataset(const GeneralOptions &general_options, Dataset &signal_dataset, Dataset &background_dataset)
Constructs a new CombinedDataset holding a reference to the wrapped Datasets.
virtual unsigned int getNumberOfEvents() const override
Returns the number of events in this dataset.
double m_weight_double
Contains the weight of the currently loaded event.
Dataset & operator=(const Dataset &)=delete
Specify no assignment operator.
virtual unsigned int getNumberOfSpectators() const override
Returns the number of spectators in this dataset, so the size of the given subset of the spectators.
virtual unsigned int getNumberOfFeatures() const override
Returns the number of features in this dataset.
MultiDataset(const GeneralOptions &general_options, const std::vector< std::vector< float >> &input, const std::vector< std::vector< float >> &spectators, const std::vector< float > &targets={}, const std::vector< float > &weights={})
Constructs a new MultiDataset.
virtual unsigned int getNumberOfSpectators() const override
Returns the number of spectators in this dataset, so the size of the given subset of the spectators.
Abstract base class for different kinds of events.
Wraps another Dataset and provides a view to a subset of its features and events.
std::vector< float > m_input
Contains all feature values of the currently loaded event.
virtual unsigned int getNumberOfEvents() const override
Returns the number of events in the wrapped dataset.
std::vector< float > m_spectators
Contains all spectators values of the currently loaded event.
Dataset & m_dataset
Reference to the wrapped dataset.
General options which are shared by all MVA trainings.
virtual void loadEvent(unsigned int iEvent) override
Does nothing in the case of a single dataset, because the only event is already loaded.
virtual std::vector< float > getSpectator(unsigned int iSpectator) override
Returns all values of one spectator in a std::vector<float> of the wrapped dataset.
Dataset & m_signal_dataset
Reference to the wrapped dataset containing signal events.
Wraps the data of a single event into a Dataset.
virtual unsigned int getNumberOfFeatures() const override
Returns the number of features in this dataset.
virtual std::vector< float > getFeature(unsigned int iFeature) override
Returns all values (in this case only one) of one feature in a std::vector<float>
virtual unsigned int getNumberOfFeatures() const override
Returns the number of features in this dataset, so the size of the given subset of the variables.
bool checkForBranch(TTree *, const std::string &) const
Checks if the given branchname exists in the TTree.
virtual ~ROOTDataset()
Virtual destructor.
std::vector< float > m_weights
weight vector
virtual unsigned int getNumberOfSpectators() const override
Returns the number of features in this dataset.
virtual std::vector< float > getSpectator(unsigned int iSpectator) override
Returns all values of one spectator in a std::vector<float>
Proivdes a dataset from a ROOT file This is the usually used dataset providing training data to the m...
virtual std::vector< float > getTargets()
Returns all targets.
float m_weight
Contains the weight of the currently loaded event.
virtual unsigned int getSpectatorIndex(const std::string &spectator)
Return index of spectator with the given name.
bool m_isSignal
Defines if the currently loaded event is signal or background.
std::vector< std::vector< float > > m_matrix
Feature matrix.
Dataset(const GeneralOptions &general_options)
Constructs a new dataset given the general options.
void setBranchAddresses()
Sets the branch addresses of all features, weight and target again.
virtual std::vector< float > getSpectator(unsigned int iSpectator) override
Returns all values of one spectator in a std::vector<float> of the wrapped dataset.
Wraps two other Datasets, one containing signal, the other background events Used by the reweighting ...
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.
std::vector< float > getVectorFromTTree(std::string &variableType, std::string &branchName, T &memberVariableTarget)
Returns all values for a specified variableType and branchName.
virtual void loadEvent(unsigned int iEvent) override
Load the event number iEvent from the wrapped dataset.
double m_target_double
Contains the target value of the currently loaded event.
virtual unsigned int getNumberOfEvents() const =0
Returns the number of events in this dataset.
float m_target
Contains the target value of the currently loaded event.
virtual std::vector< float > getFeature(unsigned int iFeature) override
Returns all values of one feature in a std::vector<float> of the wrapped dataset.
std::vector< double > m_input_double
Contains all feature values of the currently loaded event.
virtual unsigned int getFeatureIndex(const std::string &feature)
Return index of feature with the given name.
void setRootInputType()
Tries to infer the data-type of a root file and sets m_isDoubleInputType.
virtual float getSignalFraction()
Returns the signal fraction of the whole sample.