KHitWireLine.cxx
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 ///
3 /// \file KHitWireLine.cxx
4 ///
5 /// \brief Kalman filter wire-time measurement on a SurfWireLine surface.
6 ///
7 /// \author H. Greenlee
8 ///
9 ////////////////////////////////////////////////////////////////////////
10 
12 #include "cetlib_except/exception.h"
17 
18 namespace trkf {
19 
20  /// Constructor.
21  ///
22  /// Arguments:
23  ///
24  /// hit - Hit.
25  /// psurf - Measurement surface (can be null).
26  ///
27  /// The measurement surface is only a suggestion. It is allowed to
28  /// be specified to allow measurements to whare surfaces to save
29  /// memory.
30  ///
33  const std::shared_ptr<const Surface>& psurf)
34  : KHit(psurf), fHit(hit)
35  {
36  // Extract wire id.
37  geo::WireID wireid = hit->WireID();
38 
39  // Extract time information from hit.
40 
41  double t = hit->PeakTime();
42  double terr = hit->SigmaPeakTime();
43 
44  // Don't let the time error be less than 1./sqrt(12.) ticks.
45  // This should be removed when hit errors are fixed.
46 
47  if (terr < 1. / std::sqrt(12.)) terr = 1. / std::sqrt(12.);
48 
49  // Calculate position and error.
50 
51  double x = detProp.ConvertTicksToX(t, wireid.Plane, wireid.TPC, wireid.Cryostat);
52  double xerr = terr * detProp.GetXTicksCoefficient();
53 
54  // Check the surface (determined by wire id + drift time). If the
55  // surface pointer is null, make a new SurfWireLine surface and
56  // update the base class appropriately. Otherwise, just check
57  // that the specified surface agrees with the wire id + drift time.
58 
59  if (psurf.get() == 0) {
60  std::shared_ptr<const Surface> new_psurf(new SurfWireLine(wireid, x));
61  setMeasSurface(new_psurf);
62  }
63  else {
64  SurfWireLine check_surf(wireid, x);
65  if (!check_surf.isEqual(*psurf))
66  throw cet::exception("KHitWireLine") << "Measurement surface doesn't match hit.\n";
67  }
68 
69  setMeasPlane(wireid.Plane);
70 
71  // Update measurement vector and error matrix.
72 
73  trkf::KVector<1>::type mvec(1, 0.);
74  setMeasVector(mvec);
75 
77  merr(0, 0) = xerr * xerr;
78  setMeasError(merr);
79 
80  // Set the unique id from a combination of the channel number and the time.
81 
82  fID = (hit->Channel() % 200000) * 10000 + (int(std::abs(t)) % 10000);
83  }
84 
85  /// Constructor.
86  ///
87  /// Arguments:
88  ///
89  /// wireid - Wire id.
90  /// x - X coordinate.
91  /// xerr - X error.
92  ///
93  KHitWireLine::KHitWireLine(const geo::WireID& wireid, double x, double xerr)
94  : KHit(std::shared_ptr<const Surface>(new SurfWireLine(wireid, x)))
95  {
96  // Get services.
97 
99 
100  // Get plane number.
101 
102  setMeasPlane(wireid.Plane);
103 
104  // Update measurement vector and error matrix.
105  // The measured value (aka impact parameter) is always zero.
106 
107  trkf::KVector<1>::type mvec(1, 0.);
108  setMeasVector(mvec);
109 
111  merr(0, 0) = xerr * xerr;
112  setMeasError(merr);
113  }
114 
115  bool
117  KVector<1>::type& pvec,
118  KSymMatrix<1>::type& perr,
119  KHMatrix<1>::type& hmatrix) const
120  {
121  // Make sure that the track surface and the measurement surface are the
122  // same. Throw an exception if they are not.
123 
124  if (!getMeasSurface()->isEqual(*tre.getSurface()))
125  throw cet::exception("KHitWireLine")
126  << "Track surface not the same as measurement surface.\n";
127 
128  // Prediction is the signed impact parameter (parameter 0).
129 
130  int size = tre.getVector().size();
131  pvec.resize(1, /* preserve */ false);
132  pvec.clear();
133  pvec(0) = tre.getVector()(0);
134 
135  perr.resize(1, /* preserve */ false);
136  perr.clear();
137  perr(0, 0) = tre.getError()(0, 0);
138 
139  // Update prediction error to include contribution from track slope.
140 
142  double pitch = geom->WirePitch();
143  double phi = tre.getVector()(2);
144  double cosphi = std::cos(phi);
145  double slopevar = pitch * pitch * cosphi * cosphi / 12.;
146  perr(0, 0) += slopevar;
147 
148  // Hmatrix - dr/dr = 1., all others are zero.
149 
150  hmatrix.resize(1, size, /* preserve */ false);
151  hmatrix.clear();
152  hmatrix(0, 0) = 1.;
153 
154  return true;
155  }
156 } // end namespace trkf
void setMeasSurface(const std::shared_ptr< const Surface > &psurf)
Measurement surface.
Definition: KHitBase.h:114
ublas::symmetric_matrix< double, ublas::lower, ublas::row_major, ublas::bounded_array< double, N *(N+1)/2 > > type
const TrackError & getError() const
Track error matrix.
Definition: KETrack.h:53
bool isEqual(float x1, float x2)
const std::shared_ptr< const Surface > & getSurface() const
Surface.
Definition: KTrack.h:55
double GetXTicksCoefficient(int t, int c) const
geo::WireID WireID() const
Definition: Hit.h:233
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
STL namespace.
virtual bool isEqual(const Surface &surf) const
Test two surfaces for equality, within tolerance.
Definition: SurfYZLine.cxx:270
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
art framework interface to geometry description
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
KMatrix< N, 5 >::type type
void setMeasVector(const typename KVector< N >::type &mvec)
Set measurement vector.
Definition: KHit.h:94
T abs(T value)
ublas::vector< double, ublas::bounded_array< double, N > > type
Linear surface defined by wire id and x coordinate.
void setMeasError(const typename KSymMatrix< N >::type &merr)
Set measurement error.
Definition: KHit.h:101
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Detector simulation of raw signals on wires.
int fID
Unique id.
Definition: KHitBase.h:147
double ConvertTicksToX(double ticks, int p, int t, int c) const
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
const TrackVector & getVector() const
Track state vector.
Definition: KTrack.h:56
Kalman filter wire-time measurement on a SurfWireLine surface.
KHitWireLine(const detinfo::DetectorPropertiesData &detProp, const art::Ptr< recob::Hit > &hit, const std::shared_ptr< const Surface > &psurf)
Constructor from Hit.
bool subpredict(const KETrack &tre, KVector< 1 >::type &pvec, KSymMatrix< 1 >::type &perr, KHMatrix< 1 >::type &hmatrix) const override
void setMeasPlane(int plane)
Measurement plane.
Definition: KHitBase.h:121
list x
Definition: train.py:276
float SigmaPeakTime() const
Uncertainty for the signal peak, in tick units.
Definition: Hit.h:219
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
const std::shared_ptr< const Surface > & getMeasSurface() const
Measurement surface.
Definition: KHitBase.h:91
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33