Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 09:25:00

0001 // @(#)root/hist:$Id$
0002 // Author: L. Moneta Thu Aug 31 10:40:20 2006
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for class HFitInterface
0012 // set of free functions used to couple the ROOT data object with the fitting classes
0013 
0014 #ifndef ROOT_HFitInterface
0015 #define ROOT_HFitInterface
0016 
0017 
0018 class TH1;
0019 class THnBase;
0020 class TF1;
0021 class TF2;
0022 class TGraph;
0023 class TGraphErrors;
0024 class TGraph2D;
0025 class TMultiGraph;
0026 struct Foption_t;
0027 
0028 #include "TFitResultPtr.h"
0029 
0030 namespace ROOT {
0031 
0032    namespace Math {
0033       class MinimizerOptions;
0034    }
0035 
0036    namespace Fit {
0037 
0038       //class BinData;
0039 
0040       class FitResult;
0041       class DataRange;
0042       class BinData;
0043       class UnBinData;
0044       class SparseData;
0045 
0046       enum class EFitObjectType {
0047          kHistogram,
0048          kGraph
0049       };
0050 
0051       enum class EChisquareType {
0052          kNeyman = 0,
0053          kPLikeRatio,
0054          kPearson
0055       };
0056 
0057 
0058 
0059       /**
0060          Decode list of options into fitOption
0061        */
0062       void FitOptionsMake(EFitObjectType type, const char *option, Foption_t &fitOption);
0063 
0064       /**
0065          fitting function for a TH1 (called from TH1::Fit)
0066        */
0067       TFitResultPtr FitObject(TH1 * h1, TF1 *f1, Foption_t & option, const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
0068 
0069       /**
0070          fitting function for a TGraph (called from TGraph::Fit)
0071        */
0072       TFitResultPtr FitObject(TGraph * gr, TF1 *f1 , Foption_t & option , const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
0073 
0074       /**
0075          fitting function for a MultiGraph (called from TMultiGraph::Fit)
0076        */
0077       TFitResultPtr FitObject(TMultiGraph * mg, TF1 *f1 , Foption_t & option , const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
0078 
0079       /**
0080          fitting function for a TGraph2D (called from TGraph2D::Fit)
0081        */
0082       TFitResultPtr FitObject(TGraph2D * gr, TF1 *f1 , Foption_t & option , const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
0083 
0084       /**
0085          fitting function for a THn / THnSparse (called from THnBase::Fit)
0086        */
0087       TFitResultPtr FitObject(THnBase * s1, TF1 *f1, Foption_t & option, const ROOT::Math::MinimizerOptions & moption, const char *goption, ROOT::Fit::DataRange & range);
0088 
0089 
0090       /**
0091           fit an unbin data set (from tree or from histogram buffer)
0092           using a TF1 pointer and fit options.
0093           N.B. ownership of fit data is passed to the UnBinFit function which will be responsible of
0094           deleting the data after the fit. User calling this function MUST NOT delete UnBinData after
0095           calling it.
0096       */
0097       TFitResultPtr UnBinFit(ROOT::Fit::UnBinData * data, TF1 * f1 , Foption_t & option , const ROOT::Math::MinimizerOptions & moption);
0098 
0099       /**
0100           fill the data vector from a TH1. Pass also the TF1 function which is
0101           needed in case of integral option and to reject points rejected by the function
0102       */
0103       void FillData ( BinData  & dv, const TH1 * hist, TF1 * func = nullptr);
0104 
0105       /**
0106           fill the data vector from a TH1 with sparse data. Pass also the TF1 function which is
0107           needed in case of integral option and to reject points rejected by the function
0108       */
0109       void FillData ( SparseData  & dv, const TH1 * hist, TF1 * func = nullptr);
0110 
0111       /**
0112           fill the data vector from a THnBase. Pass also the TF1 function which is
0113           needed in case of integral option and to reject points rejected by the function
0114       */
0115       void FillData ( SparseData  & dv, const THnBase * hist, TF1 * func = nullptr);
0116 
0117       /**
0118           fill the data vector from a THnBase. Pass also the TF1 function which is
0119           needed in case of integral option and to reject points rejected by the function
0120       */
0121       void FillData ( BinData  & dv, const THnBase * hist, TF1 * func = nullptr);
0122 
0123       /**
0124           fill the data vector from a TGraph2D. Pass also the TF1 function which is
0125           needed in case of integral option and to reject points rejected by the function
0126       */
0127       void FillData ( BinData  & dv, const TGraph2D * gr, TF1 * func = nullptr);
0128 
0129 
0130       /**
0131           fill the data vector from a TGraph. Pass also the TF1 function which is
0132           needed in case to exclude points rejected by the function
0133       */
0134       void FillData ( BinData  & dv, const TGraph * gr, TF1 * func = nullptr);
0135       /**
0136           fill the data vector from a TMultiGraph. Pass also the TF1 function which is
0137           needed in case to exclude points rejected by the function
0138       */
0139       void FillData ( BinData  & dv, const TMultiGraph * gr,  TF1 * func = nullptr);
0140 
0141 
0142       /**
0143           compute initial parameter for an exponential function given the fit data
0144           Set the constant and slope assuming a simple exponential going through xmin and xmax
0145           of the data set
0146        */
0147       void InitExpo(const ROOT::Fit::BinData & data, TF1 * f1);
0148 
0149 
0150       /**
0151           compute initial parameter for gaussian function given the fit data
0152           Set the sigma limits for zero top 10* initial rms values
0153           Set the initial parameter values in the TF1
0154        */
0155       void InitGaus(const ROOT::Fit::BinData & data, TF1 * f1);
0156 
0157       /**
0158           compute initial parameter for 2D gaussian function given the fit data
0159           Set the sigma limits for zero top 10* initial rms values
0160           Set the initial parameter values in the TF1
0161        */
0162       void Init2DGaus(const ROOT::Fit::BinData & data, TF1 * f1);
0163 
0164       /**
0165          compute confidence intervals at level cl for a fitted histogram h1 in a TGraphErrors gr
0166       */
0167       bool GetConfidenceIntervals(const TH1 * h1, const ROOT::Fit::FitResult & r, TGraphErrors * gr, double cl = 0.95);
0168 
0169       /**
0170          compute the chi2 value for an histogram given a function  (see TH1::Chisquare for the documentation)
0171       */
0172       double Chisquare(const TH1 & h1, TF1 & f1, bool useRange, EChisquareType type, bool useIntegral = false);
0173 
0174       /**
0175          compute the chi2 value for a graph given a function (see TGraph::Chisquare)
0176       */
0177       double Chisquare(const TGraph & h1, TF1 & f1, bool useRange);
0178 
0179 
0180    } // end namespace Fit
0181 
0182 } // end namespace ROOT
0183 
0184 
0185 #endif /* ROOT_Fit_TH1Interface */