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