ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalTimeFitter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include <sstream>
9#include <string>
10#include <array>
11namespace {
12 constexpr double tdc_bc_conv = IMdtCalibrationTool::tdcBinSize;
13 constexpr double max_drift_time_30mm = 750;
14} // namespace
15
16namespace MuonCalib {
17
19 double timeShift = 0;
20 float tdcmin = FLT_MAX;
21 double timeoffset = 0.;
22 int stepf{0}, stepl{0}, stepr{0}, dtt{0}, dttbuono{0};
23 std::array<int, 13> stepff{};
24 double chi2r{0.}, chi2l{0.};
25 double chi2min = FLT_MAX;
26 double bestchi2 = FLT_MAX;
27
28 stepff[0] = 512;
29 stepff[1] = 256;
30 stepff[2] = 128;
31 stepff[3] = 64;
32 stepff[4] = 32;
33 stepff[5] = 16;
34 stepff[6] = 8;
35 stepff[7] = 4;
36 stepff[8] = 2;
37 stepff[9] = 1;
38 stepff[10] = 1;
39 stepff[11] = 1;
40 stepff[12] = 1;
41
42 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg->mdtHOT()) {
43 if (mdt_hit->tdcCount() < tdcmin) tdcmin = mdt_hit->tdcCount();
44 }
45
46 stepl = 512;
47 stepr = 512;
48 stepf = 512;
49 for (int jj = 0; jj < 11; jj++) {
50 bool outofrange{false};
51 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg->mdtHOT()) {
52 double newtime = (mdt_hit->tdcCount() - tdcmin + stepl) * tdc_bc_conv;
54 if (newtime < 0. || newtime > max_drift_time_30mm) { outofrange = true; }
55 mdt_hit->setDriftTime(newtime);
56 double r = m_rtRel->radius(newtime);
57 double dr = getDefaultResolution(r); // get H8 resolution
58 mdt_hit->setDriftRadius(r, dr);
59 }
60 if (!outofrange) {
61 m_fitter->fit(*seg);
62 chi2l = seg->chi2();
63 } else {
64 chi2l = FLT_MAX;
65 }
66 outofrange = false;
67 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg->mdtHOT()) {
68 double newtime = (mdt_hit->tdcCount() - tdcmin + stepr) * tdc_bc_conv;
69
70 if (newtime < 0. || newtime > max_drift_time_30mm) { outofrange = true; }
71 mdt_hit->setDriftTime(newtime);
72 double r = m_rtRel->radius(newtime);
73 double dr = getDefaultResolution(r); // get H8 resolution
74 mdt_hit->setDriftRadius(r, dr);
75 }
76 if (!outofrange) {
77 m_fitter->fit(*seg);
78 chi2r = seg->chi2();
79 } else {
80 chi2r = FLT_MAX;
81 }
82 chi2min = chi2l;
83 stepf = stepl;
84 dtt = stepl;
85 if (chi2r < chi2l) {
86 chi2min = chi2r;
87 stepf = stepr;
88 dtt = stepr;
89 }
90 if (chi2min < bestchi2) {
91 bestchi2 = chi2min;
92 dttbuono = dtt;
93 stepl = stepf - stepff[jj];
94 stepr = stepff[jj] + stepf;
95 if (stepl < 0) stepl = 0;
96 if (stepr < 0) stepr = 0;
97 } else {
98 stepl = stepf - stepff[jj];
99 stepr = stepff[jj] + stepf;
100 if (stepl < 0) stepl = 0;
101 if (stepr < 0) stepr = 0;
102 }
103 timeoffset = dttbuono;
104 }
105
106 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg->mdtHOT()) {
107 double newtime = (mdt_hit->tdcCount() - tdcmin + timeoffset) * tdc_bc_conv;
108 mdt_hit->setDriftTime(newtime);
109 double r = m_rtRel->radius(newtime);
110 double dr = getDefaultResolution(r); // get H8 resolution
111 mdt_hit->setDriftRadius(r, dr);
112 }
113 m_fitter->fit(*seg);
114
115 timeShift = -(timeoffset - tdcmin) * tdc_bc_conv;
116 return timeShift;
117 }
118
120 double timeShift = 999.;
121 for (const MuonCalibSegment::MdtHitPtr& mdt_hit : seg->mdtHOT()) {
122 mdt_hit->setDriftTime(400.);
123 double t = mdt_hit->driftTime();
124 double r = m_rtRel->radius(t);
125 double dr = mdt_hit->sigmaDriftRadius();
126 mdt_hit->setDriftRadius(r, dr);
127
128 timeShift = t;
129 }
130
131 return timeShift;
132 }
133
134 std::unique_ptr<IRtRelation> GlobalTimeFitter::getDefaultRtRelation() {
135 static const MuonCalib::CalibFunc::ParVec rtPars{
136
137 -50., // t_Start
138 8., // t_binSize
139
140 0.2, // r(-50)
141 0.2, // r(-50+8)
142 0.2, // ...
143 0.25, 0.294403, 0.311703, 0.485873, 0.804235, 1.19624, 1.5562, 1.91466, 2.3147, 2.66996, 3.05436, 3.40371, 3.80574,
144 4.13506, 4.45473, 4.77338, 5.05294, 5.33755, 5.58459, 5.8718, 6.09389, 6.37129, 6.56824, 6.73359, 6.96923, 7.16944,
145 7.38872, 7.55627, 7.73885, 7.86403, 8.07223, 8.26818, 8.39531, 8.54069, 8.69377, 8.86487, 9.01724, 9.16516, 9.24791,
146 9.45596, 9.56237, 9.69553, 9.80647, 9.9432, 10.039, 10.207, 10.2884, 10.3977, 10.6045, 10.6181, 10.7883, 10.9057,
147 10.9908, 11.1615, 11.2359, 11.3409, 11.4451, 11.5412, 11.6896, 11.7487, 11.8853, 11.9571, 12.0381, 12.1739, 12.2601,
148 12.3892, 12.4406, 12.5809, 12.6297, 12.7495, 12.8314, 12.9463, 13.0487, 13.1337, 13.2417, 13.2706, 13.3917, 13.5107,
149 13.60, 13.69, 13.71, 13.8088, 13.8577, 14.0212, 14.0671, 14.1225, 14.2112, 14.3113, 14.3747, 14.3531, 14.4799,
150 14.458, 14.516, 14.8312, 14.85, 14.86, 14.87
151
152 };
153 return std::make_unique<RtRelationLookUp>(rtPars);
154 }
155
156} // namespace MuonCalib
static constexpr double tdcBinSize
Conversion to go from tdc counts -> drift Time.
std::vector< double > ParVec
Definition CalibFunc.h:35
const IRtRelation * m_rtRel
double GTFit(MuonCalibSegment *seg)
double getDefaultResolution(double r)
const IMdtSegmentFitter * m_fitter
double GTFit2(MuonCalibSegment *seg)
static std::unique_ptr< IRtRelation > getDefaultRtRelation()
A MuonCalibSegment is a reconstructed three dimensional track segment in the MuonSpectrometer.
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
int r
Definition globals.cxx:22
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.