CMS 3D CMS Logo

TMultiDimFet.h
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM ofFileline software.
4 *
5 * Based on TMultiDimFet.h (from ROOT) by Christian Holm Christense.
6 *
7 * Authors:
8 * Hubert Niewiadomski
9 * Jan Kašpar (jan.kaspar@gmail.com)
10 *
11 ****************************************************************************/
12 
13 #ifndef SimG4Core_TotemRPProtonTransportParametrization_TMultiDimFet_H
14 #define SimG4Core_TotemRPProtonTransportParametrization_TMultiDimFet_H
15 
16 #ifndef ROOT_TNamed
17 #include "TNamed.h"
18 #endif
19 #ifndef ROOT_TVectorD
20 #include "TVectorD.h"
21 #endif
22 #ifndef ROOT_TMatrixD
23 #include "TMatrixD.h"
24 #endif
25 #ifndef ROOT_TList
26 #include "TList.h"
27 #endif
28 #ifndef ROOT_TVirtualFitter
29 #include "TVirtualFitter.h"
30 #endif
31 
32 #include <vector>
33 
34 //class TBrowser;
35 
36 class TMultiDimFet : public TNamed {
37 public:
39 
40 protected:
41  TVectorD fQuantity;
42  TVectorD fSqError;
43  Double_t fMeanQuantity; // Mean of dependent quantity
44  Double_t fMaxQuantity;
45  Double_t fMinQuantity;
46  Double_t fSumSqQuantity;
47  Double_t fSumSqAvgQuantity;
48 
49  TVectorD fVariables;
50  Int_t fNVariables; // Number of independent variables
51  TVectorD fMeanVariables;
52  TVectorD fMaxVariables; // max value of independent variables
53  TVectorD fMinVariables; // min value of independent variables
54 
55  Int_t fSampleSize;
56 
57  TVectorD fTestQuantity;
58  TVectorD fTestSqError;
59  TVectorD fTestVariables;
60 
62 
63  Double_t fMinAngle;
64  Double_t fMaxAngle;
65  Int_t fMaxTerms; // Max terms expected in final expr.
66  Double_t fMinRelativeError;
67  std::vector<Int_t> fMaxPowers;
68  Double_t fPowerLimit;
69 
70  TMatrixD fFunctions;
71  Int_t fMaxFunctions; // max number of functions
72  std::vector<Int_t> fFunctionCodes;
73  Int_t fMaxStudy;
74 
75  TMatrixD fOrthFunctions;
76  TVectorD fOrthFunctionNorms;
77 
78  std::vector<Int_t> fMaxPowersFinal;
79  Int_t fMaxFunctionsTimesNVariables; // fMaxFunctionsTimesNVariables
80  std::vector<Int_t> fPowers; // ex-array
81  std::vector<Int_t> fPowerIndex; // Index of accepted powers, ex-array
82 
83  TVectorD fResiduals;
84  Double_t fMaxResidual;
85  Double_t fMinResidual;
88  Double_t fSumSqResidual;
89 
90  Int_t fNCoefficients; // Dimension of model coefficients
91  TVectorD fOrthCoefficients;
93  TVectorD fCoefficients; // Vector of the final coefficients
94  TVectorD fCoefficientsRMS;
95  Double_t fRMS;
96  Double_t fChi2;
98 
99  Double_t fError;
100  Double_t fTestError;
101  Double_t fPrecision;
102  Double_t fTestPrecision;
103  Double_t fCorrelationCoeff;
106 
107  TList *fHistograms;
108  Byte_t fHistogramMask;
109 
110  //TVirtualFitter* fFitter; //! Fit object (MINUIT)
111 
112  EMDFPolyType fPolyType; // Type of polynomials to use
113  Bool_t fShowCorrelation; // print correlation matrix
114  Bool_t fIsUserFunction; // Flag for user defined function
115  Bool_t fIsVerbose; //
116 
117  virtual Double_t EvalFactor(Int_t p, Double_t x) const;
118  virtual Double_t EvalControl(const Int_t *powers);
119  virtual void MakeCoefficientErrors();
120  virtual void MakeCorrelation();
121  virtual Double_t MakeGramSchmidt(Int_t function);
122  virtual void MakeCoefficients();
123  virtual void MakeCandidates();
124  virtual void MakeNormalized();
125  virtual void MakeParameterization();
126  virtual void MakeRealCode(const char *filename, const char *classname, Option_t *option = "");
127  virtual Bool_t Select(const Int_t *iv);
128  virtual Bool_t TestFunction(Double_t squareResidual, Double_t dResidur);
129 
130 public:
131  TMultiDimFet();
132  // TMultiDimFet(const TMultiDimFet &in);
133  const TMultiDimFet &operator=(const TMultiDimFet &in);
134 
135  TMultiDimFet(Int_t dimension, EMDFPolyType type = kMonomials, Option_t *option = "");
136  ~TMultiDimFet() override;
137 
138  virtual void AddRow(const Double_t *x, Double_t D, Double_t E = 0);
139  virtual void AddTestRow(const Double_t *x, Double_t D, Double_t E = 0);
140  //void Browse(TBrowser* b) override;
141  void Clear(Option_t *option = "") override; // *MENU*
142  //void Draw(Option_t * ="d") override { }
143  virtual Double_t Eval(const Double_t *x, const Double_t *coeff = nullptr) const;
144  virtual void FindParameterization(double precision); // *MENU*
145  //virtual void Fit(Option_t *option=""); // *MENU*
146 
147  Double_t GetChi2() const { return fChi2; }
148  const TMatrixD *GetCorrelationMatrix() const { return &fCorrelationMatrix; }
149  const TVectorD *GetCoefficients() const { return &fCoefficients; }
150  Double_t GetError() const { return fError; }
151  std::vector<Int_t> GetFunctionCodes() const { return fFunctionCodes; }
152  const TMatrixD *GetFunctions() const { return &fFunctions; }
153  virtual TList *GetHistograms() const { return fHistograms; }
154  Double_t GetMaxAngle() const { return fMaxAngle; }
155  Int_t GetMaxFunctions() const { return fMaxFunctions; }
156  std::vector<Int_t> GetMaxPowers() const { return fMaxPowers; }
157  Double_t GetMaxQuantity() const { return fMaxQuantity; }
158  Int_t GetMaxStudy() const { return fMaxStudy; }
159  Int_t GetMaxTerms() const { return fMaxTerms; }
160  const TVectorD *GetMaxVariables() const { return &fMaxVariables; }
161  Double_t GetMeanQuantity() const { return fMeanQuantity; }
162  const TVectorD *GetMeanVariables() const { return &fMeanVariables; }
163  Double_t GetMinAngle() const { return fMinAngle; }
164  Double_t GetMinQuantity() const { return fMinQuantity; }
165  Double_t GetMinRelativeError() const { return fMinRelativeError; }
166  const TVectorD *GetMinVariables() const { return &fMinVariables; }
167  Int_t GetNVariables() const { return fNVariables; }
168  Int_t GetNCoefficients() const { return fNCoefficients; }
169  Int_t GetPolyType() const { return fPolyType; }
170  std::vector<Int_t> GetPowerIndex() const { return fPowerIndex; }
171  Double_t GetPowerLimit() const { return fPowerLimit; }
172  std::vector<Int_t> GetPowers() const { return fPowers; }
173  Double_t GetPrecision() const { return fPrecision; }
174  const TVectorD *GetQuantity() const { return &fQuantity; }
175  Double_t GetResidualMax() const { return fMaxResidual; }
176  Double_t GetResidualMin() const { return fMinResidual; }
177  Int_t GetResidualMaxRow() const { return fMaxResidualRow; }
178  Int_t GetResidualMinRow() const { return fMinResidualRow; }
179  Double_t GetResidualSumSq() const { return fSumSqResidual; }
180  Double_t GetRMS() const { return fRMS; }
181  Int_t GetSampleSize() const { return fSampleSize; }
182  const TVectorD *GetSqError() const { return &fSqError; }
183  Double_t GetSumSqAvgQuantity() const { return fSumSqAvgQuantity; }
184  Double_t GetSumSqQuantity() const { return fSumSqQuantity; }
185  Double_t GetTestError() const { return fTestError; }
186  Double_t GetTestPrecision() const { return fTestPrecision; }
187  const TVectorD *GetTestQuantity() const { return &fTestQuantity; }
188  Int_t GetTestSampleSize() const { return fTestSampleSize; }
189  const TVectorD *GetTestSqError() const { return &fTestSqError; }
190  const TVectorD *GetTestVariables() const { return &fTestVariables; }
191  const TVectorD *GetVariables() const { return &fVariables; }
192 
193  //static TMultiDimFet* Instance() { return fgInstance; }
194  Bool_t IsFolder() const override { return kTRUE; }
195  virtual Double_t MakeChi2(const Double_t *coeff = nullptr);
196  virtual void MakeCode(const char *functionName = "MDF", Option_t *option = ""); // *MENU*
197  virtual void MakeHistograms(Option_t *option = "A"); // *MENU*
198  virtual void MakeMethod(const Char_t *className = "MDF", Option_t *option = ""); // *MENU*
199  void Print(Option_t *option = "ps") const override; // *MENU*
200  virtual void PrintPolynomialsSpecial(Option_t *option = "m") const; // *MENU*
201 
202  void SetMaxAngle(Double_t angle = 0);
203  void SetMaxFunctions(Int_t n) { fMaxFunctions = n; }
204  void SetMaxPowers(const Int_t *powers);
205  void SetMaxStudy(Int_t n) { fMaxStudy = n; }
206  void SetMaxTerms(Int_t terms) { fMaxTerms = terms; }
207  void SetMinRelativeError(Double_t error);
208  void SetMinAngle(Double_t angle = 1);
209  void SetPowerLimit(Double_t limit = 1e-3);
210  virtual void SetPowers(const Int_t *powers, Int_t terms);
211 
212  void ReducePolynomial(double error);
213  void ZeroDoubiousCoefficients(double error);
214 
215  ClassDefOverride(TMultiDimFet, 1) // Multi dimensional fit class
216 };
217 #endif //SimG4Core_TotemRPProtonTransportParametrization_TMultiDimFet_H
const TVectorD * GetTestSqError() const
Definition: TMultiDimFet.h:189
Int_t GetNVariables() const
Definition: TMultiDimFet.h:167
Double_t fMaxQuantity
Definition: TMultiDimFet.h:44
TMatrixD fCorrelationMatrix
Multi Correlation coefficient.
Definition: TMultiDimFet.h:104
std::vector< Int_t > GetFunctionCodes() const
Definition: TMultiDimFet.h:151
Double_t fSumSqQuantity
Min value of dependent quantity.
Definition: TMultiDimFet.h:46
Double_t fMinAngle
Size of test sample.
Definition: TMultiDimFet.h:63
TVectorD fTestVariables
Test sample, Error in quantity.
Definition: TMultiDimFet.h:59
const TMultiDimFet & operator=(const TMultiDimFet &in)
Definition: TMultiDimFet.cc:83
TVectorD fMinVariables
Definition: TMultiDimFet.h:53
Int_t fTestSampleSize
Test sample, independent variables.
Definition: TMultiDimFet.h:61
Double_t GetMaxQuantity() const
Definition: TMultiDimFet.h:157
Double_t fSumSqAvgQuantity
SumSquare of dependent quantity.
Definition: TMultiDimFet.h:47
Double_t fMinQuantity
Max value of dependent quantity.
Definition: TMultiDimFet.h:45
virtual void MakeCoefficientErrors()
void ZeroDoubiousCoefficients(double error)
void SetPowerLimit(Double_t limit=1e-3)
int32_t *__restrict__ iv
Int_t fParameterisationCode
Chi square of fit.
Definition: TMultiDimFet.h:97
Double_t fMinResidual
Max redsidual value.
Definition: TMultiDimFet.h:85
EMDFPolyType fPolyType
Bit pattern of hisograms used.
Definition: TMultiDimFet.h:112
Double_t GetMeanQuantity() const
Definition: TMultiDimFet.h:161
TMatrixD fFunctions
Control parameter.
Definition: TMultiDimFet.h:70
Int_t GetMaxTerms() const
Definition: TMultiDimFet.h:159
Double_t GetSumSqQuantity() const
Definition: TMultiDimFet.h:184
Int_t GetResidualMinRow() const
Definition: TMultiDimFet.h:178
Double_t fTestCorrelationCoeff
Correlation matrix.
Definition: TMultiDimFet.h:105
Double_t GetPrecision() const
Definition: TMultiDimFet.h:173
void SetMaxPowers(const Int_t *powers)
virtual Double_t EvalControl(const Int_t *powers)
void SetMaxTerms(Int_t terms)
Definition: TMultiDimFet.h:206
TMatrixD fOrthFunctions
max functions to study
Definition: TMultiDimFet.h:75
const TVectorD * GetVariables() const
Definition: TMultiDimFet.h:191
Byte_t fHistogramMask
List of histograms.
Definition: TMultiDimFet.h:108
~TMultiDimFet() override
Double_t fMaxAngle
Min angle for acepting new function.
Definition: TMultiDimFet.h:64
Int_t GetNCoefficients() const
Definition: TMultiDimFet.h:168
Double_t GetPowerLimit() const
Definition: TMultiDimFet.h:171
std::vector< Int_t > fPowers
Definition: TMultiDimFet.h:80
Double_t fPowerLimit
maximum powers, ex-array
Definition: TMultiDimFet.h:68
Double_t fPrecision
Error from test.
Definition: TMultiDimFet.h:101
virtual void MakeHistograms(Option_t *option="A")
TVectorD fCoefficientsRMS
Definition: TMultiDimFet.h:94
virtual void MakeParameterization()
std::vector< Int_t > GetMaxPowers() const
Definition: TMultiDimFet.h:156
virtual Double_t MakeGramSchmidt(Int_t function)
std::vector< Int_t > GetPowers() const
Definition: TMultiDimFet.h:172
Int_t fMaxResidualRow
Min redsidual value.
Definition: TMultiDimFet.h:86
void Print(Option_t *option="ps") const override
Double_t fTestError
Error from parameterization.
Definition: TMultiDimFet.h:100
virtual void AddTestRow(const Double_t *x, Double_t D, Double_t E=0)
void SetMinRelativeError(Double_t error)
virtual void MakeNormalized()
virtual Double_t Eval(const Double_t *x, const Double_t *coeff=nullptr) const
virtual Bool_t TestFunction(Double_t squareResidual, Double_t dResidur)
Double_t GetRMS() const
Definition: TMultiDimFet.h:180
virtual void SetPowers(const Int_t *powers, Int_t terms)
Int_t fNVariables
Training sample, independent variables.
Definition: TMultiDimFet.h:50
void SetMaxStudy(Int_t n)
Definition: TMultiDimFet.h:205
const TVectorD * GetTestQuantity() const
Definition: TMultiDimFet.h:187
Double_t GetTestError() const
Definition: TMultiDimFet.h:185
virtual void MakeCandidates()
Double_t fChi2
Root mean square of fit.
Definition: TMultiDimFet.h:96
Double_t GetResidualSumSq() const
Definition: TMultiDimFet.h:179
Bool_t fIsVerbose
Definition: TMultiDimFet.h:115
Int_t GetMaxStudy() const
Definition: TMultiDimFet.h:158
Bool_t fShowCorrelation
Definition: TMultiDimFet.h:113
Int_t fMinResidualRow
Row giving max residual.
Definition: TMultiDimFet.h:87
virtual void PrintPolynomialsSpecial(Option_t *option="m") const
TVectorD fTestSqError
Test sample, dependent quantity.
Definition: TMultiDimFet.h:58
TVectorD fQuantity
Definition: TMultiDimFet.h:41
Double_t fMinRelativeError
Definition: TMultiDimFet.h:66
Double_t GetResidualMax() const
Definition: TMultiDimFet.h:175
const TVectorD * GetQuantity() const
Definition: TMultiDimFet.h:174
virtual void MakeCorrelation()
TVectorD fOrthCoefficients
Definition: TMultiDimFet.h:91
Double_t fRMS
Vector of RMS of coefficients.
Definition: TMultiDimFet.h:95
std::vector< Int_t > fPowerIndex
Definition: TMultiDimFet.h:81
std::vector< Int_t > GetPowerIndex() const
Definition: TMultiDimFet.h:170
Double_t fMeanQuantity
Training sample, error in quantity.
Definition: TMultiDimFet.h:43
TVectorD fOrthFunctionNorms
As above, but orthogonalised.
Definition: TMultiDimFet.h:76
virtual void MakeCode(const char *functionName="MDF", Option_t *option="")
Int_t GetSampleSize() const
Definition: TMultiDimFet.h:181
virtual TList * GetHistograms() const
Definition: TMultiDimFet.h:153
Double_t fSumSqResidual
Row giving min residual.
Definition: TMultiDimFet.h:88
virtual void AddRow(const Double_t *x, Double_t D, Double_t E=0)
virtual Double_t MakeChi2(const Double_t *coeff=nullptr)
Double_t fMaxResidual
Vector of the final residuals.
Definition: TMultiDimFet.h:84
virtual void MakeRealCode(const char *filename, const char *classname, Option_t *option="")
virtual Bool_t Select(const Int_t *iv)
TVectorD fMaxVariables
mean value of independent variables
Definition: TMultiDimFet.h:52
const TVectorD * GetMeanVariables() const
Definition: TMultiDimFet.h:162
virtual void FindParameterization(double precision)
Double_t GetSumSqAvgQuantity() const
Definition: TMultiDimFet.h:183
Int_t GetResidualMaxRow() const
Definition: TMultiDimFet.h:177
Double_t fTestPrecision
Relative precision of param.
Definition: TMultiDimFet.h:102
const TVectorD * GetTestVariables() const
Definition: TMultiDimFet.h:190
const TVectorD * GetCoefficients() const
Definition: TMultiDimFet.h:149
Double_t GetMinRelativeError() const
Definition: TMultiDimFet.h:165
TList * fHistograms
Multi Correlation coefficient.
Definition: TMultiDimFet.h:107
Int_t fMaxTerms
Max angle for acepting new function.
Definition: TMultiDimFet.h:65
void SetMaxFunctions(Int_t n)
Definition: TMultiDimFet.h:203
const TVectorD * GetMinVariables() const
Definition: TMultiDimFet.h:166
Double_t GetMaxAngle() const
Definition: TMultiDimFet.h:154
TVectorD fTestQuantity
Size of training sample.
Definition: TMultiDimFet.h:57
Double_t GetResidualMin() const
Definition: TMultiDimFet.h:176
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
TVectorD fVariables
Sum of squares away from mean.
Definition: TMultiDimFet.h:49
Int_t GetTestSampleSize() const
Definition: TMultiDimFet.h:188
Int_t fMaxFunctions
Functions evaluated over sample.
Definition: TMultiDimFet.h:71
Double_t GetTestPrecision() const
Definition: TMultiDimFet.h:186
Double_t GetChi2() const
Definition: TMultiDimFet.h:147
Int_t fSampleSize
Definition: TMultiDimFet.h:55
Bool_t fIsUserFunction
Definition: TMultiDimFet.h:114
Double_t fError
Exit code of parameterisation.
Definition: TMultiDimFet.h:99
Bool_t IsFolder() const override
Definition: TMultiDimFet.h:194
Int_t fNCoefficients
Sum of Square residuals.
Definition: TMultiDimFet.h:90
const TVectorD * GetMaxVariables() const
Definition: TMultiDimFet.h:160
Double_t GetMinQuantity() const
Definition: TMultiDimFet.h:164
Int_t fMaxFunctionsTimesNVariables
maximum powers from fit, ex-array
Definition: TMultiDimFet.h:79
std::vector< Int_t > fFunctionCodes
Definition: TMultiDimFet.h:72
Double_t GetMinAngle() const
Definition: TMultiDimFet.h:163
TVectorD fSqError
Training sample, dependent quantity.
Definition: TMultiDimFet.h:42
Int_t GetPolyType() const
Definition: TMultiDimFet.h:169
void SetMinAngle(Double_t angle=1)
Double_t fCorrelationCoeff
Relative precision of test.
Definition: TMultiDimFet.h:103
TMatrixD fOrthCurvatureMatrix
The model coefficients.
Definition: TMultiDimFet.h:92
virtual void MakeCoefficients()
TVectorD fResiduals
Definition: TMultiDimFet.h:83
std::vector< Int_t > fMaxPowers
Min relative error accepted.
Definition: TMultiDimFet.h:67
TVectorD fMeanVariables
Definition: TMultiDimFet.h:51
void Clear(Option_t *option="") override
virtual void MakeMethod(const Char_t *className="MDF", Option_t *option="")
void ReducePolynomial(double error)
Double_t GetError() const
Definition: TMultiDimFet.h:150
Int_t GetMaxFunctions() const
Definition: TMultiDimFet.h:155
std::vector< Int_t > fMaxPowersFinal
Norm of the evaluated functions.
Definition: TMultiDimFet.h:78
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
void SetMaxAngle(Double_t angle=0)
const TVectorD * GetSqError() const
Definition: TMultiDimFet.h:182
const TMatrixD * GetCorrelationMatrix() const
Definition: TMultiDimFet.h:148
const TMatrixD * GetFunctions() const
Definition: TMultiDimFet.h:152
std::string className(const T &t)
Definition: ClassName.h:31
TVectorD fCoefficients
Model matrix.
Definition: TMultiDimFet.h:93
Int_t fMaxStudy
acceptance code, ex-array
Definition: TMultiDimFet.h:73
virtual Double_t EvalFactor(Int_t p, Double_t x) const
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11