SFrame 3.6
SH1< Type > Class Template Reference

Ligh-weight 1-dimensional histogram class. More...

#include <plug-ins/include/SH1.h>

List of all members.

Public Member Functions

 SH1 ()
 Default constructor.
template<typename T >
 SH1 (const SH1< T > &parent)
 Fancy copy constructor.
 SH1 (const char *name, const char *title, Int_t bins, Double_t low, Double_t high, Bool_t computeErrors=kTRUE)
 Regular constructor with all parameters.
virtual ~SH1 ()
 Destructor.
void Fill (Double_t pos, Type weight=1) throw ( SError )
 Increase the contents of the bin at a specific position.
Int_t GetNBins () const
 Get the number of bins.
Int_t FindBin (Double_t pos) const
 Find the bin belonging to a specific position on the axis.
Type GetBinContent (Int_t bin) const
 Get the content of a specific bin.
void SetBinContent (Int_t bin, Type content)
 Set the content of a specific bin.
Type GetBinError (Int_t bin) const
 Get the error of a specific bin.
void SetBinError (Int_t bin, Type error)
 Set the error of a specific bin.
Int_t GetEntries () const
 Get the total number of entries in the histogram.
void SetEntries (Int_t entries)
 Set the total number of entries in the histogram.
TH1 * ToHist () const
 Function creating a TH1 histogram with the contents of the object.
virtual Int_t Merge (TCollection *coll)
 Merge a collection of SH1 objects.
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const
 Write the SH1 object as a TH1 object (const version)
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0)
 Write the SH1 object as a TH1 object (non-const version)

Detailed Description

template<typename Type>
class SH1< Type >

Ligh-weight 1-dimensional histogram class.

In many cases the TH1* histograms of ROOT can be unnecessarily "heavy". Those objects take quite a lot of memory, and are not the quickest. However they also provide a lot of functionality in return.

This class can be used when you just want to see some simple distribution. It only provides the very basic features. The created histograms can only have evenly sized bins for instance.

But for convenience when such an object is written out to a file, it is written out as an appropriate TH1 histogram, with the same contents as the object has in memory. So in principle changing one's code to use SH1D histograms instead of TH1D histograms in the cycle, should not be visible in the output file.

When creating the objects in the default mode (with statistical uncertainty computation enabled), they give about a 50% speed increase over using TH1. But when the statistical uncertainty computation is turned off, the speed increase is >200%.

Version:
Revision:
313

Definition at line 51 of file SH1.h.


Constructor & Destructor Documentation

template<typename Type >
SH1< Type >::SH1 ( )

Default constructor.

This constructor is needed for the dictionary generation. There has to be a constructor that expects no parameters.

Definition at line 33 of file SH1.icc.

template<typename Type >
template<typename T >
SH1< Type >::SH1 ( const SH1< T > &  parent)

Fancy copy constructor.

It's kind of a fancy copy constructor. The idea here is that one should be able to initialise let's say an SH1<double> object from an SH1<int> object. This is also why I can't use memcpy to copy the contents of the arrays. (The sizes of the arrays could be different in memory...)

Parameters:
parentThe parent that should be copied

Definition at line 49 of file SH1.icc.

template<typename Type >
SH1< Type >::SH1 ( const char *  name,
const char *  title,
Int_t  bins,
Double_t  low,
Double_t  high,
Bool_t  computeErrors = kTRUE 
)

Regular constructor with all parameters.

This is the standard TH1-like constructor. It defines all basic properties of the histogram. It has one extra parameter compared to TH1, "computeErrors". When set to false (the default is true), the histogram doesn't calculate the statistical uncertainties for the bins. This can result in serious speed improvements.

Parameters:
nameThe name of the histogram
titleThe title of the histogram
binsThe number of bins that the histogram should have
lowThe lower edge of the X axis
highThe higher edge of the X axis
computeErrorsFlag for turning on/off the statistical uncertainty calculation

Definition at line 76 of file SH1.icc.

template<typename Type >
SH1< Type >::~SH1 ( ) [virtual]

Destructor.

The destructor has to delete all the internal buffers that were created on the heap.

Definition at line 95 of file SH1.icc.


Member Function Documentation

template<typename Type >
void SH1< Type >::Fill ( Double_t  pos,
Type  weight = 1 
) throw ( SError )

Increase the contents of the bin at a specific position.

This is the main function for filling the histogram with entries. It fills the appropriate bin with the specified weight, and if error calculation was requested, it calculates the new uncertainty of the bin.

