LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar_content::TrackParticleBuildingAlgorithm Class Reference

TrackParticleBuildingAlgorithm class. More...

#include "TrackParticleBuildingAlgorithm.h"

Inheritance diagram for lar_content::TrackParticleBuildingAlgorithm:
lar_content::CustomParticleCreationAlgorithm

Public Member Functions

 TrackParticleBuildingAlgorithm ()
 Default constructor. More...
 

Protected Member Functions

virtual pandora::StatusCode Run ()
 

Private Member Functions

pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
void CreatePfo (const pandora::ParticleFlowObject *const pInputPfo, const pandora::ParticleFlowObject *&pOutputPfo) const
 Create specialised Pfo from an generic input Pfo. More...
 

Private Attributes

unsigned int m_slidingFitHalfWindow
 

Detailed Description

Constructor & Destructor Documentation

lar_content::TrackParticleBuildingAlgorithm::TrackParticleBuildingAlgorithm ( )

Default constructor.

Definition at line 25 of file TrackParticleBuildingAlgorithm.cc.

Member Function Documentation

void lar_content::TrackParticleBuildingAlgorithm::CreatePfo ( const pandora::ParticleFlowObject *const  pInputPfo,
const pandora::ParticleFlowObject *&  pOutputPfo 
) const
privatevirtual

Create specialised Pfo from an generic input Pfo.

Parameters
pInputPfothe address of the input Pfo
pOutputPfothe address of the output Pfo

Implements lar_content::CustomParticleCreationAlgorithm.

Definition at line 33 of file TrackParticleBuildingAlgorithm.cc.

References evd::details::begin(), lar_content::LArPfoHelper::GetSlidingFitTrajectory(), lar_content::LArPfoHelper::GetVertex(), lar_content::LArTrackPfo::GetVertexDirection(), lar_content::LArTrackPfo::GetVertexPosition(), lar_content::LArPfoHelper::IsFinalState(), lar_content::LArPfoHelper::IsNeutrino(), lar_content::LArPfoHelper::IsNeutrinoFinalState(), lar_content::LArPfoHelper::IsTrack(), m_slidingFitHalfWindow, and lar_content::LArTrackPfoParameters::m_trackStateVector.

34 {
35  try
36  {
37  // Need an input vertex to provide a track propagation direction
38  const Vertex *const pInputVertex = LArPfoHelper::GetVertex(pInputPfo);
39 
40  // In cosmic mode, build tracks from all parent pfos, otherwise require that pfo is track-like
42  {
43  if (!LArPfoHelper::IsTrack(pInputPfo))
44  return;
45  }
46  else
47  {
48  if (!LArPfoHelper::IsFinalState(pInputPfo))
49  return;
50 
51  if (LArPfoHelper::IsNeutrino(pInputPfo))
52  return;
53  }
54 
55  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
56  const LArTPC *const pFirstLArTPC(this->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
57  const float layerPitch(pFirstLArTPC->GetWirePitchW());
58 
59  // Calculate sliding fit trajectory
60  LArTrackStateVector trackStateVector;
61  LArPfoHelper::GetSlidingFitTrajectory(pInputPfo, pInputVertex, m_slidingFitHalfWindow, layerPitch, trackStateVector);
62 
63  if (trackStateVector.empty())
64  return;
65 
66  // Build track-like pfo from track trajectory (TODO Correct these placeholder parameters)
67  LArTrackPfoFactory trackFactory;
68  LArTrackPfoParameters pfoParameters;
69  pfoParameters.m_particleId = (LArPfoHelper::IsTrack(pInputPfo) ? pInputPfo->GetParticleId() : MU_MINUS);
70  pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
71  pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
72  pfoParameters.m_energy = 0.f;
73  pfoParameters.m_momentum = pInputPfo->GetMomentum();
74  pfoParameters.m_propertiesToAdd = pInputPfo->GetPropertiesMap();
75  pfoParameters.m_trackStateVector = trackStateVector;
76 
77  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pOutputPfo,
78  trackFactory));
79 
80  const LArTrackPfo *const pLArPfo = dynamic_cast<const LArTrackPfo*>(pOutputPfo);
81  if (NULL == pLArPfo)
82  throw StatusCodeException(STATUS_CODE_FAILURE);
83 
84  // Now update vertex and direction
85  PandoraContentApi::ParticleFlowObject::Metadata pfodata;
86  pfodata.m_momentum = pLArPfo->GetVertexDirection();
87  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*this, pOutputPfo, pfodata));
88 
89  const Vertex *pOutputVertex(NULL);
90 
91  PandoraContentApi::Vertex::Parameters vtxParameters;
92  vtxParameters.m_position = pLArPfo->GetVertexPosition();
93  vtxParameters.m_vertexLabel = pInputVertex->GetVertexLabel();
94  vtxParameters.m_vertexType = pInputVertex->GetVertexType();
95 
96  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, vtxParameters, pOutputVertex));
97  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*this, pOutputPfo, pOutputVertex));
98  }
99  catch (StatusCodeException &statusCodeException)
100  {
101  if (STATUS_CODE_FAILURE == statusCodeException.GetStatusCode())
102  throw statusCodeException;
103  }
104 }
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.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
static bool IsFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a primary parent particle.
static bool IsNeutrinoFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a neutrino (or antineutrino) interaction.
std::vector< LArTrackState > LArTrackStateVector
Definition: LArPfoObjects.h:64
StatusCode lar_content::TrackParticleBuildingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
privatevirtual

