ATLAS Offline Software
BaseFunctionFitter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <TString.h> // for Form
8 #include <cmath>
9 
10 namespace MuonCalib {
11 
12 //*****************************************************************************
13 
15 // METHOD fit_parameters //
17 
19  const std::vector<SamplePoint> & sample_point,
20  const unsigned int & first_point,
21  const unsigned int & last_point,
22  BaseFunction * base_function) {
23 
25 // CHECKS //
27 
28  if (first_point<1 || first_point>sample_point.size()) {
29  throw std::runtime_error(Form("File: %s, Line: %d\nBaseFunctionFitter::fit_parameters() - ERROR: Illegal first point %d, must be >=1 and <=%lu", __FILE__, __LINE__, first_point, sample_point.size()));
30  }
31  if (last_point<first_point || last_point>sample_point.size()) {
32  throw std::runtime_error(Form("File: %s, Line: %d\nBaseFunctionFitter::fit_parameters() - ERROR: Illegal last point %d, must be >=%d and <=%lu", __FILE__, __LINE__, last_point, first_point, sample_point.size()));
33  }
34 
36 // IF ALL CHECK ARE PASSED, FILL THE MINIMIZATION OBJECTS //
38 
39 // clear the objects //
41 
42  for (int j=0; j<m_nb_coefficients; j++) {
43  for (int p=j; p<m_nb_coefficients; p++) {
44 
45  for (unsigned int k=first_point-1; k<last_point; k++) {
46  m_A.fillSymmetric(j,p,m_A(j,p)+base_function->value(j,sample_point[k].x1())
47  *base_function->value(p,sample_point[k].x1())/
48  std::pow(sample_point[k].error(), 2));
49 
50  }
51 
52  }
53 
54  for (unsigned int k=first_point-1; k<last_point; k++) {
55  m_b[j] = m_b[j]+sample_point[k].x2()*
56  base_function->value(j,
57  sample_point[k].x1())/
58  std::pow(sample_point[k].error(), 2);
59  }
60 
61  }
62 
63 // perform the minimization //
64  Amg::MatrixX aInv = m_A.inverse();
65  m_alpha = aInv*m_b;
66 
67  return false;
68 
69 }
70 
71 }
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:29
MuonCalib::BaseFunctionFitter::m_nb_coefficients
int m_nb_coefficients
number of coefficients
Definition: BaseFunctionFitter.h:51
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
MuonCalib::BaseFunction
Definition: BaseFunction.h:23
MuonCalib::BaseFunctionFitter::m_A
Amg::MatrixX m_A
coefficient matrix for the fit
Definition: BaseFunctionFitter.h:52
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
BaseFunctionFitter.h
MuonCalib::BaseFunctionFitter::m_alpha
Amg::VectorX m_alpha
coefficients of the base functions after the fit
Definition: BaseFunctionFitter.h:53
MuonCalib::BaseFunctionFitter::fit_parameters
bool fit_parameters(const std::vector< SamplePoint > &sample_point, const unsigned int &first_point, const unsigned int &last_point, BaseFunction *base_function)
perform a fit of the base functions (base_function) to the sample points as given in "sample_point" s...
Definition: BaseFunctionFitter.cxx:18
MuonCalib::BaseFunctionFitter::m_b
Amg::VectorX m_b
m_A*m_alpha = m_b;
Definition: BaseFunctionFitter.h:54
MuonCalib::BaseFunction::value
virtual double value(const int &k, const double &x) const =0
get the value of the k-th base function at x
get_generator_info.error
error
Definition: get_generator_info.py:40
MuonCalib::BaseFunctionFitter::init
void init(void)
default initialization method
fitman.k
k
Definition: fitman.py:528