ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCalib::T0Refinement Class Reference

#include <T0Refinement.h>

Collaboration diagram for MuonCalib::T0Refinement:

Public Member Functions

 T0Refinement ()
 Default constructor.
 ~T0Refinement ()=default
 Destructor.
double getDeltaT0 (MuonCalibSegment *segment, const IRtRelation *rt, bool overwrite, double &error, bool &failed, bool curved=false)
 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
void SetDeltaT0 (const double dt0)
 Set the scan point distance.
void setTimeOut (const double time_out)
 set the time-out for pattern finding to time_out (s)
void setRoadWidth (const double road_width)
 set the road with to road_width (mm) (default: 1mm)

Private Attributes

std::unique_ptr< StraightPatRec > m_qfitter
std::unique_ptr< CurvedPatRec > m_cfitter
double m_delta_t0
double m_time_out

Detailed Description

Definition at line 33 of file T0Refinement.h.

Constructor & Destructor Documentation

◆ T0Refinement()

T0Refinement::T0Refinement ( )

Default constructor.

Definition at line 14 of file T0Refinement.cxx.

15 : m_qfitter (std::make_unique<StraightPatRec>()),
16 m_cfitter (std::make_unique<CurvedPatRec>()),
17 m_delta_t0 (30.0),
18 m_time_out (2.0)
19{
20 m_qfitter->setRoadWidth(1.0); // 1.0 mm road width
21 m_qfitter->switchOnRefit();
22 m_qfitter->setTimeOut(m_time_out);
23 m_cfitter->setRoadWidth(1.0); // 1.0 mm road width
24 m_cfitter->setTimeOut(m_time_out);
25}
std::unique_ptr< StraightPatRec > m_qfitter
std::unique_ptr< CurvedPatRec > m_cfitter

◆ ~T0Refinement()

MuonCalib::T0Refinement::~T0Refinement ( )
default

Destructor.

Member Function Documentation

◆ getDeltaT0()

double T0Refinement::getDeltaT0 ( MuonCalibSegment * segment,
const IRtRelation * rt,
bool overwrite,
double & error,
bool & failed,
bool curved = false )

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

Definition at line 27 of file T0Refinement.cxx.

