18 #include "lardata/RecoObjects/Cluster3D.h" 53 double referenceTicks,
58 firstWire = hitVec.front()->getHits()[viewToCheck]->getHit().WireID().Wire;
59 lastWire = hitVec.back()->getHits()[viewToCheck]->getHit().WireID().Wire;
61 double maxDeltaTicks = referenceTicks - hitVec.front()->getHits()[viewToCheck]->getTimeTicks();
62 double minDeltaTicks = referenceTicks - hitVec.back()->getHits()[viewToCheck]->getTimeTicks();
64 if (minDeltaTicks > maxDeltaTicks)
std::swap(maxDeltaTicks, minDeltaTicks);
66 double bestDeltaTicks = 1000000.;
69 if (hitVec.size() > 1)
76 double nextBestDeltaTicks = bestDeltaTicks;
78 for(
const auto& hitPair : hitVec)
80 int curWire = hitPair->getHits()[viewToCheck]->getHit().WireID().Wire;
81 double deltaTicks = referenceTicks - hitPair->getHits()[viewToCheck]->getTimeTicks();
83 maxDeltaTicks =
std::max(maxDeltaTicks, deltaTicks);
84 minDeltaTicks =
std::min(minDeltaTicks, deltaTicks);
86 if (bestDeltaTicks > fabs(deltaTicks))
89 nextBestDeltaTicks = bestDeltaTicks;
90 bestDeltaTicks = fabs(deltaTicks);
92 else if (nextBestDeltaTicks > fabs(deltaTicks))
94 nextBestDeltaTicks = fabs(deltaTicks);
99 if (fabs(curWire - lastWire) > 2000)
101 if (referenceWire <= lastWire)
break;
105 maxDeltaTicks = deltaTicks;
106 minDeltaTicks = deltaTicks;
107 bestDeltaTicks = fabs(deltaTicks);
108 nextBestDeltaTicks = bestDeltaTicks;
114 bestDeltaTicks = nextBestDeltaTicks;
119 if (minDeltaTicks * maxDeltaTicks > 0. && bestDeltaTicks > 30.) bestDeltaTicks = 0.;
121 return bestDeltaTicks;
131 int viewToCheck = (m_view + 1) % 3;
133 return left->
getHits()[viewToCheck]->getHit().WireID().Wire < right->
getHits()[viewToCheck]->getHit().WireID().Wire;
143 return left.second < right.second;
154 typedef std::map<const reco::ClusterHit2D*, std::vector<const reco::ClusterHit3D*> > Hit2DtoHit3DMapU;
156 Hit2DtoHit3DMapU hit2DToHit3DMap[3];
158 for(
const auto& hitPair : hitPairList)
163 for(
const auto& hit2D : hitPair->getHits())
165 size_t view = hit2D->getHit().View();
167 hit2DToHit3DMap[view][hit2D].push_back(hitPair);
172 for(
size_t idx = 0; idx < 3; idx++)
174 for(
auto& mapPair : hit2DToHit3DMap[idx])
176 size_t numHitPairs = mapPair.second.size();
178 if (numHitPairs > 1) std::sort(mapPair.second.begin(), mapPair.second.end(),
OrderHitsAlongWire(idx));
183 int nSkeletonPoints(0);
186 for(
const auto& hitPair : hitPairList)
192 if (hitPair->getHits().size() < 3)
continue;
206 size_t numHitPairs[3] = {0, 0, 0};
207 int deltaWires[3] = {0, 0, 0};
208 double viewDeltaT[3] = {0., 0., 0.};
209 double bestDeltaTicks[3] = {0., 0., 0.};
210 int wireNumByView[3] = {
int(hitPair->getHits()[0]->getHit().WireID().Wire),
211 int(hitPair->getHits()[1]->getHit().WireID().Wire),
212 int(hitPair->getHits()[2]->getHit().WireID().Wire)};
214 size_t bestViewIdx(0);
217 for(
size_t viewIdx = 0; viewIdx < 3; viewIdx++)
222 std::vector<const reco::ClusterHit3D*>& hitVec(hit2DToHit3DMap[viewIdx][hit2D]);
224 numHitPairs[viewIdx] = hitVec.size();
226 if (numHitPairs[viewIdx] > 1)
228 int viewToCheck = (viewIdx + 1) % 3;
234 wireNumByView[viewToCheck],
239 int deltaFirst = wireNumByView[viewToCheck] - firstWire;
240 int deltaLast = wireNumByView[viewToCheck] - lastWire;
245 deltaWires[viewIdx] = deltaFirst + deltaLast;
246 numHitPairs[viewIdx] = lastWire - firstWire + 1;
247 viewDeltaT[viewIdx] = fabs(hit2DTimeTicks - hitPair->getHits()[viewToCheck]->getTimeTicks());
252 if (numHitPairs[viewIdx] < numHitPairs[bestViewIdx])
254 bestViewIdx = viewIdx;
259 if (bestViewIdx < 3 && numHitPairs[bestViewIdx] > 0)
262 int maxBestWires = 0.05 * numHitPairs[bestViewIdx] + 1;
267 if (fabs(deltaWires[bestViewIdx]) < maxBestWires + 1)
279 int nextBestIdx = (bestViewIdx + 1) % 3;
281 for(
size_t idx = 0; idx < 3; idx++)
283 if (idx == bestViewIdx)
continue;
285 if (numHitPairs[idx] < numHitPairs[nextBestIdx]) nextBestIdx = idx;
290 std::cout <<
"***** invalid next best view: " << nextBestIdx <<
" *******" <<
std::endl;
294 if (viewDeltaT[bestViewIdx] < 1.01*bestDeltaTicks[bestViewIdx] && viewDeltaT[nextBestIdx] < 6.01*bestDeltaTicks[nextBestIdx])
304 return nSkeletonPoints;
320 typedef std::map<const reco::ClusterHit2D*, std::vector<const reco::ClusterHit3D*> > Hit2DtoHit3DMap;
323 Hit2DtoHit3DMap hit2DToHit3DMap[3];
326 unsigned int nSkeletonHits(0);
329 for(
const auto& hitPair : skeletonHitList)
337 for(
const auto& hit2D : hitPair->getHits())
339 size_t view = hit2D->getHit().View();
341 hit2DToHit3DMap[view][hit2D].push_back(hitPair);
346 if (!nSkeletonHits)
return;
350 for(
size_t idx = 0; idx < 3; idx++)
352 for(
auto& mapPair : hit2DToHit3DMap[idx])
354 size_t numHitPairs = mapPair.second.size();
356 if (numHitPairs > 1) std::sort(mapPair.second.begin(), mapPair.second.end(),
OrderHitsAlongWire(idx));
369 for(
int bestViewVecIdx = 0; bestViewVecIdx < 2; bestViewVecIdx++)
371 std::list<reco::ClusterHit3D> tempHitPairList;
374 std::map<const reco::ClusterHit3D*, const reco::ClusterHit3D*> hit3DToHit3DMap;
376 while(hitPairItr != skeletonHitList.end())
380 std::vector<std::pair<size_t,size_t> > bestViewVec;
382 for(
const auto& hit2D : hit3D->
getHits())
384 bestViewVec.push_back(std::pair<size_t,size_t>(hit2D->getHit().View(),hit2DToHit3DMap[hit2D->getHit().View()][hit2D].size()));
387 std::sort(bestViewVec.begin(), bestViewVec.end(),
OrderBestViews());
389 size_t bestViewIdx = bestViewVec[bestViewVecIdx].first;
390 size_t bestViewCnt = bestViewVec[bestViewVecIdx].second;
392 if (bestViewCnt > 5)
continue;
394 std::vector<const reco::ClusterHit3D*>& hit3DVec = hit2DToHit3DMap[bestViewIdx][hit3D->
getHits()[bestViewIdx]];
396 double avePosition[3] = {hit3D->
getPosition()[0],0.,0.};
398 for(
const auto& tempHit3D : hit3DVec)
400 avePosition[1] += tempHit3D->getPosition()[1];
401 avePosition[2] += tempHit3D->getPosition()[2];
404 avePosition[1] *= 1./double(hit3DVec.size());
405 avePosition[2] *= 1./double(hit3DVec.size());
419 tempHitPairListPtr.push_back(&tempHitPairList.back());
421 hit3DToHit3DMap[tempHitPairListPtr.back()] = hit3D;
424 for(
const auto& pair : hit3DToHit3DMap)
426 pair.second->
setPosition(pair.first->getPosition());
float getTimeTicks() const
const Eigen::Vector3f getPosition() const
Declaration of signal hit object.
float getTotalCharge() const
Hit has been rejected for any reason.
float getSigmaPeakTime() const
float getOverlapFraction() 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.
art framework interface to geometry description
OrderHitsAlongWire(int view=0)
void reconfigure(fhicl::ParameterSet const &pset)
a handler for the case where the algorithm control parameters are to be reset
float getAvePeakTime() const
bool operator()(const std::pair< size_t, size_t > &left, const std::pair< size_t, size_t > &right)
void swap(Handle< T > &a, Handle< T > &b)
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)
static int max(int a, int b)
double FindFirstAndLastWires(std::vector< const reco::ClusterHit3D * > &hitVec, int viewToCheck, int referenceWire, double referenceTicks, int &firstWire, int &lastWire) const
A function to find the bounding wires in a given view.
double m_maximumDeltaTicks
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
virtual ~SkeletonAlg()
Destructor.
float getArclenToPoca() const
float getDeltaPeakTime() const
Skeleton hit position averaged.
const ClusterHit2DVec & getHits() const
void setPosition(const Eigen::Vector3f &pos) const
QTextStream & endl(QTextStream &s)