LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
sppt::SpacePointAlg_TimeSort Class Reference

#include "SpacePointAlg_TimeSort.h"

Public Member Functions

 SpacePointAlg_TimeSort (fhicl::ParameterSet const &pset)
 
void setTimeOffsets (detinfo::DetectorPropertiesData const &detProp)
 
void fillCoordinatesArrays ()
 
void createSpacePoints (detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &hitVec_U, std::vector< art::Ptr< recob::Hit >> &hitVec_V, std::vector< art::Ptr< recob::Hit >> &hitVec_Y, std::unique_ptr< std::vector< recob::SpacePoint >> &spptCollection, std::unique_ptr< std::vector< std::vector< art::Ptr< recob::Hit >>>> &spptAssociatedHits)
 

Private Member Functions

void sortHitsByTime (std::vector< art::Ptr< recob::Hit >> &hits_handle) const
 

Private Attributes

float fTimeDiffMax
 
float fYDiffMax
 Maximum allowed time difference. More...
 
float fZDiffMax
 Maximum allowed y-coordinate difference. More...
 
bool TIME_OFFSET_SET {false}
 Maximum allowed z-coordinate difference. More...
 
bool COORDINATES_FILLED {false}
 
double TIME_OFFSET_U
 
double TIME_OFFSET_V
 
double TIME_OFFSET_Y
 
double TICKS_TO_X
 
boost::multi_array< double, 2 > coordinates_UV_y
 
boost::multi_array< double, 2 > coordinates_UV_z
 
boost::multi_array< double, 2 > coordinates_UY_y
 
boost::multi_array< double, 2 > coordinates_UY_z
 

Detailed Description

Definition at line 40 of file SpacePointAlg_TimeSort.h.

Constructor & Destructor Documentation

sppt::SpacePointAlg_TimeSort::SpacePointAlg_TimeSort ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 48 of file SpacePointAlg_TimeSort.cxx.

References fTimeDiffMax, fYDiffMax, fZDiffMax, and fhicl::ParameterSet::get().

49  {
50  fTimeDiffMax = pset.get<float>("TimeDiffMax");
51  fZDiffMax = pset.get<float>("ZDiffMax");
52  fYDiffMax = pset.get<float>("YDiffMax");
53 
54  //enforce a minimum time diff
55  if (fTimeDiffMax < 0) {
56  throw cet::exception("SpacePointAlg_TimeSort")
57  << "Time difference must be greater than zero.";
58  }
59  if (fZDiffMax < 0) {
60  throw cet::exception("SpacePointAlg_TimeSort")
61  << "Z-coordinate difference must be greater than zero.";
62  }
63  if (fYDiffMax < 0) {
64  throw cet::exception("SpacePointAlg_TimeSort")
65  << "Y-coordinate difference must be greater than zero.";
66  }
67  }
float fYDiffMax
Maximum allowed time difference.
float fZDiffMax
Maximum allowed y-coordinate difference.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Function Documentation

void sppt::SpacePointAlg_TimeSort::createSpacePoints ( detinfo::DetectorPropertiesData const &  detProp,
std::vector< art::Ptr< recob::Hit >> &  hitVec_U,
std::vector< art::Ptr< recob::Hit >> &  hitVec_V,
std::vector< art::Ptr< recob::Hit >> &  hitVec_Y,
std::unique_ptr< std::vector< recob::SpacePoint >> &  spptCollection,
std::unique_ptr< std::vector< std::vector< art::Ptr< recob::Hit >>>> &  spptAssociatedHits 
)

Definition at line 119 of file SpacePointAlg_TimeSort.cxx.

References util::abs(), COORDINATES_FILLED, coordinates_UV_y, coordinates_UV_z, coordinates_UY_y, coordinates_UY_z, fillCoordinatesArrays(), fTimeDiffMax, fYDiffMax, fZDiffMax, MF_LOG_DEBUG, setTimeOffsets(), sortHitsByTime(), TICKS_TO_X, TIME_OFFSET_SET, TIME_OFFSET_U, TIME_OFFSET_V, and TIME_OFFSET_Y.

