164fLowLimitX(0), fHighLimitX(0),
165fLowLimitY(0), fHighLimitY(0),
166fLowLimitZ(0), fHighLimitZ(0),
167fData(0), fIntegralData(0),
193fFitDone(
kFALSE), fChisquare(0), fPlot(0) {
208 for (par = 0; par <
fNpar; ++par) {
240 parameters.reserve(
fNpar);
241 for (par = 0; par <
fNpar; ++par) {
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");
513 for (par = 0; par <
fNpar; ++par) {
516 Error(
"CheckConsistency",
"Nonexistent MC histogram for source #%d",par);
519 if ((!
h->Class()->InheritsFrom(cl)) ||
h->GetNbinsX() !=
fData->
GetNbinsX() ||
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) {
531 Double_t MCEvents =
h->GetBinContent(bin);
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);
683 tot += weight *
h->GetBinContent(
x,
y, z);
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) {
714 Double_t binContent =
h->GetBinContent(bin);
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);
760 a_ji[par] = ((
TH1*)
fMCs.
At(par))->GetBinContent(bin);
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) {
825 Double_t func = - d_i / (1.0 - t_i);
826 Double_t deriv = func / (1.0 - t_i);
828 Double_t r = 1.0 / (t_i + 1.0 / wgtFrac[par]);
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");
void Error(const char *location, const char *msgfmt,...)
void TFractionFitFCN(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t flag)
char * Form(const char *fmt,...)
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
const double * GetParams() const
parameter values (return const pointer)
double Error(unsigned int i) const
parameter error by index
double Parameter(unsigned int i) const
parameter value by index
int Status() const
minimizer status code
Fitter class, entry point for performing all type of fits.
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 *)...
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...
const FitResult & Result() const
get fit result
const FitConfig & Config() const
access to the fit configuration (const method)
bool CalculateMinosErrors()
perform an error analysis on the result using MINOS To be called only after fitting and when a minimi...
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
void RemoveLimits()
remove all limit
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 The c...
Documentation for class Functor class.
Documentation for the abstract class IBaseFunctionMultiDim.
double ErrorDef() const
error definition
void SetErrorDef(double err)
set error def
void SetPrintLevel(int level)
set print level
The ROOT global object gROOT contains a list of all defined classes.
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O.
Fits MC fractions to data histogram.
void ComputeFCN(Double_t &f, const Double_t *par, Int_t flag)
Used internally to compute the likelihood value.
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...
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...
virtual ~TFractionFitter()
TFractionFitter default destructor.
TH1 * GetPlot()
Return the "template prediction" corresponding to the fit result (this is not the same as the weighte...
Double_t GetProb() const
return the fit probability
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...
void CheckConsistency()
Function used internally to check the consistency between the various histograms.
void SetRangeX(Int_t low, Int_t high)
Set the X range of the histogram to be used in the fit.
void SetMC(Int_t parm, TH1 *MC)
Change the histogram for template number <parm>.
Double_t EvaluateFCN(const Double_t *par)
ROOT::Fit::Fitter * GetFitter() const
Give direct access to the underlying fitter class.
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).
void ExcludeBin(Int_t bin)
Exclude the given bin from the fit.
TFractionFitter()
TFractionFitter default constructor.
void IncludeBin(Int_t bin)
Include the given bin in the fit, if it was excluded before using ExcludeBin().
ROOT::Fit::Fitter * fFractionFitter
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 SetData(TH1 *data)
Change the histogram to be fitted to.
bool IsExcluded(Int_t bin) const
Function for internal use, checking whether the given bin is excluded from the fit or not.
void SetRangeZ(Int_t low, Int_t high)
Set the Z range of the histogram to be used in the fit (3D histograms only).
Double_t GetChisquare() const
Return the likelihood ratio Chi-squared (chi2) for the fit.
void UnConstrain(Int_t parm)
Remove the constraints on the possible values of parameter <parm>.
Int_t GetNDF() const
return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
void ReleaseRangeZ()
Release restrictions on the Z range of the histogram to be used in the fit.
void SetWeight(Int_t parm, TH1 *weight)
Set bin by bin weights for template number <parm> (the parameter numbering follows that of the input ...
void ReleaseRangeX()
Release restrictions on the X range of the histogram to be used in the fit.
void ErrorAnalysis(Double_t UP)
Set UP to the given value (see class TMinuit), and perform a MINOS minimisation.
void ComputeChisquareLambda()
Method used internally to compute the likelihood ratio chi2 See the function GetChisquare() for detai...
TFitResultPtr Fit()
Perform the fit with the default UP value.
void ReleaseRangeY()
Release restrictions on the Y range of the histogram to be used in the fit.
std::vector< Int_t > fExcludedBins
TH1 * GetMCPrediction(Int_t parm) const
Return the adjusted MC template (Aji) for template (parm).
void CheckParNo(Int_t parm) const
Function for internal use, checking parameter validity An invalid parameter results in an error.
virtual void SetTitle(const char *title)
See GetStatOverflows for more information.
virtual Int_t GetNbinsY() const
virtual Int_t GetNbinsZ() const
virtual Int_t GetDimension() const
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
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 Int_t GetNbinsX() const
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...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual const char * GetName() const
Returns name of object.
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Int_t GetEntries() const
Return the number of objects in array (i.e.
virtual void Delete(Option_t *option="")
Remove all objects from the array AND delete all heap based objects.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
TObject * At(Int_t idx) const
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
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.
const char * Data() const
void ToUpper()
Change string to upper case.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
static constexpr double s
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
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...