diff --git a/src/algorithms/tracking/TrackSeeding.cc b/src/algorithms/tracking/TrackSeeding.cc index d9c068608e..4491473623 100644 --- a/src/algorithms/tracking/TrackSeeding.cc +++ b/src/algorithms/tracking/TrackSeeding.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -188,15 +189,9 @@ std::unique_ptr eicrecon::TrackSeeding::make auto slopeZ0 = lineFit(rzHitPositions); const auto xypos = findPCA(RX0Y0); - //Determine charge - std::vector> xyrelPos; - - for ( const auto& spptr : seed.sp() ) - { - xyrelPos.emplace_back(spptr->x()-xypos.first, spptr->y()-xypos.second); - } - int charge = determineCharge(xyrelPos); + //Determine charge + int charge = determineCharge(xyHitPositions, xypos, RX0Y0); float theta = atan(1./std::get<0>(slopeZ0)); // normalize to 0 eicrecon::TrackSeeding::findPCA(std::tuple>& positions) const +int eicrecon::TrackSeeding::determineCharge(std::vector>& positions, const std::pair& PCA, std::tuple& RX0Y0) const { - // determine the charge by the bend angle of the first two hits - int charge = 1; + const auto& firstpos = positions.at(0); - const auto& secondpos = positions.at(1); + auto hit_x = firstpos.first; + auto hit_y = firstpos.second; - const auto firstphi = atan2(firstpos.second, firstpos.first); - const auto secondphi = atan2(secondpos.second, secondpos.first); - auto dphi = secondphi - firstphi; - if(dphi > M_PI) dphi -= 2.*M_PI; - if(dphi < -M_PI) dphi += 2*M_PI; - if(dphi < 0) charge = -1; + auto xpos = PCA.first; + auto ypos = PCA.second; - return charge; + float X0 = std::get<1>(RX0Y0); + float Y0 = std::get<2>(RX0Y0); + + Acts::Vector3 B_z(0,0,1); + Acts::Vector3 radial(X0-xpos, Y0-ypos, 0); + Acts::Vector3 hit(hit_x-xpos, hit_y-ypos, 0); + + auto cross = radial.cross(hit); + + float dot = cross.dot(B_z); + + return copysign(1., -dot); } + /** * Circle fit to a given set of data points (in 2D) * This is an algebraic fit, due to Taubin, based on the journal article diff --git a/src/algorithms/tracking/TrackSeeding.h b/src/algorithms/tracking/TrackSeeding.h index 165c4b01b7..2f0b8d885b 100644 --- a/src/algorithms/tracking/TrackSeeding.h +++ b/src/algorithms/tracking/TrackSeeding.h @@ -44,7 +44,7 @@ namespace eicrecon { Acts::SeedFinderOptions m_seedFinderOptions; Acts::SeedFinderOrthogonalConfig m_seedFinderConfig; - int determineCharge(std::vector>& positions) const; + int determineCharge(std::vector>& positions, const std::pair& PCA, std::tuple& RX0Y0) const; std::pair findPCA(std::tuple& circleParams) const; std::vector getSpacePoints(const edm4eic::TrackerHitCollection& trk_hits); std::unique_ptr makeTrackParams(SeedContainer& seeds);