ATLAS Offline Software
Loading...
Searching...
No Matches
CaloBlueprintNodeBuilder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
9#include "Acts/Geometry/Blueprint.hpp"
10#include "Acts/Geometry/PortalShell.hpp"
11#include "Acts/Geometry/Volume.hpp"
12#include "Acts/Geometry/StaticBlueprintNode.hpp"
13#include "Acts/Geometry/GeometryIdentifierBlueprintNode.hpp"
14#include <Acts/Navigation/SurfaceArrayNavigationPolicy.hpp>
15#include <Acts/Navigation/TryAllNavigationPolicy.hpp>
16#include <Acts/Utilities/AxisDefinitions.hpp>
17#include <Acts/Geometry/ContainerBlueprintNode.hpp>
18#include <Acts/Geometry/Extent.hpp>
19#include <Acts/Definitions/Units.hpp>
20#include <Acts/Geometry/LayerBlueprintNode.hpp>
21#include <Acts/Geometry/VolumeResizeStrategy.hpp>
22#include <Acts/Geometry/VolumeAttachmentStrategy.hpp>
23#include <Acts/Geometry/TrackingVolume.hpp>
24#include <Acts/Geometry/CylinderVolumeBounds.hpp>
25
27
28#include <Acts/Surfaces/SurfaceArray.hpp>
30
31using namespace Acts;
32using namespace Acts::Experimental;
33using namespace Acts::UnitLiterals;
34using AttachmentStrategy = Acts::VolumeAttachmentStrategy;
35using ResizeStrategy = Acts::VolumeResizeStrategy;
36
37using namespace ActsTrk::detail::GeoVolIds;
38
40 ATH_MSG_DEBUG("Initializing CaloBlueprintNodeBuilder");
41
43
44 return StatusCode::SUCCESS;
45}
46
47std::shared_ptr<BlueprintNode> ActsTrk::CaloBlueprintNodeBuilder::buildBlueprintNode(const GeometryContext& /*gctx*/,
48 std::shared_ptr<BlueprintNode>&& childNode) {
49
50
51 std::map<caloRegion, caloSampleSurfaceMap_t> caloRegionSampleSurfaceMap;
52 std::map<caloRegion, caloSampleDDEElementsMap_t> caloRegionSampleDDEElementsMap;
53
54 fillMaps(caloRegionSampleSurfaceMap, caloRegionSampleDDEElementsMap);
55
56 ATH_MSG_DEBUG("Have filled first two maps");
57
58 generateCylinderSurfaces(caloRegionSampleSurfaceMap[caloRegion::CylinderSymmetricZZero], caloRegionSampleDDEElementsMap[caloRegion::CylinderSymmetricZZero],false);
59 generateCylinderSurfaces(caloRegionSampleSurfaceMap[caloRegion::CylinderNegativeZ], caloRegionSampleDDEElementsMap[caloRegion::CylinderNegativeZ],true);
60 generateCylinderSurfaces(caloRegionSampleSurfaceMap[caloRegion::CylinderPositiveZ], caloRegionSampleDDEElementsMap[caloRegion::CylinderPositiveZ],true);
61 generateDiscSurfaces(caloRegionSampleSurfaceMap[caloRegion::DiscNegativeZ], caloRegionSampleDDEElementsMap[caloRegion::DiscNegativeZ]);
62 generateDiscSurfaces(caloRegionSampleSurfaceMap[caloRegion::DiscPositiveZ], caloRegionSampleDDEElementsMap[caloRegion::DiscPositiveZ]);
63
64 ATH_MSG_DEBUG("Have generated calorimeter cylindrical surfaces");
65
66 // The calo node is a container node that will hold the itk and calo nodes as children.
67 // The calo cylinder is static in order to avoid merging issues with the itk portals
68 // that are supposed to carry material.
69 // Given this node expands to encompass the sub-nodes added, we set the dimensions to nominal
70 // values of 0,100,100.
71 std::shared_ptr<StaticBlueprintNode> itkCaloNode{};
72 {
74 auto envelope = std::make_unique<TrackingVolume>(Amg::Transform3D::Identity(),
75 std::make_shared<CylinderVolumeBounds>(0., 4250.0, 6779.0),"ITkCalo");
76 envelope->assignGeometryId(Acts::GeometryIdentifier{}.withVolume(s_caloEnvelopeID));
77 itkCaloNode = std::make_shared<StaticBlueprintNode>(std::move(envelope));
78 }
79 if (childNode) {
80 itkCaloNode->addChild(std::move(childNode));
81 }
82
83 ATH_MSG_DEBUG("Top level calorimeter node created");
84
85 auto caloNode = std::make_shared<CylinderContainerBlueprintNode>("CaloNode", AxisDirection::AxisZ);
86 CylinderContainerBlueprintNode& caloBarrelCylinderNode = caloNode->addCylinderContainer("CaloBarrelSymmetricZZeroCylinders", AxisDirection::AxisR);
87 caloBarrelCylinderNode.setAttachmentStrategy(VolumeAttachmentStrategy::Gap);
88 caloBarrelCylinderNode.setResizeStrategy(ResizeStrategy::Gap);
89
90 ATH_MSG_DEBUG("EM Barrel container node created");
91
92 //Barrel cylinders symmetric about z = 0
93 for (unsigned int sampleIndex = 0; sampleIndex < m_caloCylinderSymmetricSampleList.size(); ++sampleIndex) {
94 auto& sampleName = m_caloCylinderSymmetricSampleList.at(sampleIndex).first;
95 addCylindricalTrackingVolumeToCaloNode(caloBarrelCylinderNode, sampleName, caloRegionSampleSurfaceMap[caloRegion::CylinderSymmetricZZero].at({sampleName, getSampleEnum(sampleName)}), sampleIndex, false);
96 }
97
98 //now do asymmetric cylinders, first negative z
99
100 CylinderContainerBlueprintNode& caloBarrelCylinderNegativeZNode = caloNode->addCylinderContainer("CaloBarrelNegativeZAsymmetricCylinders", AxisDirection::AxisR);
101 caloBarrelCylinderNegativeZNode.setAttachmentStrategy(VolumeAttachmentStrategy::Gap);
102 caloBarrelCylinderNegativeZNode.setResizeStrategy(ResizeStrategy::Gap);
103
104 //then positive z
105 CylinderContainerBlueprintNode& caloBarrelCylinderPositiveZNode = caloNode->addCylinderContainer("CaloBarrelPositiveZAsymmetricCylinders", AxisDirection::AxisR);
106 caloBarrelCylinderPositiveZNode.setAttachmentStrategy(VolumeAttachmentStrategy::Gap);
107 caloBarrelCylinderPositiveZNode.setResizeStrategy(ResizeStrategy::Gap);
108
109 for (unsigned int sampleIndex = 0; sampleIndex < m_caloCylinderAsymmetricSampleList.size(); ++sampleIndex) {
110 auto& sampleName = m_caloCylinderAsymmetricSampleList.at(sampleIndex).first;
111 //We only add TileGap1 and 2 here, because the TileExt0,1,2
112 //will need a special treatment to avoid clashes in Z.
113 if (sampleIndex < 2){
114 addCylindricalTrackingVolumeToCaloNode(caloBarrelCylinderNegativeZNode, sampleName+"NegZ", caloRegionSampleSurfaceMap[caloRegion::CylinderNegativeZ].at({sampleName, getSampleEnum(sampleName)}), sampleIndex+m_caloCylinderSymmetricSampleList.size(), false);
115 addCylindricalTrackingVolumeToCaloNode(caloBarrelCylinderPositiveZNode, sampleName+"PosZ", caloRegionSampleSurfaceMap[caloRegion::CylinderPositiveZ].at({sampleName, getSampleEnum(sampleName)}), sampleIndex+m_caloCylinderSymmetricSampleList.size()+m_caloCylinderAsymmetricSampleList.size(), false);
116 }
117 else{
118 //Tile extended barrel surfaces must be added to top level node directly because they always overlap in R
119 //or Z with other calorimeter surfaces, volumes etc.
120 //Note there is a speed penalty to do it this way.
121 itkCaloNode->addLayer(sampleName+"NegZ" + "_Layer", [&](auto& layer) {
122 layer.setSurfaces(caloRegionSampleSurfaceMap[caloRegion::CylinderNegativeZ].at({sampleName, getSampleEnum(sampleName)}));
123 layer.setEnvelope(Acts::ExtentEnvelope{{
124 .z = {0.1_mm, 0.1_mm},
125 .r = {2_mm, 2_mm},
126 }});
127 });
128 itkCaloNode->addLayer(sampleName+"PosZ" + "_Layer", [&](auto& layer) {
129 layer.setSurfaces(caloRegionSampleSurfaceMap[caloRegion::CylinderPositiveZ].at({sampleName, getSampleEnum(sampleName)}));
130 layer.setEnvelope(Acts::ExtentEnvelope{{
131 .z = {0.1_mm, 0.1_mm},
132 .r = {2_mm, 2_mm},
133 }});
134 });
135 }
136 }
137
138
139 CylinderContainerBlueprintNode& caloEndCapDiscNegativeZNode = caloNode->addCylinderContainer("CaloEndCapDiscNegativeZ", AxisDirection::AxisZ);
140 caloEndCapDiscNegativeZNode.setAttachmentStrategy(VolumeAttachmentStrategy::Gap);
141 // The -z end of this container defines the calorimeter's global minZ, so the
142 // enclosing envelope's -z edge coincides with this container's own -z edge to
143 // within floating-point rounding. With ResizeStrategy::Gap on that side, the
144 // resize mints a degenerate (~1e-13 mm) end-gap volume whose two disc faces
145 // coincide, which CylinderNavigationPolicy cannot resolve. Expand the
146 // outermost wheel on the boundary (-z) side instead; keep Gap on the interior
147 // (+z) side. NOTE: (inner, outer) map to (minZ, maxZ) for an AxisZ stack.
148 caloEndCapDiscNegativeZNode.setResizeStrategies(ResizeStrategy::Expand, ResizeStrategy::Gap);
149
150 CylinderContainerBlueprintNode& caloEndCapDiscPositiveZNode = caloNode->addCylinderContainer("CaloEndCapDiscPositiveZ", AxisDirection::AxisZ);
151 caloEndCapDiscPositiveZNode.setAttachmentStrategy(VolumeAttachmentStrategy::Gap);
152 // Mirror of the negative endcap: the +z (maxZ, outer) end is the global maxZ
153 // boundary, so Expand there and keep Gap on the interior (-z) side.
154 caloEndCapDiscPositiveZNode.setResizeStrategies(ResizeStrategy::Gap, ResizeStrategy::Expand);
155
156 for (unsigned int sampleIndex = 0; sampleIndex < m_caloDiscSampleList.size(); ++sampleIndex) {
157 auto& sampleName = m_caloDiscSampleList.at(sampleIndex).first;
158 addCylindricalTrackingVolumeToCaloNode(caloEndCapDiscNegativeZNode, sampleName+"NegZ", caloRegionSampleSurfaceMap[caloRegion::DiscNegativeZ].at({sampleName, getSampleEnum(sampleName)}), sampleIndex+m_caloCylinderSymmetricSampleList.size()+(2*m_caloCylinderAsymmetricSampleList.size()), true);
159 addCylindricalTrackingVolumeToCaloNode(caloEndCapDiscPositiveZNode, sampleName+"PosZ", caloRegionSampleSurfaceMap[caloRegion::DiscPositiveZ].at({sampleName, getSampleEnum(sampleName)}), sampleIndex+m_caloCylinderSymmetricSampleList.size()+(2*m_caloCylinderAsymmetricSampleList.size())+m_caloDiscSampleList.size(), true);
160 }
161
162 ATH_MSG_DEBUG("Have added all Barrel layers to caloBarrelCylinderNode");
163
164 // Add calo barrel node to the top level calo node.
165 itkCaloNode->addChild(caloNode);
166
167 //return the top level calo node
168 return itkCaloNode;
169}
170
172 ATH_MSG_DEBUG("Finalizing CaloBlueprintNodeBuilder");
173 return StatusCode::SUCCESS;
174}
175
176void ActsTrk::CaloBlueprintNodeBuilder::fillMaps(std::map<caloRegion, caloSampleSurfaceMap_t>& caloRegionSampleSurfaceMap,
177 std::map<caloRegion, caloSampleDDEElementsMap_t>& caloRegionSampleDDEElementsMap) const {
178
179
180 //loop over all possible calo sampling layers
181 //and create empty vectors of surfaces in the map
182
183 //Create map between each calorimeter sampling and a vector of
184 //cylinder surfaces. We can have N cylinders in a given sampling,
185 //and the value of N is determined by how often the average radius
186 //calculated for a given phi ring, at fixed Z, changes by more than
187 //a tolerance value
188
189 //Use the same loop to create map bwteeen sampling and vectors of DDE
190 for (const auto & currentSample : m_caloCylinderSymmetricSampleList) {
191 caloRegionSampleSurfaceMap[caloRegion::CylinderSymmetricZZero][currentSample] = std::vector<std::shared_ptr<Surface> >();
192 caloRegionSampleDDEElementsMap[caloRegion::CylinderSymmetricZZero][currentSample] = std::vector<const CaloDetDescrElement*>();
193 }
194
195 for (const auto & currentSample : m_caloCylinderAsymmetricSampleList) {
196 caloRegionSampleSurfaceMap[caloRegion::CylinderNegativeZ][currentSample] = std::vector<std::shared_ptr<Surface> >();
197 caloRegionSampleDDEElementsMap[caloRegion::CylinderNegativeZ][currentSample] = std::vector<const CaloDetDescrElement*>();
198 caloRegionSampleSurfaceMap[caloRegion::CylinderPositiveZ][currentSample] = std::vector<std::shared_ptr<Surface> >();
199 caloRegionSampleDDEElementsMap[caloRegion::CylinderPositiveZ][currentSample] = std::vector<const CaloDetDescrElement*>();
200 }
201
202 for (const auto & currentSample : m_caloDiscSampleList) {
203 caloRegionSampleSurfaceMap[caloRegion::DiscNegativeZ][currentSample] = std::vector<std::shared_ptr<Surface> >();
204 caloRegionSampleDDEElementsMap[caloRegion::DiscNegativeZ][currentSample] = std::vector<const CaloDetDescrElement*>();
205 caloRegionSampleSurfaceMap[caloRegion::DiscPositiveZ][currentSample] = std::vector<std::shared_ptr<Surface> >();
206 caloRegionSampleDDEElementsMap[caloRegion::DiscPositiveZ][currentSample] = std::vector<const CaloDetDescrElement*>();
207 }
208
209 //for each calo sampling collect all the DDE in a vector
210 for (const CaloDetDescrElement* theDDE : m_caloDetSecrMgr->element_range()){
211 if (!theDDE){
212 ATH_MSG_ERROR("Null pointer to CaloDetDescrElement");
213 continue;
214 }
215
216 CaloCell_ID::CaloSample currentSample=theDDE->getSampling();
217 std::pair <std::string, CaloCell_ID::CaloSample> samplePair = std::make_pair(getSampleName(currentSample), currentSample);
218
219 //check if have cylinder symmetric about z = 0
221 caloRegionSampleDDEElementsMap[caloRegion::CylinderSymmetricZZero][{samplePair.first,samplePair.second}].push_back(theDDE);
222 }
223
224 //check if have cylinder asymmetric about z = 0, if so check if in negative or positive z
226 if (theDDE->z() < 0.0) {
227 caloRegionSampleDDEElementsMap[caloRegion::CylinderNegativeZ][{samplePair.first,samplePair.second}].push_back(theDDE);
228 }
229 else {
230 caloRegionSampleDDEElementsMap[caloRegion::CylinderPositiveZ][{samplePair.first,samplePair.second}].push_back(theDDE);
231 }
232 }
233
234 //check if sampling is in disc list
235 if (std::find(m_caloDiscSampleList.begin(), m_caloDiscSampleList.end(), std::make_pair(samplePair.first,samplePair.second)) != m_caloDiscSampleList.end()) {
236 //check if in negative or positive z
237 if (theDDE->z() < 0.0) {
238 caloRegionSampleDDEElementsMap[caloRegion::DiscNegativeZ][{getSampleName(currentSample), currentSample}].push_back(theDDE);
239 }
240 else {
241 caloRegionSampleDDEElementsMap[caloRegion::DiscPositiveZ][{getSampleName(currentSample), currentSample}].push_back(theDDE);
242 }
243 }
244
245 }
246
247 auto sortAllLayersInZ = [&caloRegionSampleDDEElementsMap](const std::vector<std::pair<std::string, CaloCell_ID::CaloSample>>& caloSampleList, const caloRegion& region) {
248 for (const auto & currentSample : caloSampleList) {
249 std::vector<const CaloDetDescrElement*> currentElements = caloRegionSampleDDEElementsMap[region][currentSample];
250 std::sort(currentElements.begin(), currentElements.end(), [](const CaloDetDescrElement* a, const CaloDetDescrElement* b) {return a->z() < b->z();});
251 caloRegionSampleDDEElementsMap[region][currentSample] = std::move(currentElements);
252 }
253 };
254
255 //Sort the DDE, by Z, in all possible layers
259
260 auto sortAllLayersInR = [&caloRegionSampleDDEElementsMap](const std::vector<std::pair<std::string, CaloCell_ID::CaloSample>>& caloSampleList, const caloRegion& region) {
261 for (const auto& currentSample : caloSampleList) {
262 std::vector<const CaloDetDescrElement*> currentElements = caloRegionSampleDDEElementsMap[region][currentSample];
263 std::sort(currentElements.begin(), currentElements.end(), [](const CaloDetDescrElement* a, const CaloDetDescrElement* b) {return a->r() < b->r();});
264 caloRegionSampleDDEElementsMap[region][currentSample] = std::move(currentElements);
265 }
266 };
267
268 //Sort the DDE, by R, in all possible layers
271
272}
273
274void ActsTrk::CaloBlueprintNodeBuilder::generateCylinderSurfaces(caloSampleSurfaceMap_t& caloSampleSurfaceMap, caloSampleDDEElementsMap_t& caloSampleDDEElementsMap, bool asymmetricZ) const{
275
276 std::vector<std::pair<std::string, CaloCell_ID::CaloSample>> sampleList;
277 if (asymmetricZ) sampleList = m_caloCylinderAsymmetricSampleList;
278 else sampleList = m_caloCylinderSymmetricSampleList;
279
280 for (const auto & currentSample : sampleList) {
281
282 std::vector<const CaloDetDescrElement*> currentElements = caloSampleDDEElementsMap[currentSample];
283
284 double maxLArBRadius = 0.0, minLArBRadius = std::numeric_limits<double>::max();
285 double lowZLarB = 0.0, highZLarB = 0.0;
286
287 //loop over cells runs from -z to +z in a given sampling layer
288 //There are many cells with the same z value, but different phi values
289 //We will find the average radius of the cells in a given phi ring
290 double totalRadiusFixedPhi = 0.0;
291 bool firstCellInPhiRing = true;
292 unsigned int phiCounter = 0;
293
294 //Then we will also track changes in radius as we move in Z from
295 //each ring of cells in phi to the next ring of cells in phi
296 bool firstPhiRing = true;
297 double initialRadius = 0.0;
298 double initialZ = -std::numeric_limits<double>::max();
299
300 //check if we ever move along in Z value
301 bool movedInZ = false;
302
303 for (const CaloDetDescrElement* theDDE : currentElements){
304
305 double z = theDDE->z();
306 double radius = theDDE->r();
307
308 ATH_MSG_DEBUG(" Calo Sampling is " << currentSample.first);
309
310 if (firstCellInPhiRing) {
311 ATH_MSG_DEBUG("First Cell in phi ring " << currentSample.first << " has z = " << z << " and r = " << radius);
312 initialZ = z;
313 firstCellInPhiRing = false;
314 }
315
316 if (firstPhiRing) {
317 ATH_MSG_DEBUG("First Cell in layer " << currentSample.first << " has z = " << z << " and r = " << radius);
318 initialRadius = theDDE->r();
319 firstPhiRing = false;
320 lowZLarB = z;
321 }
322
323 ATH_MSG_DEBUG("Z and initialZ are " << z << " and " << initialZ);
324
325 //if z has not changed then we add the radius to the summed radius for this phi ring
326 //and increment the counter of cells in this phi ring
327 if (std::abs(z - initialZ) < 0.0001) {
328 ATH_MSG_DEBUG("phiCounter is " << phiCounter << " and radius is " << radius << " and totalRadiusFixedPhi is " << totalRadiusFixedPhi << " and hash is " << theDDE->calo_hash());
329 totalRadiusFixedPhi += radius;
330 phiCounter++;
331 continue;
332 }
333 else {
334 movedInZ = true;
335 firstCellInPhiRing = true;
336 if (phiCounter > 0) {
337 double cellRingRadius = totalRadiusFixedPhi / phiCounter;
338 totalRadiusFixedPhi = 0.0;
339 phiCounter = 0;
340
341 if (cellRingRadius > maxLArBRadius) maxLArBRadius = radius;
342 if (cellRingRadius < minLArBRadius) minLArBRadius = radius;
343
344 //if radius changes by more than tolerance, then we will create a cylinder
345 //with the average cell radius and length from neg to pos z
346 highZLarB = z;
347 ATH_MSG_DEBUG("Values of cellRingRadius, initialRadius, highZLarB and lowZLarB are " << cellRingRadius << ", " << initialRadius << ", " << highZLarB << " and " << lowZLarB);
348 if (std::abs(cellRingRadius - initialRadius) > m_radiusTolerance && highZLarB - lowZLarB > 0.0) {
349 ATH_MSG_DEBUG("CYLINDER: Create cylinder for layer " << currentSample.first);
350 ATH_MSG_DEBUG("CYLINDER: Create Cylinder: Min and Max LAr B radius are " << minLArBRadius << " " << maxLArBRadius);
351 ATH_MSG_DEBUG("CYLINDER: Create Cylinder: Min and Max LAr B z are " << lowZLarB << " " << highZLarB);
352
353 caloSampleSurfaceMap[currentSample].push_back(generateCylinderSurface(maxLArBRadius, minLArBRadius, lowZLarB, highZLarB, asymmetricZ));
354
355 //reset the dimensions of the cylinder to the initial conditions, in
356 //preparation for the next cylinder
357 firstPhiRing = true;
358 minLArBRadius = std::numeric_limits<double>::max();
359 maxLArBRadius = 0.0;
360 lowZLarB = 0.0;
361 highZLarB = 0.0;
362 }//if radius changes by more than tolerance
363 }//if at least one cell in phi (should always be the case!)
364 else ATH_MSG_ERROR("phiCounter is zero!");
365 }//if z has changed
366 }//loop over calorimeter DDE
367
368 if (0 == caloSampleSurfaceMap[currentSample].size()){
369 //If we never found any shift in Z whilst looping over the DDE
370 //then thee min/max Z and radius were not set
371 //so we set them here.
372 if (!movedInZ) {
373 lowZLarB = initialZ;
374 highZLarB = initialZ+0.001;
375 if (phiCounter > 0) {
376 maxLArBRadius = totalRadiusFixedPhi / phiCounter;
377 minLArBRadius = 0.0;
378 }
379 }
380 ATH_MSG_DEBUG("CYLINDER: Zero size Vector: Create cylinder for layer " << currentSample.first);
381 ATH_MSG_DEBUG("CYLINDER: Create Cylinder: Min and Max LAr B radius are " << minLArBRadius << " " << maxLArBRadius);
382 ATH_MSG_DEBUG("CYLINDER: Create Cylinder: Min and Max LAr B z are " << lowZLarB << " " << highZLarB);
383 caloSampleSurfaceMap[currentSample].push_back(generateCylinderSurface(maxLArBRadius, minLArBRadius, lowZLarB, highZLarB, asymmetricZ));
384 }
385 }
386}
387
388std::shared_ptr<CylinderSurface> ActsTrk::CaloBlueprintNodeBuilder::generateCylinderSurface(const double& maxLArBRadius, const double& minLArBRadius, const double& lowZLarB, const double& highZLarB, bool asymmetricZ) const{
389
390 //Characterise the dimensions of the cylinder
391 double LArBRadius = (maxLArBRadius + minLArBRadius) / 2.0;
392 double LArBLength = std::abs(highZLarB - lowZLarB);
393
394 ATH_MSG_DEBUG("Cylinder radius and length are " << LArBRadius << " and " << LArBLength);
395
396 if (asymmetricZ) {
397 double zShift = (highZLarB + lowZLarB) / 2.0;
398 ATH_MSG_DEBUG("Cylinder is asymmetric in Z, with shift of " << zShift);
399 return Surface::makeShared<CylinderSurface>(Transform3(Translation3(0.0, 0.0, zShift)), LArBRadius, LArBLength/2);
400 }
401 else return Surface::makeShared<CylinderSurface>(Transform3::Identity(), LArBRadius, LArBLength/2);
402
403}
404
406
407 for (const auto & currentSample : m_caloDiscSampleList) {
408
409 const std::vector<const CaloDetDescrElement*> & currentElements = caloSampleDDEElementsMap[currentSample];
410
411 double totalZFixedPhi = 0.0;
412 bool firstCellInPhiRing = true;
413 unsigned int phiCounter = 0;
414
415 bool firstPhiRing = true;
416 double initialRadius = 0.0;
417 double initialZ = -std::numeric_limits<double>::max();
418
419 //loop over cells runs from -z to +z in a given sampling layer
420 //There are many cells with the same z value, but different phi values
421 //We will find a min amd max radius in this phi ring.
422 double minDiscRadius = std::numeric_limits<double>::max(), maxDiscRadius = 0.0;
423
424 unsigned int currentElementsSize = currentElements.size();
425 unsigned int DDECounter = 0;
426
427 for (const CaloDetDescrElement* theDDE : currentElements){
428
429 bool isLastDDE = (DDECounter == (currentElementsSize-1));
430
431 ATH_MSG_DEBUG("Disc DDE with sampling, r and z of " << currentSample << ", " << theDDE->r() << ", " << theDDE->z());
432 ATH_MSG_DEBUG("isLastDDE is " << isLastDDE);
433
434 double z = theDDE->z();
435 double radius = theDDE->r();
436
437 if (firstCellInPhiRing) {
438 initialRadius = radius;
439 firstCellInPhiRing = false;
440 }
441
442 if (firstPhiRing) {
443 initialZ = z;
444 firstPhiRing = false;
445 minDiscRadius = radius;
446 }
447
448 //if radius is unchanged then we add the z to the summed z for this phi ring
449 //and increment the counter of cells in this phi ring
450 if (std::abs(radius - initialRadius) < 0.0001 && !isLastDDE) {
451 totalZFixedPhi += z;
452 phiCounter++;
453 DDECounter++;
454 continue;
455 }
456 else {
457 firstCellInPhiRing = true;
458 if (phiCounter > 0) {
459 double cellRingZ = totalZFixedPhi / phiCounter;
460 totalZFixedPhi = 0.0;
461 phiCounter = 0;
462
463 //if z changes by more than tolerance, then we will create a disc
464 //with the min and max radius found
465 //if we reach the last DDE and no new surface has been created, then we also create a disc surface
466 maxDiscRadius = radius;
467 ATH_MSG_DEBUG("cellRingZ, initialZ and z tolerance are " << cellRingZ << ", " << initialZ << " and " << m_zTolerance);
468 if (std::abs(cellRingZ - initialZ) > m_zTolerance || isLastDDE) {
469 ATH_MSG_DEBUG("DISC: About to create disc surface for sampling " << currentSample);
470 caloSampleSurfaceMap[currentSample].push_back(generateDiscSurface(cellRingZ,maxDiscRadius, minDiscRadius));
471 //reset the dimensions of the disc to the initial conditions, in
472 //preparation for the next disc
473 minDiscRadius = std::numeric_limits<double>::max();
474 maxDiscRadius = 0.0;
475 firstPhiRing = true;
476 }//if z changes by more than tolerance
477 }//if at least one cell in phi (should always be the case!)
478 else ATH_MSG_ERROR("phiCounter is zero!");
479 }//if radius has changed
480 DDECounter++;
481 }//loop over calorimeter DDE
482 }//loop over calo samplings
483}
484
485std::shared_ptr<Acts::DiscSurface> ActsTrk::CaloBlueprintNodeBuilder::generateDiscSurface(const double& z, const double& maxLArBRadius, const double& minLArBRadius) const{
486
487 ATH_MSG_DEBUG("DISC: Disc min and max radius are " << minLArBRadius << " and " << maxLArBRadius << " with z of " << z);
488 auto surface = Surface::makeShared<DiscSurface>(Amg::getTranslateZ3D(z), minLArBRadius, maxLArBRadius);
489
490 return surface;
491
492}
493
494void ActsTrk::CaloBlueprintNodeBuilder::addCylindricalTrackingVolumeToCaloNode(CylinderContainerBlueprintNode& containerNode, const std::string& volumeName,const std::vector<std::shared_ptr<Acts::Surface>>& surfaces, int layerIndex, const bool& isDisc) const{
495
496 // Construct the container node with geometry identifier and layer, and add the surfaces to the layer.
497 Acts::Experimental::GeometryIdentifierBlueprintNode& geoIdNode = containerNode.withGeometryIdentifier();
498 geoIdNode.setAllVolumeIdsTo(s_caloBarrelId +
499 layerIndex);
500
501 AxisDirection axis = AxisDirection::AxisZ;
502 if (isDisc) axis = AxisDirection::AxisR;
503 CylinderContainerBlueprintNode& cylinder = geoIdNode.addCylinderContainer(volumeName,
504 axis);
505
506 cylinder.addLayer(volumeName + "_Layer", [&](auto& layer) {
507 layer.setSurfaces(surfaces);
508 layer.setEnvelope(Acts::ExtentEnvelope{{
509 .z = {0.1_mm, 0.1_mm},
510 .r = {2_mm, 2_mm},
511 }});
512 });
513
514}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Acts::VolumeResizeStrategy ResizeStrategy
Acts::VolumeAttachmentStrategy AttachmentStrategy
std::map< std::pair< std::string, CaloCell_ID::CaloSample >, std::vector< std::shared_ptr< Acts::Surface > > > caloSampleSurfaceMap_t
std::map< std::pair< std::string, CaloCell_ID::CaloSample >, std::vector< const CaloDetDescrElement * > > caloSampleDDEElementsMap_t
std::unique_ptr< CaloDetDescrManager > buildCaloDetDescrNoAlign(ISvcLocator *svcLocator, IMessageSvc *msgSvc)
static Double_t a
size_t size() const
Number of registered mappings.
#define z
void fillMaps(std::map< caloRegion, caloSampleSurfaceMap_t > &caloRegionSampleSurfaceMap, std::map< caloRegion, caloSampleDDEElementsMap_t > &caloRegionSampleDDEElementsMap) const
fillMaps fills two maps.
std::vector< std::pair< std::string, CaloCell_ID::CaloSample > > m_caloDiscSampleList
std::string getSampleName(CaloCell_ID::CaloSample currentSample) const
void addCylindricalTrackingVolumeToCaloNode(Acts::Experimental::CylinderContainerBlueprintNode &containerNode, const std::string &volumeName, const std::vector< std::shared_ptr< Acts::Surface > > &surfaces, int layerIndex, const bool &isDisc) const
addCylindricalTrackingVolumeToCaloNode adds a cylindrical tracking volume to the calo node.
std::shared_ptr< Acts::CylinderSurface > generateCylinderSurface(const double &maxLArBRadius, const double &minLArBRadius, const double &lowZLarB, const double &highZLarB, bool asymmetricZ) const
generateCylinderSurface generates a cylindrical surface for a given set of parameters.
std::shared_ptr< Acts::DiscSurface > generateDiscSurface(const double &z, const double &maxLArBRadius, const double &minLArBRadius) const
std::vector< std::pair< std::string, CaloCell_ID::CaloSample > > m_caloCylinderAsymmetricSampleList
void generateCylinderSurfaces(caloSampleSurfaceMap_t &caloSampleSurfaceMap, caloSampleDDEElementsMap_t &caloSampleDDEElementsMap, bool asymmetricZ) const
generateCylinderSurfaces generates cylindrical surfaces for each calo sampling.
std::vector< std::pair< std::string, CaloCell_ID::CaloSample > > m_caloCylinderSymmetricSampleList
std::shared_ptr< Acts::Experimental::BlueprintNode > buildBlueprintNode(const Acts::GeometryContext &gctx, std::shared_ptr< Acts::Experimental::BlueprintNode > &&childNode) override
Build the Itk Blueprint Node.
std::unique_ptr< CaloDetDescrManager > m_caloDetSecrMgr
CaloCell_ID::CaloSample getSampleEnum(const std::string &sampleName) const
void generateDiscSurfaces(caloSampleSurfaceMap_t &caloSampleSurfaceMap, caloSampleDDEElementsMap_t &caloSampleDDEElementsMap) const
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
This class groups all DetDescr information related to a CaloCell.
Define the volume parts of the GeometryIdentifier for each ATLAS subsystem centrally.
constexpr std::size_t s_caloEnvelopeID
Volume Ids ofthe Calorimeter.
constexpr std::size_t s_caloBarrelId
Amg::Transform3D getTranslateZ3D(const double Z)
: Returns a shift transformation along the z-axis
IMessageSvc * getMessageSvc(bool quiet=false)
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.