LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
sppt::SpacePointAlg_TimeSort Class Reference

#include "SpacePointAlg_TimeSort.h"

Public Member Functions

 SpacePointAlg_TimeSort (fhicl::ParameterSet const &pset)
 
 ~SpacePointAlg_TimeSort ()
 
void reconfigure (fhicl::ParameterSet const &pset)
 
void setTimeOffsets ()
 
void fillCoordinatesArrays ()
 
void createSpacePoints (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)
 

Private Attributes

float fTimeDiffMax
 
float fYDiffMax
 Maximum allowed time difference. More...
 
float fZDiffMax
 Maximum allowed y-coordinate difference. More...
 
bool TIME_OFFSET_SET
 Maximum allowed z-coordinate difference. More...
 
bool COORDINATES_FILLED
 
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 34 of file SpacePointAlg_TimeSort.h.

Constructor & Destructor Documentation

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

Definition at line 37 of file SpacePointAlg_TimeSort.cxx.

References COORDINATES_FILLED, reconfigure(), and TIME_OFFSET_SET.

37  {
38  this->reconfigure(pset);
39  TIME_OFFSET_SET = false;
40  COORDINATES_FILLED = false;
41  }
bool TIME_OFFSET_SET
Maximum allowed z-coordinate difference.
void reconfigure(fhicl::ParameterSet const &pset)
sppt::SpacePointAlg_TimeSort::~SpacePointAlg_TimeSort ( )

Definition at line 44 of file SpacePointAlg_TimeSort.cxx.

44 {}

Member Function Documentation

