LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
trkf::KGTrack Class Reference

#include "KGTrack.h"

Public Member Functions

 KGTrack (int prefplane)
 
int getPrefPlane () const
 
const std::multimap< double, KHitTrack > & getTrackMap () const
 KHitTrack collection, indexed by path distance. More...
 
size_t numHits () const
 Number of measurements in track. More...
 
const KHitTrackstartTrack () const
 Track at start point. More...
 
const KHitTrackendTrack () const
 Track at end point. More...
 
bool isValid () const
 Validity flag. More...
 
std::multimap< double, KHitTrack > & getTrackMap ()
 Modifiable KHitTrack collection, indexed by path distance. More...
 
KHitTrackstartTrack ()
 Modifiable track at start point. More...
 
KHitTrackendTrack ()
 Modifiable track at end point. More...
 
void addTrack (const KHitTrack &trh)
 Add track. More...
 
void recalibrate ()
 Recalibrate track map. More...
 
void clear ()
 Clear track collection. More...
 
void fillTrack (detinfo::DetectorPropertiesData const &detProp, recob::Track &track, int id) const
 Fill a recob::Track. More...
 
void fillHits (art::PtrVector< recob::Hit > &hits, std::vector< unsigned int > &hittpindex) const
 Fill a PtrVector of Hits. More...
 
const std::multimap< double, KHitTrackTrackMap () const
 
std::ostream & Print (std::ostream &out) const
 Printout. More...
 

Private Attributes

int fPrefPlane
 Preferred plane. More...
 
std::multimap< double, KHitTrackfTrackMap
 KHitTrack collection, indexed by path distance. More...
 

Detailed Description

Definition at line 47 of file KGTrack.h.

Constructor & Destructor Documentation

trkf::KGTrack::KGTrack ( int  prefplane)

Definition at line 27 of file KGTrack.cxx.

27 : fPrefPlane(prefplane) {}
int fPrefPlane
Preferred plane.
Definition: KGTrack.h:105

Member Function Documentation

void trkf::KGTrack::addTrack ( const KHitTrack trh)

Add track.

Definition at line 76 of file KGTrack.cxx.

References fTrackMap, trkf::KHitTrack::getHit(), trkf::KFitTrack::getPath(), and trkf::KTrack::isValid().

Referenced by trkf::KalmanFilterAlg::buildTrack(), trkf::KalmanFilterAlg::extendTrack(), and trkf::KalmanFilterAlg::smoothTrack().

