Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
MatchingBaseAlgorithm.cc
Go to the documentation of this file.
1
10
12
14
15using namespace pandora;
16
17namespace lar_content
18{
19
23
24//------------------------------------------------------------------------------------------------------------------------------------------
25
29
30//------------------------------------------------------------------------------------------------------------------------------------------
31
32void MatchingBaseAlgorithm::SelectInputClusters(const ClusterList *const pInputClusterList, ClusterList &selectedClusterList) const
33{
34 if (!pInputClusterList)
35 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
36
37 selectedClusterList = *pInputClusterList;
38}
39
40//------------------------------------------------------------------------------------------------------------------------------------------
41
43{
44}
45
46//------------------------------------------------------------------------------------------------------------------------------------------
47
49{
50 ClusterSet deletedClusters;
51
52 ClusterList parentClusters;
53 for (const auto &mapEntry : clusterMergeMap)
54 parentClusters.push_back(mapEntry.first);
55 parentClusters.sort(LArClusterHelper::SortByNHits);
56
57 for (const Cluster *const pParentCluster : parentClusters)
58 {
59 const HitType hitType(LArClusterHelper::GetClusterHitType(pParentCluster));
60 const std::string &clusterListName(this->GetClusterListName(hitType));
61
62 if (!((TPC_VIEW_U == hitType) || (TPC_VIEW_V == hitType) || (TPC_VIEW_W == hitType)))
63 throw StatusCodeException(STATUS_CODE_FAILURE);
64
65 ClusterList daughterClusters(clusterMergeMap.at(pParentCluster));
66 daughterClusters.sort(LArClusterHelper::SortByNHits);
67
68 for (const Cluster *const pDaughterCluster : daughterClusters)
69 {
70 if (deletedClusters.count(pParentCluster) || deletedClusters.count(pDaughterCluster))
71 throw StatusCodeException(STATUS_CODE_FAILURE);
72
73 this->UpdateUponDeletion(pDaughterCluster);
74 this->UpdateUponDeletion(pParentCluster);
75 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=,
76 PandoraContentApi::MergeAndDeleteClusters(*this, pParentCluster, pDaughterCluster, clusterListName, clusterListName));
77
78 this->UpdateForNewCluster(pParentCluster);
79 deletedClusters.insert(pDaughterCluster);
80 }
81 }
82
83 return !(deletedClusters.empty());
84}
85
86//------------------------------------------------------------------------------------------------------------------------------------------
87
89{
90 bool particlesMade(false);
91 const PfoList *pPfoList(nullptr);
92 std::string pfoListName;
93 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pPfoList, pfoListName));
94
95 for (const ProtoParticle &protoParticle : protoParticleVector)
96 {
97 PandoraContentApi::ParticleFlowObject::Parameters pfoParameters;
98 this->SetPfoParameters(protoParticle, pfoParameters);
99
100 const ParticleFlowObject *pPfo(nullptr);
101 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::ParticleFlowObject::Create(*this, pfoParameters, pPfo));
102 particlesMade = true;
103 }
104
105 if (!pPfoList->empty())
106 {
109 }
110
111 return particlesMade;
112}
113
114//------------------------------------------------------------------------------------------------------------------------------------------
115
116void MatchingBaseAlgorithm::SetPfoParameters(const ProtoParticle &protoParticle, PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
117{
118 this->SetPfoParticleId(pfoParameters);
119 pfoParameters.m_charge = PdgTable::GetParticleCharge(pfoParameters.m_particleId.Get());
120 pfoParameters.m_mass = PdgTable::GetParticleMass(pfoParameters.m_particleId.Get());
121 pfoParameters.m_energy = 0.f;
122 pfoParameters.m_momentum = CartesianVector(0.f, 0.f, 0.f);
123 pfoParameters.m_clusterList = protoParticle.m_clusterList;
124}
125
126//------------------------------------------------------------------------------------------------------------------------------------------
127
128void MatchingBaseAlgorithm::SetPfoParticleId(PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
129{
130 pfoParameters.m_particleId = E_MINUS; // Shower
131}
132
133//------------------------------------------------------------------------------------------------------------------------------------------
134
136{
137 try
138 {
141 this->PerformMainLoop();
143 this->TidyUp();
144 }
145 catch (StatusCodeException &statusCodeException)
146 {
147 this->TidyUp();
148
149 if (STATUS_CODE_SUCCESS != statusCodeException.GetStatusCode())
150 throw statusCodeException;
151 }
152
153 return STATUS_CODE_SUCCESS;
154}
155
156//------------------------------------------------------------------------------------------------------------------------------------------
157
159{
160 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "OutputPfoListName", m_outputPfoListName));
161
162 return STATUS_CODE_SUCCESS;
163}
164
165} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
Header file for the cluster helper class.
Header file for the three dimension algorithm base 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
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 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 MergeAndDeleteClusters(const pandora::Algorithm &algorithm, const pandora::Cluster *const pClusterToEnlarge, const pandora::Cluster *const pClusterToDelete)
Merge two clusters in the current list, enlarging one cluster and deleting the second.
static pandora::HitType GetClusterHitType(const pandora::Cluster *const pCluster)
Get the hit type associated with a two dimensional cluster.
static bool SortByNHits(const pandora::Cluster *const pLhs, const pandora::Cluster *const pRhs)
Sort clusters by number of hits, then layer span, then inner layer, then position,...
virtual bool MakeClusterMerges(const ClusterMergeMap &clusterMergeMap)
Merge clusters together.
virtual void UpdateForNewCluster(const pandora::Cluster *const pNewCluster)=0
Update to reflect addition of a new cluster to the problem space.
virtual void PrepareAllInputClusters()=0
Perform any preparatory steps required, e.g. caching expensive fit results for clusters.
virtual void SelectAllInputClusters()=0
Select a subset of input clusters for processing in this algorithm.
virtual void UpdateUponDeletion(const pandora::Cluster *const pDeletedCluster)=0
Update to reflect cluster deletion.
virtual bool CreateThreeDParticles(const ProtoParticleVector &protoParticleVector)
Create particles using findings from recent algorithm processing.
virtual const std::string & GetClusterListName(const pandora::HitType hitType) const =0
Get the cluster list name corresponding to a specified hit type.
virtual void TidyUp()=0
Tidy member variables in derived class.
virtual void SetPfoParameters(const ProtoParticle &protoParticle, PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
Set Pfo properties.
std::string m_outputPfoListName
The output pfo list name.
pandora::StatusCode Run()
Run the algorithm.
virtual pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
virtual void ExamineOverlapContainer()=0
Examine contents of overlap container, collect together best-matching 2D particles and modify cluster...
virtual void SelectInputClusters(const pandora::ClusterList *const pInputClusterList, pandora::ClusterList &selectedClusterList) const
Select a subset of input clusters for processing in this algorithm.
virtual void SetPfoParticleId(PandoraContentApi::ParticleFlowObject::Parameters &pfoParameters) const
Set pfo particle id.
virtual void PrepareInputClusters(pandora::ClusterList &preparedClusterList)
Perform any preparatory steps required on the input clusters, e.g. caching expensive fit results.
virtual void PerformMainLoop()=0
Main loop over cluster combinations in order to populate the overlap container. Responsible for calli...
CartesianVector class.
Cluster class.
Definition Cluster.h:31
ParticleFlowObject class.
static float GetParticleMass(const int pdgCode)
Get the mass of a particle type.
Definition PdgTable.h:205
static int GetParticleCharge(const int pdgCode)
Get the charge of a particle type.
Definition PdgTable.h:227
StatusCodeException class.
StatusCode GetStatusCode() const
Get status code.
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
std::unordered_map< const pandora::Cluster *, pandora::ClusterList > ClusterMergeMap
std::vector< ProtoParticle > ProtoParticleVector
pandora::ClusterList m_clusterList
List of 2D clusters in a 3D proto particle.
HitType
Calorimeter hit type enum.
MANAGED_CONTAINER< const Cluster * > ClusterList
std::unordered_set< const Cluster * > ClusterSet
StatusCode
The StatusCode enum.
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList