16 LArHitWidthHelper::ConstituentHit::ConstituentHit(
const CartesianVector &positionVector,
const float hitWidth,
const Cluster *
const pParentClusterAddress) :
17 m_positionVector(positionVector),
19 m_pParentClusterAddress(pParentClusterAddress)
30 return (m_referencePoint.GetDistanceSquared(lhsPosition) < m_referencePoint.GetDistanceSquared(rhsPosition));
37 const Cluster *
const pCluster,
const float maxConstituentHitWidth,
const bool isUniformHits,
const float hitWidthScalingFactor) :
39 m_numCaloHits(pCluster->GetNCaloHits()),
52 m_numCaloHits(numCaloHits),
53 m_constituentHitVector(constituentHitVector),
54 m_totalWeight(totalWeight),
55 m_lowerXExtrema(lowerXExtrema),
56 m_higherXExtrema(higherXExtrema)
77 if (clusterToParametersMap.empty())
78 throw StatusCodeException(STATUS_CODE_NOT_INITIALIZED);
80 const auto clusterParametersIter(clusterToParametersMap.find(pCluster));
82 if (clusterParametersIter == clusterToParametersMap.end())
83 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
85 return clusterParametersIter->second;
92 if (maxConstituentHitWidth < std::numeric_limits<float>::epsilon())
94 std::cout <<
"LArHitWidthHelper::GetConstituentHits - Negative or equivalent to zero constitent hit width not allowed" << std::endl;
95 throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
98 const OrderedCaloHitList &orderedCaloHitList(pCluster->GetOrderedCaloHitList());
100 if (orderedCaloHitList.empty())
101 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
103 unsigned int totalConstituentHits(0);
104 for (
const OrderedCaloHitList::value_type &mapEntry : orderedCaloHitList)
106 for (
const CaloHit *
const pCaloHit : *mapEntry.second)
108 const float hitWidth = pCaloHit->GetCellSize1() * hitWidthScalingFactor;
109 const unsigned int numberOfConstituentHits = std::ceil(hitWidth / maxConstituentHitWidth);
111 totalConstituentHits += numberOfConstituentHits;
115 return totalConstituentHits;
121 const Cluster *
const pCluster,
const float maxConstituentHitWidth,
const float hitWidthScalingFactor,
const bool isUniform)
123 if (maxConstituentHitWidth < std::numeric_limits<float>::epsilon())
125 std::cout <<
"LArHitWidthHelper::GetConstituentHits - Negative or equivalent to zero constitent hit width not allowed" << std::endl;
126 throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
129 const OrderedCaloHitList &orderedCaloHitList(pCluster->GetOrderedCaloHitList());
131 if (orderedCaloHitList.empty())
132 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
135 for (
const OrderedCaloHitList::value_type &mapEntry : orderedCaloHitList)
137 for (
const CaloHit *
const pCaloHit : *mapEntry.second)
139 const float hitWidth = pCaloHit->GetCellSize1() * hitWidthScalingFactor;
140 const unsigned int numberOfConstituentHits = std::ceil(hitWidth / maxConstituentHitWidth);
147 const float constituentHitWidth = hitWidth / numberOfConstituentHits;
153 return constituentHitVector;
161 const CartesianVector &hitCenter(pCaloHit->GetPositionVector());
162 const bool isOdd(numberOfConstituentHits % 2 == 1);
163 float xDistanceFromCenter(0.
f);
166 unsigned int loopIterations(std::ceil(numberOfConstituentHits / 2.0));
167 for (
unsigned int i = 0; i < loopIterations; ++i)
173 constituentHitVector.push_back(
ConstituentHit(hitCenter, constituentHitWidth, pCluster));
178 xDistanceFromCenter += constituentHitWidth / 2;
183 xDistanceFromCenter += constituentHitWidth;
186 CartesianVector positivePosition(hitCenter + CartesianVector(xDistanceFromCenter, 0.
f, 0.
f)),
187 negativePosition(hitCenter - CartesianVector(xDistanceFromCenter, 0.
f, 0.
f));
189 constituentHitVector.push_back(
ConstituentHit(positivePosition, constituentHitWidth, pCluster));
190 constituentHitVector.push_back(
ConstituentHit(negativePosition, constituentHitWidth, pCluster));
198 float clusterWeight(0.
f);
200 clusterWeight += constituentHit.GetHitWidth();
202 return clusterWeight;
209 float clusterWeight(0.
f);
210 const OrderedCaloHitList &orderedCaloHitList(pCluster->GetOrderedCaloHitList());
212 for (
const OrderedCaloHitList::value_type &mapEntry : orderedCaloHitList)
214 for (
const CaloHit *
const pCaloHit : *mapEntry.second)
215 clusterWeight += pCaloHit->GetCellSize1();
218 return clusterWeight;
225 CartesianPointVector constituentHitPositionVector;
228 constituentHitPositionVector.push_back(constituentHit.GetPositionVector());
230 return constituentHitPositionVector;
237 CartesianVector lowerXCoordinate(0.
f, 0.
f, 0.
f), higherXCoordinate(0.
f, 0.
f, 0.
f);
240 return lowerXCoordinate;
247 CartesianVector lowerXCoordinate(0.
f, 0.
f, 0.
f), higherXCoordinate(0.
f, 0.
f, 0.
f);
250 return higherXCoordinate;
256 const ConstituentHitVector &constituentHitVector, CartesianVector &lowerXCoordinate, CartesianVector &higherXCoordinate)
260 CartesianVector innerCoordinate(0.
f, 0.
f, 0.
f), outerCoordinate(0.
f, 0.
f, 0.
f);
264 const float deltaX(outerCoordinate.GetX() - innerCoordinate.GetX());
265 const float deltaZ(outerCoordinate.GetZ() - innerCoordinate.GetZ());
267 if ((deltaX > 0.
f) || ((std::fabs(deltaX) < std::numeric_limits<float>::epsilon()) && (deltaZ > 0.
f)))
269 lowerXCoordinate = innerCoordinate;
270 higherXCoordinate = outerCoordinate;
274 lowerXCoordinate = outerCoordinate;
275 higherXCoordinate = innerCoordinate;
282 const CartesianVector &lineStart,
const CartesianVector &lineDirection,
const CaloHit *
const pCaloHit)
284 const CartesianVector &hitPosition(pCaloHit->GetPositionVector());
286 if (std::fabs(lineDirection.GetZ()) < std::numeric_limits<float>::epsilon())
289 float xOnLine(lineStart.GetX());
290 if (std::fabs(lineDirection.GetX()) > std::numeric_limits<float>::epsilon())
292 const float gradient(lineDirection.GetZ() / lineDirection.GetX());
293 xOnLine += ((hitPosition.GetZ() - lineStart.GetZ()) / gradient);
296 const float &hitWidth(pCaloHit->GetCellSize1());
297 const float hitLowXEdge(hitPosition.GetX() - (hitWidth * 0.5f));
298 const float hitHighXEdge(hitPosition.GetX() + (hitWidth * 0.5f));
299 const float closestPointX(xOnLine < hitLowXEdge ? hitLowXEdge : xOnLine > hitHighXEdge ? hitHighXEdge : xOnLine);
301 return CartesianVector(closestPointX, 0.
f, hitPosition.GetZ());
308 const CartesianVector &hitPosition(pCaloHit->GetPositionVector());
309 const float hitWidth(pCaloHit->GetCellSize1());
310 const float hitLowXEdge(hitPosition.GetX() - (hitWidth * 0.5f));
311 const float hitHighXEdge(hitPosition.GetX() + (hitWidth * 0.5f));
312 const float modDeltaZ(std::fabs(hitPosition.GetZ() - point2D.GetZ()));
314 if ((hitLowXEdge < point2D.GetX()) && (hitHighXEdge > point2D.GetX()))
317 const float deltaX = hitLowXEdge > point2D.GetX() ? (point2D.GetX() - hitLowXEdge) : (point2D.GetX() - hitHighXEdge);
319 return std::sqrt((deltaX * deltaX) + (modDeltaZ * modDeltaZ));
326 float closestDistance(std::numeric_limits<float>::max());
328 for (
const CaloHit *
const pCaloHit : caloHitList)
332 if (separation < closestDistance)
333 closestDistance = separation;
336 return closestDistance;
343 const CartesianVector &hitPosition1(pCaloHit1->GetPositionVector());
344 const float hitWidth1(pCaloHit1->GetCellSize1());
345 const float hitLowXEdge1(hitPosition1.GetX() - (hitWidth1 * 0.5f));
346 const float hitHighXEdge1(hitPosition1.GetX() + (hitWidth1 * 0.5f));
348 const CartesianVector &hitPosition2(pCaloHit2->GetPositionVector());
349 const float hitWidth2(pCaloHit2->GetCellSize1());
350 const float hitLowXEdge2(hitPosition2.GetX() - (hitWidth2 * 0.5f));
351 const float hitHighXEdge2(hitPosition2.GetX() + (hitWidth2 * 0.5f));
353 const float modDeltaZ(std::fabs(hitPosition1.GetZ() - hitPosition2.GetZ()));
356 if ((hitLowXEdge1 < hitHighXEdge2) && (hitLowXEdge1 > hitLowXEdge2))
359 if ((hitHighXEdge1 > hitLowXEdge2) && (hitHighXEdge1 < hitHighXEdge2))
363 if ((hitLowXEdge1 > hitLowXEdge2) && (hitHighXEdge1 < hitHighXEdge2))
366 if ((hitLowXEdge2 > hitLowXEdge1) && (hitHighXEdge2 < hitHighXEdge1))
369 const float deltaX = hitLowXEdge1 < hitLowXEdge2 ? (hitLowXEdge2 - hitHighXEdge1) : (hitLowXEdge1 - hitHighXEdge2);
371 return std::sqrt((deltaX * deltaX) + (modDeltaZ * modDeltaZ));
static float GetOriginalTotalClusterWeight(const pandora::Cluster *const pCluster)
Sum the widths of the original, unscaled hits contained within a cluster.
static const ClusterParameters & GetClusterParameters(const pandora::Cluster *const pCluster, const ClusterToParametersMap &clusterToParametersMap)
Return the cluster parameters of a given cluster, exception thrown if not found in map [cluster -> cl...
Header file for the lar hit width helper class.
bool operator()(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs)
Sort clusters by the higher x extremal point of their constituent hits.
static void SplitHitIntoConstituents(const pandora::CaloHit *const pCaloHit, const pandora::Cluster *const pCluster, const unsigned int numberOfConstituentHits, const float constituentHitWidth, ConstituentHitVector &constituentHitVector)
Break up the calo hit into constituent hits.
static void GetExtremalCoordinatesX(const ConstituentHitVector &constituentHitVector, pandora::CartesianVector &lowerXCoordinate, pandora::CartesianVector &higherXCoordinate)
Calculate the higher and lower x extremal points of the constituent hits.
static ConstituentHitVector GetConstituentHits(const pandora::Cluster *const pCluster, const float maxConstituentHitWidth, const float hitWidthScalingFactor, const bool isUniform)
Break up the cluster hits into constituent hits.
static pandora::CartesianVector GetClosestPointToLine2D(const pandora::CartesianVector &lineStart, const pandora::CartesianVector &lineDirection, const pandora::CaloHit *const pCaloHit)
Consider the hit width to find the closest position of a calo hit to a specified line.
const pandora::CartesianVector & GetPositionVector() const
Returns the constituent hit central position.
Header file for the cluster helper class.
const pandora::CartesianVector & GetHigherXExtrema() const
Returns the higher x extremal point of the constituent hits.
std::vector< ConstituentHit > ConstituentHitVector
static unsigned int GetNProposedConstituentHits(const pandora::Cluster *const pCluster, const float maxConstituentHitWidth, const float hitWidthScalingFactor)
Return the number of constituent hits that a given cluster would be broken into.
static pandora::CartesianPointVector GetConstituentHitPositionVector(const ConstituentHitVector &constituentHitVector)
Obtain a vector of the contituent hit central positions.
static pandora::CartesianVector GetExtremalCoordinatesLowerX(const ConstituentHitVector &constituentHitVector)
Return the lower x extremal point of the constituent hits.
static float GetTotalClusterWeight(const ConstituentHitVector &constituentHitVector)
Sum the widths of constituent hits.
static float GetClosestDistanceToPoint2D(const pandora::CaloHit *const pCaloHit, const pandora::CartesianVector &point2D)
Consider the hit width to find the smallest distance between a calo hit and a given point...
ConstituentHit(const pandora::CartesianVector &positionVector, const float hitWidth, const pandora::Cluster *const pParentClusterAddress)
Constructor.
static void GetExtremalCoordinates(const pandora::ClusterList &clusterList, pandora::CartesianVector &innerCoordinate, pandora::CartesianVector &outerCoordinate)
Get positions of the two most distant calo hits in a list of cluster (ordered by Z) ...
static pandora::CartesianVector GetExtremalCoordinatesHigherX(const ConstituentHitVector &constituentHitVector)
Return the higher x extremal point of the constituent hits.
bool operator()(const ConstituentHit &lhs, const ConstituentHit &rhs)
Sort constituent hits by their position relative to a referencePoint.
std::unordered_map< const pandora::Cluster *, const ClusterParameters > ClusterToParametersMap
static float GetClosestDistance(const pandora::CaloHit *const pThisCaloHit, const pandora::CaloHitList &caloHitList)
Find the smallest separation between a hit and a list of hits, with the consideration of their hit wi...
ClusterParameters(const pandora::Cluster *const pCluster, const float maxConsituentHitWidth, const bool isUniformHits, const float hitWidthScalingFactor)
Constructor.