LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TestBeamParticleCreationAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 TestBeamParticleCreationAlgorithm::TestBeamParticleCreationAlgorithm() :
21  m_keepInteractionVertex(true),
22  m_keepStartVertex(false)
23 {
24 }
25 
26 //------------------------------------------------------------------------------------------------------------------------------------------
27 
29 {
30  const PfoList *pParentNuPfoList(nullptr);
31 
32  if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*this, m_parentPfoListName, pParentNuPfoList))
33  {
34  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
35  std::cout << "TestBeamParticleCreationAlgorithm: pfo list " << m_parentPfoListName << " unavailable." << std::endl;
36 
37  return STATUS_CODE_SUCCESS;
38  }
39 
40  PfoList neutrinoPfos;
41 
42  for (const Pfo *const pNuPfo : *pParentNuPfoList)
43  {
44  if (!LArPfoHelper::IsNeutrino(pNuPfo))
45  continue;
46 
47  neutrinoPfos.push_back(pNuPfo);
48 
49  const Pfo *pTestBeamPfo(nullptr);
51  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->SetupTestBeamPfo(pNuPfo, pTestBeamPfo, testBeamStartVertex));
52  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->SetupTestBeamVertex(pNuPfo, pTestBeamPfo, testBeamStartVertex));
53  }
54 
55  for (const Pfo *const pNuPfo : neutrinoPfos)
56  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Pfo>(*this, pNuPfo, m_parentPfoListName));
57 
58  return STATUS_CODE_SUCCESS;
59 }
60 
61 //------------------------------------------------------------------------------------------------------------------------------------------
62 
63 StatusCode TestBeamParticleCreationAlgorithm::SetupTestBeamPfo(const Pfo *const pNuPfo, const Pfo *&pTestBeamPfo, CartesianVector &testBeamStartVertex) const
64 {
65  pTestBeamPfo = nullptr;
67 
68  for (const Pfo *const pNuDaughterPfo : pNuPfo->GetDaughterPfoList())
69  {
70  CaloHitList collectedHits;
71  LArPfoHelper::GetCaloHits(pNuDaughterPfo, TPC_3D, collectedHits);
72 
73  for (const CaloHit *const pCaloHit : collectedHits)
74  {
75  if (pCaloHit->GetPositionVector().GetZ() < testBeamStartVertex.GetZ())
76  {
77  testBeamStartVertex = pCaloHit->GetPositionVector();
78  pTestBeamPfo = pNuDaughterPfo;
79  }
80  }
81  }
82 
83  if (!pTestBeamPfo)
84  return STATUS_CODE_NOT_FOUND;
85 
86  for (const Pfo *const pNuDaughterPfo : pNuPfo->GetDaughterPfoList())
87  {
88  if (pNuDaughterPfo != pTestBeamPfo)
89  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SetPfoParentDaughterRelationship(*this, pTestBeamPfo, pNuDaughterPfo));
90  }
91 
92  // Move test beam pfo to parent list from its initial track or shower list
93  const std::string &originalListName(LArPfoHelper::IsTrack(pTestBeamPfo) ? m_trackPfoListName : m_showerPfoListName);
94  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, originalListName, m_parentPfoListName, PfoList(1, pTestBeamPfo)));
95 
96  // Alter metadata: test beam score (1, if not previously set) and particle id (electron if primary pfo shower-like, else charged pion)
97  PandoraContentApi::ParticleFlowObject::Metadata pfoMetadata;
98  pfoMetadata.m_propertiesToAdd["IsTestBeam"] = 1.f;
99  pfoMetadata.m_propertiesToAdd["TestBeamScore"] = (pNuPfo->GetPropertiesMap().count("TestBeamScore")) ? pNuPfo->GetPropertiesMap().at("TestBeamScore") : 1.f;
100  pfoMetadata.m_particleId = (std::fabs(pTestBeamPfo->GetParticleId()) == E_MINUS) ? E_MINUS : PI_PLUS;
101  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*this, pTestBeamPfo, pfoMetadata));
102 
103  return STATUS_CODE_SUCCESS;
104 }
105 
106 //------------------------------------------------------------------------------------------------------------------------------------------
107 
108 StatusCode TestBeamParticleCreationAlgorithm::SetupTestBeamVertex(const Pfo *const pNuPfo, const Pfo *const pTestBeamPfo, const CartesianVector &testBeamStartVertex) const
109 {
110  try
111  {
112  const Vertex *const pInitialVertex(LArPfoHelper::GetVertex(pTestBeamPfo));
113  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RemoveFromPfo(*this, pTestBeamPfo, pInitialVertex));
114  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Vertex>(*this, pInitialVertex, m_daughterVertexListName));
115  }
116  catch (const StatusCodeException &)
117  {
118  std::cout << "TestBeamParticleCreationAlgorithm::SetupTestBeamVertex - Test beam particle has no initial vertex" << std::endl;
119  }
120 
121  if (m_keepStartVertex)
122  {
123  std::string vertexListName;
124  const VertexList *pVertexList(nullptr);
125  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pVertexList, vertexListName));
126 
127  PandoraContentApi::Vertex::Parameters parameters;
128  parameters.m_position = testBeamStartVertex;
129  parameters.m_vertexLabel = VERTEX_START;
130  parameters.m_vertexType = VERTEX_3D;
131  const Vertex *pTestBeamStartVertex(nullptr);
132  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, parameters, pTestBeamStartVertex));
133 
134  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*this, m_parentVertexListName));
135  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Vertex>(*this, m_parentVertexListName));
136  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*this, pTestBeamPfo, pTestBeamStartVertex));
137  }
138  else
139  {
140  try
141  {
142  const Vertex *const pNuVertex(LArPfoHelper::GetVertex(pNuPfo));
143  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RemoveFromPfo(*this, pNuPfo, pNuVertex));
144  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*this, pTestBeamPfo, pNuVertex));
145  // ATTN This vertex already lives in m_parentVertexListName
146  }
147  catch (const StatusCodeException &)
148  {
149  std::cout << "TestBeamParticleCreationAlgorithm::SetupTestBeamVertex - Cannot transfer interaction vertex to test beam particle" << std::endl;
150  }
151  }
152 
153  return STATUS_CODE_SUCCESS;
154 }
155 
156 //------------------------------------------------------------------------------------------------------------------------------------------
157 
158 StatusCode TestBeamParticleCreationAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
159 {
160  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
161  "ParentPfoListName", m_parentPfoListName));
162 
163  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
164  "TrackPfoListName", m_trackPfoListName));
165 
166  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
167  "ShowerPfoListName", m_showerPfoListName));
168 
169  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
170  "ParentVertexListName", m_parentVertexListName));
171 
172  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle,
173  "DaughterVertexListName", m_daughterVertexListName));
174 
175  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
176  "KeepInteractionVertex", m_keepInteractionVertex));
177 
178  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle,
179  "KeepStartVertex", m_keepStartVertex));
180 
182  {
183  std::cout << "TestBeamParticleCreationAlgorithm::ReadSettings - Must persist exactly one vertex per test beam particle." << std::endl;
184  return STATUS_CODE_INVALID_PARAMETER;
185  }
186 
187  return STATUS_CODE_SUCCESS;
188 }
189 
190 } // namespace lar_content
Header file for the pfo helper class.
bool m_keepInteractionVertex
Keep the vertex for the test beam particle at the interaction point.
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
Int_t max
Definition: plot.C:27
bool m_keepStartVertex
Keep the vertex for the test beam particle at the position of hit at minimum z.
pandora::StatusCode SetupTestBeamVertex(const pandora::Pfo *const pNuPfo, const pandora::Pfo *const pTestBeamPfo, const pandora::CartesianVector &testBeamStartVertex) const
Set up the test beam vertex.
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
std::string m_daughterVertexListName
The daughter vertex list name.
std::string m_parentVertexListName
The parent vertex list name.
pandora::StatusCode SetupTestBeamPfo(const pandora::Pfo *const pNuPfo, const pandora::Pfo *&pTestBeamPfo, pandora::CartesianVector &testBeamStartVertex) const
Set up the test beam pfo.
Header file for the test beam particle creation algorithm class.
static void GetCaloHits(const pandora::PfoList &pfoList, const pandora::HitType &hitType, pandora::CaloHitList &caloHitList)
Get a list of calo hits of a particular hit type from a list of pfos.
std::list< Vertex > VertexList
Definition: DCEL.h:178
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)