Line data Source code
1 : #ifndef ALINDLOCALREGRESSION_H
2 : #define ALINDLOCALREGRESSION_H
3 : /* Copyright(c) 2006-07, ALICE Experiment at CERN, All rights reserved. *
4 : * See cxx source for full Copyright notice */
5 :
6 : #include "TGraph.h"
7 : #include "TGraphSmooth.h"
8 : #include "TRandom.h"
9 : #include "TSpline.h"
10 : #include "TLinearFitter.h"
11 : #include "TDecompSVD.h"
12 : #include "TDecompSparse.h"
13 : #include "TMatrixDSparse.h"
14 : #include "TF1.h"
15 : #include "TH1F.h"
16 : #include "TNamed.h"
17 : #include "TClonesArray.h"
18 : #include "TMath.h"
19 :
20 :
21 : #include "TTreeStream.h"
22 : class TTreeSRedirector;
23 : class THn;
24 : class TObjString;
25 :
26 : class AliNDLocalRegression : public TNamed {
27 : public:
28 : AliNDLocalRegression();
29 : AliNDLocalRegression(const char* name, const char* title);
30 : ~AliNDLocalRegression();
31 :
32 : Bool_t MakeFit(TTree * tree , const char *formulaVal, const char * formulaVar, const char*selection, const char * formulaKernel, const char * dimensionFormula, Double_t weightCut=0.00001, Int_t entries=1000000000, Bool_t useBinNorm=kTRUE);
33 : Bool_t CleanCovariance();
34 : Double_t Eval(Double_t *point);
35 : Double_t EvalError(Double_t *point);
36 : Bool_t Derivative(Double_t *point, Double_t *d);
37 : Bool_t EvalAndDerivative(Double_t *point, Double_t &val, Double_t *d);
38 0 : const THn *GetHistogram() {return fHistPoints;}
39 0 : const TObjArray * GetFitParam(){ return fLocalFitParam;}
40 : void SetCuts(Double_t nSigma=6, Double_t robustFraction=0.95, Int_t estimator=1);
41 : void SetHistogram(THn* histo );
42 0 : void SetTree(TTree * tree) {fInputTree = tree;}
43 0 : TTreeSRedirector *GetStreamer(){return fStreamer;}
44 0 : void SetStreamer( TTreeSRedirector *streamer){ fStreamer=streamer;}
45 : Bool_t AddWeekConstrainsAtBoundaries(Int_t nDims, Int_t *indexes, Double_t *relWeight, TTreeSRedirector* pcstream, Bool_t useCommon=kFALSE);
46 : void DumpToTree(Int_t div, TTreeStream & stream);
47 : //
48 0 : const TObjArray *GetLocalFitParam() const { return fLocalFitParam; }
49 0 : const TObjArray *GetLocalFitQuality() const { return fLocalFitQuality; }
50 0 : const TObjArray *GetLocalFitCovar() const { return fLocalFitCovar; }
51 : //
52 0 : const TMatrixD *GetLocalRobustStat() const { return fLocalRobustStat; }
53 : //
54 : // function to access the Local Regression from the TFormula
55 : static void AddVisualCorrection(AliNDLocalRegression* corr, Int_t position=0);
56 : static AliNDLocalRegression* GetVisualCorrection(Int_t position);
57 0 : static AliNDLocalRegression* GetVisualCorrection(const char *corName){return (fgVisualCorrection==NULL) ? 0: ( AliNDLocalRegression*) fgVisualCorrection->FindObject(corName);}
58 : static Int_t GetVisualCorrectionIndex(const char *corName);
59 0 : Int_t GetVisualCorrectionIndex(){return GetVisualCorrectionIndex(GetName());}
60 0 : static TObjArray* GetVisualCorrections() { return fgVisualCorrection;}
61 : //
62 : static Double_t GetCorrND(Double_t index, Double_t par0);
63 : static Double_t GetCorrNDError(Double_t index, Double_t par0);
64 : static Double_t GetCorrND(Double_t index, Double_t par0,Double_t par1);
65 : static Double_t GetCorrNDError(Double_t index, Double_t par0,Double_t par1);
66 : static Double_t GetCorrND(Double_t index, Double_t par0,Double_t par1, Double_t par2);
67 : static Double_t GetCorrNDError(Double_t index, Double_t par0,Double_t par1, Double_t par2);
68 : static Double_t GetCorrND(Double_t index, Double_t par0,Double_t par1, Double_t par2, Double_t par3);
69 : static Double_t GetCorrNDError(Double_t index, Double_t par0,Double_t par1, Double_t par2, Double_t par3);
70 0 : static void SetVerboseLevel(Int_t verbose){ fgVerboseLevel=TMath::Max(verbose,1);}
71 : //
72 : static Double_t EvalGraphKernel(TGraph * gr, Double_t evalTime, Double_t kernelWidth, Int_t sigmaCut=3, Bool_t evalLog=kFALSE, Int_t pol=1, TVectorD *param=0, TMatrixD *covar=0);
73 : public:
74 : Bool_t MakeRobustStatistic(TVectorD &values,TVectorD &errors, TObjArray &pointArray, TObjArray &kernelArrayI2, Double_t weightCut, Double_t robustFraction);
75 :
76 : protected:
77 : THn *fHistPoints; // histogram local point distoribution
78 : Double_t fRobustFractionLTS; // fraction of data used for the robust mean and robust rms estimator (LTS https://en.wikipedia.org/wiki/Least_trimmed_squares)
79 : Double_t fRobustRMSLTSCut; // cut on the robust RMS |value-localmean|<fRobustRMSLTSCut*localRMS
80 : Int_t fCutType; // type of the cut 0- no cut 1-cut localmean=median, 2-cut localmen=rosbut mean
81 : TTree * fInputTree; // ! input tree - object not owner
82 : TTreeSRedirector * fStreamer; // ! streamer to keep - test intermediate data
83 : //
84 : TObjString *fFormulaVal; // value:error definition formula
85 : TObjString *fSelection; // point selector formula
86 : //
87 : TObjString *fFormulaVar; // :separated variable definition formula
88 : TObjString *fKernelWidthFormula; //: separated - kernel width for the regression
89 : TObjString *fPolDimensionFormula; //: separated - polynom for the regression
90 : //
91 : Int_t fNVar; // number of variables
92 : Int_t fNParameters; // number of local parameters to fit
93 : //
94 : TObjArray *fLocalFitParam; // local fit parameters + RMS + chi2
95 : TObjArray *fLocalFitQuality; // local fit npoints chi2
96 : TObjArray *fLocalFitCovar; // local fit covariance matrix
97 : //
98 : TMatrixD *fLocalRobustStat; // local robust statistic
99 : protected:
100 : static TObjArray *fgVisualCorrection; ///< array of orrection for visualization
101 : static Int_t fgVerboseLevel; ///< verbose level
102 : Int_t *fBinIndex; //[fNParameters] working arrays current bin index
103 : Double_t *fBinCenter; //[fNParameters] working current local variables - bin center
104 : Double_t *fBinDelta; //[fNParameters] working current local variables - bin delta
105 : Double_t *fBinWidth; //[fNParameters] working current local variables - bin delta
106 : Bool_t fUseBinNorm; // switch make polynom in units of bins (kTRUE) or in natural units (kFALSE)
107 : private:
108 : AliNDLocalRegression& operator=(const AliNDLocalRegression&);
109 : AliNDLocalRegression(const AliNDLocalRegression&);
110 128 : ClassDef(AliNDLocalRegression, 2);
111 : };
112 : #endif
|