164 fLowLimitX(0), fHighLimitX(0),
165 fLowLimitY(0), fHighLimitY(0),
166 fLowLimitZ(0), fHighLimitZ(0),
167 fData(0), fIntegralData(0),
193 fFitDone(
kFALSE), fChisquare(0), fPlot(0) {
211 TString s =
Form(
"Prediction for MC sample %i",par);
240 parameters.reserve(fNpar);
304 Error(
"SetWeight",
"Inconsistent weights histogram for source %d", parm);
325 if (parm < 0 || parm >
fNpar) {
326 Error(
"CheckParNo",
"Invalid parameter number %d",parm);
363 Error(
"SetRangeY",
"Y range cannot be set for 1D histogram");
392 Error(
"SetRangeZ",
"Z range cannot be set for 1D or 2D histogram");
417 for (
int b = 0;
b < excluded; ++
b) {
419 Error(
"ExcludeBin",
"bin %d already excluded", bin);
433 for (std::vector<Int_t>::iterator it =
fExcludedBins.begin();
442 Error(
"IncludeBin",
"bin %d was not excluded", bin);
483 Error(
"CheckConsistency",
"Nonexistent data histogram");
486 Int_t minX, maxX, minY, maxY, minZ, maxZ;
488 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
491 for (z = minZ; z <= maxZ; ++
z) {
492 for (y = minY; y <= maxY; ++
y) {
493 for (x = minX; x <= maxX; ++
x) {
501 Error(
"CheckConsistency",
"Empty data histogram");
509 Error(
"CheckConsistency",
"Need at least two MC histograms");
516 Error(
"CheckConsistency",
"Nonexistent MC histogram for source #%d",par);
522 Error(
"CheckConsistency",
"Histogram inconsistency for source #%d",par);
526 for (z = minZ; z <= maxZ; ++
z) {
527 for (y = minY; y <= maxY; ++
y) {
528 for (x = minX; x <= maxX; ++
x) {
533 Error(
"CheckConsistency",
"Number of MC events (bin = %d, par = %d) cannot be negative: " 534 " their distribution is binomial (see paper)", bin, par);
541 Error(
"CheckConsistency",
"Empty MC histogram #%d",par);
563 if (!status)
Warning(
"Fit",
"Abnormal termination of minimization.");
582 Error(
"ErrorAnalysis",
"Fit not yet performed");
602 Error(
"GetResult",
"Fit not yet performed");
620 Error(
"GetPlot",
"Fit not yet performed");
639 minY = maxY = minZ = maxZ = 0;
665 Int_t minX, maxX, minY, maxY, minZ, maxZ;
667 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
668 for (mc = 0; mc <
fNpar; ++mc) {
674 for (z = minZ; z <= maxZ; ++
z) {
675 for (y = minY; y <= maxY; ++
y) {
676 for (x = minX; x <= maxX; ++
x) {
680 Error(
"ComputeFCN",
"Invalid weight encountered for MC source %d",mc);
698 for (z = minZ; z <= maxZ; ++
z) {
699 for (y = minY; y <= maxY; ++
y) {
700 for (x = minX; x <= maxX; ++
x) {
710 for (mc = 0; mc <
fNpar; ++mc) {
719 binPrediction = binContent > 0 ? binContent / (1+weight*
fFractions[mc]*ti) : 0;
722 prediction +=
fFractions[mc]*weight*binPrediction;
723 result -= binPrediction;
724 if (binContent > 0 && binPrediction > 0)
725 result += binContent*
TMath::Log(binPrediction);
728 ((
TH1*)
fAji.
At(mc))->SetBinContent(bin, binPrediction);
736 result -= prediction;
738 if (found > 0 && prediction > 0)
753 std::vector<Double_t> wgtFrac(
fNpar);
754 std::vector<Double_t> a_ji(
fNpar);
763 if (wgtFrac[
par] == 0) {
764 Error(
"FindPrediction",
"Fraction[%d] = 0!",
par);
782 if (wgtFrac[
par] > maxWgtFrac) {
784 maxWgtFrac = wgtFrac[
par];
792 if (
par == k_0)
continue;
793 if (wgtFrac[
par] == maxWgtFrac) {
795 contentsMax += a_ji[
par];
801 if (contentsMax == 0) {
802 A_ki = d_i / (1.0 + maxWgtFrac);
804 if (
par == k_0 || wgtFrac[
par] == maxWgtFrac)
continue;
805 A_ki -= a_ji[
par] * wgtFrac[
par] / (maxWgtFrac - wgtFrac[
par]);
819 Int_t maxIter = 100000;
820 for(
Int_t i = 0; i < maxIter; ++i) {
821 if (t_i >= 1 || t_i < t_min) {
826 Double_t deriv = func / (1.0 - t_i);
829 func += a_ji[
par] *
r;
830 deriv -= a_ji[
par] * r *
r;
835 delta = (delta > 0) ? step : -step;
840 Warning(
"FindPrediction",
"Did not find solution for t_i in %d iterations", maxIter);
853 Error(
"TFractionFitFCN",
"Invalid fit object encountered!");
901 if (ndf <= 0)
return 0;
912 Error(
"ComputeChisquareLambda",
"Fit not yet (successfully) performed");
921 Int_t minX, maxX, minY, maxY, minZ, maxZ;
922 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
926 for(
Int_t x = minX;
x <= maxX;
x++) {
927 for(
Int_t y = minY;
y <= maxY;
y++) {
928 for(
Int_t z = minZ;
z <= maxZ;
z++) {
932 if(fi != 0) logLyn += di *
TMath::Log(fi) - fi;
933 if(di != 0) logLmn += di *
TMath::Log(di) - di;
937 if(bji != 0) logLyn += aji *
TMath::Log(bji) - bji;
938 if(aji != 0) logLmn += aji *
TMath::Log(aji) - aji;
960 Error(
"GetMCPrediction",
"Fit not yet performed");
Double_t EvaluateFCN(const Double_t *par)
virtual const char * GetName() const
Returns name of object.
virtual ~TFractionFitter()
TFractionFitter default destructor.
void RemoveLimits()
remove all limit
void Constrain(Int_t parm, Double_t low, Double_t high)
Constrain the values of parameter number <parm> (the parameter numbering follows that of the input te...
void SetPrintLevel(int level)
set print level
void ReleaseRangeX()
Release restrictions on the X range of the histogram to be used in the fit.
bool CalculateMinosErrors()
perform an error analysis on the result using MINOS To be called only after fitting and when a minimi...
double Error(unsigned int i) const
parameter error by index
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
Documentation for class Functor class.
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
Double_t GetChisquare() const
Return the likelihood ratio Chi-squared (chi2) for the fit.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
std::vector< Int_t > fExcludedBins
bool FitFCN(unsigned int npar, Function &fcn, const double *params=0, unsigned int dataSize=0, bool chi2fit=false)
Fit using the a generic FCN function as a C++ callable object implementing double () (const double *)...
void ToUpper()
Change string to upper case.
virtual Int_t GetNbinsZ() const
void TFractionFitFCN(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t flag)
double Parameter(unsigned int i) const
parameter value by index
void GetRanges(Int_t &minX, Int_t &maxX, Int_t &minY, Int_t &maxY, Int_t &minZ, Int_t &maxZ) const
Used internally to obtain the bin ranges according to the dimensionality of the histogram and the lim...
TObject * At(Int_t idx) const
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
void SetErrorDef(double err)
set error def
void ReleaseRangeY()
Release restrictions on the Y range of the histogram to be used in the fit.
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
const FitResult & Result() const
get fit result
virtual Int_t GetDimension() const
void SetRangeZ(Int_t low, Int_t high)
Set the Z range of the histogram to be used in the fit (3D histograms only).
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O...
void CheckConsistency()
Function used internally to check the consistency between the various histograms. ...
ROOT::Fit::Fitter * fFractionFitter
bool IsExcluded(Int_t bin) const
Function for internal use, checking whether the given bin is excluded from the fit or not...
void UnConstrain(Int_t parm)
Remove the constraints on the possible values of parameter <parm>.
void SetData(TH1 *data)
Change the histogram to be fitted to.
const FitConfig & Config() const
access to the fit configuration (const method)
void SetMC(Int_t parm, TH1 *MC)
Change the histogram for template number <parm>.
Int_t GetNDF() const
return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
void CheckParNo(Int_t parm) const
Function for internal use, checking parameter validity An invalid parameter results in an error...
TH1 * GetMCPrediction(Int_t parm) const
Return the adjusted MC template (Aji) for template (parm).
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
Fitter class, entry point for performing all type of fits.
void GetResult(Int_t parm, Double_t &value, Double_t &error) const
Obtain the fit result for parameter <parm> (the parameter numbering follows that of the input templat...
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
void SetRangeX(Int_t low, Int_t high)
Set the X range of the histogram to be used in the fit.
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
char * Form(const char *fmt,...)
const double * GetParams() const
parameter values (return const pointer)
The ROOT global object gROOT contains a list of all defined classes.
int Status() const
minimizer status code
TFractionFitter()
TFractionFitter default constructor.
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 void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
void ComputeFCN(Double_t &f, const Double_t *par, Int_t flag)
Used internally to compute the likelihood value.
TH1 * GetPlot()
Return the "template prediction" corresponding to the fit result (this is not the same as the weighte...
void ComputeChisquareLambda()
Method used internally to compute the likelihood ratio chi2 See the function GetChisquare() for detai...
double func(double *x, double *p)
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
void SetRangeY(Int_t low, Int_t high)
Set the Y range of the histogram to be used in the fit (2D or 3D histograms only).
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Double_t GetProb() const
return the fit probability
void ErrorAnalysis(Double_t UP)
Set UP to the given value (see class TMinuit), and perform a MINOS minimisation.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
you should not use this method at all Int_t Int_t z
Fits MC fractions to data histogram.
bool SetFCN(unsigned int npar, Function &fcn, const double *params=0, unsigned int dataSize=0, bool chi2fit=false)
Set a generic FCN function as a C++ callable object implementing double () (const double *) Note that...
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
double ErrorDef() const
error definition
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
TFitResultPtr Fit()
Perform the fit with the default UP value.
Int_t GetEntries() const
Return the number of objects in array (i.e.
void SetLimits(double low, double up)
set a double side limit, if low == up the parameter is fixed if low > up the limits are removed ...
void FindPrediction(int bin, double &t_i, int &k_0, double &A_ki) const
Function used internally to obtain the template prediction in the individual bins 'bin' <=> 'i' (pape...
void ExcludeBin(Int_t bin)
Exclude the given bin from the fit.
virtual void SetTitle(const char *title)
Change (i.e.
virtual Int_t GetNbinsX() const
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
void IncludeBin(Int_t bin)
Include the given bin in the fit, if it was excluded before using ExcludeBin().
void SetWeight(Int_t parm, TH1 *weight)
Set bin by bin weights for template number <parm> (the parameter numbering follows that of the input ...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual Int_t GetNbinsY() const
ROOT::Fit::Fitter * GetFitter() const
Give direct access to the underlying fitter class.
void ReleaseRangeZ()
Release restrictions on the Z range of the histogram to be used in the fit.
const char * Data() const