#ifndef ROOT_TUnfoldBinning
#define ROOT_TUnfoldBinning
#include "TUnfold.h"
#include <iostream>
#include <TNamed.h>
#include <TObjArray.h>
#include <TObjString.h>
class TAxis;
class TF1;
class TUnfoldBinning : public TNamed {
protected:
TUnfoldBinning *parentNode;
TUnfoldBinning *childNode;
TUnfoldBinning *nextNode;
TUnfoldBinning *prevNode;
TObjArray *fAxisList;
TObjArray *fAxisLabelList;
Int_t fHasUnderflow,fHasOverflow;
Int_t fDistributionSize;
Int_t fFirstBin;
Int_t fLastBin;
TF1 *fBinFactorFunction;
Double_t fBinFactorConstant;
public:
TUnfoldBinning(const char *name=0,Int_t nBins=0,const char *binNames=0);
TUnfoldBinning(const TAxis &axis,Int_t includeUnderflow,Int_t includeOverflow);
TUnfoldBinning *AddBinning(TUnfoldBinning *binning);
TUnfoldBinning *AddBinning(const char *name,Int_t nBins=0,const char *binNames=0);
Bool_t AddAxis(const char *name,Int_t nBins,const Double_t *binBorders,
Bool_t hasUnderflow,Bool_t hasOverflow);
Bool_t AddAxis(const char *name,Int_t nBins,Double_t xMin,Double_t xMax,
Bool_t hasUnderflow,Bool_t hasOverflow);
Bool_t AddAxis(const TAxis &axis,Bool_t includeUnderflow,Bool_t includeOverflow);
virtual ~TUnfoldBinning(void);
void PrintStream(std::ostream &out,Int_t indent=0) const;
inline void SetBinFactorFunction(Double_t normalisation,TF1 *userFunc=0) {
fBinFactorConstant=normalisation; fBinFactorFunction=userFunc; }
inline TUnfoldBinning const *GetChildNode(void) const { return childNode; }
inline TUnfoldBinning const *GetPrevNode(void) const { return prevNode; }
inline TUnfoldBinning const *GetNextNode(void) const { return nextNode; }
inline TUnfoldBinning const *GetParentNode(void) const { return parentNode; }
TUnfoldBinning const *FindNode(char const *name) const;
Int_t GetTH1xNumberOfBins(Bool_t originalAxisBinning=kTRUE,const char *axisSteering=0) const;
TH1 *CreateHistogram(const char *histogramName,Bool_t originalAxisBinning=kFALSE,Int_t **binMap=0,const char *histogramTitle=0,const char *axisSteering=0) const;
TH2D *CreateErrorMatrixHistogram(const char *histogramName,Bool_t originalAxisBinning,Int_t **binMap=0,const char *histogramTitle=0,const char *axisSteering=0) const;
static TH2D *CreateHistogramOfMigrations(TUnfoldBinning const *xAxis,
TUnfoldBinning const *yAxis,
char const *histogramName,
Bool_t originalXAxisBinning=kFALSE,
Bool_t originalYAxisBinning=kFALSE,
char const *histogramTitle=0);
TH1 *ExtractHistogram(const char *histogramName,const TH1 *globalBins,const TH2 *globalBinsEmatrix=0,Bool_t originalAxisBinning=kTRUE,const char *axisSteering=0) const;
Int_t GetGlobalBinNumber(Double_t x) const;
Int_t GetGlobalBinNumber(Double_t x,Double_t y) const;
Int_t GetGlobalBinNumber(Double_t x,Double_t y,Double_t z) const;
Int_t GetGlobalBinNumber(Double_t x0,Double_t x1,Double_t x2,Double_t x3) const;
Int_t GetGlobalBinNumber(const Double_t *x) const;
inline Int_t GetStartBin(void) const { return fFirstBin; }
inline Int_t GetEndBin(void) const { return fLastBin; }
TString GetBinName(Int_t iBin) const;
Double_t GetBinSize(Int_t iBin) const;
virtual Double_t GetBinFactor(Int_t iBin) const;
void GetBinUnderflowOverflowStatus(Int_t iBin,Int_t *uStatus,Int_t *oStatus) const;
void GetBinNeighbours(Int_t globalBin,Int_t axis,
Int_t *prev,Double_t *distPrev,
Int_t *next,Double_t *distNext) const;
enum { MAXDIM=32 };
const TUnfoldBinning *GetBinLocation(Int_t binTHxx,const char *axisSteering,
Int_t axisBins[MAXDIM]) const;
void DecodeAxisSteering(const char *axisSteering,const char *options,
Int_t *isOptionGiven) const;
inline Int_t GetDistributionNumberOfBins(void) const { return fDistributionSize; }
inline Int_t GetDistributionDimension(void) const { return fAxisList->GetEntriesFast(); }
virtual Double_t GetDistributionAverageBinSize(Int_t axis,Bool_t includeUnderflow, Bool_t includeOverflow) const;
inline TVectorD const *GetDistributionBinning(Int_t axis) const {
return (TVectorD const *)fAxisList->At(axis); }
inline TString GetDistributionAxisLabel(Int_t axis) const {
return ((TObjString * const)fAxisLabelList->At(axis))->GetString(); }
virtual Double_t GetDistributionUnderflowBinWidth(Int_t axis) const;
virtual Double_t GetDistributionOverflowBinWidth(Int_t axis) const;
virtual Double_t GetDistributionBinCenter(Int_t axis,Int_t bin) const;
protected:
TUnfoldBinning *GetRootNode(void);
TUnfoldBinning const *GetRootNode(void) const;
void Initialize(Int_t nBins);
Int_t UpdateFirstLastBin(Bool_t startWithRootNode=kTRUE);
Bool_t HasUnconnectedBins(void) const;
TUnfoldBinning const *ToAxisBins(Int_t globalBin,Int_t *axisBins) const;
Int_t ToGlobalBin(Int_t const *axisBins) const;
TString BuildHistogramTitle(const char *histogramName,const char *histogramTitle,
Int_t const *axisList) const;
TString BuildHistogramTitle2D(const char *histogramName,const char *histogramTitle,
Int_t xAxis,const TUnfoldBinning *yAxisBinning,Int_t yAxis) const;
Int_t GetTHxxBinning(Int_t maxDim,Int_t *axisBins,Int_t *axisList,const char *axisSteering) const;
Int_t GetTHxxBinningSingleNode(Int_t maxDim,Int_t *axisBins,Int_t *axisList,const char *axisSteering) const;
Int_t GetTHxxBinsRecursive(const char *axisSteering) const;
const TUnfoldBinning *GetBinLocationRecursive(Int_t &offset,const char *axisSteering,
Int_t axisBins[MAXDIM]) const;
const TUnfoldBinning *GetNonemptyNode(void) const;
Int_t *CreateBinMap(const TH1 *hist,Int_t nDim,const Int_t *axisList,const char *axisSteering) const;
Int_t FillBinMapRecursive(Int_t startBin,const char *axisSteering,
Int_t *binMap) const;
Int_t FillBinMapSingleNode(const TH1 *hist,Int_t startBin,Int_t nDim,const Int_t *axisList,const char *axisSteering,Int_t *binMap) const;
ClassDef(TUnfoldBinning, TUnfold_CLASS_VERSION)
};
#endif