23 #include "art/Framework/Services/Registry/ServiceHandle.h"
24 #include "canvas/Persistency/Common/Ptr.h"
25 #include "cetlib_except/exception.h"
26 #include "messagefacility/MessageLogger/MessageLogger.h"
36 #include "boost/multi_array.hpp"
40 HitTimeComparison(art::Ptr<recob::Hit>
const&
a, art::Ptr<recob::Hit>
const& b)
42 return a->PeakTime() < b->PeakTime();
57 throw cet::exception(
"SpacePointAlg_TimeSort")
58 <<
"Time difference must be greater than zero.";
61 throw cet::exception(
"SpacePointAlg_TimeSort")
62 <<
"Z-coordinate difference must be greater than zero.";
65 throw cet::exception(
"SpacePointAlg_TimeSort")
66 <<
"Y-coordinate difference must be greater than zero.";
86 art::ServiceHandle<geo::Geometry const> geom;
95 for (
unsigned int iu = 0; iu < nwires_u; iu++) {
96 for (
unsigned int iv = 0; iv < nwires_v; iv++) {
97 geom->IntersectionPoint(iu,
106 for (
unsigned int iy = 0; iy < nwires_y; iy++) {
107 geom->IntersectionPoint(iu,
128 std::unique_ptr<std::vector<recob::SpacePoint>>& spptCollection,
133 mf::LogWarning(
"SpacePointAlg_TimeSort")
134 <<
"Time offsets not set before createSpacePoints call!"
135 <<
"\nYou should call SpacePointAlg_TimeSort::setTimeOffsets() in beginRun()!"
136 <<
"\nWill be set now, but you should modify your code!";
140 mf::LogWarning(
"SpacePointAlg_TimeSort")
141 <<
"Coordinate arrays not filled before createSpacePoints call!"
142 <<
"\nYou should call SpacePointAlg_TimeSort::fillCoordinateArrays() in beginRun()!"
143 <<
"\nWill be filled now, but you should modify your code!";
152 MF_LOG_DEBUG(
"SpacePointAlg_TimeSort")
153 <<
"Sorted " << hitVec_U.size() <<
" u hits, " << hitVec_V.size() <<
" v hits, "
154 << hitVec_Y.size() <<
" y hits.";
157 std::vector<art::Ptr<recob::Hit>>::iterator ihitu = hitVec_U.begin();
158 std::vector<art::Ptr<recob::Hit>>::iterator ihitv = hitVec_V.begin();
159 std::vector<art::Ptr<recob::Hit>>::iterator ihity = hitVec_Y.begin();
160 std::vector<art::Ptr<recob::Hit>>::iterator ihitv_inner, ihity_inner;
164 double time_hitv_inner, time_hity_inner;
165 while (ihitu != hitVec_U.end()) {
168 mf::LogInfo(
"SpacePointAlg_TimeSort")
169 <<
"Hit times (u,v,y)=(" << time_hitu <<
"," << time_hitv <<
"," << time_hity <<
")";
174 if (ihitv == hitVec_V.end())
break;
177 if (ihitv == hitVec_V.end())
break;
182 if (ihity == hitVec_Y.end())
break;
185 if (ihity == hitVec_Y.end())
break;
200 mf::LogInfo(
"SpacePointAlg_TimeSort") <<
"Matching hit times (u,v,y)=(" << time_hitu <<
","
201 << time_hitv <<
"," << time_hity <<
")";
206 time_hitv_inner = (*ihitv_inner)->PeakTime() +
TIME_OFFSET_V;
208 time_hity_inner = (*ihity_inner)->PeakTime() +
TIME_OFFSET_Y;
213 unsigned int uwire = (*ihitu)->WireID().Wire;
214 unsigned int vwire = (*ihitv_inner)->WireID().Wire;
215 unsigned int ywire = (*ihity_inner)->WireID().Wire;
217 mf::LogInfo(
"SpacePointAlg_TimeSort")
235 xyz[2] = (
coordinates_UV_z[vwire][uwire] + coordinates_UY_z[ywire][uwire]) * 0.5;
238 double t_val = (time_hitu + time_hitv_inner + time_hity_inner) / 3.;
239 double t_err = 0.5 * std::sqrt((time_hitu - t_val) * (time_hitu - t_val) +
240 (time_hitv_inner - t_val) * (time_hitv_inner - t_val) +
241 (time_hity_inner - t_val) * (time_hity_inner - t_val));
247 spptCollection->push_back(spt);
250 std::vector<art::Ptr<recob::Hit>> myhits = {*ihitu, *ihitv_inner, *ihity_inner};
251 spptAssociatedHits->push_back(myhits);
255 if (time_hitv_inner <= time_hity_inner) {
257 if (ihitv_inner == hitVec_V.end())
break;
258 time_hitv_inner = (*ihitv_inner)->PeakTime() +
TIME_OFFSET_V;
262 if (ihity_inner == hitVec_Y.end())
break;
263 time_hity_inner = (*ihity_inner)->PeakTime() +
TIME_OFFSET_Y;
270 MF_LOG_DEBUG(
"SpacePointAlg_TimeSort")
271 <<
"Finished with " << spptCollection->size() <<
" spacepoints.";
279 std::sort(hitVec.begin(), hitVec.end(), HitTimeComparison);
void sortHitsByTime(std::vector< art::Ptr< recob::Hit >> &hits_handle) const
SpacePointAlg_TimeSort(fhicl::ParameterSet const &pset)
float fYDiffMax
Maximum allowed time difference.
void setTimeOffsets(detinfo::DetectorPropertiesData const &detProp)
double GetXTicksCoefficient(int t, int c) const
double GetXTicksOffset(int p, int t, int c) const
Declaration of signal hit object.
boost::multi_array< double, 2 > coordinates_UV_y
Planes which measure Z direction.
float fZDiffMax
Maximum allowed y-coordinate difference.
boost::multi_array< double, 2 > coordinates_UY_z
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
bool TIME_OFFSET_SET
Maximum allowed z-coordinate difference.
Definition of data types for geometry description.
boost::multi_array< double, 2 > coordinates_UY_y
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)
art framework interface to geometry description
boost::multi_array< double, 2 > coordinates_UV_z