Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
EnergyCorrectionsPlugin.cc
Go to the documentation of this file.
1
9#include "Helpers/XmlHelper.h"
10
11#include "Objects/Cluster.h"
12
14
15namespace pandora
16{
17
18StatusCode EnergyCorrections::MakeEnergyCorrections(const Cluster *const pCluster, float &correctedElectromagneticEnergy,
19 float &correctedHadronicEnergy) const
20{
21 correctedHadronicEnergy = pCluster->GetHadronicEnergy();
22
23 for (const EnergyCorrectionPlugin *const pPlugin : m_hadEnergyCorrectionPlugins)
24 {
25 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, pPlugin->MakeEnergyCorrections(pCluster, correctedHadronicEnergy));
26 }
27
28 correctedElectromagneticEnergy = pCluster->GetElectromagneticEnergy();
29
30 for (const EnergyCorrectionPlugin *const pPlugin : m_emEnergyCorrectionPlugins)
31 {
32 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, pPlugin->MakeEnergyCorrections(pCluster, correctedElectromagneticEnergy));
33 }
34
35 return STATUS_CODE_SUCCESS;
36}
37
38//------------------------------------------------------------------------------------------------------------------------------------------
39
41 m_pPandora(pPandora)
42{
43}
44
45//------------------------------------------------------------------------------------------------------------------------------------------
46
48{
49 for (const EnergyCorrectionPluginMap::value_type &mapEntry : m_hadEnergyCorrectionPluginMap)
50 delete mapEntry.second;
51
52 for (const EnergyCorrectionPluginMap::value_type &mapEntry : m_emEnergyCorrectionPluginMap)
53 delete mapEntry.second;
54
59}
60
61//------------------------------------------------------------------------------------------------------------------------------------------
62
63StatusCode EnergyCorrections::RegisterPlugin(const std::string &name, const EnergyCorrectionType energyCorrectionType,
64 EnergyCorrectionPlugin *const pEnergyCorrectionPlugin)
65{
66 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, pEnergyCorrectionPlugin->RegisterDetails(m_pPandora, name, name));
67
68 EnergyCorrectionPluginMap &energyCorrectionPluginMap(this->GetEnergyCorrectionPluginMap(energyCorrectionType));
69
70 if (!energyCorrectionPluginMap.insert(EnergyCorrectionPluginMap::value_type(name, pEnergyCorrectionPlugin)).second)
71 return STATUS_CODE_ALREADY_PRESENT;
72
73 return STATUS_CODE_SUCCESS;
74}
75
76//------------------------------------------------------------------------------------------------------------------------------------------
77
79{
80 for (EnergyCorrectionPluginMap::value_type &mapEntry : m_hadEnergyCorrectionPluginMap)
81 {
82 TiXmlElement *const pXmlElement(pXmlHandle->FirstChild(mapEntry.first).Element());
83 if (nullptr != pXmlElement)
84 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->ReadSettings(TiXmlHandle(pXmlElement)));
85
86 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->Initialize());
87 }
88
89 for (EnergyCorrectionPluginMap::value_type &mapEntry : m_emEnergyCorrectionPluginMap)
90 {
91 TiXmlElement *const pXmlElement(pXmlHandle->FirstChild(mapEntry.first).Element());
92
93 if (nullptr != pXmlElement)
94 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->ReadSettings(TiXmlHandle(pXmlElement)));
95
96 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->Initialize());
97 }
98
99 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->InitializePlugin(pXmlHandle,
100 "HadronicEnergyCorrectionPlugins", HADRONIC, m_hadEnergyCorrectionPlugins));
101
102 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, this->InitializePlugin(pXmlHandle,
103 "ElectromagneticEnergyCorrectionPlugins", ELECTROMAGNETIC, m_emEnergyCorrectionPlugins));
104
105 return STATUS_CODE_SUCCESS;
106}
107
108//------------------------------------------------------------------------------------------------------------------------------------------
109
110StatusCode EnergyCorrections::InitializePlugin(const TiXmlHandle *const pXmlHandle, const std::string &xmlTagName,
111 const EnergyCorrectionType energyCorrectionType, EnergyCorrectionPluginVector &energyCorrectionPluginVector)
112{
113 if (!energyCorrectionPluginVector.empty())
114 return STATUS_CODE_FAILURE;
115
116 StringVector requestedPluginNames;
117 PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadVectorOfValues(*pXmlHandle,
118 xmlTagName, requestedPluginNames));
119
120 EnergyCorrectionPluginMap &energyCorrectionPluginMap(this->GetEnergyCorrectionPluginMap(energyCorrectionType));
121
122 for (const std::string &requestedPluginName : requestedPluginNames)
123 {
124 EnergyCorrectionPluginMap::const_iterator mapIter = energyCorrectionPluginMap.find(requestedPluginName);
125
126 if (energyCorrectionPluginMap.end() == mapIter)
127 return STATUS_CODE_NOT_FOUND;
128
129 energyCorrectionPluginVector.push_back(mapIter->second);
130 }
131
132 return STATUS_CODE_SUCCESS;
133}
134
135//------------------------------------------------------------------------------------------------------------------------------------------
136
138{
139 switch (energyCorrectionType)
140 {
141 case HADRONIC:
143
144 case ELECTROMAGNETIC:
146
147 default:
148 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
149 }
150}
151
152//------------------------------------------------------------------------------------------------------------------------------------------
153
155{
156 for (const EnergyCorrectionPluginMap::value_type &mapEntry : m_hadEnergyCorrectionPluginMap)
157 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->Reset());
158
159 for (const EnergyCorrectionPluginMap::value_type &mapEntry : m_emEnergyCorrectionPluginMap)
160 PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, mapEntry.second->Reset());
161
162 return STATUS_CODE_SUCCESS;
163}
164
165} // namespace pandora
Header file for the cluster class.
Header file for the calo hit 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
float GetHadronicEnergy() const
Get the sum of hadronic energy measures of all constituent calo hits, units GeV.
Definition Cluster.h:526
float GetElectromagneticEnergy() const
Get the sum of electromagnetic energy measures of all constituent calo hits, units GeV.
Definition Cluster.h:519
EnergyCorrectionPlugin class.
StatusCode InitializePlugin(const TiXmlHandle *const pXmlHandle, const std::string &xmlTagName, const EnergyCorrectionType energyCorrectionType, EnergyCorrectionPluginVector &energyCorrectionPluginVector)
Read requested plugin names/labels from a specified xml tag and attempt to assign the plugin pointers...
EnergyCorrectionPluginMap m_hadEnergyCorrectionPluginMap
The hadronic energy correction plugin map.
std::vector< EnergyCorrectionPlugin * > EnergyCorrectionPluginVector
StatusCode ResetForNextEvent()
Call the reset callback in all managed plugins.
StatusCode RegisterPlugin(const std::string &pluginName, const EnergyCorrectionType energyCorrectionType, EnergyCorrectionPlugin *const pEnergyCorrectionPlugin)
Register an energy correction plugin.
std::map< std::string, EnergyCorrectionPlugin * > EnergyCorrectionPluginMap
EnergyCorrectionPluginVector m_emEnergyCorrectionPlugins
The final electromagnetic energy correction plugin vector.
StatusCode InitializePlugins(const TiXmlHandle *const pXmlHandle)
Initialize plugins.
StatusCode MakeEnergyCorrections(const Cluster *const pCluster, float &correctedElectromagneticEnergy, float &correctedHadronicEnergy) const
Make an ordered list of energy corrections to a cluster.
EnergyCorrectionPluginMap m_emEnergyCorrectionPluginMap
The electromagnetic energy correction plugin map.
const Pandora *const m_pPandora
Address of the associated pandora instance.
EnergyCorrections(const Pandora *const pPandora)
Default constructor.
EnergyCorrectionPluginVector m_hadEnergyCorrectionPlugins
The final hadronic energy correction plugin vector.
EnergyCorrectionPluginMap & GetEnergyCorrectionPluginMap(const EnergyCorrectionType energyCorrectionType)
Get the energy correction plugin map corresponding to the specified energy correction type.
Pandora class.
Definition Pandora.h:40
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
StatusCodeException class.
TiXmlElement * Element() const
Definition tinyxml.h:1710
TiXmlHandle FirstChild() const
Return a handle to the first child node.
Definition tinyxml.cc:1635
static StatusCode ReadVectorOfValues(const TiXmlHandle &xmlHandle, const std::string &xmlElementName, std::vector< T > &vector)
Read a vector of values from a (space separated) list in an xml element.
Definition XmlHelper.h:229
std::vector< std::string > StringVector
EnergyCorrectionType
Energy correction type enum.
StatusCode
The StatusCode enum.