8#include <tracking/trackFindingCDC/findlets/minimal/AxialTrackMerger.h>
10#include <tracking/trackFindingCDC/processing/AxialTrackUtil.h>
12#include <tracking/trackFindingCDC/fitting/CDCKarimakiFitter.h>
14#include <tracking/trackingUtilities/eventdata/tracks/CDCTrack.h>
15#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
16#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
18#include <tracking/trackingUtilities/numerics/WeightComperator.h>
20#include <tracking/trackingUtilities/utilities/StringManipulation.h>
22#include <framework/core/ModuleParamList.templateDetails.h>
24#include <Math/Vector2D.h>
27using namespace TrackFindingCDC;
28using namespace TrackingUtilities;
32 return "Merges axial tracks found in the Legendre search";
37 moduleParamList->
addParameter(prefixed(prefix,
"minFitProb"),
39 "Minimal fit probability of the common fit "
40 "of two tracks to be eligible for merging",
43 moduleParamList->
addParameter(prefixed(prefix,
"removeHitsAfterSuperLayerBreak"),
45 "Remove the hits of the tracks after a super layer break "
46 "before merging the tracks",
51 const std::vector<const CDCWireHit*>& allAxialWireHits)
55 for (
CDCTrack& track : axialTracks) {
56 if (track.size() < 5)
continue;
64 for (
CDCTrack& track : axialTracks) {
80 const std::vector<const CDCWireHit*>& allAxialWireHits)
83 for (
auto itTrack = axialTracks.begin(); itTrack != axialTracks.end(); ++itTrack) {
85 auto followingTracks = asRange(std::next(itTrack), axialTracks.end());
99template <
class ACDCTracks>
102 std::vector<WithWeight<CDCTrack*>> weightedTracks;
104 if (&track == &track2)
continue;
105 if (track2.size() < 3)
continue;
108 if (std::isnan(fitProb))
continue;
110 weightedTracks.emplace_back(&track2, fitProb);
113 auto bestMatch = std::max_element(weightedTracks.begin(), weightedTracks.end(), LessWeight());
114 if (bestMatch == weightedTracks.end())
return {
nullptr, 0};
115 else return *bestMatch;
130 recoHit3D.getRecoPos2D());
131 if (not isValid(fbInfo))
continue;
137 recoHit3D.getRecoPos2D());
138 if (not isValid(fbInfo))
continue;
142 if (not trajectory3D1.
isCurler() and fbVote12 < 0)
return NAN;
143 if (not trajectory3D2.
isCurler() and fbVote21 < 0)
return NAN;
148 std::vector<const CDCWireHit*> combinedWireHits;
149 combinedWireHits.reserve(track1.size() + track2.size());
151 combinedWireHits.push_back(&(hit.getWireHit()));
154 combinedWireHits.push_back(&(hit.getWireHit()));
161 std::sort(combinedWireHits.begin(), combinedWireHits.end());
162 erase_unique(combinedWireHits);
169 commonTrajectory2D = fitter.fit(combinedWireHits);
171 commonTrajectory2D = fitter.fit(combinedWireHits);
173 commonTrajectory2D = fitter.fit(combinedWireHits);
175 commonTrajectory2D = fitter.fit(combinedWireHits);
177 commonTrajectory2D = fitter.fit(combinedWireHits);
181 if (combinedWireHits.size() <= std::max(track1.size(), track2.size())
182 or combinedWireHits.size() < 15) {
190 std::vector<const CDCWireHit*>& wireHits,
193 auto farFromTrajectory = [&trajectory2D, &factor](
const CDCWireHit * wireHit) {
194 ROOT::Math::XYVector pos2D = wireHit->getRefPos2D();
195 double driftLength = wireHit->getRefDriftLength();
196 double dist = std::fabs(trajectory2D.
getDist2D(pos2D)) - driftLength;
197 return std::fabs(dist) > driftLength * factor;
199 erase_remove_if(wireHits, farFromTrajectory);
204 const std::vector<const CDCWireHit*>& allAxialWireHits)
206 if (&track1 == &track2)
return;
208 CDCTrajectory2D trajectory2D = track1.getStartTrajectory3D().getTrajectory2D();
211 track1.push_back(std::move(recoHit3D));
222 const auto& tmp = recoHit3D.getRefPos2D();
223 recoHit3D.setRecoPos3D({tmp.X(), tmp.Y(), 0});
224 recoHit3D.setRLInfo(ERightLeft::c_Unknown);
231 recoHit3D.getWireHit()->setTakenFlag(
false);
The Module parameter list class.
void apply(std::vector< TrackingUtilities::CDCTrack > &axialTracks, const std::vector< const TrackingUtilities::CDCWireHit * > &axialWireHits) final
Merge tracks together. Allows for axial hits to be added as it may see fit.
static void removeStrangeHits(double factor, std::vector< const TrackingUtilities::CDCWireHit * > &wireHits, TrackingUtilities::CDCTrajectory2D &trajectory)
Remove all hits that are further than factor * driftlength away from the trajectory.
void doTracksMerging(std::vector< TrackingUtilities::CDCTrack > &axialTracks, const std::vector< const TrackingUtilities::CDCWireHit * > &allAxialWireHits)
The track finding often finds two curling tracks, originating from the same particle.
bool m_param_removeHitsAfterSuperLayerBreak
Parameter : Remove the hits of the tracks after a super layer break before merging.
std::string getDescription() final
Short description of the findlet.
static void mergeTracks(TrackingUtilities::CDCTrack &track1, TrackingUtilities::CDCTrack &track2, const std::vector< const TrackingUtilities::CDCWireHit * > &allAxialWireHits)
Function to merge two track candidates.
static double doTracksFitTogether(TrackingUtilities::CDCTrack &track1, TrackingUtilities::CDCTrack &track2)
Fits the hit content of both tracks in a common fit repeated with an annealing schedule removing far ...
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
static TrackingUtilities::WithWeight< TrackingUtilities::MayBePtr< TrackingUtilities::CDCTrack > > calculateBestTrackToMerge(TrackingUtilities::CDCTrack &track, ACDCTracks &tracks)
Searches for the best candidate to merge this track to.
double m_param_minFitProb
Parameter : Minimal fit probability of the common fit of two tracks to be eligible for merging.
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 representing a three dimensional reconstructed hit.
static CDCRecoHit3D reconstruct(const CDCRecoHit2D &recoHit2D, const CDCTrajectory2D &trajectory2D)
Reconstructs the three dimensional hit from the two dimensional and the two dimensional trajectory.
Class representing a sequence of three dimensional reconstructed hits.
Particle trajectory as it is seen in xy projection represented as a circle.
double getPValue() const
Getter for p-value.
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.
bool isCurler(double factor=1) const
Checks if the trajectory leaves the outer radius of the CDC times the given tolerance factor.
ROOT::Math::XYZVector getFlightDirection3DAtSupport() const
Get the unit momentum at the start point of the trajectory.
Class representing a hit wire in the central drift chamber.
A mixin class to attach a weight to an object.
Weight getWeight() const
Getter for the weight.
void addParameter(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
Abstract base class for different kinds of events.
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 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< TrackingUtilities::CDCRecoHit3D > splitBack2BackTrack(TrackingUtilities::CDCTrack &track)
Tries to split back-to-back tracks into two different tracks.
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...