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

#include <CurvedPatRec.h>

Inheritance diagram for MuonCalib::CurvedPatRec:
Collaboration diagram for MuonCalib::CurvedPatRec:

Public Types

using MdtHitVec = MuonCalibSegment::MdtHitVec
using MdtHitPtr = MuonCalibSegment::MdtHitPtr
typedef std::vector< unsigned int > HitSelection

Public Member Functions

 CurvedPatRec ()
 Default constructor: road width of 0.5 mm is used.
 CurvedPatRec (const double road_width)
 Constructor: user defined road width [mm] for pattern recognition.
double roadWidth () const
 get the road width used in the pattern recognition [mm]
void setRoadWidth (const double r_road_width)
 set the road width [mm] for the pattern recognition = r_road_width
void setTimeOut (const double time_out)
 set the time-out for the track finding to time_out (in seconds)
bool fit (MuonCalibSegment &r_segment) const
 reconstruction of the track using all hits in the segment "r_segment", returns true in case of success; the algorithm overwrites the track radii, the track position, track direction, and chi^2 per degrees of freedom; warning: the errors of the track radii are only approximate
bool fit (MuonCalibSegment &r_segment, HitSelection r_selection) const
 reconstruction of the track using only those hits in r_segment for which the r_selection[.
bool fit (MuonCalibSegment &r_segment, HitSelection r_selection, CurvedLine &curved_track) const
void printLevel (int)
void SetRefineSegmentFlag (const bool flag)
 number of hits selected for track
bool RefineSegmentFlag () const
 get refine segment flag
void switchOnRefit ()
 switch on/off chi^2 refit after hit selection
void switchOffRefit ()
bool refit () const
 return refit flag

Protected Attributes

bool m_refine_segment
 flags
bool m_refit

Private Member Functions

Amg::Vector3D getHitPoint (const MdtHitPtr &hit, const MTStraightLine &straight_track) const
std::vector< Amg::Vector3DgetHitPoints (const MdtHitVec &track_hits, const MTStraightLine &straight_track) const
std::vector< Amg::Vector3DgetHitPoints (const MdtHitVec &track_hits, const CurvedLine &curved_track) const

Private Attributes

double m_road_width {0.5}
double m_time_out {10}

Detailed Description

Definition at line 35 of file CurvedPatRec.h.

Member Typedef Documentation

◆ HitSelection

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

Definition at line 32 of file IMdtSegmentFitter.h.

◆ MdtHitPtr

◆ MdtHitVec

Constructor & Destructor Documentation

◆ CurvedPatRec() [1/2]

CurvedPatRec::CurvedPatRec ( )
default

Default constructor: road width of 0.5 mm is used.

◆ CurvedPatRec() [2/2]

CurvedPatRec::CurvedPatRec ( const double road_width)

Constructor: user defined road width [mm] for pattern recognition.

Definition at line 18 of file CurvedPatRec.cxx.

18{ m_road_width = road_width; }

Member Function Documentation

◆ fit() [1/3]

bool CurvedPatRec::fit ( MuonCalibSegment & r_segment) const
virtual

reconstruction of the track using all hits in the segment "r_segment", returns true in case of success; the algorithm overwrites the track radii, the track position, track direction, and chi^2 per degrees of freedom; warning: the errors of the track radii are only approximate

Implements MuonCalib::IMdtSegmentFitter.

Definition at line 23 of file CurvedPatRec.cxx.

23 {
24 // select all hits //
26 // call the other fit function //
27 return fit(r_segment, selection);
28}
bool fit(MuonCalibSegment &r_segment) const
reconstruction of the track using all hits in the segment "r_segment", returns true in case of succes...
std::vector< unsigned int > HitSelection
unsigned int mdtHitsOnTrack() const
retrieve the number of MdtCalibHitBase s assigned to this segment
const std::string selection

◆ fit() [2/3]

bool CurvedPatRec::fit ( MuonCalibSegment & r_segment,
HitSelection r_selection ) const
virtual

reconstruction of the track using only those hits in r_segment for which the r_selection[.

] is 0, return true in case of success; the algorithm overwrites the track position, direction, and the chi^2 in r_segment; it updates the distances of all hits from the track, i.e. also of those hits which were rejected from the track reconstruction; warning: the errors of the track radii are only approximate

Implements MuonCalib::IMdtSegmentFitter.

Definition at line 29 of file CurvedPatRec.cxx.

29 {
30 CurvedLine curved_track;
31 return fit(r_segment, r_selection, curved_track);
32}

◆ fit() [3/3]

bool CurvedPatRec::fit ( MuonCalibSegment & r_segment,
HitSelection r_selection,
CurvedLine & curved_track ) const

Definition at line 33 of file CurvedPatRec.cxx.

33 {
35 // VARIABLES //
37 std::unique_ptr<StraightPatRec> sfitter = std::make_unique<StraightPatRec>();
38 time_t start, end; // start and end times (needed for time-out)
39 double diff; // difference of start and end time (needed for time-out)
40 Combination combination;
41 std::vector<unsigned int> hit_index; // hit indices for a given combination
42 unsigned int try_nb_hits; // try to find a segment with try_nb_hits hits
43 bool segment_found(false); // flag indicating the a segment has been found
44 MdtHitVec cand_track_hits; // vector of the track hits
45 // found so far
46 CurvedLine aux_line; // memory for reconstructed curved lines
47 Amg::Vector3D null(0.0, 0.0, 0.0);
48 Amg::Vector3D xhat(1.0, 0.0, 0.0);
49 std::vector<Amg::Vector3D> points; // hit points for the track fit
50 MdtHitVec loc_track_hits; // track hit store
51
53 // RESETS //
55 time(&start);
56
58 // CHECK SIZE OF THE SELECTION VECTOR //
60
61 if (r_selection.size() != r_segment.mdtHitsOnTrack()) {
62 throw std::runtime_error(
63 Form("File: %s, Line: %d\nCurvedPatRec::fit - Size of selection vector does not match the number of hits on track!", __FILE__,
64 __LINE__));
65 }
66
68 // PREPARATORY WORK //
70
71 // perform a straight track fit to get an estimate of the incidence angle //
72 Amg::Vector3D est_dir(0.0, 0.0, 1.0);
73 sfitter->setRoadWidth(2.0 * m_road_width);
74 sfitter->setTimeOut(0.5 * m_time_out);
75 MTStraightLine track;
76 if (sfitter->fit(r_segment, r_selection, track)) { est_dir = track.directionVector(); }
77
78 // store track hits //
79 unsigned int k = 0;
80 for (const MuonCalibSegment::MdtHitPtr &hit : r_segment.mdtHOT()) {
81 if (r_selection[k] == 0 && hit->sigmaDriftRadius() < 100) { loc_track_hits.push_back(hit); };
82 ++k;
83 }
84
85 // return, if there are too few hits //
86 if (loc_track_hits.size() < 4) { return false; }
88 // PATTERN RECOGNITION //
90
91 // try to find a segment with as many hits on it as possible //
92 try_nb_hits = loc_track_hits.size();
93
94 MdtHitVec stored_track_hits;
95 double chi2 = -1.;
96
97 while (!segment_found && try_nb_hits > 3) {
98 // loop over the combinations //
99 combination.setNewParameters(loc_track_hits.size(), try_nb_hits);
100 for (unsigned int cb = 0; cb < combination.numberOfCombinations(); cb++) {
101 // time-out //
102 time(&end);
103 diff = difftime(end, start);
104 if (diff > m_time_out) {
105 MsgStream log(Athena::getMessageSvc(), "CurvedPatRec");
106 log << MSG::WARNING << "Class CurvedPatRec, method fit: time-out for track finding after " << m_time_out << " seconds!"
107 << endmsg;
108 return false;
109 }
110
111 // analyse the hit combination //
112 if (cb == 0) {
113 combination.currentCombination(hit_index);
114 } else {
115 combination.nextCombination(hit_index);
116 }
117 MdtHitVec track_hits;
118 for (unsigned int k = 0; k < try_nb_hits; ++k) { track_hits.push_back(loc_track_hits[hit_index[k] - 1]); }
119
120 // find candidates //
121 CurvedCandidateFinder finder(track_hits);
122 const std::vector<CurvedLine> candidates(finder.getCandidates(m_road_width, est_dir));
123 if (candidates.empty()) { continue; }
124
125 segment_found = true;
126
127 for (const auto & candidate : candidates) {
128 std::vector<Amg::Vector3D> errors(track_hits.size());
129 for (unsigned int k = 0; k < errors.size(); k++) {
130 if (track_hits[k]->sigmaDriftRadius() > 0.0) {
131 errors[k] = Amg::Vector3D(1.0, track_hits[k]->sigmaDriftRadius(), 0.0);
132 } else {
133 errors[k] = Amg::Vector3D(1.0, 1.0, 0.0);
134 }
135 }
136
137 // get hit points //
138 points = getHitPoints(track_hits, candidate);
139
140 // fit a curved line through the points //
141 aux_line = CurvedLine(points, errors);
142
143 // calculate chi^2 //
144 double tmp_chi2(0.0);
145 for (auto & track_hit : track_hits) {
146 MTStraightLine tang(curved_track.getTangent((track_hit->localPosition()).z()));
147 MTStraightLine wire(Amg::Vector3D(0.0, track_hit->localPosition().y(), track_hit->localPosition().z()), xhat,
148 null, null);
149 double d(std::abs(tang.signDistFrom(wire)));
150 if (track_hit->sigma2DriftRadius() != 0) {
151 tmp_chi2 = tmp_chi2 + std::pow(d - track_hit->driftRadius(), 2) / track_hit->sigma2DriftRadius();
152 } else {
153 tmp_chi2 = tmp_chi2 + std::pow(d - track_hit->driftRadius(), 2) / 0.01;
154 }
155 }
156
157 // compare chi^2 with chi^2 values found so far //
158 if (chi2 < 0 || tmp_chi2 < chi2) {
159 chi2 = tmp_chi2;
160 curved_track = aux_line;
161 // store the track hits //
162 stored_track_hits = track_hits;
163 }
164 }
165 }
166
167 try_nb_hits = try_nb_hits - 1;
168 }
169
170 if (!segment_found) { return false; }
171
173 // SECOND REFINED CURVED FIT //
175
176 // get hit points //
177 points = getHitPoints(stored_track_hits, curved_track);
178 std::vector<Amg::Vector3D> errors(stored_track_hits.size());
179 for (unsigned int k = 0; k < errors.size(); k++) {
180 if (stored_track_hits[k]->sigmaDriftRadius() > 0.0) {
181 errors[k] = Amg::Vector3D(1.0, stored_track_hits[k]->sigmaDriftRadius(), 0.0);
182 } else {
183 errors[k] = Amg::Vector3D(1.0, 1.0, 0.0);
184 }
185 }
186
187 // fit a curved line through the points //
188 curved_track = CurvedLine(points, errors);
189
191 // CALCULATE CHI^2 //
193
194 chi2 = 0.0;
195 for (auto & stored_track_hit : stored_track_hits) {
196 MTStraightLine tang(curved_track.getTangent((stored_track_hit->localPosition()).z()));
197 MTStraightLine wire(Amg::Vector3D(0.0, stored_track_hit->localPosition().y(), stored_track_hit->localPosition().z()), xhat,
198 null, null);
199 double d(std::abs(tang.signDistFrom(wire)));
200 if (stored_track_hit->sigma2DriftRadius() != 0) {
201 chi2 += std::pow(d - stored_track_hit->driftRadius(), 2) / stored_track_hit->sigma2DriftRadius();
202 } else {
203 chi2 += std::pow(d - stored_track_hit->driftRadius(), 2) / 0.01;
204 }
205 }
206
208 // UPDATE HIT RESIDUALS //
210
211 for (const MdtHitPtr& hit : r_segment.mdtHOT()) {
212 Amg::Vector3D pos(0.0, hit->localPosition().y(), hit->localPosition().z());
213 MTStraightLine aux_line(pos, xhat, null, null);
214
215 MTStraightLine tang(curved_track.getTangent(pos.z()));
216
217 double dist(tang.signDistFrom(aux_line)); // track distance
218 double dist_err(1.0); // unknown error of the track distance
219 hit->setDistanceToTrack(dist, dist_err);
220 }
221
222 if (std::isnan(chi2)) { chi2 = 1.0e6; }
223
225 // UPDATE SEGMENT POSITION, DIRECTION, CHI^2 //
227
228 MTStraightLine tangent(curved_track.getTangent((r_segment.position()).z()));
229 r_segment.set(chi2 / (stored_track_hits.size() - 3), tangent.positionVector(), tangent.directionVector());
230 curved_track.setChi2(chi2);
231 curved_track.setNumberOfTrackHits(stored_track_hits.size());
232 curved_track.setUsedHits(stored_track_hits);
233 return true;
234}
#define endmsg
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
void currentCombination(std::vector< unsigned int > &index_array) const
get the current combination; the result is stored in the vector index_array
unsigned int numberOfCombinations() const
get the number of combinations
void setNewParameters(const unsigned int &nb_elements, const unsigned int &wh_class)
set the number of elements = nb_elements; set the class of which the combination is = wh_class
void nextCombination(std::vector< unsigned int > &index_array)
get the next combination; the results is stored in the array index_array
void setChi2(double chi2)
Cache the chi2.
MTStraightLine getTangent(const double loc_z) const
get the tangent to the line a the local z coordinate "loc_z"
void setUsedHits(const MdtHitVec &hits)
void setNumberOfTrackHits(unsigned int n_hits)
cache the number of track hits
MuonCalibSegment::MdtHitPtr MdtHitPtr
std::vector< Amg::Vector3D > getHitPoints(const MdtHitVec &track_hits, const MTStraightLine &straight_track) const
MuonCalibSegment::MdtHitVec MdtHitVec
std::shared_ptr< MdtCalibHitBase > MdtHitPtr
typedef for a collection of MdtCalibHitBase s
const MdtHitVec & mdtHOT() const
retrieve the full set of MdtCalibHitBase s assigned to this segment
void set(double chi2, const Amg::Vector3D &pos, const Amg::Vector3D &dir)
const Amg::Vector3D & position() const
retrieve local position of segment (on station level)
double chi2(TH1 *h0, TH1 *h1)
Eigen::Matrix< double, 3, 1 > Vector3D
IMessageSvc * getMessageSvc(bool quiet=false)
time(flags, cells_name, *args, **kw)

◆ getHitPoint()

Amg::Vector3D CurvedPatRec::getHitPoint ( const MdtHitPtr & hit,
const MTStraightLine & straight_track ) const
private

Definition at line 236 of file CurvedPatRec.cxx.

236 {
238 // CALCULATE HIT POINT //
240
241 Amg::Vector3D point = straight_track.positionVector() +
242 (straight_track.directionVector().unit().dot(hit->localPosition() - straight_track.positionVector())) *
243 straight_track.directionVector().unit();
244 Amg::Vector3D point_2 = hit->localPosition() + hit->driftRadius() * (point - hit->localPosition()).unit();
245
246 return point_2;
247}
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Amg::Vector3D directionVector() const
get the direction vector of the straight line
Amg::Vector3D positionVector() const
get the position vector of the straight line
dot(G, fn, nodesToHighlight=[])
Definition dot.py:5

◆ getHitPoints() [1/2]

std::vector< Amg::Vector3D > CurvedPatRec::getHitPoints ( const MdtHitVec & track_hits,
const CurvedLine & curved_track ) const
private

Definition at line 269 of file CurvedPatRec.cxx.

269 {
271 // VARIABLES //
273
274 std::vector<Amg::Vector3D> hit_vec;
275
277 // FILL HIT VECTOR //
279
280 for (const auto & track_hit : track_hits) {
281 hit_vec.emplace_back(getHitPoint(track_hit, curved_track.getTangent((track_hit->localPosition()).z())));
282 }
283
285 // RETURN THE HIT VECTOR //
287
288 return hit_vec;
289}
Amg::Vector3D getHitPoint(const MdtHitPtr &hit, const MTStraightLine &straight_track) const

◆ getHitPoints() [2/2]

std::vector< Amg::Vector3D > CurvedPatRec::getHitPoints ( const MdtHitVec & track_hits,
const MTStraightLine & straight_track ) const
private

Definition at line 249 of file CurvedPatRec.cxx.

249 {
251 // VARIABLES //
253
254 std::vector<Amg::Vector3D> hit_vec;
255
257 // FILL HIT VECTOR //
259
260 for (const auto & track_hit : track_hits) { hit_vec.emplace_back(getHitPoint(track_hit, straight_track)); }
261
263 // RETURN THE HIT VECTOR //
265
266 return hit_vec;
267}

◆ printLevel()

void MuonCalib::CurvedPatRec::printLevel ( int )
inlinevirtual

Implements MuonCalib::IMdtSegmentFitter.

Definition at line 87 of file CurvedPatRec.h.

87{};

◆ RefineSegmentFlag()

bool MuonCalib::IMdtPatRecFitter::RefineSegmentFlag ( ) const
inlineinherited

get refine segment flag

Definition at line 37 of file IMdtPatRecFitter.h.

◆ refit()

bool MuonCalib::IMdtPatRecFitter::refit ( ) const
inlineinherited

return refit flag

Definition at line 43 of file IMdtPatRecFitter.h.

◆ roadWidth()

double CurvedPatRec::roadWidth ( ) const

get the road width used in the pattern recognition [mm]

Definition at line 20 of file CurvedPatRec.cxx.

20{ return m_road_width; }

◆ SetRefineSegmentFlag()

void MuonCalib::IMdtPatRecFitter::SetRefineSegmentFlag ( const bool flag)
inlineinherited

number of hits selected for track

virtual unsigned int numberOfTrackHits() const = 0; get selected track hits virtual const std::vector<const MdtCalibHitBase *> &trackHits() const = 0; set refine segment flag

Parameters
flagif true the hit selection is changed in the segment

Definition at line 34 of file IMdtPatRecFitter.h.

bool flag
Definition master.py:29

◆ setRoadWidth()

void CurvedPatRec::setRoadWidth ( const double r_road_width)
virtual

set the road width [mm] for the pattern recognition = r_road_width

Implements MuonCalib::IMdtPatRecFitter.

Definition at line 21 of file CurvedPatRec.cxx.

21{ m_road_width = r_road_width; }

◆ setTimeOut()

void CurvedPatRec::setTimeOut ( const double time_out)

set the time-out for the track finding to time_out (in seconds)

Definition at line 22 of file CurvedPatRec.cxx.

22{ m_time_out = time_out; }

◆ switchOffRefit()

void MuonCalib::IMdtPatRecFitter::switchOffRefit ( )
inlineinherited

Definition at line 41 of file IMdtPatRecFitter.h.

41{ m_refit = false; }

◆ switchOnRefit()

void MuonCalib::IMdtPatRecFitter::switchOnRefit ( )
inlineinherited

switch on/off chi^2 refit after hit selection

Definition at line 40 of file IMdtPatRecFitter.h.

40{ m_refit = true; }

Member Data Documentation

◆ m_refine_segment

bool MuonCalib::IMdtPatRecFitter::m_refine_segment
protectedinherited

flags

Definition at line 49 of file IMdtPatRecFitter.h.

◆ m_refit

bool MuonCalib::IMdtPatRecFitter::m_refit
protectedinherited

Definition at line 50 of file IMdtPatRecFitter.h.

◆ m_road_width

double MuonCalib::CurvedPatRec::m_road_width {0.5}
private

Definition at line 99 of file CurvedPatRec.h.

99{0.5}; // road width to be used in pattern finding

◆ m_time_out

double MuonCalib::CurvedPatRec::m_time_out {10}
private

Definition at line 100 of file CurvedPatRec.h.

100{10}; // time out for pattern recognition.

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