13#include <Eigen/Geometry>
15#include <framework/datastore/StoreArray.h>
17#include <tracking/spacePointCreation/SpacePoint.h>
53 if ((index < 1) or (index > 3)) {
54 B2FATAL(
"Invalid sorting mode chosen! You used " <<
m_sortingMode
55 <<
". Must be one of 1 (by radius), 2 (by x) or 3 (by y).");
72 for (
auto& spArray : SPs) {
73 for (
auto& sp : spArray) {
92 bool doFit(
double qualityCut,
int maxRejected,
int minSPs)
100 if (not fitting) {
return false;}
102 B2DEBUG(20,
"Refitting without sp with index " <<
m_largestChi2.second
103 <<
" and chi2 contribution " <<
m_largestChi2.first <<
"...");
107 if (rejected > maxRejected) { B2DEBUG(20,
"Rejected " << rejected <<
"!");
return false; }
122 std::pair<std::vector<double>, std::vector<double>>
getResult()
162 ->
bool { return this->compareRads(lhs, rhs); });
182 B2DEBUG(20,
"Trying fit with " << nHits <<
" hits...");
184 if (nHits < minSPs) { B2DEBUG(20,
"Only " << nHits <<
" hits!");
return false; };
186 Eigen::Matrix<double, 3, 1> average = Eigen::Matrix<double, 3, 1>::Zero(3, 1);
187 Eigen::Matrix<double, Eigen::Dynamic, 3> data = Eigen::Matrix<double, Eigen::Dynamic, 3>::Zero(nHits, 3);
188 Eigen::Matrix<double, Eigen::Dynamic, 3> P = Eigen::Matrix<double, Eigen::Dynamic, 3>::Zero(nHits, 3);
191 average(0) += sp->getPosition().X();
192 average(1) += sp->getPosition().Y();
193 average(2) += sp->getPosition().Z();
195 average *= 1. / nHits;
199 data(index, 0) = sp->getPosition().X();
200 data(index, 1) = sp->getPosition().Y();
201 data(index, 2) = sp->getPosition().Z();
203 P(index, 0) = sp->getPosition().X() - average(0);
204 P(index, 1) = sp->getPosition().Y() - average(1);
205 P(index, 2) = sp->getPosition().Z() - average(2);
210 Eigen::Matrix<double, 3, 3> product = P.transpose() * P;
212 Eigen::EigenSolver<Eigen::Matrix<double, 3, 3>> eigencollection(product);
213 Eigen::Matrix<double, 3, 1> eigenvalues = eigencollection.eigenvalues().real();
214 Eigen::Matrix<std::complex<double>, 3, 3> eigenvectors = eigencollection.eigenvectors();
215 Eigen::Matrix<double, 3, 1>::Index maxRow, maxCol;
216 eigenvalues.maxCoeff(&maxRow, &maxCol);
218 Eigen::Matrix<double, 3, 1> e = eigenvectors.col(maxRow).real();
221 Eigen::Matrix<double, 3, 1> start = data.row(nHits - 1).transpose();
222 Eigen::Matrix<double, 3, 1> second = data.row(nHits - 2).transpose();
223 m_start = {start(0), start(1), start(2)};
226 Eigen::Hyperplane<double, 3> plane(e.normalized(), start);
227 Eigen::ParametrizedLine<double, 3> line(second, e.normalized());
228 double factor = line.intersectionParameter(plane);
240 int largestChi2_index = 0;
242 Eigen::Matrix<double, 3, 1> origin(sp->getPosition().X(), sp->getPosition().Y(), sp->getPosition().Z());
243 plane = Eigen::Hyperplane<double, 3>(e.normalized(), origin);
245 Eigen::Matrix<double, 3, 1> point = line.intersectionPoint(plane);
247 double delta_chi2 = (point - origin).transpose() * (point - origin);
258 B2DEBUG(20,
"Reduced chi2 result is " <<
m_reducedChi2 <<
"...");
273 double radA = a->getPosition().X() * a->getPosition().X() + a->getPosition().Y() * a->getPosition().Y();
274 double radB = b->getPosition().X() * b->getPosition().X() + b->getPosition().Y() * b->getPosition().Y();
277 double xA = a->getPosition().X();
278 double xB = b->getPosition().X();
281 double yA = a->getPosition().Y();
282 double yB = b->getPosition().Y();
285 B2FATAL(
"Invalid sorting mode chosen! You used " <<
m_sortingMode
286 <<
". Must be one of 1 (by radius), 2 (by x) or 3 (by y).");
299 std::vector<const SpacePoint*> sortedSPs;
301 auto forwardIt = std::lower_bound(sortedSPs.begin(), sortedSPs.end(), SP,
303 return this->comparePars(lhs, rhs);
305 sortedSPs.insert(forwardIt, SP);
320 Eigen::Matrix<double, 3, 1> posA(a->getPosition().X(), a->getPosition().Y(), a->getPosition().Z());
321 Eigen::Matrix<double, 3, 1> posB(b->getPosition().X(), b->getPosition().Y(), b->getPosition().Z());
326 Eigen::ParametrizedLine<double, 3> line(origin, direction.normalized());
327 Eigen::Hyperplane<double, 3> planeA(direction.normalized(), posA);
328 Eigen::Hyperplane<double, 3> planeB(direction.normalized(), posB);
330 double parA = line.intersectionParameter(planeA);
331 double parB = line.intersectionParameter(planeB);
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Track finding algorithm class for linear tracks produced by cosmics in the VXD without magnetic field...
void resortHits()
Function to resort the member vector of SpacePoints m_spacePoints based on the members m_start and m_...
unsigned short m_sortingMode
Storing identifier for sorting algorithm to be used for the function addSpacePoint.
~StandaloneCosmicsCollector()=default
Destructor.
void addSpacePoints(std::vector< StoreArray< SpacePoint > > SPs)
Function to initialize the track finder anew for an event with its set of SpacePoints provided via th...
StandaloneCosmicsCollector()=default
Constructor.
std::vector< double > m_direction
Direction of the line obtained by the last performed line fit.
std::pair< double, int > m_largestChi2
Pair containing the index of the vector m_spacePoints for the SpacePoint with the largest contributio...
std::vector< double > m_start
Start point obtained by the last performed line fit.
void addSpacePoint(const SpacePoint *SP)
Adding single SpacePoint to the sorted member vector m_spacePoints, beginning with the SpacePoint wit...
bool comparePars(const SpacePoint *a, const SpacePoint *b)
Comparison function to compare two SpacePoints based on the distance between the start point of the f...
bool doFit(double qualityCut, int maxRejected, int minSPs)
Function to perform the actual line fit based on the StoreArray of SpacePoints provided.
std::vector< const SpacePoint * > m_spacePoints
Member vector of SpacePoints holding the SpacePoints considered for the track candidate.
double m_reducedChi2
Member variable containing the reduced chi squared value of the current line fit.
std::vector< const SpacePoint * > getSPTC()
Getter for the sorted list of SpacePoints used for the final fit which met the given requirements.
bool compareRads(const SpacePoint *a, const SpacePoint *b)
Compare function used by addSpacePoint to sort the member vector of SpacePoints m_spacePoints by the ...
std::pair< std::vector< double >, std::vector< double > > getResult()
Getter for the position and momentum seed resulting from the linear fit.
bool doLineFit(int minSPs)
Function performing the actual line fit via a principal component analysis method yielding a directio...
void setSortingMode(unsigned short index)
Set sorting mode used in addSpacePoints.
double getReducedChi2()
Getter for the final reduced chi squared value obtained for the set of SpacePoints used for the last ...
Accessor to arrays stored in the data store.
Abstract base class for different kinds of events.