8#include <tracking/trackFindingCDC/processing/TrackQualityTools.h>
9#include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
10#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
11#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory3D.h>
12#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectory2D.h>
14#include <tracking/trackFindingCDC/topology/CDCWire.h>
15#include <tracking/trackFindingCDC/utilities/ReversedRange.h>
17#include <Math/VectorUtil.h>
20using namespace TrackFindingCDC;
26 if (recoHit.getStereoKind() == EStereoKind::c_Axial) {
29 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
41 if (arcLength2DOfApogee < 0) {
42 arcLength2DOfApogee += 2 * TMath::Pi() * radius;
49 double currentArcLength2D = recoHit.getArcLength2D();
50 if (currentArcLength2D < 0) B2INFO(
"Below 0");
51 if (currentArcLength2D > arcLength2DOfApogee) {
52 splittedCDCTrack.push_back(recoHit);
57 if (splittedCDCTrack.size() > 0) {
58 tracks.push_back(splittedCDCTrack);
64 if (track.empty())
return;
69 const Vector3D startPosition(0, 0, 0);
77 unsigned int numberOfPositiveHits = 0;
79 const double currentArcLength = trajectory2D.
calcArcLength2D(recoHit.getRecoPos2D());
80 if (currentArcLength > 0) {
81 numberOfPositiveHits++;
84 const bool reverseTrajectory = 2 * numberOfPositiveHits < track.size();
86 if (reverseTrajectory) {
93 Vector2D recoPos2D = recoHit.getRLWireHit().reconstruct3D(trajectory2D).xy();
96 if (arcLength2D < 0) {
97 arcLength2D += arcLength2DPeriod;
99 recoHit.setArcLength2D(arcLength2D);
100 recoHit.getWireHit().getAutomatonCell().unsetAssignedFlag();
101 recoHit.getWireHit().getAutomatonCell().setTakenFlag();
105 track.sortByArcLength2D();
108 Vector3D frontPosition = track.front().getRLWireHit().reconstruct3D(trajectory2D);
109 double arcLengthOffset = trajectory3D.
setLocalOrigin(frontPosition);
110 track.setStartTrajectory3D(trajectory3D);
112 recoHit.shiftArcLength2D(-arcLengthOffset);
116 Vector3D backPosition = track.back().getRLWireHit().reconstruct3D(trajectory2D);
117 double backArcLength2D = trajectory3D.
setLocalOrigin(backPosition);
118 if (backArcLength2D < 0) {
121 track.setEndTrajectory3D(trajectory3D);
127 const CDCTrajectory2D& trajectory2D = track.getStartTrajectory3D().getTrajectory2D();
131 if (trajectory2D.
isCurler(outerCylindricalRFactor)) {
137 double arcLength2DOfExitWithFactor = trajectory2D.
calcArcLength2D(outerExitWithFactor);
138 if (arcLength2DOfExitWithFactor < 0) {
139 arcLength2DOfExitWithFactor += 2 * TMath::Pi() * radius;
141 bool removeAfterThis =
false;
144 if (removeAfterThis) {
145 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
149 double currentArcLength2D = recoHit.getArcLength2D();
150 if (currentArcLength2D < 0) {
151 currentArcLength2D += 2 * TMath::Pi() * radius;
154 if (currentArcLength2D > arcLength2DOfExitWithFactor) {
155 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
156 removeAfterThis =
true;
163 ILayer lastLayer = -1;
166 std::vector<std::vector<const CDCRecoHit3D*>> trackletList;
167 trackletList.reserve(3);
169 std::vector<const CDCRecoHit3D*>* currentTracklet =
nullptr;
172 if (currentTracklet ==
nullptr) {
173 trackletList.emplace_back();
174 currentTracklet = &(trackletList.back());
177 const ILayer currentLayer = recoHit.getWire().getICLayer();
178 const Vector2D& currentPosition = recoHit.getRecoPos2D();
179 if (lastLayer != -1) {
180 const ILayer delta = currentLayer - lastLayer;
181 const double distance = (currentPosition - lastWirePosition).norm();
182 if (abs(delta) > 4 or distance > 50) {
183 trackletList.emplace_back();
184 currentTracklet = &(trackletList.back());
188 lastWirePosition = currentPosition;
189 lastLayer = currentLayer;
191 currentTracklet->push_back(&recoHit);
194 if (trackletList.size() > 1) {
195 for (
const std::vector<const CDCRecoHit3D*>& tracklet : trackletList) {
196 if (tracklet.size() < 5) {
198 recoHit->getWireHit().getAutomatonCell().setAssignedFlag();
211 if (std::isnan(radius)) {
215 std::vector<std::vector<const CDCRecoHit3D*>> trackletList;
217 double lastArcLength2D = NAN;
219 std::vector<const CDCRecoHit3D*>* currentTracklet =
nullptr;
222 if (currentTracklet ==
nullptr) {
223 trackletList.emplace_back();
224 currentTracklet = &(trackletList.back());
227 const double currentArcLength2D = recoHit.getArcLength2D();
228 if (not std::isnan(lastArcLength2D)) {
229 const double delta = (currentArcLength2D - lastArcLength2D);
230 if (std::fabs(delta) > m_maximumArcLength2DDistance) {
231 trackletList.emplace_back();
232 currentTracklet = &(trackletList.back());
236 lastArcLength2D = currentArcLength2D;
238 currentTracklet->push_back(&recoHit);
241 if (trackletList.size() > 1) {
243 while (trackletList.size() > 0) {
244 if (trackletList.back().size() > 4) {
248 for (
const CDCRecoHit3D* recoHit : trackletList.back()) {
249 recoHit->getWireHit().getAutomatonCell().setAssignedFlag();
252 trackletList.pop_back();
255 std::reverse(trackletList.begin(), trackletList.end());
257 while (trackletList.size() > 0) {
258 if (trackletList.back().size() > 4) {
262 for (
const CDCRecoHit3D* recoHit : trackletList.back()) {
263 recoHit->getWireHit().getAutomatonCell().setAssignedFlag();
266 trackletList.pop_back();
273 const bool deleteTrack = track.size() < minimalHits;
277 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
284 double lastAngle = NAN;
285 bool removeAfterThis =
false;
287 for (
const CDCRecoHit3D& recoHit : reversedRange(track)) {
288 if (removeAfterThis) {
289 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
293 const double currentAngle = recoHit.getRecoPos2D().phi();
294 if (not std::isnan(lastAngle)) {
295 const double delta = currentAngle - lastAngle;
296 const double normalizedDelta =
298 ROOT::Math::VectorUtil::Phi_0_2pi(delta),
299 ROOT::Math::VectorUtil::Phi_0_2pi(-delta));
300 if (fabs(normalizedDelta) > maximalAngle) {
301 removeAfterThis =
true;
302 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
306 lastAngle = currentAngle;
313 ISuperLayer lastLayer = -1;
314 bool deleteTrack =
true;
317 const ISuperLayer currentLayer = recoHit.getISuperLayer();
318 if (lastLayer != -1 and lastLayer != currentLayer) {
323 lastLayer = currentLayer;
328 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
344 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
355 if (std::isnan(radius)) {
359 double lastArcLength2D = NAN;
360 bool removeAfterThis =
false;
363 if (removeAfterThis) {
364 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
368 const double currentArcLength2D = recoHit.getArcLength2D();
369 if (not std::isnan(lastArcLength2D)) {
370 const double delta = (currentArcLength2D - lastArcLength2D) / radius;
371 if (fabs(delta) > m_maximumArcLength2DDistance) {
372 removeAfterThis =
true;
373 recoHit.getWireHit().getAutomatonCell().setAssignedFlag();
378 lastArcLength2D = currentArcLength2D;
void setAssignedFlag(bool setTo=true)
Sets the already assigned marker flag to the given value. Default value true.
Class representing a three dimensional reconstructed hit.
Class representing a sequence of three dimensional reconstructed hits.
void setStartTrajectory3D(const CDCTrajectory3D &startTrajectory3D)
Setter for the two dimensional trajectory.
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Particle trajectory as it is seen in xy projection represented as a circle.
PerigeeCircle getGlobalCircle() const
Getter for the circle in global coordinates.
Vector2D getOuterExit(double factor=1) const
Calculates the point where the trajectory meets the outer wall of the CDC.
void reverse()
Reverses the trajectory in place.
double calcArcLength2D(const Vector2D &point) const
Calculate the travel distance from the start position of the trajectory.
bool isCurler(double factor=1) const
Checks if the trajectory leaves the outer radius of the CDC times the given tolerance factor.
double getArcLength2DPeriod() const
Getter for the arc length for one round trip around the trajectory.
const UncertainPerigeeCircle & getLocalCircle() const
Getter for the circle in local coordinates.
Particle full three dimensional trajectory.
void reverse()
Reverses the trajectory in place.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
double shiftPeriod(int nPeriods)
Adjusts the z0 to the one that lies n periods forward.
double setLocalOrigin(const Vector3D &localOrigin)
Setter for the origin of the local coordinate system.
void setFlightTime(double flightTime)
Setter for the time when the particle reached the support point position.
Vector2D apogee() const
Getter for the apogee of the circle. If it was a line both components will be infinity.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
A three dimensional vector.
Abstract base class for different kinds of events.