Referenced by sppt::TTSpacePointFinder::produce().

126  {
127 
128  if (!TIME_OFFSET_SET) {
129  mf::LogWarning("SpacePointAlg_TimeSort")
130  << "Time offsets not set before createSpacePoints call!"
131  << "\nYou should call SpacePointAlg_TimeSort::setTimeOffsets() in beginRun()!"
132  << "\nWill be set now, but you should modify your code!";
133  setTimeOffsets(detProp);
134  }
135  if (!COORDINATES_FILLED) {
136  mf::LogWarning("SpacePointAlg_TimeSort")
137  << "Coordinate arrays not filled before createSpacePoints call!"
138  << "\nYou should call SpacePointAlg_TimeSort::fillCoordinateArrays() in beginRun()!"
139  << "\nWill be filled now, but you should modify your code!";
141  }
142 
143  //sort the hits by the time
144  sortHitsByTime(hitVec_U);
145  sortHitsByTime(hitVec_V);
146  sortHitsByTime(hitVec_Y);
147 
148  MF_LOG_DEBUG("SpacePointAlg_TimeSort")
149  << "Sorted " << hitVec_U.size() << " u hits, " << hitVec_V.size() << " v hits, "
150  << hitVec_Y.size() << " y hits.";
151 
152  //now, do the loop to search for like-timed hits across the three planes
153  std::vector<art::Ptr<recob::Hit>>::iterator ihitu = hitVec_U.begin();
154  std::vector<art::Ptr<recob::Hit>>::iterator ihitv = hitVec_V.begin();
155  std::vector<art::Ptr<recob::Hit>>::iterator ihity = hitVec_Y.begin();
156  std::vector<art::Ptr<recob::Hit>>::iterator ihitv_inner, ihity_inner;
157  double time_hitu = (*ihitu)->PeakTime() + TIME_OFFSET_U;
158  double time_hitv = (*ihitv)->PeakTime() + TIME_OFFSET_V;
159  double time_hity = (*ihity)->PeakTime() + TIME_OFFSET_Y;
160  double time_hitv_inner, time_hity_inner;
161  while (ihitu != hitVec_U.end()) {
162  time_hitu = (*ihitu)->PeakTime() + TIME_OFFSET_U;
163 
164  mf::LogInfo("SpacePointAlg_TimeSort")
165  << "Hit times (u,v,y)=(" << time_hitu << "," << time_hitv << "," << time_hity << ")";
166 
167  //if time_hitu is too much bigger than time_hitv, need to advance hitv iterator
168  while ((time_hitu - time_hitv) > fTimeDiffMax) {
169  ihitv++;
170  if (ihitv == hitVec_V.end()) break;
171  time_hitv = (*ihitv)->PeakTime() + TIME_OFFSET_V;
172  }
173  if (ihitv == hitVec_V.end()) break;
174 
175  //same thing with time_hitu and time_hity
176  while ((time_hitu - time_hity) > fTimeDiffMax) {
177  ihity++;
178  if (ihity == hitVec_Y.end()) break;
179  time_hity = (*ihity)->PeakTime() + TIME_OFFSET_Y;
180  }
181  if (ihity == hitVec_Y.end()) break;
182 
183  //OK, now we know time_hitu <= time_hitv and time_hitu <= time_hity.
184  //Next, check if time_hitu is near time_hitv and time_hit y. If not,
185  //we have to increment ihitu.
186  if (std::abs(time_hitu - time_hitv) > fTimeDiffMax ||
187  std::abs(time_hitu - time_hity) > fTimeDiffMax) {
188  ihitu++;
189  continue;
190  }
191 
192  //OK! Note we KNOW that these three match in time:
193  // -- time_hitu is within fTimeDiffMax of both time_hitv and time_hity; and
194  // -- time_hitu <= time_hitv AND time_hitu <=time_hity, so time_hitv and time_hity are near too
195 
196  mf::LogInfo("SpacePointAlg_TimeSort") << "Matching hit times (u,v,y)=(" << time_hitu << ","
197  << time_hitv << "," << time_hity << ")";
198 
199  //Next thing to do, we need to loop over all possible 3-hit matches for our given u-hit.
200  //We need new iterators in v and y at this location, and will loop over those
201  ihitv_inner = ihitv;
202  time_hitv_inner = (*ihitv_inner)->PeakTime() + TIME_OFFSET_V;
203  ihity_inner = ihity;
204  time_hity_inner = (*ihity_inner)->PeakTime() + TIME_OFFSET_Y;
205 
206  while (std::abs(time_hitu - time_hitv_inner) < fTimeDiffMax &&
207  std::abs(time_hitu - time_hity_inner) < fTimeDiffMax) {
208 
209  unsigned int uwire = (*ihitu)->WireID().Wire;
210  unsigned int vwire = (*ihitv_inner)->WireID().Wire;
211  unsigned int ywire = (*ihity_inner)->WireID().Wire;
212 
213  mf::LogInfo("SpacePointAlg_TimeSort")
214  << "(y,z) coordinate for uv/uy: (" << coordinates_UV_y[vwire][uwire] << ","
215  << coordinates_UV_z[vwire][uwire] << ")/(" << coordinates_UY_y[ywire][uwire] << ","
216  << coordinates_UY_z[ywire][uwire] << ")";
217 
218  if (std::abs(coordinates_UV_y[vwire][uwire] - coordinates_UY_y[ywire][uwire]) < fYDiffMax &&
219  std::abs(coordinates_UV_z[vwire][uwire] - coordinates_UY_z[ywire][uwire]) < fZDiffMax) {
220 
221  double xyz[3];
222  double xyz_err[6];
223  //triangular error matrix:
224  // | 0. |
225  // | 0. 0. |
226  // | 0. 0. 0. |
227 
228  //get average y and z, with errors
229  xyz[1] = (coordinates_UV_y[vwire][uwire] + coordinates_UY_y[ywire][uwire]) * 0.5;
230  xyz_err[2] = std::abs(coordinates_UV_y[vwire][uwire] - xyz[1]);
231  xyz[2] = (coordinates_UV_z[vwire][uwire] + coordinates_UY_z[ywire][uwire]) * 0.5;
232  xyz_err[5] = std::abs(coordinates_UV_z[vwire][uwire] - xyz[2]);
233 
234  double t_val = (time_hitu + time_hitv_inner + time_hity_inner) / 3.;
235  double t_err = 0.5 * std::sqrt((time_hitu - t_val) * (time_hitu - t_val) +
236  (time_hitv_inner - t_val) * (time_hitv_inner - t_val) +
237  (time_hity_inner - t_val) * (time_hity_inner - t_val));
238  xyz[0] = TICKS_TO_X * t_val;
239  xyz_err[0] = TICKS_TO_X * t_err;
240 
241  //make space point to put on event
242  recob::SpacePoint spt(xyz, xyz_err, 0., spptCollection->size());
243  spptCollection->push_back(spt);
244 
245  //make association with hits
246  std::vector<art::Ptr<recob::Hit>> myhits = {*ihitu, *ihitv_inner, *ihity_inner};
247  spptAssociatedHits->push_back(myhits);
248  }
249 
250  //now increment the v or y hit, whichever is smalles (closest to u hit) in time
251  if (time_hitv_inner <= time_hity_inner) {
252  ihitv_inner++;
253  if (ihitv_inner == hitVec_V.end()) break;
254  time_hitv_inner = (*ihitv_inner)->PeakTime() + TIME_OFFSET_V;
255  }
256  else {
257  ihity_inner++;
258  if (ihity_inner == hitVec_Y.end()) break;
259  time_hity_inner = (*ihity_inner)->PeakTime() + TIME_OFFSET_Y;
260  }
261  }
262 
263  ihitu++;
264  } // end while looping over u hits
265 
266  MF_LOG_DEBUG("SpacePointAlg_TimeSort")
267  << "Finished with " << spptCollection->size() << " spacepoints.";
268 
269  } //end createSpacePoints
void sortHitsByTime(std::vector< art::Ptr< recob::Hit >> &hits_handle) const
float fYDiffMax
Maximum allowed time difference.
void setTimeOffsets(detinfo::DetectorPropertiesData const &detProp)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
constexpr auto abs(T v)
Returns the absolute value of the argument.
boost::multi_array< double, 2 > coordinates_UV_y
float fZDiffMax
Maximum allowed y-coordinate difference.
boost::multi_array< double, 2 > coordinates_UY_z
bool TIME_OFFSET_SET
Maximum allowed z-coordinate difference.
boost::multi_array< double, 2 > coordinates_UY_y
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
#define MF_LOG_DEBUG(id)
boost::multi_array< double, 2 > coordinates_UV_z
void sppt::SpacePointAlg_TimeSort::fillCoordinatesArrays ( )

