All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
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,
KHitTrack
TrackMap () 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:133

Member Function Documentation

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

Add track.

Definition at line 81 of file KGTrack.cxx.

82  {
83  if (!trh.isValid()) throw cet::exception("KGTrack") << "Adding invalid track to KGTrack.\n";
84  fTrackMap.insert(std::make_pair(trh.getPath() + trh.getHit()->getPredDistance(), trh));
85  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
void trkf::KGTrack::clear ( )
inline

Clear track collection.

Definition at line 107 of file KGTrack.h.

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

Track at end point.

Throw exception if track is not valid.

Definition at line 42 of file KGTrack.cxx.

43  {
44  /// Throw exception if track is not valid.
45 
46  if (!isValid()) throw cet::exception("KGTrack") << "Ending track is not valid.\n";
47 
48  // Return track.
49 
50  return (*fTrackMap.rbegin()).second;
51  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
bool isValid() const
Validity flag.
Definition: KGTrack.h:79
KHitTrack & trkf::KGTrack::endTrack ( )

Modifiable track at end point.

Throw exception if track is not valid.

Definition at line 68 of file KGTrack.cxx.

69  {
70  /// Throw exception if track is not valid.
71 
72  if (!isValid()) throw cet::exception("KGTrack") << "Ending track is not valid.\n";
73 
74  // Return track.
75 
76  return (*fTrackMap.rbegin()).second;
77  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
bool isValid() const
Validity flag.
Definition: KGTrack.h:79
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 224 of file KGTrack.cxx.

225  {
226  hits.reserve(hits.size() + fTrackMap.size());
227 
228  // Loop over KHitTracks and fill hits belonging to this track.
229 
230  unsigned int counter = 0; //Index of corresponding trajectory point
231  for (std::multimap<double, KHitTrack>::const_iterator it = fTrackMap.begin();
232  it != fTrackMap.end();
233  ++it) {
234  const KHitTrack& track = (*it).second;
235  ++counter;
236  // Extrack Hit from track.
237  const std::shared_ptr<const KHitBase>& hit = track.getHit();
238  if (const KHitWireX* phit = dynamic_cast<const KHitWireX*>(&*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  else if (const KHitWireLine* phit = dynamic_cast<const KHitWireLine*>(&*hit)) {
246  const art::Ptr<recob::Hit> prhit = phit->getHit();
247  if (!prhit.isNull()) {
248  hits.push_back(prhit);
249  hittpindex.push_back(counter - 1);
250  }
251  }
252  }
253  }
process_name use argoneut_mc_hitfinder track
process_name hit
Definition: cheaterreco.fcl:51
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
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 126 of file KGTrack.cxx.

129  {
130 
131  // Make propagator for propating to standard track surface.
132 
133  PropXYZPlane prop(detProp, 0., false);
134 
135  // Fill collections of trajectory points and direction vectors.
136 
137  std::vector<recob::tracking::Point_t> xyz;
138  std::vector<recob::tracking::Vector_t> pxpypz;
139  std::vector<recob::tracking::SMatrixSym55> cov;
140  std::vector<recob::TrajectoryPointFlags> outFlags;
141 
142  xyz.reserve(fTrackMap.size());
143  pxpypz.reserve(fTrackMap.size());
144  outFlags.reserve(fTrackMap.size());
145 
146  // Loop over KHitTracks.
147 
148  int ndof = 0;
149  float totChi2 = 0.;
150  unsigned int n = 0;
151  for (std::multimap<double, KHitTrack>::const_iterator itr = fTrackMap.begin();
152  itr != fTrackMap.end();
153  ++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.) throw cet::exception("KGTrack") << __func__ << ": null momentum\n";
169  pxpypz.push_back({mom[0], mom[1], mom[2]});
170 
171  ndof += 1;
172  totChi2 += trh.getChisq();
173  outFlags.emplace_back(n, recob::TrajectoryPointFlags::makeMask());
174 
175  // Fill error matrix.
176 
178 
179  // Construct surface perpendicular to track momentun, and
180  // propagate track to that surface (zero distance).
181 
182  const std::shared_ptr<const Surface> psurf(
183  new SurfXYZPlane(pos[0], pos[1], pos[2], mom[0], mom[1], mom[2]));
184  KETrack tre(trh);
185  std::optional<double> dist = prop.err_prop(tre, psurf, Propagator::UNKNOWN, false);
186  if (!dist) throw cet::exception("KGTrack") << __func__ << ": error propagation failed\n";
187  for (int i = 0; i < 5; ++i) {
188  for (int j = 0; j < 5; ++j)
189  covar(i, j) = tre.getError()(i, j);
190  }
191 
192  // Only save first and last error matrix.
193 
194  if (cov.size() < 2)
195  cov.push_back(covar);
196  else
197  cov.back() = covar;
198  }
199 
200  // Fill track.
201 
202  ndof = ndof - 4; //fit measures 4 parameters: position and direction on plane
203  if (xyz.size() >= 2) {
204  track = recob::Track(std::move(xyz),
205  std::move(pxpypz),
206  std::move(outFlags),
207  true,
208  this->startTrack().PdgCode(),
209  totChi2,
210  ndof,
211  std::move(cov.front()),
212  std::move(cov.back()),
213  id);
214  }
215  }
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
Definition: TrackingTypes.h:85
pdgs p
Definition: selectors.fcl:22
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
TrackCollectionProxyElement< TrackCollProxy > Track
Proxy to an element of a proxy collection of recob::Track objects.
const KHitTrack & startTrack() const
Track at start point.
Definition: KGTrack.cxx:31
auto const detProp
int trkf::KGTrack::getPrefPlane ( ) const
inline

Definition at line 52 of file KGTrack.h.

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

KHitTrack collection, indexed by path distance.

Definition at line 59 of file KGTrack.h.

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

Modifiable KHitTrack collection, indexed by path distance.

Definition at line 88 of file KGTrack.h.

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

Validity flag.

Definition at line 79 of file KGTrack.h.

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

Number of measurements in track.

Definition at line 66 of file KGTrack.h.

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

Printout.

Printout

Definition at line 259 of file KGTrack.cxx.

260  {
261 
262  int n = 0;
263 
264  double oldxyz[3] = {0., 0., 0.};
265  double len = 0.;
266  bool first = true;
267  for (auto const& ele : fTrackMap) {
268  double s = ele.first;
269  const KHitTrack& trh = ele.second;
270  double xyz[3];
271  double mom[3];
272  trh.getPosition(xyz);
273  trh.getMomentum(mom);
274  double tmom = std::sqrt(mom[0] * mom[0] + mom[1] * mom[1] + mom[2] * mom[2]);
275  if (tmom != 0.) {
276  mom[0] /= tmom;
277  mom[1] /= tmom;
278  mom[2] /= tmom;
279  }
280  if (!first) {
281  double dx = xyz[0] - oldxyz[0];
282  double dy = xyz[1] - oldxyz[1];
283  double dz = xyz[2] - oldxyz[2];
284  len += std::sqrt(dx * dx + dy * dy + dz * dz);
285  }
286  const KHitBase& hit = *(trh.getHit());
287  int plane = hit.getMeasPlane();
288  std::ios_base::fmtflags f = out.flags();
289  out << "State " << std::setw(4) << n << ", path=" << std::setw(8) << std::fixed
290  << std::setprecision(2) << s << ", length=" << std::setw(8) << len
291  << ", x=" << std::setw(8) << xyz[0] << ", y=" << std::setw(8) << xyz[1]
292  << ", z=" << std::setw(8) << xyz[2] << ", dx=" << std::setw(8) << mom[0]
293  << ", dy=" << std::setw(8) << mom[1] << ", dz=" << std::setw(8) << mom[2]
294  << ", plane=" << std::setw(1) << plane << "\n";
295  out.flags(f);
296 
297  oldxyz[0] = xyz[0];
298  oldxyz[1] = xyz[1];
299  oldxyz[2] = xyz[2];
300 
301  ++n;
302  first = false;
303  }
304  return out;
305  }
process_name hit
Definition: cheaterreco.fcl:51
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
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 94 of file KGTrack.cxx.

95  {
96  std::multimap<double, KHitTrack> newmap;
97 
98  // Loop over old track map.
99 
100  bool first = true;
101  double s0 = 0.;
102  for (std::multimap<double, KHitTrack>::iterator i = fTrackMap.begin(); i != fTrackMap.end();
103  ++i) {
104  KHitTrack& trh = (*i).second;
105  if (first) {
106  first = false;
107  s0 = trh.getPath();
108  }
109  double s = trh.getPath() - s0;
110  trh.setPath(s);
111  newmap.insert(std::make_pair(s, trh));
112  }
113 
114  // Update data member track map.
115 
116  fTrackMap.swap(newmap);
117  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
const KHitTrack & trkf::KGTrack::startTrack ( ) const

Track at start point.

Definition at line 31 of file KGTrack.cxx.

32  {
33  if (!isValid()) throw cet::exception("KGTrack") << "Starting track is not valid.\n";
34 
35  // Return track.
36 
37  return (*fTrackMap.begin()).second;
38  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
bool isValid() const
Validity flag.
Definition: KGTrack.h:79
KHitTrack & trkf::KGTrack::startTrack ( )

Modifiable track at start point.

Throw exception if track is not valid.

Definition at line 55 of file KGTrack.cxx.

56  {
57  /// Throw exception if track is not valid.
58 
59  if (!isValid()) throw cet::exception("KGTrack") << "Starting track is not valid.\n";
60 
61  // Return track.
62 
63  return (*fTrackMap.begin()).second;
64  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136
bool isValid() const
Validity flag.
Definition: KGTrack.h:79
const std::multimap<double, KHitTrack> trkf::KGTrack::TrackMap ( ) const
inline

Definition at line 123 of file KGTrack.h.

124  {
125  return fTrackMap;
126  }
std::multimap< double, KHitTrack > fTrackMap
KHitTrack collection, indexed by path distance.
Definition: KGTrack.h:136

Member Data Documentation

int trkf::KGTrack::fPrefPlane
private

Preferred plane.

Definition at line 133 of file KGTrack.h.

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

KHitTrack collection, indexed by path distance.

Definition at line 136 of file KGTrack.h.


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