Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:09

0001 /****************************************************************************
0002 *
0003 * This is a part of TOTEM ofFileline software.
0004 *
0005 * Based on TMultiDimFet.h (from ROOT) by Christian Holm Christense.
0006 *
0007 * Authors:
0008 *   Hubert Niewiadomski
0009 *   Jan Kašpar (jan.kaspar@gmail.com)
0010 *
0011 ****************************************************************************/
0012 
0013 #ifndef SimG4Core_TotemRPProtonTransportParametrization_TMultiDimFet_H
0014 #define SimG4Core_TotemRPProtonTransportParametrization_TMultiDimFet_H
0015 
0016 #ifndef ROOT_TNamed
0017 #include "TNamed.h"
0018 #endif
0019 #ifndef ROOT_TVectorD
0020 #include "TVectorD.h"
0021 #endif
0022 #ifndef ROOT_TMatrixD
0023 #include "TMatrixD.h"
0024 #endif
0025 #ifndef ROOT_TList
0026 #include "TList.h"
0027 #endif
0028 #ifndef ROOT_TVirtualFitter
0029 #include "TVirtualFitter.h"
0030 #endif
0031 
0032 #include <vector>
0033 
0034 //class TBrowser;
0035 
0036 class TMultiDimFet : public TNamed {
0037 public:
0038   enum EMDFPolyType { kMonomials, kChebyshev, kLegendre };
0039 
0040 protected:
0041   TVectorD fQuantity;          //! Training sample, dependent quantity
0042   TVectorD fSqError;           //! Training sample, error in quantity
0043   Double_t fMeanQuantity;      // Mean of dependent quantity
0044   Double_t fMaxQuantity;       //! Max value of dependent quantity
0045   Double_t fMinQuantity;       //! Min value of dependent quantity
0046   Double_t fSumSqQuantity;     //! SumSquare of dependent quantity
0047   Double_t fSumSqAvgQuantity;  //! Sum of squares away from mean
0048 
0049   TVectorD fVariables;      //! Training sample, independent variables
0050   Int_t fNVariables;        // Number of independent variables
0051   TVectorD fMeanVariables;  //! mean value of independent variables
0052   TVectorD fMaxVariables;   // max value of independent variables
0053   TVectorD fMinVariables;   // min value of independent variables
0054 
0055   Int_t fSampleSize;  //! Size of training sample
0056 
0057   TVectorD fTestQuantity;   //! Test sample, dependent quantity
0058   TVectorD fTestSqError;    //! Test sample, Error in quantity
0059   TVectorD fTestVariables;  //! Test sample, independent variables
0060 
0061   Int_t fTestSampleSize;  //! Size of test sample
0062 
0063   Double_t fMinAngle;             //! Min angle for acepting new function
0064   Double_t fMaxAngle;             //! Max angle for acepting new function
0065   Int_t fMaxTerms;                // Max terms expected in final expr.
0066   Double_t fMinRelativeError;     //! Min relative error accepted
0067   std::vector<Int_t> fMaxPowers;  //! maximum powers, ex-array
0068   Double_t fPowerLimit;           //! Control parameter
0069 
0070   TMatrixD fFunctions;                //! Functions evaluated over sample
0071   Int_t fMaxFunctions;                // max number of functions
0072   std::vector<Int_t> fFunctionCodes;  //! acceptance code, ex-array
0073   Int_t fMaxStudy;                    //! max functions to study
0074 
0075   TMatrixD fOrthFunctions;      //! As above, but orthogonalised
0076   TVectorD fOrthFunctionNorms;  //! Norm of the evaluated functions
0077 
0078   std::vector<Int_t> fMaxPowersFinal;  //! maximum powers from fit, ex-array
0079   Int_t fMaxFunctionsTimesNVariables;  // fMaxFunctionsTimesNVariables
0080   std::vector<Int_t> fPowers;          // ex-array
0081   std::vector<Int_t> fPowerIndex;      // Index of accepted powers, ex-array
0082 
0083   TVectorD fResiduals;      //! Vector of the final residuals
0084   Double_t fMaxResidual;    //! Max redsidual value
0085   Double_t fMinResidual;    //! Min redsidual value
0086   Int_t fMaxResidualRow;    //! Row giving max residual
0087   Int_t fMinResidualRow;    //! Row giving min residual
0088   Double_t fSumSqResidual;  //! Sum of Square residuals
0089 
0090   Int_t fNCoefficients;           // Dimension of model coefficients
0091   TVectorD fOrthCoefficients;     //! The model coefficients
0092   TMatrixD fOrthCurvatureMatrix;  //! Model matrix
0093   TVectorD fCoefficients;         // Vector of the final coefficients
0094   TVectorD fCoefficientsRMS;      //! Vector of RMS of coefficients
0095   Double_t fRMS;                  //! Root mean square of fit
0096   Double_t fChi2;                 //! Chi square of fit
0097   Int_t fParameterisationCode;    //! Exit code of parameterisation
0098 
0099   Double_t fError;                 //! Error from parameterization
0100   Double_t fTestError;             //! Error from test
0101   Double_t fPrecision;             //! Relative precision of param
0102   Double_t fTestPrecision;         //! Relative precision of test
0103   Double_t fCorrelationCoeff;      //! Multi Correlation coefficient
0104   TMatrixD fCorrelationMatrix;     //! Correlation matrix
0105   Double_t fTestCorrelationCoeff;  //! Multi Correlation coefficient
0106 
0107   TList *fHistograms;     //! List of histograms
0108   Byte_t fHistogramMask;  //! Bit pattern of hisograms used
0109 
0110   //TVirtualFitter* fFitter;            //! Fit object (MINUIT)
0111 
0112   EMDFPolyType fPolyType;   // Type of polynomials to use
0113   Bool_t fShowCorrelation;  // print correlation matrix
0114   Bool_t fIsUserFunction;   // Flag for user defined function
0115   Bool_t fIsVerbose;        //
0116 
0117   virtual Double_t EvalFactor(Int_t p, Double_t x) const;
0118   virtual Double_t EvalControl(const Int_t *powers);
0119   virtual void MakeCoefficientErrors();
0120   virtual void MakeCorrelation();
0121   virtual Double_t MakeGramSchmidt(Int_t function);
0122   virtual void MakeCoefficients();
0123   virtual void MakeCandidates();
0124   virtual void MakeNormalized();
0125   virtual void MakeParameterization();
0126   virtual void MakeRealCode(const char *filename, const char *classname, Option_t *option = "");
0127   virtual Bool_t Select(const Int_t *iv);
0128   virtual Bool_t TestFunction(Double_t squareResidual, Double_t dResidur);
0129 
0130 public:
0131   TMultiDimFet();
0132   TMultiDimFet(const TMultiDimFet &in) = default;
0133   const TMultiDimFet &operator=(const TMultiDimFet &in);
0134 
0135   TMultiDimFet(Int_t dimension, EMDFPolyType type = kMonomials, Option_t *option = "");
0136   ~TMultiDimFet() override;
0137 
0138   virtual void AddRow(const Double_t *x, Double_t D, Double_t E = 0);
0139   virtual void AddTestRow(const Double_t *x, Double_t D, Double_t E = 0);
0140   //void     Browse(TBrowser* b) override;
0141   void Clear(Option_t *option = "") override;  // *MENU*
0142   //void     Draw(Option_t * ="d") override { }
0143   virtual Double_t Eval(const Double_t *x, const Double_t *coeff = nullptr) const;
0144   virtual void FindParameterization(double precision);  // *MENU*
0145   //virtual void     Fit(Option_t *option=""); // *MENU*
0146 
0147   Double_t GetChi2() const { return fChi2; }
0148   const TMatrixD *GetCorrelationMatrix() const { return &fCorrelationMatrix; }
0149   const TVectorD *GetCoefficients() const { return &fCoefficients; }
0150   Double_t GetError() const { return fError; }
0151   std::vector<Int_t> GetFunctionCodes() const { return fFunctionCodes; }
0152   const TMatrixD *GetFunctions() const { return &fFunctions; }
0153   virtual TList *GetHistograms() const { return fHistograms; }
0154   Double_t GetMaxAngle() const { return fMaxAngle; }
0155   Int_t GetMaxFunctions() const { return fMaxFunctions; }
0156   std::vector<Int_t> GetMaxPowers() const { return fMaxPowers; }
0157   Double_t GetMaxQuantity() const { return fMaxQuantity; }
0158   Int_t GetMaxStudy() const { return fMaxStudy; }
0159   Int_t GetMaxTerms() const { return fMaxTerms; }
0160   const TVectorD *GetMaxVariables() const { return &fMaxVariables; }
0161   Double_t GetMeanQuantity() const { return fMeanQuantity; }
0162   const TVectorD *GetMeanVariables() const { return &fMeanVariables; }
0163   Double_t GetMinAngle() const { return fMinAngle; }
0164   Double_t GetMinQuantity() const { return fMinQuantity; }
0165   Double_t GetMinRelativeError() const { return fMinRelativeError; }
0166   const TVectorD *GetMinVariables() const { return &fMinVariables; }
0167   Int_t GetNVariables() const { return fNVariables; }
0168   Int_t GetNCoefficients() const { return fNCoefficients; }
0169   Int_t GetPolyType() const { return fPolyType; }
0170   std::vector<Int_t> GetPowerIndex() const { return fPowerIndex; }
0171   Double_t GetPowerLimit() const { return fPowerLimit; }
0172   std::vector<Int_t> GetPowers() const { return fPowers; }
0173   Double_t GetPrecision() const { return fPrecision; }
0174   const TVectorD *GetQuantity() const { return &fQuantity; }
0175   Double_t GetResidualMax() const { return fMaxResidual; }
0176   Double_t GetResidualMin() const { return fMinResidual; }
0177   Int_t GetResidualMaxRow() const { return fMaxResidualRow; }
0178   Int_t GetResidualMinRow() const { return fMinResidualRow; }
0179   Double_t GetResidualSumSq() const { return fSumSqResidual; }
0180   Double_t GetRMS() const { return fRMS; }
0181   Int_t GetSampleSize() const { return fSampleSize; }
0182   const TVectorD *GetSqError() const { return &fSqError; }
0183   Double_t GetSumSqAvgQuantity() const { return fSumSqAvgQuantity; }
0184   Double_t GetSumSqQuantity() const { return fSumSqQuantity; }
0185   Double_t GetTestError() const { return fTestError; }
0186   Double_t GetTestPrecision() const { return fTestPrecision; }
0187   const TVectorD *GetTestQuantity() const { return &fTestQuantity; }
0188   Int_t GetTestSampleSize() const { return fTestSampleSize; }
0189   const TVectorD *GetTestSqError() const { return &fTestSqError; }
0190   const TVectorD *GetTestVariables() const { return &fTestVariables; }
0191   const TVectorD *GetVariables() const { return &fVariables; }
0192 
0193   //static TMultiDimFet* Instance()               { return fgInstance; }
0194   Bool_t IsFolder() const override { return kTRUE; }
0195   virtual Double_t MakeChi2(const Double_t *coeff = nullptr);
0196   virtual void MakeCode(const char *functionName = "MDF", Option_t *option = "");   // *MENU*
0197   virtual void MakeHistograms(Option_t *option = "A");                              // *MENU*
0198   virtual void MakeMethod(const Char_t *className = "MDF", Option_t *option = "");  // *MENU*
0199   void Print(Option_t *option = "ps") const override;                               // *MENU*
0200   virtual void PrintPolynomialsSpecial(Option_t *option = "m") const;               // *MENU*
0201 
0202   void SetMaxAngle(Double_t angle = 0);
0203   void SetMaxFunctions(Int_t n) { fMaxFunctions = n; }
0204   void SetMaxPowers(const Int_t *powers);
0205   void SetMaxStudy(Int_t n) { fMaxStudy = n; }
0206   void SetMaxTerms(Int_t terms) { fMaxTerms = terms; }
0207   void SetMinRelativeError(Double_t error);
0208   void SetMinAngle(Double_t angle = 1);
0209   void SetPowerLimit(Double_t limit = 1e-3);
0210   virtual void SetPowers(const Int_t *powers, Int_t terms);
0211 
0212   void ReducePolynomial(double error);
0213   void ZeroDoubiousCoefficients(double error);
0214 
0215   ClassDefOverride(TMultiDimFet, 1)  // Multi dimensional fit class
0216 };
0217 #endif  //SimG4Core_TotemRPProtonTransportParametrization_TMultiDimFet_H