ATLAS Offline Software
Public Types | Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
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. More...
 
 CurvedPatRec (const double &road_width)
 Constructor: user defined road width [mm] for pattern recognition. More...
 
double roadWidth () const
 get the road width used in the pattern recognition [mm] More...
 
void setRoadWidth (const double &r_road_width)
 set the road width [mm] for the pattern recognition = r_road_width More...
 
void setTimeOut (const double &time_out)
 set the time-out for the track finding to time_out (in seconds) More...
 
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 More...
 
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[. More...
 
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 More...
 
bool RefineSegmentFlag () const
 get refine segment flag More...
 
void switchOnRefit ()
 switch on/off chi^2 refit after hit selection More...
 
void switchOffRefit ()
 
bool refit () const
 return refit flag More...
 

Protected Attributes

bool m_refine_segment
 flags More...
 
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

Definition at line 38 of file CurvedPatRec.h.

◆ MdtHitVec

Definition at line 37 of file CurvedPatRec.h.

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 //
25  HitSelection selection(r_segment.mdtHitsOnTrack(), 0);
26  // call the other fit function //
27  return fit(r_segment, selection);
28 }

◆ 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);
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 }

◆ 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 }

◆ 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 }

◆ 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 38 of file IMdtPatRecFitter.h.

38 { return m_refine_segment; }

◆ refit()

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

return refit flag

Definition at line 44 of file IMdtPatRecFitter.h.

44 { return m_refit; }

◆ 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 35 of file IMdtPatRecFitter.h.

◆ 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 42 of file IMdtPatRecFitter.h.

42 { m_refit = false; }

◆ switchOnRefit()

void MuonCalib::IMdtPatRecFitter::switchOnRefit ( )
inlineinherited

switch on/off chi^2 refit after hit selection

Definition at line 41 of file IMdtPatRecFitter.h.

41 { m_refit = true; }

Member Data Documentation

◆ m_refine_segment

bool MuonCalib::IMdtPatRecFitter::m_refine_segment
protectedinherited

flags

Definition at line 50 of file IMdtPatRecFitter.h.

◆ m_refit

bool MuonCalib::IMdtPatRecFitter::m_refit
protectedinherited

Definition at line 51 of file IMdtPatRecFitter.h.

◆ m_road_width

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

Definition at line 99 of file CurvedPatRec.h.

◆ m_time_out

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

Definition at line 100 of file CurvedPatRec.h.


The documentation for this class was generated from the following files:
MuonCalib::CurvedPatRec::MdtHitPtr
MuonCalibSegment::MdtHitPtr MdtHitPtr
Definition: CurvedPatRec.h:38
MuonCalib::CurvedPatRec::getHitPoints
std::vector< Amg::Vector3D > getHitPoints(const MdtHitVec &track_hits, const MTStraightLine &straight_track) const
Definition: CurvedPatRec.cxx:249
MuonCalib::CurvedPatRec::m_time_out
double m_time_out
Definition: CurvedPatRec.h:100
drawFromPickle.candidates
candidates
Definition: drawFromPickle.py:271
hist_file_dump.d
d
Definition: hist_file_dump.py:137
MuonCalib::CurvedLine::getTangent
MTStraightLine getTangent(const double &loc_z) const
get the tangent to the line a the local z coordinate "loc_z"
Definition: CurvedLine.cxx:114
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
MuonCalib::CurvedLine
Definition: CurvedLine.h:31
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
MuonCalib::MTStraightLine::directionVector
Amg::Vector3D directionVector() const
get the direction vector of the straight line
Definition: MTStraightLine.cxx:43
MuonCalib::Combination
Definition: MuonSpectrometer/MuonCalib/MuonCalibUtils/MuonCalibMath/MuonCalibMath/Combination.h:33
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
MuonCalib::MuonCalibSegment::position
const Amg::Vector3D & position() const
retrieve local position of segment (on station level)
Definition: MuonCalibSegment.cxx:186
MuonCalib::CurvedPatRec::fit
bool fit(MuonCalibSegment &r_segment) const
reconstruction of the track using all hits in the segment "r_segment", returns true in case of succes...
Definition: CurvedPatRec.cxx:23
MuonCalib::CurvedPatRec::m_road_width
double m_road_width
Definition: CurvedPatRec.h:99
MuonCalib::IMdtPatRecFitter::m_refit
bool m_refit
Definition: IMdtPatRecFitter.h:51
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
MuonCalib::CurvedLine::setChi2
void setChi2(double chi2)
Cache the chi2.
Definition: CurvedLine.cxx:190
MuonCalib::CurvedLine::setNumberOfTrackHits
void setNumberOfTrackHits(unsigned int n_hits)
cache the number of track hits
Definition: CurvedLine.cxx:192
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
master.flag
bool flag
Definition: master.py:29
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
selection
std::string selection
Definition: fbtTestBasics.cxx:73
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
MuonCalib::MuonCalibSegment::mdtHitsOnTrack
unsigned int mdtHitsOnTrack() const
retrieve the number of MdtCalibHitBase s assigned to this segment
Definition: MuonCalibSegment.cxx:147
MuonCalib::CurvedCandidateFinder
Definition: CurvedCandidateFinder.h:35
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
MuonCalib::IMdtPatRecFitter::m_refine_segment
bool m_refine_segment
flags
Definition: IMdtPatRecFitter.h:50
MuonCalib::MuonCalibSegment::set
void set(double chi2, const Amg::Vector3D &pos, const Amg::Vector3D &dir)
Definition: MuonCalibSegment.cxx:129
MuonCalib::CurvedLine::setUsedHits
void setUsedHits(const MdtHitVec &hits)
Definition: CurvedLine.cxx:197
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:20
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MuonCalib::MTStraightLine
Definition: MTStraightLine.h:16
MuonCalib::CurvedPatRec::MdtHitVec
MuonCalibSegment::MdtHitVec MdtHitVec
Definition: CurvedPatRec.h:37
MuonCalib::MTStraightLine::positionVector
Amg::Vector3D positionVector() const
get the position vector of the straight line
Definition: MTStraightLine.cxx:42
MuonCalib::MuonCalibSegment::mdtHOT
const MdtHitVec & mdtHOT() const
retrieve the full set of MdtCalibHitBase s assigned to this segment
Definition: MuonCalibSegment.cxx:148
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
python.TrkVertexSeedFinderToolsConfig.finder
finder
Definition: TrkVertexSeedFinderToolsConfig.py:99
MuonCalib::CurvedPatRec::getHitPoint
Amg::Vector3D getHitPoint(const MdtHitPtr &hit, const MTStraightLine &straight_track) const
Definition: CurvedPatRec.cxx:236
MuonCalib::MuonCalibSegment::MdtHitPtr
std::shared_ptr< MdtCalibHitBase > MdtHitPtr
typedef for a collection of MdtCalibHitBase s
Definition: MuonCalibSegment.h:44
fitman.k
k
Definition: fitman.py:528
MuonCalib::IMdtSegmentFitter::HitSelection
std::vector< unsigned int > HitSelection
Definition: IMdtSegmentFitter.h:32