LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PcaShowerParticleBuildingAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
15 
18 
20 
21 using namespace pandora;
22 
23 namespace lar_content
24 {
25 
26 PcaShowerParticleBuildingAlgorithm::PcaShowerParticleBuildingAlgorithm() :
27  m_layerFitHalfWindow(20)
28 {
29 }
30 
31 //------------------------------------------------------------------------------------------------------------------------------------------
32 
33 void PcaShowerParticleBuildingAlgorithm::CreatePfo(const ParticleFlowObject *const pInputPfo, const ParticleFlowObject *&pOutputPfo) const
34 {
35  try
36  {
37  // In cosmic mode, build showers from all daughter pfos, otherwise require that pfo is shower-like
39  {
40  if (!LArPfoHelper::IsShower(pInputPfo))
41  return;
42  }
43  else
44  {
45  if (LArPfoHelper::IsFinalState(pInputPfo))
46  return;
47 
48  if (LArPfoHelper::IsNeutrino(pInputPfo))
49  return;
50  }
51 
52  // Need an input vertex to provide a shower propagation direction
53  const Vertex *const pInputVertex = LArPfoHelper::GetVertex(pInputPfo);
54 
55  // Run the PCA analysis
56  const LArShowerPCA showerPCA(LArPfoHelper::GetPrincipalComponents(pInputPfo, pInputVertex));
57 
58  // Build a new pfo
59  LArShowerPfoFactory pfoFactory;
60  LArShowerPfoParameters pfoParameters;
61  pfoParameters.m_particleId = (LArPfoHelper::IsShower(pInputPfo) ? pInputPfo->GetParticleId() : E_MINUS);
62  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
63  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
64  pfoParameters.m_energy = 0.f;
65  pfoParameters.m_momentum = pInputPfo->GetMomentum();
66  pfoParameters.m_propertiesToAdd = pInputPfo->GetPropertiesMap();
67  pfoParameters.m_showerVertex = pInputVertex->GetPosition();
68  pfoParameters.m_showerCentroid = showerPCA.GetCentroid();
69  pfoParameters.m_showerDirection = showerPCA.GetPrimaryAxis();
70  pfoParameters.m_showerSecondaryVector = showerPCA.GetSecondaryAxis();
71  pfoParameters.m_showerTertiaryVector = showerPCA.GetTertiaryAxis();
72  pfoParameters.m_showerEigenValues = showerPCA.GetEigenValues();
73  pfoParameters.m_showerLength = showerPCA.GetAxisLengths();
74  pfoParameters.m_showerOpeningAngle =
75  (showerPCA.GetPrimaryLength() > 0.f ? std::atan(showerPCA.GetSecondaryLength() / showerPCA.GetPrimaryLength()) : 0.f);
76 
77  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pOutputPfo, pfoFactory));
78 
79  const LArShowerPfo *const pLArPfo = dynamic_cast<const LArShowerPfo *>(pOutputPfo);
80 
81  if (!pLArPfo)
82  throw StatusCodeException(STATUS_CODE_FAILURE);
83 
84  // Build a new vertex - TODO: tune vertex position based on PCA results
85  const Vertex *pOutputVertex = nullptr;
86 
87  PandoraContentApi::Vertex::Parameters vtxParameters;
88  vtxParameters.m_position = pInputVertex->GetPosition();
89  vtxParameters.m_vertexLabel = pInputVertex->GetVertexLabel();
90  vtxParameters.m_vertexType = pInputVertex->GetVertexType();
91 
92  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, vtxParameters, pOutputVertex));
93  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Vertex>(*this, pOutputPfo, pOutputVertex));
94  }
95  catch (StatusCodeException &statusCodeException)
96  {
97  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
98  throw statusCodeException;
99  }
100 }
101 
102 //------------------------------------------------------------------------------------------------------------------------------------------
103 
104 StatusCode PcaShowerParticleBuildingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
105 {
106  PANDORA_RETURN_RESULT_IF_AND_IF(
107  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "LayerFitHalfWindow", m_layerFitHalfWindow));
108 
110 }
111 
112 } // namespace lar_content
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static LArShowerPCA GetPrincipalComponents(const pandora::CartesianPointVector &pointVector, const pandora::CartesianVector &vertexPosition)
Perform PCA analysis on a set of 3D points and return results.
Header file for the pfo helper class.
pandora::InputFloat m_showerOpeningAngle
Shower opening angle.
Definition: LArShowerPfo.h:29
const pandora::CartesianVector & GetCentroid() const
Return centroid.
pandora::InputCartesianVector m_showerCentroid
Shower centroid from 3d shower fit.
Definition: LArShowerPfo.h:28
pandora::InputCartesianVector m_showerTertiaryVector
Shower teriary eigen vector.
Definition: LArShowerPfo.h:32
float GetPrimaryLength() const
Return primary length.
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
Header file for the principal curve analysis helper class.
pandora::InputCartesianVector m_showerVertex
Shower starting point.
Definition: LArShowerPfo.h:34
TFile f
Definition: plotHisto.C:6
Header file for the geometry helper class.
pandora::InputCartesianVector m_showerDirection
Shower direction, also the primary eigen vector.
Definition: LArShowerPfo.h:30
static bool IsShower(const pandora::ParticleFlowObject *const pPfo)
Return shower flag based on Pfo Particle ID.
lar pfo object factory responsible for pfo creation
Definition: LArShowerPfo.h:124
const pandora::CartesianVector & GetEigenValues() const
Return vector of eigenvalues.
Header file for the cluster helper class.
pandora::InputCartesianVector m_showerEigenValues
Shower eigenvalues from 3d PCA.
Definition: LArShowerPfo.h:33
Header file for the lar pfo class.
const pandora::CartesianVector & GetAxisLengths() const
Return vector of lengths.
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
Header file for the lar three dimensional sliding fit result class.
pandora::InputCartesianVector m_showerLength
Shower length and widths from 3d shower fit.
Definition: LArShowerPfo.h:27
static bool IsFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a primary parent particle.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
pandora::InputCartesianVector m_showerSecondaryVector
Shower secondary eigen vector.
Definition: LArShowerPfo.h:31
static bool IsNeutrinoFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a neutrino (or antineutrino) interaction.
const pandora::CartesianVector & GetSecondaryAxis() const
Return secondary axis.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
const pandora::CartesianVector & GetTertiaryAxis() const
Return tertiary axis.
LArShowerPCA class.
float GetSecondaryLength() const
Return secondary length.
void CreatePfo(const pandora::ParticleFlowObject *const pInputPfo, const pandora::ParticleFlowObject *&pOutputPfo) const
Create specialised Pfo from an generic input Pfo.
Header file for the neutrino event creation algorithm class.
const pandora::CartesianVector & GetPrimaryAxis() const
Return primary axis.