determine a t0 correction for the given segment; the algorithm choses the correction such that the chi^2 of the segment fit becomes maximum; the algorithm has to get a pointer to r-t relationship to be used for the fitting; if overwrite is set to true, the segment is refitted with the refined t0 and overwritten; in case of failure failed=true; error is the estimated error of the time correction, if curved is set to true, a curved fit is performed
28 {
30
32
34
36
38
39 double delta_t0_opt;
40 MuonCalibSegment seg(*segment);
41 NtupleStationId
id((seg.mdtHOT())[0]->identify());
44 BaseFunctionFitter
fitter(3);
45 SimplePolynomial pol;
46 std::vector<SamplePoint> my_points(3);
47 IMdtPatRecFitter* segment_fitter = nullptr;
48 if (curved) {
50 } else {
52 }
55
57
59
60
64 time = mdt_hit->driftTime();
65 sigma = mdt_hit->sigmaDriftRadius();
66 if (sigma > 10.0 && std::abs(mdt_hit->driftRadius()) > 14.0) r_selection[
k] = 1;
67 if (sigma > 10.0 && mdt_hit->driftTime() < 50.0)
sigma = 0.3;
68 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
70 }
71 MTStraightLine straight_track;
72 CurvedLine curved_track;
73 if (curved) {
74 if (!
m_cfitter->fit(seg, r_selection, curved_track)) {
75 failed = true;
76 return 0.0;
77 }
78 } else {
79 if (!
m_qfitter->fitCallByReference(seg, r_selection, straight_track)) {
80 failed = true;
81 return 0.0;
82 }
83 }
84
85 my_points[0].set_x1(0.0);
86 if (curved) {
88 } else {
90 }
91 my_points[0].set_error(1.0);
92
94
97 sigma = mdt_hit->sigmaDriftRadius();
98 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
99 }
100 if (!segment_fitter->
fit(seg, r_selection)) {
101 failed = true;
102 return 0.0;
103 }
104
106 if (curved) {
108 } else {
110 }
111 my_points[1].set_error(1.0);
112
113
115 if (my_points[1].
x2() > my_points[0].
x2()) {
118 } else {
121 }
122 sigma = mdt_hit->sigmaDriftRadius();
123 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
124 }
125 if (!segment_fitter->
fit(seg, r_selection)) {
126 failed = true;
127 return 0.0;
128 }
129 if (curved) {
131 } else {
133 }
134 my_points[2].set_error(1.0);
135
136
137 if (my_points[1].
x2() > my_points[0].
x2() && my_points[2].
x2() < my_points[0].
x2()) {
138 my_points[1].set_x1(my_points[2].
x1());
139 my_points[1].set_x2(my_points[2].
x2());
140
142
145 sigma = mdt_hit->sigmaDriftRadius();
146 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
147 }
148 if (!segment_fitter->
fit(seg, r_selection)) {
149 failed = true;
150 return 0.0;
151 }
152 if (curved) {
154 } else {
156 }
157 my_points[2].set_error(1.0);
158 }
159
161 if (my_points[1].
x1() < 0.0) {
162 for (
unsigned int l = 3; my_points[
l - 1].x2() < my_points[l - 2].
x2() && std::abs(my_points[l - 1].
x1()) < 200.0;
l++) {
163 SamplePoint new_point;
165
167 time = mdt_hit->driftTime() + new_point.
x1();
168 sigma = mdt_hit->sigmaDriftRadius();
169 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
170 }
171
172 if (!segment_fitter->
fit(seg, r_selection)) {
173 failed = true;
174 return 0.0;
175 }
176 if (curved) {
178 } else {
180 }
182 my_points.push_back(new_point);
183 }
184 }
185
187 if (my_points[2].
x1() > 0.0) {
188 for (
unsigned int l = 3; my_points[
l - 1].x2() <= my_points[l - 2].
x2() && std::abs(my_points[l - 1].
x1()) < 200.0;
l++) {
189 SamplePoint new_point;
192 time = mdt_hit->driftTime() + new_point.
x1();
193 sigma = mdt_hit->sigmaDriftRadius();
194 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
195 }
196 if (!segment_fitter->
fit(seg, r_selection)) {
197 failed = true;
198 return 0.0;
199 }
200 if (curved) {
202 } else {
204 }
206 my_points.push_back(new_point);
207 }
208 }
210
212
213 fitter.fit_parameters(my_points, my_points.size() - 2, my_points.size(), pol);
217 error = std::sqrt(1.0 / denom);
218 if (std::isnan(error)) {
219 failed = true;
220 return 0.0;
221 }
222
223 double direction{-0.5}, min_chi2{DBL_MAX};
224 double best_t0 = delta_t0_opt;
225 double current_t0 = delta_t0_opt;
226 std::vector<double>
t0s,
chi2, mchi2;
227 while (1) {
229 time = mdt_hit->driftTime() + current_t0;
230 sigma = mdt_hit->sigmaDriftRadius();
231 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
232 }
233 if (!segment_fitter->
fit(seg, r_selection)) {
234 failed = true;
235 return 0.0;
236 }
237 double chisq(0.0);
238 if (curved) {
240 } else {
242 }
243
244 if (chisq < min_chi2) {
245 min_chi2 = chisq;
246 best_t0 = current_t0;
247 } else {
248 if (direction > 0) break;
250 current_t0 = delta_t0_opt;
251 }
253 t0s.push_back(current_t0);
254 chi2.push_back(chisq);
255 mchi2.push_back(min_chi2);
256 if (
t0s.size() > 100) {
257 failed = true;
258 return 0.0;
259 }
260 }
261
263
265 delta_t0_opt = best_t0;
266 failed = false;
267 if (!overwrite) { return delta_t0_opt; }
268 bool segment_t0_was_applied{false};
270 segment_t0_was_applied |= mdt_hit->segmentT0Applied();
271 time = mdt_hit->driftTime() + delta_t0_opt;
272 sigma = mdt_hit->sigmaDriftRadius();
273 if (sigma > 10.0 && segment->
mdtHOT()[k]->driftTime() < 50.0)
sigma = 0.3;
274 mdt_hit->setDriftTime(time);
275 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
276 mdt_hit->setSegmentT0Applied(true);
277 }
278 if (segment_t0_was_applied) {
280 } else {
282 }
283
285 if (segment_fitter->
fit(*segment, std::move(r_selection)) == 0.0) {
286 failed = true;
287 return 0.0;
288 }
289
290 if (segment->
chi2() > 100.0) {
291 failed = true;
292 return 0.0;
293 }
294
295 return delta_t0_opt;
296}
double chi2PerDegreesOfFreedom() const
Return chi2 / number of TrackHits - 3.
void SetRefineSegmentFlag(const bool flag)
number of hits selected for track
std::vector< unsigned int > HitSelection
virtual bool fit(MuonCalibSegment &seg) const =0
fit using all hits
virtual double radius(double t) const =0
returns drift radius for a given time
double chi2PerDegreesOfFreedom() const
Return chi2 / number of TrackHits - 2.
unsigned int mdtHitsOnTrack() const
retrieve the number of MdtCalibHitBase s assigned to this segment
std::shared_ptr< MdtCalibHitBase > MdtHitPtr
typedef for a collection of MdtCalibHitBase s
double chi2() const
retrieve chi2
const MdtHitVec & mdtHOT() const
retrieve the full set of MdtCalibHitBase s assigned to this segment
double fittedT0() const
retrieve fitted T0, return -99999 if no fit was performed
void setFittedT0(double t0)
sets t0 field
void set_error(const double merror)
void set_x2(const double mx2)
set the error of the x2 coordinate sample point to merror
void set_x1(const double mx1)
set the x2 coordinate of the sample point to mx2
double x1() const
< get the x1 coordinate of the sample point
double chi2(TH1 *h0, TH1 *h1)
time(flags, cells_name, *args, **kw)
const ShapeFitter * fitter
l
Printing final latex table to .tex output file.
const Amg::Vector3D & direction() const
Method to retrieve the direction at the Intersection.