Definition at line 81 of file SpacePointAlg_TimeSort.cxx.

References COORDINATES_FILLED, coordinates_UV_y, coordinates_UV_z, coordinates_UY_y, coordinates_UY_z, Get, geo::WireIDIntersection::invalid(), geo::kU, geo::kV, and geo::kZ.

Referenced by sppt::TTSpacePointFinder::beginRun(), and createSpacePoints().

82  {
83  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
84  constexpr geo::TPCID tpcid{0, 0};
85  constexpr geo::PlaneID uplane_id{tpcid, geo::View_t::kU};
86  constexpr geo::PlaneID vplane_id{tpcid, geo::View_t::kV};
87  constexpr geo::PlaneID zplane_id{tpcid, geo::View_t::kZ};
88 
89  unsigned int nwires_u = wireReadoutGeom.Nwires(uplane_id);
90  unsigned int nwires_v = wireReadoutGeom.Nwires(vplane_id);
91  unsigned int nwires_y = wireReadoutGeom.Nwires(zplane_id);
92 
93  coordinates_UV_y.resize(boost::extents[nwires_v][nwires_u]);
94  coordinates_UV_z.resize(boost::extents[nwires_v][nwires_u]);
95  coordinates_UY_y.resize(boost::extents[nwires_y][nwires_u]);
96  coordinates_UY_z.resize(boost::extents[nwires_y][nwires_u]);
97  for (unsigned int iu = 0; iu < nwires_u; iu++) {
98  geo::WireID const uplane_wire_id{uplane_id, iu};
99  for (unsigned int iv = 0; iv < nwires_v; iv++) {
100  auto intersection =
101  wireReadoutGeom.WireIDsIntersect(uplane_wire_id, geo::WireID{vplane_id, iv})
103  coordinates_UV_y[iv][iu] = intersection.y;
104  coordinates_UV_z[iv][iu] = intersection.z;
105  }
106  for (unsigned int iy = 0; iy < nwires_y; iy++) {
107  auto intersection =
108  wireReadoutGeom.WireIDsIntersect(uplane_wire_id, geo::WireID{zplane_id, iy})
110  coordinates_UY_y[iy][iu] = intersection.y;
111  coordinates_UY_z[iy][iu] = intersection.z;
112  }
113  }
114 
115  COORDINATES_FILLED = true;
116  }
Planes which measure V.
Definition: geo_types.h:132
The data type to uniquely identify a Plane.
Definition: geo_types.h:364
boost::multi_array< double, 2 > coordinates_UV_y
Planes which measure Z direction.
Definition: geo_types.h:134
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
boost::multi_array< double, 2 > coordinates_UY_z
Planes which measure U.
Definition: geo_types.h:131
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
boost::multi_array< double, 2 > coordinates_UY_y
static constexpr WireIDIntersection invalid()
Definition: geo_types.h:594
boost::multi_array< double, 2 > coordinates_UV_z
void sppt::SpacePointAlg_TimeSort::setTimeOffsets ( detinfo::DetectorPropertiesData const &  detProp)

