22 #include "TDecompSVD.h" 40 , m_minAllowedCosAng(0.7)
41 , m_pcaAlg(pset.
get<
fhicl::ParameterSet>(
"PrincipalComponentsAlg"))
53 bool foundGoodSeed(
false);
65 if (eigenVal0 > 5. && eigenVal1 > 0.001) {
79 hit3DList.resize(hitPairListPtr.size());
81 std::copy(hitPairListPtr.begin(), hitPairListPtr.end(), hit3DList.begin());
91 checkList.resize(hitPairListPtr.size());
93 std::copy(hitPairListPtr.begin(), hitPairListPtr.end(), checkList.begin());
95 std::reverse(checkList.begin(), checkList.end());
109 double seedDir[3] = {seedPca.getEigenVectors().row(2)(0),
110 seedPca.getEigenVectors().row(2)(1),
111 seedPca.getEigenVectors().row(2)(2)};
112 double seedStart[3] = {
113 hit3DList.front()->getX(), hit3DList.front()->getY(), hit3DList.front()->getZ()};
115 if (hit3DList.size() > 10) {
120 LineFit2DHits(hit3DList, seedStart[0], newSeedPos, newSeedDir, chiDOF);
124 double cosAng = seedDir[0] * newSeedDir[0] + seedDir[1] * newSeedDir[1] +
125 seedDir[2] * newSeedDir[2];
127 if (cosAng < 0.) newSeedDir *= -1.;
129 seedStart[0] = newSeedPos[0];
130 seedStart[1] = newSeedPos[1];
131 seedStart[2] = newSeedPos[2];
132 seedDir[0] = newSeedDir[0];
133 seedDir[1] = newSeedDir[1];
134 seedDir[2] = newSeedDir[2];
138 for (
const auto& hit3D : hit3DList)
139 hit3D->setStatusBit(0x40000000);
141 seedHitPairVec.emplace_back(std::pair<recob::Seed, reco::HitPairListPtr>(
144 foundGoodSeed =
true;
149 return foundGoodSeed;
155 bool foundGoodSeedHits(
false);
158 std::set<const reco::ClusterHit2D*> hit2DSet;
161 double lastArcLen = hit3DList.front()->getArclenToPoca();
166 while (++lastItr != hit3DList.end()) {
175 for (
const auto& hit2D : hit3D->
getHits()) {
176 hit2DSet.insert(hit2D);
185 if (startItr != hit3DList.begin()) hit3DList.erase(hit3DList.begin(), startItr);
186 if (lastItr != hit3DList.end()) hit3DList.erase(lastItr, hit3DList.end());
200 double cosAng = primarySeedAxis.dot(planeVec0);
208 return foundGoodSeedHits;
216 double& ChiDOF)
const 239 std::set<const reco::ClusterHit2D*> hit2DSet;
241 for (
const auto& hit3D : hit3DList) {
242 for (
const auto& hit2D : hit3D->getHits())
243 hit2DSet.insert(hit2D);
246 if (hit2DSet.size() < 4)
return;
248 const unsigned int nvars = 4;
249 unsigned int npts = 3 * hit3DList.size();
251 TMatrixD A(npts, nvars);
254 unsigned short ninpl[3] = {0};
255 unsigned short nok = 0;
256 unsigned short iht(0);
259 for (
const auto&
hit : hit2DSet) {
262 unsigned int ipl = wireID.
Plane;
265 double const off = plane.WireCoordinate(
geo::Point_t{0, 0, 0});
268 double const cw = plane.WireCoordinate(
geo::Point_t{0, 1, 0}) - off;
271 double const sw = plane.WireCoordinate(
geo::Point_t{0, 0, 1}) - off;
273 double const x =
hit->getXPosition() - XOrigin;
279 w[iht] = wireID.
Wire - off;
284 if (ninpl[ipl] == 2) ++nok;
294 TVectorD tVec = svd.Solve(w, ok);
299 if (npts <= 4)
return;
301 for (
const auto&
hit : hit2DSet) {
305 double const cw = plane.WireCoordinate(
geo::Point_t{0, 1, 0}) - off;
306 double const sw = plane.WireCoordinate(
geo::Point_t{0, 0, 1}) - off;
307 double const x =
hit->getXPosition() - XOrigin;
308 double const ypr = tVec[0] + tVec[2] *
x;
309 double const zpr = tVec[1] + tVec[3] *
x;
310 double const diff = ypr * cw + zpr * sw - (wireID.
Wire - off);
311 ChiDOF += diff * diff;
315 float werr2 = plane.
WirePitch() * plane.WirePitch();
317 ChiDOF /= (float)(npts - 4);
319 double norm = sqrt(1 + tVec[2] * tVec[2] + tVec[3] * tVec[3]);
321 Dir[1] = tVec[2] /
norm;
322 Dir[2] = tVec[3] /
norm;
Define a comparator which will sort hits by arc length along a PCA axis.
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.
void PCAAnalysis_3D(const reco::HitPairListPtr &hitPairList, reco::PrincipalComponents &pca, bool skeletonOnly=false) const
void flipAxis(size_t axis)
double WireCoordinate(Point_t const &point) const
Returns the coordinate of the point on the plane, in wire units.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
WireID_t Wire
Index of the wire within its plane.
PrincipalComponentsAlg m_pcaAlg
geo::WireReadoutGeom const * m_wireReadoutGeom
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.
Encapsulate the construction of a single detector plane .
std::vector< SeedHitPairListPair > SeedHitPairListPairVec
float getArclenToPoca() const
PlaneGeo const & Plane(TPCID const &tpcid, View_t view) const
Returns the specified wire.
void LineFit2DHits(const reco::HitPairListPtr &hitList, double XOrigin, TVector3 &Pos, TVector3 &Dir, double &ChiDOF) const
const ClusterHit2DVec & getHits() const
double WirePitch() const
Return the wire pitch (in centimeters). It is assumed constant.
const EigenVectors & getEigenVectors() const