BCDataSet Class Reference

A class representing a set of data points. More...

#include <BCDataSet.h>

Public Member Functions

Constructors and destructor
 BCDataSet (unsigned n=0)
 Default constructor. More...
 
virtual ~BCDataSet ()
 Destructor.
 
operators
BCDataPointoperator[] (unsigned index)
 Raw and fast access. More...
 
const BCDataPointoperator[] (unsigned index) const
 Raw and fast access. More...
 
Member functions (get)
unsigned GetNDataPoints () const
 
unsigned GetNValuesPerPoint () const
 
BCDataPointGetDataPoint (unsigned index)
 Safer, but slower, access to data points. More...
 
const BCDataPointGetDataPoint (unsigned index) const
 Safer, but slower, access to data points. More...
 
BCDataPointBack ()
 Access to last added data point. More...
 
std::vector< double > GetDataComponents (unsigned index) const
 Viewing the data set as a table with one row per point, this method returns a specified column. More...
 
bool BoundsExist () const
 
const BCDataPointGetLowerBounds () const
 
const BCDataPointGetUpperBounds () const
 
BCDataPointGetUserLowerBounds ()
 
BCDataPointGetUserUpperBounds ()
 
double GetLowerBound (unsigned index) const
 Return user-set lower bound on data, if set, otherwise actual lower bound. More...
 
double GetUpperBound (unsigned index) const
 Return user-set upper bound on data, if set, otherwise actual upper bound. More...
 
double GetRangeWidth (unsigned index) const
 Return upper-bound minus lower-bound for data axis, using user-set bounds, if provided, other actual bounds. More...
 
bool IsFixed (unsigned index) const
 Return wether data axis is fixed. More...
 
Setters
void SetNValuesPerPoint (unsigned n)
 Set number of values inside each data point. More...
 
void SetBounds (unsigned index, double lower_bound, double upper_bound, bool fixed=false)
 Set bounds for data values. More...
 
void Fix (unsigned i, bool b=true)
 Set fixed flag of a data axis. More...
 
Member functions (miscellaneous methods)
bool ReadDataFromFile (const std::string &filename, const std::string &treename, const std::string &branchnames, char delim= ',')
 Reads data from a TTree in file. More...
 
bool ReadDataFromFile (const std::string &filename, int nvariables)
 Reads data from a file. More...
 
bool ReadDataFromFileTree (const std::string &filename, const std::string &treename, const std::string &branchnames, char delim= ',')
 Reads a TTree from a .root file. More...
 
bool ReadDataFromFileTxt (const std::string &filename, int nvariables)
 Reads data from a .txt file. More...
 
bool AddDataPoint (const BCDataPoint &datapoint)
 Adds a data point to the data set. More...
 
void AdjustBoundForUncertainties (unsigned i, double nSigma, unsigned i_err1, int i_err2=-1)
 Recalculate a data axis bound accounting for uncertainties specified by other data axes. More...
 
void Reset ()
 Resets the content of the data set.
 
void PrintSummary (void(*output)(const std::string &)=BCLog::OutSummary) const
 Print summary to string handler. More...
 
TGraph * GetGraph (unsigned x, unsigned y) const
 Get data set as ROOT TGraph object,. More...
 
TGraphErrors * GetGraph (unsigned x, unsigned y, int ex, int ey) const
 Get data set as ROOT TGraphErrors object. More...
 
TGraphAsymmErrors * GetGraph (unsigned x, unsigned y, int ex_below, int ex_above, int ey_below, int ey_above) const
 Get data set as ROOT TGraphAsymmErrors object. More...
 
TH2 * CreateH2 (const char *name, const char *title, unsigned x, unsigned y, unsigned nbins_x=100, unsigned nbins_y=100, double x_padding=0.10, double y_padding=0.10) const
 Get ROOT TH2 with ranges set to data bounds. More...
 

Detailed Description

A class representing a set of data points.

Author
Daniel Kollar
Kevin Kröninger
Version
1.0
Date
08.2008

This class represents a data set containing a set of data points. The data points are organized in a vector. The class provides functions to read in data from a file.

Definition at line 39 of file BCDataSet.h.

Constructor & Destructor Documentation

BCDataSet::BCDataSet ( unsigned  n = 0)

Default constructor.

Parameters
nDimensionality (Number of values inside) of data points.

Definition at line 31 of file BCDataSet.cxx.

Member Function Documentation

bool BCDataSet::AddDataPoint ( const BCDataPoint datapoint)

Adds a data point to the data set.

Parameters
datapointThe data point to be added

Definition at line 209 of file BCDataSet.cxx.

void BCDataSet::AdjustBoundForUncertainties ( unsigned  i,
double  nSigma,
unsigned  i_err1,
int  i_err2 = -1 
)

