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
30 {
32
34
36
38
40
41 double delta_t0_opt;
42 MuonCalibSegment seg(*segment);
43 NtupleStationId
id((seg.mdtHOT())[0]->identify());
46 BaseFunctionFitter
fitter(3);
47 SimplePolynomial pol;
48 std::vector<SamplePoint> my_points(3);
49 IMdtPatRecFitter* segment_fitter = nullptr;
50 if (curved) {
52 } else {
54 }
57
59
61
62
66 time = mdt_hit->driftTime();
67 sigma = mdt_hit->sigmaDriftRadius();
68 if (sigma > 10.0 && std::abs(mdt_hit->driftRadius()) > 14.0) r_selection[
k] = 1;
69 if (sigma > 10.0 && mdt_hit->driftTime() < 50.0)
sigma = 0.3;
70 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
72 }
73 MTStraightLine straight_track;
74 CurvedLine curved_track;
75 if (curved) {
76 if (!
m_cfitter->fit(seg, r_selection, curved_track)) {
77 failed = true;
78 return 0.0;
79 }
80 } else {
81 if (!
m_qfitter->fitCallByReference(seg, r_selection, straight_track)) {
82 failed = true;
83 return 0.0;
84 }
85 }
86
87 my_points[0].set_x1(0.0);
88 if (curved) {
90 } else {
92 }
93 my_points[0].set_error(1.0);
94
96
99 sigma = mdt_hit->sigmaDriftRadius();
100 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
101 }
102 if (!segment_fitter->
fit(seg, r_selection)) {
103 failed = true;
104 return 0.0;
105 }
106
108 if (curved) {
110 } else {
112 }
113 my_points[1].set_error(1.0);
114
115
117 if (my_points[1].
x2() > my_points[0].
x2()) {
120 } else {
123 }
124 sigma = mdt_hit->sigmaDriftRadius();
125 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
126 }
127 if (!segment_fitter->
fit(seg, r_selection)) {
128 failed = true;
129 return 0.0;
130 }
131 if (curved) {
133 } else {
135 }
136 my_points[2].set_error(1.0);
137
138
139 if (my_points[1].
x2() > my_points[0].
x2() && my_points[2].
x2() < my_points[0].
x2()) {
140 my_points[1].set_x1(my_points[2].
x1());
141 my_points[1].set_x2(my_points[2].
x2());
142
144
147 sigma = mdt_hit->sigmaDriftRadius();
148 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
149 }
150 if (!segment_fitter->
fit(seg, r_selection)) {
151 failed = true;
152 return 0.0;
153 }
154 if (curved) {
156 } else {
158 }
159 my_points[2].set_error(1.0);
160 }
161
163 if (my_points[1].
x1() < 0.0) {
164 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++) {
165 SamplePoint new_point;
167
169 time = mdt_hit->driftTime() + new_point.
x1();
170 sigma = mdt_hit->sigmaDriftRadius();
171 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
172 }
173
174 if (!segment_fitter->
fit(seg, r_selection)) {
175 failed = true;
176 return 0.0;
177 }
178 if (curved) {
180 } else {
182 }
184 my_points.push_back(new_point);
185 }
186 }
187
189 if (my_points[2].
x1() > 0.0) {
190 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++) {
191 SamplePoint new_point;
194 time = mdt_hit->driftTime() + new_point.
x1();
195 sigma = mdt_hit->sigmaDriftRadius();
196 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
197 }
198 if (!segment_fitter->
fit(seg, r_selection)) {
199 failed = true;
200 return 0.0;
201 }
202 if (curved) {
204 } else {
206 }
208 my_points.push_back(new_point);
209 }
210 }
212
214
215 fitter.fit_parameters(my_points, my_points.size() - 2, my_points.size(), pol);
219 error = std::sqrt(1.0 / denom);
220 if (std::isnan(error)) {
221 failed = true;
222 return 0.0;
223 }
224
225 double direction{-0.5}, min_chi2{DBL_MAX};
226 double best_t0 = delta_t0_opt;
227 double current_t0 = delta_t0_opt;
228 std::vector<double>
t0s,
chi2, mchi2;
229 while (1) {
231 time = mdt_hit->driftTime() + current_t0;
232 sigma = mdt_hit->sigmaDriftRadius();
233 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
234 }
235 if (!segment_fitter->
fit(seg, r_selection)) {
236 failed = true;
237 return 0.0;
238 }
239 double chisq(0.0);
240 if (curved) {
242 } else {
244 }
245
246 if (chisq < min_chi2) {
247 min_chi2 = chisq;
248 best_t0 = current_t0;
249 } else {
250 if (direction > 0) break;
251 direction = 0.5;
252 current_t0 = delta_t0_opt;
253 }
254 current_t0 += direction;
255 t0s.push_back(current_t0);
256 chi2.push_back(chisq);
257 mchi2.push_back(min_chi2);
258 if (
t0s.size() > 100) {
259 failed = true;
260 return 0.0;
261 }
262 }
263
265
267 delta_t0_opt = best_t0;
268 failed = false;
269 if (!overwrite) { return delta_t0_opt; }
270 bool segment_t0_was_applied{false};
272 segment_t0_was_applied |= mdt_hit->segmentT0Applied();
273 time = mdt_hit->driftTime() + delta_t0_opt;
274 sigma = mdt_hit->sigmaDriftRadius();
275 if (sigma > 10.0 && segment->
mdtHOT()[k]->driftTime() < 50.0)
sigma = 0.3;
276 mdt_hit->setDriftTime(time);
277 mdt_hit->setDriftRadius(rt->
radius(time), sigma);
278 mdt_hit->setSegmentT0Applied(true);
279 }
280 if (segment_t0_was_applied) {
282 } else {
284 }
285
287 if (segment_fitter->
fit(*segment, r_selection) == 0.0) {
288 failed = true;
289 return 0.0;
290 }
291
292 if (segment->
chi2() > 100.0) {
293 failed = true;
294 return 0.0;
295 }
296
297 return delta_t0_opt;
298}
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.