Reimplemented from lar_content::CustomParticleCreationAlgorithm.

Definition at line 108 of file TrackParticleBuildingAlgorithm.cc.

References m_slidingFitHalfWindow, and lar_content::CustomParticleCreationAlgorithm::ReadSettings().

109 {
110  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
111  "SlidingFitHalfWindow", m_slidingFitHalfWindow));
112 
114 }
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
StatusCode lar_content::CustomParticleCreationAlgorithm::Run ( )
protectedvirtualinherited

Definition at line 20 of file CustomParticleCreationAlgorithm.cc.

21 {
22  // Get input Pfo List
23  const PfoList *pPfoList(NULL);
24 
25  if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*this, m_pfoListName, pPfoList))
26  {
27  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
28  std::cout << "CustomParticleCreationAlgorithm: cannot find pfo list " << m_pfoListName << std::endl;
29 
30  return STATUS_CODE_SUCCESS;
31  }
32 
33  // Get input Vertex List
34  const VertexList *pVertexList(NULL);
35 
36  if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*this, m_vertexListName, pVertexList))
37  {
38  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
39  std::cout << "CustomParticleCreationAlgorithm: cannot find vertex list " << m_vertexListName << std::endl;
40 
41  return STATUS_CODE_SUCCESS;
42  }
43 
44  // Create temporary lists
45  const PfoList *pTempPfoList = NULL; std::string tempPfoListName;
46  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pTempPfoList,
47  tempPfoListName));
48 
49  const VertexList *pTempVertexList = NULL; std::string tempVertexListName;
50  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pTempVertexList,
51  tempVertexListName));
52 
53  // Loop over input Pfos
54  PfoList pfoList(pPfoList->begin(), pPfoList->end());
55  VertexList vertexList(pVertexList->begin(), pVertexList->end());
56 
57  for (PfoList::const_iterator iter = pfoList.begin(), iterEnd = pfoList.end(); iter != iterEnd; ++iter)
58  {
59  const ParticleFlowObject *const pInputPfo = *iter;
60 
61  if (pInputPfo->GetVertexList().empty())
62  continue;
63 
64  const Vertex *const pInputVertex = LArPfoHelper::GetVertex(pInputPfo);
65 
66  if (vertexList.end() == std::find(vertexList.begin(), vertexList.end(), pInputVertex))
67  throw StatusCodeException(STATUS_CODE_FAILURE);
68 
69  // Build a new pfo and vertex from the old pfo
70  const ParticleFlowObject *pOutputPfo(NULL);
71 
72  this->CreatePfo(pInputPfo, pOutputPfo);
73 
74  if (NULL == pOutputPfo)
75  continue;
76 
77  if (pOutputPfo->GetVertexList().empty())
78  throw StatusCodeException(STATUS_CODE_FAILURE);
79 
80  // Transfer clusters and hierarchy information to new pfo, and delete old pfo and vertex
81  ClusterList clusterList(pInputPfo->GetClusterList().begin(), pInputPfo->GetClusterList().end());
82  PfoList parentList(pInputPfo->GetParentPfoList().begin(), pInputPfo->GetParentPfoList().end());
83  PfoList daughterList(pInputPfo->GetDaughterPfoList().begin(), pInputPfo->GetDaughterPfoList().end());
84 
85  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Pfo>(*this, pInputPfo, m_pfoListName));
86  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Vertex>(*this, pInputVertex, m_vertexListName));
87 
88  for (ClusterList::const_iterator cIter = clusterList.begin(), cIterEnd = clusterList.end(); cIter != cIterEnd; ++cIter)
89  {
90  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo<Cluster>(*this, pOutputPfo, *cIter));
91  }
92 
93  for (PfoList::const_iterator pIter = parentList.begin(), pIterEnd = parentList.end(); pIter != pIterEnd; ++pIter)
94  {
95  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SetPfoParentDaughterRelationship(*this, *pIter, pOutputPfo));
96  }
97 
98  for (PfoList::const_iterator dIter = daughterList.begin(), dIterEnd = daughterList.end(); dIter != dIterEnd; ++dIter)
99  {
100  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SetPfoParentDaughterRelationship(*this, pOutputPfo, *dIter));
101  }
102  }
103 
104  if (!pTempPfoList->empty())
105  {
106  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Pfo>(*this, m_pfoListName));
107  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Pfo>(*this, m_pfoListName));
108  }
109 
110  if (!pTempVertexList->empty())
111  {
112  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*this, m_vertexListName));
113  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Vertex>(*this, m_vertexListName));
114  }
115 
116  return STATUS_CODE_SUCCESS;
117 }
std::string m_vertexListName
The name of the input vertex list.
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
intermediate_table::const_iterator const_iterator
std::string m_pfoListName
The name of the input pfo list.
std::list< Vertex > VertexList
Definition: DCEL.h:178
virtual void CreatePfo(const pandora::ParticleFlowObject *const pInputPfo, const pandora::ParticleFlowObject *&pOutputPfo) const =0
Create specialised Pfo from an generic input Pfo.

Member Data Documentation

unsigned int lar_content::TrackParticleBuildingAlgorithm::m_slidingFitHalfWindow
private

Definition at line 34 of file TrackParticleBuildingAlgorithm.h.

Referenced by CreatePfo(), and ReadSettings().


The documentation for this class was generated from the following files: