9 #include "Pandora/AlgorithmHeaders.h" 22 NeutrinoDaughterVerticesAlgorithm::NeutrinoDaughterVerticesAlgorithm() :
23 m_useParentShowerVertex(false),
24 m_halfWindowLayers(20)
32 const PfoList *pPfoList = NULL;
33 PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_neutrinoListName,
36 if (!pPfoList || pPfoList->empty())
38 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
39 std::cout <<
"NeutrinoDaughterVerticesAlgorithm: unable to find pfo list " <<
m_neutrinoListName << 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 if (pDaughterPfo->GetParentPfoList().size() != 1)
140 throw StatusCodeException(STATUS_CODE_FAILURE);
142 const ParticleFlowObject *
const pParentPfo = *(pDaughterPfo->GetParentPfoList().begin());
144 ClusterList parentList, daughterList;
148 if (parentList.empty() && pParentPfo->GetVertexList().empty())
151 bool foundVtx(
false);
152 float vtxDistance(0.
f);
153 CartesianVector vtxPosition(0.
f, 0.
f, 0.
f);
154 CartesianVector vtxDirection(0.
f, 0.
f, 0.
f);
158 const Cluster *
const pDaughterCluster = *dIter;
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);
162 bool foundDirection(
false);
166 if (pointingClusterMap.end() != cIter)
174 foundDirection =
true;
181 if ((maxPosition - minPosition).GetMagnitudeSquared() < std::numeric_limits<float>::epsilon())
186 minDirection = (maxPosition - minPosition).GetUnitVector();
187 maxDirection = (minPosition - maxPosition).GetUnitVector();
195 const Cluster *
const pParentCluster = *pIter;
202 const Vertex *
const pVertex = *(pParentPfo->GetVertexList().begin());
203 minDistance =
std::min(minDistance, (pVertex->GetPosition() - minPosition).GetMagnitude());
204 maxDistance =
std::min(maxDistance, (pVertex->GetPosition() - maxPosition).GetMagnitude());
207 if (!foundVtx || (minDistance < vtxDistance))
210 vtxDistance = minDistance;
211 vtxPosition = minPosition;
212 vtxDirection = minDirection;
215 if (!foundVtx || (maxDistance < vtxDistance))
218 vtxDistance = maxDistance;
219 vtxPosition = maxPosition;
220 vtxDirection = maxDirection;
234 if (pDaughterPfo->GetParentPfoList().size() != 1)
235 throw StatusCodeException(STATUS_CODE_FAILURE);
237 const ParticleFlowObject *
const pParentPfo = *(pDaughterPfo->GetParentPfoList().begin());
240 throw StatusCodeException(STATUS_CODE_FAILURE);
242 ClusterList parentList, daughterList;
246 if (daughterList.empty())
251 const Vertex *
const pVertex = *(pParentPfo->GetVertexList().begin());
258 if (parentList.empty())
261 bool foundVtx(
false);
262 float vtxDistanceSquared(0.
f);
263 CartesianVector vtxPosition(0.
f, 0.
f, 0.
f);
267 const Cluster *
const pDaughterCluster = *dIter;
271 const Cluster *
const pParentCluster = *pIter;
273 CartesianVector closestDaughterPosition(0.
f, 0.
f, 0.
f), closestParentPosition(0.
f, 0.
f, 0.
f);
276 const float closestDistanceSquared((closestDaughterPosition - closestParentPosition).GetMagnitudeSquared());
278 if (!foundVtx || closestDistanceSquared < vtxDistanceSquared)
281 vtxDistanceSquared = closestDistanceSquared;
296 const ParticleFlowObject *
const pPfo)
const 298 if (!pPfo->GetVertexList().empty())
299 throw StatusCodeException(STATUS_CODE_FAILURE);
301 PandoraContentApi::ParticleFlowObject::Metadata metadata;
302 metadata.m_momentum = vtxDirection;
303 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
305 const VertexList *pVertexList = NULL; std::string vertexListName;
306 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*
this, pVertexList, vertexListName));
308 PandoraContentApi::Vertex::Parameters parameters;
309 parameters.m_position = vtxPosition;
310 parameters.m_vertexLabel = VERTEX_INTERACTION;
311 parameters.m_vertexType = VERTEX_3D;
313 const Vertex *pVertex(NULL);
314 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*
this, parameters, pVertex));
316 if (!pVertexList->empty())
318 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*
this,
m_vertexListName));
319 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Vertex>(*
this, pPfo, pVertex));
327 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
330 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
333 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
336 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
339 return STATUS_CODE_SUCCESS;
unsigned int m_halfWindowLayers
number of layers to use for half-window of sliding fit
std::string m_vertexListName
The name of the output cosmic-ray vertex list.
Header file for the pfo helper class.
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.
Header file for the neutrino daughter vertices algorithm class.
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.
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.
Header file for the geometry helper class.
void GetDaughterPfos(const pandora::PfoList *const pfoList, pandora::PfoVector &pfoVector) const
Get the vector of daughter pfos.
Header file for the cluster helper class.
const Vertex & GetOuterVertex() const
Get the outer vertex.
const Vertex & GetInnerVertex() const
Get the inner vertex.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
std::unordered_map< const pandora::Cluster *, LArPointingCluster > LArPointingClusterMap
const pandora::CartesianVector & GetDirection() const
Get the vertex direction.
bool m_useParentShowerVertex
use the parent pfo for the shower vertices
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) ...
void SetParticleParameters(const pandora::CartesianVector &vtxPosition, const pandora::CartesianVector &vtxDirection, const pandora::ParticleFlowObject *const pPfo) const
Set the vertex and direction of the Pfos.
pandora::StatusCode Run()
void BuildDaughterShower(const pandora::ParticleFlowObject *const pDaughterPfo) const
Reconstruct the vertex and direction of a shower-like Pfos.
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 BuildDaughterParticles(const LArPointingClusterMap &pointingClusterMap, const pandora::PfoVector &pfoVector) const
Reconstruct the vertex and direction of daughter Pfos.
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.
std::string m_neutrinoListName
The input list of pfo list names.
std::list< Vertex > VertexList
const pandora::CartesianVector & GetPosition() const
Get the vertex position.
void BuildDaughterTrack(const LArPointingClusterMap &pointingClusterMap, const pandora::ParticleFlowObject *const pDaughterPfo) const
Reconstruct the vertex and direction of a track-like Pfos.
static float GetClosestDistance(const pandora::ClusterList &clusterList1, const pandora::ClusterList &clusterList2)
Get closest distance between clusters in a pair of cluster lists.