163 fLowLimitX(0), fHighLimitX(0),
164 fLowLimitY(0), fHighLimitY(0),
165 fLowLimitZ(0), fHighLimitZ(0),
166 fData(0), fIntegralData(0),
192 fFitDone(
kFALSE), fChisquare(0), fPlot(0) {
210 TString s =
Form(
"Prediction for MC sample %i",par);
239 parameters.reserve(fNpar);
303 Error(
"SetWeight",
"Inconsistent weights histogram for source %d", parm);
324 if (parm < 0 || parm >
fNpar) {
325 Error(
"CheckParNo",
"Invalid parameter number %d",parm);
362 Error(
"SetRangeY",
"Y range cannot be set for 1D histogram");
391 Error(
"SetRangeZ",
"Z range cannot be set for 1D or 2D histogram");
416 for (
int b = 0; b < excluded; ++b) {
418 Error(
"ExcludeBin",
"bin %d already excluded", bin);
432 for (std::vector<Int_t>::iterator it =
fExcludedBins.begin();
441 Error(
"IncludeBin",
"bin %d was not excluded", bin);
482 Error(
"CheckConsistency",
"Nonexistent data histogram");
485 Int_t minX, maxX, minY, maxY, minZ, maxZ;
487 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
490 for (z = minZ; z <= maxZ; ++z) {
491 for (y = minY; y <= maxY; ++
y) {
492 for (x = minX; x <= maxX; ++
x) {
500 Error(
"CheckConsistency",
"Empty data histogram");
508 Error(
"CheckConsistency",
"Need at least two MC histograms");
515 Error(
"CheckConsistency",
"Nonexistent MC histogram for source #%d",par);
521 Error(
"CheckConsistency",
"Histogram inconsistency for source #%d",par);
525 for (z = minZ; z <= maxZ; ++z) {
526 for (y = minY; y <= maxY; ++
y) {
527 for (x = minX; x <= maxX; ++
x) {
532 Error(
"CheckConsistency",
"Number of MC events (bin = %d, par = %d) cannot be negative: "
533 " their distribution is binomial (see paper)", bin, par);
540 Error(
"CheckConsistency",
"Empty MC histogram #%d",par);
562 if (!status)
Warning(
"Fit",
"Abnormal termination of minimization.");
581 Error(
"ErrorAnalysis",
"Fit not yet performed");
601 Error(
"GetResult",
"Fit not yet performed");
619 Error(
"GetPlot",
"Fit not yet performed");
638 minY = maxY = minZ = maxZ = 0;
664 Int_t minX, maxX, minY, maxY, minZ, maxZ;
666 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
667 for (mc = 0; mc <
fNpar; ++mc) {
673 for (z = minZ; z <= maxZ; ++z) {
674 for (y = minY; y <= maxY; ++
y) {
675 for (x = minX; x <= maxX; ++
x) {
679 Error(
"ComputeFCN",
"Invalid weight encountered for MC source %d",mc);
697 for (z = minZ; z <= maxZ; ++z) {
698 for (y = minY; y <= maxY; ++
y) {
699 for (x = minX; x <= maxX; ++
x) {
709 for (mc = 0; mc <
fNpar; ++mc) {
718 binPrediction = binContent > 0 ? binContent / (1+weight*
fFractions[mc]*ti) : 0;
721 prediction +=
fFractions[mc]*weight*binPrediction;
722 result -= binPrediction;
723 if (binContent > 0 && binPrediction > 0)
724 result += binContent*
TMath::Log(binPrediction);
727 ((
TH1*)
fAji.
At(mc))->SetBinContent(bin, binPrediction);
735 result -= prediction;
737 if (found > 0 && prediction > 0)
752 std::vector<Double_t> wgtFrac(
fNpar);
753 std::vector<Double_t> a_ji(
fNpar);
762 if (wgtFrac[par] == 0) {
763 Error(
"FindPrediction",
"Fraction[%d] = 0!", par);
781 if (wgtFrac[par] > maxWgtFrac) {
783 maxWgtFrac = wgtFrac[
par];
791 if (par == k_0)
continue;
792 if (wgtFrac[par] == maxWgtFrac) {
794 contentsMax += a_ji[
par];
800 if (contentsMax == 0) {
801 A_ki = d_i / (1.0 + maxWgtFrac);
803 if (par == k_0 || wgtFrac[par] == maxWgtFrac)
continue;
804 A_ki -= a_ji[
par] * wgtFrac[
par] / (maxWgtFrac - wgtFrac[
par]);
818 Int_t maxIter = 100000;
819 for(
Int_t i = 0; i < maxIter; ++i) {
820 if (t_i >= 1 || t_i < t_min) {
825 Double_t deriv = func / (1.0 - t_i);
828 func += a_ji[
par] *
r;
829 deriv -= a_ji[
par] * r *
r;
834 delta = (delta > 0) ? step : -step;
839 Warning(
"FindPrediction",
"Did not find solution for t_i in %d iterations", maxIter);
852 Error(
"TFractionFitFCN",
"Invalid fit object encountered!");
900 if (ndf <= 0)
return 0;
911 Error(
"ComputeChisquareLambda",
"Fit not yet (successfully) performed");
920 Int_t minX, maxX, minY, maxY, minZ, maxZ;
921 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
925 for(
Int_t x = minX;
x <= maxX;
x++) {
926 for(
Int_t y = minY;
y <= maxY;
y++) {
927 for(
Int_t z = minZ; z <= maxZ; z++) {
931 if(fi != 0) logLyn += di *
TMath::Log(fi) - fi;
932 if(di != 0) logLmn += di *
TMath::Log(di) - di;
936 if(bji != 0) logLyn += aji *
TMath::Log(bji) - bji;
937 if(aji != 0) logLmn += aji *
TMath::Log(aji) - aji;
959 Error(
"GetMCPrediction",
"Fit not yet performed");
const FitConfig & Config() const
access to the fit configuration (const method)
Double_t EvaluateFCN(const Double_t *par)
void GetResult(Int_t parm, Double_t &value, Double_t &error) const
Obtain the fit result for parameter
(the parameter numbering follows that of the input templat...
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
(the parameter numbering follows that of the input te...
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 SetPrintLevel(int level)
set print level
void ReleaseRangeX()
Release restrictions on the X range of the histogram to be used in the fit.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
bool CalculateMinosErrors()
perform an error analysis on the result using MINOS To be called only after fitting and when a minimi...
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...
virtual Int_t GetDimension() const
virtual void SetName(const char *name)
Change (i.e.
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.
ClassImp(TFractionFitter) TFractionFitter
TFractionFitter default constructor.
void TFractionFitFCN(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t flag)
double ErrorDef() const
error definition
virtual Int_t GetNbinsX() const
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
void SetErrorDef(double err)
set error def
TH1 * GetMCPrediction(Int_t parm) const
Return the adjusted MC template (Aji) for template (parm).
void ReleaseRangeY()
Release restrictions on the Y range of the histogram to be used in the fit.
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.
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
const char * Data() 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).
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
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...
const FitResult & Result() const
get fit result
void CheckConsistency()
Function used internally to check the consistency between the various histograms. ...
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
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.
ROOT::Fit::Fitter * fFractionFitter
void UnConstrain(Int_t parm)
Remove the constraints on the possible values of parameter
.
void SetData(TH1 *data)
Change the histogram to be fitted to.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void SetMC(Int_t parm, TH1 *MC)
Change the histogram for template number
.
void Error(const char *location, const char *msgfmt,...)
const double * GetParams() const
parameter values (return const pointer)
bool IsExcluded(Int_t bin) const
Function for internal use, checking whether the given bin is excluded from the fit or not...
int Status() const
minimizer status code
virtual TObject * RemoveAt(Int_t idx)
Remove object at index idx.
Fitter class, entry point for performing all type of fits.
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
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...
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
void SetRangeX(Int_t low, Int_t high)
Set the X range of the histogram to be used in the fit.
Double_t GetProb() const
return the fit probability
char * Form(const char *fmt,...)
virtual Int_t GetNbinsZ() const
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Int_t GetNDF() const
return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
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...
Double_t GetChisquare() const
Return the likelihood ratio Chi-squared (chi2) for the fit.
void ComputeChisquareLambda()
Method used internally to compute the likelihood ratio chi2 See the function GetChisquare() for detai...
double Error(unsigned int i) const
parameter error by index
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).
Int_t GetEntries() const
Return the number of objects in array (i.e.
void ErrorAnalysis(Double_t UP)
Set UP to the given value (see class TMinuit), and perform a MINOS minimisation.
void CheckParNo(Int_t parm) const
Function for internal use, checking parameter validity An invalid parameter results in an error...
virtual Int_t GetNbinsY() const
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...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TFitResultPtr Fit()
Perform the fit with the default UP 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 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 ExcludeBin(Int_t bin)
Exclude the given bin from the fit.
virtual void SetTitle(const char *title)
Change (i.e.
ROOT::Fit::Fitter * GetFitter() const
Give direct access to the underlying fitter class.
TObject * At(Int_t idx) const
double Parameter(unsigned int i) const
parameter value by index
virtual void SetTitle(const char *title="")
Change (i.e. 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
(the parameter numbering follows that of the input ...
void ReleaseRangeZ()
Release restrictions on the Z range of the histogram to be used in the fit.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.