/* * Class.h * * Created on: 23 mar 2018 * Author: Daniel Wielanek * E-mail: daniel.wielanek@gmail.com * Warsaw University of Technology, Faculty of Physics */ #ifndef NICAROOT_ANALYSIS_FEMTO_CORRFIT_TEMPCLASS_H_ #define NICAROOT_ANALYSIS_FEMTO_CORRFIT_TEMPCLASS_H_ #include "TObject.h" #include "TString.h" #include #include #include #include #include #include #include #include #include #include #include #include "Math/Minimizer.h" #include "Math/Factory.h" #include /** * abstract class for fitting correlation functions */ class TempClass: public TObject { private: /** * line color */ Color_t fLineColor; /** * line style */ Style_t fLineStyle; /** * iine width */ Width_t fLineWidth; Int_t fParametersNo; static TempClass *fgMinimizer; void ResizeStringArray(TString *&array, Int_t old_size, Int_t new_size)const; protected: /** * state of parameters */ enum EParState{ kFixed,//!< kFixed kRange,//!< kRange kFree //!< kFree }; enum EMinFunc{ kChi, kLog }; enum EMinAlgo{ kMinuitMigrad, kMinuitSimplex, kMinuitCombined, kMinuitScan, kMinuitFumili, kGLSMultiMinConjungateFR, kGLSMultiMinConjugatePR, kGLSMultiMinBFGS, kGLSMultiMinBFGS2, kGLSMultiMinSteppestDescent, kGLSMultiFit, kGLSSimAn, kDefaultAlgo }; EMinFunc fMinFunc; EMinAlgo fMinAlgo; void OptionToAlgo(TString option, EMinAlgo &alg)const; void AlgoToOptions(EMinAlgo algo, TString &opt1, TString &opt2)const; /** * called for each calculation of chi2 or loglikehood minimalization - used * for recalculation CF is parameters are changed */ virtual void ParametersChanged(const Double_t *params)const{}; /** * minimal number of entries in numerator and denominator in bin */ Double_t fThreshold; /** * * @return line color */ Color_t GetLineColor()const{return fLineColor;}; /** * * @return line style */ Style_t GetLineStyle()const{return fLineStyle;}; /** * * @return line widht */ Width_t GetLineWidth()const{return fLineWidth;}; /** * number of dimensions */ const Int_t fDim; /** * last calcualte chi square value */ Double_t fChi[2]; /** * number of degrees of freedom */ Int_t fNDF; /** * max numer of iterations */ Int_t fMaxIterations; /** * array if fiSparFixed[i]=true then i-th parameter is fixed */ EParState *fIsParFixed;//[fParametersNo] /** * desired precission */ Double_t fTolerance; /** * lower limits of parameters */ Double_t *fMin;//[fParametersNo]; /** * upper limits of parameters */ Double_t *fMax;//[fParametersNo]; /** * array of fixed parameters */ Double_t *fFixedPars;//[fParametersNo] /** * used only for "STEP" option - number of samples for given parameter in first fit */ Double_t *fFittingSteps1;//[fParametersNo] /** * used only for "STEP" option - number of samples for given parameter in second fit */ Double_t *fFittingSteps2;//[fParametersNo] /** * range of fitted functions */ Double_t *fRange;//! can't stream this /** * array of parameters after fitting */ Double_t *fFittedParams;//[fParametersNo] /** * max step */ Double_t *fMaxStep;//[fParametersNo] /** * array of parameters */ TString *fParameterName;//[fParametersNo] /** * pointer to correlation function */ TObject *fCF; /** * function used for fitting (temporary) */ TF1 *fFittingFunction; /** * fitted function */ TF1 *fFittedFunction; /** * copy of denominator */ TH1 *fDenominatorHistogram; /** * numerator histogram copy */ TH1 *fNumeratorHistogram; /** * copy of correlation function */ TH1 *fCorrelationFunctionHistogram; /** * compute chi square and ndf without empty bins * @param histo histogram to fit * @param func fitting function * @param chi chi square * @param bins number of non-empty bins */ virtual void ComputeChiSquare(TH1 *histo, TF1 *func, Double_t &chi, Double_t &bins)const{}; /** * function used for creating TF1 * @param x - values of function * @param params parameters of function * @return return value of function at given point with given parameters */ virtual Double_t GetFun(Double_t *x, Double_t *params)const{return 0;}; /** * function used for creating TF1, its fitted CF's *denominator * @param x * @param params * @return */ virtual Double_t GetFunD(Double_t *x, Double_t *params)const{return 0;}; /** * set parameters, their names or ranges * @param f function with is set */ void SetupFunction(TF1 *f)const; void NumericalMinimization(); /** * copy setting from fFittingFunction to fFittedFunction */ void CopyFunction(); /** * fit this function to given CF * @param histo - object that will be fittend * @param opt - parameters like A:B where B are TF1 options and A is TempClass option * @see NicaFemto1DCF#Fit or @see NicaFemto3DCF#Fit */ /** * check ranges set by user and other stuff */ virtual void Check(); /** * clear all histograms, and functions */ void Clear(); /** * fit funcion by steps, usefull only for 1D fits * @param step - step of fitting */ void FitStep(Int_t step){}; /** * resize arrays used for storing parameters, it should be called only if number of parameters is not the same as in ctor */ void ChangeParametersNo(); double Derivative(const double *x, int icoord){return 0;}; double operator() (const double * x, int icoord){return 0;}; double operator()(const double *x)const; double Eval(const double *x) const { return 0;}; double FunctorChiTFD(const double *params){std::cout<<"x"<GetChiTFD(params);}; double FunctorLogTFD(const double *params){std::cout<<"x"<GetLogTFD(params);} virtual double GetChiTFD(const double *params){return 0;}; virtual double GetLogTFD(const double *params){return 0;} /** * set name of parameters if they depend on used frame */ virtual void ReadParametersName(){};; /** * return TF1 function used for fitting in options TF and TFD * @param opt if "TF" then function used for direct function is returned, if "TFD" then function used in TFD is used */ virtual TF1* GetFittingFunction(Option_t *opt)const{return NULL;}; /** * "recompute errors in numerator by adding influence of errors in denominator used when fitting with TFD is called * @param num numerator * @param den denominator */ virtual void SetErrors(TH1 *num, const TH1 *den)const{}; /** * compute chi square of function fitted by TFD option, don't take into account of bins where number of entries in denominator * is zero or if entries in numerator are below CORRFIT_THRESHOLD * @param chi computed value of chi square */ virtual void ComputeChiSquareD(Double_t &chi)const{}; /** * calculate error of correlation function * @param Num numerator value * @param NumErr numeratora error * @param Den denominator * @param DenErr denominator error * @param cf calculated correlaction function * @param cfe calculated error of CF */ void CalcError(const Double_t Num, const Double_t NumErr, const Double_t Den, const Double_t DenErr, Double_t &cf, Double_t&cfe)const; public: TempClass(Int_t nparams=1, Int_t dim=1); virtual void Fit(TObject *histo, Option_t *opt ="TF:R"); void SetTolerance(Double_t tol){fTolerance = tol;}; void SetMaxStep(Double_t val, Int_t par){fMaxStep[par]=val;}; void SetMaxIteration(Int_t max){fMaxIterations = max;}; virtual void Draw(Option_t *draw_option="full"){}; void SetParLimits(Int_t par, Double_t min, Double_t max); void FixParameter(Int_t par, Double_t val); void SetParameterName(Int_t par, TString name); void SetRange(Double_t min, Double_t max); void SetLineColor(Color_t color){fLineColor= color;}; void SetLineStyle(Style_t style){fLineStyle = style;}; void SetLineWidth(Width_t width){fLineWidth = width;}; void SetThreshold(Double_t thres){fThreshold = thres;}; Bool_t IsParFixed(Int_t par)const; Double_t GetParMin(Int_t par)const; Double_t GetParMax(Int_t par)const; Double_t GetParError(Int_t par) const; Double_t GetParameter(Int_t par) const; Double_t GetChiSquare(Option_t *opt="fitted") const; Double_t GetNDF() const{ return fNDF;}; Double_t GetChiNDF(Option_t *opt="fitted") const; TH2F *GetChiSquareMap(Int_t par1, Int_t par1_steps, Int_t par2, Int_t par2_steps, Bool_t scale=kTRUE) const; TH2F *GetChiSquareMap(Int_t par1, Int_t par1_steps, Double_t par1_min, Double_t par1_max, Int_t par2, Int_t par2_steps, Double_t par2_min, Double_t par2_max, Bool_t scale=kTRUE) const; TObjArray* DrawChiSquareMap(Int_t par1, Int_t par1_steps, Double_t par1_min, Double_t par1_max, Int_t par2, Int_t par2_steps, Double_t par2_min, Double_t par2_max, Bool_t scale=kTRUE) const; Int_t GetParametersNo() const{return fParametersNo;}; TString GetParameterName(Int_t no)const{ return fParameterName[no];}; TF1* GetFittedFunction()const; virtual ~TempClass(); ClassDef(TempClass,1) }; class TempClass2 : public TempClass{ protected: void ResizeStringArray(TString *&array, Int_t old_size, Int_t new_size)const{}; void FitStep(Int_t step){}; double GetFunc(const double *x); TString GetParam(){return "zzz";}; public: TempClass2(); virtual ~TempClass2(); ClassDef(TempClass2,1) }; #endif /* NICAROOT_ANALYSIS_FEMTO_CORRFIT_TEMPCLASS_H_ */