9 #include "Pandora/AlgorithmHeaders.h" 22 NeutrinoDaughterVerticesAlgorithm::NeutrinoDaughterVerticesAlgorithm() : m_useParentShowerVertex(false), m_halfWindowLayers(20)
30 const PfoList *pPfoList = NULL;
31 PANDORA_THROW_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_INITIALIZED, !=, PandoraContentApi::GetList(*
this,
m_neutrinoListName, pPfoList));
33 if (!pPfoList || pPfoList->empty())
35 if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
38 return STATUS_CODE_SUCCESS;
48 return STATUS_CODE_SUCCESS;
60 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
65 for (
PfoList::const_iterator pIter = outputList.begin(), pIterEnd = outputList.end(); pIter != pIterEnd; ++pIter)
67 ClusterList clusterList;
70 if (clusterList.empty())
73 pfoVector.push_back(*pIter);
85 const ParticleFlowObject *
const pPfo = *pIter;
90 ClusterList clusterList;
95 const Cluster *
const pCluster = *cIter;
101 if (!pointingClusterMap.insert(LArPointingClusterMap::value_type(pCluster, pointingCluster)).second)
102 throw StatusCodeException(STATUS_CODE_FAILURE);
104 catch (StatusCodeException &statusCodeException)
106 if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
107 throw statusCodeException;
119 const ParticleFlowObject *
const pPfo = *iter;
136 if (pDaughterPfo->GetParentPfoList().size() != 1)
137 throw StatusCodeException(STATUS_CODE_FAILURE);
139 const ParticleFlowObject *
const pParentPfo = *(pDaughterPfo->GetParentPfoList().begin());
141 ClusterList parentList, daughterList;
145 if (parentList.empty() && pParentPfo->GetVertexList().empty())
148 bool foundVtx(
false);
149 float vtxDistance(0.
f);
150 CartesianVector vtxPosition(0.
f, 0.
f, 0.
f);
151 CartesianVector vtxDirection(0.
f, 0.
f, 0.
f);
155 const Cluster *
const pDaughterCluster = *dIter;
157 CartesianVector minPosition(0.
f, 0.
f, 0.
f), maxPosition(0.
f, 0.
f, 0.
f);
158 CartesianVector minDirection(0.
f, 0.
f, 0.
f), maxDirection(0.
f, 0.
f, 0.
f);
159 bool foundDirection(
false);
163 if (pointingClusterMap.end() != cIter)
171 foundDirection =
true;
178 if ((maxPosition - minPosition).GetMagnitudeSquared() < std::numeric_limits<float>::epsilon())
183 minDirection = (maxPosition - minPosition).GetUnitVector();
184 maxDirection = (minPosition - maxPosition).GetUnitVector();
192 const Cluster *
const pParentCluster = *pIter;
199 const Vertex *
const pVertex = *(pParentPfo->GetVertexList().begin());
200 minDistance =
std::min(minDistance, (pVertex->GetPosition() - minPosition).GetMagnitude());
201 maxDistance =
std::min(maxDistance, (pVertex->GetPosition() - maxPosition).GetMagnitude());
204 if (!foundVtx || (minDistance < vtxDistance))
207 vtxDistance = minDistance;
208 vtxPosition = minPosition;
209 vtxDirection = minDirection;
212 if (!foundVtx || (maxDistance < vtxDistance))
215 vtxDistance = maxDistance;
216 vtxPosition = maxPosition;
217 vtxDirection = maxDirection;
231 if (pDaughterPfo->GetParentPfoList().size() != 1)
232 throw StatusCodeException(STATUS_CODE_FAILURE);
234 const ParticleFlowObject *
const pParentPfo = *(pDaughterPfo->GetParentPfoList().begin());
237 throw StatusCodeException(STATUS_CODE_FAILURE);
239 ClusterList parentList, daughterList;
243 if (daughterList.empty())
248 const Vertex *
const pVertex = *(pParentPfo->GetVertexList().begin());
249 const CartesianVector vtxPosition(
255 if (parentList.empty())
258 bool foundVtx(
false);
259 float vtxDistanceSquared(0.
f);
260 CartesianVector vtxPosition(0.
f, 0.
f, 0.
f);
264 const Cluster *
const pDaughterCluster = *dIter;
268 const Cluster *
const pParentCluster = *pIter;
270 CartesianVector closestDaughterPosition(0.
f, 0.
f, 0.
f), closestParentPosition(0.
f, 0.
f, 0.
f);
273 const float closestDistanceSquared((closestDaughterPosition - closestParentPosition).GetMagnitudeSquared());
275 if (!foundVtx || closestDistanceSquared < vtxDistanceSquared)
278 vtxDistanceSquared = closestDistanceSquared;
293 const CartesianVector &vtxPosition,
const CartesianVector &vtxDirection,
const ParticleFlowObject *
const pPfo)
const 295 if (!pPfo->GetVertexList().empty())
296 throw StatusCodeException(STATUS_CODE_FAILURE);
298 PandoraContentApi::ParticleFlowObject::Metadata
metadata;
299 metadata.m_momentum = vtxDirection;
300 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*
this, pPfo, metadata));
304 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*
this, pVertexList, vertexListName));
306 PandoraContentApi::Vertex::Parameters parameters;
307 parameters.m_position = vtxPosition;
308 parameters.m_vertexLabel = VERTEX_INTERACTION;
309 parameters.m_vertexType = VERTEX_3D;
311 const Vertex *pVertex(NULL);
312 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*
this, parameters, pVertex));
314 if (!pVertexList->empty())
316 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*
this,
m_vertexListName));
317 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Vertex>(*
this, pPfo, pVertex));
325 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"NeutrinoPfoListName",
m_neutrinoListName));
327 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
"OutputVertexListName",
m_vertexListName));
329 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=,
332 PANDORA_RETURN_RESULT_IF_AND_IF(
333 STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
"SlidingFitHalfWindow",
m_halfWindowLayers));
335 return STATUS_CODE_SUCCESS;
unsigned int m_halfWindowLayers
number of layers to use for half-window of sliding fit
std::unordered_map< const pandora::Cluster *, LArPointingCluster > LArPointingClusterMap
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 int max(int a, int b)
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
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) ...
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
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.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
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.
QTextStream & endl(QTextStream &s)
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.