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

Interface to the straight line fitter for drift circles used by Calib. More...

#include <MuCCaFitter.h>

Inheritance diagram for MuonCalib::MuCCaFitter:
Collaboration diagram for MuonCalib::MuCCaFitter:

Public Types

typedef std::vector< unsigned int > HitSelection

Public Member Functions

bool fit (MuonCalibSegment &seg) const
 fit using all hits
bool fit (MuonCalibSegment &seg, HitSelection selection) const
 fit subset of the hits.
void printLevel (int level)
 set print level

Private Member Functions

double getY (const Amg::Vector3D &p) const
 these methods are needed to change the reference frame between the local one of the hit and one used by the fitter: apparently the 2 frames are the same ... TO BE CHECKED!
double getX (const Amg::Vector3D &p) const
double getZ (const Amg::Vector3D &p) const
Amg::Vector3D getVec (double x, double y, double z) const

Private Attributes

bool m_debug

Detailed Description

Interface to the straight line fitter for drift circles used by Calib.

Author
Fabri.nosp@m.zio..nosp@m.Petru.nosp@m.cci@.nosp@m.cern..nosp@m.ch

Definition at line 29 of file MuCCaFitter.h.

Member Typedef Documentation

◆ HitSelection

typedef std::vector<unsigned int> MuonCalib::IMdtSegmentFitter::HitSelection
inherited

Definition at line 32 of file IMdtSegmentFitter.h.

Member Function Documentation

◆ fit() [1/2]

bool MuonCalib::MuCCaFitter::fit ( MuonCalibSegment & seg) const
virtual

fit using all hits

Implements MuonCalib::IMdtSegmentFitter.

Definition at line 19 of file MuCCaFitter.cxx.

19 {
20 // select all hits
21 HitSelection selection(seg.mdtHitsOnTrack(), 0);
22 // call fit function
23 return fit(seg, std::move(selection));
24 }
std::vector< unsigned int > HitSelection
bool fit(MuonCalibSegment &seg) const
fit using all hits
const std::string selection

◆ fit() [2/2]

bool MuonCalib::MuCCaFitter::fit ( MuonCalibSegment & seg,
HitSelection selection ) const
virtual

fit subset of the hits.

If the HitSelection vector contains a 0 for a given hit the hit is used else the hit is not included in the fit. The size of the HitSelection vector should be equal to the number of hits on track else no fit is performed.

Implements MuonCalib::IMdtSegmentFitter.

Definition at line 26 of file MuCCaFitter.cxx.

26 {
27 MsgStream log(Athena::getMessageSvc(), "MuCCaFitter");
28 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "fit() New seg:" << endmsg;
29
30 int N = seg.mdtHitsOnTrack();
31
32 if (N < 2) { return false; }
33
34 if ((int)selection.size() != N) {
35 selection.clear();
36 selection.assign(N, 0);
37 } else {
38 int used(0);
39 for (int i = 0; i < N; ++i) {
40 if (selection[i] == 0) ++used;
41 }
42 if (used < 2) {
43 log << MSG::WARNING << "fit() TO FEW HITS SELECTED" << endmsg;
44 return false;
45 }
46 }
47
48 const Amg::Vector3D& pos = seg.position();
49
50 double S(0), Sy(0), Sz(0), Zc{0}, Yc{0};
51 std::vector<double> y(N), x(N), z(N);
52 std::vector<double> r(N), sr(N), w(N), rw(N);
53 int ii{0}, jj{0};
54 {
55 for (const MuonCalibSegment::MdtHitPtr& hit : seg.mdtHOT()) {
56 const MdtCalibHitBase& h = *hit;
57 y[ii] = getY(h.localPosition());
58 z[ii] = getZ(h.localPosition());
59 r[ii] = std::abs(h.driftRadius());
60
61 if (h.sigma2DriftRadius() > 0) {
62 w[ii] = 1. / (h.sigma2DriftRadius());
63 sr[ii] = std::sqrt(h.sigma2DriftRadius());
64 } else {
65 w[ii] = 0.;
66 sr[ii] = 0.;
67 }
68 if (log.level() <= MSG::DEBUG)
69 log << MSG::DEBUG << "fit() MuCCaFitter: (" << x[ii] << "," << y[ii] << ") R = " << r[ii] << " W " << w[ii] << endmsg;
70 rw[ii] = r[ii] * w[ii];
71 if (selection[jj]) {
72 ++jj;
73 continue;
74 }
75 S += w[ii];
76 Sz += w[ii] * z[ii];
77 Sy += w[ii] * y[ii];
78 ++ii;
79 ++jj;
80 }
81 }
82 if (S == 0)[[unlikely]]{
83 log << MSG::ERROR <<"Divisor S is zero."<<endmsg;
84 return false;
85 }
86 Zc = Sz / S;
87 Yc = Sy / S;
88
89 std::unique_ptr<MuCCaFitterImplementation> Fitter = std::make_unique<MuCCaFitterImplementation>();
90 if (log.level() <= MSG::DEBUG) {
91 for (int i = 0; i != ii; i++) {
92 log << MSG::DEBUG << "fit() MuCCaFitter hits passed to computepam Z=" << x[i] << " phi=" << y[i] << " zzz=" << z[i]
93 << " drift=" << r[i] << " error=" << w[i] << endmsg;
94 }
95 }
96 Fitter->Computeparam3(ii, z, y, r, sr);
97 if (log.level() <= MSG::DEBUG) {
98 log << MSG::DEBUG << "fit() MuCCaFitter computed track a=" << Fitter->get_a() << " da= " << Fitter->get_da()
99 << " b= " << Fitter->get_b() << " db= " << Fitter->get_db() << " corrab= " << Fitter->get_corrab()
100 << " chi2f= " << Fitter->get_chi2f() << endmsg;
101 }
102
103 double afit = Fitter->get_a();
104 double chi2f = Fitter->get_chi2f();
105
106 std::vector<double> dist(N), ddist(N);
107 double R, dis;
108 double theta = std::atan(afit);
109 if (theta < 0.) theta = M_PI + theta;
110 double sinus = std::sin(theta);
111 double cosin = std::cos(theta);
112 double d = -(getZ(pos) - Zc) * sinus + (getY(pos) - Yc) * cosin;
113 if (log.level() <= MSG::DEBUG) {
114 log << MSG::DEBUG << "fit() MuCCaFitter>>> theta= " << theta << " sinus= " << sinus << " cosin= " << cosin << endmsg;
115 log << MSG::DEBUG << "fit() MuCCaFitter>>> getZ( pos )= " << getZ(pos) << " getY( pos )= " << getY(pos) << " Zc= " << Zc
116 << " Yc= " << Yc << endmsg;
117 }
118 double Syy(0), Szy(0), Syyzz(0), Att(0);
119 R = 0;
120 for (int i = 0; i < N; ++i) {
121 if (selection[i]) continue;
122 Syy += (y[i] - Yc) * (y[i] - Yc) * w[i];
123 Szy += (y[i] - Yc) * (z[i] - Zc) * w[i];
124 Syyzz += ((y[i] - Yc) - (z[i] - Zc)) * ((y[i] - Yc) + (z[i] - Zc)) * w[i];
125 dis = (y[i] - Yc) * cosin - (z[i] - Zc) * sinus;
126 if (dis > d) {
127 R -= rw[i];
128 } else {
129 R += rw[i];
130 }
131 }
132 Att = Syy + cosin * (2 * sinus * Szy - cosin * Syyzz);
133 d = R / S;
134 if (log.level() <= MSG::DEBUG){
135 log << MSG::DEBUG << "fit() MuCCaFitter>>> d= " << d << " R= " << R << " S= " << S << " Att= " << Att << endmsg;
136 }
137 if (Att == 0.)[[unlikely]]{
138 log << MSG::ERROR << "Divisor Att is zero."<< endmsg;
139 return false;
140 }
141 for (int i = 0; i < N; ++i) {
142 if (selection[i]) continue;
143 dist[i] = cosin * (y[i] - Yc) - sinus * (z[i] - Zc) - d;
144 double dth = -(sinus * (y[i] - Yc) + cosin * (z[i] - Zc)) * (std::sqrt(1. / Att));
145 ddist[i] = std::sqrt(dth * dth + (1. / S));
146 }
147 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "fit() Transforming back to real world" << endmsg;
148 Amg::Vector3D ndir = getVec(0., sinus, cosin);
149 Amg::Vector3D npos = getVec(0., Yc + cosin * d, Zc - sinus * d);
150
151 if (log.level() <= MSG::DEBUG)
152 log << MSG::DEBUG << "fit() New line: position " << npos << " direction " << ndir << " chi2f " << chi2f << endmsg;
153
154 seg.set(chi2f / (N - 2), npos, ndir);
155
156 int i{0};
157 for (const MuonCalibSegment::MdtHitPtr& hit_ptr : seg.mdtHOT()) {
158 hit_ptr->setDistanceToTrack(dist[i], ddist[i]);
159 ++i;
160 }
161
162 if (log.level() <= MSG::DEBUG) log << MSG::DEBUG << "fit() fit done" << endmsg;
163 return true;
164 }
#define M_PI
Scalar theta() const
theta method
#define endmsg
bool hit(const Container &ids, int pdgId)
#define y
#define x
#define z
Amg::Vector3D getVec(double x, double y, double z) const
Definition MuCCaFitter.h:59
double getZ(const Amg::Vector3D &p) const
Definition MuCCaFitter.h:58
double getY(const Amg::Vector3D &p) const
these methods are needed to change the reference frame between the local one of the hit and one used ...
Definition MuCCaFitter.h:56
std::shared_ptr< MdtCalibHitBase > MdtHitPtr
typedef for a collection of MdtCalibHitBase s
int r
Definition globals.cxx:22
Eigen::Matrix< double, 3, 1 > Vector3D
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
IMessageSvc * getMessageSvc(bool quiet=false)
@ Zc
Z -> cc, nC = 1 (partial containment).
constexpr std::size_t N
#define unlikely(x)

