LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
KHitContainer.cxx
Go to the documentation of this file.
1 
12 
13 #include "cetlib_except/exception.h"
14 
15 namespace trkf {
16 
19  {}
20 
23  {}
24 
25  void fill(const art::PtrVector<recob::Hit>& hits, int only_plane)
26  {}
27 
30  {
31  fSorted.clear();
32  fUnsorted.clear();
33  fUnused.clear();
34  }
35 
38  {
39  fUnsorted.splice(fUnsorted.end(), fSorted);
40  fUnsorted.splice(fUnsorted.end(), fUnused);
41  }
42 
52  void KHitContainer::sort(const KTrack& trk, bool addUnsorted,
53  const Propagator* prop,
55  {
56  if(!prop)
57  throw cet::exception("KHitContainer") << __func__ << ": no propagator" << "\n";
58 
59  // Maybe transfer all objects in unsorted list to the sorted list.
60 
61  if(addUnsorted)
62  fSorted.splice(fSorted.end(), fUnsorted);
63 
64  // Loop over objects in sorted list.
65 
66  for(std::list<KHitGroup>::iterator igr = fSorted.begin();
67  igr != fSorted.end();) {
68 
69  KHitGroup& gr = *igr;
70 
71  // Get destination surface.
72 
73  const std::shared_ptr<const Surface>& psurf = gr.getSurface();
74 
75  // Make a fresh copy of the track and propagate it to
76  // the destination surface.
77 
78  KTrack trkp = trk;
79  boost::optional<double> dist = prop->vec_prop(trkp, psurf, dir, false, 0, 0);
80  if(!dist) {
81 
82  // If propagation failed, reset the path flag for this surface
83  // and move the KHitGroup to the unsorted list. Be careful to
84  // keep the list iterator valid.
85 
86  gr.setPath(false, 0.);
88  ++igr;
89  fUnsorted.splice(fUnsorted.end(), fSorted, it);
90  }
91  else {
92 
93  // Otherwise (if propagation succeeded), set the path distance
94  // and advance the iterator to the next KHitGroup.
95 
96  gr.setPath(true, *dist);
97  ++igr;
98  }
99  }
100 
101  // Finally, sort the sorted list in order of path distance.
102 
103  fSorted.sort();
104  }
105 
107  unsigned int KHitContainer::getPreferredPlane() const
108  {
109  // Count hits in each plane.
110 
111  std::vector<unsigned int> planehits(3, 0);
112 
113  // Loop over KHitGroups in the unsorted list.
114 
116  igr != fUnsorted.end(); ++igr) {
117 
118  const KHitGroup& gr = *igr;
119 
120  // Get plane of this KHitGroup.
121 
122  int plane = gr.getPlane();
123  ++planehits.at(plane);
124  }
125 
126  // Figure out which plane has the most hits.
127 
128  unsigned int prefplane = 0;
129  for(unsigned int i=0; i<planehits.size(); ++i) {
130  if(planehits[i] >= planehits[prefplane])
131  prefplane = i;
132  }
133  return prefplane;
134  }
135 
136 } // end namespace trkf
void sort(const KTrack &trk, bool addUnsorted, const Propagator *prop, Propagator::PropDirection dir=Propagator::UNKNOWN)
(Re)sort objects in unsorted and sorted lists.
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.
KHitContainer()
Default constructor.
unsigned int getPreferredPlane() const
Return the plane with the most KHitGroups in the unsorted list.
std::list< KHitGroup > fUnused
Unused KHitGroup objects.
virtual ~KHitContainer()
Destructor.
void hits()
Definition: readHits.C:15
intermediate_table::const_iterator const_iterator
std::list< KHitGroup > fUnsorted
Unsorted KHitGroup objects.
Definition: KHitContainer.h:99
boost::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
void clear()
Clear all lists.
TDirectory * dir
Definition: macro.C:5
virtual void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)=0
const std::shared_ptr< const Surface > & getSurface() const
Surface accessor.
Definition: KHitGroup.h:50
std::list< KHitGroup > fSorted
Sorted KHitGroup objects.
Definition: KHitContainer.h:98
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
PropDirection
Propagation direction enum.
Definition: Propagator.h:92
void reset()
Move all objects to unsorted list (from sorted and unused lists).
int getPlane() const
Plane index.
Definition: KHitGroup.h:53