ClusterParamsAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // ClusterParamsAlg.h
3 //
4 // ClusterParamsAlg class
5 //
6 // Andrzej Szelc (andrzej.szelc@yale.edu)
7 //
8 ////////////////////////////////////////////////////////////////////////
9 #ifndef CLUSTERPARAMSALG_H
10 #define CLUSTERPARAMSALG_H
11 
12 #include <string>
13 #include <vector>
14 
15 #include "ClusterParams.h"
17 
18 namespace util {
19  class GeometryUtilities;
20 }
21 
22 namespace cluster {
23 
25  public:
27  ClusterParamsAlg(const std::vector<util::PxHit>&);
28 
29  void Initialize();
30 
31  void
32  SetMinNHits(size_t nhit)
33  {
34  fMinNHits = nhit;
35  }
36 
37  size_t
38  MinNHits() const
39  {
40  return fMinNHits;
41  }
42 
43  int SetHits(const std::vector<util::PxHit>&);
44 
45  void
47  {
48  fQMinRefDir = qmin;
49  }
50 
51  void
52  SetVerbose(bool yes = true)
53  {
54  verbose = yes;
55  }
56 
57  template <typename Stream>
58  void TimeReport(Stream& stream) const;
59 
60  /**
61  * This function returns a feature vector suitable for a neural net
62  * This function uses the data from cluster_params but packages it
63  * up in a different way, and so is inappropriate to include in
64  * clusterParams.hh. That's why it's here.
65  * @param data takes a reference to a vector< float>
66  */
67  void GetFANNVector(std::vector<float>& data);
68  // std::vector<float> & GetFANNVector();
69 
70  /**
71  * For debugging purposes, prints the result of GetFANNVector
72  * in a nicely formatted form.
73  * @return [description]
74  */
75  void PrintFANNVector();
76 
77  /**
78  Runs all the functions which calculate cluster params
79  and stashes the results in the private ClusterParams
80  struct.
81 
82  @param override_DoGetAverages force re-execution of GetAverages()
83  @param override_DoGetRoughAxis force re-execution of GetRoughAxis()
84  @param override_DoGetProfileInfo force re-execution of GetProfileInfo()
85  @param override_DoRefineStartPoints force re-execution of RefineStartPoints()
86  @param override_DoGetFinalSlope force re-execution of GetFinalSlope()
87  @param override_DoEndCharge force re-execution of GetEndCharges()
88  */
89  void FillParams(util::GeometryUtilities const& gser,
90  bool override_DoGetAverages = false,
91  bool override_DoGetRoughAxis = false,
92  bool override_DoGetProfileInfo = false,
93  bool override_DoRefineStartPointsAndDirection = false,
94  bool override_DoGetFinalSlope = false,
95  bool override_DoTrackShowerSep = false,
96  bool override_DoEndCharge = false);
97 
98  const cluster_params&
99  GetParams() const
100  {
101  return fParams;
102  }
103 
104  /**
105  Calculates the following variables:
106  mean_charge
107  mean_x
108  mean_y
109  charge_wgt_x
110  charge_wgt_y
111  eigenvalue_principal
112  eigenvalue_secondary
113  multi_hit_wires
114  N_Wires
115  @param override force recalculation of variables
116  */
117  void GetAverages(bool override = false);
118 
119  /**
120  Calculates the following variables:
121  verticalness
122  fRough2DSlope
123  fRough2DIntercept
124  @param override [description]
125  */
126  void GetRoughAxis(bool override = false);
127 
128  /**
129  Calculates the following variables:
130  opening_angle
131  opening_angle_highcharge
132  closing_angle
133  closing_angle_highcharge
134  offaxis_hits
135  @param override [description]
136  */
137  void GetProfileInfo(util::GeometryUtilities const& gser, bool override = false);
138 
139  /**
140  Calculates the following variables:
141  length
142  width
143  */
144  void RefineStartPoints(util::GeometryUtilities const& gser);
145 
146  /**
147  Calculates the following variables:
148  hit_density_1D
149  hit_density_2D
150  angle_2d
151  direction
152  @param override [description]
153  */
154  void GetFinalSlope(util::GeometryUtilities const& gser, bool override = false);
155 
156  /**
157  Calculates the following variables:
158  start_charge
159  end_charge
160  @param override_ force recompute the variables
161  @see StartCharge(), EndCharge()
162  */
163  void GetEndCharges(util::GeometryUtilities const& gser, bool override_ = false);
164 
165  void RefineDirection(bool override = false);
166 
167  void RefineStartPointAndDirection(util::GeometryUtilities const& gser, bool override = false);
168 
169  void TrackShowerSeparation(bool override = false);
170 
171  void
173  {
174  fNeuralNetPath = s;
175  }
176 
177  void FillPolygon(util::GeometryUtilities const& gser);
178 
179  void GetOpeningAngle();
180 
181  const util::PxPoint&
183  {
184  return fRoughBeginPoint;
185  }
186  const util::PxPoint&
188  {
189  return fRoughEndPoint;
190  }
191 
192  double
194  {
195  return fRough2DSlope;
196  }
197  double
199  {
200  return fRough2DIntercept;
201  }
202 
203  /**
204  * @brief Returns the expected charge at the beginning of the cluster
205  * @param nbins use at least this number of charge bins from charge profile
206  * @param length space at the start of cluster where to collect charge, in cm
207  * @brief the expected charge at the beginning of the cluster
208  * @see EndCharge(), IntegrateFitCharge()
209  *
210  * ClusterParamsAlg extracts a binned charge profile, parametrized versus
211  * the distance from the start of the cluster.
212  * All the charge on the plane orthogonal to cluster axis is collapsed into
213  * the point where that plane intersects the axis.
214  * The resulting 1D distribution is then binned.
215  *
216  * This method returns the charge under the first length cm of the cluster.
217  *
218  * This method considers the first nbins of this charge distribution and
219  * through a linear fit determines the expected charge at the first bin.
220  * Then, it scales the result to reflect how much charge would be deposited
221  * in a space of length centimetres, according to this linear fit.
222  *
223  * Note that length may be 0 (charge will be 0) or negative (sort of
224  * extrapolation ahead of the cluster start).
225  *
226  * For more details, see IntegrateFitCharge().
227  */
228  double StartCharge(util::GeometryUtilities const& gser,
229  float length = 1.,
230  unsigned int nbins = 10);
231 
232  /**
233  * @brief Returns the expected charge at the end of the cluster
234  * @param nbins use at least this number of charge bins from charge profile
235  * @param length space before the end of cluster where to collect charge, in cm
236  * @brief the expected charge at the end of the cluster
237  * @see StartCharge(), IntegrateFitCharge()
238  *
239  * This method returns the charge under the last length cm of the cluster.
240  * See StartCharge() for a detailed explanation.
241  * For even more details, see IntegrateFitCharge().
242  */
243  double EndCharge(util::GeometryUtilities const& gser,
244  float length = 1.,
245  unsigned int nbins = 10);
246 
247  /**
248  * @brief Returns the number of multiple hits per wire
249  * @return the number of multiple hits per wire
250  *
251  * This returns the fraction of wires that have more than one hit belonging
252  * to this cluster.
253  */
254  float MultipleHitWires();
255 
256  /**
257  * @brief Returns the number of multiple hits per wire
258  * @return the number of multiple hits per wire
259  *
260  * This returns the number of wires with mmore than one hit belonging
261  * to this cluster, divided by the cluster length in cm.
262  */
263  float MultipleHitDensity(util::GeometryUtilities const& gser);
264 
265  void EnableFANN();
266 
267  void
269  {
270  enableFANN = false;
271  }
272 
273  size_t
274  GetNHits() const
275  {
276  return fHitVector.size();
277  }
278  const std::vector<util::PxHit>&
279  GetHitVector() const
280  {
281  return fHitVector;
282  }
283  int
284  Plane() const
285  {
286  return fPlane;
287  }
288  void SetPlane(int p);
289 
290  protected:
291  /// Cut value for # hits: below this value clusters are not evaluated
292  size_t fMinNHits;
293 
294  /**
295  This vector holds the pointer to hits.
296  This should be used for computation for speed.
297  */
298  std::vector<util::PxHit> fHitVector;
299 
300  // bool to control debug/verbose mode defaults to off.
301  bool verbose;
302 
303  //settable parameters:
304  std::vector<double> fChargeCutoffThreshold;
305  int fPlane;
306 
307  //this is required in RefineDirection
308  double fQMinRefDir;
309 
310  std::vector<double> fChargeProfile;
311  std::vector<double> fCoarseChargeProfile;
312 
313  std::vector<double> fChargeProfileNew;
314 
321 
322  //extreme intercepts using the rough_2d_slope
327 
328  // book keeping variables to validate completion of methods:
338 
339  double fRough2DSlope; // slope
340  double fRough2DIntercept; // slope
344 
345  /**
346  * @brief Integrates the charge between two positions in the cluster axis
347  * @param from_length position on the axis to start integration from, in cm
348  * @param to_length position on the axis to end integration at, in cm
349  * @param fit_first_bin first bin for the charge fit
350  * @param fit_end_bin next-to-last bin for the charge fit
351  * @return the charged fit integrated in the specified range, in ADC counts
352  * @see StartCharge(), EndCharge()
353  *
354  * This function provides an almost-punctual charge at a position in the
355  * axis. Since the effective punctual charge is 0 ADC counts by definition,
356  * the charge can be integrated for some length.
357  * The procedure is made of two steps:
358  * 1. the charge profile is parametrized with a linear fit within the
359  * specified region
360  * 2. an integration of that fit is performed along the segment specified.
361  *
362  * The region at point 1. is from `fit_first_bin` to `fit_end_bin`. These
363  * are specified in bin units. The binning is the one of the charge profile.
364  * It is suggested that a few bins are always kept, say 5 to 10, to reduce
365  * statistical fluctuations but maintaining a decent hypothesis of linearity
366  * along the range.
367  * The linear fit weighs all the bins in the profile the same.
368  *
369  * The region at point to is from `from_length` to `to_length`, and it is
370  * measured in cm along the cluster axis, starting at the start of the
371  * cluster.
372  */
373  double IntegrateFitCharge(util::GeometryUtilities const& gser,
374  double from_length,
375  double to_length,
376  unsigned int fit_first_bin,
377  unsigned int fit_end_bin);
378 
379  /// Returns the integral of f(x) = mx + q defined in [x1, x2]
380  static double LinearIntegral(double m, double q, double x1, double x2);
381 
382  public:
384 
386 
387  std::vector<std::string> fTimeRecord_ProcName;
388  std::vector<double> fTimeRecord_ProcTime;
389 
390  }; //class ClusterParamsAlg
391 
392 } //namespace cluster
393 
394 //------------------------------------------------------------------------------
395 //--- template implementation
396 //---
397 
398 namespace cluster {
399 
400  template <typename Stream>
401  void
402  ClusterParamsAlg::TimeReport(Stream& stream) const
403  {
404 
405  stream << " <<ClusterParamsAlg::TimeReport>> starts...\n";
406  for (size_t i = 0; i < fTimeRecord_ProcName.size(); ++i) {
407 
408  stream << " Function: " << fTimeRecord_ProcName[i].c_str()
409  << " ... Time = " << fTimeRecord_ProcTime[i] << " [s]\n";
410  }
411  stream << " <<ClusterParamsAlg::TimeReport>> ends...\n";
412  }
413 
414 } //namespace cluster
415 
416 #endif
const util::PxPoint & RoughStartPoint()
Namespace for general, non-LArSoft-specific utilities.
std::vector< double > fCoarseChargeProfile
void SetRefineDirectionQMin(double qmin)
std::vector< std::string > fTimeRecord_ProcName
std::string string
Definition: nybbler.cc:12
void setNeuralNetPath(std::string s)
std::vector< util::PxHit > fHitVector
Cluster finding and building.
const cluster_params & GetParams() const
cluster::cluster_params fParams
uint8_t nhit
Definition: CRTFragment.hh:201
const std::vector< util::PxHit > & GetHitVector() const
p
Definition: test.py:223
void Initialize(void)
std::vector< double > fTimeRecord_ProcTime
verbose
Definition: train.py:477
std::vector< double > fChargeProfile
void SetMinNHits(size_t nhit)
std::vector< double > fChargeProfileNew
size_t fMinNHits
Cut value for # hits: below this value clusters are not evaluated.
const util::PxPoint & RoughEndPoint()
void SetVerbose(bool yes=true)
static QCString * s
Definition: config.cpp:1042
std::vector< double > fChargeCutoffThreshold