8#include <tracking/trackFindingCDC/findlets/minimal/SegmentAliasResolver.h>
10#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
12#include <tracking/trackingUtilities/eventdata/segments/CDCSegment2D.h>
13#include <tracking/trackingUtilities/eventdata/segments/CDCFacetSegment.h>
14#include <tracking/trackingUtilities/eventdata/segments/CDCRLWireHitSegment.h>
15#include <tracking/trackingUtilities/eventdata/hits/CDCWireHit.h>
17#include <tracking/trackingUtilities/utilities/StringManipulation.h>
19#include <framework/core/ModuleParamList.templateDetails.h>
21#include <Math/Vector2D.h>
26using namespace TrackFindingCDC;
27using namespace TrackingUtilities;
34 aliasTrajectory2D.
getChi2() < segment.getTrajectory2D().getChi2()) {
36 std::swap(segment, aliasSegment);
43 return "Resolves the rl aliasing of segments in various scenarios";
48 moduleParamList->
addParameter(prefixed(prefix,
"investigateAlias"),
50 "Which alias resolutions should be applied. "
51 "Options are trailing_hit, last_hit, full.",
54 moduleParamList->
addParameter(prefixed(prefix,
"reestimateDriftLength"),
56 "Switch to reestimate the drift length in the alias resolver",
59 moduleParamList->
addParameter(prefixed(prefix,
"reestimatePositions"),
61 "Switch to reestimate the reconstructed positions in the alias resolver",
69 if (investigatedAlias ==
"full") {
71 }
else if (investigatedAlias ==
"cross") {
73 }
else if (investigatedAlias ==
"borders") {
75 }
else if (investigatedAlias ==
"middle") {
78 B2ERROR(
"Unknown alias to investigate " << investigatedAlias);
87 if (segment->hasAliasFlag())
continue;
88 int nRLSwitches = segment.getNRLSwitches();
90 bool aliasStable = nRLSwitches > 2;
91 if (aliasStable)
continue;
94 refit(aliasSegment,
true);
95 swapBetterChi2(segment, aliasSegment);
102 int nRLSwitches = segment.getNRLSwitches();
104 bool aliasStable = nRLSwitches > 2;
105 if (aliasStable)
continue;
107 if (nRLSwitches == 1) {
112 if (recoHit2D.getRLInfo() == ERightLeft::c_Left) {
113 recoHit2D = recoHit2D.getAlias();
118 if (recoHit2D.getRLInfo() == ERightLeft::c_Right) {
119 recoHit2D = recoHit2D.getAlias();
122 refit(rightSegment,
true);
123 refit(leftSegment,
true);
124 swapBetterChi2(segment, rightSegment);
125 swapBetterChi2(segment, leftSegment);
127 }
else if (nRLSwitches == 0) {
138 auto itMinLRecoHit2D =
139 std::min_element(frontCrossSegment.begin(), frontCrossSegment.end(), lessDriftLength);
140 for (
CDCRecoHit2D& recoHit2D : asRange(frontCrossSegment.begin(), itMinLRecoHit2D)) {
141 recoHit2D = recoHit2D.getAlias();
147 auto itMinLRecoHit2D =
148 std::min_element(backCrossSegment.begin(), backCrossSegment.end(), lessDriftLength);
149 for (
CDCRecoHit2D& recoHit2D : asRange(itMinLRecoHit2D, backCrossSegment.end())) {
150 recoHit2D = recoHit2D.getAlias();
153 refit(frontCrossSegment,
true);
154 refit(backCrossSegment,
true);
155 swapBetterChi2(segment, frontCrossSegment);
156 swapBetterChi2(segment, backCrossSegment);
169 refit(aliasSegment,
false);
174 swapBetterChi2(segment, aliasSegment);
185 refit(aliasSegment,
false);
190 swapBetterChi2(segment, aliasSegment);
201 double minimalDriftLength = 0.1;
204 if (aliasHit.getRefDriftLength() < minimalDriftLength) {
205 minimalHit = &aliasHit;
213 refit(aliasSegment,
false);
218 swapBetterChi2(segment, aliasSegment);
223 std::sort(outputSegments.begin(), outputSegments.end());
233 rlWireHit.setRefDriftLength(rlWireHit.getWireHit().getRefDriftLength());
236 for (
CDCFacet& facet : facetSegment) {
237 facet.adjustFitLine();
243 segment = replacement;
251 const EFitPos fitPos = EFitPos::c_RecoPos;
252 const EFitVariance fitVariance = EFitVariance::c_Proper;
255 if (observations2D.
size() < 4) {
256 segment.getTrajectory2D().clear();
259 segment.setTrajectory2D(trajectory2D);
The Module parameter list class.
Class serving as a storage of observed drift circles to present to the Riemann fitter.
std::size_t appendRange(const TrackingUtilities::CDCSegment2D &segment2D)
Appends all reconstructed hits from the two dimensional segment.
std::size_t size() const
Returns the number of observations stored.
DriftLengthEstimator m_driftLengthEstimator
Instance of the drift length estimator to be used.
bool m_middleAliases
Switch whether the hits in the middle with lowest drift radius should be aliased.
void apply(std::vector< TrackingUtilities::CDCSegment2D > &outputSegments) final
Main algorithm applying the fit to each segment.
void initialize() final
Signals the beginning of the event processing.
bool m_param_reestimatePositions
Parameter : Switch to restimate the reconstructed positions with a pass of facets.
std::vector< std::string > m_param_investigateAlias
Parameter : Which alias resolutions should be applied.
bool m_param_reestimateDriftLength
Parameter : Switch to reestimate the drift length before each fit.
void refit(TrackingUtilities::CDCSegment2D &segment, bool reestimate)
Fit the alias segment.
bool m_fullAlias
Switch whether the complete segment should be aliased.
std::string getDescription() final
Short description of the findlet.
bool m_borderAliases
Switch whether the border hits at the beginning and the end should be aliased.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters to a module.
CDCRiemannFitter m_riemannFitter
Instance of the riemann fitter to be used.
bool m_crossAliases
Switch whether the segment should be aliased at the waist where an rl side switch was missed.
A segment consisting of adjacent facets.
static CDCFacetSegment create(const CDCRLWireHitSegment &rlWireHitSegment)
Construct a train of facets from the given oriented wire hits.
Class representing a triple of neighboring oriented wire with additional trajectory information.
A segment consisting of two dimensional reconstructed hits.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
Class representing a two dimensional reconstructed hit in the central drift chamber.
void setRLInfo(ERightLeft &rlInfo)
Setter the right left passage information.
void reverse()
Turns the orientation in place.
double getRefDriftLength() const
Getter for the drift length at the wire reference position.
const ROOT::Math::XYVector & getRefPos2D() const
Getter for the reference position of the wire.
void setRecoPos2D(const ROOT::Math::XYVector &recoPos2D)
Setter for the position in the reference plane.
A reconstructed sequence of two dimensional hits in one super layer.
static CDCSegment2D condense(const CDCTangentSegment &tangentSegment)
Averages the reconstructed positions from hits that overlap in adjacent tangents in the given tangent...
CDCTrajectory2D & getTrajectory2D() const
Getter for the two dimensional trajectory fitted to the segment.
void setAliasScore(double aliasScore)
Setter for the flag that this segment may have an aliased version.
Particle trajectory as it is seen in xy projection represented as a circle.
ROOT::Math::XYVector getClosest(const ROOT::Math::XYVector &point) const
Calculates the closest approach on the trajectory to the given point.
double getChi2() const
Getter for the chi2 value of the circle fit.
bool isFitted() const
Checks if the circle is already set to a valid value.
ERightLeft isRightOrLeft(const ROOT::Math::XYVector &point) const
Checks if the given point is to the right or to the left of the trajectory.
void initialize() override
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.