Unlike TH1, this class doesn't handle it silently when it receives a NaN value as input. In this case it throws an exception to stop the execution. User code should really just not pass NaN values to histograms...

Parameters:
posThe position at which a bin should be filled
weightThe amount with which the bin should be filled

Definition at line 116 of file SH1.icc.

References REPORT_FATAL, and SError::StopExecution.

template<typename Type >
Int_t SH1< Type >::FindBin ( Double_t  pos) const

Find the bin belonging to a specific position on the axis.

This function can be used to find which bin corresponds to a certain position on the axis. It follows the ROOT histograms' internal binning, so the arrays have a size of "GetNBins()+2", the regular bin numbers go from 1 to GetNBins(), the underflow bin is 0, and the overflow bin is "GetNBins()+1".

Parameters:
posThe position on the X axis that should be associated to a bin
Returns:
The bin number corresponding to the specified axis position

Definition at line 155 of file SH1.icc.

template<typename Type >
Type SH1< Type >::GetBinContent ( Int_t  bin) const

Get the content of a specific bin.

This function gets the contents of a given bin directly. It's not checked if the specified bin is in the correct range!

Parameters:
binThe bin that should be investigated
Returns:
The content of the specified bin

Definition at line 171 of file SH1.icc.

template<typename Type >
Type SH1< Type >::GetBinError ( Int_t  bin) const

Get the error of a specific bin.

This function gets the uncertainty of a given bin directly. It's not checked if the specified bin is in the correct range!

Parameters:
binThe bin that should be investigated
Returns:
The uncertinty of the bin

Definition at line 199 of file SH1.icc.

template<typename Type >
Int_t SH1< Type >::GetEntries ( ) const

Get the total number of entries in the histogram.

Returns:
The number of entries in the histogram

Definition at line 225 of file SH1.icc.

template<typename Type >
Int_t SH1< Type >::GetNBins ( ) const

Get the number of bins.

Returns:
The number of bins of the histogram

Definition at line 140 of file SH1.icc.

template<typename Type >
Int_t SH1< Type >::Merge ( TCollection *  coll) [virtual]

Merge a collection of SH1 objects.

This function takes care of correctly merging the separate histogram objects created on the PROOF worker nodes.

Definition at line 280 of file SH1.icc.

References REPORT_ERROR.

template<typename Type >
void SH1< Type >::SetBinContent ( Int_t  bin,
Type  content 
)

Set the content of a specific bin.

This function sets the contents of a given bin directly. It's not checked if the specified bin is in the correct range! Also note, that when using this function, you're on your own with calculating the uncertainties of the bin.

Parameters:
binThe bin that should be accessed
contentThe new content of the bin

Definition at line 185 of file SH1.icc.

template<typename Type >
void SH1< Type >::SetBinError ( Int_t  bin,
Type  error 
)

Set the error of a specific bin.

This function sets the uncertainty of a given bin directly. It's not checked if the specified bin is in the correct range!

Parameters:
binThe bin that should be accessed
errorThe new uncertainty of the bin

Definition at line 213 of file SH1.icc.

template<typename Type >
void SH1< Type >::SetEntries ( Int_t  entries)

Set the total number of entries in the histogram.

Parameters:
entriesThe new number of entries in the histogram

Definition at line 234 of file SH1.icc.

template<typename Type >
TH1 * SH1< Type >::ToHist ( ) const

Function creating a TH1 histogram with the contents of the object.

This function could be used to create a TH1-type histogram from the current object. This is useful when you have to use some functionality of TH1 that's not available in SH1. (Like fitting, division, etc.)

Note that the caller is responsible for deleting the created histogram later on.

Returns:
A pointer to the newly created TH1 histogram object

Definition at line 250 of file SH1.icc.

References SLogger::endmsg(), and ERROR.

template<typename Type >
Int_t SH1< Type >::Write ( const char *  name = 0,
Int_t  option = 0,
Int_t  bufsize = 0 
) [virtual]

Write the SH1 object as a TH1 object (non-const version)

Definition at line 341 of file SH1.icc.

template<typename Type >
Int_t SH1< Type >::Write ( const char *  name = 0,
Int_t  option = 0,
Int_t  bufsize = 0 
) const [virtual]

Write the SH1 object as a TH1 object (const version)

The default TObject::Write(...) function is overwritten here in order to not write an instance of this object to the output file, but instead a TH1 object.

Definition at line 329 of file SH1.icc.


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