ATLAS Offline Software
Loading...
Searching...
No Matches
RtParabolicExtrapolation.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include "GaudiKernel/MsgStream.h"
13
14using namespace MuonCalib;
15
17
18//*****************************************************************************
19
20//:::::::::::::::::::::::::::::::::::::::::::::::::::
21//:: METHOD getRtWithParabolicExtrapolation(.,.,.) ::
22//:::::::::::::::::::::::::::::::::::::::::::::::::::
23
25 const double r_max) const {
27 // VARIABLES //
29
30 double t_min(t_from_r(r_min, in_rt));
31 double t_max(t_from_r(r_max, in_rt));
32 std::vector<SamplePoint> t_r(10);
33 BaseFunctionFitter fitter(3);
35 std::vector<double> rt_param(102); // parameters of the output r-t relationship
36 double r, t; // drift radius
37
39 // FILL SAMPLE POINTS //
41
42 double step_size((t_max - t_min) / static_cast<double>(t_r.size() - 1));
43 for (unsigned int k = 0; k < t_r.size(); k++) {
44 t_r[k].set_x1(t_min + k * step_size);
45 t_r[k].set_x2(in_rt.radius(t_min + k * step_size));
46 t_r[k].set_error(1.0);
47 }
48 fitter.fit_parameters(t_r, 1, t_r.size(), pol);
49
50 rt_param[0] = in_rt.tLower();
51 rt_param[1] = (in_rt.tUpper() - in_rt.tLower()) / 99.0;
52 for (unsigned int k = 0; k < 100; k++) {
53 t = rt_param[0] + rt_param[1] * k;
54 r = in_rt.radius(t);
55 if (r < r_min) {
56 rt_param[k + 2] = r;
57 } else {
58 rt_param[k + 2] = 0.0;
59 for (unsigned int l = 0; l < 3; l++) { rt_param[k + 2] = rt_param[k + 2] + fitter.coefficients()[l] * pol.value(l, t); }
60 }
61 }
62
63 return RtRelationLookUp(rt_param);
64}
65
66//*****************************************************************************
67
68//:::::::::::::::::::::::::::::::::::::::::::::::::::::::
69//:: METHOD getRtWithParabolicExtrapolation(.,.,.,.,.) ::
70//:::::::::::::::::::::::::::::::::::::::::::::::::::::::
71
73 const double r_max, const double r_ext,
74 const std::vector<SamplePoint>& add_fit_points) const {
76 // VARIABLES //
78
79 // double t_min(t_from_r(r_min, in_rt));
80 double t_min(get_max_t_at_r(r_min, in_rt));
81 double t_max(t_from_r(r_max, in_rt));
82 std::vector<SamplePoint> t_r(10);
83 BaseFunctionFitter fitter(3);
85 std::vector<double> rt_param(102); // parameters of the output r-t relationship
86 double r, t; // drift radius, drift time
87
89 // FILL SAMPLE POINTS //
91
92 double step_size((t_max - t_min) / static_cast<double>(t_r.size() - 1));
93
94 // r-t-points in fit region
95 for (unsigned int k = 0; k < t_r.size(); k++) {
96 t_r[k].set_x1(t_min + k * step_size);
97 t_r[k].set_x2(in_rt.radius(t_min + k * step_size));
98 t_r[k].set_error(1.0);
99 }
100
101 // addtional points for the fit
102 for (const auto & add_fit_point : add_fit_points) { t_r.push_back(add_fit_point); }
103
104 // perform fit //
105 fitter.fit_parameters(t_r, 1, t_r.size(), pol);
106
107 // bring r-t-points in the right format for RtRelationLookUp and fill non
108 // modified and extrapolated points in the r-t
109 rt_param[0] = in_rt.tLower();
110 rt_param[1] = (in_rt.tUpper() - in_rt.tLower()) / 99.0;
111 for (unsigned int k = 0; k < 100; k++) {
112 t = rt_param[0] + rt_param[1] * k;
113 r = in_rt.radius(t);
114
115 // distinguish if extrapolation area is right or left from fit region
116 if (r_ext < r_min) {
117 if (r > r_min && t > t_min) {
118 rt_param[k + 2] = r; // fill original values
119 } else {
120 rt_param[k + 2] = 0.0;
121 for (unsigned int l = 0; l < 3; l++) { // fill extrapolated values
122 rt_param[k + 2] = rt_param[k + 2] + fitter.coefficients()[l] * pol.value(l, t);
123 }
124 if (rt_param[k + 2] < 0.0) { rt_param[k + 2] = 0.0; }
125 }
126 } else if (r_ext > r_max) {
127 if (r < r_max) {
128 rt_param[k + 2] = r; // fill original values
129 } else {
130 rt_param[k + 2] = 0.0;
131 for (unsigned int l = 0; l < 3; l++) { // fill extrapolated values
132 rt_param[k + 2] = rt_param[k + 2] + fitter.coefficients()[l] * pol.value(l, t);
133 }
134 }
135 }
136 // fill only original values if the radius where we want to extrapolate to is
137 // within the fit region
138 else if (r_ext <= r_max && r_ext >= r_min) {
139 rt_param[k + 2] = r;
140 MsgStream log(Athena::getMessageSvc(), "RtParabolicExtrapolation");
141 log << MSG::WARNING << "getRtWithParabolicExtrapolation() - Extrapolated radius withing fit region - Nothing to be done."
142 << endmsg;
143 }
144 }
145
146 return RtRelationLookUp(rt_param);
147}
148
149//*****************************************************************************
150
151//:::::::::::::::::::::
152//:: METHOD t_from_r ::
153//:::::::::::::::::::::
154
155double RtParabolicExtrapolation::t_from_r(const double r, const IRtRelation& in_rt) const {
157 // VARIABLES //
159
160 double precision(0.010); // spatial precision of the inversion
161 double t_max(in_rt.tUpper()); // upper time search limit
162 double t_min(in_rt.tLower()); // lower time search limit
163
165 // SEARCH FOR THE CORRESPONDING DRIFT TIME //
167
168 while (t_max - t_min > 0.1 && std::abs(in_rt.radius(0.5 * (t_min + t_max)) - r) > precision) {
169 if (in_rt.radius(0.5 * (t_min + t_max)) > r) {
170 t_max = 0.5 * (t_min + t_max);
171 } else {
172 t_min = 0.5 * (t_min + t_max);
173 }
174 }
175
176 return 0.5 * (t_min + t_max);
177}
178
179//*****************************************************************************
180
181//:::::::::::::::::::::::::::
182//:: METHOD get_max_t_at_r ::
183//:::::::::::::::::::::::::::
184
185double RtParabolicExtrapolation::get_max_t_at_r(const double r, const IRtRelation& in_rt) const {
186 for (double t = in_rt.tUpper(); t >= in_rt.tLower(); t = t - 1.0) {
187 if (in_rt.radius(t) < r) { return t + 1.0; }
188 }
189 return in_rt.tLower();
190}
#define endmsg
This class performs a fit of a linear combination of base functions to a set of sample points.
generic interface for a rt-relation
Definition IRtRelation.h:19
virtual double tLower() const =0
Returns the lower time covered by the r-t.
virtual double radius(double t) const =0
returns drift radius for a given time
virtual double tUpper() const =0
Returns the upper time covered by the r-t.
This class provides a legendre polynomial of order k.
double value(const int k, const double x) const override final
get the value of the k-th base function at x
double t_from_r(const double r, const IRtRelation &in_rt) const
RtParabolicExtrapolation()
Default constructor.
double get_max_t_at_r(const double r, const IRtRelation &in_rt) const
RtRelationLookUp getRtWithParabolicExtrapolation(const IRtRelation &in_rt, const double r_min=13.0, const double r_max=14.0) const
get an r-t relationship which is equivalent to the input relationship in_rt for r<r_min and has r(t) ...
Equidistant look up table for rt-relations with the time as key.
singleton-like access to IMessageSvc via open function and helper
int r
Definition globals.cxx:22
IMessageSvc * getMessageSvc(bool quiet=false)
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.