9 #include "Pandora/AlgorithmHeaders.h" 22 CosmicRayVertexBuildingAlgorithm::CosmicRayVertexBuildingAlgorithm() :
23 m_useParentShowerVertex(false),
24 m_halfWindowLayers(30)
32 const PfoList *pPfoList = NULL;
33 PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_parentPfoListName,
38 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
39 std::cout <<
"CosmicRayVertexBuildingAlgorithm: pfo list unavailable." << std::endl;
41 return STATUS_CODE_SUCCESS;
51 return STATUS_CODE_SUCCESS;
63 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
68 for (
PfoList::const_iterator pIter = outputList.begin(), pIterEnd = outputList.end(); pIter != pIterEnd; ++pIter)
70 ClusterList clusterList;
73 if (clusterList.empty())
76 pfoVector.push_back(*pIter);
88 const ParticleFlowObject *
const pPfo = *pIter;
93 ClusterList clusterList;
98 const Cluster *
const pCluster = *cIter;
104 if (!pointingClusterMap.insert(LArPointingClusterMap::value_type(pCluster, pointingCluster)).second)
105 throw StatusCodeException(STATUS_CODE_FAILURE);
107 catch (StatusCodeException &statusCodeException)
109 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
110 throw statusCodeException;
122 const ParticleFlowObject *
const pPfo = *iter;
139 ClusterList clusterList;
142 if (clusterList.empty())
146 bool foundVtx(
false);
147 CartesianVector vtxPosition(0.
f, 0.
f, 0.
f);
148 CartesianVector vtxDirection(0.
f, 0.
f, 0.
f);
150 bool foundEnd(
false);
151 CartesianVector endPosition(0.
f, 0.
f, 0.
f);
152 CartesianVector endDirection(0.
f, 0.
f, 0.
f);
156 const Cluster *
const pCluster = *cIter1;
160 CartesianVector minPosition(0.
f, 0.
f, 0.
f), maxPosition(0.
f,0.
f,0.
f);
161 CartesianVector minDirection(0.
f, 0.
f, 0.
f), maxDirection(0.
f,0.
f,0.
f);
165 if (pointingClusterMap.end() != cIter2)
177 minDirection = (maxPosition - minPosition).GetUnitVector();
178 maxDirection = (minPosition - maxPosition).GetUnitVector();
181 if ((maxPosition - minPosition).GetMagnitudeSquared() < std::numeric_limits<float>::epsilon())
182 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
184 if (!foundVtx || (minPosition.GetY() >
std::max(maxPosition.GetY(), vtxPosition.GetY())))
187 vtxPosition = minPosition;
188 vtxDirection = minDirection;
191 if (!foundVtx || (maxPosition.GetY() >
std::max(minPosition.GetY(), vtxPosition.GetY())))
194 vtxPosition = maxPosition;
195 vtxDirection = maxDirection;
198 if (!foundEnd || (minPosition.GetY() <
std::min(maxPosition.GetY(), endPosition.GetY())))
201 endPosition = minPosition;
202 endDirection = minDirection;
205 if (!foundEnd || (maxPosition.GetY() <
std::min(minPosition.GetY(), endPosition.GetY())))
208 endPosition = maxPosition;
209 endDirection = maxDirection;
212 catch(StatusCodeException &statusCodeException)
214 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
215 throw statusCodeException;
221 if (!(foundVtx && foundEnd))
231 if (pDaughterPfo->GetParentPfoList().size() != 1)
232 throw StatusCodeException(STATUS_CODE_FAILURE);
234 const ParticleFlowObject *
const pParentPfo = *(pDaughterPfo->GetParentPfoList().begin());
236 ClusterList parentList, daughterList;
240 if (daughterList.empty() || parentList.empty())
243 bool foundVtx(
false);
244 float vtxDistanceSquared(0.
f);
245 CartesianVector vtxPosition(0.
f, 0.
f, 0.
f);
249 const Cluster *
const pDaughterCluster = *dIter;
253 const Cluster *
const pParentCluster = *pIter;
255 CartesianVector closestDaughterPosition(0.
f, 0.
f, 0.
f), closestParentPosition(0.
f, 0.
f, 0.
f);
258 const float closestDistanceSquared((closestDaughterPosition - closestParentPosition).GetMagnitudeSquared());
260 if (!foundVtx || closestDistanceSquared < vtxDistanceSquared)
263 vtxDistanceSquared = closestDistanceSquared;
278 const ParticleFlowObject *
const pPfo)
const 280 if (!pPfo->GetVertexList().empty())
281 throw StatusCodeException(STATUS_CODE_FAILURE);
283 PandoraContentApi::ParticleFlowObject::Metadata metadata;
284 metadata.m_momentum = vtxDirection;
285 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
287 const VertexList *pVertexList = NULL; std::string vertexListName;
288 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*
this, pVertexList, vertexListName));
290 PandoraContentApi::Vertex::Parameters parameters;
291 parameters.m_position = vtxPosition;
292 parameters.m_vertexLabel = VERTEX_START;
293 parameters.m_vertexType = VERTEX_3D;
295 const Vertex *pVertex(NULL);
296 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*
this, parameters, pVertex));
298 if (!pVertexList->empty())
300 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*
this,
m_vertexListName));
301 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Vertex>(*
this, pPfo, pVertex));
309 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"InputPfoListName",
m_parentPfoListName));
311 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"OutputVertexListName",
m_vertexListName));
313 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
316 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
319 return STATUS_CODE_SUCCESS;
Header file for the pfo helper class.
bool m_useParentShowerVertex
use the parent pfo for the shower vertices
static void GetClusters(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::ClusterList &clusterList)
Get a list of clusters of a particular hit type from a list of pfos.
void SetParticleParameters(const pandora::CartesianVector &vtxPosition, const pandora::CartesianVector &vtxDirection, const pandora::ParticleFlowObject *const pPfo) const
Set the vertex and direction of the Pfos.
LArPointingCluster class.
static void GetClosestPositions(const pandora::Cluster *const pCluster1, const pandora::Cluster *const pCluster2, pandora::CartesianVector &position1, pandora::CartesianVector &position2)
Get pair of closest positions for a pair of clusters.
std::string m_vertexListName
The name of the output vertex list.
Header file for the cosmic-ray vertex building algorithm class.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
static float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
void BuildCosmicRayParent(const LArPointingClusterMap &pointingClusterMap, const pandora::ParticleFlowObject *const pPfo) const
Reconstruct the vertex and direction of a parent cosmic-ray Pfo.
Header file for the geometry helper class.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
void BuildCosmicRayParticles(const LArPointingClusterMap &pointingClusterMap, const pandora::PfoVector &pfoVector) const
Reconstruct the vertex and direction of a list of cosmic-ray Pfos.
pandora::StatusCode Run()
Header file for the cluster helper class.
const Vertex & GetOuterVertex() const
Get the outer vertex.
const Vertex & GetInnerVertex() const
Get the inner vertex.
std::string m_parentPfoListName
The name of the input pfo list.
std::unordered_map< const pandora::Cluster *, LArPointingCluster > LArPointingClusterMap
const pandora::CartesianVector & GetDirection() const
Get the vertex direction.
unsigned int m_halfWindowLayers
number of layers to use for half-window of sliding fit
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 bool IsFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a primary parent particle.
static void GetAllDownstreamPfos(const pandora::PfoList &inputPfoList, pandora::PfoList &outputPfoList)
Get a flat list of all pfos, recursively, of all daughters associated with those pfos in an input lis...
void GetCosmicPfos(const pandora::PfoList *const pPfoList, pandora::PfoVector &pfoVector) const
Get the list of input pfos to this algorithm.
void BuildCosmicRayDaughter(const pandora::ParticleFlowObject *const pPfo) const
Reconstruct the vertex and direction of a daughter cosmic-ray Pfo.
void BuildPointingClusterMap(const pandora::PfoVector &pfoVector, LArPointingClusterMap &pointingClusterMap) const
Build a map of 3D sliding fits from the input Pfos.
std::list< Vertex > VertexList
const pandora::CartesianVector & GetPosition() const
Get the vertex position.