All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Cluster.cxx
Go to the documentation of this file.
1 /** ****************************************************************************
2  * @file Cluster.cxx
3  * @brief Declaration of cluster object.
4  * @author mitchell.soderberg@yale.edu
5  * @see Cluster.h
6  *
7  * Changes:
8  * 20141212 Gianluca Petrillo (petrillo@fnal.gov)
9  * data architecture revision changes
10  *
11  * ****************************************************************************/
12 
13 
14 // class header
16 
17 // C/C++ standard libraries
18 #include <iomanip> // std::setw(), ...
19 #include <cmath> // std::sqrt
20 #include <algorithm> // std::min(), std::max()
21 
22 
23 namespace {
24  template <typename T>
25  inline T sqr(T v) { return v*v; }
26 } // local namespace
27 
28 
29 namespace recob{
30 
31  const Cluster::SentryArgument_t Cluster::Sentry;
32 
33 
34  //----------------------------------------------------------------------
36  : fNHits(0)
37  , fEndWires{ 0., 0. }
38  , fSigmaEndWires{ 0., 0. }
39  , fEndTicks{ 0., 0. }
40  , fSigmaEndTicks{ 0., 0. }
41  , fEndCharges{ 0., 0. }
42  , fAngles{ 0., 0. }
43  , fOpeningAngles{ 0., 0. }
44  , fChargeSum{ 0., 0. }
45  , fChargeStdDev{ 0., 0. }
46  , fChargeAverage{ 0., 0. }
47  , fMultipleHitDensity(0.)
48  , fWidth(0.)
49  , fID(InvalidID)
50  , fView(geo::kUnknown)
51  , fPlaneID()
52  {} // Cluster::Cluster()
53 
54 
55  //----------------------------------------------------------------------
57  float start_wire,
58  float sigma_start_wire,
59  float start_tick,
60  float sigma_start_tick,
61  float start_charge,
62  float start_angle,
63  float start_opening,
64  float end_wire,
65  float sigma_end_wire,
66  float end_tick,
67  float sigma_end_tick,
68  float end_charge,
69  float end_angle,
70  float end_opening,
71  float integral,
72  float integral_stddev,
73  float summedADC,
74  float summedADC_stddev,
75  unsigned int n_hits,
76  float multiple_hit_density,
77  float width,
78  ID_t ID,
79  geo::View_t view,
80  geo::PlaneID const& plane,
81  SentryArgument_t /* sentry = Sentry */
82  )
83  : fNHits(n_hits)
84  , fEndWires{ start_wire, end_wire }
85  , fSigmaEndWires{ sigma_start_wire, sigma_end_wire }
86  , fEndTicks{ start_tick, end_tick }
87  , fSigmaEndTicks{ sigma_start_tick, sigma_end_tick }
88  , fEndCharges{ start_charge, end_charge }
89  , fAngles{ start_angle, end_angle }
90  , fOpeningAngles{ start_opening, end_opening }
91  , fChargeSum{ integral, summedADC }
92  , fChargeStdDev{ integral_stddev, summedADC_stddev }
93  , fChargeAverage{}
94  , fMultipleHitDensity(multiple_hit_density)
95  , fWidth(width)
96  , fID(ID)
97  , fView(view)
98  , fPlaneID(plane)
99  {
100 
101  for (unsigned int mode = cmFirstMode; mode < NChargeModes; ++mode)
102  fChargeAverage[mode] = (fNHits > 0)? fChargeSum[mode] / fNHits: 0.;
103 
104  } // Cluster::Cluster(float...)
105 
106 
107 #if 0
108  // FIXME DELME
109  //----------------------------------------------------------------------
110  // Addition operator.
111  //
112  // The two clusters must have the same view and must lay on the same plane.
113  // If one of the clusters has an invalid plane, the sum will inherit the
114  // other's plane. If both are invalid, sum will also have an invalid plane.
115  //
116  Cluster Cluster::operator + (Cluster const& other) const {
117 
118  // throw exception if the clusters are not from the same view
119  if (other.View() != View()) return {};
120 
121  if (other.hasPlane() && hasPlane() && (other.Plane() != Plane())) return {};
122 
123  const unsigned int n_hits = NHits() + other.NHits();
124  double charge_stddev[2];
125  for (unsigned int mode = cmFirstMode; mode < NChargeModes; ++mode) {
126 
127  // this assumes that the definition of the std dev is unbiased...
128  const double this_variance = sqr(ChargeStdDev(mode)) * (NHits()-1.)/NHits();
129  const double other_variance
130  = sqr(other.ChargeStdDev(mode)) * (other.NHits()-1.) / other.NHits();
131 
132  const double e2 = (
133  (sqr(NHits()) + sqr(other.NHits())) / sqr(n_hits)
134  * sqr(ChargeAverage(mode) - other.ChargeAverage(mode))
135  + NHits() * this_variance
136  + other.NHits() * other_variance
137  ) / (n_hits - 1.); // unbiased
138 
139  charge_stddev[mode] = std::sqrt(e2);
140  } // for charge mode
141 
142  return Cluster (
143  std::min(StartWire(), other.StartWire()), // start_wire
144  std::min(StartTick(), other.StartTick()), // start_tick
145  0., // start_charge
146  0., // start_angle
147  0., // start_opening
148  std::max(EndWire(), other.EndWire()), // end_wire
149  std::max(EndTick(), other.EndTick()), // end_tick
150  0., // end_charge
151  0., // end_angle
152  0., // end_opening
153  Integral() + other.Integral(), // integral
154  charge_stddev[cmFit], // integral_stddev
155  SummedADC() + other.SummedADC(), // summedADC
156  charge_stddev[cmADC], // summedADC_stddev
157  n_hits, // n_hits
158  0., // multiple_hit_density
159  0., // width
160  InvalidID, // ID
161  View(), // view
162  hasPlane()? Plane(): other.Plane() // plane
163  );
164 
165  } // Cluster::operator+ ()
166 
167 #endif // 0
168 
169 
170  //----------------------------------------------------------------------
171  // ostream operator.
172  //
173  std::ostream& operator<< (std::ostream& o, Cluster const& c) {
174  o << std::setiosflags(std::ios::fixed) << std::setprecision(2);
175  o << "Cluster ID " << std::setw(5) << std::right << c.ID()
176  << " : Cryo = " << std::setw(3) << std::right << c.Plane().Cryostat
177  << " TPC = " << std::setw(3) << std::right << c.Plane().TPC
178  << " Plane = " << std::setw(3) << std::right << c.Plane().Plane
179  << " View = " << std::setw(3) << std::right << c.View()
180  << " StartWire = " << std::setw(7) << std::right << c.StartWire()
181  << " EndWire = " << std::setw(7) << std::right << c.EndWire()
182  << " StartTime = " << std::setw(9) << std::right << c.StartTick()
183  << " EndTime = " << std::setw(9) << std::right << c.EndTick()
184  << " N hits = " << std::setw(5) << std::right << c.NHits()
185  << " Width = " << std::setw(5) << std::right << c.Width()
186  << " Charge(fit) = " << std::setw(10) << std::right << c.Integral()
187  << " Charge(ADC) = " << std::setw(10) << std::right << c.SummedADC()
188  ;
189  return o;
190  } // operator<< (ostream, Cluster)
191 
192 
193  //----------------------------------------------------------------------
194  // < operator.
195  //
196  bool operator < (Cluster const& a, Cluster const& b) {
197 
198  if (a.hasPlane() && b.hasPlane() && a.Plane() != b.Plane())
199  return a.Plane() < b.Plane();
200  if (a.View() != b.View())
201  return a.View() < b.View();
202  if (a.ID() != b. ID())
203  return a.ID() < b.ID();
204  if (a.StartTick() != b.StartTick())
205  return a.StartTick() < b.StartTick();
206  if (a.EndTick() != b.EndTick())
207  return a.EndTick() < b.EndTick();
208 
209  return false; // they are equal enough
210  } // operator < (Cluster, Cluster)
211 
212 }// namespace
213 
Sums from the fitted hit values.
Definition: Cluster.h:85
static constexpr ID_t InvalidID
Value for an invalid cluster ID.
Definition: Cluster.h:179
Just an alias for loops.
Definition: Cluster.h:88
bool operator<(Cluster const &a, Cluster const &b)
Definition: Cluster.cxx:196
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Unknown view.
Definition: geo_types.h:136
walls no right
Definition: selectors.fcl:105
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
float StartWire() const
Returns the wire coordinate of the start of the cluster.
Definition: Cluster.h:286
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
Set of hits with a 2D structure.
Definition: Cluster.h:71
float EndTick() const
Returns the tick coordinate of the end of the cluster.
Definition: Cluster.h:342
geo::PlaneID Plane() const
Returns the plane ID this cluster lies on.
Definition: Cluster.h:744
Type of sentry argument.
Definition: Cluster.h:176
Sums directly from ADC counts.
Definition: Cluster.h:86
static const SentryArgument_t Sentry
An instance of the sentry object.
Definition: Cluster.h:182
process_name gaushit a
float SummedADC() const
Returns the total charge of the cluster from signal ADC counts.
Definition: Cluster.h:634
float ChargeStdDev(ChargeMode_t mode) const
Returns the standard deviation of charge of the cluster hits.
Definition: Cluster.h:691
const char mode
Definition: noise_ana.cxx:20
float Width() const
A measure of the cluster width, in homogenized units.
Definition: Cluster.h:727
constexpr T sqr(T v)
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Declaration of cluster object.
float ChargeAverage(ChargeMode_t mode) const
Returns the average charge of the cluster hits.
Definition: Cluster.h:708
geo::View_t View() const
Returns the view for this cluster.
Definition: Cluster.h:741
QuadExpr operator+(double v, const QuadExpr &e)
Definition: QuadExpr.h:37
ID_t ID() const
Identifier of this cluster.
Definition: Cluster.h:738
bool hasPlane() const
Returns whether geometry plane is valid.
Definition: Cluster.h:749
Cluster()
Default constructor: an empty cluster.
Definition: Cluster.cxx:35
unsigned int NHits() const
Number of hits in the cluster.
Definition: Cluster.h:275
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
float StartTick() const
Returns the tick coordinate of the start of the cluster.
Definition: Cluster.h:297
int ID_t
Type of cluster ID.
Definition: Cluster.h:74
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:173
float Integral() const
Returns the total charge of the cluster from hit shape.
Definition: Cluster.h:600
float EndWire() const
Returns the wire coordinate of the end of the cluster.
Definition: Cluster.h:329