#ifndef ROOT_TFractionFitter
#define ROOT_TFractionFitter
#ifndef ROOT_TVirtualFitter
# include "TVirtualFitter.h"
#endif
#ifndef ROOT_TObjArray
# include "TObjArray.h"
#endif
class TH1;
class TFractionFitter: public TObject {
public:
TFractionFitter();
TFractionFitter(TH1* data, TObjArray *MCs);
virtual ~TFractionFitter();
TVirtualFitter* GetFitter() const;
void ErrorAnalysis(Double_t UP);
void SetRangeX(Int_t low, Int_t high);
void ReleaseRangeX();
void SetRangeY(Int_t low, Int_t high);
void ReleaseRangeY();
void SetRangeZ(Int_t low, Int_t high);
void ReleaseRangeZ();
void Constrain(Int_t parm, Double_t low, Double_t high);
void UnConstrain(Int_t parm);
void SetData(TH1 *data);
void SetMC(Int_t parm, TH1 *MC);
void SetWeight(Int_t parm, TH1* weight);
Int_t Fit();
void GetResult(Int_t parm, Double_t& value, Double_t& error) const;
TH1* GetPlot();
friend void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
Double_t GetChisquare() const;
Int_t GetNDF() const;
Double_t GetProb() const;
TH1* GetMCPrediction(Int_t parm) const;
private:
void CheckParNo(Int_t parm) const;
void CheckConsistency();
void FindPrediction(int bin, double* fractions, double& Ti, int& k0, double& Aki) const;
void ComputeFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
void GetRanges(Int_t& minX, Int_t& maxX, Int_t& minY, Int_t& maxY,
Int_t& minZ, Int_t& maxZ) const;
void ComputeChisquareLambda();
protected:
Bool_t fFitDone;
Int_t fLowLimitX;
Int_t fHighLimitX;
Int_t fLowLimitY;
Int_t fHighLimitY;
Int_t fLowLimitZ;
Int_t fHighLimitZ;
Int_t fNpfits;
Int_t fNDF;
Double_t fChisquare;
TObjArray fAji;
TH1* fData;
TObjArray fMCs;
TObjArray fWeights;
Double_t fIntegralData;
Double_t* fIntegralMCs;
Double_t* fFractions;
TH1* fPlot;
Int_t fNpar;
ClassDef(TFractionFitter, 0)
};
void TFractionFitFCN(Int_t& npar, Double_t* gin, Double_t& f, Double_t* par, Int_t flag);
#endif // ROOT_TFractionFitter