77  {
78  if (!trh.isValid()) throw cet::exception("KGTrack") << "Adding invalid track to KGTrack.\n";
79  fTrackMap.insert(std::make_pair(trh.getPath() + trh.getHit()->getPredDistance(), trh));
80  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void trkf::KGTrack::clear ( )
inline

Clear track collection.

Definition at line 86 of file KGTrack.h.

References hits(), and track.

86 { fTrackMap.clear(); }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
const KHitTrack & trkf::KGTrack::endTrack ( ) const

Track at end point.

Throw exception if track is not valid.

Definition at line 40 of file KGTrack.cxx.

References fTrackMap, and isValid().

Referenced by trkf::KalmanFilterAlg::buildTrack(), trkf::KalmanFilterAlg::extendTrack(), trkf::KalmanFilterAlg::fitMomentumRange(), trkf::Track3DKalmanHitAlg::qualityCutsOnSeedTrack(), trkf::Track3DKalmanHitAlg::smoothandextendTrack(), and trkf::KalmanFilterAlg::smoothTrack().

41  {
43 
44  if (!isValid()) throw cet::exception("KGTrack") << "Ending track is not valid.\n";
45 
46  // Return track.
47 
48  return (*fTrackMap.rbegin()).second;
49  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
bool isValid() const
Validity flag.
Definition: KGTrack.h:66
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
KHitTrack & trkf::KGTrack::endTrack ( )

Modifiable track at end point.

Throw exception if track is not valid.

Definition at line 64 of file KGTrack.cxx.

References fTrackMap, and isValid().

65  {
67 
68  if (!isValid()) throw cet::exception("KGTrack") << "Ending track is not valid.\n";
69 
70  // Return track.
71 
72  return (*fTrackMap.rbegin()).second;
73  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
bool isValid() const
Validity flag.
Definition: KGTrack.h:66
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void trkf::KGTrack::fillHits ( art::PtrVector< recob::Hit > &  hits,
std::vector< unsigned int > &  hittpindex 
) const

Fill a PtrVector of Hits.

Fill a PtrVector of Hits.

Arguments:

hits - Hit vector to fill.

Definition at line 216 of file KGTrack.cxx.

References util::counter(), fTrackMap, trkf::KHitTrack::getHit(), art::Ptr< T >::isNull(), art::PtrVector< T >::push_back(), art::PtrVector< T >::reserve(), art::PtrVector< T >::size(), and track.

Referenced by trkf::Track3DKalmanHitAlg::extendandsmoothLoop(), and trkf::Track3DKalmanHitAlg::filterHitsOnKalmanTrack().

218  {
219  hits.reserve(hits.size() + fTrackMap.size());
220 
221  // Loop over KHitTracks and fill hits belonging to this track.
222 
223  unsigned int counter = 0; //Index of corresponding trajectory point
225  it != fTrackMap.end();
226  ++it) {
227  const KHitTrack& track = (*it).second;
228  ++counter;
229  // Extrack Hit from track.
230  const std::shared_ptr<const KHitBase>& hit = track.getHit();
231  if (const KHitWireX* phit = dynamic_cast<const KHitWireX*>(&*hit)) {
232  const art::Ptr<recob::Hit> prhit = phit->getHit();
233  if (!prhit.isNull()) {
234  hits.push_back(prhit);
235  hittpindex.push_back(counter - 1);
236  }
237  }
238  else if (const KHitWireLine* phit = dynamic_cast<const KHitWireLine*>(&*hit)) {
239  const art::Ptr<recob::Hit> prhit = phit->getHit();
240  if (!prhit.isNull()) {
241  hits.push_back(prhit);
242  hittpindex.push_back(counter - 1);
243  }
244  }
245  }
246  }
void reserve(size_type n)
Definition: PtrVector.h:337
intermediate_table::const_iterator const_iterator
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:295
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
bool isNull() const noexcept
Definition: Ptr.h:211
size_type size() const
Definition: PtrVector.h:302
Detector simulation of raw signals on wires.
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
Float_t track
Definition: plot.C:35
void trkf::KGTrack::fillTrack ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track track,
int  id 
) const

Fill a recob::Track.

Fill a recob::Track.

Arguments:

track - Track to fill.

Definition at line 119 of file KGTrack.cxx.

References larg4::dist(), trkf::Propagator::err_prop(), fTrackMap, trkf::KFitTrack::getChisq(), trkf::KETrack::getError(), trkf::KTrack::getMomentum(), trkf::KTrack::getPosition(), recob::TrajectoryPointFlags::makeMask(), n, startTrack(), and trkf::Propagator::UNKNOWN.

122  {
123 
124  // Make propagator for propating to standard track surface.
125 
126  PropXYZPlane prop(detProp, 0., false);
127 
128  // Fill collections of trajectory points and direction vectors.
129 
130  std::vector<recob::tracking::Point_t> xyz;
131  std::vector<recob::tracking::Vector_t> pxpypz;
132  std::vector<recob::tracking::SMatrixSym55> cov;
133  std::vector<recob::TrajectoryPointFlags> outFlags;
134 
135  xyz.reserve(fTrackMap.size());
136  pxpypz.reserve(fTrackMap.size());
137  outFlags.reserve(fTrackMap.size());
138 
139  // Loop over KHitTracks.
140 
141  int ndof = 0;
142  float totChi2 = 0.;
143  unsigned int n = 0;
145  itr != fTrackMap.end();
146  ++itr, ++n) {
147  const KHitTrack& trh = (*itr).second;
148 
149  // Get position.
150 
151  double pos[3];
152  trh.getPosition(pos);
153  xyz.push_back({pos[0], pos[1], pos[2]});
154 
155  // Get momentum vector.
156  // Fill direction unit vector and momentum.
157 
158  double mom[3];
159  trh.getMomentum(mom);
160  double p = std::sqrt(mom[0] * mom[0] + mom[1] * mom[1] + mom[2] * mom[2]);
161  if (p == 0.) throw cet::exception("KGTrack") << __func__ << ": null momentum\n";
162  pxpypz.push_back({mom[0], mom[1], mom[2]});
163 
164  ndof += 1;
165  totChi2 += trh.getChisq();
166  outFlags.emplace_back(n, recob::TrajectoryPointFlags::makeMask());
167 
168  // Fill error matrix.
169 
171 
172  // Construct surface perpendicular to track momentun, and
173  // propagate track to that surface (zero distance).
174 
175  const std::shared_ptr<const Surface> psurf(
176  new SurfXYZPlane(pos[0], pos[1], pos[2], mom[0], mom[1], mom[2]));
177  KETrack tre(trh);
178  std::optional<double> dist = prop.err_prop(tre, psurf, Propagator::UNKNOWN, false);
179  if (!dist) throw cet::exception("KGTrack") << __func__ << ": error propagation failed\n";
180  for (int i = 0; i < 5; ++i) {
181  for (int j = 0; j < 5; ++j)
182  covar(i, j) = tre.getError()(i, j);
183  }
184 
185  // Only save first and last error matrix.
186 
187  if (cov.size() < 2)
188  cov.push_back(covar);
189  else
190  cov.back() = covar;
191  }
192 
193  // Fill track.
194 
195  ndof = ndof - 4; //fit measures 4 parameters: position and direction on plane
196  if (xyz.size() >= 2) {
197  track = recob::Track(std::move(xyz),
198  std::move(pxpypz),
199  std::move(outFlags),
200  true,
201  this->startTrack().PdgCode(),
202  totChi2,
203  ndof,
204  std::move(cov.front()),
205  std::move(cov.back()),
206  id);
207  }
208  }
static constexpr Mask_t makeMask(Flags...flags)
Returns a bit mask with only the specified bit set.
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 >> SMatrixSym55
intermediate_table::const_iterator const_iterator
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
Char_t n[5]
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
Definition: Track.h:992
const KHitTrack & startTrack() const
Track at start point.
Definition: KGTrack.cxx:30
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int trkf::KGTrack::getPrefPlane ( ) const
inline

