All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PcaShowerParticleBuildingAlgorithm.cc
Go to the documentation of this file.
1 /**
2  * @file larpandoracontent/LArCustomParticles/PcaShowerParticleBuildingAlgorithm.cc
3  *
4  * @brief Implementation of the 3D shower building algorithm class.
5  *
6  * $Log: $
7  */
8 
9 #include "Pandora/AlgorithmHeaders.h"
10 
15 
18 
20 
21 using namespace pandora;
22 
23 namespace lar_content
24 {
25 
26 PcaShowerParticleBuildingAlgorithm::PcaShowerParticleBuildingAlgorithm() : m_layerFitHalfWindow(20)
27 {
28 }
29 
30 //------------------------------------------------------------------------------------------------------------------------------------------
31 
32 void PcaShowerParticleBuildingAlgorithm::CreatePfo(const ParticleFlowObject *const pInputPfo, const ParticleFlowObject *&pOutputPfo) const
33 {
34  try
35  {
36  // In cosmic mode, build showers from all daughter pfos, otherwise require that pfo is shower-like
38  {
39  if (!LArPfoHelper::IsShower(pInputPfo))
40  return;
41  }
42  else
43  {
44  if (LArPfoHelper::IsFinalState(pInputPfo))
45  return;
46 
47  if (LArPfoHelper::IsNeutrino(pInputPfo))
48  return;
49  }
50 
51  // Need an input vertex to provide a shower propagation direction
52  const Vertex *const pInputVertex = LArPfoHelper::GetVertex(pInputPfo);
53 
54  // Run the PCA analysis
55  const LArShowerPCA showerPCA(LArPfoHelper::GetPrincipalComponents(pInputPfo, pInputVertex));
56 
57  // Build a new pfo
58  LArShowerPfoFactory pfoFactory;
59  LArShowerPfoParameters pfoParameters;
60  pfoParameters.m_particleId = (LArPfoHelper::IsShower(pInputPfo) ? pInputPfo->GetParticleId() : E_MINUS);
61  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
62  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
63  pfoParameters.m_energy = 0.f;
64  pfoParameters.m_momentum = pInputPfo->GetMomentum();
65  pfoParameters.m_propertiesToAdd = pInputPfo->GetPropertiesMap();
66  pfoParameters.m_showerVertex = pInputVertex->GetPosition();
67  pfoParameters.m_showerCentroid = showerPCA.GetCentroid();
68  pfoParameters.m_showerDirection = showerPCA.GetPrimaryAxis();
69  pfoParameters.m_showerSecondaryVector = showerPCA.GetSecondaryAxis();
70  pfoParameters.m_showerTertiaryVector = showerPCA.GetTertiaryAxis();
71  pfoParameters.m_showerEigenValues = showerPCA.GetEigenValues();
72  pfoParameters.m_showerLength = showerPCA.GetAxisLengths();
73  pfoParameters.m_showerOpeningAngle =
74  (showerPCA.GetPrimaryLength() > 0.f ? std::atan(showerPCA.GetSecondaryLength() / showerPCA.GetPrimaryLength()) : 0.f);
75 
76  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pOutputPfo, pfoFactory));
77 
78  const LArShowerPfo *const pLArPfo = dynamic_cast<const LArShowerPfo *>(pOutputPfo);
79 
80  if (!pLArPfo)
81  throw StatusCodeException(STATUS_CODE_FAILURE);
82 
83  // Build a new vertex - TODO: tune vertex position based on PCA results
84  const Vertex *pOutputVertex = nullptr;
85 
87  vtxParameters.m_position = pInputVertex->GetPosition();
88  vtxParameters.m_vertexLabel = pInputVertex->GetVertexLabel();
89  vtxParameters.m_vertexType = pInputVertex->GetVertexType();
90 
91  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, vtxParameters, pOutputVertex));
92  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Vertex>(*this, pOutputPfo, pOutputVertex));
93  }
94  catch (StatusCodeException &statusCodeException)
95  {
96  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
97  throw statusCodeException;
98  }
99 }
100 
101 //------------------------------------------------------------------------------------------------------------------------------------------
102 
103 StatusCode PcaShowerParticleBuildingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
104 {
105  PANDORA_RETURN_RESULT_IF_AND_IF(
106  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "LayerFitHalfWindow", m_layerFitHalfWindow));
107 
109 }
110 
111 } // 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
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
fhicl::Table< sbnd::crt::CRTDetSimParams > Parameters
required by fuzzyCluster table::sbnd_g4_services gaushitTruthMatch pandora
Definition: reco_sbnd.fcl:182
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.
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.