Loading [MathJax]/jax/input/TeX/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ActsCaloTrackingVolumeBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "ActsInterop/Logger.h"
7 
8 #include "StoreGate/ReadHandle.h"
10 #include "CaloDetDescr/CaloDetDescrElement.h"
12 
13 #include "Acts/Geometry/TrackingVolume.hpp"
14 #include "Acts/Geometry/VolumeBounds.hpp"
15 #include "Acts/Geometry/GlueVolumesDescriptor.hpp"
16 
17 // ACTS
18 #include "Acts/Geometry/GenericCuboidVolumeBounds.hpp"
19 #include "Acts/Geometry/CutoutCylinderVolumeBounds.hpp"
20 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
21 //#include "Acts/Utilities/IVisualization.hpp"
22 #include "Acts/Utilities/Helpers.hpp"
23 #include "Acts/Geometry/TrackingVolumeArrayCreator.hpp"
24 #include "Acts/Utilities/BinnedArrayXD.hpp"
25 #include "Acts/Geometry/CylinderVolumeHelper.hpp"
26 
27 #include <fstream>
28 
29 using Box = Acts::Volume::BoundingBox; // shortcut
30 
31 using CVBBV = Acts::CylinderVolumeBounds::BoundValues;
32 using CCVBBV = Acts::CutoutCylinderVolumeBounds::BoundValues;
33 
35  const std::string& name,
36  const IInterface* parent)
37 : base_class(type, name, parent)
38 {
39 
40 }
41 
44 {
45  m_caloMgr = detStore()->tryConstRetrieve<CaloDetDescrManager>(caloMgrStaticKey);
46  if(!m_caloMgr) {
47  std::unique_ptr<CaloDetDescrManager> caloMgrPtr = buildCaloDetDescrNoAlign(serviceLocator()
49  ATH_CHECK(detStore()->record(std::move(caloMgrPtr), caloMgrStaticKey));
50  ATH_CHECK(detStore()->retrieve(m_caloMgr, caloMgrStaticKey));
51  }
52  return StatusCode::SUCCESS;
53 }
54 
55 std::shared_ptr<Acts::TrackingVolume>
57  const Acts::GeometryContext& gctx,
58  std::shared_ptr<const Acts::TrackingVolume> insideVolume,
59  std::shared_ptr<const Acts::VolumeBounds> /*outsideBounds*/) const
60 {
61 
62 
63  // generate the calo cell volume description
64  std::vector<std::unique_ptr<Acts::Volume>> cells;
65  cells = cellFactory();
66 
67  ATH_MSG_VERBOSE("Collected " << cells.size() << " calo cells");
68 
69 
70  // we need to turn the cells into boundary boxes
71  std::vector<std::unique_ptr<Box>> boxStore;
72  std::vector<Box*> prims;
73  for (const auto& cell : cells) {
74  boxStore.push_back(
75  std::make_unique<Box>(cell->boundingBox({0.1, 0.1, 0.1})));
76  prims.push_back(boxStore.back().get());
77  }
78 
79  ATH_MSG_VERBOSE("Generated Bounding Boxes");
80 
81 
82  ATH_MSG_VERBOSE("Figure out dimensions of wrapping volume");
83 
84  std::shared_ptr<Acts::CutoutCylinderVolumeBounds> caloVolBounds
85  = makeCaloVolumeBounds(boxStore, insideVolume);
86 
87  // build a BVH octree for the bounding boxes
88  // but only AFTER we've built the calo volume bounds
89  // Box* top;
90  // top = Acts::make_octree(boxStore, prims, 1, 0.1);
91 
92  // Create Tracking Volume that coutains the Calo
93  // This needs to own the Abstract Volumes (cells), but we
94  // need to up-cast them to Volume, since that's what TrackingVolume can own
95  std::vector<std::unique_ptr<const Acts::Volume>> cellVols;
96  cellVols.reserve(cells.size());
97  for(auto& cell : cells) {
98  std::unique_ptr<const Acts::Volume> up;
99  // release, up-cast, then immediately pack again
100  up = std::unique_ptr<const Acts::Volume>(dynamic_cast<const Acts::Volume*>(cell.release()));
101  cellVols.push_back(std::move(up));
102  }
103 
104  // This was removed in https://github.com/acts-project/acts/pull/3029
105  // To be reimplemented using new geometry model instead of explicit TrackingVolume content
106  (void)gctx; // suppress compiler warning
107  throw std::runtime_error{"Calo building for ACTS currently disabled"};
108 
109  /***** TODO START *****
110  std::shared_ptr<Acts::TrackingVolume> calo;
111  // = Acts::TrackingVolume::create(Acts::Transform3::Identity(),
112  // caloVolBounds,
113  // std::move(boxStore),
114  // std::move(cellVols),
115  // top,
116  // nullptr, // no material for now
117  // "Calo");
118 
119  // We need to interglue all the volumes together
120  std::shared_ptr<Acts::TrackingVolume> mutInsideVolume
121  = std::const_pointer_cast<Acts::TrackingVolume>(insideVolume);
122  auto idBounds = dynamic_cast<const Acts::CylinderVolumeBounds*>(&insideVolume->volumeBounds());
123  if (idBounds == nullptr) { // protection against nullptr
124  ATH_MSG_ERROR("Unable to dynamic cast volume bounds to Acts::CylinderVolumeBounds");
125  throw std::runtime_error("Error casting to CylinderVolumeBounds");
126  }
127 
128  // we want gap volumes at pos and neg xy face, and at outer cyl cover
129  // which will include the solenoid area
130 
131  auto trackingVolumeArrayCreator
132  = std::make_shared<const Acts::TrackingVolumeArrayCreator>(
133  Acts::TrackingVolumeArrayCreator::Config{},
134  makeActsAthenaLogger(this, std::string("TrkVolArrCrtr"), std::string("ActsTGSvc")));
135  Acts::CylinderVolumeHelper::Config cvhCfg;
136  cvhCfg.trackingVolumeArrayCreator = trackingVolumeArrayCreator;
137  Acts::CylinderVolumeHelper cvh(cvhCfg, makeActsAthenaLogger(this, std::string("ACaloTrkVB"), std::string("CylVolHlp")));
138 
139  std::vector<double> lPos = {};
140  std::vector<std::shared_ptr<Acts::TrackingVolume>> noVolumes;
141 
142  ATH_MSG_VERBOSE("Creating gap volume to extend ID");
143  // positive xy gap
144  auto idGapPosXY = cvh.createGapTrackingVolume(gctx,
145  noVolumes,
146  nullptr,
147  idBounds->get(CVBBV::eMinR),
148  idBounds->get(CVBBV::eMaxR),
149  idBounds->get(CVBBV::eHalfLengthZ),
150  caloVolBounds->get(CCVBBV::eHalfLengthZcutout),
151  lPos,
152  false,
153  "ID::PositiveGap"
154  );
155  // negative xy gap
156  auto idGapNegXY = cvh.createGapTrackingVolume(gctx,
157  noVolumes,
158  nullptr,
159  idBounds->get(CVBBV::eMinR),
160  idBounds->get(CVBBV::eMaxR),
161  -caloVolBounds->get(CCVBBV::eHalfLengthZcutout),
162  -idBounds->get(CVBBV::eHalfLengthZ),
163  lPos,
164  false,
165  "ID::NegativeGap"
166  );
167  // outer cover gap
168  auto idGapCylOuter = cvh.createGapTrackingVolume(gctx,
169  noVolumes,
170  nullptr,
171  idBounds->get(CVBBV::eMaxR),
172  caloVolBounds->get(CCVBBV::eMedR),
173  -caloVolBounds->get(CCVBBV::eHalfLengthZcutout),
174  +caloVolBounds->get(CCVBBV::eHalfLengthZcutout),
175  lPos,
176  false,
177  "ID::CylOutGap"
178  );
179 
180  ATH_MSG_VERBOSE("Create container volume to contain ID and gap volumes");
181  auto idContainerZ = cvh.createContainerTrackingVolume(gctx, {idGapNegXY, mutInsideVolume, idGapPosXY});
182  auto idContainer = cvh.createContainerTrackingVolume(gctx, {idContainerZ, idGapCylOuter});
183 
184 
185  ATH_MSG_VERBOSE("Begin volume glueing");
186 
187  const Acts::GlueVolumesDescriptor& gvd
188  = idContainer->glueVolumesDescriptor();
189  // let's see what the GVD says is on the inner cover of the ID
190  const auto& tVolArrPos = gvd.glueVolumes(Acts::positiveFaceXY);
191  const auto& tVolArrNeg = gvd.glueVolumes(Acts::negativeFaceXY);
192 
193  std::cout << "POSITIVE: " << std::endl;
194  for(const auto& subvol : tVolArrPos->arrayObjects()) {
195  std::cout << subvol->volumeName() << std::endl;
196  std::cout << *subvol << std::endl;
197  }
198 
199  std::cout << "NEGATIVE: " << std::endl;
200  for(const auto& subvol : tVolArrNeg->arrayObjects()) {
201  std::cout << subvol->volumeName() << std::endl;
202  std::cout << *subvol << std::endl;
203  }
204 
205  using BoundarySurface = Acts::BoundarySurfaceT<Acts::TrackingVolume>;
206 
207 
208  // Glue outer radial cover of ID to inner cover of Calo cutout
209  auto idOutVolArray = gvd.glueVolumes(Acts::tubeOuterCover);
210  // Attach that volume array to the calo inner cover
211  ATH_MSG_VERBOSE("Glueing " << calo->volumeName() << " inner cover to " << idOutVolArray->arrayObjects().size() << " volumes");
212  std::const_pointer_cast<BoundarySurface>(calo->boundarySurfaces().at(Acts::tubeInnerCover))
213  ->attachVolumeArray(idOutVolArray, Acts::Direction::Backward);
214  // Loop through the array and attach their boundary surfaces to the calo
215  for(const auto& idVol : idOutVolArray->arrayObjects()){
216  ATH_MSG_VERBOSE("Glueing outer cover of " << idVol->volumeName()
217  << " to inner cover of " << calo->volumeName());
218  std::const_pointer_cast<BoundarySurface>(idVol->boundarySurfaces().at(Acts::tubeOuterCover))
219  ->attachVolume(calo.get(), Acts::Direction::Forward);
220  }
221 
222  // Glue positive XY face of ID to inner positive XY face of Calo.
223  // ID has multiple, Calo has only one
224  auto idPosXYVolArray = gvd.glueVolumes(Acts::positiveFaceXY);
225  ATH_MSG_VERBOSE("Glueing " << calo->volumeName() << " positive inner cutout disc to "
226  << idPosXYVolArray->arrayObjects().size() << " volumes");
227  std::const_pointer_cast<BoundarySurface>(calo->boundarySurfaces().at(Acts::index5))
228  ->attachVolumeArray(idPosXYVolArray, Acts::Direction::Backward);
229  // Other way round, attach ID volumes to calo
230  for(const auto& idVol : idPosXYVolArray->arrayObjects()){
231  ATH_MSG_VERBOSE("Glueing positive XY face of " << idVol->volumeName()
232  << " to positive inner coutout disc of " << calo->volumeName());
233  std::const_pointer_cast<BoundarySurface>(idVol->boundarySurfaces().at(Acts::positiveFaceXY))
234  ->attachVolume(calo.get(), Acts::Direction::Forward);
235  }
236 
237  // Glue negative XY face of ID to inner negative XY face of Calo.
238  // ID has multiple, Calo has only one
239  auto idNegXYVolArray = gvd.glueVolumes(Acts::negativeFaceXY);
240  ATH_MSG_VERBOSE("Glueing " << calo->volumeName() << " negative inner cutout disc to "
241  << idNegXYVolArray->arrayObjects().size() << " volumes");
242  std::const_pointer_cast<BoundarySurface>(calo->boundarySurfaces().at(Acts::index4))
243  ->attachVolumeArray(idNegXYVolArray, Acts::Direction::Forward);
244  // Other way round, attach ID volumes to calo
245  for(const auto& idVol : idNegXYVolArray->arrayObjects()){
246  ATH_MSG_VERBOSE("Glueing negative XY face of " << idVol->volumeName()
247  << " to negative inner coutout disc of " << calo->volumeName());
248  std::const_pointer_cast<BoundarySurface>(idVol->boundarySurfaces().at(Acts::negativeFaceXY))
249  ->attachVolume(calo.get(), Acts::Direction::Backward);
250  }
251 
252  // For navigational purposes we need to create three pseudo container cylinders.
253  // One for the middle, which includes the central part of the Calo and the ID, and
254  // two that fit cleanly at the +- XY face that then only include the Calo
255 
256  // Construct track vol array for use in positive and negative pseudocontainer.
257  // This will only contain the calo
258 
259  double caloRMin = caloVolBounds->get(CCVBBV::eMinR);
260  double caloRMed = caloVolBounds->get(CCVBBV::eMedR);
261  double caloRMax = caloVolBounds->get(CCVBBV::eMaxR);
262  double caloDZ1 = caloVolBounds->get(CCVBBV::eHalfLengthZ);
263  double caloDZ2 = caloVolBounds->get(CCVBBV::eHalfLengthZcutout);
264 
265  Acts::Vector3 caloChokeRPos
266  = {caloRMin + (caloRMax - caloRMin)/2., 0, 0};
267 
268  std::vector<Acts::TrackingVolumeOrderPosition> tVolOrdPosNeg;
269  tVolOrdPosNeg.push_back(std::make_pair(calo, caloChokeRPos));
270  std::vector<float> posNegBoundaries
271  = {float(caloRMin), float(caloRMax)};
272  auto binUtilityPosNeg = std::make_unique<const Acts::BinUtility>(posNegBoundaries,
273  Acts::open, Acts::AxisDirection::AxisR);
274 
275  auto tVolArrPosNeg
276  = std::make_shared<const Acts::BinnedArrayXD<Acts::TrackingVolumePtr>>(
277  tVolOrdPosNeg, std::move(binUtilityPosNeg));
278 
279  double chokeZOffset = caloDZ2 + (caloDZ1 - caloDZ2)/2.;
280  Acts::Transform3 posTrf(Acts::Translation3(Acts::Vector3::UnitZ() * chokeZOffset));
281  Acts::Transform3 negTrf(Acts::Translation3(Acts::Vector3::UnitZ()* -1 *chokeZOffset));
282 
283  auto posNegCylBounds = std::make_shared<Acts::CylinderVolumeBounds>(
284  caloRMin, caloRMax, (caloDZ1 - caloDZ2) / 2.);
285 
286  // they share the same bounds and tvol array
287  auto posContainer = std::make_shared<Acts::TrackingVolume>(
288  posTrf,
289  posNegCylBounds,
290  nullptr, nullptr,
291  tVolArrPosNeg,
292  Acts::MutableTrackingVolumeVector{});
293  ATH_MSG_VERBOSE("Built positive container " << *posContainer);
294  ATH_MSG_VERBOSE(" - containing: " << calo->volumeName());
295  auto negContainer = std::make_shared<Acts::TrackingVolume>(
296  negTrf,
297  posNegCylBounds,
298  nullptr, nullptr,
299  tVolArrPosNeg,
300  Acts::MutableTrackingVolumeVector{});
301  ATH_MSG_VERBOSE("Built negative container " << *negContainer);
302  ATH_MSG_VERBOSE(" - containing: " << calo->volumeName());
303 
304  // now build the central pseudocontainer
305  std::vector<Acts::TrackingVolumeOrderPosition> tVolOrderedCtr;
306  tVolOrderedCtr.push_back(std::make_pair(idContainer, Acts::Vector3(caloRMed / 2., 0, 0)));
307  tVolOrderedCtr.push_back(std::make_pair(calo,
308  Acts::Vector3(caloRMed +
309  (caloRMax- caloRMed) / 2., 0, 0)));
310 
311  std::vector<float> ctrBoundaries = {0, float(caloRMed), float(caloRMax)};
312  auto binUtilityCtr
313  = std::make_unique<const Acts::BinUtility>(
314  ctrBoundaries,
315  Acts::open, Acts::AxisDirection::AxisR);
316 
317  auto tVolArrCtr
318  = std::make_shared<const Acts::BinnedArrayXD<Acts::TrackingVolumePtr>>(
319  tVolOrderedCtr, std::move(binUtilityCtr));
320 
321 
322  auto ctrContainer = std::make_shared<Acts::TrackingVolume>(Acts::Transform3::Identity(),
323  std::make_shared<Acts::CylinderVolumeBounds>(
324  caloRMin, caloRMax, caloDZ2),
325  nullptr, nullptr,
326  tVolArrCtr,
327  Acts::MutableTrackingVolumeVector{}
328  );
329 
330  ATH_MSG_VERBOSE("Built central container " << *ctrContainer);
331  ATH_MSG_VERBOSE("- containing: " << idContainer->volumeName() << ", " << calo->volumeName());
332 
333  // and now combine those together into another one
334  Acts::TrackingVolumeArrayCreator tvac{Acts::TrackingVolumeArrayCreator::Config{}};
335 
336  auto mainContainer = std::make_shared<Acts::TrackingVolume>(Acts::Transform3::Identity(),
337  std::make_shared<Acts::CylinderVolumeBounds>(
338  caloRMin, caloRMax, caloDZ1),
339  nullptr, nullptr,
340  tvac.trackingVolumeArray(gctx, {negContainer, ctrContainer, posContainer},
341  Acts::AxisDirection::AxisZ),
342  Acts::MutableTrackingVolumeVector{}
343  );
344 
345 
346  ATH_MSG_VERBOSE("Built main container: " << *mainContainer);
347 
348  return mainContainer;
349  ***** TODO END *****/
350 }
351 
352 std::shared_ptr<Acts::CutoutCylinderVolumeBounds>
353 ActsCaloTrackingVolumeBuilder::makeCaloVolumeBounds(const std::vector<std::unique_ptr<Box>>& boxStore,
354  std::shared_ptr<const Acts::TrackingVolume> insideVolume) const
355 {
356  using namespace Acts::VectorHelpers;
357 
358  // determine the dimensions of the
359  double rmin_at_center = std::numeric_limits<double>::max();
360  double rmin_at_choke = std::numeric_limits<double>::max();
361  double rmax = std::numeric_limits<double>::lowest();
363  double zmax = std::numeric_limits<double>::lowest();
364  double cutout_zmin_abs = std::numeric_limits<double>::max();
365 
366  // We need to figure out what the size of the inner cutout cylinder is
367  // so we can make sure everything worked fine!
368  // We check what the min radius at small z, and then we turn it around and
369  // check z bounds at lower radii.
370  for (const auto& box : boxStore) {
371  Acts::Vector3 vmin = box->min().cast<double>();
372  Acts::Vector3 vmax = box->max().cast<double>();
373 
374  double vrmin = perp(vmin);
375  double vrmax = perp(vmax);
376 
377  rmin_at_choke = std::min(rmin_at_choke, std::min(vrmin, vrmax));
378 
379  rmax = std::max(rmax, std::max(vrmin, vrmax));
380  zmin = std::min(zmin, std::min(vmin.z(), vmax.z()));
381  zmax = std::max(zmax, std::max(vmin.z(), vmax.z()));
382 
383  if (std::abs(vmin.z()) < 100) {
384  rmin_at_center = std::min(vrmin, rmin_at_center);
385  }
386  if (std::abs(vmax.z()) < 100) {
387  rmin_at_center = std::min(vrmax, rmin_at_center);
388  }
389  }
390 
391  for (const auto& box : boxStore) {
392  Acts::Vector3 vmin = box->min().cast<double>();
393  Acts::Vector3 vmax = box->max().cast<double>();
394  double vrmin = perp(vmin);
395  double vrmax = perp(vmax);
396 
397  if (vrmin < rmin_at_center * 0.9) {
398  cutout_zmin_abs = std::min(cutout_zmin_abs, std::abs(vmin.z()));
399  }
400  if (vrmax < rmin_at_center * 0.9) {
401  cutout_zmin_abs = std::min(cutout_zmin_abs, std::abs(vmax.z()));
402  }
403  }
404 
405  double dz1 = (zmax - zmin) / 2.;
406  double dz2 = cutout_zmin_abs;
407 
408  // envelopes
409  double envZ = 5;
410  double envR = 5;
411  dz1 += envZ;
412  dz2 -= envZ;
413  rmax += envR;
414  if(rmin_at_choke > envR) rmin_at_choke -= envR;
415  rmin_at_center -= envR;
416 
417 
418  ATH_MSG_VERBOSE("rmin_at_center: " << rmin_at_center
419  << " rmin at choke: " << rmin_at_choke
420  << " rmax: " << rmax << " zmin: " << zmin << " zmax: " << zmax
421  << " coutout_zmin_abs: " << cutout_zmin_abs);
422 
423  // Ok now let's analyse what we're wrapping the calo around: the ID
424  // The ID will have to be built already.
425 
426  // We need to figure out the dimensions of the ID.
427  // Assuming the wrapping volume is a cylinder.
428  auto idCylBds
429  = dynamic_cast<const Acts::CylinderVolumeBounds*>(&insideVolume->volumeBounds());
430  if (idCylBds == nullptr) { // protection against nullptr
431  ATH_MSG_ERROR("Unable to dynamic cast volume bounds to Acts::CylinderVolumeBounds");
432  throw std::runtime_error("Error casting to CylinderVolumeBounds");
433  }
434 
435  double idRMax = idCylBds->get(CVBBV::eMaxR);
436  double idRMin = idCylBds->get(CVBBV::eMinR);
437  double idHlZ = idCylBds->get(CVBBV::eHalfLengthZ);
438 
439  ATH_MSG_VERBOSE("ID volume bounds:\n" << *idCylBds);
440 
441  ATH_MSG_VERBOSE("Inside volume transform: \n" << insideVolume->transform().matrix());
442 
443  if (!insideVolume->transform().isApprox(Acts::Transform3::Identity())) {
444  ATH_MSG_VERBOSE("Inside volume transform is not unity.");
445 
446  // transformation matrix is NOT unity. Let's check:
447  // - Rotation is approximate unity
448  // - Translation is only along z axis
449  const auto& trf = insideVolume->transform();
450 
451  Acts::RotationMatrix3 rot = trf.rotation();
452  bool unityRot = rot.isApprox(Acts::RotationMatrix3::Identity());
453 
454  ATH_MSG_VERBOSE("\n" << rot);
455 
456  // dot product with Z axis is about 1 => ok
457  const Acts::Vector3 trl = trf.translation();
458  bool transZOnly = std::abs(1 - std::abs(Acts::Vector3::UnitZ().dot(trl.normalized()))) < 1e-6;
459 
460  ATH_MSG_VERBOSE("TRL "<< trl.transpose());
461  ATH_MSG_VERBOSE("TRL "<< trl.normalized().dot(Acts::Vector3::UnitZ()));
462 
463  if(!unityRot || !transZOnly) {
464  ATH_MSG_ERROR("The ID appears to be shifted from the origin. I cannot handle this.");
465  ATH_MSG_ERROR("(I'm not building the Calo!)");
466  throw std::runtime_error("Error building calo");
467  }
468  else {
469  ATH_MSG_VERBOSE("Checked: non unitarity is ONLY due to shift along z axis: that's ok");
470  double prevIdHlZ = idHlZ;
471  idHlZ += std::abs(trl.z());
472  ATH_MSG_VERBOSE("Modifying effective half length of ID cylinder: " << prevIdHlZ << " => " << idHlZ);
473  }
474  }
475 
476  // make sure we can fit the ID inside the calo cutout
477  if (idRMax > rmin_at_center || idHlZ > dz2 || (idRMin > rmin_at_choke && idRMin != 0.)) {
478  ATH_MSG_ERROR("Cannot fit ID inside the Calo");
479  ATH_MSG_ERROR("This can be because the ID overlaps into the calo volume");
480  ATH_MSG_ERROR("Or because the Calo choke radius is SMALLER than the ID inner radius");
481  ATH_MSG_ERROR("Currently, I can only make the choke radius smaller, I can not make it larger");
482  ATH_MSG_ERROR("nor can I manipulate the ID volume bounds at this point.");
483  ATH_MSG_ERROR("ID rMax: " << idRMax << " Calo rMin@center: " << rmin_at_center);
484  ATH_MSG_ERROR("ID hlZ: " << idHlZ << " Calo inner Z hl: " << dz2);
485  ATH_MSG_ERROR("ID rMin: " << idRMin << " Calo rMin@choke: " << rmin_at_choke);
486  ATH_MSG_ERROR("(I'm not building the Calo!)");
487  throw std::runtime_error("Error building calo");
488  }
489 
490  // Let's harmonize the sizes, so we have a exact wrap of the ID
491  // Choke is now exactly as wide as space inside the ID.
492  // We can fit the beam pipe in there later.
493  rmin_at_choke = idRMin;
494 
495  std::shared_ptr<Acts::CutoutCylinderVolumeBounds> volBds = nullptr;
496  volBds = std::make_shared<Acts::CutoutCylinderVolumeBounds>(
497  rmin_at_choke, rmin_at_center, rmax, dz1, dz2);
498 
499  ATH_MSG_VERBOSE(*volBds);
500 
501  return volBds;
502 }
503 
504 
505 namespace {
506  double
507  eta_to_theta(double eta)
508  {
509  return 2 * std::atan(std::exp(-eta));
510  }
511 }
512 
513 Acts::Volume
515  double dz,
516  double eta,
517  double deta,
518  double phi,
519  double dphi) const
520 {
521  double eta_max = eta + deta * 0.5;
522  double eta_min = eta - deta * 0.5;
523  double theta_max = eta_to_theta(eta_max);
524  double theta = eta_to_theta(eta);
525  double theta_min = eta_to_theta(eta_min);
526  double phi_max = phi + dphi * 0.5;
527  double phi_min = phi - dphi * 0.5;
528  double z_min = z - dz;
529  double z_max = z + dz;
530 
531  double r_min, r_max;
532 
533  // inner face
534  r_min = std::tan(theta_min) * z_min;
535  r_max = std::tan(theta_max) * z_min;
536 
537  Acts::Vector3 p1(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_min);
538  Acts::Vector3 p2(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_min);
539  Acts::Vector3 p3(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_min);
540  Acts::Vector3 p4(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_min);
541 
542  // outer face
543  r_min = std::tan(theta_min) * z_max;
544  r_max = std::tan(theta_max) * z_max;
545 
546  Acts::Vector3 p5(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_max);
547  Acts::Vector3 p6(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_max);
548  Acts::Vector3 p7(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_max);
549  Acts::Vector3 p8(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_max);
550 
551  double r_mid = std::tan(theta) * z_min;
552  Acts::Vector3 center;
553  center.x() = r_mid * std::cos(phi);
554  center.y() = r_mid * std::sin(phi);
555  center.z() = z;
556 
557  Acts::Transform3 glob2vol = Acts::Transform3::Identity();
558  glob2vol *= Acts::AngleAxis3(-phi, Acts::Vector3::UnitZ());
559  glob2vol *= Acts::AngleAxis3(
560  -theta, Acts::Vector3::UnitZ().cross(center).normalized());
561  glob2vol
562  *= Acts::Translation3(-(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 8.);
563 
564  p1 = glob2vol * p1;
565  p2 = glob2vol * p2;
566  p3 = glob2vol * p3;
567  p4 = glob2vol * p4;
568  p5 = glob2vol * p5;
569  p6 = glob2vol * p6;
570  p7 = glob2vol * p7;
571  p8 = glob2vol * p8;
572 
573  auto globalToLocal = glob2vol.inverse();
574 
575  auto cubo = std::make_shared<Acts::GenericCuboidVolumeBounds>(
576  std::array<Acts::Vector3, 8>({{p1, p2, p3, p4, p5, p6, p7, p8}}));
577  Acts::Volume vol(globalToLocal, std::move(cubo));
578 
579  return vol;
580 }
581 
582 
583 Acts::Volume
585  double dr,
586  double eta,
587  double deta,
588  double phi,
589  double dphi) const
590 {
591  // std::cout << "build barrel" << std::endl;
592  double eta_max = eta + deta * 0.5;
593  double eta_min = eta - deta * 0.5;
594  double theta = eta_to_theta(eta);
595  double theta_max = eta_to_theta(eta_max);
596  double theta_min = eta_to_theta(eta_min);
597  double phi_max = phi + dphi * 0.5;
598  double phi_min = phi - dphi * 0.5;
599 
600  double r_min = r - dr;
601  double r_max = r + dr;
602 
603  double z_min, z_max;
604 
605  // inner face
606  z_min = r_min / std::tan(theta_min);
607  z_max = r_min / std::tan(theta_max);
608 
609  Acts::Vector3 p1(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_min);
610  Acts::Vector3 p2(r_min * std::cos(phi_min), r_min * std::sin(phi_min), z_max);
611  Acts::Vector3 p3(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_max);
612  Acts::Vector3 p4(r_min * std::cos(phi_max), r_min * std::sin(phi_max), z_min);
613 
614  // outer face
615  z_min = r_max / std::tan(theta_min);
616  z_max = r_max / std::tan(theta_max);
617 
618  Acts::Vector3 p5(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_min);
619  Acts::Vector3 p6(r_max * std::cos(phi_min), r_max * std::sin(phi_min), z_max);
620  Acts::Vector3 p7(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_max);
621  Acts::Vector3 p8(r_max * std::cos(phi_max), r_max * std::sin(phi_max), z_min);
622 
623  Acts::Vector3 center;
624  center.x() = r * std::cos(phi);
625  center.y() = r * std::sin(phi);
626  center.z() = r / std::tan(theta);
627 
628  Acts::Transform3 glob2vol = Acts::Transform3::Identity();
629  glob2vol *= Acts::AngleAxis3(-phi, Acts::Vector3::UnitZ());
630  glob2vol *= Acts::AngleAxis3(
631  -theta, Acts::Vector3::UnitZ().cross(center).normalized());
632  glob2vol
633  *= Acts::Translation3(-(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 8.);
634 
635  p1 = glob2vol * p1;
636  p2 = glob2vol * p2;
637  p3 = glob2vol * p3;
638  p4 = glob2vol * p4;
639  p5 = glob2vol * p5;
640  p6 = glob2vol * p6;
641  p7 = glob2vol * p7;
642  p8 = glob2vol * p8;
643 
644  auto globalToLocal = glob2vol.inverse();
645 
646  auto cubo = std::make_shared<Acts::GenericCuboidVolumeBounds>(
647  std::array<Acts::Vector3, 8>({{p1, p2, p3, p4, p5, p6, p7, p8}}));
648 
649  Acts::Volume vol(globalToLocal, std::move(cubo));
650 
651  return vol;
652 }
653 
654 Acts::Volume
655 ActsCaloTrackingVolumeBuilder::build_box(double x, double dx, double y, double dy, double z, double dz) const
656 {
657  // std::cout << "build box" << std::endl;
658 
659  double x_min, x_max, y_min, y_max, z_min, z_max;
660  x_min = x - dx;
661  x_max = x + dx;
662  y_min = y - dy;
663  y_max = y + dy;
664  z_min = z - dz;
665  z_max = z + dz;
666 
667  // inner face
668  Acts::Vector3 p1(x_min, y_min, z_min);
669  Acts::Vector3 p2(x_min, y_max, z_min);
670  Acts::Vector3 p3(x_max, y_max, z_min);
671  Acts::Vector3 p4(x_max, y_min, z_min);
672 
673  // outer face
674  Acts::Vector3 p5(x_min, y_min, z_max);
675  Acts::Vector3 p6(x_min, y_max, z_max);
676  Acts::Vector3 p7(x_max, y_max, z_max);
677  Acts::Vector3 p8(x_max, y_min, z_max);
678 
679  Acts::Transform3 glob2vol = Acts::Transform3::Identity();
680  glob2vol
681  *= Acts::Translation3(-(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8) / 8.);
682 
683  p1 = glob2vol * p1;
684  p2 = glob2vol * p2;
685  p3 = glob2vol * p3;
686  p4 = glob2vol * p4;
687  p5 = glob2vol * p5;
688  p6 = glob2vol * p6;
689  p7 = glob2vol * p7;
690  p8 = glob2vol * p8;
691 
692  auto globalToLocal = glob2vol.inverse();
693 
694  auto cubo = std::make_shared<Acts::GenericCuboidVolumeBounds>(
695  std::array<Acts::Vector3, 8>({{p1, p2, p3, p4, p5, p6, p7, p8}}));
696  Acts::Volume vol(globalToLocal, std::move(cubo));
697 
698  return vol;
699 }
700 
701 std::vector<std::unique_ptr<Acts::Volume>>
703 {
704  //Acts::ply_helper<double> ply_lar;
705  //Acts::ply_helper<double> ply_tile;
706  //Acts::ply_helper<double> ply_fcal;
707 
708  //float x, y, z, r, phi_raw, eta_raw, dphi, deta, dr, dx, dy, dz;
709  float z, dz, eta_raw, deta, phi_raw, dphi, r, dr, x, y, dx, dy;
710  size_t calosample;
711  float scale;
712 
713  // storage of cells we will produce
714  std::vector<std::unique_ptr<Acts::Volume>> cells;
715  cells.reserve(m_caloMgr->element_size()); // about 180k
716 
717  for(auto it = m_caloMgr->element_begin();it < m_caloMgr->element_end();++it) {
718  const CaloDetDescrElement* cde = *it;
719 
720  z = cde->z();
721  dz = cde->dz();
722  eta_raw = cde->eta_raw();
723  deta = cde->deta();
724  phi_raw = cde->phi_raw();
725  dphi = cde->dphi();
726  r = cde->r();
727  dr = cde->dr();
728  x = cde->x();
729  y = cde->y();
730  dx = cde->dx();
731  dy = cde->dy();
732 
733  calosample = cde->getSampling();
734 
735  scale = 1.;
736  if (calosample >= 12 && calosample <= 20) {
737  scale = 0.5;
738  }
739 
740  //Acts::ply_helper<double>* ply;
741  //if (calosample <= 11) {
742  //ply = &ply_lar;
743  //} else if (calosample <= 20) {
744  //ply = &ply_tile;
745  //} else {
746  //ply = &ply_fcal;
747  //}
748 
749 
750  switch (calosample) {
751  case 4:
752  case 5:
753  case 6:
754  case 7:
755  case 8:
756  case 9:
757  case 10:
758  case 11:
759  case 17:
760  dz *= scale;
761  cells.push_back(std::make_unique<Acts::Volume>(
762  build_endcap(z, dz, eta_raw, deta, phi_raw, dphi)));
763  break;
764  case 0:
765  case 1:
766  case 2:
767  case 3:
768  case 12:
769  case 13:
770  case 14:
771  case 15:
772  case 16:
773  case 18:
774  case 19:
775  case 20:
776  dr *= scale;
777  cells.push_back(std::make_unique<Acts::Volume>(
778  build_barrel(r, dr, eta_raw, deta, phi_raw, dphi)));
779  break;
780  case 21:
781  case 22:
782  case 23:
783  scale = 1.;
784  dx *= scale;
785  dy *= scale;
786  // dz *= scale;
787  cells.push_back(std::make_unique<Acts::Volume>(
788  build_box(x, dx, y, dy, z, dz)));
789  break;
790  default:
791  std::stringstream ss;
792  ss << "Unkown calo sample " << calosample;
793  std::runtime_error(ss.str());
794  }
795 
796  //cells.back()->boundingBox({0.1, 0.1, 0.1}).draw(*ply);
797  //auto cvb = dynamic_cast<const
798  //Acts::GenericCuboidVolumeBounds*>(&cells.back()->volumeBounds());
799  //cvb->draw(*ply, cells.back()->transform());
800  }
801 
802  //std::ofstream os("lar.ply");
803  //os << ply_lar << std::flush;
804  //os.close();
805 
806  //os = std::ofstream("tile.ply");
807  //os << ply_tile << std::flush;
808  //os.close();
809 
810  //os = std::ofstream("fcal.ply");
811  //os << ply_fcal << std::flush;
812  //os.close();
813 
814  return cells;
815 }
CaloDetDescrElement::deta
float deta() const
cell deta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:356
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:676
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
ActsCaloTrackingVolumeBuilder::trackingVolume
std::shared_ptr< Acts::TrackingVolume > trackingVolume(const Acts::GeometryContext &gctx, std::shared_ptr< const Acts::TrackingVolume > insideVolume=nullptr, std::shared_ptr< const Acts::VolumeBounds > outsideBounds=nullptr) const override
Definition: ActsCaloTrackingVolumeBuilder.cxx:56
ActsCaloTrackingVolumeBuilder.h
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
CaloDetDescrElement::y
float y() const
cell y
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:365
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:44
ActsCaloTrackingVolumeBuilder::makeCaloVolumeBounds
std::shared_ptr< Acts::CutoutCylinderVolumeBounds > makeCaloVolumeBounds(const std::vector< std::unique_ptr< Acts::Volume::BoundingBox >> &boxStore, std::shared_ptr< const Acts::TrackingVolume > insideVolume) const
Definition: ActsCaloTrackingVolumeBuilder.cxx:353
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
PixelAthClusterMonAlgCfg.zmin
zmin
Definition: PixelAthClusterMonAlgCfg.py:169
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
CaloDetDescrElement::dr
float dr() const
cell dr
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:360
skel.it
it
Definition: skel.GENtoEVGEN.py:407
PlotCalibFromCool.vmin
vmin
Definition: PlotCalibFromCool.py:696
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
ActsCaloTrackingVolumeBuilder::build_box
Acts::Volume build_box(double x, double dx, double y, double dy, double z, double dz) const
Definition: ActsCaloTrackingVolumeBuilder.cxx:655
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
x
#define x
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
CaloDetDescrElement::eta_raw
float eta_raw() const
cell eta_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:350
CaloDetDescrElement::dz
float dz() const
cell dz
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:379
ActsCaloTrackingVolumeBuilder::build_barrel
Acts::Volume build_barrel(double r, double dr, double eta, double deta, double phi, double dphi) const
Definition: ActsCaloTrackingVolumeBuilder.cxx:584
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
ActsCaloTrackingVolumeBuilder::cellFactory
std::vector< std::unique_ptr< Acts::Volume > > cellFactory() const
Definition: ActsCaloTrackingVolumeBuilder.cxx:702
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
z
#define z
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:169
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsCaloTrackingVolumeBuilder::ActsCaloTrackingVolumeBuilder
ActsCaloTrackingVolumeBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ActsCaloTrackingVolumeBuilder.cxx:34
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
CCVBBV
Acts::CutoutCylinderVolumeBounds::BoundValues CCVBBV
Definition: ActsCaloTrackingVolumeBuilder.cxx:32
Box
Acts::Volume::BoundingBox Box
Definition: ActsCaloTrackingVolumeBuilder.cxx:29
dot.dot
def dot(G, fn, nodesToHighlight=[])
Definition: dot.py:5
ActsCaloTrackingVolumeBuilder::build_endcap
Acts::Volume build_endcap(double z, double dz, double eta, double deta, double phi, double dphi) const
Definition: ActsCaloTrackingVolumeBuilder.cxx:514
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
CaloDetDescrBuilder.h
CaloDetDescrManager_Base::element_begin
calo_element_const_iterator element_begin() const
first element
Definition: CaloDetDescrManager.cxx:111
CaloDetDescrElement::x
float x() const
cell x
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:363
CVBBV
Acts::CylinderVolumeBounds::BoundValues CVBBV
Definition: ActsCaloTrackingVolumeBuilder.cxx:31
makeTRTBarrelCans.dy
tuple dy
Definition: makeTRTBarrelCans.py:21
CaloDetDescrElement::dphi
float dphi() const
cell dphi
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:358
ActsCaloTrackingVolumeBuilder::m_caloMgr
const CaloDetDescrManager * m_caloMgr
Definition: ActsCaloTrackingVolumeBuilder.h:64
y
#define y
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloDetDescrElement::dx
float dx() const
cell dx
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:375
CaloDetDescrElement::getSampling
CaloCell_ID::CaloSample getSampling() const
cell sampling
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:395
CaloDetDescrManager_Base::element_size
calo_element_vec_size element_size() const
total number of elements
Definition: CaloDetDescrManager.cxx:105
CaloDetDescrElement::z
float z() const
cell z
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:367
makeTRTBarrelCans.dx
tuple dx
Definition: makeTRTBarrelCans.py:20
ActsCaloTrackingVolumeBuilder::initialize
StatusCode initialize() override
Definition: ActsCaloTrackingVolumeBuilder.cxx:43
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
CaloLCW_tf.trf
trf
Definition: CaloLCW_tf.py:20
ReadHandle.h
Handle class for reading from StoreGate.
CaloDetDescrElement::r
float r() const
cell r
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:348
Logger.h
TRTCalib_cfilter.p3
p3
Definition: TRTCalib_cfilter.py:132
CaloDetDescrElement::dy
float dy() const
cell dy
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:377
NSWL1::globalToLocal
Polygon globalToLocal(const Polygon &pol, float z, const Trk::PlaneSurface &surf)
Definition: GeoUtils.cxx:103
buildCaloDetDescrNoAlign
std::unique_ptr< CaloDetDescrManager > buildCaloDetDescrNoAlign(ISvcLocator *svcLocator, IMessageSvc *msgSvc)
Definition: CaloDetDescrBuilder.cxx:791
PlotCalibFromCool.vmax
vmax
Definition: PlotCalibFromCool.py:697
CaloDetDescrElement::phi_raw
float phi_raw() const
cell phi_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:352