LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 StatusCode TestBeamParticleCreationAlgorithm::Run()
21 {
22  const PfoList *pParentNuPfoList(nullptr);
23 
24  if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*this, m_parentPfoListName, pParentNuPfoList))
25  {
26  if (PandoraContentApi::GetSettings(*this)->ShouldDisplayAlgorithmInfo())
27  std::cout << "TestBeamParticleCreationAlgorithm: pfo list " << m_parentPfoListName << " unavailable." << std::endl;
28 
29  return STATUS_CODE_SUCCESS;
30  }
31 
32  PfoList neutrinoPfos;
33 
34  for (const Pfo *const pNuPfo : *pParentNuPfoList)
35  {
36  if (!LArPfoHelper::IsNeutrino(pNuPfo))
37  continue;
38 
39  neutrinoPfos.push_back(pNuPfo);
40 
41  const Pfo *pTestBeamPfo(nullptr);
42  CartesianVector testBeamStartVertex(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
43  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->SetupTestBeamPfo(pNuPfo, pTestBeamPfo, testBeamStartVertex));
44  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->SetupTestBeamVertex(pNuPfo, pTestBeamPfo, testBeamStartVertex));
45  }
46 
47  for (const Pfo *const pNuPfo : neutrinoPfos)
48  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Pfo>(*this, pNuPfo, m_parentPfoListName));
49 
50  return STATUS_CODE_SUCCESS;
51 }
52 
53 //------------------------------------------------------------------------------------------------------------------------------------------
54 
55 StatusCode TestBeamParticleCreationAlgorithm::SetupTestBeamPfo(const Pfo *const pNuPfo, const Pfo *&pTestBeamPfo, CartesianVector &testBeamStartVertex) const
56 {
57  pTestBeamPfo = nullptr;
58  testBeamStartVertex = CartesianVector(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
59 
60  for (const Pfo *const pNuDaughterPfo : pNuPfo->GetDaughterPfoList())
61  {
62  CaloHitList collectedHits;
63  LArPfoHelper::GetCaloHits(pNuDaughterPfo, TPC_3D, collectedHits);
64 
65  for (const CaloHit *const pCaloHit : collectedHits)
66  {
67  if (pCaloHit->GetPositionVector().GetZ() < testBeamStartVertex.GetZ())
68  {
69  testBeamStartVertex = pCaloHit->GetPositionVector();
70  pTestBeamPfo = pNuDaughterPfo;
71  }
72  }
73  }
74 
75  if (!pTestBeamPfo)
76  return STATUS_CODE_NOT_FOUND;
77 
78  for (const Pfo *const pNuDaughterPfo : pNuPfo->GetDaughterPfoList())
79  {
80  if (pNuDaughterPfo != pTestBeamPfo)
81  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SetPfoParentDaughterRelationship(*this, pTestBeamPfo, pNuDaughterPfo));
82  }
83 
84  // Move test beam pfo to parent list from its initial track or shower list
85  const std::string &originalListName(LArPfoHelper::IsTrack(pTestBeamPfo) ? m_trackPfoListName : m_showerPfoListName);
86  PANDORA_RETURN_RESULT_IF(
87  STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, originalListName, m_parentPfoListName, PfoList(1, pTestBeamPfo)));
88 
89  // Alter metadata: test beam score (1, if not previously set) and particle id (electron if primary pfo shower-like, else charged pion)
90  PandoraContentApi::ParticleFlowObject::Metadata pfoMetadata;
91  pfoMetadata.m_propertiesToAdd["IsTestBeam"] = 1.f;
92  pfoMetadata.m_propertiesToAdd["TestBeamScore"] =
93  (pNuPfo->GetPropertiesMap().count("TestBeamScore")) ? pNuPfo->GetPropertiesMap().at("TestBeamScore") : 1.f;
94  pfoMetadata.m_particleId = (std::fabs(pTestBeamPfo->GetParticleId()) == E_MINUS) ? E_MINUS : PI_PLUS;
95  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::AlterMetadata(*this, pTestBeamPfo, pfoMetadata));
96 
97  return STATUS_CODE_SUCCESS;
98 }
99 
100 //------------------------------------------------------------------------------------------------------------------------------------------
101 
102 StatusCode TestBeamParticleCreationAlgorithm::SetupTestBeamVertex(
103  const Pfo *const pNuPfo, const Pfo *const pTestBeamPfo, const CartesianVector &testBeamStartVertex) const
104 {
105  try
106  {
107  const Vertex *const pInitialVertex(LArPfoHelper::GetVertex(pTestBeamPfo));
108  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RemoveFromPfo(*this, pTestBeamPfo, pInitialVertex));
109  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Delete<Vertex>(*this, pInitialVertex, m_daughterVertexListName));
110  }
111  catch (const StatusCodeException &)
112  {
113  std::cout << "TestBeamParticleCreationAlgorithm::SetupTestBeamVertex - Test beam particle has no initial vertex" << std::endl;
114  }
115 
116  // Set start vertex
117  std::string vertexListName;
118  const VertexList *pVertexList(nullptr);
119  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pVertexList, vertexListName));
120 
121  PandoraContentApi::Vertex::Parameters parameters;
122  parameters.m_position = testBeamStartVertex;
123  parameters.m_vertexLabel = VERTEX_START;
124  parameters.m_vertexType = VERTEX_3D;
125  const Vertex *pTestBeamStartVertex(nullptr);
126  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, parameters, pTestBeamStartVertex));
127  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*this, m_parentVertexListName));
128  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*this, pTestBeamPfo, pTestBeamStartVertex));
129 
130  // Retain interaction vertex
131  try
132  {
133  const Vertex *const pNuVertex(LArPfoHelper::GetVertex(pNuPfo));
134  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RemoveFromPfo(*this, pNuPfo, pNuVertex));
135  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::AddToPfo(*this, pTestBeamPfo, pNuVertex));
136  // ATTN This vertex already lives in m_parentVertexListName
137  }
138  catch (const StatusCodeException &)
139  {
140  std::cout << "TestBeamParticleCreationAlgorithm::SetupTestBeamVertex - Cannot transfer interaction vertex to test beam particle" << std::endl;
141  }
142 
143  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ReplaceCurrentList<Vertex>(*this, m_parentVertexListName));
144  return STATUS_CODE_SUCCESS;
145 }
146 
147 //------------------------------------------------------------------------------------------------------------------------------------------
148 
149 StatusCode TestBeamParticleCreationAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
150 {
151  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "ParentPfoListName", m_parentPfoListName));
152 
153  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "TrackPfoListName", m_trackPfoListName));
154 
155  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "ShowerPfoListName", m_showerPfoListName));
156 
157  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "ParentVertexListName", m_parentVertexListName));
158 
159  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "DaughterVertexListName", m_daughterVertexListName));
160 
161  return STATUS_CODE_SUCCESS;
162 }
163 
164 } // namespace lar_content
Header file for the pfo helper class.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
Header file for the test beam particle creation algorithm class.
std::list< Vertex > VertexList
Definition: DCEL.h:169