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

TestBeamParticleCreationAlgorithm class. More...

#include "TestBeamParticleCreationAlgorithm.h"

Inheritance diagram for lar_content::TestBeamParticleCreationAlgorithm:

Public Member Functions

 TestBeamParticleCreationAlgorithm ()
 Constructor. More...
 

Private Member Functions

pandora::StatusCode Run ()
 
pandora::StatusCode SetupTestBeamPfo (const pandora::Pfo *const pNuPfo, const pandora::Pfo *&pTestBeamPfo, pandora::CartesianVector &testBeamStartVertex) const
 Set up the test beam pfo. More...
 
pandora::StatusCode SetupTestBeamVertex (const pandora::Pfo *const pNuPfo, const pandora::Pfo *const pTestBeamPfo, const pandora::CartesianVector &testBeamStartVertex) const
 Set up the test beam vertex. More...
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 

Private Attributes

std::string m_parentPfoListName
 The parent pfo list name. More...
 
std::string m_trackPfoListName
 The track pfo list name. More...
 
std::string m_showerPfoListName
 The shower pfo list name. More...
 
std::string m_parentVertexListName
 The parent vertex list name. More...
 
std::string m_daughterVertexListName
 The daughter vertex list name. More...
 
bool m_keepInteractionVertex
 Keep the vertex for the test beam particle at the interaction point. More...
 
bool m_keepStartVertex
 Keep the vertex for the test beam particle at the position of hit at minimum z. More...
 

Detailed Description

Constructor & Destructor Documentation

lar_content::TestBeamParticleCreationAlgorithm::TestBeamParticleCreationAlgorithm ( )

Constructor.

Definition at line 20 of file TestBeamParticleCreationAlgorithm.cc.

20  :
22  m_keepStartVertex(false)
23 {
24 }
bool m_keepInteractionVertex
Keep the vertex for the test beam particle at the interaction point.
bool m_keepStartVertex
Keep the vertex for the test beam particle at the position of hit at minimum z.

Member Function Documentation

StatusCode lar_content::TestBeamParticleCreationAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 158 of file TestBeamParticleCreationAlgorithm.cc.

References m_daughterVertexListName, m_keepInteractionVertex, m_keepStartVertex, m_parentPfoListName, m_parentVertexListName, m_showerPfoListName, and m_trackPfoListName.

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 }
bool m_keepInteractionVertex
Keep the vertex for the test beam particle at the interaction point.
bool m_keepStartVertex
Keep the vertex for the test beam particle at the position of hit at minimum z.
std::string m_daughterVertexListName
The daughter vertex list name.
std::string m_parentVertexListName
The parent vertex list name.
StatusCode lar_content::TestBeamParticleCreationAlgorithm::Run ( )
private

Definition at line 28 of file TestBeamParticleCreationAlgorithm.cc.

References lar_content::LArPfoHelper::IsNeutrino(), m_parentPfoListName, max, SetupTestBeamPfo(), and SetupTestBeamVertex().

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 }
Int_t max
Definition: plot.C:27
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)
pandora::StatusCode SetupTestBeamPfo(const pandora::Pfo *const pNuPfo, const pandora::Pfo *&pTestBeamPfo, pandora::CartesianVector &testBeamStartVertex) const
Set up the test beam pfo.
StatusCode lar_content::TestBeamParticleCreationAlgorithm::SetupTestBeamPfo ( const pandora::Pfo *const  pNuPfo,
const pandora::Pfo *&  pTestBeamPfo,
pandora::CartesianVector &  testBeamStartVertex 
) const
private

Set up the test beam pfo.

Parameters
pNuPfothe input neutrino-hypothesis pfo
pTestBeamPfoto receive the output test-beam-hypothesis pfo
testBeamStartVertexto receive the position of the test beam start-position vertex (position of hit at minimum z)
Returns
status code

Definition at line 63 of file TestBeamParticleCreationAlgorithm.cc.

References lar_content::LArPfoHelper::GetCaloHits(), lar_content::LArPfoHelper::IsTrack(), m_parentPfoListName, m_showerPfoListName, m_trackPfoListName, and max.

Referenced by Run().

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 }
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
Int_t max
Definition: plot.C:27
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.
StatusCode lar_content::TestBeamParticleCreationAlgorithm::SetupTestBeamVertex ( const pandora::Pfo *const  pNuPfo,
const pandora::Pfo *const  pTestBeamPfo,
const pandora::CartesianVector &  testBeamStartVertex 
) const
private

Set up the test beam vertex.

Parameters
pNuPfothe input neutrino-hypothesis pfo
pTestBeamPfothe input test-beam-hypothesis pfo
testBeamStartVertexthe input position of the test beam start-position vertex
Returns
status code

Definition at line 108 of file TestBeamParticleCreationAlgorithm.cc.

References lar_content::LArPfoHelper::GetVertex(), m_daughterVertexListName, m_keepStartVertex, and m_parentVertexListName.

Referenced by Run().

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 }
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
bool m_keepStartVertex
Keep the vertex for the test beam particle at the position of hit at minimum z.
std::string m_daughterVertexListName
The daughter vertex list name.
std::string m_parentVertexListName
The parent vertex list name.
std::list< Vertex > VertexList
Definition: DCEL.h:178

Member Data Documentation

std::string lar_content::TestBeamParticleCreationAlgorithm::m_daughterVertexListName
private

The daughter vertex list name.

Definition at line 59 of file TestBeamParticleCreationAlgorithm.h.

Referenced by ReadSettings(), and SetupTestBeamVertex().

bool lar_content::TestBeamParticleCreationAlgorithm::m_keepInteractionVertex
private

Keep the vertex for the test beam particle at the interaction point.

Definition at line 61 of file TestBeamParticleCreationAlgorithm.h.

Referenced by ReadSettings().

bool lar_content::TestBeamParticleCreationAlgorithm::m_keepStartVertex
private

Keep the vertex for the test beam particle at the position of hit at minimum z.

Definition at line 62 of file TestBeamParticleCreationAlgorithm.h.

Referenced by ReadSettings(), and SetupTestBeamVertex().

std::string lar_content::TestBeamParticleCreationAlgorithm::m_parentPfoListName
private

The parent pfo list name.

Definition at line 54 of file TestBeamParticleCreationAlgorithm.h.

Referenced by ReadSettings(), Run(), and SetupTestBeamPfo().

std::string lar_content::TestBeamParticleCreationAlgorithm::m_parentVertexListName
private

The parent vertex list name.

Definition at line 58 of file TestBeamParticleCreationAlgorithm.h.

Referenced by ReadSettings(), and SetupTestBeamVertex().

std::string lar_content::TestBeamParticleCreationAlgorithm::m_showerPfoListName
private

The shower pfo list name.

Definition at line 56 of file TestBeamParticleCreationAlgorithm.h.

Referenced by ReadSettings(), and SetupTestBeamPfo().

std::string lar_content::TestBeamParticleCreationAlgorithm::m_trackPfoListName
private

The track pfo list name.

Definition at line 55 of file TestBeamParticleCreationAlgorithm.h.

Referenced by ReadSettings(), and SetupTestBeamPfo().


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