LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
KHitContainer.cxx
Go to the documentation of this file.
1 
12 
13 #include "cetlib_except/exception.h"
14 
15 namespace trkf {
16 
17  void fill(const art::PtrVector<recob::Hit>& hits, int only_plane) {}
18 
21  {
22  fSorted.clear();
23  fUnsorted.clear();
24  fUnused.clear();
25  }
26 
29  {
30  fUnsorted.splice(fUnsorted.end(), fSorted);
31  fUnsorted.splice(fUnsorted.end(), fUnused);
32  }
33 
44  bool addUnsorted,
45  const Propagator& prop,
47  {
48  // Maybe transfer all objects in unsorted list to the sorted list.
49 
50  if (addUnsorted) fSorted.splice(fSorted.end(), fUnsorted);
51 
52  // Loop over objects in sorted list.
53 
54  for (std::list<KHitGroup>::iterator igr = fSorted.begin(); igr != fSorted.end();) {
55 
56  KHitGroup& gr = *igr;
57 
58  // Get destination surface.
59 
60  const std::shared_ptr<const Surface>& psurf = gr.getSurface();
61 
62  // Make a fresh copy of the track and propagate it to
63  // the destination surface.
64 
65  KTrack trkp = trk;
66  std::optional<double> dist = prop.vec_prop(trkp, psurf, dir, false, 0, 0);
67  if (!dist) {
68 
69  // If propagation failed, reset the path flag for this surface
70  // and move the KHitGroup to the unsorted list. Be careful to
71  // keep the list iterator valid.
72 
73  gr.setPath(false, 0.);
75  ++igr;
76  fUnsorted.splice(fUnsorted.end(), fSorted, it);
77  }
78  else {
79 
80  // Otherwise (if propagation succeeded), set the path distance
81  // and advance the iterator to the next KHitGroup.
82 
83  gr.setPath(true, *dist);
84  ++igr;
85  }
86  }
87 
88  // Finally, sort the sorted list in order of path distance.
89 
90  fSorted.sort();
91  }
92 
94  unsigned int KHitContainer::getPreferredPlane() const
95  {
96  // Count hits in each plane.
97 
98  std::vector<unsigned int> planehits(3, 0);
99 
100  // Loop over KHitGroups in the unsorted list.
101 
102  for (std::list<KHitGroup>::const_iterator igr = fUnsorted.begin(); igr != fUnsorted.end();
103  ++igr) {
104 
105  const KHitGroup& gr = *igr;
106 
107  // Get plane of this KHitGroup.
108 
109  int plane = gr.getPlane();
110  ++planehits.at(plane);
111  }
112 
113  // Figure out which plane has the most hits.
114 
115  unsigned int prefplane = 0;
116  for (unsigned int i = 0; i < planehits.size(); ++i) {
117  if (planehits[i] >= planehits[prefplane]) prefplane = i;
118  }
119  return prefplane;
120  }
121 
122 } // end namespace trkf
intermediate_table::iterator iterator
void setPath(bool has_path, double path)
Set path flag and estimated path distance.
Definition: KHitGroup.h:71
A collection of KHitGroups.
intermediate_table::const_iterator const_iterator
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:52
unsigned int getPreferredPlane() const
Return the plane with the most KHitGroups in the unsorted list.
std::list< KHitGroup > fUnused
Unused KHitGroup objects.
Definition: KHitContainer.h:99
void hits()
Definition: readHits.C:15
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
std::list< KHitGroup > fUnsorted
Unsorted KHitGroup objects.
Definition: KHitContainer.h:98
void clear()
Clear all lists.
TDirectory * dir
Definition: macro.C:5
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:48
std::list< KHitGroup > fSorted
Sorted KHitGroup objects.
Definition: KHitContainer.h:97
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:51