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);
681 Int_t numberFunctions = 0;
700 control[numberFunctions - 1] = Int_t(1.0
e+6 *
s);
725 for (
j = 0;
j <
i;
j++)
749 Double_t
x = control[
i];
754 if (control[
j] <=
x) {
762 control[
k] = control[
i];
794 Double_t
f =
Eval(
x, coeff);
833 if (!outName.EndsWith(
".C") && !outName.EndsWith(
".cxx"))
855 for (
j = 0;
j <=
i;
j++) {
859 curvatureMatrix(
j,
i) = curvatureMatrix(
i,
j);
873 const TVectorD diag = TMatrixDDiag_const(curvatureMatrix);
874 curvatureMatrix.NormByDiag(diag);
876 TDecompChol chol(curvatureMatrix);
877 if (!chol.Decompose())
878 Error(
"MakeCoefficientErrors",
"curvature matrix is singular");
879 chol.Invert(curvatureMatrix);
881 curvatureMatrix.NormByDiag(diag);
898 Int_t
col = 0, row = 0;
902 for (row =
col - 1; row > -1; row--) {
904 for (
i = row;
i <=
col;
i++)
975 Double_t xidotXj = 0;
993 for (
j = 0;
j <
i;
j++) {
1107 if (
opt.Length() < 1)
1117 if (
opt.Contains(
"x") ||
opt.Contains(
"a")) {
1126 if (
opt.Contains(
"d") ||
opt.Contains(
"a")) {
1133 if (
opt.Contains(
"n") ||
opt.Contains(
"a")) {
1137 fHistograms->Add(
new TH1D(Form(
"x_%d_norm",
i), Form(
"Normalized variable # %d",
i), 100, -1, 1));
1141 if (
opt.Contains(
"s") ||
opt.Contains(
"a")) {
1149 if (
opt.Contains(
"r1") ||
opt.Contains(
"a")) {
1154 Form(
"Computed residual versus x_%d",
i),
1164 if (
opt.Contains(
"r2") ||
opt.Contains(
"a")) {
1168 "Computed residuals vs Quantity",
1178 if (
opt.Contains(
"r3") ||
opt.Contains(
"a")) {
1182 "Computed residuals over training sample",
1187 if (
opt.Contains(
"r4") ||
opt.Contains(
"a")) {
1191 "Distribution of residuals from test",
1363 edm::LogInfo(
"TMultiDimFet") <<
"Coeff SumSqRes Contrib Angle QM Func" 1364 <<
" Value W^2 Powers" 1370 if (dResidur == 0) {
1399 squareResidual -= dResidur;
1411 << squareResidual <<
" " << std::setw(10) << std::setprecision(4) << dResidur
1412 <<
" " << std::setw(7) << std::setprecision(3) <<
fMaxAngle <<
" " 1413 << std::setw(7) << std::setprecision(3) <<
s <<
" " << std::setw(5) <<
i <<
" " 1415 <<
" " << std::setw(10) << std::setprecision(4)
1449 Bool_t isMethod = (
classname[0] ==
'\0' ? kFALSE : kTRUE);
1451 const char *cv_qual = (isMethod ?
"" :
"static ");
1455 Error(
"MakeRealCode",
"couldn't open output file '%s'",
filename);
1465 outFile <<
"// -*- mode: c++ -*-" 1470 <<
"// File " <<
filename <<
" generated by TMultiDimFet::MakeRealCode" 1474 outFile <<
"// on " << date.AsString() <<
"\n";
1476 outFile <<
"// ROOT version " << gROOT->GetVersion() <<
"\n" 1480 outFile <<
"// This file contains the function " 1484 <<
"// double " <<
prefix <<
"MDF(double *x); " 1488 <<
"// For evaluating the parameterization obtained" 1490 <<
"// from TMultiDimFet and the point x" 1494 <<
"// See TMultiDimFet class documentation for more " 1510 <<
"// Static data variables" 1522 outFile <<
"// Assignment to mean vector." 1533 outFile <<
"// Assignment to minimum vector." 1544 outFile <<
"// Assignment to maximum vector." 1555 outFile <<
"// Assignment to coefficients vector." 1557 outFile << cv_qual <<
"double " <<
prefix <<
"gCoefficient[] = {" << std::flush;
1559 outFile << (
i != 0 ?
"," :
"") <<
"\n" 1567 outFile <<
"// Assignment to powers vector." 1569 <<
"// The powers are stored row-wise, that is" 1571 <<
"// p_ij = " <<
prefix <<
"gPower[i * NVariables + j];" 1573 outFile << cv_qual <<
"int " <<
prefix <<
"gPower[] = {" << std::flush;
1595 <<
"// The " << (isMethod ?
"method " :
"function ") <<
" double " <<
prefix <<
"MDF(double *x)" 1601 <<
" double returnValue = " <<
prefix <<
"gDMean;" 1603 <<
" int i = 0, j = 0, k = 0;" 1605 <<
" for (i = 0; i < " <<
prefix <<
"gNCoefficients ; i++) {" 1607 <<
" // Evaluate the ith term in the expansion" 1609 <<
" double term = " <<
prefix <<
"gCoefficient[i];" 1611 <<
" for (j = 0; j < " <<
prefix <<
"gNVariables; j++) {" 1613 <<
" // Evaluate the polynomial in the jth variable." 1615 <<
" int power = " <<
prefix <<
"gPower[" <<
prefix <<
"gNVariables * i + j]; " 1617 <<
" double p1 = 1, p2 = 0, p3 = 0, r = 0;" 1619 <<
" double v = 1 + 2. / (" <<
prefix <<
"gXMax[j] - " <<
prefix <<
"gXMin[j]) * (x[j] - " <<
prefix 1622 <<
" // what is the power to use!" 1624 <<
" switch(power) {" 1626 <<
" case 1: r = 1; break; " 1628 <<
" case 2: r = v; break; " 1634 <<
" for (k = 3; k <= power; k++) { " 1639 outFile <<
" p3 = ((2 * i - 3) * p2 * v - (i - 2) * p1)" 1643 outFile <<
" p3 = 2 * v * p2 - p1; " 1645 outFile <<
" p1 = p2; p2 = p3; " 1653 <<
" // multiply this term by the poly in the jth var" 1659 <<
" // Add this term to the final result" 1661 <<
" returnValue += term;" 1665 <<
" return returnValue;" 1700 if (
opt.Contains(
"p")) {
1704 <<
"----------------" 1709 <<
" Power Limit Parameter: " <<
fPowerLimit <<
"\n" 1711 <<
" Max functions to study: " <<
fMaxStudy <<
"\n" 1712 <<
" Max angle (optional): " <<
fMaxAngle <<
"\n" 1715 <<
" Maximum Powers: " << std::flush;
1720 <<
" Parameterisation will be done using " << std::flush;
1722 edm::LogInfo(
"TMultiDimFet") <<
"Chebyshev polynomials" 1733 if (
opt.Contains(
"s")) {
1737 <<
"------------------" 1739 <<
" D" << std::flush;
1741 edm::LogInfo(
"TMultiDimFet") <<
" " << std::setw(10) <<
i + 1 << std::flush;
1743 <<
" Max: " << std::setw(10) << std::setprecision(7) <<
fMaxQuantity << std::flush;
1747 <<
" Min: " << std::setw(10) << std::setprecision(7) <<
fMinQuantity << std::flush;
1751 <<
" Mean: " << std::setw(10) << std::setprecision(7) <<
fMeanQuantity << std::flush;
1759 if (
opt.Contains(
"r")) {
1760 edm::LogInfo(
"TMultiDimFet") <<
"Results of Parameterisation:" 1762 <<
"----------------------------" 1764 <<
" Total reduction of square residuals " <<
fSumSqResidual <<
"\n" 1765 <<
" Relative precision obtained: " <<
fPrecision <<
"\n" 1766 <<
" Error obtained: " <<
fError <<
"\n" 1772 <<
" Estimated root mean square: " <<
fRMS <<
"\n" 1773 <<
" Maximum powers used: " << std::flush;
1777 <<
" Function codes of candidate functions." 1779 <<
" 1: considered," 1780 <<
" 2: too little contribution," 1781 <<
" 3: accepted." << std::flush;
1785 <<
" " << std::flush;
1786 else if (
i % 10 == 0)
1791 <<
" Loop over candidates stopped because " << std::flush;
1794 edm::LogInfo(
"TMultiDimFet") <<
"max allowed studies reached" 1798 edm::LogInfo(
"TMultiDimFet") <<
"all candidates considered several times" 1802 edm::LogInfo(
"TMultiDimFet") <<
"wanted relative error obtained" 1806 edm::LogInfo(
"TMultiDimFet") <<
"max number of terms reached" 1817 if (
opt.Contains(
"f")) {
1820 <<
"---------------" 1837 if (
opt.Contains(
"c")) {
1842 <<
" # Value Error Powers" 1844 <<
" ---------------------------------------" 1859 <<
"-------------------";
1863 if (
opt.Contains(
"m")) {
1867 <<
"-----------------" 1869 <<
" Normalised variables: " 1899 edm::LogInfo(
"TMultiDimFet") <<
" * L" <<
p - 1 <<
"(y" <<
j <<
")";
1902 edm::LogInfo(
"TMultiDimFet") <<
" * C" <<
p - 1 <<
"(y" <<
j <<
")";
1925 if (
opt.Contains(
"m")) {
1929 <<
"-----------------" 1931 <<
" Normalised variables: " 1961 edm::LogInfo(
"TMultiDimFet") <<
"*Leg(" <<
p - 1 <<
",y" <<
j <<
")";
1964 edm::LogInfo(
"TMultiDimFet") <<
"*C" <<
p - 1 <<
"(y" <<
j <<
")";
1999 if (ang >= 90 || ang < 0) {
2000 Warning(
"SetMaxAngle",
"angle must be in [0,90)");
2013 if (ang > 90 || ang <= 0) {
2014 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