KHitContainer.cxx
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 ///
3 /// \file KHitContainer.cxx
4 ///
5 /// \brief A collection of KHitGroups.
6 ///
7 /// \author H. Greenlee
8 ///
9 ////////////////////////////////////////////////////////////////////////
10 
12 
13 #include "cetlib_except/exception.h"
14 
15 namespace trkf {
16 
17  void
18  fill(const art::PtrVector<recob::Hit>& hits, int only_plane)
19  {}
20 
21  /// Clear all lists.
22  void
24  {
25  fSorted.clear();
26  fUnsorted.clear();
27  fUnused.clear();
28  }
29 
30  /// Move all objects to unsorted list (from sorted and unused lists).
31  void
33  {
34  fUnsorted.splice(fUnsorted.end(), fSorted);
35  fUnsorted.splice(fUnsorted.end(), fUnused);
36  }
37 
38  /// (Re)sort objects in unsorted and sorted lists.
39  ///
40  /// Arguments:
41  ///
42  /// trk - Track to be propagated.
43  /// addUnsorted - If true, include unsorted objects in sort.
44  /// prop - Propagator.
45  /// dir - Propagation direction.
46  ///
47  void
49  bool addUnsorted,
50  const Propagator& prop,
52  {
53  // Maybe transfer all objects in unsorted list to the sorted list.
54 
55  if (addUnsorted) fSorted.splice(fSorted.end(), fUnsorted);
56 
57  // Loop over objects in sorted list.
58 
59  for (std::list<KHitGroup>::iterator igr = fSorted.begin(); igr != fSorted.end();) {
60 
61  KHitGroup& gr = *igr;
62 
63  // Get destination surface.
64 
65  const std::shared_ptr<const Surface>& psurf = gr.getSurface();
66 
67  // Make a fresh copy of the track and propagate it to
68  // the destination surface.
69 
70  KTrack trkp = trk;
71  std::optional<double> dist = prop.vec_prop(trkp, psurf, dir, false, 0, 0);
72  if (!dist) {
73 
74  // If propagation failed, reset the path flag for this surface
75  // and move the KHitGroup to the unsorted list. Be careful to
76  // keep the list iterator valid.
77 
78  gr.setPath(false, 0.);
80  ++igr;
81  fUnsorted.splice(fUnsorted.end(), fSorted, it);
82  }
83  else {
84 
85  // Otherwise (if propagation succeeded), set the path distance
86  // and advance the iterator to the next KHitGroup.
87 
88  gr.setPath(true, *dist);
89  ++igr;
90  }
91  }
92 
93  // Finally, sort the sorted list in order of path distance.
94 
95  fSorted.sort();
96  }
97 
98  /// Return the plane with the most KHitGroups in the unsorted list.
99  unsigned int
101  {
102  // Count hits in each plane.
103 
104  std::vector<unsigned int> planehits(3, 0);
105 
106  // Loop over KHitGroups in the unsorted list.
107 
108  for (std::list<KHitGroup>::const_iterator igr = fUnsorted.begin(); igr != fUnsorted.end();
109  ++igr) {
110 
111  const KHitGroup& gr = *igr;
112 
113  // Get plane of this KHitGroup.
114 
115  int plane = gr.getPlane();
116  ++planehits.at(plane);
117  }
118 
119  // Figure out which plane has the most hits.
120 
121  unsigned int prefplane = 0;
122  for (unsigned int i = 0; i < planehits.size(); ++i) {
123  if (planehits[i] >= planehits[prefplane]) prefplane = i;
124  }
125  return prefplane;
126  }
127 
128 } // end namespace trkf
intermediate_table::iterator iterator
void setPath(bool has_path, double path)
Set path flag and estimated path distance.
Definition: KHitGroup.h:73
A collection of KHitGroups.
intermediate_table::const_iterator const_iterator
string dir
std::optional< double > vec_prop(KTrack &trk, const std::shared_ptr< const Surface > &psurf, PropDirection dir, bool doDedx, TrackMatrix *prop_matrix=0, TrackError *noise_matrix=0) const
Propagate without error (long distance).
Definition: Propagator.cxx:53
unsigned int getPreferredPlane() const
Return the plane with the most KHitGroups in the unsorted list.
std::list< KHitGroup > fUnused
Unused KHitGroup objects.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
std::list< KHitGroup > fUnsorted
Unsorted KHitGroup objects.
void clear()
Clear all lists.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
void sort(const KTrack &trk, bool addUnsorted, const Propagator &prop, Propagator::PropDirection dir=Propagator::UNKNOWN)
(Re)sort objects in unsorted and sorted lists.
const std::shared_ptr< const Surface > & getSurface() const
Surface accessor.
Definition: KHitGroup.h:50
std::list< KHitGroup > fSorted
Sorted KHitGroup objects.
PropDirection
Propagation direction enum.
Definition: Propagator.h:94
void reset()
Move all objects to unsorted list (from sorted and unused lists).
int getPlane() const
Plane index.
Definition: KHitGroup.h:53