Definition at line 70 of file SpacePointAlg_TimeSort.cxx.

References detinfo::DetectorPropertiesData::GetXTicksCoefficient(), detinfo::DetectorPropertiesData::GetXTicksOffset(), geo::kU, geo::kV, geo::kZ, TICKS_TO_X, TIME_OFFSET_SET, TIME_OFFSET_U, TIME_OFFSET_V, and TIME_OFFSET_Y.

Referenced by sppt::TTSpacePointFinder::beginRun(), and createSpacePoints().

71  {
72  TIME_OFFSET_U = -1 * detProp.GetXTicksOffset(geo::View_t::kU, 0, 0);
73  TIME_OFFSET_V = -1 * detProp.GetXTicksOffset(geo::View_t::kV, 0, 0);
74  TIME_OFFSET_Y = -1 * detProp.GetXTicksOffset(geo::View_t::kZ, 0, 0);
75  TICKS_TO_X = detProp.GetXTicksCoefficient();
76 
77  TIME_OFFSET_SET = true;
78  }
Planes which measure V.
Definition: geo_types.h:132
Planes which measure Z direction.
Definition: geo_types.h:134
Planes which measure U.
Definition: geo_types.h:131
bool TIME_OFFSET_SET
Maximum allowed z-coordinate difference.
void sppt::SpacePointAlg_TimeSort::sortHitsByTime ( std::vector< art::Ptr< recob::Hit >> &  hits_handle) const
private

