LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackParticleBuildingAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
11 #include "Managers/GeometryManager.h"
12 
15 
17 
19 
20 using namespace pandora;
21 
22 namespace lar_content
23 {
24 
25 TrackParticleBuildingAlgorithm::TrackParticleBuildingAlgorithm() :
26  m_slidingFitHalfWindow(20)
27 {
28 }
29 
30 //------------------------------------------------------------------------------------------------------------------------------------------
31 
32 void TrackParticleBuildingAlgorithm::CreatePfo(const ParticleFlowObject *const pInputPfo, const ParticleFlowObject *&pOutputPfo) const
33 {
34  try
35  {
36  // Need an input vertex to provide a track propagation direction
37  const Vertex *const pInputVertex = LArPfoHelper::GetVertex(pInputPfo);
38 
39  // In cosmic mode, build tracks from all parent pfos, otherwise require that pfo is track-like
41  {
42  if (!LArPfoHelper::IsTrack(pInputPfo))
43  return;
44  }
45  else
46  {
47  if (!LArPfoHelper::IsFinalState(pInputPfo))
48  return;
49 
50  if (LArPfoHelper::IsNeutrino(pInputPfo))
51  return;
52  }
53 
54  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
55  const LArTPC *const pFirstLArTPC(this->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
56  const float layerPitch(pFirstLArTPC->GetWirePitchW());
57 
58  // Calculate sliding fit trajectory
59  LArTrackStateVector trackStateVector;
60  LArPfoHelper::GetSlidingFitTrajectory(pInputPfo, pInputVertex, m_slidingFitHalfWindow, layerPitch, trackStateVector);
61 
62  if (trackStateVector.empty())
63  return;
64 
65  // Build track-like pfo from track trajectory (TODO Correct these placeholder parameters)
66  LArTrackPfoFactory trackFactory;
67  LArTrackPfoParameters pfoParameters;
68  pfoParameters.m_particleId = (LArPfoHelper::IsTrack(pInputPfo) ? pInputPfo->GetParticleId() : MU_MINUS);
69  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
70  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
71  pfoParameters.m_energy = 0.f;
72  pfoParameters.m_momentum = pInputPfo->GetMomentum();
73  pfoParameters.m_propertiesToAdd = pInputPfo->GetPropertiesMap();
74  pfoParameters.m_trackStateVector = trackStateVector;
75 
76  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pOutputPfo, trackFactory));
77 
78  const LArTrackPfo *const pLArPfo = dynamic_cast<const LArTrackPfo *>(pOutputPfo);
79  if (NULL == pLArPfo)
80  throw StatusCodeException(STATUS_CODE_FAILURE);
81 
82  // Now update vertex and direction
83  PandoraContentApi::ParticleFlowObject::Metadata pfodata;
84  pfodata.m_momentum = pLArPfo->GetVertexDirection();
85  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*this, pOutputPfo, pfodata));
86 
87  const Vertex *pOutputVertex(NULL);
88 
89  PandoraContentApi::Vertex::Parameters vtxParameters;
90  vtxParameters.m_position = pLArPfo->GetVertexPosition();
91  vtxParameters.m_vertexLabel = pInputVertex->GetVertexLabel();
92  vtxParameters.m_vertexType = pInputVertex->GetVertexType();
93 
94  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, vtxParameters, pOutputVertex));
95  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*this, pOutputPfo, pOutputVertex));
96  }
97  catch (StatusCodeException &statusCodeException)
98  {
99  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
100  throw statusCodeException;
101  }
102 }
103 
104 //------------------------------------------------------------------------------------------------------------------------------------------
105 
106 StatusCode TrackParticleBuildingAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
107 {
108  PANDORA_RETURN_RESULT_IF_AND_IF(
109  STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "SlidingFitHalfWindow", m_slidingFitHalfWindow));
110 
112 }
113 
114 } // namespace lar_content
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
lar pfo object
Definition: LArTrackPfo.h:44
Header file for the pfo helper class.
Header file for the lar pfo class.
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
static void GetSlidingFitTrajectory(const pandora::CartesianPointVector &pointVector, const pandora::CartesianVector &vertexPosition, const unsigned int layerWindow, const float layerPitch, LArTrackStateVector &trackStateVector, pandora::IntVector *const pIndexVector=nullptr)
Apply 3D sliding fit to a set of 3D points and return track trajectory.
const pandora::CartesianVector & GetVertexDirection() const
Get vertex direction.
Definition: LArTrackPfo.cc:46
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
Header file for the 3D track building algorithm class.
LArTrackStateVector m_trackStateVector
Definition: LArTrackPfo.h:36
Header file for the cluster helper class.
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
void CreatePfo(const pandora::ParticleFlowObject *const pInputPfo, const pandora::ParticleFlowObject *&pOutputPfo) const
Create specialised Pfo from an generic input Pfo.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
static bool IsFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a primary parent particle.
lar pfo object factory responsible for pfo creation
Definition: LArTrackPfo.h:84
static bool IsNeutrinoFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a neutrino (or antineutrino) interaction.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
std::vector< LArTrackState > LArTrackStateVector
Definition: LArPfoObjects.h:67
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
const pandora::CartesianVector & GetVertexPosition() const
Get vertex position.
Definition: LArTrackPfo.cc:26