21 #include "TDecompSVD.h" 39 , m_minAllowedCosAng(0.7)
40 , m_pcaAlg(pset.
get<
fhicl::ParameterSet>(
"PrincipalComponentsAlg"))
52 bool foundGoodSeed(
false);
64 if (eigenVal0 > 5. && eigenVal1 > 0.001) {
78 hit3DList.resize(hitPairListPtr.size());
80 std::copy(hitPairListPtr.begin(), hitPairListPtr.end(), hit3DList.begin());
90 checkList.resize(hitPairListPtr.size());
92 std::copy(hitPairListPtr.begin(), hitPairListPtr.end(), checkList.begin());
94 std::reverse(checkList.begin(), checkList.end());
108 double seedDir[3] = {seedPca.getEigenVectors().row(2)(0),
109 seedPca.getEigenVectors().row(2)(1),
110 seedPca.getEigenVectors().row(2)(2)};
111 double seedStart[3] = {
112 hit3DList.front()->getX(), hit3DList.front()->getY(), hit3DList.front()->getZ()};
114 if (hit3DList.size() > 10) {
119 LineFit2DHits(hit3DList, seedStart[0], newSeedPos, newSeedDir, chiDOF);
123 double cosAng = seedDir[0] * newSeedDir[0] + seedDir[1] * newSeedDir[1] +
124 seedDir[2] * newSeedDir[2];
126 if (cosAng < 0.) newSeedDir *= -1.;
128 seedStart[0] = newSeedPos[0];
129 seedStart[1] = newSeedPos[1];
130 seedStart[2] = newSeedPos[2];
131 seedDir[0] = newSeedDir[0];
132 seedDir[1] = newSeedDir[1];
133 seedDir[2] = newSeedDir[2];
137 for (
const auto& hit3D : hit3DList)
138 hit3D->setStatusBit(0x40000000);
140 seedHitPairVec.emplace_back(std::pair<recob::Seed, reco::HitPairListPtr>(
143 foundGoodSeed =
true;
148 return foundGoodSeed;
154 bool foundGoodSeedHits(
false);
157 std::set<const reco::ClusterHit2D*> hit2DSet;
160 double lastArcLen = hit3DList.front()->getArclenToPoca();
165 while (++lastItr != hit3DList.end()) {
174 for (
const auto& hit2D : hit3D->
getHits()) {
175 hit2DSet.insert(hit2D);
184 if (startItr != hit3DList.begin()) hit3DList.erase(hit3DList.begin(), startItr);
185 if (lastItr != hit3DList.end()) hit3DList.erase(lastItr, hit3DList.end());
199 double cosAng = primarySeedAxis.dot(planeVec0);
207 return foundGoodSeedHits;
215 double& ChiDOF)
const 238 std::set<const reco::ClusterHit2D*> hit2DSet;
240 for (
const auto& hit3D : hit3DList) {
241 for (
const auto& hit2D : hit3D->getHits())
242 hit2DSet.insert(hit2D);
245 if (hit2DSet.size() < 4)
return;
247 const unsigned int nvars = 4;
248 unsigned int npts = 3 * hit3DList.size();
250 TMatrixD A(npts, nvars);
253 unsigned short ninpl[3] = {0};
254 unsigned short nok = 0;
255 unsigned short iht(0);
258 for (
const auto&
hit : hit2DSet) {
260 unsigned int ipl = wireID.
Plane;
271 double const x =
hit->getXPosition() - XOrigin;
277 w[iht] = wireID.
Wire - off;
282 if (ninpl[ipl] == 2) ++nok;
292 TVectorD tVec = svd.Solve(w, ok);
297 if (npts <= 4)
return;
299 for (
const auto&
hit : hit2DSet) {
304 double const x =
hit->getXPosition() - XOrigin;
305 double const ypr = tVec[0] + tVec[2] *
x;
306 double const zpr = tVec[1] + tVec[3] *
x;
307 double const diff = ypr * cw + zpr * sw - (wireID.
Wire - off);
308 ChiDOF += diff * diff;
313 ChiDOF /= (float)(npts - 4);
315 double norm = sqrt(1 + tVec[2] * tVec[2] + tVec[3] * tVec[3]);
317 Dir[1] = tVec[2] /
norm;
318 Dir[2] = tVec[3] /
norm;
Define a comparator which will sort hits by arc length along a PCA axis.
Length_t WireCoordinate(Point_t const &pos, PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
void PCAAnalysis_calc3DDocas(const reco::HitPairListPtr &hitPairVector, const reco::PrincipalComponents &pca) const
bool getHitsAtEnd(reco::HitPairListPtr &hit3DList, reco::PrincipalComponents &seedPca) const
Separate function to find hits at the ends of the input hits.
geo::Geometry const * m_geometry
void PCAAnalysis_3D(const reco::HitPairListPtr &hitPairList, reco::PrincipalComponents &pca, bool skeletonOnly=false) const
void flipAxis(size_t axis)
WireID_t Wire
Index of the wire within its plane.
PrincipalComponentsAlg m_pcaAlg
This is an algorithm for finding recob::Seed objects in 3D clusters.
Define a comparator which will sort hits by the absolute value of arc length so hits are ordered clos...
const EigenValues & getEigenValues() const
T get(std::string const &key) const
bool findTrackSeeds(reco::HitPairListPtr &hitPairListPtr, reco::PrincipalComponents &inputPCA, SeedHitPairListPairVec &seedHitMap) const override
Given the list of hits this will search for candidate Seed objects and return them.
std::list< const reco::ClusterHit3D * > HitPairListPtr
PlaneID_t Plane
Index of the plane within its TPC.
Detector simulation of raw signals on wires.
double m_minAllowedCosAng
The minimum cos(ang) between input and seed axes.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
PCASeedFinderAlg(fhicl::ParameterSet const &pset)
Constructor.
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
std::vector< SeedHitPairListPair > SeedHitPairListPairVec
float getArclenToPoca() const
void LineFit2DHits(const reco::HitPairListPtr &hitList, double XOrigin, TVector3 &Pos, TVector3 &Dir, double &ChiDOF) const
const ClusterHit2DVec & getHits() const
Length_t WirePitch(PlaneID const &planeid=plane_zero) const
Returns the distance between two consecutive wires.
art framework interface to geometry description
const EigenVectors & getEigenVectors() const