Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
ParticleIdPlugin.cc
Go to the documentation of this file.
1
9#include "Helpers/XmlHelper.h"
10
11#include "Objects/Cluster.h"
13
14#include "Pandora/PdgTable.h"
15
17
18#include <cstdlib>
19
20namespace pandora
21{
22
23template <typename T>
24bool ParticleId::IsEmShower(const T *const pT) const
25{
27 return false;
28
29 return m_pEmShowerPlugin->IsMatch(pT);
30}
31
32//------------------------------------------------------------------------------------------------------------------------------------------
33
34template <typename T>
35bool ParticleId::IsPhoton(const T *const pT) const
36{
37 if (!m_pPhotonPlugin)
38 return false;
39
40 return m_pPhotonPlugin->IsMatch(pT);
41}
42
43//------------------------------------------------------------------------------------------------------------------------------------------
44
45template <typename T>
46bool ParticleId::IsElectron(const T *const pT) const
47{
49 return false;
50
51 return m_pElectronPlugin->IsMatch(pT);
52}
53
54//------------------------------------------------------------------------------------------------------------------------------------------
55
56template <typename T>
57bool ParticleId::IsMuon(const T *const pT) const
58{
59 if (!m_pMuonPlugin)
60 return false;
61
62 return m_pMuonPlugin->IsMatch(pT);
63}
64
65//------------------------------------------------------------------------------------------------------------------------------------------
66
67ParticleId::ParticleId(const Pandora *const pPandora) :
68 m_pPandora(pPandora),
69 m_pEmShowerPlugin(nullptr),
70 m_pPhotonPlugin(nullptr),
71 m_pElectronPlugin(nullptr),
72 m_pMuonPlugin(nullptr)
73{
74}
75
76//------------------------------------------------------------------------------------------------------------------------------------------
77
79{
80 for (const ParticleIdPluginMap::value_type &mapEntry : m_particleIdPluginMap)
81 delete mapEntry.second;
82
84 m_pEmShowerPlugin = nullptr;
85 m_pPhotonPlugin = nullptr;
86 m_pElectronPlugin = nullptr;
87 m_pMuonPlugin = nullptr;
88}
89
90//------------------------------------------------------------------------------------------------------------------------------------------
91
92StatusCode ParticleId::RegisterPlugin(const std::string &name, ParticleIdPlugin *const pParticleIdPlugin)
93{
94 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, pParticleIdPlugin->RegisterDetails(m_pPandora, name, name));
95
96 if (!m_particleIdPluginMap.insert(ParticleIdPluginMap::value_type(name, pParticleIdPlugin)).second)
97 return STATUS_CODE_ALREADY_PRESENT;
98
99 return STATUS_CODE_SUCCESS;
100}
101
102//------------------------------------------------------------------------------------------------------------------------------------------
103
105{
106 for (const ParticleIdPluginMap::value_type &mapEntry : m_particleIdPluginMap)
107 {
108 TiXmlElement *pXmlElement(pXmlHandle->FirstChild(mapEntry.first).Element());
109
110 if (nullptr != pXmlElement)
111 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->ReadSettings(TiXmlHandle(pXmlElement)));
112
113 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->Initialize());
114 }
115
116 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->InitializePlugin(pXmlHandle, "EmShowerPlugin", m_pEmShowerPlugin));
117 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->InitializePlugin(pXmlHandle, "PhotonPlugin", m_pPhotonPlugin));
118 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->InitializePlugin(pXmlHandle, "ElectronPlugin", m_pElectronPlugin));
119 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->InitializePlugin(pXmlHandle, "MuonPlugin", m_pMuonPlugin));
120
121 return STATUS_CODE_SUCCESS;
122}
123
124//------------------------------------------------------------------------------------------------------------------------------------------
125
126StatusCode ParticleId::InitializePlugin(const TiXmlHandle *const pXmlHandle, const std::string &xmlTagName, ParticleIdPlugin *&pParticleIdPlugin)
127{
128 if (nullptr != pParticleIdPlugin)
129 return STATUS_CODE_FAILURE;
130
131 std::string requestedPluginName;
132 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(*pXmlHandle,
133 xmlTagName, requestedPluginName));
134
135 if (requestedPluginName.empty())
136 return STATUS_CODE_SUCCESS;
137
138 ParticleIdPluginMap::const_iterator mapIter = m_particleIdPluginMap.find(requestedPluginName);
139
140 if (m_particleIdPluginMap.end() == mapIter)
141 return STATUS_CODE_NOT_FOUND;
142
143 pParticleIdPlugin = mapIter->second;
144 return STATUS_CODE_SUCCESS;
145}
146
147//------------------------------------------------------------------------------------------------------------------------------------------
148
150{
151 for (const ParticleIdPluginMap::value_type &mapEntry : m_particleIdPluginMap)
152 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->Reset());
153
154 return STATUS_CODE_SUCCESS;
155}
156
157//------------------------------------------------------------------------------------------------------------------------------------------
158//------------------------------------------------------------------------------------------------------------------------------------------
159
160template bool ParticleId::IsEmShower(const Cluster *const ) const;
161template bool ParticleId::IsPhoton(const Cluster *const ) const;
162template bool ParticleId::IsElectron(const Cluster *const ) const;
163template bool ParticleId::IsMuon(const Cluster *const ) const;
164
165template bool ParticleId::IsEmShower(const ParticleFlowObject *const ) const;
166template bool ParticleId::IsPhoton(const ParticleFlowObject *const ) const;
167template bool ParticleId::IsElectron(const ParticleFlowObject *const ) const;
168template bool ParticleId::IsMuon(const ParticleFlowObject *const ) const;
169
170} // namespace pandora
Header file for the cluster class.
Header file for the particle flow object class.
Header file for the particle id plugin class.
#define PANDORA_RETURN_RESULT_IF_AND_IF(StatusCode1, StatusCode2, Operator, Command)
Definition StatusCodes.h:31
#define PANDORA_RETURN_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:19
Header file for the xml helper class.
Cluster class.
Definition Cluster.h:31
Pandora class.
Definition Pandora.h:40
ParticleFlowObject class.
bool IsElectron(const T *const pT) const
Provide identification of whether a cluster or pfo is an electron.
ParticleId(const Pandora *const pPandora)
Default constructor.
ParticleIdPlugin * m_pElectronPlugin
The electron id plugin pointer.
ParticleIdPlugin * m_pEmShowerPlugin
The electromagnetic shower id plugin pointer.
bool IsEmShower(const T *const pT) const
Provide identification of whether a cluster or pfo is an electromagnetic shower.
StatusCode ResetForNextEvent()
Call the reset callback in all managed plugins.
ParticleIdPlugin * m_pPhotonPlugin
The photon id plugin pointer.
bool IsMuon(const T *const pT) const
Provide identification of whether a cluster or pfo is a muon.
ParticleIdPluginMap m_particleIdPluginMap
The particle id plugin map.
bool IsPhoton(const T *const pT) const
Provide identification of whether a cluster or pfo is a photon.
ParticleIdPlugin * m_pMuonPlugin
The muon id plugin pointer.
const Pandora *const m_pPandora
Address of the associated pandora instance.
StatusCode RegisterPlugin(const std::string &pluginName, ParticleIdPlugin *const pParticleIdPlugin)
Register a particle id plugin.
StatusCode InitializePlugin(const TiXmlHandle *const pXmlHandle, const std::string &xmlTagName, ParticleIdPlugin *&pParticleIdPlugin)
Read requested plugin name/label from a specified xml tag and attempt to assign the plugin pointer as...
StatusCode InitializePlugins(const TiXmlHandle *const pXmlHandle)
Initialize plugins.
ParticleIdPlugin class.
virtual bool IsMatch(const Cluster *const pCluster) const =0
Whether the cluster matches the specific particle hypothesis.
StatusCode RegisterDetails(const Pandora *const pPandora, const std::string &type, const std::string &instanceName)
Register i) the pandora instance that will run the process and ii) the process type.
Definition Process.h:146
TiXmlElement * Element() const
Definition tinyxml.h:1710
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition tinyxml.cc:1635
static StatusCode ReadValue(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, T &t)
Read a value from an xml element.
Definition XmlHelper.h:136
StatusCode
The StatusCode enum.