Recalculate a data axis bound accounting for uncertainties specified by other data axes.

If a second error index is provided, the first is taken as error below the value, and the second as error above the value.

Parameters
iIndex of the data axis to be recalculated
nSigmaMultiples of the stored uncertainty to account for
i_err1Index of the data axis containing uncertainty (below point, if next i_err2 also specified)
i_err2Index of the data axis containing uncertainty above point

Definition at line 232 of file BCDataSet.cxx.

BCDataPoint& BCDataSet::Back ( )
inline

Access to last added data point.

Definition at line 99 of file BCDataSet.h.

bool BCDataSet::BoundsExist ( ) const
Returns
Whether bounds for the data set exist.

Definition at line 55 of file BCDataSet.cxx.

TH2 * BCDataSet::CreateH2 ( const char *  name,
const char *  title,
unsigned  x,
unsigned  y,
unsigned  nbins_x = 100,
unsigned  nbins_y = 100,
double  x_padding = 0.10,
double  y_padding = 0.10 
) const

Get ROOT TH2 with ranges set to data bounds.

Padding is specified as fraction of boundary range.

Note
The caller is responsible for deletion of the returned object.
Parameters
nameName of histogram
titleTitle of histogram
xIndex of data axis for abscissa
yIndex of data axis for ordinate
nbins_xnumber of bins on abscissa (default 100)
nbins_ynumber of bins on ordinate (default 100)
x_paddingAmount to pad on either side of abscissa boundaries (default = 0.10)
y_paddingAmount to pad on either side of ordinate boundaries (default = 0.10)
Returns
pointer to empty ROOT TH2

Definition at line 353 of file BCDataSet.cxx.

void BCDataSet::Fix ( unsigned  i,
bool  b = true 
)
inline

Set fixed flag of a data axis.

Parameters
iindex of axis to fix
bwhether to fix (true) or unfix (false)

Definition at line 182 of file BCDataSet.h.

std::vector< double > BCDataSet::GetDataComponents ( unsigned  index) const

Viewing the data set as a table with one row per point, this method returns a specified column.

Parameters
indexThe index of the component to be returned.
Returns
The (index)th component of all data points

Definition at line 37 of file BCDataSet.cxx.

BCDataPoint& BCDataSet::GetDataPoint ( unsigned  index)
inline

Safer, but slower, access to data points.

Parameters
indexThe index of the data point to be returned.
Returns
The data point at the index.

Definition at line 87 of file BCDataSet.h.

const BCDataPoint& BCDataSet::GetDataPoint ( unsigned  index) const
inline

Safer, but slower, access to data points.

Parameters
indexThe index of the data point to be returned.
Returns
The data point at the index.

Definition at line 94 of file BCDataSet.h.

TGraph * BCDataSet::GetGraph ( unsigned  x,
unsigned  y 
) const

Get data set as ROOT TGraph object,.

Note
The caller is responsible for deletion of the returned object.
Parameters
xIndex of data axis plotted as abscissa
yIndex of data axis plotted as ordinate
Returns
pointer to filled ROOT TGraph

Definition at line 295 of file BCDataSet.cxx.

TGraphErrors * BCDataSet::GetGraph ( unsigned  x,
unsigned  y,
int  ex,
int  ey 
) const

Get data set as ROOT TGraphErrors object.

Set error indices negative to leave errors unset.

Note
The caller is responsible for deletion of the returned object.
Parameters
xIndex of data axis plotted as abscissa
yIndex of data axis plotted as ordinate
exIndex of data axis for error on abscissa
eyIndex of data axis for error on ordinate
Returns
pointer to filled ROOT TGraphErrors

Definition at line 310 of file BCDataSet.cxx.

TGraphAsymmErrors * BCDataSet::GetGraph ( unsigned  x,
unsigned  y,
int  ex_below,
int  ex_above,
int  ey_below,
int  ey_above 
) const

Get data set as ROOT TGraphAsymmErrors object.

Set error indices negative to leave errors unset.

Note
The caller is responsible for deletion of the returned object.
Parameters
xIndex of data axis plotted as abscissa
yIndex of data axis plotted as ordinate
ex_belowIndex of data axis for error on abscissa below data points
ex_aboveIndex of data axis for error on abscissa below data points
ey_belowIndex of data axis for error on ordinate below data points
ey_aboveIndex of data axis for error on ordinate below data points
Returns
pointer to filled ROOT TGraphAsymmErrors

Definition at line 330 of file BCDataSet.cxx.

double BCDataSet::GetLowerBound ( unsigned  index) const

Return user-set lower bound on data, if set, otherwise actual lower bound.

Parameters
indexIndex of data value to return lower bound of.
Returns
Lower bound on data values.

Definition at line 64 of file BCDataSet.cxx.

