172 if(startWithRootNode) {
212(
const char *
name,
Int_t nBins,
const char *binNames)
236 AddAxis(axis,includeUnderflow,includeOverflow);
250(
const char *
name,
Int_t nBins,
const char *binNames)
268 "binning \"%s\" already has parent \"%s\", can not be added to %s",
274 "binning \"%s\" has previous node \"%s\", can not be added to %s",
280 "binning \"%s\" has next node \"%s\", can not be added to %s",
323 Fatal(
"AddAxis",
"number of bins %d is not positive",
327 Fatal(
"AddAxis",
"xmin=%f required to be smaller than xmax=%f",
333 for(
Int_t i=0;i<=nBin;i++) {
334 binBorders[i]=
x+i*dx;
336 r=
AddAxis(
name,nBin,binBorders,hasUnderflow,hasOverflow);
337 delete [] binBorders;
358 for(
Int_t i=0;i<nBin;i++) {
363 delete [] binBorders;
384 Fatal(
"AddAxis",
"node already has %d bins without axis",
387 Fatal(
"AddAxis",
"number of bins %d is not positive",
392 for(
Int_t i=0;i<=nBin;i++) {
393 (*bins)(i)=binBorders[i];
395 Fatal(
"AddAxis",
"bin border %d is not finite",i);
397 }
else if((i>0)&&((*bins)(i)<=(*bins)(i-1))) {
398 Fatal(
"AddAxis",
"bins not in order x[%d]=%f <= %f=x[%d]",
399 i,(*bins)(i),(*bins)(i-1),i-1);
405 Int_t bitMask=1<<axis;
439 out<<
"TUnfoldBinning \""<<
GetName()<<
"\" has ";
471 (ibin<fAxisLabelList->GetEntriesFast());ibin++) {
550 r=child->FindNode(
name);
590(
const char *histogramName,
const char *histogramTitle,
Int_t const *axisList)
599 for(iEnd=2;iEnd>0;iEnd--) {
600 if(axisList[iEnd]>=0)
break;
602 for(
Int_t i=0;i<=iEnd;i++) {
634(
const char *histogramName,
const char *histogramTitle,
645 }
else if(xAxis>=0) {
651 }
else if(yAxis>=0) {
684(
Bool_t originalAxisBinning,
const char *axisSteering)
const
686 Int_t axisBins[3],axisList[3];
742(
const char *histogramName,
Bool_t originalAxisBinning,
Int_t **binMap,
743 const char *histogramTitle,
const char *axisSteering)
const
745 Int_t nBin[3],axisList[3];
760 r=
new TH3D(histogramName,title,
765 r=
new TH2D(histogramName,title,
773 if(originalAxisBinning) {
775 "Original binning can not be represented as THxx");
777 r=
new TH1D(histogramName,title,nBin[0],0.5,nBin[0]+0.5);
803(
const char *histogramName,
Bool_t originalAxisBinning,
Int_t **binMap,
804 const char *histogramTitle,
const char *axisSteering)
const
806 Int_t nBin[3],axisList[3];
817 if(originalAxisBinning) {
818 Info(
"CreateErrorMatrixHistogram",
819 "Original binning can not be represented on one axis");
821 r=
new TH2D(histogramName,title,nBin[0],0.5,nBin[0]+0.5,
822 nBin[0],0.5,nBin[0]+0.5);
847 char const *histogramName,
Bool_t originalXAxisBinning,
848 Bool_t originalYAxisBinning,
char const *histogramTitle)
850 Int_t nBinX[3],axisListX[3];
852 xAxis->
GetTHxxBinning(originalXAxisBinning ? 1 : 0,nBinX,axisListX,0);
854 Int_t nBinY[3],axisListY[3];
856 yAxis->
GetTHxxBinning(originalYAxisBinning ? 1 : 0,nBinY,axisListY,0);
859 (histogramName,histogramTitle,axisListX[0],yAxis,axisListY[0]);
866 return new TH2D(histogramName,title,
870 return new TH2D(histogramName,title,
872 nBinY[0],0.5,0.5+nBinY[0]);
878 return new TH2D(histogramName,title,
879 nBinX[0],0.5,0.5+nBinX[0],
882 return new TH2D(histogramName,title,
883 nBinX[0],0.5,0.5+nBinX[0],
884 nBinY[0],0.5,0.5+nBinY[0]);
905 const char *axisSteering)
const
907 for(
Int_t i=0;i<3;i++) {
914 (maxDim,axisBins,axisList,axisSteering);
963(
Int_t maxDim,
Int_t *axisBins,
Int_t *axisList,
const char *axisSteering)
const
969 Int_t isOptionGiven[3];
974 for(
Int_t i=0;i<numDimension;i++) {
975 if(isOptionGiven[0] & (1<<i))
continue;
978 if((
r>0)&&(
r<=maxDim)) {
984 for(
Int_t i=0;i<numDimension;i++) {
985 if(isOptionGiven[0] & (1<<i))
continue;
997 for(
Int_t i=0;i<numDimension;i++) {
999 if(isOptionGiven[0] & mask)
continue;
1001 if((
fHasUnderflow & mask)&& !(isOptionGiven[1] & mask)) nBinI++;
1002 if((
fHasOverflow & mask)&& !(isOptionGiven[2] & mask)) nBinI++;
1026 r +=child->GetTHxxBinsRecursive(axisSteering);
1029 Int_t axisBins[3],axisList[3];
1046 for(
Int_t i=0;i<nMax;i++) {
1062 if((globalBin<0)||(globalBin>=nMax)) {
1063 Error(
"SetBinMapEntry",
"global bin number %d outside range (max=%d)",
1066 binMap[globalBin]=destBin;
1083(
Int_t *binMap,
const char *axisSteering,
Int_t firstBinX)
const {
1085 Int_t axisBins[3],axisList[3];
1090 Error(
"FillBinMap1D",
"distribution %s with steering=%s is not 1D",
1091 (
char *)
GetName(),axisSteering);
1095 r =child->FillBinMap1D(binMap,axisSteering,
r);
1144(
const TH1 *hist,
Int_t nDim,
const Int_t *axisList,
const char *axisSteering)
1155 Fatal(
"CreateBinMap",
"called with nDim=%d but GetNonemptyNode()=0",
1176(
Int_t startBin,
const char *axisSteering,
Int_t *binMap)
const
1182 nbin += child->FillBinMapRecursive(startBin+nbin,axisSteering,binMap);
1215 const char *axisSteering,
Int_t *binMap)
const
1221 Int_t isOptionGiven[3+10];
1223 Int_t haveSelectedBin=0;
1224 for(
Int_t i=3;i<3+10;i++) {
1225 haveSelectedBin |= isOptionGiven[i];
1231 for(
Int_t i=0;i<dimension;i++) {
1240 Fatal(
"FillBinMapSingleNode",
1241 "bin %d outside binning scheme",
1244 Fatal(
"FillBinMapSingleNode",
1245 "bin %d located in %s %d-%d rather than %s %d=%d",
1246 i,(
const char *)
dest->GetName(),
1247 dest->GetStartBin(),
dest->GetEndBin(),
1253 for(
Int_t axis=0;axis<dimension;axis++) {
1254 Int_t mask=(1<<axis);
1256 if(((axisBins[axis]<0)&&(isOptionGiven[1] & mask))||
1257 ((axisBins[axis]>=axisNbin[axis])&&(isOptionGiven[2] & mask)))
1260 if((axisBins[axis]>=0)&&(axisBins[axis]<axisNbin[axis])&&
1261 (haveSelectedBin & mask)) {
1262 if(!(isOptionGiven[3+axisBins[axis]] & mask)) skip=
kTRUE;
1273 ibin[0]=ibin[1]=ibin[2]=0;
1274 for(
Int_t hdim=0;hdim<nDim;hdim++) {
1275 Int_t axis=axisList[hdim];
1276 ibin[hdim]=axisBins[axis]+1;
1278 binMap[globalBin]=hist->
GetBin(ibin[0],ibin[1],ibin[2]);
1279 }
else if(nDim==1) {
1287 Error(
"FillBinMapSingleNode",
"inconsistent dimensions %d %d",nDim,
1291 if(axisList[ii]>=0) {
1292 binMap[globalBin]=axisBins[axisList[ii]]+1;
1297 Fatal(
"FillBinMapSingleNode",
"inconsistent dimensions %d %d",nDim,
1307 for(
Int_t axis=dimension-1;axis>=0;axis--) {
1308 Int_t mask=(1<<axis);
1309 if(isOptionGiven[0] & mask) {
1313 Int_t iBin=axisBins[axis];
1314 Int_t nMax=axisNbin[axis];
1324 binMap[globalBin] = startBin +
r;
1326 binMap[globalBin] = startBin + axisBins[0];
1333 for(
Int_t axis=dimension-1;axis>=0;axis--) {
1334 Int_t mask=(1<<axis);
1335 if(isOptionGiven[0] & mask) {
1339 Int_t nMax=axisNbin[axis];
1375(
const char *histogramName,
const TH1 *globalBins,
1376 const TH2 *globalBinsEmatrix,
Bool_t originalAxisBinning,
1377 const char *axisSteering)
const
1386 if(binMap[iSrc]>nMax) nMax=binMap[iSrc];
1394 Int_t iDest=binMap[iSrc];
1398 if(!globalBinsEmatrix) {
1403 if(binMap[jSrc]==iDest) {
1411 for(
Int_t i=0;i<nMax;i++) {
1436 Fatal(
"GetBinNumber",
1437 "called with 1 argument for %d dimensional distribution",
1456 Fatal(
"GetBinNumber",
1457 "called with 2 arguments for %d dimensional distribution",
1485 Fatal(
"GetBinNumber",
1486 "called with 3 arguments for %d dimensional distribution",
1516 Fatal(
"GetBinNumber",
1517 "called with 4 arguments for %d dimensional distribution",
1549 Fatal(
"GetBinNumber",
1550 "called with 5 arguments for %d dimensional distribution",
1584 Fatal(
"GetBinNumber",
1585 "called with 6 arguments for %d dimensional distribution",
1631 Fatal(
"GetBinNumber",
1632 "no axes are defined for node %s",
1641 if(!(
x[dim]>=(*bins)[i0])) {
1644 }
else if(!(
x[dim]<(*bins)[i1])) {
1650 if(
x[dim]<(*bins)[i2]) {
1658 iAxisBins[dim]=iBin;
1688 for(
Int_t axis=0;axis<dimension;axis++) {
1692 Int_t i=axisBins[axis];
1693 if(i<0) thisAxisString +=
"[ufl]";
1694 else if(i>=bins->
GetNrows()-1) thisAxisString +=
"[ofl]";
1699 axisString =
":"+thisAxisString+axisString;
1704 Int_t i=axisBins[0];
1732 Int_t pos=axisBins[axis];
1735 }
else if(pos>=bins->
GetNrows()-1) {
1738 r *= (*bins)(pos+1)-(*bins)(pos);
1782 for(
Int_t axis=0;axis<dimension;axis++) {
1784 (axis,axisBins[axis]);
1797 Error(
"GetBinFactor",
1798 "internal error: user function is neither TF1 or TVectorD");
1837 if((axis>=0)&&(axis<dimension)) {
1841 Int_t centerBin= axisBins[axis];
1842 axisBins[axis] =centerBin-1;
1846 }
else if((axisBins[axis]<0)&&(nMax>=3)) {
1847 axisBins[axis]=nMax-1;
1855 axisBins[axis] =centerBin+1;
1859 }
else if((axisBins[axis]==nMax)&&(nMax>=3)) {
1887 for(
Int_t axis=0;axis<dimension;axis++) {
1890 if(axisBins[axis]<0) *uStatus |= (1<<axis);
1891 if(axisBins[axis]>=nBin) *oStatus |= (1<<axis);
1911 if(bin<fAxisLabelList->GetEntriesFast()) {
1952 Error(
"GetDistributionAverageBinSize",
"axis %d does not exist",axis);
1971 return (*bins)[1]-(*bins)[0];
2015 }
else if(bin>=bins->
GetNrows()-1) {
2019 r=0.5*((*bins)[bin+1]+(*bins)[bin]);
2040 if(isBelow) *isBelow=0;
2041 if(isAbove) *isAbove=0;
2043 for(
Int_t axis=dimension-1;axis>=0;axis--) {
2045 Int_t i=axisBins[axis];
2051 if((i>=0)&&(i<nMax)) {
2052 if(
r>=0)
r =
r*nMax +i;
2055 if((i<0)&&(isBelow)) *isBelow |= 1<<axis;
2056 if((i>=nMax)&&(isAbove)) *isAbove |= 1<<axis;
2066 Fatal(
"ToGlobalBin",
"bad input %d for dimensionless binning %s %d",
2067 axisBins[0],(
const char *)
GetName(),
2097 for(
int axis=0;axis<dimension;axis++) {
2105 axisBins[axis] += i % nMax;
2136(
const char *axisSteering,
const char *options,
Int_t *isOptionGiven)
const
2139 for(
Int_t i=0;i<nOpt;i++) isOptionGiven[i]=0;
2144 for(
Int_t i=0;i<nPattern;i++) {
2149 if((bracketBegin>0)&&(pattern[len-1]==
']')) {
2150 TString axisId=pattern(0,bracketBegin);
2152 if((axisId[0]==
'*')&&(axisId.
Length()==1)) {
2157 for(
Int_t j=0;j<nAxis;j++) {
2163 for(
Int_t o=0;o<nOpt;o++) {
2164 if(pattern.
Last(options[o])>bracketBegin) {
2165 isOptionGiven[o] |= mask;
2169 Error(
"DecodeAxisSteering",
2170 "steering \"%s\" does not end with [options]",
2171 (
const char *)pattern);
static const double x2[5]
static const double x4[22]
static const double x1[5]
static const double x3[11]
static void indent(ostringstream &buf, int indent_level)
TVectorT< Double_t > TVectorD
Class to manage histogram axis.
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
const char * GetTitle() const
Returns title of object.
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
1-D histogram with a double per channel (see TH1 documentation)}
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
virtual Int_t GetDimension() const
virtual Int_t GetBin(Int_t binx, Int_t biny=0, Int_t binz=0) const
Return Global bin number corresponding to binx,y,z.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
2-D histogram with a double per channel (see TH1 documentation)}
Service class for 2-Dim histogram classes.
3-D histogram with a double per channel (see TH1 documentation)}
The TNamed class is the base class for all named ROOT classes.
virtual const char * GetName() const
Returns name of object.
Int_t GetEntriesFast() const
virtual void AddLast(TObject *obj)
Add object in the next empty slot in the array.
Int_t GetEntries() const
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const
Collectable string class.
Mother of all ROOT objects.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Ssiz_t Last(char c) const
Find last occurrence of a character c.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Binning schemes for use with the unfolding algorithm TUnfoldDensity.
void PrintStream(std::ostream &out, Int_t indent=0, int debug=0) const
Print some information about this binning tree.
@ MAXDIM
maximum numner of axes per distribution
Bool_t HasOverflow(int axis) const
check whether the axis has an overflow bin
Int_t GetTH1xNumberOfBins(Bool_t originalAxisBinning=kTRUE, const char *axisSteering=0) const
Return the number of histogram bins required when storing this binning in a one-dimensional histogram...
Int_t FillBinMapSingleNode(const TH1 *hist, Int_t startBin, Int_t nDim, const Int_t *axisList, const char *axisSteering, Int_t *binMap) const
Fill bin map for a single node.
virtual Double_t GetDistributionOverflowBinWidth(Int_t axis) const
Return bin width assigned to the overflow bin.
TH1 * CreateHistogram(const char *histogramName, Bool_t originalAxisBinning=kFALSE, Int_t **binMap=0, const char *histogramTitle=0, const char *axisSteering=0) const
Create a THxx histogram capable to hold the bins of this binning node and its children.
TH1 * ExtractHistogram(const char *histogramName, const TH1 *globalBins, const TH2 *globalBinsEmatrix=0, Bool_t originalAxisBinning=kTRUE, const char *axisSteering=0) const
Extract a distribution from the given set of global bins.
Int_t fFirstBin
global bin number of the first bin
virtual ~TUnfoldBinning(void)
Int_t UpdateFirstLastBin(Bool_t startWithRootNode=kTRUE)
Update fFirstBin and fLastBin members of this node and its children.
TString BuildHistogramTitle(const char *histogramName, const char *histogramTitle, Int_t const *axisList) const
Construct a title.
Int_t FillBinMapRecursive(Int_t startBin, const char *axisSteering, Int_t *binMap) const
Recursively fill bin map.
Int_t FillBinMap1D(Int_t *binMap, const char *axisSteering, Int_t firstBinX) const
Map all global bins referenced by this node to the one-dimensional histogram destHist,...
TUnfoldBinning * parentNode
mother node
Int_t GetDistributionDimension(void) const
query dimension of this node's distribution
TUnfoldBinning const * GetPrevNode(void) const
previous sister node
void SetBinFactor(Double_t normalisation, TObject *factors)
Set normalisation factors which are used in calls to GetBinFactor().
TUnfoldBinning * childNode
first daughter node
TString GetBinName(Int_t iBin) const
Get the name of a bin.
virtual Double_t GetDistributionUnderflowBinWidth(Int_t axis) const
Return bin width assigned to the underflow bin.
Double_t GetBinSize(Int_t iBin) const
Get N-dimensional bin size.
Int_t GetDistributionNumberOfBins(void) const
number of bins in the distribution possibly including under/overflow
Double_t GetGlobalFactor(void) const
Return global scaling factor for this node.
Int_t GetGlobalBinNumber(Double_t x) const
Locate a bin in a one-dimensional distribution.
Bool_t HasUnconnectedBins(void) const
Check whether there are bins but no axis.
void SetBinFactorFunction(Double_t normalisation, TF1 *userFunc=0)
Set normalisation factor and function which are used in calls to GetBinFactor().
virtual Double_t GetBinFactor(Int_t iBin) const
Return scaling factor for the given global bin number.
TUnfoldBinning * nextNode
next sister
TObject * fBinFactorFunction
function to calculate a scale factor from bin centres (may be a TF1 or a TVectorD
Int_t GetTHxxBinning(Int_t maxDim, Int_t *axisBins, Int_t *axisList, const char *axisSteering) const
Calculate properties of a THxx histogram to store this binning.
Int_t fHasUnderflow
bit fields indicating whether there are underflow bins on the axes
Int_t GetEndBin(void) const
last+1 bin of this node (includes children)
TObjArray * fAxisLabelList
for each axis its name (TObjString), or names of unconnected bins
Double_t fBinFactorConstant
common scale factor for all bins of this node
TUnfoldBinning const * GetNextNode(void) const
next sister node
Bool_t HasUnderflow(int axis) const
check whether an axis has an underflow bin
Int_t ToGlobalBin(Int_t const *axisBins, Int_t *isBelow=0, Int_t *isAbove=0) const
Get global bin number, given axis bin numbers.
Int_t * CreateEmptyBinMap(void) const
Create an empty bin map, useful together with the getter methods of class TUnfold and TUnfoldSys.
static TH2D * CreateHistogramOfMigrations(TUnfoldBinning const *xAxis, TUnfoldBinning const *yAxis, char const *histogramName, Bool_t originalXAxisBinning=kFALSE, Bool_t originalYAxisBinning=kFALSE, char const *histogramTitle=0)
Create a TH2D histogram capable to hold the bins of the two input binning schemes on the x and y axes...
TUnfoldBinning const * GetParentNode(void) const
mother node
TObjArray * fAxisList
for each axis the bin borders (TVectorD)
Int_t fLastBin
global bin number of the last(+1) bin, including daughters
void GetBinUnderflowOverflowStatus(Int_t iBin, Int_t *uStatus, Int_t *oStatus) const
Return bit maps indicating underflow and overflow status.
virtual Double_t GetDistributionBinCenter(Int_t axis, Int_t bin) const
return bin center for a given axis and bin number
Int_t fDistributionSize
number of bins in this node's distribution
Int_t fHasOverflow
bit fields indicating whether there are overflow bins on the axes
const TUnfoldBinning * GetNonemptyNode(void) const
Find a node which has non-empty distributions if there is none or if there are many,...
void Initialize(Int_t nBins)
Initialize variables for a given number of bins.
void SetBinMapEntry(Int_t *binMap, Int_t globalBin, Int_t destBin) const
Set one entry in a bin map.
virtual Double_t GetDistributionAverageBinSize(Int_t axis, Bool_t includeUnderflow, Bool_t includeOverflow) const
Get average bin size on the specified axis.
void DecodeAxisSteering(const char *axisSteering, const char *options, Int_t *isOptionGiven) const
Decode axis steering.
virtual Bool_t IsBinFactorGlobal(void) const
Check whether there is only a global scaling factor for this node.
TString GetDistributionAxisLabel(Int_t axis) const
get name of an axis
TH2D * CreateErrorMatrixHistogram(const char *histogramName, Bool_t originalAxisBinning, Int_t **binMap=0, const char *histogramTitle=0, const char *axisSteering=0) const
Create a TH2D histogram capable to hold a covariance matrix.
TUnfoldBinning * AddBinning(TUnfoldBinning *binning)
Add a TUnfoldBinning as the last child of this node.
const TObjString * GetUnconnectedBinName(Int_t bin) const
Return the bin names of unconnected bins.
Int_t GetBinNeighbours(Int_t globalBin, Int_t axis, Int_t *prev, Double_t *distPrev, Int_t *next, Double_t *distNext, Bool_t isPeriodic=kFALSE) const
Get neighbour bins along the specified axis.
TVectorD const * GetDistributionBinning(Int_t axis) const
get vector of bin borders for one axis
TUnfoldBinning(const char *name=0, Int_t nBins=0, const char *binNames=0)
Create a new node without axis.
Int_t * CreateBinMap(const TH1 *hist, Int_t nDim, const Int_t *axisList, const char *axisSteering) const
Create mapping from global bin number to a histogram for this node.
Bool_t AddAxis(const char *name, Int_t nBins, const Double_t *binBorders, Bool_t hasUnderflow, Bool_t hasOverflow)
Add an axis with the specified bin borders.
TUnfoldBinning * prevNode
previous sister
TUnfoldBinning const * GetRootNode(void) const
return root node of the binnig scheme
Int_t GetStartBin(void) const
first bin of this node
TUnfoldBinning const * ToAxisBins(Int_t globalBin, Int_t *axisBins) const
Return distribution in which the bin is located and bin numbers on the corresponding axes.
TUnfoldBinning const * FindNode(char const *name) const
Traverse the tree and return the first node which matches the given name.
Int_t GetTHxxBinsRecursive(const char *axisSteering) const
Calculate number of bins required to store this binning with the given axisSteering.
TUnfoldBinning const * GetChildNode(void) const
first daughter node
Int_t GetTHxxBinningSingleNode(Int_t maxDim, Int_t *axisBins, Int_t *axisList, const char *axisSteering) const
Get the properties of a histogram capable to hold the distribution attached to this node.
TString BuildHistogramTitle2D(const char *histogramName, const char *histogramTitle, Int_t xAxis, const TUnfoldBinning *yAxisBinning, Int_t yAxis) const
Construct a histogram title for a 2D histogram with different binning schemes on x and y axis.
Element * GetMatrixArray()
std::string GetName(const std::string &scope_name)
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Int_t Finite(Double_t x)
Check if it is finite with a mask in order to be consistent in presence of fast math.
Double_t Sqrt(Double_t x)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
#define dest(otri, vertexptr)