8#include <tracking/trackFindingCDC/processing/AxialTrackUtil.h>
10#include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
11#include <tracking/trackFindingCDC/fitting/CDCKarimakiFitter.h>
12#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
14#include <tracking/trackingUtilities/geometry/VectorUtil.h>
15#include <tracking/trackingUtilities/eventdata/tracks/CDCTrack.h>
16#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
17#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
18#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
20#include <tracking/trackingUtilities/utilities/Algorithms.h>
24using namespace TrackFindingCDC;
25using namespace TrackingUtilities;
28 const std::vector<const CDCWireHit*>& allAxialWireHits,
29 std::vector<CDCTrack>& axialTracks,
30 bool withPostprocessing)
32 if (foundAxialWireHits.empty())
return;
43 for (
const CDCWireHit* wireHit : foundAxialWireHits) {
47 track.push_back(std::move(recoHit3D));
51 track.sortByArcLength2D();
54 bool success = withPostprocessing ?
postprocessTrack(track, allAxialWireHits) :
true;
58 recoHit3D.getWireHit().getAutomatonCell().setTakenFlag(
true);
60 axialTracks.emplace_back(std::move(track));
64 recoHit3D.getWireHit().getAutomatonCell().setMaskedFlag(
true);
65 recoHit3D.getWireHit().getAutomatonCell().setTakenFlag(
false);
93 return not(track.size() < 5);
99 if (track.size() < 5)
return;
103 observations2D.
append(item);
121 track.sortByArcLength2D();
124 track.setStartTrajectory3D(trajectory3D);
126 ROOT::Math::XYZVector backPosition = track.back().getRecoPos3D();
128 track.setEndTrajectory3D(trajectory3D);
145 const CDCTrajectory2D& trajectory2D = track.getStartTrajectory3D().getTrajectory2D();
146 auto farFromTrajectory = [&trajectory2D, &maximumDistance](
CDCRecoHit3D & recoHit3D) {
147 ROOT::Math::XYVector refPos2D = recoHit3D.getRefPos2D();
148 double distance = trajectory2D.
getDist2D(refPos2D) - recoHit3D.getSignedRecoDriftLength();
149 if (std::fabs(distance) > maximumDistance) {
150 recoHit3D.getWireHit().getAutomatonCell().setTakenFlag(
false);
152 recoHit3D.getWireHit().getAutomatonCell().setMaskedFlag(
true);
157 erase_remove_if(track, farFromTrajectory);
161 double minimal_probability_for_good_fit)
164 const auto lowPValue = [&](
const CDCTrack & track) {
168 if (not(fittedTrajectory.
getPValue() >= minimal_probability_for_good_fit)) {
170 track.forwardTakenFlag(
false);
175 erase_remove_if(axialTracks, lowPValue);
179 const std::vector<const CDCWireHit*>& allAxialWireHits,
180 double minimalDistance)
182 if (track.size() < 10)
return;
184 const CDCTrajectory2D& trackTrajectory2D = track.getStartTrajectory3D().getTrajectory2D();
186 for (
const CDCWireHit* wireHit : allAxialWireHits) {
187 if (wireHit->getAutomatonCell().hasTakenFlag())
continue;
190 const ROOT::Math::XYVector& recoPos2D = recoHit3D.
getRecoPos2D();
192 if (fabs(trackTrajectory2D.
getDist2D(recoPos2D)) < minimalDistance) {
193 track.push_back(std::move(recoHit3D));
201 const auto isShort = [&](
const CDCTrack & track) {
202 if (track.size() < minimal_size) {
204 track.forwardTakenFlag(
false);
209 erase_remove_if(axialTracks, isShort);
214 std::vector<CDCRecoHit3D> removedHits;
216 if (track.size() < 5)
return removedHits;
219 ROOT::Math::XYVector center = track.getStartTrajectory3D().getGlobalCenter();
222 auto isOnMajorArm = [¢er, &majorArmSign](
const CDCRecoHit3D & hit) {
223 return getArmSign(hit, center) == majorArmSign;
226 auto itFirstMinorArmHit = std::stable_partition(track.begin(),
230 for (
const CDCRecoHit3D& recoHit3D : asRange(itFirstMinorArmHit, track.end())) {
231 recoHit3D.getWireHit().getAutomatonCell().setTakenFlag(
false);
232 removedHits.push_back(recoHit3D);
234 track.erase(itFirstMinorArmHit, track.end());
241 ROOT::Math::XYVector center = track.getStartTrajectory3D().getGlobalCenter();
243 if (std::abs(armSignVote) <
int(track.size()) and center.Mag2() > 3600.) {
252 if (armSignVote > 0) {
253 return ESign::c_Plus;
255 return ESign::c_Minus;
264 if (VectorUtil::hasNAN(center)) {
265 B2WARNING(
"Trajectory is not set or wrong!");
272 if (armSign == ESign::c_Plus) {
274 }
else if (armSign == ESign::c_Minus) {
277 B2ERROR(
"Strange behaviour of getArmSignVote");
280 int armSignVote = votePos - voteNeg;
286 return sign(VectorUtil::isRightOrLeftOf(center, hit.
getRecoPos2D()));
291 double apogeeArcLength = fabs(track.getStartTrajectory3D().getGlobalCircle().perimeter()) / 2.;
293 std::array<int, ISuperLayerUtil::c_N> nForwardArmHitsBySLayer = {0};
294 std::array<int, ISuperLayerUtil::c_N> nBackwardArmHitsBySLayer = {0};
298 if ((hit.getArcLength2D() <= apogeeArcLength) and (hit.getArcLength2D() > 0)) {
299 nForwardArmHitsBySLayer[hit.getISuperLayer()]++;
301 nBackwardArmHitsBySLayer[hit.getISuperLayer()]++;
305 std::vector<ISuperLayer> forwardSLayerHoles =
getSLayerHoles(nForwardArmHitsBySLayer);
306 std::vector<ISuperLayer> backwardSLayerHoles =
getSLayerHoles(nBackwardArmHitsBySLayer);
309 if (forwardSLayerHoles.empty() and backwardSLayerHoles.empty())
return;
313 assert(std::is_sorted(forwardSLayerHoles.begin(), forwardSLayerHoles.end()));
314 if (forwardSLayerHoles.empty())
return;
316 const ISuperLayer breakSLayer = forwardSLayerHoles.front();
318 auto isInBackwardArm = [apogeeArcLength](
const CDCRecoHit3D & recoHit3D) {
319 if ((recoHit3D.getArcLength2D() >= apogeeArcLength) or (recoHit3D.getArcLength2D() < 0)) {
320 recoHit3D.getWireHit().getAutomatonCell().unsetTakenFlag();
326 erase_remove_if(track, isInBackwardArm);
328 auto isAfterSLayerBreak = [breakSLayer](
const CDCRecoHit3D & recoHit3D) {
329 recoHit3D.getWireHit().getAutomatonCell().unsetTakenFlag();
330 if (recoHit3D.getISuperLayer() >= breakSLayer) {
331 recoHit3D.getWireHit().getAutomatonCell().unsetTakenFlag();
337 erase_remove_if(track, isAfterSLayerBreak);
342 std::vector<ISuperLayer> sLayerHoles;
352 for (
ISuperLayer iSLayer = firstSlayer; iSLayer <= lastSlayer; iSLayer += 2) {
353 if (nHitsBySLayer[iSLayer] == 0) {
354 sLayerHoles.push_back(iSLayer);
363 if (nHitsBySLayer[iSLayer] > 0)
return iSLayer;
371 if (nHitsBySLayer[iSLayer] > 0)
return iSLayer;
TrackingUtilities::CDCTrajectory2D fit(const CDCObservations2D &observations2D) const
Fits a collection of observation drift circles.
Class implementing the fitter using Karimakis method.
static const CDCKarimakiFitter & getNoDriftVarianceFitter()
Static getter for a general fitter that does not use the drift length variances.
Class serving as a storage of observed drift circles to present to the Riemann fitter.
std::size_t append(const TrackingUtilities::CDCWireHit &wireHit, TrackingUtilities::ERightLeft rlInfo=TrackingUtilities::ERightLeft::c_Unknown)
Appends the hit circle at wire reference position without a right left passage hypotheses.
Class implementing the Riemann fit for two dimensional trajectory circle.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Cell used by the cellular automata.
void setTakenFlag(bool setTo=true)
Sets the taken flag to the given value. Default value true.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
Class representing a three dimensional reconstructed hit.
const CDCWireHit & getWireHit() const
Getter for the wire hit.
double getArcLength2D() const
Getter for the travel distance in the xy projection.
void setArcLength2D(const double arcLength2D)
Setter for the travel distance in the xy projection.
const ROOT::Math::XYVector getRecoPos2D() const
Getter for the 2d position of the hit.
static CDCRecoHit3D reconstructNearest(const CDCWireHit *axialWireHit, const CDCTrajectory2D &trajectory2D)
Reconstruct a three dimensional hit from a wire hit (as in reconstruct(rlWireHit, trajectory2D)),...
Class representing a sequence of three dimensional reconstructed hits.
Particle trajectory as it is seen in xy projection represented as a circle.
void reverse()
Reverses the trajectory in place.
ROOT::Math::XYVector getGlobalCenter() const
Getter for the center of the trajectory in global coordinates.
ESign getChargeSign() const
Gets the charge sign of the trajectory.
double setLocalOrigin(const ROOT::Math::XYVector &localOrigin)
Setter for the origin of the local coordinate system.
double getPValue() const
Getter for p-value.
double getArcLength2DPeriod() const
Getter for the arc length for one round trip around the trajectory.
ROOT::Math::XYVector getGlobalPerigee() const
Getter for the closest approach on the trajectory to the global origin.
double getDist2D(const ROOT::Math::XYVector &point) const
Calculates the distance from the point to the trajectory as seen from the xy projection.
Particle full three dimensional trajectory.
double setLocalOrigin(const ROOT::Math::XYZVector &localOrigin)
Setter for the origin of the local coordinate system.
static CDCTrajectorySZ basicAssumption()
Constructs a basic assumption, what the z0 start position and the sz slope are, including some broad ...
Class representing a hit wire in the central drift chamber.
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
signed short ISuperLayer
The type of the layer and superlayer ids.
Abstract base class for different kinds of events.
static const ISuperLayer c_Invalid
Constant making an invalid superlayer id.
static const ISuperLayer c_N
Constant representing the total number of cdc superlayers.
static bool isInvalid(ISuperLayer iSuperLayer)
Indicates if the given number corresponds to a true cdc superlayer - excludes the logic ids for inner...
static void normalizeTrack(TrackingUtilities::CDCTrack &track)
Refit and resort the track. Unmask all hits.
static void deleteShortTracks(std::vector< TrackingUtilities::CDCTrack > &axialTracks, double minimal_size=5)
Remove tracks that are shorter than the given number of hits.
static void updateRecoHit3D(const TrackingUtilities::CDCTrajectory2D &trajectory2D, TrackingUtilities::CDCRecoHit3D &hit)
update given CDCRecoHit3D with given trajectory
static void addCandidateFromHits(const std::vector< const TrackingUtilities::CDCWireHit * > &foundAxialWireHits, const std::vector< const TrackingUtilities::CDCWireHit * > &allAxialWireHits, std::vector< TrackingUtilities::CDCTrack > &axialTracks, bool withPostprocessing=true)
Create CDCTrack using CDCWireHit hits and store it in the list. Then call the postprocessing on it.
static void deleteTracksWithLowFitProbability(std::vector< TrackingUtilities::CDCTrack > &axialTracks, double minimal_probability_for_good_fit=0.4)
Check an (improper) p-values of the tracks. If they are below the given value, delete the track from ...
static void removeHitsAfterSuperLayerBreak(TrackingUtilities::CDCTrack &track)
Searches for a break in the super layer chain and remove all hits that come after that.
static std::vector< CDC::ISuperLayer > getSLayerHoles(const std::array< int, CDC::ISuperLayerUtil::c_N > &nHitsBySLayer)
Helper function getting the empty axial!
static std::vector< TrackingUtilities::CDCRecoHit3D > splitBack2BackTrack(TrackingUtilities::CDCTrack &track)
Tries to split back-to-back tracks into two different tracks.
static TrackingUtilities::ESign getMajorArmSign(const TrackingUtilities::CDCTrack &track, const ROOT::Math::XYVector ¢er)
Calculate whether the majority of hits is to the right or to the left relative to the line from origi...
static int getArmSignVote(const TrackingUtilities::CDCTrack &track, const ROOT::Math::XYVector ¢er)
Calculate the sum of right and left votes for the hits relative to the center.
static void assignNewHitsToTrack(TrackingUtilities::CDCTrack &track, const std::vector< const TrackingUtilities::CDCWireHit * > &allAxialWireHits, double minimalDistance=0.2)
Assign new hits to the track basing on the distance from the hit to the track.
static bool postprocessTrack(TrackingUtilities::CDCTrack &track, const std::vector< const TrackingUtilities::CDCWireHit * > &allAxialWireHits)
Perform all track postprocessing - return whether the track is considered good after the postprocessi...
static TrackingUtilities::ESign getArmSign(const TrackingUtilities::CDCRecoHit3D &hit, const ROOT::Math::XYVector ¢er)
Calculate whether the hits is to the right or to the left relative to the line from origin to the giv...
static void deleteHitsFarAwayFromTrajectory(TrackingUtilities::CDCTrack &track, double maximumDistance=0.2)
Postprocessing: Delete axial hits that do not "match" to the given track.
static bool isBack2BackTrack(TrackingUtilities::CDCTrack &track)
Checks whether the track has hits on both arms as seen from the origin.
static CDC::ISuperLayer getLastOccupiedISuperLayer(const std::array< int, CDC::ISuperLayerUtil::c_N > &nHitsBySLayer)
Helper function to extract the last filled entry in the array of super layers ( = the final superlaye...
static bool checkTrackQuality(const TrackingUtilities::CDCTrack &track)
Check track quality – currently based on number of hits only.
static CDC::ISuperLayer getFirstOccupiedISuperLayer(const std::array< int, CDC::ISuperLayerUtil::c_N > &nHitsBySLayer)
Helper function to extract the first filled entry in the array of super layers ( = the start superlay...