165fLowLimitX(0), fHighLimitX(0),
166fLowLimitY(0), fHighLimitY(0),
167fLowLimitZ(0), fHighLimitZ(0),
168fData(0), fIntegralData(0),
194fFitDone(
kFALSE), fChisquare(0), fPlot(0) {
209 for (par = 0; par <
fNpar; ++par) {
212 TString s =
Form(
"Prediction for MC sample %i",par);
243 parameters.reserve(
fNpar);
244 for (par = 0; par <
fNpar; ++par) {
307 Error(
"SetWeight",
"Inconsistent weights histogram for source %d", parm);
328 if (parm < 0 || parm >
fNpar) {
329 Error(
"CheckParNo",
"Invalid parameter number %d",parm);
366 Error(
"SetRangeY",
"Y range cannot be set for 1D histogram");
395 Error(
"SetRangeZ",
"Z range cannot be set for 1D or 2D histogram");
420 for (
int b = 0;
b < excluded; ++
b) {
422 Error(
"ExcludeBin",
"bin %d already excluded", bin);
436 for (std::vector<Int_t>::iterator it =
fExcludedBins.begin();
445 Error(
"IncludeBin",
"bin %d was not excluded", bin);
486 Error(
"CheckConsistency",
"Nonexistent data histogram");
489 Int_t minX, maxX, minY, maxY, minZ, maxZ;
491 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
494 for (z = minZ; z <= maxZ; ++z) {
495 for (
y = minY;
y <= maxY; ++
y) {
496 for (
x = minX;
x <= maxX; ++
x) {
504 Error(
"CheckConsistency",
"Empty data histogram");
512 Error(
"CheckConsistency",
"Need at least two MC histograms");
516 for (par = 0; par <
fNpar; ++par) {
519 Error(
"CheckConsistency",
"Nonexistent MC histogram for source #%d",par);
522 if ((!
h->Class()->InheritsFrom(cl)) ||
h->GetNbinsX() !=
fData->
GetNbinsX() ||
525 Error(
"CheckConsistency",
"Histogram inconsistency for source #%d",par);
529 for (z = minZ; z <= maxZ; ++z) {
530 for (
y = minY;
y <= maxY; ++
y) {
531 for (
x = minX;
x <= maxX; ++
x) {
534 Double_t MCEvents =
h->GetBinContent(bin);
536 Error(
"CheckConsistency",
"Number of MC events (bin = %d, par = %d) cannot be negative: "
537 " their distribution is binomial (see paper)", bin, par);
544 Error(
"CheckConsistency",
"Empty MC histogram #%d",par);
566 if (!status)
Warning(
"Fit",
"Abnormal termination of minimization.");
585 Error(
"ErrorAnalysis",
"Fit not yet performed");
605 Error(
"GetResult",
"Fit not yet performed");
623 Error(
"GetPlot",
"Fit not yet performed");
642 minY = maxY = minZ = maxZ = 0;
668 Int_t minX, maxX, minY, maxY, minZ, maxZ;
670 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
671 for (mc = 0; mc <
fNpar; ++mc) {
677 for (z = minZ; z <= maxZ; ++z) {
678 for (
y = minY;
y <= maxY; ++
y) {
679 for (
x = minX;
x <= maxX; ++
x) {
683 Error(
"ComputeFCN",
"Invalid weight encountered for MC source %d",mc);
686 tot += weight *
h->GetBinContent(
x,
y, z);
703 for (z = minZ; z <= maxZ; ++z) {
704 for (
y = minY;
y <= maxY; ++
y) {
705 for (
x = minX;
x <= maxX; ++
x) {
715 for (mc = 0; mc <
fNpar; ++mc) {
719 Double_t binContent =
h->GetBinContent(bin);
724 binPrediction = binContent > 0 ? binContent / (1+weight*
fFractions[mc]*ti) : 0;
727 prediction +=
fFractions[mc]*weight*binPrediction;
729 if (binContent > 0 && binPrediction > 0)
733 ((
TH1*)
fAji.
At(mc))->SetBinContent(bin, binPrediction);
743 if (found > 0 && prediction > 0)
758 std::vector<Double_t> wgtFrac(
fNpar);
759 std::vector<Double_t> a_ji(
fNpar);
765 a_ji[par] = ((
TH1*)
fMCs.
At(par))->GetBinContent(bin);
768 if (wgtFrac[par] == 0) {
769 Error(
"FindPrediction",
"Fraction[%d] = 0!", par);
787 if (wgtFrac[par] > maxWgtFrac) {
789 maxWgtFrac = wgtFrac[par];
797 if (par == k_0)
continue;
798 if (wgtFrac[par] == maxWgtFrac) {
800 contentsMax += a_ji[par];
806 if (contentsMax == 0) {
807 A_ki = d_i / (1.0 + maxWgtFrac);
809 if (par == k_0 || wgtFrac[par] == maxWgtFrac)
continue;
810 A_ki -= a_ji[par] * wgtFrac[par] / (maxWgtFrac - wgtFrac[par]);
824 Int_t maxIter = 100000;
825 for(
Int_t i = 0; i < maxIter; ++i) {
826 if (t_i >= 1 || t_i < t_min) {
830 Double_t func = - d_i / (1.0 - t_i);
831 Double_t deriv = func / (1.0 - t_i);
833 Double_t r = 1.0 / (t_i + 1.0 / wgtFrac[par]);
834 func += a_ji[par] *
r;
835 deriv -= a_ji[par] *
r *
r;
840 delta = (delta > 0) ? step : -step;
845 Warning(
"FindPrediction",
"Did not find solution for t_i in %d iterations", maxIter);
858 Error(
"TFractionFitFCN",
"Invalid fit object encountered!");
906 if (ndf <= 0)
return 0;
917 Error(
"ComputeChisquareLambda",
"Fit not yet (successfully) performed");
926 Int_t minX, maxX, minY, maxY, minZ, maxZ;
927 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
931 for(
Int_t x = minX;
x <= maxX;
x++) {
932 for(
Int_t y = minY;
y <= maxY;
y++) {
933 for(
Int_t z = minZ; z <= maxZ; z++) {
937 if(fi != 0) logLyn += di *
TMath::Log(fi) - fi;
938 if(di != 0) logLmn += di *
TMath::Log(di) - di;
942 if(bji != 0) logLyn += aji *
TMath::Log(bji) - bji;
943 if(aji != 0) logLmn += aji *
TMath::Log(aji) - aji;
965 Error(
"GetMCPrediction",
"Fit not yet performed");
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void TFractionFitFCN(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t flag)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
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
TClass instances represent classes, structs and namespaces in the ROOT type system.
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...
TH1 * GetPlot()
Return the "template prediction" corresponding to the fit result (this is not the same as the weighte...
Int_t fLowLimitX
First bin in X dimension.
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...
TObjArray fAji
Array of pointers to predictions of real template distributions.
void CheckConsistency()
Function used internally to check the consistency between the various histograms.
Bool_t fFitDone
Flags whether a valid fit has been performed.
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>.
TObjArray fMCs
Array of pointers to template histograms.
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).
~TFractionFitter() override
TFractionFitter default destructor.
void ExcludeBin(Int_t bin)
Exclude the given bin from the fit.
TFractionFitter()
TFractionFitter default constructor.
TObjArray fWeights
Array of pointers to corresponding weight factors (may be null)
void IncludeBin(Int_t bin)
Include the given bin in the fit, if it was excluded before using ExcludeBin().
ROOT::Fit::Fitter * fFractionFitter
Pointer to Fitter class.
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.
TH1 * fPlot
Pointer to histogram containing summed template predictions.
Int_t fHighLimitY
Last bin in Y dimension.
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).
Int_t fNpar
number of fit parameters
Int_t fHighLimitZ
Last bin in Z dimension.
Int_t fNpfits
Number of points used in the fit.
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 fLowLimitY
First bin in Y dimension.
Int_t fHighLimitX
Last bin in X dimension.
Int_t GetNDF() const
return the number of degrees of freedom in the fit the fNDF parameter has been previously computed du...
Double_t * fFractions
Template fractions scaled to the "data" histogram statistics.
Int_t fLowLimitZ
First bin in Z dimension.
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 ...
Double_t fIntegralData
"data" histogram content integral over allowed fit range
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...
Int_t fNDF
Number of degrees of freedom in the fit.
TFitResultPtr Fit()
Perform the fit with the default UP value.
Double_t * fIntegralMCs
Same for template histograms (weights not taken into account)
Double_t fChisquare
Template fit chisquare.
void ReleaseRangeY()
Release restrictions on the Y range of the histogram to be used in the fit.
TH1 * fData
Pointer to the "data" histogram to be fitted to.
std::vector< Int_t > fExcludedBins
Bins excluded from the fit.
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.
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
void SetTitle(const char *title) override
Change (i.e.
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.
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.
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
void AddAt(TObject *obj, Int_t idx) override
Add object at position ids.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
void Delete(Option_t *option="") override
Remove all objects from the array AND delete all heap based objects.
TObject * At(Int_t idx) const override
TObject * RemoveAt(Int_t idx) override
Remove object at index idx.
void Add(TObject *obj) override
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
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...
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.