Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
GeometryManager.cc
Go to the documentation of this file.
1
10#include "Geometry/LArTPC.h"
12
14
16
17#include <algorithm>
18
19namespace pandora
20{
21
23 m_hitTypeToGranularityMap(this->GetDefaultHitTypeToGranularityMap()),
24 m_pPandora(pPandora)
25{
26}
27
28//------------------------------------------------------------------------------------------------------------------------------------------
29
34
35//------------------------------------------------------------------------------------------------------------------------------------------
36
37const SubDetector &GeometryManager::GetSubDetector(const std::string &subDetectorName) const
38{
39 SubDetectorMap::const_iterator iter = m_subDetectorMap.find(subDetectorName);
40
41 if (m_subDetectorMap.end() == iter)
42 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
43
44 return *(iter->second);
45}
46
47//------------------------------------------------------------------------------------------------------------------------------------------
48
50{
51 SubDetectorTypeMap::const_iterator iter = m_subDetectorTypeMap.find(subDetectorType);
52
53 if (m_subDetectorTypeMap.end() == iter)
54 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
55
56 if (m_subDetectorTypeMap.count(subDetectorType) != 1)
57 throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
58
59 return *(iter->second);
60}
61
62//------------------------------------------------------------------------------------------------------------------------------------------
63
65{
66 if (1 != m_larTPCMap.size())
67 throw StatusCodeException(STATUS_CODE_OUT_OF_RANGE);
68
69 return *(m_larTPCMap.begin()->second);
70}
71
72//------------------------------------------------------------------------------------------------------------------------------------------
73
75{
76 HitTypeToGranularityMap::const_iterator iter = m_hitTypeToGranularityMap.find(hitType);
77
78 if (m_hitTypeToGranularityMap.end() != iter)
79 return iter->second;
80
81 std::cout << "GeometryManager: specified hitType must be registered with a specific granularity. See PandoraApi.h " << std::endl;
82 throw StatusCodeException(STATUS_CODE_NOT_FOUND);
83}
84
85//------------------------------------------------------------------------------------------------------------------------------------------
86
89{
90 const SubDetector *pSubDetector = nullptr;
91
92 try
93 {
94 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, factory.Create(parameters, pSubDetector));
95
96 if (!m_subDetectorMap.insert(SubDetectorMap::value_type(pSubDetector->GetSubDetectorName(), pSubDetector)).second)
97 throw StatusCodeException(STATUS_CODE_FAILURE);
98
99 m_subDetectorTypeMap.insert(SubDetectorTypeMap::value_type(pSubDetector->GetSubDetectorType(), pSubDetector));
100 }
101 catch (StatusCodeException &statusCodeException)
102 {
103 std::cout << "Failed to create sub detector: " << statusCodeException.ToString() << std::endl;
104 delete pSubDetector;
105 pSubDetector = nullptr;
106 return statusCodeException.GetStatusCode();
107 }
108
109 return STATUS_CODE_SUCCESS;
110}
111
112//------------------------------------------------------------------------------------------------------------------------------------------
113
116{
117 const LArTPC *pLArTPC = nullptr;
118
119 try
120 {
121 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, factory.Create(parameters, pLArTPC));
122
123 if (!m_larTPCMap.insert(LArTPCMap::value_type(pLArTPC->GetLArTPCVolumeId(), pLArTPC)).second)
124 throw StatusCodeException(STATUS_CODE_FAILURE);
125 }
126 catch (StatusCodeException &statusCodeException)
127 {
128 std::cout << "Failed to create lar tpc: " << statusCodeException.ToString() << std::endl;
129 delete pLArTPC;
130 pLArTPC = nullptr;
131 return statusCodeException.GetStatusCode();
132 }
133
134 return STATUS_CODE_SUCCESS;
135}
136
137//------------------------------------------------------------------------------------------------------------------------------------------
138
139template <typename PARAMETERS, typename OBJECT>
141{
142 const OBJECT *pDetectorGap = nullptr;
143
144 try
145 {
146 PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, factory.Create(parameters, pDetectorGap));
147
148 if (!pDetectorGap)
149 return STATUS_CODE_FAILURE;
150
151 m_detectorGapList.push_back(pDetectorGap);
152 return STATUS_CODE_SUCCESS;
153 }
154 catch (StatusCodeException &statusCodeException)
155 {
156 std::cout << "Failed to create gap: " << statusCodeException.ToString() << std::endl;
157 delete pDetectorGap;
158 pDetectorGap = nullptr;
159 return statusCodeException.GetStatusCode();
160 }
161}
162
163//------------------------------------------------------------------------------------------------------------------------------------------
164
166{
167 for (const SubDetectorMap::value_type &mapEntry : m_subDetectorMap)
168 delete mapEntry.second;
169
170 for (const LArTPCMap::value_type &mapEntry : m_larTPCMap)
171 delete mapEntry.second;
172
173 for (const DetectorGap *const pDetectorGap : m_detectorGapList)
174 delete pDetectorGap;
175
176 m_subDetectorMap.clear();
177 m_larTPCMap.clear();
178 m_subDetectorTypeMap.clear();
179 m_detectorGapList.clear();
181
182 return STATUS_CODE_SUCCESS;
183}
184
185//------------------------------------------------------------------------------------------------------------------------------------------
186
188{
189 HitTypeToGranularityMap hitTypeToGranularityMap;
190
191 if (!hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(TRACKER, VERY_FINE)).second ||
192 !hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(ECAL, FINE)).second ||
193 !hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(HCAL, COARSE)).second ||
194 !hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(MUON, VERY_COARSE)).second ||
195 !hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(TPC_VIEW_U, VERY_FINE)).second ||
196 !hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(TPC_VIEW_V, VERY_FINE)).second ||
197 !hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(TPC_VIEW_W, VERY_FINE)).second ||
198 !hitTypeToGranularityMap.insert(HitTypeToGranularityMap::value_type(TPC_3D, VERY_FINE)).second)
199 {
200 throw StatusCodeException(STATUS_CODE_FAILURE);
201 }
202
203 return hitTypeToGranularityMap;
204}
205
206//------------------------------------------------------------------------------------------------------------------------------------------
207
209{
210 HitTypeToGranularityMap::iterator iter = m_hitTypeToGranularityMap.find(hitType);
211
212 if (m_hitTypeToGranularityMap.end() != iter)
213 {
214 iter->second = granularity;
215 }
216 else
217 {
218 m_hitTypeToGranularityMap[hitType] = granularity;
219 }
220
221 return STATUS_CODE_SUCCESS;
222}
223
224//------------------------------------------------------------------------------------------------------------------------------------------
225//------------------------------------------------------------------------------------------------------------------------------------------
226
230
231} // namespace pandora
Header file for the detector gap class.
Header file for the geometry manager class.
Header file for the lar tpc class.
Header file for the object factory class.
#define PANDORA_THROW_RESULT_IF(StatusCode1, Operator, Command)
Definition StatusCodes.h:43
Header file for the sub detector class.
DetectorGap class.
Definition DetectorGap.h:25
SubDetectorMap m_subDetectorMap
Map from sub detector name to sub detector.
HitTypeToGranularityMap m_hitTypeToGranularityMap
The hit type to granularity map.
StatusCode SetHitTypeGranularity(const HitType hitType, const Granularity granularity)
Set the granularity level to be associated with a specified hit type.
LArTPCMap m_larTPCMap
Map from lar tpc volume id to lar tpc.
DetectorGapList m_detectorGapList
List of gaps in the active detector volume.
const SubDetector & GetSubDetector(const std::string &subDetectorName) const
Get the sub detector corresponding to a specified name.
StatusCode CreateSubDetector(const object_creation::Geometry::SubDetector::Parameters &parameters, const ObjectFactory< object_creation::Geometry::SubDetector::Parameters, object_creation::Geometry::SubDetector::Object > &factory)
Create sub detector.
HitTypeToGranularityMap GetDefaultHitTypeToGranularityMap() const
Get the default hit type to granularity map.
std::map< HitType, Granularity > HitTypeToGranularityMap
StatusCode EraseAllContent()
Erase all geometry manager content.
SubDetectorTypeMap m_subDetectorTypeMap
Map from sub detector type to sub detector.
Granularity GetHitTypeGranularity(const HitType hitType) const
Get the granularity level specified for a given calorimeter hit type.
GeometryManager(const Pandora *const pPandora)
Constructor.
StatusCode CreateGap(const PARAMETERS &parameters, const ObjectFactory< PARAMETERS, OBJECT > &factory)
Create gap.
StatusCode CreateLArTPC(const object_creation::Geometry::LArTPC::Parameters &parameters, const ObjectFactory< object_creation::Geometry::LArTPC::Parameters, object_creation::Geometry::LArTPC::Object > &factory)
Create lar tpc.
const LArTPC & GetLArTPC() const
If there is exactly one registered lar tpc instance, return it; else raise an exception.
LArTPC class.
Definition LArTPC.h:26
unsigned int GetLArTPCVolumeId() const
Get the lar volume id, uniquely specifying the lar tpc.
Definition LArTPC.h:168
ObjectFactory class responsible for extended pandora object creation.
virtual StatusCode Create(const Parameters &parameters, const Object *&pObject) const =0
Create an object with the given parameters.
Pandora class.
Definition Pandora.h:40
StatusCodeException class.
std::string ToString() const
Get status code as a string.
StatusCode GetStatusCode() const
Get status code.
SubDetector class.
Definition SubDetector.h:26
const std::string & GetSubDetectorName() const
Get the sub detector name, uniquely specifying the sub detector.
SubDetectorType GetSubDetectorType() const
Get the sub detector type, e.g. ECAL_BARREL, HCAL_ENDCAP, TPC, etc.
HitType
Calorimeter hit type enum.
Granularity
Granularity enum.
StatusCode
The StatusCode enum.
SubDetectorType
Subdetector type enum.