LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
trkf::KGTrack Class Reference

#include "KGTrack.h"

Public Member Functions

 KGTrack (int prefplane)
 Constructor. More...
 
 ~KGTrack ()
 Destructor. More...
 
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 (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 39 of file KGTrack.h.

Constructor & Destructor Documentation

trkf::KGTrack::KGTrack ( int  prefplane)

Constructor.

Default constructor.

Definition at line 24 of file KGTrack.cxx.

24  :
25  fPrefPlane(prefplane)
26  {}
int fPrefPlane
Preferred plane.
Definition: KGTrack.h:108
trkf::KGTrack::~KGTrack ( )

Destructor.

Definition at line 29 of file KGTrack.cxx.

30  {}

Member Function Documentation

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

Add track.

Definition at line 85 of file KGTrack.cxx.

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

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

85  {
86  if(!trh.isValid())
87  throw cet::exception("KGTrack") << "Adding invalid track to KGTrack.\n";
88  fTrackMap.insert(std::make_pair(trh.getPath() + trh.getHit()->getPredDistance(), trh));
89  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:111
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 fillHits(), fillTrack(), fTrackMap, hits(), and track.

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

Track at end point.

Throw exception if track is not valid.

Definition at line 46 of file KGTrack.cxx.

References fTrackMap, and isValid().

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

47  {
49 
50  if(!isValid())
51  throw cet::exception("KGTrack") << "Ending track is not valid.\n";
52 
53  // Return track.
54 
55  return (*fTrackMap.rbegin()).second;
56  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:111
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 72 of file KGTrack.cxx.

References fTrackMap, and isValid().

73  {
75 
76  if(!isValid())
77  throw cet::exception("KGTrack") << "Ending track is not valid.\n";
78 
79  // Return track.
80 
81  return (*fTrackMap.rbegin()).second;
82  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:111
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 219 of file KGTrack.cxx.

References 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 clear(), trkf::Track3DKalmanHitAlg::extendandsmoothLoop(), trkf::Track3DKalmanHitAlg::filterHitsOnKalmanTrack(), and trkf::TrackKalmanCheater::produce().

221  {
222  hits.reserve(hits.size() + fTrackMap.size());
223 
224  // Loop over KHitTracks and fill hits belonging to this track.
225 
226  unsigned int counter = 0; //Index of corresponding trajectory point
228  it != fTrackMap.end(); ++it) {
229  const KHitTrack& track = (*it).second;
230  ++counter;
231  // Extrack Hit from track.
232  const std::shared_ptr<const KHitBase>& hit = track.getHit();
233  if(const KHitWireX* phit = dynamic_cast<const KHitWireX*>(&*hit)) {
234  const art::Ptr<recob::Hit> prhit = phit->getHit();
235  if(!prhit.isNull()){
236  hits.push_back(prhit);
237  hittpindex.push_back(counter-1);
238  }
239  }
240  else if(const KHitWireLine* phit = dynamic_cast<const KHitWireLine*>(&*hit)) {
241  const art::Ptr<recob::Hit> prhit = phit->getHit();
242  if(!prhit.isNull()){
243  hits.push_back(prhit);
244  hittpindex.push_back(counter-1);
245  }
246  }
247  }
248  }
void reserve(size_type n)
Definition: PtrVector.h:343
intermediate_table::const_iterator const_iterator
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
size_type size() const
Definition: PtrVector.h:308
Detector simulation of raw signals on wires.
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:111
bool isNull() const
Definition: Ptr.h:328
Float_t track
Definition: plot.C:34
void trkf::KGTrack::fillTrack ( recob::Track track,
int  id 
) const

Fill a recob::Track.

Fill a recob::Track.

Arguments:

track - Track to fill.

Definition at line 128 of file KGTrack.cxx.

References 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.

Referenced by clear(), and trkf::TrackKalmanCheater::produce().

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

References fPrefPlane.

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

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

KHitTrack collection, indexed by path distance.

Definition at line 54 of file KGTrack.h.

References fTrackMap.

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

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

Modifiable KHitTrack collection, indexed by path distance.

Definition at line 71 of file KGTrack.h.

References addTrack(), endTrack(), fTrackMap, recalibrate(), and startTrack().

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

Validity flag.

Definition at line 66 of file KGTrack.h.

References fTrackMap.

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:111
size_t trkf::KGTrack::numHits ( ) const
inline

Number of measurements in track.

Definition at line 57 of file KGTrack.h.

References endTrack(), fTrackMap, and startTrack().

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:111
std::ostream & trkf::KGTrack::Print ( std::ostream &  out) const

Printout.

Printout

Definition at line 253 of file KGTrack.cxx.

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

Referenced by trkf::operator<<(), and TrackMap().

253  {
254 
255  int n = 0;
256 
257  double oldxyz[3] = {0., 0., 0.};
258  double len = 0.;
259  bool first = true;
260  for(auto const& ele : fTrackMap) {
261  double s = ele.first;
262  const KHitTrack& trh = ele.second;
263  double xyz[3];
264  double mom[3];
265  trh.getPosition(xyz);
266  trh.getMomentum(mom);
267  double tmom = std::sqrt(mom[0]*mom[0] + mom[1]*mom[1] + mom[2]*mom[2]);
268  if(tmom != 0.) {
269  mom[0] /= tmom;
270  mom[1] /= tmom;
271  mom[2] /= tmom;
272  }
273  if(!first) {
274  double dx = xyz[0] - oldxyz[0];
275  double dy = xyz[1] - oldxyz[1];
276  double dz = xyz[2] - oldxyz[2];
277  len += std::sqrt(dx*dx + dy*dy + dz*dz);
278  }
279  const KHitBase& hit = *(trh.getHit());
280  int plane = hit.getMeasPlane();
281  std::ios_base::fmtflags f = out.flags();
282  out << "State " << std::setw(4) << n
283  << ", path=" << std::setw(8) << std::fixed << std::setprecision(2) << s
284  << ", length=" << std::setw(8) << len
285  << ", x=" << std::setw(8) << xyz[0]
286  << ", y=" << std::setw(8) << xyz[1]
287  << ", z=" << std::setw(8) << xyz[2]
288  << ", dx=" << std::setw(8) << mom[0]
289  << ", dy=" << std::setw(8) << mom[1]
290  << ", dz=" << std::setw(8) << mom[2]
291  << ", plane=" << std::setw(1) << plane
292  << "\n";
293  out.flags(f);
294 
295  oldxyz[0] = xyz[0];
296  oldxyz[1] = xyz[1];
297  oldxyz[2] = xyz[2];
298 
299  ++n;
300  first = false;
301  }
302  return out;
303  }
Float_t s
Definition: plot.C:23
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:111
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 97 of file KGTrack.cxx.

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

Referenced by getTrackMap(), and trkf::KalmanFilterAlg::smoothTrack().

98  {
99  std::multimap<double, KHitTrack> newmap;
100 
101  // Loop over old track map.
102 
103  bool first = true;
104  double s0 = 0.;
106  i != fTrackMap.end(); ++i) {
107  KHitTrack& trh = (*i).second;
108  if(first) {
109  first = false;
110  s0 = trh.getPath();
111  }
112  double s = trh.getPath() - s0;
113  trh.setPath(s);
114  newmap.insert(std::make_pair(s, trh));
115  }
116 
117  // Update data member track map.
118 
119  fTrackMap.swap(newmap);
120  }
Float_t s
Definition: plot.C:23
intermediate_table::iterator iterator
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:111
const KHitTrack & trkf::KGTrack::startTrack ( ) const

Track at start point.

Throw exception if track is not valid.

Definition at line 33 of file KGTrack.cxx.

References fTrackMap, and isValid().

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

34  {
36 
37  if(!isValid())
38  throw cet::exception("KGTrack") << "Starting track is not valid.\n";
39 
40  // Return track.
41 
42  return (*fTrackMap.begin()).second;
43  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:111
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 59 of file KGTrack.cxx.

References fTrackMap, and isValid().

60  {
62 
63  if(!isValid())
64  throw cet::exception("KGTrack") << "Starting track is not valid.\n";
65 
66  // Return track.
67 
68  return (*fTrackMap.begin()).second;
69  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:111
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 fTrackMap, and Print().

Referenced by trkf::TrackKalmanCheater::produce().

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

Member Data Documentation

int trkf::KGTrack::fPrefPlane
private

Preferred plane.

Definition at line 108 of file KGTrack.h.

Referenced by getPrefPlane().

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

KHitTrack collection, indexed by path distance.

Definition at line 111 of file KGTrack.h.

Referenced by addTrack(), clear(), endTrack(), fillHits(), fillTrack(), getTrackMap(), isValid(), numHits(), Print(), recalibrate(), startTrack(), and TrackMap().


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