Main algorithm applying the fit to each segment.
81{
83 for (CDCSegment2D& segment : outputSegments) {
84 if (segment->hasAliasFlag()) continue;
85 int nRLSwitches = segment.getNRLSwitches();
86
87 bool aliasStable = nRLSwitches > 2;
88 if (aliasStable) continue;
89
90 CDCSegment2D aliasSegment = segment.getAlias();
91 refit(aliasSegment,
true);
92 swapBetterChi2(segment, aliasSegment);
93 }
94 }
95
96
98 for (CDCSegment2D& segment : outputSegments) {
99 int nRLSwitches = segment.getNRLSwitches();
100
101 bool aliasStable = nRLSwitches > 2;
102 if (aliasStable) continue;
103
104 if (nRLSwitches == 1) {
105
106 CDCSegment2D rightSegment = segment;
107 CDCSegment2D leftSegment = segment;
108 for (CDCRecoHit2D& recoHit2D : rightSegment) {
109 if (recoHit2D.getRLInfo() == ERightLeft::c_Left) {
110 recoHit2D = recoHit2D.getAlias();
111 }
112 }
113
114 for (CDCRecoHit2D& recoHit2D : leftSegment) {
115 if (recoHit2D.getRLInfo() == ERightLeft::c_Right) {
116 recoHit2D = recoHit2D.getAlias();
117 }
118 }
119 refit(rightSegment,
true);
120 refit(leftSegment,
true);
121 swapBetterChi2(segment, rightSegment);
122 swapBetterChi2(segment, leftSegment);
123
124 } else if (nRLSwitches == 0) {
125
126 CDCSegment2D frontCrossSegment = segment;
127 CDCSegment2D backCrossSegment = segment;
128
129 auto lessDriftLength = [](const CDCRecoHit2D & lhs, const CDCRecoHit2D & rhs) {
131 };
132
133
134 {
135 auto itMinLRecoHit2D =
136 std::min_element(frontCrossSegment.begin(), frontCrossSegment.end(), lessDriftLength);
137 for (CDCRecoHit2D& recoHit2D : asRange(frontCrossSegment.begin(), itMinLRecoHit2D)) {
138 recoHit2D = recoHit2D.getAlias();
139 }
140 }
141
142
143 {
144 auto itMinLRecoHit2D =
145 std::min_element(backCrossSegment.begin(), backCrossSegment.end(), lessDriftLength);
146 for (CDCRecoHit2D& recoHit2D : asRange(itMinLRecoHit2D, backCrossSegment.end())) {
147 recoHit2D = recoHit2D.getAlias();
148 }
149 }
150 refit(frontCrossSegment,
true);
151 refit(backCrossSegment,
true);
152 swapBetterChi2(segment, frontCrossSegment);
153 swapBetterChi2(segment, backCrossSegment);
154 }
155 }
156 }
157
159 for (CDCSegment2D& segment : outputSegments) {
160
161 CDCSegment2D aliasSegment = segment;
162 CDCRecoHit2D& aliasHit = aliasSegment.back();
166 refit(aliasSegment,
false);
171 swapBetterChi2(segment, aliasSegment);
172 }
173 }
174
175 for (CDCSegment2D& segment : outputSegments) {
176
177 CDCSegment2D aliasSegment = segment;
178 CDCRecoHit2D& aliasHit = aliasSegment.front();
182 refit(aliasSegment,
false);
187 swapBetterChi2(segment, aliasSegment);
188 }
189 }
190 }
191
193 for (CDCSegment2D& segment : outputSegments) {
194
195 CDCSegment2D aliasSegment = segment;
196
197
198 double minimalDriftLength = 0.1;
199 CDCRecoHit2D* minimalHit = nullptr;
200 for (CDCRecoHit2D& aliasHit : aliasSegment) {
202 minimalHit = &aliasHit;
204 }
205 }
206 if (minimalHit) {
207 CDCRecoHit2D& aliasHit = *minimalHit;
210 refit(aliasSegment,
false);
211 Vector2D recoPos2D = aliasSegment.getTrajectory2D().getClosest(aliasHit.
getRefPos2D());
215 swapBetterChi2(segment, aliasSegment);
216 }
217 }
218 }
219
220 std::sort(outputSegments.begin(), outputSegments.end());
221}
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 Vector2D & getRefPos2D() const
Getter for the reference position of the wire.
void setRecoPos2D(const Vector2D &recoPos2D)
Setter for the position in the reference plane.
CDCTrajectory2D & getTrajectory2D() const
Getter for the two dimensional trajectory fitted to the segment.
ERightLeft isRightOrLeft(const Vector2D &point) const
Checks if the given point is to the right or to the left of the trajectory.
Vector2D getClosest(const Vector2D &point) const
Calculates the closest approach on the trajectory to the given point.
bool m_middleAliases
Switch whether the hits in the middle with lowest drift radius should be aliased.
void refit(CDCSegment2D &segment, bool reestimate)
Fit the alias segment.
bool m_fullAlias
Switch whether the complete segment should be aliased.
bool m_borderAliases
Switch whether the border hits at the beginning and the end should be aliased.
bool m_crossAliases
Switch whether the segment should be aliased at the waist where an rl side switch was missed.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.