28 {
30 // CHECK IF THERE ARE ENOUGH HITS ON THE SEGMENT //
32
33 if (segment->mdtHitsOnTrack() < 3) { return 0.0; }
34
36 // VARIABLES //
38
39 double delta_t0_opt; // the best t0 correction
40 MuonCalibSegment seg(*segment); // segment used internally
41 NtupleStationId id((seg.mdtHOT())[0]->identify()); // station identifier
42 double time; // time and radius of a hit
43 double sigma; // sigma(r)
44 BaseFunctionFitter fitter(3);
45 SimplePolynomial pol; // polynomial base functions x^k
46 std::vector<SamplePoint> my_points(3);
47 IMdtPatRecFitter* segment_fitter = nullptr;
48 if (curved) {
49 segment_fitter = m_cfitter.get();
50 } else {
51 segment_fitter = m_qfitter.get();
52 }
53 segment_fitter->SetRefineSegmentFlag(false);
54 IMdtSegmentFitter::HitSelection r_selection(seg.mdtHitsOnTrack(), 0);
55
57 // DETERMINE THE CHI^2 VALUES FOR THREE DIFFERENT t0s //
59
60 // original drift times //
61 m_qfitter->setFixSelection(false);
62 unsigned int k = 0;
63 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
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);
69 ++k;
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) {
87 my_points[0].set_x2(curved_track.chi2PerDegreesOfFreedom());
88 } else {
89 my_points[0].set_x2(straight_track.chi2PerDegreesOfFreedom());
90 }
91 my_points[0].set_error(1.0);
92
93 m_qfitter->setFixSelection(true);
94 // shift drift times by +m_delta_t0 and refit //
95 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
96 time = mdt_hit->driftTime() + m_delta_t0;
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
105 my_points[1].set_x1(m_delta_t0);
106 if (curved) {
107 my_points[1].set_x2(curved_track.chi2PerDegreesOfFreedom());
108 } else {
109 my_points[1].set_x2(straight_track.chi2PerDegreesOfFreedom());
110 }
111 my_points[1].set_error(1.0);
112
113 // shift drift times by -m_delta_t0 and refit //
114 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
115 if (my_points[1].x2() > my_points[0].x2()) {
116 time = mdt_hit->driftTime() - m_delta_t0;
117 my_points[2].set_x1(-m_delta_t0);
118 } else {
119 time = mdt_hit->driftTime() + 2.0 * m_delta_t0;
120 my_points[2].set_x1(2.0 * m_delta_t0);
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) {
130 my_points[2].set_x2(curved_track.chi2PerDegreesOfFreedom());
131 } else {
132 my_points[2].set_x2(straight_track.chi2PerDegreesOfFreedom());
133 }
134 my_points[2].set_error(1.0);
135
136 // negative branch of T0 shifts
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
141 my_points[2].set_x1(-2.0 * m_delta_t0);
142
143 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
144 time = mdt_hit->driftTime() - 2.0 * m_delta_t0;
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) {
153 my_points[2].set_x2(curved_track.chi2PerDegreesOfFreedom());
154 } else {
155 my_points[2].set_x2(straight_track.chi2PerDegreesOfFreedom());
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;
164 new_point.set_x1(my_points[l - 1].x1() - m_delta_t0);
165
166 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
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) {
177 new_point.set_x2(curved_track.chi2PerDegreesOfFreedom());
178 } else {
179 new_point.set_x2(straight_track.chi2PerDegreesOfFreedom());
180 }
181 new_point.set_error(1.0);
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;
190 new_point.set_x1(my_points[l - 1].x1() + m_delta_t0);
191 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
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) {
201 new_point.set_x2(curved_track.chi2PerDegreesOfFreedom());
202 } else {
203 new_point.set_x2(straight_track.chi2PerDegreesOfFreedom());
204 }
205 new_point.set_error(1.0);
206 my_points.push_back(new_point);
207 }
208 }
210 // CALCULATE THE BEST t0 CORRECTION //
212
213 fitter.fit_parameters(my_points, my_points.size() - 2, my_points.size(), pol);
214 double nom(fitter.coefficients()[1]);
215 double denom(fitter.coefficients()[2]);
216 delta_t0_opt = -0.5 * nom / denom;
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) {
228 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
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) {
239 chisq = curved_track.chi2PerDegreesOfFreedom();
240 } else {
241 chisq = straight_track.chi2PerDegreesOfFreedom();
242 }
243
244 if (chisq < min_chi2) {
245 min_chi2 = chisq;
246 best_t0 = current_t0;
247 } else {
248 if (direction > 0) break;
249 direction = 0.5;
250 current_t0 = delta_t0_opt;
251 }
252 current_t0 += direction;
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 // OVERWRITE THE SEGMENT, IF REQUESTED //
265 delta_t0_opt = best_t0;
266 failed = false;
267 if (!overwrite) { return delta_t0_opt; }
268 bool segment_t0_was_applied{false};
269 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg.mdtHOT()) {
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) {
279 segment->setFittedT0(segment->fittedT0() - delta_t0_opt);
280 } else {
281 segment->setFittedT0(-delta_t0_opt);
282 }
283
284 segment_fitter->SetRefineSegmentFlag(true);
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)
Definition SamplePoint.h:62
void set_x2(const double mx2)
set the error of the x2 coordinate sample point to merror
Definition SamplePoint.h:60
void set_x1(const double mx1)
set the x2 coordinate of the sample point to mx2
Definition SamplePoint.h:58
double x1() const
< get the x1 coordinate of the sample point
Definition SamplePoint.h:42
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.

◆ SetDeltaT0()

void MuonCalib::T0Refinement::SetDeltaT0 ( const double dt0)
inline

Set the scan point distance.

Definition at line 60 of file T0Refinement.h.

◆ setRoadWidth()

void T0Refinement::setRoadWidth ( const double road_width)

set the road with to road_width (mm) (default: 1mm)

Definition at line 301 of file T0Refinement.cxx.

301 {
302 m_qfitter->setRoadWidth(road_width);
303 m_cfitter->setRoadWidth(road_width);
304
305 return;
306}

◆ setTimeOut()

void T0Refinement::setTimeOut ( const double time_out)

set the time-out for pattern finding to time_out (s)

Definition at line 297 of file T0Refinement.cxx.

297 {
298 m_time_out = time_out;
299 return;
300}

Member Data Documentation

◆ m_cfitter

std::unique_ptr<CurvedPatRec> MuonCalib::T0Refinement::m_cfitter
private

Definition at line 71 of file T0Refinement.h.

◆ m_delta_t0

double MuonCalib::T0Refinement::m_delta_t0
private

Definition at line 72 of file T0Refinement.h.

◆ m_qfitter

std::unique_ptr<StraightPatRec> MuonCalib::T0Refinement::m_qfitter
private

Definition at line 70 of file T0Refinement.h.

◆ m_time_out

double MuonCalib::T0Refinement::m_time_out
private

Definition at line 73 of file T0Refinement.h.


The documentation for this class was generated from the following files: