LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Cluster.cxx
Go to the documentation of this file.
1 
13 // class header
15 
16 // C/C++ standard libraries
17 #include <algorithm> // std::min(), std::max()
18 #include <cmath> // std::sqrt
19 #include <iomanip> // std::setw(), ...
20 
21 namespace {
22  template <typename T>
23  inline T sqr(T v)
24  {
25  return v * v;
26  }
27 } // local namespace
28 
29 namespace recob {
30 
31  const Cluster::SentryArgument_t Cluster::Sentry;
32 
33  //----------------------------------------------------------------------
35  : fNHits(0)
36  , fEndWires{0., 0.}
37  , fSigmaEndWires{0., 0.}
38  , fEndTicks{0., 0.}
39  , fSigmaEndTicks{0., 0.}
40  , fEndCharges{0., 0.}
41  , fAngles{0., 0.}
42  , fOpeningAngles{0., 0.}
43  , fChargeSum{0., 0.}
44  , fChargeStdDev{0., 0.}
45  , fChargeAverage{0., 0.}
46  , fMultipleHitDensity(0.)
47  , fWidth(0.)
48  , fID(InvalidID)
49  , fView(geo::kUnknown)
50  , fPlaneID()
51  {} // Cluster::Cluster()
52 
53  //----------------------------------------------------------------------
54  Cluster::Cluster(float start_wire,
55  float sigma_start_wire,
56  float start_tick,
57  float sigma_start_tick,
58  float start_charge,
59  float start_angle,
60  float start_opening,
61  float end_wire,
62  float sigma_end_wire,
63  float end_tick,
64  float sigma_end_tick,
65  float end_charge,
66  float end_angle,
67  float end_opening,
68  float integral,
69  float integral_stddev,
70  float summedADC,
71  float summedADC_stddev,
72  unsigned int n_hits,
73  float multiple_hit_density,
74  float width,
75  ID_t ID,
76  geo::View_t view,
77  geo::PlaneID const& plane,
78  SentryArgument_t /* sentry = Sentry */
79  )
80  : fNHits(n_hits)
81  , fEndWires{start_wire, end_wire}
82  , fSigmaEndWires{sigma_start_wire, sigma_end_wire}
83  , fEndTicks{start_tick, end_tick}
84  , fSigmaEndTicks{sigma_start_tick, sigma_end_tick}
85  , fEndCharges{start_charge, end_charge}
86  , fAngles{start_angle, end_angle}
87  , fOpeningAngles{start_opening, end_opening}
88  , fChargeSum{integral, summedADC}
89  , fChargeStdDev{integral_stddev, summedADC_stddev}
90  , fChargeAverage{}
91  , fMultipleHitDensity(multiple_hit_density)
92  , fWidth(width)
93  , fID(ID)
94  , fView(view)
95  , fPlaneID(plane)
96  {
97 
98  for (unsigned int mode = cmFirstMode; mode < NChargeModes; ++mode)
99  fChargeAverage[mode] = (fNHits > 0) ? fChargeSum[mode] / fNHits : 0.;
100 
101  } // Cluster::Cluster(float...)
102 
103 #if 0
104  // FIXME DELME
105  //----------------------------------------------------------------------
106  // Addition operator.
107  //
108  // The two clusters must have the same view and must lay on the same plane.
109  // If one of the clusters has an invalid plane, the sum will inherit the
110  // other's plane. If both are invalid, sum will also have an invalid plane.
111  //
112  Cluster Cluster::operator + (Cluster const& other) const {
113 
114  // throw exception if the clusters are not from the same view
115  if (other.View() != View()) return {};
116 
117  if (other.hasPlane() && hasPlane() && (other.Plane() != Plane())) return {};
118 
119  const unsigned int n_hits = NHits() + other.NHits();
120  double charge_stddev[2];
121  for (unsigned int mode = cmFirstMode; mode < NChargeModes; ++mode) {
122 
123  // this assumes that the definition of the std dev is unbiased...
124  const double this_variance = sqr(ChargeStdDev(mode)) * (NHits()-1.)/NHits();
125  const double other_variance
126  = sqr(other.ChargeStdDev(mode)) * (other.NHits()-1.) / other.NHits();
127 
128  const double e2 = (
129  (sqr(NHits()) + sqr(other.NHits())) / sqr(n_hits)
130  * sqr(ChargeAverage(mode) - other.ChargeAverage(mode))
131  + NHits() * this_variance
132  + other.NHits() * other_variance
133  ) / (n_hits - 1.); // unbiased
134 
135  charge_stddev[mode] = std::sqrt(e2);
136  } // for charge mode
137 
138  return Cluster (
139  std::min(StartWire(), other.StartWire()), // start_wire
140  std::min(StartTick(), other.StartTick()), // start_tick
141  0., // start_charge
142  0., // start_angle
143  0., // start_opening
144  std::max(EndWire(), other.EndWire()), // end_wire
145  std::max(EndTick(), other.EndTick()), // end_tick
146  0., // end_charge
147  0., // end_angle
148  0., // end_opening
149  Integral() + other.Integral(), // integral
150  charge_stddev[cmFit], // integral_stddev
151  SummedADC() + other.SummedADC(), // summedADC
152  charge_stddev[cmADC], // summedADC_stddev
153  n_hits, // n_hits
154  0., // multiple_hit_density
155  0., // width
156  InvalidID, // ID
157  View(), // view
158  hasPlane()? Plane(): other.Plane() // plane
159  );
160 
161  } // Cluster::operator+ ()
162 
163 #endif // 0
164 
165  //----------------------------------------------------------------------
166  // ostream operator.
167  //
168  std::ostream& operator<<(std::ostream& o, Cluster const& c)
169  {
170  o << std::setiosflags(std::ios::fixed) << std::setprecision(2);
171  o << "Cluster ID " << std::setw(5) << std::right << c.ID() << " : Cryo = " << std::setw(3)
172  << std::right << c.Plane().Cryostat << " TPC = " << std::setw(3) << std::right
173  << c.Plane().TPC << " Plane = " << std::setw(3) << std::right << c.Plane().Plane
174  << " View = " << std::setw(3) << std::right << c.View() << " StartWire = " << std::setw(7)
175  << std::right << c.StartWire() << " EndWire = " << std::setw(7) << std::right << c.EndWire()
176  << " StartTime = " << std::setw(9) << std::right << c.StartTick()
177  << " EndTime = " << std::setw(9) << std::right << c.EndTick()
178  << " N hits = " << std::setw(5) << std::right << c.NHits()
179  << " Width = " << std::setw(5) << std::right << c.Width()
180  << " Charge(fit) = " << std::setw(10) << std::right << c.Integral()
181  << " Charge(ADC) = " << std::setw(10) << std::right << c.SummedADC();
182  return o;
183  } // operator<< (ostream, Cluster)
184 
185  //----------------------------------------------------------------------
186  // < operator.
187  //
188  bool operator<(Cluster const& a, Cluster const& b)
189  {
190 
191  if (a.hasPlane() && b.hasPlane() && a.Plane() != b.Plane()) return a.Plane() < b.Plane();
192  if (a.View() != b.View()) return a.View() < b.View();
193  if (a.ID() != b.ID()) return a.ID() < b.ID();
194  if (a.StartTick() != b.StartTick()) return a.StartTick() < b.StartTick();
195  if (a.EndTick() != b.EndTick()) return a.EndTick() < b.EndTick();
196 
197  return false; // they are equal enough
198  } // operator < (Cluster, Cluster)
199 
200 } // namespace
Sums from the fitted hit values.
Definition: Cluster.h:82
float fWidth
A measure of the cluster width, in homogenized units.
Definition: Cluster.h:154
static constexpr ID_t InvalidID
Value for an invalid cluster ID.
Definition: Cluster.h:171
float fMultipleHitDensity
Density of wires in the cluster with more than one hit.
Definition: Cluster.h:151
Just an alias for loops.
Definition: Cluster.h:85
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
Reconstruction base classes.
float fEndTicks[NEnds]
Definition: Cluster.h:106
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Unknown view.
Definition: geo_types.h:142
float fEndCharges[NEnds]
Definition: Cluster.h:115
friend std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:168
float fSigmaEndTicks[NEnds]
Definition: Cluster.h:110
The data type to uniquely identify a Plane.
Definition: geo_types.h:463
float StartWire() const
Returns the wire coordinate of the start of the cluster.
Definition: Cluster.h:276
float fSigmaEndWires[NEnds]
Definition: Cluster.h:102
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:211
Set of hits with a 2D structure.
Definition: Cluster.h:69
float EndTick() const
Returns the tick coordinate of the end of the cluster.
Definition: Cluster.h:331
geo::PlaneID Plane() const
Returns the plane ID this cluster lies on.
Definition: Cluster.h:717
geo::PlaneID fPlaneID
Location of the start of the cluster.
Definition: Cluster.h:163
Type of sentry argument.
Definition: Cluster.h:167
Sums directly from ADC counts.
Definition: Cluster.h:83
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:174
float fChargeSum[NChargeModes]
Definition: Cluster.h:139
float fChargeAverage[NChargeModes]
Definition: Cluster.h:147
float SummedADC() const
Returns the total charge of the cluster from signal ADC counts.
Definition: Cluster.h:614
float ChargeStdDev(ChargeMode_t mode) const
Returns the standard deviation of charge of the cluster hits.
Definition: Cluster.h:670
float Width() const
A measure of the cluster width, in homogenized units.
Definition: Cluster.h:701
constexpr T sqr(T v)
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:481
Declaration of cluster object.
float fAngles[NEnds]
Definition: Cluster.h:125
friend bool operator<(Cluster const &a, Cluster const &b)
Definition: Cluster.cxx:188
float ChargeAverage(ChargeMode_t mode) const
Returns the average charge of the cluster hits.
Definition: Cluster.h:685
geo::View_t View() const
Returns the view for this cluster.
Definition: Cluster.h:714
QuadExpr operator+(double v, const QuadExpr &e)
Definition: QuadExpr.h:36
ID_t ID() const
Identifier of this cluster.
Definition: Cluster.h:711
unsigned int fNHits
Number of hits in the cluster.
Definition: Cluster.h:92
float fOpeningAngles[NEnds]
Definition: Cluster.h:132
bool hasPlane() const
Returns whether geometry plane is valid.
Definition: Cluster.h:722
Cluster()
Default constructor: an empty cluster.
Definition: Cluster.cxx:34
unsigned int NHits() const
Number of hits in the cluster.
Definition: Cluster.h:265
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:399
float StartTick() const
Returns the tick coordinate of the start of the cluster.
Definition: Cluster.h:287
float fChargeStdDev[NChargeModes]
Definition: Cluster.h:143
geo::View_t fView
View for this cluster.
Definition: Cluster.h:161
int ID_t
Type of cluster ID.
Definition: Cluster.h:72
float Integral() const
Returns the total charge of the cluster from hit shape.
Definition: Cluster.h:581
float EndWire() const
Returns the wire coordinate of the end of the cluster.
Definition: Cluster.h:318