8#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
10#include <tracking/trackingUtilities/eventdata/trajectories/CDCBFieldUtil.h>
12#include <cdc/topology/CDCWireTopology.h>
13#include <cdc/topology/CDCWireLayer.h>
14#include <cdc/topology/WireLine.h>
15#include <cdc/topology/ISuperLayer.h>
17#include <tracking/trackingUtilities/geometry/UncertainPerigeeCircle.h>
18#include <tracking/trackingUtilities/geometry/PerigeeCircle.h>
19#include <tracking/trackingUtilities/geometry/VectorUtil.h>
21#include <tracking/trackingUtilities/numerics/EForwardBackward.h>
22#include <tracking/trackingUtilities/numerics/ESign.h>
23#include <tracking/trackingUtilities/numerics/Quadratic.h>
25#include <framework/gearbox/Const.h>
35using namespace TrackingUtilities;
60 const ROOT::Math::XYVector& mom2D,
65 VectorUtil::unit(mom2D),
73 const ROOT::Math::XYVector& mom2D,
77 VectorUtil::unit(mom2D),
110 const double distance,
111 const double z)
const
113 ROOT::Math::XYVector globalPos2D = wireLine.
sagPos2DAtZ(z);
114 ROOT::Math::XYVector movePerZ = wireLine.
sagMovePerZ(z);
119 double fastDistance = distance != 0.0 ? localCircle.
fastDistance(distance) : 0.0;
121 double c = localCircle.
fastDistance(localPos2D) - fastDistance;
122 double b = localCircle.
gradient(localPos2D).Dot(movePerZ);
123 double a = localCircle.
n3() * movePerZ.Mag2();
125 const std::pair<double, double> solutionsDeltaZ = solveQuadraticABC(a, b, c);
128 const std::array<double, 2> solutionsZ{solutionsDeltaZ.second + z, solutionsDeltaZ.first + z};
133 const double distance,
134 const double z)
const
136 const std::array<double, 2> solutionsZ =
reconstructBothZ(wireLine, distance, z);
138 bool firstIsInCDC = (wireLine.
backwardZ() < solutionsZ[0] and
139 solutionsZ[0] < wireLine.
forwardZ());
140 bool secondIsInCDC = (wireLine.
backwardZ() < solutionsZ[1] and
141 solutionsZ[1] < wireLine.
forwardZ());
144 assert(not(std::fabs(solutionsZ[0] - z) > std::fabs(solutionsZ[1] - z)));
145 const double recoZ = (firstIsInCDC or not secondIsInCDC) ? solutionsZ[0] : solutionsZ[1];
150 const double distance,
151 const double z)
const
153 const std::array<double, 2> solutionsZ =
reconstructBothZ(wireLine, distance, z);
155 const ROOT::Math::XYZVector firstRecoWirePos3D = wireLine.
sagPos3DAtZ(solutionsZ[0]);
156 const ROOT::Math::XYZVector secondRecoWirePos3D = wireLine.
sagPos3DAtZ(solutionsZ[1]);
157 const auto& tmp1 =
getClosest(VectorUtil::getXYVector(firstRecoWirePos3D));
158 const auto& tmp2 =
getClosest(VectorUtil::getXYVector(secondRecoWirePos3D));
159 return {{{tmp1.X(), tmp1.Y(), firstRecoWirePos3D.z()},
160 {tmp2.X(), tmp2.Y(), secondRecoWirePos3D.z()}
165 const double distance,
166 const double z)
const
168 const double recoZ =
reconstructZ(wireLine, distance, z);
169 const ROOT::Math::XYZVector recoWirePos2D = wireLine.
sagPos3DAtZ(recoZ);
170 const auto& tmp =
getClosest(VectorUtil::getXYVector(recoWirePos2D));
171 return ROOT::Math::XYZVector(tmp.X(), tmp.Y(), recoZ);
205 if (forwardBackwardInfo == EForwardBackward::c_Backward) {
206 movingOutward = not movingOutward;
224 if (forwardBackwardInfo == EForwardBackward::c_Backward) {
225 movingOutward = not movingOutward;
234 ISuperLayer iSuperLayerStep = nextISuperLayer - startISuperLayer;
235 assert(std::abs(iSuperLayerStep) == 1);
236 bool nextMovingOutward = iSuperLayerStep > 0;
303 const ROOT::Math::XYVector support =
getSupport();
305 if (support.Mag2() < innerCylindricalR * innerCylindricalR) {
309 const ROOT::Math::XYVector apogee = globalCircle.
apogee();
323 const ROOT::Math::XYVector support =
getSupport();
325 if (support.Mag2() > outerCylindricalR * outerCylindricalR) {
329 const ROOT::Math::XYVector perigee = globalCircle.
perigee();
348 const ROOT::Math::XYVector& mom2D,
353 ROOT::Math::XYVector phiVec = VectorUtil::unit(mom2D);
368std::ostream& TrackingUtilities::operator<<(std::ostream& output,
const CDCTrajectory2D& trajectory2D)
370 return output <<
"Local origin : " << trajectory2D.
getLocalOrigin() <<
", "
Class representing a sense wire layer in the central drift chamber.
double getInnerCylindricalR() const
Getter for inner radius of the layer as taken from the CDCGeometryPar.
double getOuterCylindricalR() const
Getter for outer radius of the layer as taken from the CDCGeometryPar.
Class representing the sense wire arrangement in the whole of the central drift chamber.
const std::vector< CDCWireLayer > & getWireLayers() const
Getter for the underlying storing layer vector.
ISuperLayer getISuperLayerAtCylindricalR(double cylindricalR)
Returns the logical superlayer number at the given radius.
double getInnerCylindricalR() const
Getter for the inner radius of the inner most wire layer.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
double getOuterCylindricalR() const
Getter for the outer radius of the outer most wire layer.
A three dimensional limited line represented by its closest approach to the z-axes (reference positio...
ROOT::Math::XYVector sagPos2DAtZ(const double z) const
Gives the two dimensional position with wire sag effect of the line at the given z value.
double backwardZ() const
Gives the backward z coordinate.
ROOT::Math::XYZVector sagPos3DAtZ(const double z) const
Gives the three dimensional position with wire sag effect of the line at the given z value.
double forwardZ() const
Gives the forward z coordinate.
ROOT::Math::XYVector sagMovePerZ(const double z) const
Gives the two dimensional position with wire sag effect of the line at the given z value.
static const double speedOfLight
[cm/ns]
Helper functions to interact with the magnetic field.
static double curvatureToAbsMom2D(double curvature, double bZ)
Conversion helper for two dimensional curvature to momenta.
static ESign ccwInfoToChargeSign(ERotation ccwInfo)
Conversion helper from clockwise or counterclockwise travel to the charge sign.
static double absMom2DToCurvature(double absMom2D, double charge, double bZ)
Conversion helper for momenta to two dimensional curvature.
Particle trajectory as it is seen in xy projection represented as a circle.
std::array< ROOT::Math::XYZVector, 2 > reconstructBoth3D(const CDC::WireLine &wireLine, double distance=0.0, double z=0) const
Gives the two three dimensional points where the drift circle touches the wire line.
double getMaximalCylindricalR() const
Getter for the maximal distance from the origin.
ROOT::Math::XYVector m_localOrigin
Memory for local coordinate origin of the circle representing the trajectory in global coordinates.
CDCTrajectory2D reversed() const
Returns the reverse trajectory as a copy.
ROOT::Math::XYVector getSupport() const
Get the support point of the trajectory in global coordinates.
PerigeeCircle getGlobalCircle() const
Getter for the circle in global coordinates.
CDC::ISuperLayer getAxialISuperLayerAfterStart(EForwardBackward forwardBackwardInfo) const
Indicates which axial superlayer is traversed after the one, where the start point of the trajectory ...
CDC::ISuperLayer getISuperLayerAfter(CDC::ISuperLayer iSuperLayer, bool movingOutward) const
Returns which superlayer is traversed after the current one following the trajectory outward or inwar...
double reconstructZ(const CDC::WireLine &wireLine, double distance=0.0, double z=0) const
Gives the one z positions within the CDC closest to the given z where the given drift circle on the w...
void reverse()
Reverses the trajectory in place.
bool isOriginer(double factor=1) const
Checks if the trajectory intersects with the inner radius of the CDC time the given tolerance factor.
CDC::ISuperLayer getStartISuperLayer() const
Indicates the superlayer the trajectory starts in.
ROOT::Math::XYVector getClosest(const ROOT::Math::XYVector &point) const
Calculates the closest approach on the trajectory to the given point.
ESign getChargeSign() const
Gets the charge sign of the trajectory.
double calcArcLength2D(const ROOT::Math::XYVector &point) const
Calculate the travel distance from the start position of the trajectory.
CDC::ISuperLayer getISuperLayerAfterStart(bool movingOutward) const
Returns which superlayer is traversed after the current one following the trajectory outward or inwar...
double setLocalOrigin(const ROOT::Math::XYVector &localOrigin)
Setter for the origin of the local coordinate system.
ROOT::Math::XYVector getOuterExit(double factor=1) const
Calculates the point where the trajectory meets the outer wall of the CDC.
void setPosMom2D(const ROOT::Math::XYVector &pos2D, const ROOT::Math::XYVector &mom2D, double charge)
Setter for start point and momentum at the start point subjected to the charge sign.
CDC::ISuperLayer getPreviousISuperLayer() const
Indicates which superlayer the trajectory traverses before the one, where the start point of the traj...
const ROOT::Math::XYVector & getLocalOrigin() const
Getter for the origin of the local coordinate system.
bool isCurler(double factor=1) const
Checks if the trajectory leaves the outer radius of the CDC times the given tolerance factor.
CDC::ISuperLayer getMinimalISuperLayer() const
Indicates the minimal superlayer the trajectory traverses.
bool isFitted() const
Checks if the circle is already set to a valid value.
ROOT::Math::XYVector getExit() const
Calculates the point where the trajectory leaves the CDC.
double getMinimalCylindricalR() const
Getter for the minimal distance from the origin - same as absolute value of the impact parameter.
CDC::ISuperLayer getPreviousAxialISuperLayer() const
Indicates which axial superlayer the trajectory traverses before the one, where the start point of th...
CDC::ISuperLayer getMaximalISuperLayer() const
Indicates the maximal superlayer the trajectory traverses.
double getAbsMom2D() const
Get the estimation for the absolute value of the transvers momentum.
const UncertainPerigeeCircle & getLocalCircle() const
Getter for the circle in local coordinates.
std::array< double, 2 > reconstructBothZ(const CDC::WireLine &wireLine, double distance=0.0, double z=0) const
Gives the two z positions where the given drift circle on the wire line touches the trajectory.
ROOT::Math::XYZVector reconstruct3D(const CDC::WireLine &wireLine, double distance=0.0, double z=0) const
Gives the one three dimensional positions within the CDC closest to the given z where the given drift...
UncertainPerigeeCircle m_localPerigeeCircle
Memory for the generalized circle describing the trajectory in coordinates from the local origin.
CDCTrajectory2D()
Default constructor for ROOT compatibility.
void clear()
Clears all information from this trajectory.
bool isMovingOutward() const
Indicates if the trajectory is moving outwards or inwards (to or away from the origin) from the start...
ROOT::Math::XYVector getInnerExit() const
Calculates the point where the trajectory meets the inner wall of the CDC.
CDC::ISuperLayer getNextISuperLayer() const
Indicates which superlayer the trajectory traverses after the one, where the start point of the traje...
CDC::ISuperLayer getNextAxialISuperLayer() const
Indicates which axial superlayer the trajectory traverses after the one, where the start point of the...
double m_flightTime
Memory for the estimation of the time at which the particle arrived at the support point.
Extension of the generalized circle also caching the perigee coordinates.
ROOT::Math::XYVector gradient(const ROOT::Math::XYVector &point) const
Gradient of the distance field, hence indicates the direction of increasing distance.
ROOT::Math::XYVector apogee() const
Getter for the apogee of the circle. If it was a line both components will be infinity.
double fastDistance(const ROOT::Math::XYVector &point) const
Getter for the linearised distance measure to a point.
bool isInvalid() const
Indicates if all circle parameters are zero.
ROOT::Math::XYVector closest(const ROOT::Math::XYVector &point) const
Calculates the point of closest approach on the circle to the given point.
double n3() const
Getter for the generalised circle parameter n3.
ROOT::Math::XYVector perigee() const
Getter for the perigee point.
ROOT::Math::XYVector chooseNextForwardOf(const ROOT::Math::XYVector &start, const ROOT::Math::XYVector &end1, const ROOT::Math::XYVector &end2) const
Returns the one of two end point which is first reached from the given start if one strictly follows ...
ROOT::Math::XYVector atCylindricalRForwardOf(const ROOT::Math::XYVector &startPoint, double cylindricalR) const
Approach on the circle with the given cylindrical radius that lies in the forward direction of a star...
Adds an uncertainty matrix to the circle in perigee parameterisation.
signed short ISuperLayer
The type of the layer and superlayer ids.
Abstract base class for different kinds of events.
static const ISuperLayer c_Invalid
Constant making an invalid superlayer id.
static bool isAxial(ISuperLayer iSuperLayer)
Returns if the super layer with the given id is axial.
static ISuperLayer getNextInwards(ISuperLayer iSuperLayer)
Returns the super layer that is inside of the given super layer.
static bool isInvalid(ISuperLayer iSuperLayer)
Indicates if the given number corresponds to a true cdc superlayer - excludes the logic ids for inner...
static ISuperLayer getNextOutwards(ISuperLayer iSuperLayer)
Returns the super layer that is outside of the given super layer.