Definition at line 51 of file KGTrack.h.

Referenced by trkf::KalmanFilterAlg::smoothTrackIter().

51 { return fPrefPlane; }
int fPrefPlane
Preferred plane.
Definition: KGTrack.h:105
const std::multimap<double, KHitTrack>& trkf::KGTrack::getTrackMap ( ) const
inline

KHitTrack collection, indexed by path distance.

Definition at line 54 of file KGTrack.h.

Referenced by trkf::KalmanFilterAlg::cleanTrack(), trkf::Track3DKalmanHit::fillHistograms(), trkf::KalmanFilterAlg::fitMomentumMS(), trkf::KalmanFilterAlg::smoothTrack(), and trkf::KalmanFilterAlg::updateMomentum().

54 { return fTrackMap; }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
std::multimap<double, KHitTrack>& trkf::KGTrack::getTrackMap ( )
inline

Modifiable KHitTrack collection, indexed by path distance.

Definition at line 71 of file KGTrack.h.

71 { return fTrackMap; }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
bool trkf::KGTrack::isValid ( ) const
inline

Validity flag.

Definition at line 66 of file KGTrack.h.

Referenced by trkf::KalmanFilterAlg::buildTrack(), endTrack(), trkf::KalmanFilterAlg::extendTrack(), trkf::KalmanFilterAlg::fitMomentumRange(), trkf::KalmanFilterAlg::smoothTrack(), and startTrack().

66 { return fTrackMap.size() > 0; }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
size_t trkf::KGTrack::numHits ( ) const
inline

Number of measurements in track.

Definition at line 57 of file KGTrack.h.

Referenced by trkf::KalmanFilterAlg::buildTrack(), trkf::KalmanFilterAlg::extendTrack(), trkf::Track3DKalmanHitAlg::smoothandextendTrack(), and trkf::KalmanFilterAlg::smoothTrack().

57 { return fTrackMap.size(); }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
std::ostream & trkf::KGTrack::Print ( std::ostream &  out) const

Printout.

Printout

Definition at line 251 of file KGTrack.cxx.

References f, fTrackMap, trkf::KHitTrack::getHit(), trkf::KHitBase::getMeasPlane(), trkf::KTrack::getMomentum(), trkf::KTrack::getPosition(), and n.

Referenced by trkf::operator<<().