void sppt::SpacePointAlg_TimeSort::createSpacePoints ( 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 113 of file SpacePointAlg_TimeSort.cxx.

References COORDINATES_FILLED, coordinates_UV_y, coordinates_UV_z, coordinates_UY_y, coordinates_UY_z, fillCoordinatesArrays(), fTimeDiffMax, fYDiffMax, fZDiffMax, 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().

118  {
119 
120  if(!TIME_OFFSET_SET){
121  mf::LogWarning("SpacePointAlg_TimeSort")
122  << "Time offsets not set before createSpacePoints call!"
123  << "\nYou should call SpacePointAlg_TimeSort::setTimeOffsets() in beginRun()!"
124  << "\nWill be set now, but you should modify your code!";
125  setTimeOffsets();
126  }
127  if(!COORDINATES_FILLED){
128  mf::LogWarning("SpacePointAlg_TimeSort")
129  << "Coordinate arrays not filled before createSpacePoints call!"
130  << "\nYou should call SpacePointAlg_TimeSort::fillCoordinateArrays() in beginRun()!"
131  << "\nWill be filled now, but you should modify your code!";
133  }
134 
135  //sort the hits by the time
136  sortHitsByTime(hitVec_U);
137  sortHitsByTime(hitVec_V);
138  sortHitsByTime(hitVec_Y);
139 
140  LOG_DEBUG("SpacePointAlg_TimeSort")
141  << "Sorted "
142  << hitVec_U.size() << " u hits, "
143  << hitVec_V.size() << " v hits, "
144  << hitVec_Y.size() << " y hits.";
145 
146  //now, do the loop to search for like-timed hits across the three planes
147  std::vector< art::Ptr<recob::Hit> >::iterator ihitu = hitVec_U.begin();
148  std::vector< art::Ptr<recob::Hit> >::iterator ihitv = hitVec_V.begin();
149  std::vector< art::Ptr<recob::Hit> >::iterator ihity = hitVec_Y.begin();
150  std::vector< art::Ptr<recob::Hit> >::iterator ihitv_inner,ihity_inner;
151  double time_hitu = (*ihitu)->PeakTime() + TIME_OFFSET_U;
152  double time_hitv = (*ihitv)->PeakTime() + TIME_OFFSET_V;
153  double time_hity = (*ihity)->PeakTime() + TIME_OFFSET_Y;
154  double time_hitv_inner,time_hity_inner;
155  while(ihitu != hitVec_U.end()){
156  time_hitu = (*ihitu)->PeakTime() + TIME_OFFSET_U;
157 
158  mf::LogInfo("SpacePointAlg_TimeSort")
159  << "Hit times (u,v,y)=("
160  << time_hitu << ","
161  << time_hitv << ","
162  << time_hity << ")";
163 
164  //if time_hitu is too much bigger than time_hitv, need to advance hitv iterator
165  while( (time_hitu-time_hitv)>fTimeDiffMax ){
166  ihitv++;
167  if(ihitv==hitVec_V.end()) break;
168  time_hitv = (*ihitv)->PeakTime() + TIME_OFFSET_V;
169  }
170  if(ihitv==hitVec_V.end()) break;
171 
172  //same thing with time_hitu and time_hity
173  while( (time_hitu-time_hity)>fTimeDiffMax ){
174  ihity++;
175  if(ihity==hitVec_Y.end()) break;
176  time_hity = (*ihity)->PeakTime() + TIME_OFFSET_Y;
177  }
178  if(ihity==hitVec_Y.end()) break;
179 
180  //OK, now we know time_hitu <= time_hitv and time_hitu <= time_hity.
181  //Next, check if time_hitu is near time_hitv and time_hit y. If not,
182  //we have to increment ihitu.
183  if(std::abs(time_hitu-time_hitv)>fTimeDiffMax || std::abs(time_hitu-time_hity)>fTimeDiffMax){
184  ihitu++;
185  continue;
186  }
187 
188  //OK! Note we KNOW that these three match in time:
189  // -- time_hitu is within fTimeDiffMax of both time_hitv and time_hity; and
190  // -- time_hitu <= time_hitv AND time_hitu <=time_hity, so time_hitv and time_hity are near too
191 
192  mf::LogInfo("SpacePointAlg_TimeSort")
193  << "Matching hit times (u,v,y)=("
194  << time_hitu << ","
195  << time_hitv << ","
196  << time_hity << ")";
197 
198  //Next thing to do, we need to loop over all possible 3-hit matches for our given u-hit.
199  //We need new iterators in v and y at this location, and will loop over those
200  ihitv_inner = ihitv;
201  time_hitv_inner = (*ihitv_inner)->PeakTime() + TIME_OFFSET_V;
202  ihity_inner = ihity;
203  time_hity_inner = (*ihity_inner)->PeakTime() + TIME_OFFSET_Y;
204 
205  while(std::abs(time_hitu-time_hitv_inner)<fTimeDiffMax && std::abs(time_hitu-time_hity_inner)<fTimeDiffMax){
206 
207  unsigned int uwire = (*ihitu)->WireID().Wire;
208  unsigned int vwire = (*ihitv_inner)->WireID().Wire;
209  unsigned int ywire = (*ihity_inner)->WireID().Wire;
210 
211  mf::LogInfo("SpacePointAlg_TimeSort")
212  << "(y,z) coordinate for uv/uy: ("
213  << coordinates_UV_y[vwire][uwire] << ","
214  << coordinates_UV_z[vwire][uwire] << ")/("
215  << 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  //util::CreateAssn(*this, evt, *spptCollection, myhits, *spptAssns);
249  }
250 
251  //now increment the v or y hit, whichever is smalles (closest to u hit) in time
252  if(time_hitv_inner <= time_hity_inner){
253  ihitv_inner++;
254  if(ihitv_inner==hitVec_V.end()) break;
255  time_hitv_inner = (*ihitv_inner)->PeakTime() + TIME_OFFSET_V;
256  }
257  else{
258  ihity_inner++;
259  if(ihity_inner==hitVec_Y.end()) break;
260  time_hity_inner = (*ihity_inner)->PeakTime() + TIME_OFFSET_Y;
261  }
262 
263  }
264 
265  ihitu++;
266  }// end while looping over u hits
267 
268  LOG_DEBUG("SpacePointAlg_TimeSort")
269  << "Finished with " << spptCollection->size() << " spacepoints.";
270 
271  }//end createSpacePoints
float fYDiffMax
Maximum allowed time difference.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
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 LOG_DEBUG(id)
void sortHitsByTime(std::vector< art::Ptr< recob::Hit > > &hits_handle)
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, geo::GeometryCore::IntersectionPoint(), geo::kU, geo::kV, geo::kZ, and geo::GeometryCore::Nwires().

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

