52 double referenceTicks,
57 firstWire = hitVec.front()->getHits()[planeToCheck]->getHit().WireID().Wire;
58 lastWire = hitVec.back()->getHits()[planeToCheck]->getHit().WireID().Wire;
60 double maxDeltaTicks = referenceTicks - hitVec.front()->getHits()[planeToCheck]->getTimeTicks();
61 double minDeltaTicks = referenceTicks - hitVec.back()->getHits()[planeToCheck]->getTimeTicks();
63 if (minDeltaTicks > maxDeltaTicks) std::swap(maxDeltaTicks, minDeltaTicks);
65 double bestDeltaTicks = 1000000.;
68 if (hitVec.size() > 1)
75 double nextBestDeltaTicks = bestDeltaTicks;
77 for(
const auto& hitPair : hitVec)
79 int curWire = hitPair->getHits()[planeToCheck]->getHit().WireID().Wire;
80 double deltaTicks = referenceTicks - hitPair->getHits()[planeToCheck]->getTimeTicks();
82 maxDeltaTicks =
std::max(maxDeltaTicks, deltaTicks);
83 minDeltaTicks =
std::min(minDeltaTicks, deltaTicks);
85 if (bestDeltaTicks > fabs(deltaTicks))
88 nextBestDeltaTicks = bestDeltaTicks;
89 bestDeltaTicks = fabs(deltaTicks);
91 else if (nextBestDeltaTicks > fabs(deltaTicks))
93 nextBestDeltaTicks = fabs(deltaTicks);
98 if (fabs(curWire - lastWire) > 2000)
100 if (referenceWire <= lastWire)
break;
104 maxDeltaTicks = deltaTicks;
105 minDeltaTicks = deltaTicks;
106 bestDeltaTicks = fabs(deltaTicks);
107 nextBestDeltaTicks = bestDeltaTicks;
113 bestDeltaTicks = nextBestDeltaTicks;
118 if (minDeltaTicks * maxDeltaTicks > 0. && bestDeltaTicks > 30.) bestDeltaTicks = 0.;
120 return bestDeltaTicks;
130 for(
const auto leftHit : left->
getHits())
132 if (leftHit->getHit().WireID().Plane == m_plane)
134 for(
const auto rightHit : right->
getHits())
136 if (rightHit->getHit().WireID().Plane == m_plane)
138 return leftHit->getHit().WireID().Wire < rightHit->getHit().WireID().Wire;
154 return left.second < right.second;
165 typedef std::map<const reco::ClusterHit2D*, std::vector<const reco::ClusterHit3D*> > Hit2DtoHit3DMapU;
167 Hit2DtoHit3DMapU hit2DToHit3DMap[3];
169 for(
const auto& hitPair : hitPairList)
175 unsigned status = hitPair->getStatusBits();
177 if ((status & 0x7) != 0x7)
continue;
179 for(
const auto& hit2D : hitPair->getHits())
181 size_t plane = hit2D->getHit().WireID().Plane;
183 hit2DToHit3DMap[plane][hit2D].push_back(hitPair);
188 for(
size_t idx = 0; idx < 3; idx++)
190 for(
auto& mapPair : hit2DToHit3DMap[idx])
192 size_t numHitPairs = mapPair.second.size();
193 int planeToCheck = (idx + 1) % 3;
195 if (numHitPairs > 1) std::sort(mapPair.second.begin(), mapPair.second.end(),
OrderHitsAlongWire(planeToCheck));
200 int nSkeletonPoints(0);
203 for(
const auto& hitPair : hitPairList)
209 if ((hitPair->getStatusBits() & 0x7) != 7)
continue;
223 size_t numHitPairs[3] = {0, 0, 0};
224 int deltaWires[3] = {0, 0, 0};
225 double planeDeltaT[3] = {0., 0., 0.};
226 double bestDeltaTicks[3] = {0., 0., 0.};
227 int wireNumByPlane[3] = {int(hitPair->getHits()[0]->getHit().WireID().Wire),
228 int(hitPair->getHits()[1]->getHit().WireID().Wire),
229 int(hitPair->getHits()[2]->getHit().WireID().Wire)};
231 size_t bestPlaneIdx(0);
234 for(
size_t planeIdx = 0; planeIdx < 3; planeIdx++)
239 std::vector<const reco::ClusterHit3D*>& hitVec(hit2DToHit3DMap[planeIdx][hit2D]);
241 numHitPairs[planeIdx] = hitVec.size();
243 if (numHitPairs[planeIdx] > 1)
245 int planeToCheck = (planeIdx + 1) % 3;
251 wireNumByPlane[planeToCheck],
256 int deltaFirst = wireNumByPlane[planeToCheck] - firstWire;
257 int deltaLast = wireNumByPlane[planeToCheck] - lastWire;
262 deltaWires[planeIdx] = deltaFirst + deltaLast;
263 numHitPairs[planeIdx] = lastWire - firstWire + 1;
264 planeDeltaT[planeIdx] = fabs(hit2DTimeTicks - hitPair->getHits()[planeToCheck]->getTimeTicks());
269 if (numHitPairs[planeIdx] < numHitPairs[bestPlaneIdx])
271 bestPlaneIdx = planeIdx;
276 if (bestPlaneIdx < 3 && numHitPairs[bestPlaneIdx] > 0)
279 int maxBestWires = 0.05 * numHitPairs[bestPlaneIdx] + 1;
284 if (fabs(deltaWires[bestPlaneIdx]) < maxBestWires + 1)
296 int nextBestIdx = (bestPlaneIdx + 1) % 3;
298 for(
size_t idx = 0; idx < 3; idx++)
300 if (idx == bestPlaneIdx)
continue;
302 if (numHitPairs[idx] < numHitPairs[nextBestIdx]) nextBestIdx = idx;
307 std::cout <<
"***** invalid next best plane: " << nextBestIdx <<
" *******" << std::endl;
311 if (planeDeltaT[bestPlaneIdx] < 1.01*bestDeltaTicks[bestPlaneIdx] && planeDeltaT[nextBestIdx] < 6.01*bestDeltaTicks[nextBestIdx])
321 return nSkeletonPoints;
337 typedef std::map<const reco::ClusterHit2D*, std::vector<const reco::ClusterHit3D*> > Hit2DtoHit3DMap;
340 Hit2DtoHit3DMap hit2DToHit3DMap[3];
343 unsigned int nSkeletonHits(0);
346 for(
const auto& hitPair : skeletonHitList)
354 for(
const auto& hit2D : hitPair->getHits())
356 size_t plane = hit2D->getHit().WireID().Plane;
358 hit2DToHit3DMap[plane][hit2D].push_back(hitPair);
363 if (!nSkeletonHits)
return;
367 for(
size_t idx = 0; idx < 3; idx++)
369 for(
auto& mapPair : hit2DToHit3DMap[idx])
371 size_t numHitPairs = mapPair.second.size();
372 int planeToCheck = (idx + 1) % 3;
374 if (numHitPairs > 1) std::sort(mapPair.second.begin(), mapPair.second.end(),
OrderHitsAlongWire(planeToCheck));
387 for(
int bestPlaneVecIdx = 0; bestPlaneVecIdx < 2; bestPlaneVecIdx++)
389 std::list<reco::ClusterHit3D> tempHitPairList;
392 std::map<const reco::ClusterHit3D*, const reco::ClusterHit3D*> hit3DToHit3DMap;
394 while(hitPairItr != skeletonHitList.end())
398 std::vector<std::pair<size_t,size_t> > bestPlaneVec;
400 for(
const auto& hit2D : hit3D->
getHits())
402 bestPlaneVec.push_back(std::pair<size_t,size_t>(hit2D->getHit().WireID().Plane,hit2DToHit3DMap[hit2D->getHit().WireID().Plane][hit2D].size()));
405 std::sort(bestPlaneVec.begin(), bestPlaneVec.end(),
OrderBestPlanes());
407 size_t bestPlaneIdx = bestPlaneVec[bestPlaneVecIdx].first;
408 size_t bestPlaneCnt = bestPlaneVec[bestPlaneVecIdx].second;
410 if (bestPlaneCnt > 5)
continue;
412 std::vector<const reco::ClusterHit3D*>& hit3DVec = hit2DToHit3DMap[bestPlaneIdx][hit3D->
getHits()[bestPlaneIdx]];
414 float avePosition[3] = {hit3D->
getPosition()[0],0.,0.};
416 for(
const auto& tempHit3D : hit3DVec)
418 avePosition[1] += tempHit3D->getPosition()[1];
419 avePosition[2] += tempHit3D->getPosition()[2];
422 avePosition[1] *= 1./double(hit3DVec.size());
423 avePosition[2] *= 1./double(hit3DVec.size());
439 tempHitPairListPtr.push_back(&tempHitPairList.back());
441 hit3DToHit3DMap[tempHitPairListPtr.back()] = hit3D;
444 for(
const auto& pair : hit3DToHit3DMap)
446 pair.second->
setPosition(pair.first->getPosition());
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
float getTimeTicks() const
Declaration of signal hit object.
const std::vector< float > getHitDelTSigVec() const
float getTotalCharge() const
Hit has been rejected for any reason.
float getSigmaPeakTime() const
unsigned int getStatusBits() const
void GetSkeletonHits(const reco::HitPairListPtr &inputHitList, reco::HitPairListPtr &skeletonHitList) const
Return the skeleton hits from the input list.
float getDocaToAxis() const
SkeletonAlg(fhicl::ParameterSet const &pset)
Constructor.
void reconfigure(fhicl::ParameterSet const &pset)
a handler for the case where the algorithm control parameters are to be reset
OrderHitsAlongWire(int plane=0)
float getAvePeakTime() const
int FindMedialSkeleton(reco::HitPairListPtr &hitPairList) const
This is intended to find the medial skeleton given a list of input hit pairs.
T get(std::string const &key) const
double m_minimumDeltaTicks
void AverageSkeletonPositions(reco::HitPairListPtr &skeletonHitList) const
Modifies the position of input skeleton hits by averaging along the "best" wire direction.
std::list< const reco::ClusterHit3D * > HitPairListPtr
bool operator()(const reco::ClusterHit3D *left, const reco::ClusterHit3D *right)
const float * getPosition() const
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
double m_maximumDeltaTicks
double FindFirstAndLastWires(std::vector< const reco::ClusterHit3D * > &hitVec, int planeToCheck, int referenceWire, double referenceTicks, int &firstWire, int &lastWire) const
A function to find the bounding wires in a given view.
bool operator()(const std::pair< size_t, size_t > &left, const std::pair< size_t, size_t > &right)
void setPosition(const float *pos) const
Header file to define the interface to the SkeletonAlg.
virtual ~SkeletonAlg()
Destructor.
const std::vector< geo::WireID > & getWireIDs() const
float getArclenToPoca() const
float getDeltaPeakTime() const
Skeleton hit position averaged.
float getHitChiSquare() const
const ClusterHit2DVec & getHits() const
art framework interface to geometry description