Definition at line 272 of file SpacePointAlg_TimeSort.cxx.

Referenced by createSpacePoints().

273  {
274  std::sort(hitVec.begin(), hitVec.end(), HitTimeComparison);
275  }

Member Data Documentation

bool sppt::SpacePointAlg_TimeSort::COORDINATES_FILLED {false}
private

Definition at line 61 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and fillCoordinatesArrays().

boost::multi_array<double, 2> sppt::SpacePointAlg_TimeSort::coordinates_UV_y
private

Definition at line 68 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and fillCoordinatesArrays().

boost::multi_array<double, 2> sppt::SpacePointAlg_TimeSort::coordinates_UV_z
private

Definition at line 69 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and fillCoordinatesArrays().

boost::multi_array<double, 2> sppt::SpacePointAlg_TimeSort::coordinates_UY_y
private

Definition at line 70 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and fillCoordinatesArrays().

boost::multi_array<double, 2> sppt::SpacePointAlg_TimeSort::coordinates_UY_z
private

Definition at line 71 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and fillCoordinatesArrays().

float sppt::SpacePointAlg_TimeSort::fTimeDiffMax
private

Definition at line 56 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and SpacePointAlg_TimeSort().

float sppt::SpacePointAlg_TimeSort::fYDiffMax
private

Maximum allowed time difference.

Definition at line 57 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and SpacePointAlg_TimeSort().

float sppt::SpacePointAlg_TimeSort::fZDiffMax
private

Maximum allowed y-coordinate difference.

Definition at line 58 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and SpacePointAlg_TimeSort().

double sppt::SpacePointAlg_TimeSort::TICKS_TO_X
private

Definition at line 66 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().

bool sppt::SpacePointAlg_TimeSort::TIME_OFFSET_SET {false}
private

Maximum allowed z-coordinate difference.

Definition at line 60 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().

double sppt::SpacePointAlg_TimeSort::TIME_OFFSET_U
private

Definition at line 63 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().

double sppt::SpacePointAlg_TimeSort::TIME_OFFSET_V
private

Definition at line 64 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().

double sppt::SpacePointAlg_TimeSort::TIME_OFFSET_Y
private

Definition at line 65 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().


The documentation for this class was generated from the following files: