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) {
486 if (TMath::Abs(
it->first) + del_error_abs <
error) {
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);
682 Int_t numberFunctions = 0;
701 control[numberFunctions - 1] = Int_t(1.0
e+6 *
s);
726 for (
j = 0;
j <
i;
j++)
750 Double_t
x = control[
i];
755 if (control[
j] <=
x) {
763 control[
k] = control[
i];
795 Double_t
f =
Eval(
x, coeff);
834 if (!outName.EndsWith(
".C") && !outName.EndsWith(
".cxx"))
856 for (
j = 0;
j <=
i;
j++) {
860 curvatureMatrix(
j,
i) = curvatureMatrix(
i,
j);
874 const TVectorD diag = TMatrixDDiag_const(curvatureMatrix);
875 curvatureMatrix.NormByDiag(diag);
877 TDecompChol chol(curvatureMatrix);
878 if (!chol.Decompose())
879 Error(
"MakeCoefficientErrors",
"curvature matrix is singular");
880 chol.Invert(curvatureMatrix);
882 curvatureMatrix.NormByDiag(diag);
899 Int_t
col = 0, row = 0;
903 for (row =
col - 1; row > -1; row--) {
905 for (
i = row;
i <=
col;
i++)
976 Double_t xidotXj = 0;
994 for (
j = 0;
j <
i;
j++) {
1108 if (
opt.Length() < 1)
1118 if (
opt.Contains(
"x") ||
opt.Contains(
"a")) {
1127 if (
opt.Contains(
"d") ||
opt.Contains(
"a")) {
1134 if (
opt.Contains(
"n") ||
opt.Contains(
"a")) {
1138 fHistograms->Add(
new TH1D(Form(
"x_%d_norm",
i), Form(
"Normalized variable # %d",
i), 100, -1, 1));
1142 if (
opt.Contains(
"s") ||
opt.Contains(
"a")) {
1150 if (
opt.Contains(
"r1") ||
opt.Contains(
"a")) {
1155 Form(
"Computed residual versus x_%d",
i),
1165 if (
opt.Contains(
"r2") ||
opt.Contains(
"a")) {
1169 "Computed residuals vs Quantity",
1179 if (
opt.Contains(
"r3") ||
opt.Contains(
"a")) {
1183 "Computed residuals over training sample",
1188 if (
opt.Contains(
"r4") ||
opt.Contains(
"a")) {
1192 "Distribution of residuals from test",
1364 edm::LogInfo(
"TMultiDimFet") <<
"Coeff SumSqRes Contrib Angle QM Func" 1365 <<
" Value W^2 Powers" 1371 if (dResidur == 0) {
1400 squareResidual -= dResidur;
1412 << squareResidual <<
" " << std::setw(10) << std::setprecision(4) << dResidur
1413 <<
" " << std::setw(7) << std::setprecision(3) <<
fMaxAngle <<
" " 1414 << std::setw(7) << std::setprecision(3) <<
s <<
" " << std::setw(5) <<
i <<
" " 1416 <<
" " << std::setw(10) << std::setprecision(4)
1450 Bool_t isMethod = (
classname[0] ==
'\0' ? kFALSE : kTRUE);
1452 const char *cv_qual = (isMethod ?
"" :
"static ");
1456 Error(
"MakeRealCode",
"couldn't open output file '%s'",
filename);
1466 outFile <<
"// -*- mode: c++ -*-" 1471 <<
"// File " <<
filename <<
" generated by TMultiDimFet::MakeRealCode" 1475 outFile <<
"// on " << date.AsString() <<
"\n";
1477 outFile <<
"// ROOT version " << gROOT->GetVersion() <<
"\n" 1481 outFile <<
"// This file contains the function " 1485 <<
"// double " <<
prefix <<
"MDF(double *x); " 1489 <<
"// For evaluating the parameterization obtained" 1491 <<
"// from TMultiDimFet and the point x" 1495 <<
"// See TMultiDimFet class documentation for more " 1511 <<
"// Static data variables" 1523 outFile <<
"// Assignment to mean vector." 1534 outFile <<
"// Assignment to minimum vector." 1545 outFile <<
"// Assignment to maximum vector." 1556 outFile <<
"// Assignment to coefficients vector." 1558 outFile << cv_qual <<
"double " <<
prefix <<
"gCoefficient[] = {" << std::flush;
1560 outFile << (
i != 0 ?
"," :
"") <<
"\n" 1568 outFile <<
"// Assignment to powers vector." 1570 <<
"// The powers are stored row-wise, that is" 1572 <<
"// p_ij = " <<
prefix <<
"gPower[i * NVariables + j];" 1574 outFile << cv_qual <<
"int " <<
prefix <<
"gPower[] = {" << std::flush;
1596 <<
"// The " << (isMethod ?
"method " :
"function ") <<
" double " <<
prefix <<
"MDF(double *x)" 1602 <<
" double returnValue = " <<
prefix <<
"gDMean;" 1604 <<
" int i = 0, j = 0, k = 0;" 1606 <<
" for (i = 0; i < " <<
prefix <<
"gNCoefficients ; i++) {" 1608 <<
" // Evaluate the ith term in the expansion" 1610 <<
" double term = " <<
prefix <<
"gCoefficient[i];" 1612 <<
" for (j = 0; j < " <<
prefix <<
"gNVariables; j++) {" 1614 <<
" // Evaluate the polynomial in the jth variable." 1616 <<
" int power = " <<
prefix <<
"gPower[" <<
prefix <<
"gNVariables * i + j]; " 1618 <<
" double p1 = 1, p2 = 0, p3 = 0, r = 0;" 1620 <<
" double v = 1 + 2. / (" <<
prefix <<
"gXMax[j] - " <<
prefix <<
"gXMin[j]) * (x[j] - " <<
prefix 1623 <<
" // what is the power to use!" 1625 <<
" switch(power) {" 1627 <<
" case 1: r = 1; break; " 1629 <<
" case 2: r = v; break; " 1635 <<
" for (k = 3; k <= power; k++) { " 1640 outFile <<
" p3 = ((2 * i - 3) * p2 * v - (i - 2) * p1)" 1644 outFile <<
" p3 = 2 * v * p2 - p1; " 1646 outFile <<
" p1 = p2; p2 = p3; " 1654 <<
" // multiply this term by the poly in the jth var" 1660 <<
" // Add this term to the final result" 1662 <<
" returnValue += term;" 1666 <<
" return returnValue;" 1701 if (
opt.Contains(
"p")) {
1705 <<
"----------------" 1710 <<
" Power Limit Parameter: " <<
fPowerLimit <<
"\n" 1712 <<
" Max functions to study: " <<
fMaxStudy <<
"\n" 1713 <<
" Max angle (optional): " <<
fMaxAngle <<
"\n" 1716 <<
" Maximum Powers: " << std::flush;
1721 <<
" Parameterisation will be done using " << std::flush;
1723 edm::LogInfo(
"TMultiDimFet") <<
"Chebyshev polynomials" 1734 if (
opt.Contains(
"s")) {
1738 <<
"------------------" 1740 <<
" D" << std::flush;
1742 edm::LogInfo(
"TMultiDimFet") <<
" " << std::setw(10) <<
i + 1 << std::flush;
1744 <<
" Max: " << std::setw(10) << std::setprecision(7) <<
fMaxQuantity << std::flush;
1748 <<
" Min: " << std::setw(10) << std::setprecision(7) <<
fMinQuantity << std::flush;
1752 <<
" Mean: " << std::setw(10) << std::setprecision(7) <<
fMeanQuantity << std::flush;
1760 if (
opt.Contains(
"r")) {
1761 edm::LogInfo(
"TMultiDimFet") <<
"Results of Parameterisation:" 1763 <<
"----------------------------" 1765 <<
" Total reduction of square residuals " <<
fSumSqResidual <<
"\n" 1766 <<
" Relative precision obtained: " <<
fPrecision <<
"\n" 1767 <<
" Error obtained: " <<
fError <<
"\n" 1773 <<
" Estimated root mean square: " <<
fRMS <<
"\n" 1774 <<
" Maximum powers used: " << std::flush;
1778 <<
" Function codes of candidate functions." 1780 <<
" 1: considered," 1781 <<
" 2: too little contribution," 1782 <<
" 3: accepted." << std::flush;
1786 <<
" " << std::flush;
1787 else if (
i % 10 == 0)
1792 <<
" Loop over candidates stopped because " << std::flush;
1795 edm::LogInfo(
"TMultiDimFet") <<
"max allowed studies reached" 1799 edm::LogInfo(
"TMultiDimFet") <<
"all candidates considered several times" 1803 edm::LogInfo(
"TMultiDimFet") <<
"wanted relative error obtained" 1807 edm::LogInfo(
"TMultiDimFet") <<
"max number of terms reached" 1818 if (
opt.Contains(
"f")) {
1821 <<
"---------------" 1838 if (
opt.Contains(
"c")) {
1843 <<
" # Value Error Powers" 1845 <<
" ---------------------------------------" 1860 <<
"-------------------";
1864 if (
opt.Contains(
"m")) {
1868 <<
"-----------------" 1870 <<
" Normalised variables: " 1900 edm::LogInfo(
"TMultiDimFet") <<
" * L" <<
p - 1 <<
"(y" <<
j <<
")";
1903 edm::LogInfo(
"TMultiDimFet") <<
" * C" <<
p - 1 <<
"(y" <<
j <<
")";
1926 if (
opt.Contains(
"m")) {
1930 <<
"-----------------" 1932 <<
" Normalised variables: " 1962 edm::LogInfo(
"TMultiDimFet") <<
"*Leg(" <<
p - 1 <<
",y" <<
j <<
")";
1965 edm::LogInfo(
"TMultiDimFet") <<
"*C" <<
p - 1 <<
"(y" <<
j <<
")";
2000 if (ang >= 90 || ang < 0) {
2001 Warning(
"SetMaxAngle",
"angle must be in [0,90)");
2014 if (ang > 90 || ang <= 0) {
2015 Warning(
"SetMinAngle",
"angle must be in [0,90)");
Log< level::Info, true > LogVerbatim
edm::ErrorSummaryEntry Error
TMatrixD fCorrelationMatrix
Multi Correlation coefficient.
Double_t fSumSqQuantity
Min value of dependent quantity.
Double_t fMinAngle
Size of test sample.
TVectorD fTestVariables
Test sample, Error in quantity.
const TMultiDimFet & operator=(const TMultiDimFet &in)
Int_t fTestSampleSize
Test sample, independent variables.
Double_t fSumSqAvgQuantity
SumSquare of dependent quantity.
Double_t fMinQuantity
Max value of dependent quantity.
virtual void MakeCoefficientErrors()
void ZeroDoubiousCoefficients(double error)
void SetPowerLimit(Double_t limit=1e-3)
Int_t fParameterisationCode
Chi square of fit.
Double_t fMinResidual
Max redsidual value.
EMDFPolyType fPolyType
Bit pattern of hisograms used.
TMatrixD fFunctions
Control parameter.
Double_t fTestCorrelationCoeff
Correlation matrix.
void SetMaxPowers(const Int_t *powers)
virtual Double_t EvalControl(const Int_t *powers)
TMatrixD fOrthFunctions
max functions to study
Byte_t fHistogramMask
List of histograms.
Double_t fMaxAngle
Min angle for acepting new function.
std::vector< Int_t > fPowers
Double_t fPowerLimit
maximum powers, ex-array
Double_t fPrecision
Error from test.
virtual void MakeHistograms(Option_t *option="A")
TVectorD fCoefficientsRMS
virtual void MakeParameterization()
virtual Double_t MakeGramSchmidt(Int_t function)
Int_t fMaxResidualRow
Min redsidual value.
void Print(Option_t *option="ps") const override
Double_t fTestError
Error from parameterization.
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)
virtual void SetPowers(const Int_t *powers, Int_t terms)
Int_t fNVariables
Training sample, independent variables.
virtual void MakeCandidates()
Double_t fChi2
Root mean square of fit.
Int_t fMinResidualRow
Row giving max residual.
virtual void PrintPolynomialsSpecial(Option_t *option="m") const
TVectorD fTestSqError
Test sample, dependent quantity.
Double_t fMinRelativeError
virtual void MakeCorrelation()
TVectorD fOrthCoefficients
Double_t fRMS
Vector of RMS of coefficients.
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::vector< Int_t > fPowerIndex
Double_t fMeanQuantity
Training sample, error in quantity.
TVectorD fOrthFunctionNorms
As above, but orthogonalised.
virtual void MakeCode(const char *functionName="MDF", Option_t *option="")
Double_t fSumSqResidual
Row giving min residual.
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.
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
virtual void FindParameterization(double precision)
Double_t fTestPrecision
Relative precision of param.
TList * fHistograms
Multi Correlation coefficient.
Log< level::Info, false > LogInfo
Int_t fMaxTerms
Max angle for acepting new function.
TVectorD fTestQuantity
Size of training sample.
DecomposeProduct< arg, typename Div::arg > D
TVectorD fVariables
Sum of squares away from mean.
Int_t fMaxFunctions
Functions evaluated over sample.
Double_t fError
Exit code of parameterisation.
Int_t fNCoefficients
Sum of Square residuals.
Int_t fMaxFunctionsTimesNVariables
maximum powers from fit, ex-array
std::vector< Int_t > fFunctionCodes
TVectorD fSqError
Training sample, dependent quantity.
void SetMinAngle(Double_t angle=1)
Double_t fCorrelationCoeff
Relative precision of test.
TMatrixD fOrthCurvatureMatrix
The model coefficients.
virtual void MakeCoefficients()
std::vector< Int_t > fMaxPowers
Min relative error accepted.
void Clear(Option_t *option="") override
virtual void MakeMethod(const Char_t *className="MDF", Option_t *option="")
void ReducePolynomial(double error)
std::vector< Int_t > fMaxPowersFinal
Norm of the evaluated functions.
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)
TVectorD fCoefficients
Model matrix.
Int_t fMaxStudy
acceptance code, ex-array
virtual Double_t EvalFactor(Int_t p, Double_t x) const