SFrame 3.6
|
Ligh-weight 1-dimensional histogram class. More...
#include <plug-ins/include/SH1.h>
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) |
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%.
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...)
parent | The parent that should be copied |
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.
name | The name of the histogram |
title | The title of the histogram |
bins | The number of bins that the histogram should have |
low | The lower edge of the X axis |
high | The higher edge of the X axis |
computeErrors | Flag for turning on/off the statistical uncertainty calculation |
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...
pos | The position at which a bin should be filled |
weight | The amount with which the bin should be filled |
Definition at line 116 of file SH1.icc.
References REPORT_FATAL, and SError::StopExecution.
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".
pos | The position on the X axis that should be associated to a bin |
Type SH1< Type >::GetBinContent | ( | Int_t | bin | ) | const |
Type SH1< Type >::GetBinError | ( | Int_t | bin | ) | const |
Int_t SH1< Type >::GetEntries | ( | ) | const |
Int_t SH1< Type >::GetNBins | ( | ) | const |
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.
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.
bin | The bin that should be accessed |
content | The new content of the bin |
void SH1< Type >::SetBinError | ( | Int_t | bin, |
Type | error | ||
) |
void SH1< Type >::SetEntries | ( | Int_t | entries | ) |
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.
Definition at line 250 of file SH1.icc.
References SLogger::endmsg(), and ERROR.
Int_t SH1< Type >::Write | ( | const char * | name = 0 , |
Int_t | option = 0 , |
||
Int_t | bufsize = 0 |
||
) | [virtual] |
Int_t SH1< Type >::Write | ( | const char * | name = 0 , |
Int_t | option = 0 , |
||
Int_t | bufsize = 0 |
||
) | const [virtual] |