252  {
253 
254  int n = 0;
255 
256  double oldxyz[3] = {0., 0., 0.};
257  double len = 0.;
258  bool first = true;
259  for (auto const& ele : fTrackMap) {
260  double s = ele.first;
261  const KHitTrack& trh = ele.second;
262  double xyz[3];
263  double mom[3];
264  trh.getPosition(xyz);
265  trh.getMomentum(mom);
266  double tmom = std::sqrt(mom[0] * mom[0] + mom[1] * mom[1] + mom[2] * mom[2]);
267  if (tmom != 0.) {
268  mom[0] /= tmom;
269  mom[1] /= tmom;
270  mom[2] /= tmom;
271  }
272  if (!first) {
273  double dx = xyz[0] - oldxyz[0];
274  double dy = xyz[1] - oldxyz[1];
275  double dz = xyz[2] - oldxyz[2];
276  len += std::sqrt(dx * dx + dy * dy + dz * dz);
277  }
278  const KHitBase& hit = *(trh.getHit());
279  int plane = hit.getMeasPlane();
280  std::ios_base::fmtflags f = out.flags();
281  out << "State " << std::setw(4) << n << ", path=" << std::setw(8) << std::fixed
282  << std::setprecision(2) << s << ", length=" << std::setw(8) << len
283  << ", x=" << std::setw(8) << xyz[0] << ", y=" << std::setw(8) << xyz[1]
284  << ", z=" << std::setw(8) << xyz[2] << ", dx=" << std::setw(8) << mom[0]
285  << ", dy=" << std::setw(8) << mom[1] << ", dz=" << std::setw(8) << mom[2]
286  << ", plane=" << std::setw(1) << plane << "\n";
287  out.flags(f);
288 
289  oldxyz[0] = xyz[0];
290  oldxyz[1] = xyz[1];
291  oldxyz[2] = xyz[2];
292 
293  ++n;
294  first = false;
295  }
296  return out;
297  }
TFile f
Definition: plotHisto.C:6
Detector simulation of raw signals on wires.
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
Char_t n[5]
void trkf::KGTrack::recalibrate ( )

Recalibrate track map.

Recalibrate track map.

Loop over contents of track map. Copy each KHitTrack into a new multimap track map. Offset the distance stored in the KHitTracks such that the minimum distance is zero. Also update multimap keys to agree with distance stored in track.

Definition at line 88 of file KGTrack.cxx.

References fTrackMap, trkf::KFitTrack::getPath(), and trkf::KFitTrack::setPath().

Referenced by trkf::KalmanFilterAlg::smoothTrack().

89  {
90  std::multimap<double, KHitTrack> newmap;
91 
92  // Loop over old track map.
93 
94  bool first = true;
95  double s0 = 0.;
97  ++i) {
98  KHitTrack& trh = (*i).second;
99  if (first) {
100  first = false;
101  s0 = trh.getPath();
102  }
103  double s = trh.getPath() - s0;
104  trh.setPath(s);
105  newmap.insert(std::make_pair(s, trh));
106  }
107 
108  // Update data member track map.
109 
110  fTrackMap.swap(newmap);
111  }
intermediate_table::iterator iterator
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
const KHitTrack & trkf::KGTrack::startTrack ( ) const

Track at start point.

Definition at line 30 of file KGTrack.cxx.

References fTrackMap, and isValid().

Referenced by trkf::KalmanFilterAlg::buildTrack(), trkf::KalmanFilterAlg::extendTrack(), fillTrack(), trkf::KalmanFilterAlg::fitMomentum(), trkf::Track3DKalmanHitAlg::qualityCutsOnSeedTrack(), trkf::Track3DKalmanHitAlg::smoothandextendTrack(), and trkf::KalmanFilterAlg::smoothTrack().

31  {
32  if (!isValid()) throw cet::exception("KGTrack") << "Starting track is not valid.\n";
33 
34  // Return track.
35 
36  return (*fTrackMap.begin()).second;
37  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
bool isValid() const
Validity flag.
Definition: KGTrack.h:66
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
KHitTrack & trkf::KGTrack::startTrack ( )

Modifiable track at start point.

Throw exception if track is not valid.

Definition at line 52 of file KGTrack.cxx.

References fTrackMap, and isValid().

53  {
55 
56  if (!isValid()) throw cet::exception("KGTrack") << "Starting track is not valid.\n";
57 
58  // Return track.
59 
60  return (*fTrackMap.begin()).second;
61  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
bool isValid() const
Validity flag.
Definition: KGTrack.h:66
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
const std::multimap<double, KHitTrack> trkf::KGTrack::TrackMap ( ) const
inline

Definition at line 98 of file KGTrack.h.

References pyG4Element::Print().

98 { return fTrackMap; }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:108

Member Data Documentation

int trkf::KGTrack::fPrefPlane
private

Preferred plane.

Definition at line 105 of file KGTrack.h.

std::multimap<double, KHitTrack> trkf::KGTrack::fTrackMap
private

KHitTrack collection, indexed by path distance.

Definition at line 108 of file KGTrack.h.

Referenced by addTrack(), endTrack(), fillHits(), fillTrack(), Print(), recalibrate(), and startTrack().


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