◆ getVec()

Amg::Vector3D MuonCalib::MuCCaFitter::getVec ( double x,
double y,
double z ) const
inlineprivate

Definition at line 59 of file MuCCaFitter.h.

59{ return Amg::Vector3D(x, z, y); }

◆ getX()

double MuonCalib::MuCCaFitter::getX ( const Amg::Vector3D & p) const
inlineprivate

Definition at line 57 of file MuCCaFitter.h.

◆ getY()

double MuonCalib::MuCCaFitter::getY ( const Amg::Vector3D & p) const
inlineprivate

these methods are needed to change the reference frame between the local one of the hit and one used by the fitter: apparently the 2 frames are the same ... TO BE CHECKED!

!!

Definition at line 56 of file MuCCaFitter.h.

56{ return p.z(); }

◆ getZ()

double MuonCalib::MuCCaFitter::getZ ( const Amg::Vector3D & p) const
inlineprivate

Definition at line 58 of file MuCCaFitter.h.

58{ return p.y(); }

◆ printLevel()

void MuonCalib::MuCCaFitter::printLevel ( int level)
virtual

set print level

Implements MuonCalib::IMdtSegmentFitter.

Definition at line 15 of file MuCCaFitter.cxx.

15 {
16 if (level > 0) m_debug = true;
17 }

Member Data Documentation

◆ m_debug

bool MuonCalib::MuCCaFitter::m_debug
private

Definition at line 46 of file MuCCaFitter.h.


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