Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
TestBeamParticleCreationAlgorithm.cc
Go to the documentation of this file.
1
10
12
14
15using namespace pandora;
16
17namespace lar_content
18{
19
21{
22 const PfoList *pParentNuPfoList(nullptr);
23
24 if (STATUS_CODE_SUCCESS != PandoraContentApi::GetList(*this, m_parentPfoListName, pParentNuPfoList))
25 {
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
55StatusCode 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);
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
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));
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
144 return STATUS_CODE_SUCCESS;
145}
146
147//------------------------------------------------------------------------------------------------------------------------------------------
148
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
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the pfo helper class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the test beam particle creation algorithm class.
static pandora::StatusCode SaveList(const pandora::Algorithm &algorithm, const T &t, const std::string &newListName)
Save a provided input object list under a new name.
static pandora::StatusCode ReplaceCurrentList(const pandora::Algorithm &algorithm, const std::string &newListName)
Replace the current list with a pre-saved list; use this new list as a permanent replacement for the ...
static pandora::StatusCode AddToPfo(const pandora::Algorithm &algorithm, const pandora::ParticleFlowObject *const pPfo, const T *const pT)
Add a cluster to a particle flow object.
static pandora::StatusCode CreateTemporaryListAndSetCurrent(const pandora::Algorithm &algorithm, const T *&pT, std::string &temporaryListName)
Create a temporary list and set it to be the current list, enabling object creation.
static pandora::StatusCode SetPfoParentDaughterRelationship(const pandora::Algorithm &algorithm, const pandora::ParticleFlowObject *const pParentPfo, const pandora::ParticleFlowObject *const pDaughterPfo)
Set parent-daughter particle flow object relationship.
static pandora::StatusCode RemoveFromPfo(const pandora::Algorithm &algorithm, const pandora::ParticleFlowObject *const pPfo, const T *const pT)
Remove a cluster from a particle flow object. Note this function will not remove the final object (tr...
static pandora::StatusCode GetList(const pandora::Algorithm &algorithm, const std::string &listName, const T *&pT)
Get a named list.
static const pandora::PandoraSettings * GetSettings(const pandora::Algorithm &algorithm)
Get the pandora settings instance.
static bool IsTrack(const pandora::ParticleFlowObject *const pPfo)
Return track flag based on Pfo Particle ID.
static bool IsNeutrino(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a neutrino or (antineutrino)
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.
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
std::string m_parentVertexListName
The parent vertex list name.
std::string m_daughterVertexListName
The daughter 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.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
pandora::StatusCode SetupTestBeamVertex(const pandora::Pfo *const pNuPfo, const pandora::Pfo *const pTestBeamPfo, const pandora::CartesianVector &testBeamStartVertex) const
Set up the test beam vertex.
CaloHit class.
Definition CaloHit.h:26
CartesianVector class.
float GetZ() const
Get the cartesian z coordinate.
bool ShouldDisplayAlgorithmInfo() const
Whether to display algorithm information during processing.
ParticleFlowObject class.
const PropertiesMap & GetPropertiesMap() const
Get the map from registered property name to floating point property value.
const PfoList & GetDaughterPfoList() const
Get the daughter pfo list.
StatusCode AlterMetadata(const object_creation::ParticleFlowObject::Metadata &metadata)
Alter particle flow object metadata parameters.
int GetParticleId() const
Get the particle flow object id (PDG code)
StatusCodeException class.
Vertex class.
Definition Vertex.h:26
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
MANAGED_CONTAINER< const CaloHit * > CaloHitList
MANAGED_CONTAINER< const Vertex * > VertexList
StatusCode
The StatusCode enum.
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList