23 m_useParentShowerVertex(false),
25 m_halfWindowLayers(30),
26 m_maxVertexDisplacementFromTrack(1.f)
41 std::cout <<
"CosmicRayVertexBuildingAlgorithm: pfo list unavailable." << std::endl;
43 return STATUS_CODE_SUCCESS;
53 return STATUS_CODE_SUCCESS;
62 for (PfoList::const_iterator pIter = pPfoList->begin(), pIterEnd = pPfoList->end(); pIter != pIterEnd; ++pIter)
70 for (PfoList::const_iterator pIter = outputList.begin(), pIterEnd = outputList.end(); pIter != pIterEnd; ++pIter)
75 if (clusterList.empty())
78 pfoVector.push_back(*pIter);
88 for (PfoVector::const_iterator pIter = pfoVector.begin(), pIterEnd = pfoVector.end(); pIter != pIterEnd; ++pIter)
98 for (ClusterList::const_iterator cIter = clusterList.begin(), cIterEnd = clusterList.end(); cIter != cIterEnd; ++cIter)
100 const Cluster *
const pCluster = *cIter;
106 if (!pointingClusterMap.insert(LArPointingClusterMap::value_type(pCluster, pointingCluster)).second)
111 if (STATUS_CODE_FAILURE == statusCodeException.
GetStatusCode())
112 throw statusCodeException;
122 for (PfoVector::const_iterator iter = pfoVector.begin(), iterEnd = pfoVector.end(); iter != iterEnd; ++iter)
144 if (clusterList.empty())
148 bool foundVtx(
false);
152 bool foundEnd(
false);
156 for (ClusterList::const_iterator cIter1 = clusterList.begin(), cIterEnd1 = clusterList.end(); cIter1 != cIterEnd1; ++cIter1)
158 const Cluster *
const pCluster = *cIter1;
162 CartesianVector minPosition(0.f, 0.f, 0.f), maxPosition(0.f, 0.f, 0.f);
163 CartesianVector minDirection(0.f, 0.f, 0.f), maxDirection(0.f, 0.f, 0.f);
165 LArPointingClusterMap::const_iterator cIter2 = pointingClusterMap.find(pCluster);
167 if (pointingClusterMap.end() != cIter2)
179 minDirection = (maxPosition - minPosition).GetUnitVector();
180 maxDirection = (minPosition - maxPosition).GetUnitVector();
183 if ((maxPosition - minPosition).GetMagnitudeSquared() < std::numeric_limits<float>::epsilon())
187 const float minVerticalCoordinate(
m_isDualPhase ? minPosition.GetX() : minPosition.GetY());
190 if (!foundVtx || (minVerticalCoordinate > std::max(maxVerticalCoordinate,
m_isDualPhase ? vtxPosition.
GetX() : vtxPosition.
GetY())))
193 vtxPosition = minPosition;
194 vtxDirection = minDirection;
197 if (!foundVtx || (maxVerticalCoordinate > std::max(minVerticalCoordinate,
m_isDualPhase ? vtxPosition.
GetX() : vtxPosition.
GetY())))
200 vtxPosition = maxPosition;
201 vtxDirection = maxDirection;
204 if (!foundEnd || (minVerticalCoordinate < std::min(maxVerticalCoordinate,
m_isDualPhase ? endPosition.
GetX() : endPosition.
GetY())))
207 endPosition = minPosition;
208 endDirection = minDirection;
211 if (!foundEnd || (maxVerticalCoordinate < std::min(minVerticalCoordinate,
m_isDualPhase ? endPosition.
GetX() : endPosition.
GetY())))
214 endPosition = maxPosition;
215 endDirection = maxDirection;
220 if (STATUS_CODE_FAILURE == statusCodeException.
GetStatusCode())
221 throw statusCodeException;
227 if (!(foundVtx && foundEnd))
246 if (daughterList.empty() || parentList.empty())
250 float closestMaxVerticalCoordinate(-std::numeric_limits<float>::max()), maxVerticalCoordinate(-std::numeric_limits<float>::max());
251 CartesianVector closestMaxVerticalVertex(0.f, 0.f, 0.f), maxVerticalVertex(0.f, 0.f, 0.f);
253 for (
const Cluster *
const pDaughterCluster : daughterList)
256 pDaughterCluster->GetOrderedCaloHitList().FillCaloHitList(daughterCaloHitList);
258 for (
const Cluster *
const pParentCluster : parentList)
261 pParentCluster->GetOrderedCaloHitList().FillCaloHitList(parentCaloHitList);
263 for (
const CaloHit *
const pDaughterCaloHit : daughterCaloHitList)
265 const CartesianVector &daughterPosition(pDaughterCaloHit->GetPositionVector());
267 for (
const CaloHit *
const pParentCaloHit : parentCaloHitList)
269 const CartesianVector &parentPosition(pParentCaloHit->GetPositionVector());
270 const float separationSquared((daughterPosition - parentPosition).GetMagnitudeSquared());
273 if (verticalCoordinate > maxVerticalCoordinate)
275 maxVerticalCoordinate = verticalCoordinate;
276 maxVerticalVertex = daughterPosition;
281 if (verticalCoordinate > closestMaxVerticalCoordinate)
284 closestMaxVerticalCoordinate = verticalCoordinate;
285 closestMaxVerticalVertex = daughterPosition;
293 const CartesianVector &daughterVertex(found ? closestMaxVerticalVertex : maxVerticalVertex);
307 PandoraContentApi::ParticleFlowObject::Metadata metadata;
308 metadata.m_momentum = vtxDirection;
312 std::string vertexListName;
315 PandoraContentApi::Vertex::Parameters parameters;
316 parameters.m_position = vtxPosition;
320 const Vertex *pVertex(NULL);
321 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*
this, parameters, pVertex));
323 if (!pVertexList->empty())
349 return STATUS_CODE_SUCCESS;
Header file for the cosmic-ray vertex building algorithm class.
Header file for the cluster helper class.
Header file for the geometry helper class.
Header file for the pfo helper class.
#define PANDORA_THROW_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
static pandora::StatusCode ReplaceCurrentList(const pandora::Algorithm &algorithm, const std::string &newListName)
Replace the current list with a pre-saved list; use this new list as a permanent replacement for the ...
static pandora::StatusCode CreateTemporaryListAndSetCurrent(const pandora::Algorithm &algorithm, const T *&pT, std::string &temporaryListName)
Create a temporary list and set it to be the current list, enabling object creation.
static pandora::StatusCode GetList(const pandora::Algorithm &algorithm, const std::string &listName, const T *&pT)
Get a named list.
static const pandora::PandoraSettings * GetSettings(const pandora::Algorithm &algorithm)
Get the pandora settings instance.
bool m_useParentShowerVertex
use the parent pfo for the shower vertices
std::string m_vertexListName
The name of the output vertex list.
void BuildCosmicRayParticles(const LArPointingClusterMap &pointingClusterMap, const pandora::PfoVector &pfoVector) const
Reconstruct the vertex and direction of a list of cosmic-ray Pfos.
bool m_isDualPhase
type of geometry
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
float m_maxVertexDisplacementFromTrack
The maximum separation of a close vertex from the cosmic ray track.
unsigned int m_halfWindowLayers
number of layers to use for half-window of sliding fit
void SetParticleParameters(const pandora::CartesianVector &vtxPosition, const pandora::CartesianVector &vtxDirection, const pandora::ParticleFlowObject *const pPfo) const
Set the vertex and direction of the Pfos.
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.
CosmicRayVertexBuildingAlgorithm()
Default constructor.
std::string m_parentPfoListName
The name of the input pfo list.
pandora::StatusCode Run()
Run the algorithm.
void BuildCosmicRayParent(const LArPointingClusterMap &pointingClusterMap, const pandora::ParticleFlowObject *const pPfo) const
Reconstruct the vertex and direction of a parent cosmic-ray Pfo.
void BuildPointingClusterMap(const pandora::PfoVector &pfoVector, LArPointingClusterMap &pointingClusterMap) const
Build a map of 3D sliding fits from the input Pfos.
static pandora::CartesianVector GetClosestPosition(const pandora::CartesianVector &position, const pandora::ClusterList &clusterList)
Get closest position in a list of clusters to a specified input position vector.
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 float GetWireZPitch(const pandora::Pandora &pandora, const float maxWirePitchDiscrepancy=0.01)
Return the wire pitch.
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...
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
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.
const pandora::CartesianVector & GetDirection() const
Get the vertex direction.
const pandora::CartesianVector & GetPosition() const
Get the vertex position.
LArPointingCluster class.
const Vertex & GetInnerVertex() const
Get the inner vertex.
const Vertex & GetOuterVertex() const
Get the outer vertex.
float GetX() const
Get the cartesian x coordinate.
float GetY() const
Get the cartesian y coordinate.
bool ShouldDisplayAlgorithmInfo() const
Whether to display algorithm information during processing.
ParticleFlowObject class.
const PfoList & GetParentPfoList() const
Get the parent pfo list.
const VertexList & GetVertexList() const
Get the vertex list.
StatusCode AlterMetadata(const object_creation::ParticleFlowObject::Metadata &metadata)
Alter particle flow object metadata parameters.
const Pandora & GetPandora() const
Get the associated pandora instance.
StatusCodeException class.
StatusCode GetStatusCode() const
Get status code.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
std::unordered_map< const pandora::Cluster *, LArPointingCluster > LArPointingClusterMap
MANAGED_CONTAINER< const Cluster * > ClusterList
std::vector< const ParticleFlowObject * > PfoVector
MANAGED_CONTAINER< const CaloHit * > CaloHitList
MANAGED_CONTAINER< const Vertex * > VertexList
StatusCode
The StatusCode enum.
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList