9 #include "Pandora/AlgorithmHeaders.h" 20 TrackClusterCreationAlgorithm::TrackClusterCreationAlgorithm() :
21 m_mergeBackFilteredHits(true),
23 m_maxCaloHitSeparationSquared(1.3
f * 1.3
f),
24 m_minCaloHitSeparationSquared(0.4
f * 0.4
f),
25 m_closeSeparationSquared(0.9
f * 0.9
f)
33 const CaloHitList *pCaloHitList = NULL;
34 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*
this, pCaloHitList));
36 OrderedCaloHitList selectedCaloHitList, rejectedCaloHitList;
37 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->
FilterCaloHits(pCaloHitList, selectedCaloHitList, rejectedCaloHitList));
45 this->
IdentifyJoins(selectedCaloHitList, forwardHitAssociationMap, backwardHitAssociationMap, hitJoinMap);
46 this->
CreateClusters(selectedCaloHitList, hitJoinMap, hitToClusterMap);
49 this->
CreateClusters(rejectedCaloHitList, hitJoinMap, hitToClusterMap);
51 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->
AddFilteredCaloHits(selectedCaloHitList, rejectedCaloHitList, hitToClusterMap));
53 return STATUS_CODE_SUCCESS;
60 CaloHitList availableHitList;
62 for (
const CaloHit *
const pCaloHit : *pCaloHitList)
64 if (PandoraContentApi::IsAvailable(*
this, pCaloHit))
65 availableHitList.push_back(pCaloHit);
68 if (availableHitList.empty())
69 return STATUS_CODE_SUCCESS;
71 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, selectedCaloHitList.Add(availableHitList));
75 CaloHitVector caloHits(iter->second->begin(), iter->second->end());
78 for (
const CaloHit *
const pCaloHitI : caloHits)
80 bool useCaloHit(
true);
82 for (
const CaloHit *
const pCaloHitJ : caloHits)
84 if (pCaloHitI == pCaloHitJ)
87 if ((pCaloHitI->GetMipEquivalentEnergy() < pCaloHitJ->GetMipEquivalentEnergy()) &&
96 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, rejectedCaloHitList.Add(pCaloHitI));
100 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, selectedCaloHitList.Remove(rejectedCaloHitList));
101 return STATUS_CODE_SUCCESS;
111 CaloHitList *pCaloHitList = NULL;
112 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, selectedCaloHitList.GetCaloHitsInPseudoLayer(iter->first, pCaloHitList));
114 CaloHitSet unavailableHits;
116 CaloHitVector inputAvailableHits(iter->second->begin(), iter->second->end());
119 CaloHitVector clusteredHits(pCaloHitList->begin(), pCaloHitList->end());
127 CaloHitVector newClusteredHits;
129 for (
const CaloHit *
const pCaloHitI : inputAvailableHits)
131 if (unavailableHits.count(pCaloHitI))
134 if (hitToClusterMap.end() != hitToClusterMap.find(pCaloHitI))
137 const CaloHit *pClosestHit = NULL;
140 for (
const CaloHit *
const pCaloHitJ : clusteredHits)
142 if (pCaloHitI->GetMipEquivalentEnergy() > pCaloHitJ->GetMipEquivalentEnergy())
145 const float separationSquared((pCaloHitI->GetPositionVector() - pCaloHitJ->GetPositionVector()).GetMagnitudeSquared());
147 if (separationSquared < closestSeparationSquared)
149 closestSeparationSquared = separationSquared;
150 pClosestHit = pCaloHitJ;
159 if (hitToClusterMap.end() == mapIter)
160 throw StatusCodeException(STATUS_CODE_FAILURE);
162 const Cluster *
const pCluster = mapIter->second;
163 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToCluster(*
this, pCluster, pCaloHitI));
164 (void) hitToClusterMap.insert(HitToClusterMap::value_type(pCaloHitI, pCluster));
166 newClusteredHits.push_back(pCaloHitI);
170 for (
const CaloHit *
const pCaloHit : newClusteredHits)
172 clusteredHits.push_back(pCaloHit);
173 unavailableHits.insert(pCaloHit);
178 return STATUS_CODE_SUCCESS;
188 unsigned int nLayersConsidered(0);
190 CaloHitVector caloHitsI(iterI->second->begin(), iterI->second->end());
195 if (iterJ->first == iterI->first || iterJ->first > iterI->first +
m_maxGapLayers + 1)
198 CaloHitVector caloHitsJ(iterJ->second->begin(), iterJ->second->end());
201 for (
const CaloHit *
const pCaloHitI : caloHitsI)
203 for (
const CaloHit *
const pCaloHitJ : caloHitsJ)
217 CaloHitVector caloHits(iter->second->begin(), iter->second->end());
220 for (
const CaloHit *
const pCaloHit : caloHits)
223 const CaloHit *
const pForwardHit((forwardHitAssociationMap.end() == fwdIter) ? NULL : fwdIter->second.GetPrimaryTarget());
226 const CaloHit *
const pForwardHitCheck((backwardHitAssociationMap.end() == fwdCheckIter) ? NULL : fwdCheckIter->second.GetPrimaryTarget());
228 if ((NULL != pForwardHit) && (pForwardHitCheck != pCaloHit))
232 const CaloHit *
const pBackwardHit((backwardHitAssociationMap.end() == bwdIter) ? NULL : bwdIter->second.GetPrimaryTarget());
235 const CaloHit *
const pBackwardHitCheck((forwardHitAssociationMap.end() == bwdCheckIter) ? NULL : bwdCheckIter->second.GetPrimaryTarget());
237 if ((NULL != pBackwardHit) && (pBackwardHitCheck != pCaloHit))
250 CaloHitVector caloHits(iter->second->begin(), iter->second->end());
253 for (
const CaloHit *
const pCaloHit : caloHits)
255 const CaloHit *
const pForwardJoinHit = this->
GetJoinHit(pCaloHit, forwardHitAssociationMap, backwardHitAssociationMap);
256 const CaloHit *
const pBackwardJoinHit = this->
GetJoinHit(pForwardJoinHit, backwardHitAssociationMap, forwardHitAssociationMap);
258 if ((NULL == pForwardJoinHit) || (NULL == pBackwardJoinHit) || (pBackwardJoinHit != pCaloHit))
263 if (hitJoinMap.end() == joinIter)
264 hitJoinMap.insert(HitJoinMap::value_type(pCaloHit, pForwardJoinHit));
266 if ((hitJoinMap.end() != joinIter) && (joinIter->second != pForwardJoinHit))
267 throw StatusCodeException(STATUS_CODE_FAILURE);
278 CaloHitVector caloHits(iter->second->begin(), iter->second->end());
281 for (
const CaloHit *
const pCaloHit : caloHits)
283 const Cluster *pCluster = NULL;
287 if (hitToClusterMap.end() == mapIter)
289 PandoraContentApi::Cluster::Parameters parameters;
290 parameters.m_caloHitList.push_back(pCaloHit);
291 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Cluster::Create(*
this, parameters, pCluster));
292 hitToClusterMap.insert(HitToClusterMap::value_type(pCaloHit, pCluster));
296 pCluster = mapIter->second;
301 if (hitJoinMap.end() == joinIter)
304 if (hitToClusterMap.end() != hitToClusterMap.find(joinIter->second))
305 throw StatusCodeException(STATUS_CODE_FAILURE);
307 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToCluster(*
this, pCluster, joinIter->second));
308 hitToClusterMap.insert(HitToClusterMap::value_type(joinIter->second, pCluster));
318 const float distanceSquared((pCaloHitJ->GetPositionVector() - pCaloHitI->GetPositionVector()).GetMagnitudeSquared());
325 if (forwardHitAssociationMap.end() == forwardIter)
327 forwardHitAssociationMap.insert(HitAssociationMap::value_type(pCaloHitI,
HitAssociation(pCaloHitJ, distanceSquared)));
329 else if (distanceSquared < forwardIter->second.GetPrimaryDistanceSquared())
336 if (backwardHitAssociationMap.end() == backwardIter)
338 backwardHitAssociationMap.insert(HitAssociationMap::value_type(pCaloHitJ,
HitAssociation(pCaloHitI, distanceSquared)));
340 else if (distanceSquared < backwardIter->second.GetPrimaryDistanceSquared())
342 backwardIter->second =
HitAssociation(pCaloHitI, distanceSquared);
354 if ((forwardHitAssociationMap.end() == forwardIter) || (backwardHitAssociationMap.end() == backwardIter))
386 if (hitAssociationMapI.end() == iterI)
389 const CaloHit *
const pPrimaryTarget = iterI->second.GetPrimaryTarget();
390 const CaloHit *
const pSecondaryTarget = iterI->second.GetSecondaryTarget();
392 if (NULL == pSecondaryTarget)
393 return pPrimaryTarget;
395 unsigned int primaryNSteps(0), secondaryNSteps(0);
396 const CaloHit *
const pPrimaryTrace = this->
TraceHitAssociation(pPrimaryTarget, hitAssociationMapI, hitAssociationMapJ, primaryNSteps);
397 const CaloHit *
const pSecondaryTrace = this->
TraceHitAssociation(pSecondaryTarget, hitAssociationMapI, hitAssociationMapJ, secondaryNSteps);
399 if ((pPrimaryTrace == pSecondaryTrace) || (secondaryNSteps < 5))
400 return pPrimaryTarget;
411 const CaloHit *pThisHit = pCaloHit;
412 const CaloHit *pLastHit = pCaloHit;
420 if (hitAssociationMapI.end() == iterI)
423 pLastHit = iterI->second.GetPrimaryTarget();
426 if (hitAssociationMapJ.end() == iterJ)
429 if (iterJ->second.GetPrimaryTarget() != pThisHit)
440 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
443 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
447 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
448 "MaxCaloHitSeparation", maxCaloHitSeparation));
452 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
453 "MinCaloHitSeparation", minCaloHitSeparation));
457 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
458 "CloseSeparation", closeSeparation));
461 return STATUS_CODE_SUCCESS;
pandora::StatusCode FilterCaloHits(const pandora::CaloHitList *const pCaloHitList, pandora::OrderedCaloHitList &selectedCaloHitList, pandora::OrderedCaloHitList &rejectedCaloHitList) const
Filter out low pulse height hits in close proximity to high pulse height hits.
float m_maxCaloHitSeparationSquared
Square of maximum calo hit separation.
pandora::StatusCode AddFilteredCaloHits(const pandora::OrderedCaloHitList &selectedCaloHitList, const pandora::OrderedCaloHitList &rejectedCaloHitList, HitToClusterMap &hitToClusterMap) const
Merge previously filtered hits back into their associated clusters.
void IdentifyJoins(const pandora::OrderedCaloHitList &orderedCaloHitList, const HitAssociationMap &forwardHitAssociationMap, const HitAssociationMap &backwardHitAssociationMap, HitJoinMap &hitJoinMap) const
Identify final hit joins for use in cluster formation.
pandora::StatusCode Run()
float GetSecondaryDistanceSquared() const
Get the secondary distance squared.
Header file for the cluster creation algorithm class.
void MakePrimaryAssociations(const pandora::OrderedCaloHitList &orderedCaloHitList, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Control primary association formation.
std::unordered_map< const pandora::CaloHit *, const pandora::CaloHit * > HitJoinMap
static bool SortHitsByPosition(const pandora::CaloHit *const pLhs, const pandora::CaloHit *const pRhs)
Sort calo hits by their position (use Z, followed by X, followed by Y)
Header file for the cluster helper class.
const pandora::CaloHit * GetPrimaryTarget() const
Get the primary target.
float GetPrimaryDistanceSquared() const
Get the primary distance squared.
void SetSecondaryTarget(const pandora::CaloHit *const pSecondaryTarget, const float secondaryDistanceSquared)
Set secondary target.
void CreateClusters(const pandora::OrderedCaloHitList &orderedCaloHitList, const HitJoinMap &hitJoinMap, HitToClusterMap &hitToClusterMap) const
Final cluster formation.
void CreatePrimaryAssociation(const pandora::CaloHit *const pCaloHitI, const pandora::CaloHit *const pCaloHitJ, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Create primary association if appropriate, hitI<->hitJ.
std::unordered_map< const pandora::CaloHit *, HitAssociation > HitAssociationMap
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
std::unordered_map< const pandora::CaloHit *, const pandora::Cluster * > HitToClusterMap
unsigned int m_maxGapLayers
Maximum number of layers for a gap.
const pandora::CaloHit * GetJoinHit(const pandora::CaloHit *const pCaloHit, const HitAssociationMap &hitAssociationMapI, const HitAssociationMap &hitAssociationMapJ) const
Get hit to join by tracing associations via map I, checking via map J.
bool m_mergeBackFilteredHits
Merge rejected hits into their associated clusters.
void MakeSecondaryAssociations(const pandora::OrderedCaloHitList &orderedCaloHitList, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Control secondary association formation.
void CreateSecondaryAssociation(const pandora::CaloHit *const pCaloHitI, const pandora::CaloHit *const pCaloHitJ, HitAssociationMap &forwardHitAssociationMap, HitAssociationMap &backwardHitAssociationMap) const
Create secondary association if appropriate, hitI<->hitJ.
float m_minCaloHitSeparationSquared
Square of minimum calo hit separation.
float m_closeSeparationSquared
Length scale (squared) for close hit separation.
const pandora::CaloHit * TraceHitAssociation(const pandora::CaloHit *const pCaloHit, const HitAssociationMap &hitAssociationMapI, const HitAssociationMap &hitAssociationMapJ, unsigned int &nSteps) const
Get last hit obtained by tracing associations via map I, checking via map J.