const BCDataPoint& BCDataSet::GetLowerBounds ( ) const
inline
Returns
BCDataPoint with values set to actual lower bounds of data.

Definition at line 115 of file BCDataSet.h.

unsigned BCDataSet::GetNDataPoints ( ) const
inline
Returns
The number of data points.

Definition at line 75 of file BCDataSet.h.

unsigned BCDataSet::GetNValuesPerPoint ( ) const
inline
Returns
number of values per data point (dimension of data).

Definition at line 80 of file BCDataSet.h.

double BCDataSet::GetRangeWidth ( unsigned  index) const
inline

Return upper-bound minus lower-bound for data axis, using user-set bounds, if provided, other actual bounds.

Returns
range width.

Definition at line 149 of file BCDataSet.h.

double BCDataSet::GetUpperBound ( unsigned  index) const

Return user-set upper bound on data, if set, otherwise actual upper bound.

Parameters
indexIndex of data value to return upper bound of.
Returns
Upper bound on data values.

Definition at line 76 of file BCDataSet.cxx.

const BCDataPoint& BCDataSet::GetUpperBounds ( ) const
inline
Returns
BCDataPoint with values set to actual upper bounds of data.

Definition at line 120 of file BCDataSet.h.

BCDataPoint& BCDataSet::GetUserLowerBounds ( )
inline
Returns
BCDataPoint with values set to user-set lower bounds of data.

Definition at line 125 of file BCDataSet.h.

BCDataPoint& BCDataSet::GetUserUpperBounds ( )
inline
Returns
BCDataPoint with values set to user-set upper bounds of data.

Definition at line 130 of file BCDataSet.h.

bool BCDataSet::IsFixed ( unsigned  index) const
inline

Return wether data axis is fixed.

Parameters
indexIndex of axis to query
Returns
Whether data axis is fixed.

Definition at line 156 of file BCDataSet.h.

BCDataPoint& BCDataSet::operator[] ( unsigned  index)
inline

Raw and fast access.

Definition at line 61 of file BCDataSet.h.

const BCDataPoint& BCDataSet::operator[] ( unsigned  index) const
inline

Raw and fast access.

Definition at line 66 of file BCDataSet.h.

void BCDataSet::PrintSummary ( void(*)(const std::string &)  output = BCLog::OutSummary) const

Print summary to string handler.

Parameters
outputString handler (default = BCLog::OutSummary).

Definition at line 283 of file BCDataSet.cxx.

bool BCDataSet::ReadDataFromFile ( const std::string &  filename,
const std::string &  treename,
const std::string &  branchnames,
char  delim = ',' 
)
inline

Reads data from a TTree in file.

Parameters
filenamePath to file containing TTree object.
treenameName of TTree inside file.
branchnamesList of names of branches to be read from TTree
delimCharacter deliminating branch names (default: comma).
Returns
Success of action.

Definition at line 197 of file BCDataSet.h.

bool BCDataSet::ReadDataFromFile ( const std::string &  filename,
int  nvariables 
)
inline

Reads data from a file.

Parameters
filenamePath to file containing data.
nvariablesNumber of variables (columns) in data file.
Returns
Success of action.

Definition at line 205 of file BCDataSet.h.

bool BCDataSet::ReadDataFromFileTree ( const std::string &  filename,
const std::string &  treename,
const std::string &  branchnames,
char  delim = ',' 
)

Reads a TTree from a .root file.

Opens a .root file and gets a TTree. It creates data points containing the values read from the file.

Parameters
filenameThe name of the .root file.
treenameThe name of the TTree.
branchnamesA list of the names of the branches
delimCharacter deliminating between branch names (default: comma)
Returns
Success of action.

Definition at line 88 of file BCDataSet.cxx.

bool BCDataSet::ReadDataFromFileTxt ( const std::string &  filename,
int  nvariables 
)

Reads data from a .txt file.

Opens a .txt file and creates data objects containing the values read from the file.

Parameters
filenameThe name of the .txt file.
nvariablesThe number of variables (columns) in file.
Returns
Success of action.

Definition at line 157 of file BCDataSet.cxx.

void BCDataSet::SetBounds ( unsigned  index,
double  lower_bound,
double  upper_bound,
bool  fixed = false 
)

Set bounds for data values.

Parameters
indexIndex of data axis to provide bounds for.
lower_boundThe lower bound of the data value.
upper_boundThe upper bound of the data value.
fixedIf the data value can vary or not.

Definition at line 267 of file BCDataSet.cxx.

void BCDataSet::SetNValuesPerPoint ( unsigned  n)

Set number of values inside each data point.

If set to zero, then this will be set by first added data point.

Parameters
nSize of data point.

Definition at line 256 of file BCDataSet.cxx.


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