ClusterParamsAlgBase.h
Go to the documentation of this file.
1 /** ****************************************************************************
2  * @file ClusterParamsAlgBase.h
3  * @brief Interface for a algorithm class computing cluster parameters
4  * @author petrillo@fnal.gov
5  * @date January 21, 2015
6  * @see ClusterParamsAlg.h StandardClusterParamsAlg.h
7  *
8  * Changes:
9  * 20150121 Gianluca Petrillo (petrillo@fnal.gov)
10  * structure shaped on ClusterParamsAlg class by Andrzej Szelc
11  *
12  * ****************************************************************************/
13 
14 #ifndef CLUSTERPARAMSALGBASE_H
15 #define CLUSTERPARAMSALGBASE_H
16 
17 // C/C++ standard libraries
18 #include <algorithm> // std::transform()
19 #include <stdexcept> // std::logic_error
20 #include <vector>
21 
22 // LArSoft libraries
24 
25 namespace util {
26  class GeometryUtilities;
27 }
28 
29 /// Cluster reconstruction namespace
30 namespace cluster {
31 
32  /// Implementation details of cluster namespace
33  namespace details {
34 
35  /// Type for a simple measurement: value and error
36  template <typename T>
37  class Measure_t : public std::pair<T, T> {
38  using Base_t = std::pair<T, T>;
39 
40  public:
41  using Data_t = T;
42 
43  /// Default constructor: initializes to 0
44  Measure_t() : Base_t(Data_t(0), Data_t(0)) {}
45 
46  /// Constructor: initializes to the specified value, error is 0
47  Measure_t(Data_t value) : Base_t(value, Data_t(0)) {}
48 
49  /// Constructor: initializes to the specified value and error
50  Measure_t(Data_t value, Data_t error) : Base_t(value, error) {}
51 
52  Data_t
53  value() const
54  {
55  return Base_t::first;
56  }
57  Data_t&
59  {
60  return Base_t::first;
61  }
62 
63  Data_t
64  error() const
65  {
66  return Base_t::second;
67  }
68  Data_t&
70  {
71  return Base_t::second;
72  }
73  }; // Measure_t
74 
75  } // namespace details
76 
77  /**
78  * @brief Algorithm collection class computing cluster parameters
79  * @see ClusterParamsAlg
80  *
81  * This class is an interface only.
82  * The implementing classes should implement constructors able to read the
83  * necessary information from hit lists, and any of the virtual algorithms.
84  *
85  * The interface allows for the single extraction of the information required
86  * in recob::Cluster version 14.
87  * The implementation can compute and cache different variables at once.
88  * The accessor functions are non-const, allowing the caching of the quantity
89  * after computation (without using mutable cache members).
90  *
91  * The default algorithm functions throw an exception.
92  *
93  * The algorithms require a list of hits as input. The structure chosen for
94  * this interface is recob::Hit from LArSoft, since it is complete by
95  * definition and it does not carry deep dependences (in fact, recob::Hit
96  * version 14 has only larreco/SimpleTypesAndConstants.h as compile-time
97  * dependency, and no external link-time dependency beside standard C++).
98  *
99  */
101  public:
102  /// Type used to return values with errors
103  using Measure_t = details::Measure_t<float>;
104 
105  virtual ~ClusterParamsAlgBase() = default;
106 
107  /**
108  * @brief Restores the class to post-configuration, pre-initialization state
109  *
110  * This function is expected to be called before SetHits(), and the
111  * implementation might call it in SetHits() itself.
112  */
113  virtual void
115  {}
116 
117  /**
118  * @brief Sets the list of input hits
119  * @param hits list of pointers to hits
120  * @throw undefined in case of error, this method can throw (anything)
121  *
122  * The hits are in the LArSoft format of recob::Hits, that should have
123  * enough information for all the algorithms.
124  * The hits are passed as constant pointers. The implementation is expected
125  * to either copy the vector (not just to keep a reference to it, since
126  * the vector might be temporary) or to translated the required information
127  * from the hits into its own internal format.
128  * The hits are expected to exist as long as this object is used, until
129  * the next Clear() call.
130  * It is recommended that this method call Clear() at the beginning.
131  * This is left to the implementation, that might still implement a
132  * different strategy.
133  */
134  virtual void SetHits(util::GeometryUtilities const& gser,
135  std::vector<recob::Hit const*> const& hits) = 0;
136 
137  /**
138  * @brief Sets the list of input hits
139  * @param hits list of hits (hits will not be modified)
140  * @throw undefined in case of error, this method can throw (anything)
141  *
142  * The same general directions apply as for SetHits() version with pointers.
143  * This version takes a list of recob::Hit, rather than their pointers.
144  * It can simplify upstream handling when the original list is not
145  * recob::Hit and creation of temporary recob::Hit is needed.
146  * In that case, managing to obtain pointers to these temporary objects can
147  * be inefficient.
148  *
149  * The default implementation provided here is not efficient either, since
150  * it just creates an additional vector of recob::Hit pointers and uses it.
151  * If an implementation is concerned with efficiency, it can reimplement
152  * this to initialize the algorithm in a more direct way.
153  */
154  virtual void
155  SetHits(util::GeometryUtilities const& gser, std::vector<recob::Hit> const& hits)
156  {
157  std::vector<recob::Hit const*> hitptrs;
158  hitptrs.reserve(hits.size());
159  std::transform(hits.begin(),
160  hits.end(),
161  std::back_inserter(hitptrs),
162  [](recob::Hit const& hit) { return &hit; });
163  SetHits(gser, hitptrs);
164  }
165 
166  /// Set the verbosity level
167  virtual void
168  SetVerbose(int level = 1)
169  {
170  verbose = level;
171  }
172 
173  //@{
174  /**
175  * @brief Computes the charge on the first and last wire of the track
176  * @return the charge in ADC counts, with uncertainty
177  */
178  virtual Measure_t
180  {
181  throw NotImplemented(__func__);
182  }
183  virtual Measure_t
185  {
186  throw NotImplemented(__func__);
187  }
188  //@}
189 
190  //@{
191  /**
192  * @brief Computes the angle at the start or end of the cluster
193  * @return angle at the start of the cluster, in radians
194  */
195  virtual Measure_t
197  {
198  throw NotImplemented(__func__);
199  }
200  virtual Measure_t
202  {
203  throw NotImplemented(__func__);
204  }
205  //@}
206 
207  //@{
208  /**
209  * @brief Computes the opening angle at the start or end of the cluster
210  * @return angle at the start of the cluster, in radians
211  */
212  virtual Measure_t
214  {
215  throw NotImplemented(__func__);
216  }
217  virtual Measure_t
219  {
220  throw NotImplemented(__func__);
221  }
222  //@}
223 
224  /// @name Cluster charge
225  /// @{
226  /**
227  * @brief Computes the total charge of the cluster from Hit::Integral()
228  * @return total charge of the cluster, in ADC count units
229  * @see IntegralStdDev(), SummedADC()
230  */
231  virtual Measure_t
233  {
234  throw NotImplemented(__func__);
235  }
236 
237  /**
238  * @brief Computes the standard deviation on the charge of the cluster hits
239  * @return the standard deviation of charge of hits, in ADC count units
240  * @see Integral()
241  *
242  * Hit charge is obtained by recob::Hit::Integral().
243  */
244  virtual Measure_t
246  {
247  throw NotImplemented(__func__);
248  }
249 
250  /**
251  * @brief Computes the total charge of the cluster from Hit::SummedADC()
252  * @return total charge of the cluster, in ADC count units
253  * @see SummedADCStdDev(), Integral()
254  */
255  virtual Measure_t
257  {
258  throw NotImplemented(__func__);
259  }
260 
261  /**
262  * @brief Computes the standard deviation on the charge of the cluster hits
263  * @return the standard deviation of charge of hits, in ADC count units
264  * @see SummedADC()
265  *
266  * Hit charge is obtained by recob::Hit::SummedADC().
267  */
268  virtual Measure_t
270  {
271  throw NotImplemented(__func__);
272  }
273 
274  /// @}
275 
276  /// Returns the number of hits in the cluster
277  virtual size_t
279  {
280  throw NotImplemented(__func__);
281  }
282 
283  /**
284  * @brief Fraction of wires in the cluster with more than one hit
285  * @return fraction of wires with more than one hit, or 0 if no wires
286  *
287  * Returns a quantity defined as NMultiHitWires / NWires,
288  * where NWires is the number of wires hosting at least one hit of this
289  * cluster, and NMultiHitWires is the number of wires which have more
290  * than just one hit.
291  */
292  virtual float
294  {
295  throw NotImplemented(__func__);
296  }
297 
298  /**
299  * @brief Computes the width of the cluster
300  * @return width of the cluster
301  *
302  */
303  virtual float
305  {
306  throw NotImplemented(__func__);
307  }
308 
309  protected:
310  int verbose = 0; ///< verbosity level: 0 is normal, negative is even quieter
311 
312  static std::logic_error
314  {
315  return std::logic_error(function_name + "() not implemented.");
316  }
317 
318  }; //class ClusterParamsAlgBase
319 
320 } //namespace cluster
321 
322 #endif // CLUSTERPARAMSALGBASE_H
virtual Measure_t EndCharge(util::GeometryUtilities const &gser)
Namespace for general, non-LArSoft-specific utilities.
virtual Measure_t IntegralStdDev()
Computes the standard deviation on the charge of the cluster hits.
static std::logic_error NotImplemented(std::string function_name)
std::string string
Definition: nybbler.cc:12
virtual void SetVerbose(int level=1)
Set the verbosity level.
error
Definition: include.cc:26
Cluster finding and building.
virtual void Clear()
Restores the class to post-configuration, pre-initialization state.
virtual void SetHits(util::GeometryUtilities const &gser, std::vector< recob::Hit > const &hits)
Sets the list of input hits.
Algorithm collection class computing cluster parameters.
virtual Measure_t SummedADCStdDev()
Computes the standard deviation on the charge of the cluster hits.
Measure_t()
Default constructor: initializes to 0.
virtual Measure_t StartOpeningAngle()
Computes the opening angle at the start or end of the cluster.
Type for a simple measurement: value and error.
virtual Measure_t StartAngle()
Computes the angle at the start or end of the cluster.
virtual Measure_t StartCharge(util::GeometryUtilities const &gser)
Computes the charge on the first and last wire of the track.
details::Measure_t< float > Measure_t
Type used to return values with errors.
virtual float MultipleHitDensity()
Fraction of wires in the cluster with more than one hit.
verbose
Definition: train.py:477
virtual Measure_t Integral()
Computes the total charge of the cluster from Hit::Integral()
Declaration of signal hit object.
virtual float Width(util::GeometryUtilities const &)
Computes the width of the cluster.
virtual Measure_t SummedADC()
Computes the total charge of the cluster from Hit::SummedADC()
Measure_t(Data_t value)
Constructor: initializes to the specified value, error is 0.
Measure_t(Data_t value, Data_t error)
Constructor: initializes to the specified value and error.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
virtual size_t NHits()
Returns the number of hits in the cluster.