81  {
82 
84  unsigned int nwires_u = geom->Nwires(geo::View_t::kU);
85  unsigned int nwires_v = geom->Nwires(geo::View_t::kV);
86  unsigned int nwires_y = geom->Nwires(geo::View_t::kZ);
87 
88  coordinates_UV_y.resize(boost::extents[nwires_v][nwires_u]);
89  coordinates_UV_z.resize(boost::extents[nwires_v][nwires_u]);
90  coordinates_UY_y.resize(boost::extents[nwires_y][nwires_u]);
91  coordinates_UY_z.resize(boost::extents[nwires_y][nwires_u]);
92  for(unsigned int iu=0; iu<nwires_u; iu++){
93  for(unsigned int iv=0; iv<nwires_v; iv++){
94  geom->IntersectionPoint(iu,iv,
96  0,0,
97  coordinates_UV_y[iv][iu], //y
98  coordinates_UV_z[iv][iu]); //z
99  }
100  for(unsigned int iy=0; iy<nwires_y; iy++){
101  geom->IntersectionPoint(iu,iy,
103  0,0,
104  coordinates_UY_y[iy][iu],
105  coordinates_UY_z[iy][iu]);
106  }
107  }
108 
109  COORDINATES_FILLED = true;
110  }
Planes which measure V.
Definition: geo_types.h:77
boost::multi_array< double, 2 > coordinates_UV_y
Planes which measure Z direction.
Definition: geo_types.h:79
boost::multi_array< double, 2 > coordinates_UY_z
unsigned int Nwires(unsigned int p, unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wires in the specified plane.
Planes which measure U.
Definition: geo_types.h:76
bool IntersectionPoint(geo::WireID const &wid1, geo::WireID const &wid2, double &y, double &z) const
Returns the intersection point of two wires.
boost::multi_array< double, 2 > coordinates_UY_y
boost::multi_array< double, 2 > coordinates_UV_z
void sppt::SpacePointAlg_TimeSort::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 47 of file SpacePointAlg_TimeSort.cxx.

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

Referenced by sppt::TTSpacePointFinder::reconfigure(), and SpacePointAlg_TimeSort().

47  {
48  fTimeDiffMax = p.get< float >("TimeDiffMax");
49  fZDiffMax = p.get< float >("ZDiffMax");
50  fYDiffMax = p.get< float >("YDiffMax");
51 
52  //enforce a minimum time diff
53  if(fTimeDiffMax<0){
54  mf::LogError("SpacePointAlg_TimeSort") << "Time difference must be greater than zero.";
55  return;
56  }
57  if(fZDiffMax<0){
58  mf::LogError("SpacePointAlg_TimeSort") << "Z-coordinate difference must be greater than zero.";
59  return;
60  }
61  if(fYDiffMax<0){
62  mf::LogError("SpacePointAlg_TimeSort") << "Y-coordinate difference must be greater than zero.";
63  return;
64  }
65 
66  }
float fYDiffMax
Maximum allowed time difference.
float fZDiffMax
Maximum allowed y-coordinate difference.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void sppt::SpacePointAlg_TimeSort::setTimeOffsets ( )

Definition at line 69 of file SpacePointAlg_TimeSort.cxx.

References detinfo::DetectorProperties::GetXTicksCoefficient(), detinfo::DetectorProperties::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().

69  {
70 
71  const detinfo::DetectorProperties* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
75  TICKS_TO_X = detprop->GetXTicksCoefficient();
76 
77  TIME_OFFSET_SET = true;
78  }
Planes which measure V.
Definition: geo_types.h:77
Planes which measure Z direction.
Definition: geo_types.h:79
Planes which measure U.
Definition: geo_types.h:76
bool TIME_OFFSET_SET
Maximum allowed z-coordinate difference.
virtual double GetXTicksCoefficient(int t, int c) const =0
virtual double GetXTicksOffset(int p, int t, int c) const =0
void sppt::SpacePointAlg_TimeSort::sortHitsByTime ( std::vector< art::Ptr< recob::Hit > > &  hits_handle)
private

Definition at line 274 of file SpacePointAlg_TimeSort.cxx.

References sppt::HitTimeComparison().

Referenced by createSpacePoints().

274  {
275  std::sort(hitVec.begin(),hitVec.end(),HitTimeComparison);
276  }
bool HitTimeComparison(art::Ptr< recob::Hit > a, art::Ptr< recob::Hit > b)

Member Data Documentation

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

Definition at line 64 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 65 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 66 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 67 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and fillCoordinatesArrays().

float sppt::SpacePointAlg_TimeSort::fTimeDiffMax
private

Definition at line 52 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and reconfigure().

float sppt::SpacePointAlg_TimeSort::fYDiffMax
private

Maximum allowed time difference.

Definition at line 53 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and reconfigure().

float sppt::SpacePointAlg_TimeSort::fZDiffMax
private

Maximum allowed y-coordinate difference.

Definition at line 54 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and reconfigure().

double sppt::SpacePointAlg_TimeSort::TICKS_TO_X
private

Definition at line 62 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().

bool sppt::SpacePointAlg_TimeSort::TIME_OFFSET_SET
private

Maximum allowed z-coordinate difference.

Definition at line 56 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), setTimeOffsets(), and SpacePointAlg_TimeSort().

double sppt::SpacePointAlg_TimeSort::TIME_OFFSET_U
private

Definition at line 59 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().

double sppt::SpacePointAlg_TimeSort::TIME_OFFSET_V
private

Definition at line 60 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().

double sppt::SpacePointAlg_TimeSort::TIME_OFFSET_Y
private

Definition at line 61 of file SpacePointAlg_TimeSort.h.

Referenced by createSpacePoints(), and setTimeOffsets().


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