203 if (
fData->GetDimension() > 1) {
205 fHighLimitY = fData->GetNbinsY();
206 if (fData->GetDimension() > 2) {
208 fHighLimitZ = fData->GetNbinsZ();
211 fNpar = MCs->GetEntries();
213 for (par = 0; par < fNpar; ++par) {
214 fMCs.Add(MCs->At(par));
227 fWeights.Expand(fNpar);
234 if (opt.Contains(
"Q") ) {
235 fFractionFitter->Config().MinimizerOptions().SetPrintLevel(0);
237 else if (opt.Contains(
"V") ) {
238 fFractionFitter->Config().MinimizerOptions().SetPrintLevel(2);
241 fFractionFitter->Config().MinimizerOptions().SetPrintLevel(1);
246 std::vector<ROOT::Fit::ParameterSettings> & parameters = fFractionFitter->Config().ParamsSettings();
247 parameters.reserve(fNpar);
248 for (par = 0; par < fNpar; ++par) {
253 if (fFractionFitter->Config().MinimizerOptions().ErrorDef() == 1.0 )
254 fFractionFitter->Config().MinimizerOptions().SetErrorDef(0.5);
311 Error(
"SetWeight",
"Inconsistent weights histogram for source %d", parm);
332 if (parm < 0 || parm >
fNpar) {
333 Error(
"CheckParNo",
"Invalid parameter number %d",parm);
369 if (
fData->GetDimension() < 2) {
370 Error(
"SetRangeY",
"Y range cannot be set for 1D histogram");
398 if (
fData->GetDimension() < 3) {
399 Error(
"SetRangeZ",
"Z range cannot be set for 1D or 2D histogram");
424 for (
int b = 0;
b < excluded; ++
b) {
426 Error(
"ExcludeBin",
"bin %d already excluded", bin);
440 for (std::vector<Int_t>::iterator it =
fExcludedBins.begin();
449 Error(
"IncludeBin",
"bin %d was not excluded", bin);
469 assert( parm >= 0 && parm < (
int)
fFractionFitter->Config().ParamsSettings().size() );
490 Error(
"CheckConsistency",
"Nonexistent data histogram");
493 Int_t minX, maxX, minY, maxY, minZ, maxZ;
495 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
498 for (z = minZ; z <= maxZ; ++z) {
499 for (
y = minY;
y <= maxY; ++
y) {
500 for (
x = minX;
x <= maxX; ++
x) {
508 Error(
"CheckConsistency",
"Empty data histogram");
516 Error(
"CheckConsistency",
"Need at least two MC histograms");
520 for (par = 0; par <
fNpar; ++par) {
523 Error(
"CheckConsistency",
"Nonexistent MC histogram for source #%d",par);
526 if ((!
h->Class()->InheritsFrom(cl)) ||
h->GetNbinsX() !=
fData->GetNbinsX() ||
527 (
fData->GetDimension() > 1 &&
h->GetNbinsY() !=
fData->GetNbinsY()) ||
528 (
fData->GetDimension() > 2 &&
h->GetNbinsZ() !=
fData->GetNbinsZ())) {
529 Error(
"CheckConsistency",
"Histogram inconsistency for source #%d",par);
533 for (z = minZ; z <= maxZ; ++z) {
534 for (
y = minY;
y <= maxY; ++
y) {
535 for (
x = minX;
x <= maxX; ++
x) {
538 Double_t MCEvents =
h->GetBinContent(bin);
540 Error(
"CheckConsistency",
"Number of MC events (bin = %d, par = %d) cannot be negative: "
541 " their distribution is binomial (see paper)", bin, par);
548 Error(
"CheckConsistency",
"Empty MC histogram #%d",par);
570 if (!status)
Warning(
"Fit",
"Abnormal termination of minimization.");
589 Error(
"ErrorAnalysis",
"Fit not yet performed");
609 Error(
"GetResult",
"Fit not yet performed");
627 Error(
"GetPlot",
"Fit not yet performed");
645 if (
fData->GetDimension() < 2) {
646 minY = maxY = minZ = maxZ = 0;
649 }
else if (
fData->GetDimension() < 3) {
672 Int_t minX, maxX, minY, maxY, minZ, maxZ;
674 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
675 for (mc = 0; mc <
fNpar; ++mc) {
681 for (z = minZ; z <= maxZ; ++z) {
682 for (
y = minY;
y <= maxY; ++
y) {
683 for (
x = minX;
x <= maxX; ++
x) {
687 Error(
"ComputeFCN",
"Invalid weight encountered for MC source %d",mc);
690 tot += weight *
h->GetBinContent(
x,
y, z);
699 TString ts =
"Fraction fit to hist: "; ts +=
fData->GetName();
702 fPlot->SetDirectory(
nullptr);
707 for (z = minZ; z <= maxZ; ++z) {
708 for (
y = minY;
y <= maxY; ++
y) {
709 for (
x = minX;
x <= maxX; ++
x) {
719 for (mc = 0; mc <
fNpar; ++mc) {
723 Double_t binContent =
h->GetBinContent(bin);
728 binPrediction = binContent > 0 ? binContent / (1+weight*
fFractions[mc]*ti) : 0;
731 prediction +=
fFractions[mc]*weight*binPrediction;
732 result -= binPrediction;
733 if (binContent > 0 && binPrediction > 0)
734 result += binContent*
TMath::Log(binPrediction);
737 ((
TH1*)
fAji.At(mc))->SetBinContent(bin, binPrediction);
742 fPlot->SetBinContent(bin, prediction);
745 result -= prediction;
747 if (found > 0 && prediction > 0)
762 std::vector<Double_t> wgtFrac(
fNpar);
763 std::vector<Double_t> a_ji(
fNpar);
769 a_ji[par] = ((
TH1*)
fMCs.At(par))->GetBinContent(bin);
772 if (wgtFrac[par] == 0) {
773 Error(
"FindPrediction",
"Fraction[%d] = 0!", par);
791 if (wgtFrac[par] > maxWgtFrac) {
793 maxWgtFrac = wgtFrac[par];
801 if (par == k_0)
continue;
802 if (wgtFrac[par] == maxWgtFrac) {
804 contentsMax += a_ji[par];
810 if (contentsMax == 0) {
811 A_ki = d_i / (1.0 + maxWgtFrac);
813 if (par == k_0 || wgtFrac[par] == maxWgtFrac)
continue;
814 A_ki -= a_ji[par] * wgtFrac[par] / (maxWgtFrac - wgtFrac[par]);
828 Int_t maxIter = 100000;
829 for(
Int_t i = 0; i < maxIter; ++i) {
830 if (t_i >= 1 || t_i < t_min) {
834 Double_t func = - d_i / (1.0 - t_i);
835 Double_t deriv = func / (1.0 - t_i);
837 Double_t r = 1.0 / (t_i + 1.0 / wgtFrac[par]);
838 func += a_ji[par] *
r;
839 deriv -= a_ji[par] *
r *
r;
844 delta = (delta > 0) ? step : -step;
849 Warning(
"FindPrediction",
"Did not find solution for t_i in %d iterations", maxIter);
862 Error(
"TFractionFitFCN",
"Invalid fit object encountered!");
910 if (ndf <= 0)
return 0;
921 Error(
"ComputeChisquareLambda",
"Fit not yet (successfully) performed");
930 Int_t minX, maxX, minY, maxY, minZ, maxZ;
931 GetRanges(minX, maxX, minY, maxY, minZ, maxZ);
935 for(
Int_t x = minX;
x <= maxX;
x++) {
936 for(
Int_t y = minY;
y <= maxY;
y++) {
937 for(
Int_t z = minZ; z <= maxZ; z++) {
941 if(fi != 0) logLyn += di *
TMath::Log(fi) - fi;
942 if(di != 0) logLmn += di *
TMath::Log(di) - di;
946 if(bji != 0) logLyn += aji *
TMath::Log(bji) - bji;
947 if(aji != 0) logLmn += aji *
TMath::Log(aji) - aji;
969 Error(
"GetMCPrediction",
"Fit not yet performed");
int Int_t
Signed integer 4 bytes (int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void TFractionFitFCN(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t flag)
Fitter class, entry point for performing all type of fits.
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
Documentation for class Functor class.
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/set the title.
virtual Int_t GetNbinsY() const
virtual Int_t GetNbinsZ() const
virtual Int_t GetNbinsX() const
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 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
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
IMultiGenFunctionTempl< double > IMultiGenFunction
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)
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.