ATLAS Offline Software
Parameterization.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 
8 namespace AFP {
9  Parameterization::Parameterization(std::string_view filename) : m_slopeInitIP{}, m_positionInitIP{} {
10  std::cout << "Reading parameterization from file: \"" << filename << "\"" << '\n';
11 
12  std::ifstream file;
13  file.open(filename.data());
14  if(!file.is_open()) {
15  std::stringstream errorMsg;
16  errorMsg << "Parameterization::load(): \tCould not open parameterization file: \"" << filename << "\"";
17  throw std::runtime_error(errorMsg.str().data());
18  }
19 
20  while (file.peek() == '#') {
21  char ch;
22  std::string name;
23  file >> ch >> name;
24 
25  if (name == "m_xPositionInitIP") { double value; file >> value; std::cout << '\t' << name << ": " << value << '\n'; m_positionInitIP[0] = value; }
26  if (name == "m_yPositionInitIP") { double value; file >> value; std::cout << '\t' << name << ": " << value << '\n'; m_positionInitIP[1] = value; }
27  if (name == "m_zPositionInitIP") { double value; file >> value; std::cout << '\t' << name << ": " << value << '\n'; m_positionInitIP[2] = value; }
28  if (name == "m_xSlopeInitIP") { double value; file >> value; std::cout << '\t' << name << ": " << value << '\n'; m_slopeInitIP[0] = value; }
29  if (name == "m_ySlopeInitIP") { double value; file >> value; std::cout << '\t' << name << ": " << value << '\n'; m_slopeInitIP[1] = value; }
30  if (name == "m_detectorPosition") { double value; file >> value; std::cout << '\t' << name << ": " << value << '\n'; m_parametrizationPosition = value; }
31  if (name == "m_nominalEnergy") { double value; file >> value; std::cout << '\t' << name << ": " << value << '\n'; m_energy = value; }
32 
33  file.ignore(1000, '\n');
34  }
35 
36  std::vector<std::unique_ptr<TF1>> poly;
37 
38  m_yIsUsed = false;
39 
40  for (int iEqu = 0; iEqu < m_numberOfEquations; iEqu++) {
41  file.ignore(1000, '\n');
42  std::vector<double> coef;
43 
44  for (int iPoly = 0; iPoly < m_numberOfPolynomials; iPoly++) {
45  int N = 0;
46  file >> N;
47  double value;
48 
49  for (int i = 0; i <= N; i++) {
50  if (file.eof()) {
51  std::stringstream errorMsg;
52  errorMsg << "Parameterization::load(): \tFile \"" << filename
53  << "\" does not contain a correct parameterization";
54  throw std::runtime_error(errorMsg.str().data());
55  }
56 
57  file >> value;
58  coef.push_back(value);
59  }
60 
61  file.ignore(1000, '\n');
62 
63  TString name;
64  name.Form("pol%d", N);
65  auto temp = std::make_unique<TF1>(name, name);
66  for (int iCoef = 0; iCoef <= N; ++iCoef) {
67  temp->SetParameter(iCoef, coef.at(iCoef));
68  }
69 
70  // For y-dependent equation check if polynomials are non-zero order
71  if (iEqu == 1 or iEqu == 3) {
72  m_yIsUsed = m_yIsUsed or not (N == 0 and coef[0] == 0);
73  }
74 
75  poly.push_back(std::move(temp));
76  coef.clear();
77  }
78 
79  m_equation.push_back(std::make_unique<Equation>(m_energy, std::move(poly)));
80  poly.clear();
81  }
82 
83  std::cout << "Finished reading parameterization: \"" << filename << "\"\n\n";
84  }
85 
86  double Parameterization::x(double x0, double y0, double z0, double sx0, double sy0, double E) const {
87  return getEquation(0)->evaluate(x0 + m_positionInitIP.at(0), y0 + m_positionInitIP.at(1), z0 + m_positionInitIP.at(2), sx0 + m_slopeInitIP.at(0), sy0 + m_slopeInitIP.at(1), E);
88  }
89 
90  double Parameterization::y(double x0, double y0, double z0, double sx0, double sy0, double E) const {
91  return getEquation(1)->evaluate(x0 + m_positionInitIP.at(0), y0 + m_positionInitIP.at(1), z0 + m_positionInitIP.at(2), sx0 + m_slopeInitIP.at(0), sy0 + m_slopeInitIP.at(1), E);
92  }
93 
94  double Parameterization::sx(double x0, double y0, double z0, double sx0, double sy0, double E) const {
95  return getEquation(2)->evaluate(x0 + m_positionInitIP.at(0), y0 + m_positionInitIP.at(1), z0 + m_positionInitIP.at(2), sx0 + m_slopeInitIP.at(0), sy0 + m_slopeInitIP.at(1), E);
96  }
97 
98  double Parameterization::sy(double x0, double y0, double z0, double sx0, double sy0, double E) const {
99  return getEquation(3)->evaluate(x0 + m_positionInitIP.at(0), y0 + m_positionInitIP.at(1), z0 + m_positionInitIP.at(2), sx0 + m_slopeInitIP.at(0), sy0 + m_slopeInitIP.at(1), E);
100  }
101 
102  double Parameterization::Equation::evaluate(double x, double y, double z, double sx, double sy, double E) const {
103  const double xi = (m_energy - E)/m_energy;
104 
105  const double v0 = getPolynomial(0)->Eval(xi);
106  const double v1 = x * getPolynomial(1)->Eval(xi);
107  const double v2 = y * getPolynomial(2)->Eval(xi);
108  const double v3 = z * getPolynomial(3)->Eval(xi);
109  const double v4 = sx * getPolynomial(4)->Eval(xi);
110  const double v5 = sy * getPolynomial(5)->Eval(xi);
111  const double v6 = z*sx * getPolynomial(6)->Eval(xi);
112  const double v7 = z*sy * getPolynomial(7)->Eval(xi);
113 
114  return v0 + v1 + v2 + v3 + v4 + v5 + v6 + v7;
115  }
116 }
AFP::Parameterization::Equation::getPolynomial
const TF1 * getPolynomial(int iPoly) const
Returns const raw poiner to polynomial of number iPoly.
Definition: Parameterization.h:35
fitman.sy
sy
Definition: fitman.py:524
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
Parameterization.h
python.compressB64.sx
string sx
Definition: compressB64.py:96
DeMoUpdate.errorMsg
string errorMsg
Definition: DeMoUpdate.py:897
athena.value
value
Definition: athena.py:124
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
x
#define x
AFP::Parameterization::getEquation
const Equation * getEquation(int iEqu) const
Returns const raw pointer to equation of number iEqu.
Definition: Parameterization.h:69
AFP
Header file for interface of SiGlobAlignDBTool used to read global alignment for database.
Definition: ISiGlobAlignDBTool.h:18
AFP::Parameterization::m_slopeInitIP
std::array< double, 2 > m_slopeInitIP
Crossing angles in rad.
Definition: Parameterization.h:82
MuonCalib::Legendre::poly
constexpr double poly(const double x)
Definition: LegendrePoly.h:116
parseMapping.v0
def v0
Definition: parseMapping.py:149
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
file
TFile * file
Definition: tile_monitor.h:29
AFP::Parameterization::Equation::evaluate
double evaluate(double x, double y, double z, double sx, double sy, double E) const
Evaluates value of function with given initial positions, slopes and energy.
Definition: Parameterization.cxx:102
TRT::Track::z0
@ z0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:63
AFP::Parameterization::Parameterization
Parameterization(std::string_view filename)
Takes filename of parametrization file as argument.
Definition: Parameterization.cxx:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
AFP::Parameterization::sy
double sy(double x0, double y0, double z0, double sx0, double sy0, double E) const
Evaluates value of vertical slope equation.
Definition: Parameterization.cxx:98
AFP::Parameterization::m_positionInitIP
std::array< double, 3 > m_positionInitIP
Initial vertex postition.
Definition: Parameterization.h:85
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
AFP::Parameterization::Equation::m_energy
double m_energy
Nominal energy of proton.
Definition: Parameterization.h:35
y
#define y
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
AFP::Parameterization::sx
double sx(double x0, double y0, double z0, double sx0, double sy0, double E) const
Evaluates value of horizontal slope equation.
Definition: Parameterization.cxx:94
AFP::Parameterization::y
double y(double x0, double y0, double z0, double sx0, double sy0, double E) const
Evaluates value of vertical position equation.
Definition: Parameterization.cxx:90
WriteCalibToCool.coef
coef
Definition: WriteCalibToCool.py:582
AFP::Parameterization::x
double x(double x0, double y0, double z0, double sx0, double sy0, double E) const
Evaluates value of horizontal position equation.
Definition: Parameterization.cxx:86