8#include <tracking/trackFindingCDC/filters/segmentTrack/SegmentTrackVarSet.h>
10#include <tracking/trackFindingCDC/fitting/CDCObservations2D.h>
11#include <tracking/trackFindingCDC/fitting/CDCRiemannFitter.h>
12#include <tracking/trackFindingCDC/fitting/CDCSZFitter.h>
14#include <tracking/trackFindingCDC/eventdata/tracks/CDCTrack.h>
15#include <tracking/trackFindingCDC/eventdata/segments/CDCSegment2D.h>
16#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
17#include <tracking/trackFindingCDC/eventdata/trajectories/CDCTrajectorySZ.h>
19#include <tracking/trackFindingCDC/topology/CDCWire.h>
21#include <tracking/trackFindingCDC/numerics/ToFinite.h>
24using namespace TrackFindingCDC;
28 const CDCTrack* track = testPair->getFrom();
34 double maxmimumTrajectoryDistanceFront = 0;
35 double maxmimumTrajectoryDistanceBack = 0;
36 double maxmimumHitDistanceFront = 0;
37 double maxmimumHitDistanceBack = 0;
39 double hitsInSameRegion = 0;
40 double hitsInCommon = 0;
46 const CDCTrajectory3D& trajectoryTrack3D = track->getStartTrajectory3D();
52 maxmimumTrajectoryDistanceBack = trajectoryTrack2D.
getDist2D(back.getWireHit().getRefPos2D());
57 if (segment->getStereoKind() == EStereoKind::c_Axial) {
59 if (not trajectoryTrack2D.
isFitted()) {
61 fitter.update(trajectorySegment, *segment);
70 observations.
fill(s, z);
73 if (observations.
size() > 3) {
77 double startZTrack = szTrajectoryTrack.
getZ0();
78 double startZSegments = szTrajectorySegments.
getZ0();
80 var<
named(
"z_distance")>() = startZTrack - startZSegments;
87 Vector3D backRecoPos3D = back.reconstruct3D(trajectoryTrack2D);
89 if (segment->getStereoKind() != EStereoKind::c_Axial) {
93 if (frontRecoPos3D.
z() > forwardZ or frontRecoPos3D.
z() < backwardZ or backRecoPos3D.
z() > forwardZ
94 or backRecoPos3D.
z() < backwardZ) {
100 double perpSOfFront = trajectoryTrack2D.
calcArcLength2D(segment->front().getRecoPos2D());
101 double perpSOfBack = trajectoryTrack2D.
calcArcLength2D(segment->back().getRecoPos2D());
103 double perpSMinimum = std::min(perpSOfFront, perpSOfBack);
104 double perpSMaximum = std::max(perpSOfFront, perpSOfBack);
108 if (recoHit.getArcLength2D() < 0.8 * perpSMinimum or
109 recoHit.getArcLength2D() > 1.2 * perpSMaximum) {
112 if (recoHit.getISuperLayer() == segment->getISuperLayer()) {
114 }
else if (abs(recoHit.getISuperLayer() - segment->getISuperLayer()) == 1) {
116 if (distanceFront > maxmimumHitDistanceFront) {
117 maxmimumHitDistanceFront = distanceFront;
119 double distanceBack = (back.getWireHit().getRefPos2D() - recoHit.getRecoPos2D()).norm();
120 if (distanceBack > maxmimumHitDistanceBack) {
121 maxmimumHitDistanceBack = distanceBack;
128 if (std::find_if(segment->begin(), segment->end(), [&trackHit](
const CDCRecoHit2D & segmentHit) {
129 return segmentHit.getWireHit().getHit() == trackHit.getWireHit().getHit();
130 }) != segment->end()) {
140 bool isAxialSegment = segment->getStereoKind() != EStereoKind::c_Axial;
143 if (isAxialSegment and recoHit.getStereoKind() == EStereoKind::c_Axial) {
144 observationsFull.
fill(recoHit.getWireHit().getRefPos2D());
145 if (abs(recoHit.getISuperLayer() - segment->getISuperLayer()) < 3) {
146 observationsNeigh.
fill(recoHit.getWireHit().getRefPos2D());
148 }
else if (not isAxialSegment and recoHit.getStereoKind() != EStereoKind::c_Axial) {
149 double s = recoHit.getArcLength2D();
150 double z = recoHit.getRecoZ();
151 observationsFull.
fill(s, z);
152 if (abs(recoHit.getISuperLayer() - segment->getISuperLayer()) < 3) {
153 observationsNeigh.
fill(s, z);
158 const CDCTrajectorySZ& trajectorySZ = track->getStartTrajectory3D().getTrajectorySZ();
161 bool hasZInformation = tanLambda != 0;
162 double max_hit_z_distance = -1;
163 double sum_hit_z_distance = 0;
164 double stereo_quad_tree_distance = 0;
166 if (hasZInformation) {
167 double thetaFirstSegmentHit = -10;
170 Vector3D reconstructedPosition = recoHit2D.reconstruct3D(trajectoryTrack2D);
171 const Vector2D& recoPos2D = recoHit2D.getRecoPos2D();
175 double current_z_distance = std::abs(trajectorySZ.
getZDist(perpS, reconstructedPosition.
z()));
176 if (std::isnan(current_z_distance)) {
180 if (thetaFirstSegmentHit == -10) {
181 thetaFirstSegmentHit = reconstructedPosition.
theta();
183 sum_hit_z_distance += current_z_distance;
184 if (current_z_distance > max_hit_z_distance) {
185 max_hit_z_distance = current_z_distance;
190 stereo_quad_tree_distance = thetaTrack - thetaFirstSegmentHit;
195 if (isAxialSegment) {
196 observationsFull.
fill(recoHit.getRecoPos2D());
197 observationsNeigh.
fill(recoHit.getRecoPos2D());
203 observationsFull.
fill(s, z);
204 observationsNeigh.
fill(s, z);
211 if (segment->getStereoKind() == EStereoKind::c_Axial) {
213 var<
named(
"fit_full")>() = fitter.fit(observationsFull).getPValue();
216 var<
named(
"fit_full")>() = toFinite(fitter.fit(observationsFull).getPValue(), 0);
218 if (observationsNeigh.
size() > 3) {
219 var<
named(
"fit_neigh")>() = toFinite(fitter.fit(observationsNeigh).getPValue(), 0);
225 if (observationsFull.
size() == observationsNeigh.
size()) {
229 var<
named(
"is_stereo")>() = segment->getStereoKind() != EStereoKind::c_Axial;
230 var<
named(
"segment_size")>() = segment->size();
231 var<
named(
"track_size")>() = track->size();
232 var<
named(
"mean_hit_z_distance")>() = sum_hit_z_distance;
233 var<
named(
"max_hit_z_distance")>() = max_hit_z_distance;
234 var<
named(
"stereo_quad_tree_distance")>() = toFinite(stereo_quad_tree_distance, 0);
241 var<
named(
"maxmimum_trajectory_distance_front")>() = toFinite(maxmimumTrajectoryDistanceFront, 999);
242 var<
named(
"maxmimum_trajectory_distance_back")>() = toFinite(maxmimumTrajectoryDistanceBack, 999);
244 var<
named(
"maxmimum_hit_distance_front")>() = maxmimumHitDistanceFront;
245 var<
named(
"maxmimum_hit_distance_back")>() = maxmimumHitDistanceBack;
247 var<
named(
"out_of_CDC")>() = outOfCDC;
248 var<
named(
"hits_in_same_region")>() = hitsInSameRegion;
250 var<
named(
"number_of_hits_in_common")>() = hitsInCommon;
252 var<
named(
"segment_super_layer")>() = segment->getISuperLayer();
256 var<
named(
"phi_between_track_and_segment")>() = toFinite(phiBetweenTrackAndSegment, 0);
257 var<
named(
"perp_s_of_front")>() = toFinite(perpSOfFront / radius, 0);
258 var<
named(
"perp_s_of_back")>() = toFinite(perpSOfBack / radius, 0);
Class serving as a storage of observed drift circles to present to the Riemann fitter.
std::size_t fill(double x, double y, double signedRadius=0.0, double weight=1.0)
Appends the observed position.
std::size_t size() const
Returns the number of observations stored.
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.
const CDCWireHit & getWireHit() const
Getter for the wire hit associated with the reconstructed hit.
Vector3D reconstruct3D(const CDCTrajectory2D &trajectory2D, const double z=0) const
Reconstruct the three dimensional position (especially of stereo hits) by determining the z coordinat...
const CDCWire & getWire() const
Getter for the wire the reconstructed hit associated to.
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.
double getRecoZ() const
Getter for the z coordinate of the reconstructed position.
double getArcLength2D() const
Getter for the travel distance in the xy projection.
Class implementing the Riemann fit for two dimensional trajectory circle.
static const CDCRiemannFitter & getFitter()
Static getter for a general Riemann fitter.
Class implementing the z coordinate over travel distance line fit.
static const CDCSZFitter & getFitter()
Getter for a standard sz line fitter instance.
A reconstructed sequence of two dimensional hits in one super layer.
Class representing a sequence of three dimensional reconstructed hits.
Particle trajectory as it is seen in xy projection represented as a circle.
Vector2D getMom2DAtSupport(const double bZ) const
Get the momentum at the support point of the trajectory.
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.
double calcArcLength2D(const Vector2D &point) const
Calculate the travel distance from the start position of the trajectory.
double getAbsMom2D(double bZ) const
Get the estimation for the absolute value of the transvers momentum.
bool isFitted() const
Checks if the circle is already set to a valid value.
Vector2D getExit() const
Calculates the point where the trajectory leaves the CDC.
double getDist2D(const Vector2D &point) const
Calculates the distance from the point to the trajectory as seen from the xy projection.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
Vector3D getFlightDirection3DAtSupport() const
Get the unit momentum at the start point of the trajectory.
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
Linear trajectory in sz space.
double getTanLambda() const
Getter for the slope over the travel distance coordinate.
double getZDist(const double s, const double z) const
Calculates the distance along between the given point at the sz trajectory.
double getZ0() const
Getter for the z coordinate at zero travel distance.
const Vector2D & getRefPos2D() const
The two dimensional reference position (z=0) of the underlying wire.
const WireLine & getWireLine() const
Getter for the wire line representation of the wire.
AObject Object
Type of the object to be analysed.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
bool extract(const BaseSegmentTrackFilter::Object *testPair) final
Generate and assign the contained variables.
static constexpr int named(const char *name)
Getter for the index from the name.
Float_t & var()
Reference getter for the value of the ith variable. Static version.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
bool hasNAN() const
Checks if one of the coordinates is NAN.
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
A three dimensional vector.
double z() const
Getter for the z coordinate.
double theta() const
Getter for the polar angle.
double backwardZ() const
Gives the backward z coordinate.
double forwardZ() const
Gives the forward z coordinate.
Abstract base class for different kinds of events.