9 #include "Helpers/ClusterFitHelper.h" 11 #include "Objects/Cluster.h" 28 ThreeDSlidingFitResult::ThreeDSlidingFitResult(
const T *
const pT,
const unsigned int layerWindow,
const float layerPitch) :
30 m_axisIntercept(m_primaryAxis.GetPosition()),
31 m_axisDirection(m_primaryAxis.GetMomentum()),
32 m_firstOrthoDirection(
ThreeDSlidingFitResult::GetSeedDirection(m_axisDirection).GetCrossProduct(m_axisDirection).GetUnitVector()),
33 m_secondOrthoDirection(m_axisDirection.GetCrossProduct(m_firstOrthoDirection).GetUnitVector()),
34 m_firstFitResult(
TwoDSlidingFitResult(pT, layerWindow, layerPitch, m_axisIntercept, m_axisDirection, m_firstOrthoDirection)),
35 m_secondFitResult(
TwoDSlidingFitResult(pT, layerWindow, layerPitch, m_axisIntercept, m_axisDirection, m_secondOrthoDirection)),
36 m_minLayer(
std::max(m_firstFitResult.GetMinLayer(), m_secondFitResult.GetMinLayer())),
37 m_maxLayer(
std::min(m_firstFitResult.GetMaxLayer(), m_secondFitResult.GetMaxLayer())),
38 m_minLayerPosition(0.
f, 0.
f, 0.
f),
39 m_maxLayerPosition(0.
f, 0.
f, 0.
f),
40 m_minLayerDirection(0.
f, 0.
f, 0.
f),
41 m_maxLayerDirection(0.
f, 0.
f, 0.
f)
44 throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
69 return std::min(firstLayer, secondLayer);
79 return std::max(firstLayer, secondLayer);
89 return std::sqrt(firstRms * firstRms + secondRms * secondRms);
99 return std::sqrt(firstRms * firstRms + secondRms * secondRms);
109 return std::sqrt(firstRms * firstRms + secondRms * secondRms);
128 return STATUS_CODE_INVALID_PARAMETER;
131 CartesianVector firstPosition(0.
f, 0.
f, 0.
f), secondPosition(0.
f, 0.
f, 0.
f);
134 if (STATUS_CODE_SUCCESS != statusCode1)
139 if (STATUS_CODE_SUCCESS != statusCode2)
142 float rL1(0.
f), rT1(0.
f), rL2(0.
f), rT2(0.
f);
149 return STATUS_CODE_SUCCESS;
161 return STATUS_CODE_INVALID_PARAMETER;
164 CartesianVector firstDirection(0.
f, 0.
f, 0.
f), secondDirection(0.
f, 0.
f, 0.
f);
167 if (STATUS_CODE_SUCCESS != statusCode1)
172 if (STATUS_CODE_SUCCESS != statusCode2)
175 float dTdL1(0.
f), dTdL2(0.
f);
182 return STATUS_CODE_SUCCESS;
196 const float pL(1.
f / std::sqrt(1.
f + dTdL1 * dTdL1 + dTdL2 * dTdL2));
197 const float pT1(dTdL1 / std::sqrt(1.
f + dTdL1 * dTdL1 + dTdL2 * dTdL2));
198 const float pT2(dTdL2 / std::sqrt(1.
f + dTdL1 * dTdL1 + dTdL2 * dTdL2));
200 CartesianVector globalCoordinates(0.
f, 0.
f, 0.
f);
209 CartesianPointVector pointVector;
218 if (pPointVector->size() < 2)
219 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
221 CartesianVector centroid(0.
f, 0.
f, 0.
f);
226 float minProjection(std::numeric_limits<float>::max());
227 CartesianVector fitDirection(eigenVecs.at(0));
231 if (fitDirection.GetZ() < 0.f)
232 fitDirection *= -1.
f;
234 for (
const CartesianVector &coordinate : *pPointVector)
235 minProjection = std::min(minProjection, fitDirection.GetDotProduct(coordinate - centroid));
238 const float fitProjection(layerPitch * std::floor(minProjection / layerPitch));
240 return TrackState(centroid + (fitDirection * fitProjection), fitDirection);
247 const float px(std::fabs(axisDirection.GetX()));
248 const float py(std::fabs(axisDirection.GetY()));
249 const float pz(std::fabs(axisDirection.GetZ()));
251 if (px < std::min(py, pz) + std::numeric_limits<float>::epsilon())
253 return CartesianVector(1.
f, 0.
f, 0.
f);
256 if (py < std::min(pz, px) + std::numeric_limits<float>::epsilon())
258 return CartesianVector(0.
f, 1.
f, 0.
f);
261 if (pz < std::min(px, py) + std::numeric_limits<float>::epsilon())
263 return CartesianVector(0.
f, 0.
f, 1.
f);
266 throw StatusCodeException(STATUS_CODE_FAILURE);
const int m_maxLayer
The maximum combined layer.
static pandora::TrackState GetPrimaryAxis(const pandora::Cluster *const pCluster, const float slidingFitLayerPitch)
Calculate the position and direction of the primary axis.
pandora::CartesianVector EigenValues
void GetLocalDirection(const pandora::CartesianVector &direction, float &dTdL) const
Get local sliding fit gradient for a given global direction.
float GetMaxLayerRms() const
Get rms at maximum layer.
int GetMaxLayer() const
Get the maximum occupied layer in the sliding fit.
static pandora::CartesianVector GetSeedDirection(const pandora::CartesianVector &axisDirection)
Generate a seed vector to be used in calculating the orthogonal axes.
float GetMaxLayerRms() const
Get rms at maximum layer.
float GetMinLayerRms() const
Get rms at minimum layer.
Header file for the principal curve analysis helper class.
float GetLongitudinalDisplacement(const pandora::CartesianVector &position) const
Get longitudinal projection onto primary axis.
pandora::CartesianVector m_maxLayerPosition
The global position at the maximum combined layer.
void GetGlobalDirection(const float dTdL1, const float dTdL2, pandora::CartesianVector &direction) const
Get global direction coordinates for a given pair of sliding linear fit gradients.
pandora::CartesianVector m_minLayerPosition
The global position at the minimum combined layer.
const int m_minLayer
The minimum combined layer.
int GetMaxLayer() const
Get the maximum occupied layer in the sliding fit.
const pandora::CartesianVector m_axisIntercept
The axis intercept position.
int GetMinLayer() const
Get the minimum occupied layer in the sliding fit.
const TwoDSlidingFitResult m_secondFitResult
The second sliding fit result.
Header file for the cluster helper class.
float GetFitRms(const float rL) const
Get fit rms for a given longitudinal coordinate.
pandora::StatusCode GetGlobalFitPosition(const float rL, pandora::CartesianVector &position) const
Get global fit position for a given longitudinal coordinate.
const TwoDSlidingFitResult m_firstFitResult
The first sliding fit result.
pandora::StatusCode GetGlobalFitDirection(const float rL, pandora::CartesianVector &direction) const
Get global fit direction for a given longitudinal coordinate.
const pandora::CartesianVector m_secondOrthoDirection
The orthogonal direction vector.
int GetMinLayer() const
Get the minimum occupied layer in the sliding fit.
const pandora::CartesianVector m_firstOrthoDirection
The orthogonal direction vector.
float GetMinLayerRms() const
Get rms at minimum layer.
Header file for the lar three dimensional sliding fit result class.
static void RunPca(const T &t, pandora::CartesianVector ¢roid, EigenValues &outputEigenValues, EigenVectors &outputEigenVectors)
Run principal component analysis using input calo hits (TPC_VIEW_U,V,W or TPC_3D; all treated as 3D p...
const pandora::Cluster * GetCluster() const
Get the address of the cluster, if originally provided.
void GetGlobalPosition(const float rL, const float rT1, const float rT2, pandora::CartesianVector &position) const
Get global coordinates for a given pair of sliding linear fit coordinates.
pandora::StatusCode GetGlobalFitDirection(const float rL, pandora::CartesianVector &direction) const
Get global fit direction for a given longitudinal coordinate.
float GetFitRms(const float rL) const
Get fit rms for a given longitudinal coordinate.
std::vector< pandora::CartesianVector > EigenVectors
ThreeDSlidingFitResult class.
float GetL(const int layer) const
Get longitudinal coordinate for a given sliding linear fit layer number.
pandora::CartesianVector m_minLayerDirection
The global direction at the minimum combined layer.
static void GetCoordinateVector(const pandora::Cluster *const pCluster, pandora::CartesianPointVector &coordinateVector)
Get vector of hit coordinates from an input cluster.
pandora::CartesianVector m_maxLayerDirection
The global direction at the maximum combined layer.
pandora::StatusCode GetGlobalFitPosition(const float rL, pandora::CartesianVector &position) const
Get global fit position for a given longitudinal coordinate.
const pandora::CartesianVector m_axisDirection
The axis direction vector.
const pandora::Cluster * GetCluster() const
Get the address of the cluster.
void GetLocalPosition(const pandora::CartesianVector &position, float &rL, float &rT) const
Get local sliding fit coordinates for a given global position.
ThreeDSlidingFitResult(const T *const pT, const unsigned int slidingFitWindow, const float slidingFitLayerPitch)
Constructor.
TwoDSlidingFitResult class.
int GetLayer(const float rL) const
Get layer number for given sliding linear fit longitudinal coordinate.