|
|
Go to the documentation of this file.
13 #include "Riostream.h"
20 #include "TDecompChol.h"
25 #define RADDEG (180. / TMath::Pi())
26 #define DEGRAD (TMath::Pi() / 180.)
35 #define PARAM_MAXSTUDY 1
36 #define PARAM_SEVERAL 2
37 #define PARAM_RELERR 3
38 #define PARAM_MAXTERMS 4
160 : TNamed(
"multidimfit",
"Multi-dimensional fit object"),
213 if (
opt.Contains(
"k"))
215 if (
opt.Contains(
"v"))
403 for (
i = 0;
i <
n;
i++) {
406 for (
j = 0;
j <
m;
j++)
475 typedef std::multimap<double, int> cmt;
482 double del_error_abs = 0;
483 int deleted_terms_count = 0;
485 for (cmt::iterator it =
m.begin(); it !=
m.end() && del_error_abs <
error; ++it) {
488 del_error_abs =
TMath::Abs(it->first) + del_error_abs;
489 deleted_terms_count++;
495 TVectorD fCoefficients_new(fNCoefficients_new);
496 std::vector<Int_t> fPowerIndex_new;
510 edm::LogInfo(
"TMultiDimFet") << deleted_terms_count <<
" terms removed"
546 for (
i = 3;
i <=
p;
i++) {
549 p3 = ((2 *
i - 3) *
p2 *
x - (
i - 2) *
p1) / (
i - 1);
681 Int_t numberFunctions = 0;
684 Int_t maxNumberFunctions = 1;
705 control[numberFunctions - 1] = Int_t(1.0
e+6 *
s);
730 for (
j = 0;
j <
i;
j++)
754 Double_t
x = control[
i];
759 if (control[
j] <=
x) {
767 control[
k] = control[
i];
799 Double_t
f =
Eval(
x, coeff);
860 for (
j = 0;
j <=
i;
j++) {
864 curvatureMatrix(
j,
i) = curvatureMatrix(
i,
j);
878 const TVectorD diag = TMatrixDDiag_const(curvatureMatrix);
879 curvatureMatrix.NormByDiag(diag);
881 TDecompChol chol(curvatureMatrix);
882 if (!chol.Decompose())
883 Error(
"MakeCoefficientErrors",
"curvature matrix is singular");
884 chol.Invert(curvatureMatrix);
886 curvatureMatrix.NormByDiag(diag);
903 Int_t
col = 0, row = 0;
907 for (row =
col - 1; row > -1; row--) {
909 for (
i = row;
i <=
col;
i++)
980 Double_t xidotXj = 0;
998 for (
j = 0;
j <
i;
j++) {
1112 if (
opt.Length() < 1)
1122 if (
opt.Contains(
"x") ||
opt.Contains(
"a")) {
1131 if (
opt.Contains(
"d") ||
opt.Contains(
"a")) {
1138 if (
opt.Contains(
"n") ||
opt.Contains(
"a")) {
1142 fHistograms->Add(
new TH1D(Form(
"x_%d_norm",
i), Form(
"Normalized variable # %d",
i), 100, -1, 1));
1146 if (
opt.Contains(
"s") ||
opt.Contains(
"a")) {
1154 if (
opt.Contains(
"r1") ||
opt.Contains(
"a")) {
1159 Form(
"Computed residual versus x_%d",
i),
1169 if (
opt.Contains(
"r2") ||
opt.Contains(
"a")) {
1173 "Computed residuals vs Quantity",
1183 if (
opt.Contains(
"r3") ||
opt.Contains(
"a")) {
1187 "Computed residuals over training sample",
1192 if (
opt.Contains(
"r4") ||
opt.Contains(
"a")) {
1196 "Distribution of residuals from test",
1368 edm::LogInfo(
"TMultiDimFet") <<
"Coeff SumSqRes Contrib Angle QM Func"
1369 <<
" Value W^2 Powers"
1375 if (dResidur == 0) {
1404 squareResidual -= dResidur;
1416 << squareResidual <<
" " << std::setw(10) << std::setprecision(4) << dResidur
1417 <<
" " << std::setw(7) << std::setprecision(3) <<
fMaxAngle <<
" "
1418 << std::setw(7) << std::setprecision(3) <<
s <<
" " << std::setw(5) <<
i <<
" "
1420 <<
" " << std::setw(10) << std::setprecision(4)
1454 Bool_t isMethod = (
classname[0] ==
'\0' ? kFALSE : kTRUE);
1456 const char *cv_qual = (isMethod ?
"" :
"static ");
1460 Error(
"MakeRealCode",
"couldn't open output file '%s'",
filename);
1470 outFile <<
"// -*- mode: c++ -*-"
1475 <<
"// File " <<
filename <<
" generated by TMultiDimFet::MakeRealCode"
1481 outFile <<
"// ROOT version " << gROOT->GetVersion() <<
"\n"
1485 outFile <<
"// This file contains the function "
1489 <<
"// double " <<
prefix <<
"MDF(double *x); "
1493 <<
"// For evaluating the parameterization obtained"
1495 <<
"// from TMultiDimFet and the point x"
1499 <<
"// See TMultiDimFet class documentation for more "
1515 <<
"// Static data variables"
1527 outFile <<
"// Assignment to mean vector."
1538 outFile <<
"// Assignment to minimum vector."
1549 outFile <<
"// Assignment to maximum vector."
1560 outFile <<
"// Assignment to coefficients vector."
1562 outFile << cv_qual <<
"double " <<
prefix <<
"gCoefficient[] = {" << std::flush;
1564 outFile << (
i != 0 ?
"," :
"") <<
"\n"
1572 outFile <<
"// Assignment to powers vector."
1574 <<
"// The powers are stored row-wise, that is"
1576 <<
"// p_ij = " <<
prefix <<
"gPower[i * NVariables + j];"
1578 outFile << cv_qual <<
"int " <<
prefix <<
"gPower[] = {" << std::flush;
1600 <<
"// The " << (isMethod ?
"method " :
"function ") <<
" double " <<
prefix <<
"MDF(double *x)"
1606 <<
" double returnValue = " <<
prefix <<
"gDMean;"
1608 <<
" int i = 0, j = 0, k = 0;"
1610 <<
" for (i = 0; i < " <<
prefix <<
"gNCoefficients ; i++) {"
1612 <<
" // Evaluate the ith term in the expansion"
1614 <<
" double term = " <<
prefix <<
"gCoefficient[i];"
1616 <<
" for (j = 0; j < " <<
prefix <<
"gNVariables; j++) {"
1618 <<
" // Evaluate the polynomial in the jth variable."
1620 <<
" int power = " <<
prefix <<
"gPower[" <<
prefix <<
"gNVariables * i + j]; "
1622 <<
" double p1 = 1, p2 = 0, p3 = 0, r = 0;"
1624 <<
" double v = 1 + 2. / (" <<
prefix <<
"gXMax[j] - " <<
prefix <<
"gXMin[j]) * (x[j] - " <<
prefix
1627 <<
" // what is the power to use!"
1629 <<
" switch(power) {"
1631 <<
" case 1: r = 1; break; "
1633 <<
" case 2: r = v; break; "
1639 <<
" for (k = 3; k <= power; k++) { "
1644 outFile <<
" p3 = ((2 * i - 3) * p2 * v - (i - 2) * p1)"
1648 outFile <<
" p3 = 2 * v * p2 - p1; "
1650 outFile <<
" p1 = p2; p2 = p3; "
1658 <<
" // multiply this term by the poly in the jth var"
1664 <<
" // Add this term to the final result"
1666 <<
" returnValue += term;"
1670 <<
" return returnValue;"
1705 if (
opt.Contains(
"p")) {
1709 <<
"----------------"
1714 <<
" Power Limit Parameter: " <<
fPowerLimit <<
"\n"
1716 <<
" Max functions to study: " <<
fMaxStudy <<
"\n"
1717 <<
" Max angle (optional): " <<
fMaxAngle <<
"\n"
1720 <<
" Maximum Powers: " << std::flush;
1725 <<
" Parameterisation will be done using " << std::flush;
1727 edm::LogInfo(
"TMultiDimFet") <<
"Chebyshev polynomials"
1738 if (
opt.Contains(
"s")) {
1742 <<
"------------------"
1744 <<
" D" << std::flush;
1746 edm::LogInfo(
"TMultiDimFet") <<
" " << std::setw(10) <<
i + 1 << std::flush;
1748 <<
" Max: " << std::setw(10) << std::setprecision(7) <<
fMaxQuantity << std::flush;
1752 <<
" Min: " << std::setw(10) << std::setprecision(7) <<
fMinQuantity << std::flush;
1756 <<
" Mean: " << std::setw(10) << std::setprecision(7) <<
fMeanQuantity << std::flush;
1764 if (
opt.Contains(
"r")) {
1765 edm::LogInfo(
"TMultiDimFet") <<
"Results of Parameterisation:"
1767 <<
"----------------------------"
1769 <<
" Total reduction of square residuals " <<
fSumSqResidual <<
"\n"
1770 <<
" Relative precision obtained: " <<
fPrecision <<
"\n"
1771 <<
" Error obtained: " <<
fError <<
"\n"
1777 <<
" Estimated root mean square: " <<
fRMS <<
"\n"
1778 <<
" Maximum powers used: " << std::flush;
1782 <<
" Function codes of candidate functions."
1784 <<
" 1: considered,"
1785 <<
" 2: too little contribution,"
1786 <<
" 3: accepted." << std::flush;
1790 <<
" " << std::flush;
1791 else if (
i % 10 == 0)
1796 <<
" Loop over candidates stopped because " << std::flush;
1799 edm::LogInfo(
"TMultiDimFet") <<
"max allowed studies reached"
1803 edm::LogInfo(
"TMultiDimFet") <<
"all candidates considered several times"
1807 edm::LogInfo(
"TMultiDimFet") <<
"wanted relative error obtained"
1811 edm::LogInfo(
"TMultiDimFet") <<
"max number of terms reached"
1822 if (
opt.Contains(
"f")) {
1825 <<
"---------------"
1842 if (
opt.Contains(
"c")) {
1847 <<
" # Value Error Powers"
1849 <<
" ---------------------------------------"
1864 <<
"-------------------";
1868 if (
opt.Contains(
"m")) {
1872 <<
"-----------------"
1874 <<
" Normalised variables: "
1904 edm::LogInfo(
"TMultiDimFet") <<
" * L" <<
p - 1 <<
"(y" <<
j <<
")";
1907 edm::LogInfo(
"TMultiDimFet") <<
" * C" <<
p - 1 <<
"(y" <<
j <<
")";
1930 if (
opt.Contains(
"m")) {
1934 <<
"-----------------"
1936 <<
" Normalised variables: "
1966 edm::LogInfo(
"TMultiDimFet") <<
"*Leg(" <<
p - 1 <<
",y" <<
j <<
")";
1969 edm::LogInfo(
"TMultiDimFet") <<
"*C" <<
p - 1 <<
"(y" <<
j <<
")";
2004 if (ang >= 90 || ang < 0) {
2005 Warning(
"SetMaxAngle",
"angle must be in [0,90)");
2018 if (ang > 90 || ang <= 0) {
2019 Warning(
"SetMinAngle",
"angle must be in [0,90)");
Double_t fPrecision
Error from test.
Double_t fTestError
Error from parameterization.
Double_t fChi2
Root mean square of fit.
Double_t fError
Exit code of parameterisation.
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
virtual Bool_t Select(const Int_t *iv)
void SetPowerLimit(Double_t limit=1e-3)
Double_t fMaxResidual
Vector of the final residuals.
Int_t fTestSampleSize
Test sample, independent variables.
void ReducePolynomial(double error)
std::vector< Int_t > fPowerIndex
virtual void MakeHistograms(Option_t *option="A")
virtual Double_t MakeChi2(const Double_t *coeff=nullptr)
TVectorD fOrthCoefficients
Double_t fMinQuantity
Max value of dependent quantity.
std::vector< Int_t > fMaxPowersFinal
Norm of the evaluated functions.
Double_t fMaxAngle
Min angle for acepting new function.
Int_t fNVariables
Training sample, independent variables.
Double_t fMinRelativeError
Double_t fPowerLimit
maximum powers, ex-array
Double_t fSumSqResidual
Row giving min residual.
Log< level::Info, false > LogInfo
Int_t fNCoefficients
Sum of Square residuals.
virtual void MakeCoefficients()
TVectorD fVariables
Sum of squares away from mean.
virtual void MakeRealCode(const char *filename, const char *classname, Option_t *option="")
TVectorD fCoefficientsRMS
virtual void MakeParameterization()
virtual void FindParameterization(double precision)
virtual void MakeCandidates()
TVectorD fCoefficients
Model matrix.
virtual void MakeCode(const char *functionName="MDF", Option_t *option="")
Double_t fMinResidual
Max redsidual value.
Int_t fParameterisationCode
Chi square of fit.
virtual void MakeMethod(const Char_t *className="MDF", Option_t *option="")
virtual void AddRow(const Double_t *x, Double_t D, Double_t E=0)
Double_t fMeanQuantity
Training sample, error in quantity.
TVectorD fSqError
Training sample, dependent quantity.
Double_t fTestCorrelationCoeff
Correlation matrix.
virtual void PrintPolynomialsSpecial(Option_t *option="m") const
TVectorD fTestQuantity
Size of training sample.
virtual Double_t Eval(const Double_t *x, const Double_t *coeff=nullptr) const
TMatrixD fOrthFunctions
max functions to study
Int_t fMaxFunctionsTimesNVariables
maximum powers from fit, ex-array
std::vector< Int_t > fMaxPowers
Min relative error accepted.
TVectorD fMaxVariables
mean value of independent variables
Int_t fMaxTerms
Max angle for acepting new function.
void SetMinAngle(Double_t angle=1)
Double_t fSumSqQuantity
Min value of dependent quantity.
EMDFPolyType fPolyType
Bit pattern of hisograms used.
virtual Bool_t TestFunction(Double_t squareResidual, Double_t dResidur)
TVectorD fTestVariables
Test sample, Error in quantity.
Int_t fMaxStudy
acceptance code, ex-array
Int_t fMinResidualRow
Row giving max residual.
std::vector< Int_t > fPowers
edm::ErrorSummaryEntry Error
Int_t fMaxFunctions
Functions evaluated over sample.
void Print(Option_t *option="ps") const override
virtual void MakeNormalized()
TMatrixD fCorrelationMatrix
Multi Correlation coefficient.
Double_t fCorrelationCoeff
Relative precision of test.
Double_t fSumSqAvgQuantity
SumSquare of dependent quantity.
Byte_t fHistogramMask
List of histograms.
virtual void SetPowers(const Int_t *powers, Int_t terms)
virtual void AddTestRow(const Double_t *x, Double_t D, Double_t E=0)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Double_t fMinAngle
Size of test sample.
TMatrixD fOrthCurvatureMatrix
The model coefficients.
Double_t fTestPrecision
Relative precision of param.
DecomposeProduct< arg, typename Div::arg > D
virtual Double_t MakeGramSchmidt(Int_t function)
virtual void MakeCorrelation()
void ZeroDoubiousCoefficients(double error)
virtual Double_t EvalFactor(Int_t p, Double_t x) const
void SetMinRelativeError(Double_t error)
Log< level::Info, true > LogVerbatim
void SetMaxAngle(Double_t angle=0)
TVectorD fTestSqError
Test sample, dependent quantity.
Double_t fRMS
Vector of RMS of coefficients.
void Clear(Option_t *option="") override
std::vector< Int_t > fFunctionCodes
TList * fHistograms
Multi Correlation coefficient.
Int_t fMaxResidualRow
Min redsidual value.
void SetMaxPowers(const Int_t *powers)
const TMultiDimFet & operator=(const TMultiDimFet &in)
TMatrixD fFunctions
Control parameter.
virtual void MakeCoefficientErrors()
TVectorD fOrthFunctionNorms
As above, but orthogonalised.
virtual Double_t EvalControl(const Int_t *powers)