ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CylinderVolumeBuilder.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CylinderVolumeBuilder.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 // CylinderVolumeBuilder.h, Acts project
12 
13 #pragma once
14 
15 #include <array>
16 #include <limits>
17 #include <string>
18 
26 #include "Acts/Utilities/Units.hpp"
27 
28 #ifndef ATAS_GEOMETRYTOOLS_TAKESMALLERBIGGER
29 #define ATAS_GEOMETRYTOOLS_TAKESMALLERBIGGER
30 #define takeSmaller(current, test) current = current < test ? current : test
31 #define takeBigger(current, test) current = current > test ? current : test
32 #define takeSmallerBigger(cSmallest, cBiggest, test) \
33  takeSmaller(cSmallest, test); \
34  takeBigger(cBiggest, test)
35 #endif
36 
37 namespace Acts {
38 
39 class TrackingVolume;
40 class VolumeBounds;
41 class IVolumeMaterial;
42 class ISurfaceMaterial;
43 
46  Undefined = 0,
47  Attaching = 1,
48  Inserting = 2,
49  Wrapping = 3,
53 };
54 
56 struct VolumeConfig {
57  bool present{false};
58  bool wrapping{false};
59  double rMin;
60  double rMax;
61  double zMin;
62  double zMax;
65 
68  : rMin(std::numeric_limits<double>::max()),
69  rMax(std::numeric_limits<double>::lowest()),
70  zMin(std::numeric_limits<double>::max()),
71  zMax(std::numeric_limits<double>::lowest()),
72  layers() {}
73 
78  void adaptZ(const VolumeConfig& lConfig) {
79  if (lConfig) {
80  takeSmaller(zMin, lConfig.zMin);
81  takeBigger(zMax, lConfig.zMax);
82  }
83  }
84 
89  void adaptR(const VolumeConfig& lConfig) {
90  if (lConfig) {
91  takeSmaller(rMin, lConfig.rMin);
92  takeBigger(rMax, lConfig.rMax);
93  }
94  }
95 
100  void adapt(const VolumeConfig& lConfig) {
101  adaptZ(lConfig);
102  adaptR(lConfig);
103  }
104 
111  void midPointAttachZ(VolumeConfig& lConfig) {
112  if (lConfig.zMin >= zMax) {
113  double zMid = 0.5 * (lConfig.zMin + zMax);
114  lConfig.zMin = zMid;
115  zMax = zMid;
116  } else {
117  double zMid = 0.5 * (zMin + lConfig.zMax);
118  lConfig.zMax = zMid;
119  zMin = zMid;
120  }
121  }
122 
127  void attachZ(const VolumeConfig& lConfig) {
128  if (lConfig.zMin >= zMax) {
129  zMax = lConfig.zMin;
130  } else {
131  zMin = lConfig.zMax;
132  }
133  }
134 
139  bool overlapsInR(const VolumeConfig& vConfig) const {
140  if (!present) {
141  return false;
142  }
143  return std::max(rMin, vConfig.rMin) <= std::min(rMax, vConfig.rMax);
144  }
145 
150  bool overlapsInZ(const VolumeConfig& vConfig) const {
151  if (!present) {
152  return false;
153  }
154  return std::max(zMin, vConfig.zMin) <= std::min(zMax, vConfig.zMax);
155  }
156 
161  bool wraps(const VolumeConfig& vConfig) const {
162  if ((zMax <= vConfig.zMin) || (zMin >= vConfig.zMax)) {
163  return true;
164  }
165  return containsInR(vConfig);
166  }
167 
171  bool contains(const VolumeConfig& vConfig) const {
172  return (containsInR(vConfig) && containsInZ(vConfig));
173  }
174 
178  bool containsInR(const VolumeConfig& vConfig) const {
179  return (rMin >= vConfig.rMax);
180  }
181 
185  bool containsInZ(const VolumeConfig& vConfig) const {
186  return (vConfig.zMin > zMin && vConfig.zMax < zMax);
187  }
188 
190  std::string toString() const {
192  std::stringstream sl;
193  sl << rMin << ", " << rMax << " / " << zMin << ", " << zMax;
194  return sl.str();
195  }
196 
198  operator bool() const { return present; }
199 };
200 
203  public:
208 
211 
216 
220 
221  // WrappingCondition
223  std::string wConditionScreen = "[left untouched]";
224 
226  WrappingConfig() = default;
227 
230  // set the container to be present
232  std::string wConditionAddon = "";
233  // if we have more than one config present
237  wConditionScreen = "grouped to ";
238  }
239  // adapt the new volume config to the existing configs
240  if (nVolumeConfig) {
242  wConditionScreen += "[n]";
243  }
244  if (cVolumeConfig) {
246  wConditionScreen += "[c]";
247  }
248  if (pVolumeConfig) {
250  wConditionScreen += "[p]";
251  }
252  // adapt the external one
253  if (externalVolumeConfig) {
255  }
256  // attach the volume configs
257  if (nVolumeConfig && cVolumeConfig) {
259  }
260  if (cVolumeConfig && pVolumeConfig) {
262  }
263  // adapt r afterwards
264  // - easy if no exisitng volume
265  // - possible if no central volume
270  }
271  }
272 
275  // action is only needed if an existing volume
276  // is present
277  if (existingVolumeConfig) {
278  // 0 - simple attachment case
279  if (!cVolumeConfig) {
280  // check if it can be easily attached
283  // will attach the new volume(s)
285  wConditionScreen = "[n attched]";
286  }
289  // will attach the new volume(s)
291  wConditionScreen = "[p attched]";
292  }
293  // see if inner glue volumes are needed
297  } else {
298  fGapVolumeConfig.present = true;
299  // get the zMin/zMax boundaries
303  }
304  // see if outer glue volumes are needed
308  } else {
309  sGapVolumeConfig.present = true;
310  // get the zMin/zMax boundaries
314  }
315  } else {
316  // full wrapping or full insertion case
318  // Full wrapping case
319  // - set the rMin
323  // - set the rMax
327  // will wrap the new volume(s) around existing
329  wConditionScreen = "[fully wrapped]";
331  // full insertion case
332  // set the rMax
336  // set the rMin
340  // will insert the new volume(s) into existing
342  wConditionScreen = "[fully inserted]";
344  // central wrapping case
345  // set the rMax
349  // set the rMin
353  // set the Central Wrapping
355  wConditionScreen = "[centrally wrapped]";
357  // central insertion case
358  // set the rMax
362  // set the rMin
366  // set the Central Wrapping
368  wConditionScreen = "[centrally inserted]";
369  }
370 
371  // check if gaps are needed
372  //
373  // the gap reference is either the container for FULL wrapping,
374  // insertion
375  // or it is the centralVolume for central wrapping, insertion
376  VolumeConfig referenceVolume =
379  : cVolumeConfig;
380  // - at the negative sector
381  if (existingVolumeConfig.zMin > referenceVolume.zMin) {
382  fGapVolumeConfig.present = true;
384  fGapVolumeConfig.zMin = referenceVolume.zMin;
386  } else {
387  // adapt lower z boundary
388  if (nVolumeConfig) {
390  } else if (cVolumeConfig) {
392  }
393  }
394  // - at the positive sector
395  if (existingVolumeConfig.zMax < referenceVolume.zMax) {
396  sGapVolumeConfig.present = true;
399  sGapVolumeConfig.zMax = referenceVolume.zMax;
400  } else {
401  // adapt higher z boundary
402  if (pVolumeConfig) {
404  } else if (cVolumeConfig) {
406  }
407  }
408  }
409  }
410  return;
411  }
412 
414  std::string toString() const {
415  // for screen output
416  std::stringstream sl;
417  if (containerVolumeConfig) {
418  sl << "New contaienr built with configuration: "
419  << containerVolumeConfig.toString() << '\n';
420  }
421  // go throug the new new ones first
422  if (nVolumeConfig) {
423  sl << " - n: Negative Endcap, current configuration: "
424  << nVolumeConfig.toString() << '\n';
425  }
426  if (cVolumeConfig) {
427  sl << " - c: Barrel, current configuration: "
428  << cVolumeConfig.toString() << '\n';
429  }
430  if (pVolumeConfig) {
431  sl << " - p: Negative Endcap, current configuration: "
432  << pVolumeConfig.toString() << '\n';
433  }
434  if (existingVolumeConfig) {
435  sl << "Existing volume with configuration: "
436  << existingVolumeConfig.toString() << '\n';
437  if (fGapVolumeConfig) {
438  sl << " - g1: First gap volume, configuration : "
439  << fGapVolumeConfig.toString() << '\n';
440  }
441  if (sGapVolumeConfig) {
442  sl << " - g2: Second gap volume, configuration : "
443  << sGapVolumeConfig.toString() << '\n';
444  }
445  if (wCondition != Undefined) {
446  sl << "WrappingCondition = " << wCondition << '\n';
447  }
448  }
449  return sl.str();
450  }
451 };
452 
473  public:
476  struct Config {
478  std::shared_ptr<const ITrackingVolumeHelper> trackingVolumeHelper = nullptr;
480  std::string volumeName = "";
482  std::shared_ptr<const IVolumeMaterial> volumeMaterial = nullptr;
484  bool buildToRadiusZero = false;
486  bool checkRingLayout = false;
490  std::shared_ptr<const ILayerBuilder> layerBuilder = nullptr;
492  std::shared_ptr<const IConfinedTrackingVolumeBuilder> ctVolumeBuilder =
493  nullptr;
495  std::pair<double, double> layerEnvelopeR = {1. * UnitConstants::mm,
496  1. * UnitConstants::mm};
499 
500  // The potential boundary material (MB) options - there are 6 at maximium
504  std::array<std::shared_ptr<const ISurfaceMaterial>, 6> boundaryMaterial{
505  nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
506 
508  int volumeSignature = -1;
509  };
510 
515  CylinderVolumeBuilder(const Config& cvbConfig,
516  std::unique_ptr<const Logger> logger = getDefaultLogger(
517  "CylinderVolumeBuilder", Logging::INFO));
518 
520  ~CylinderVolumeBuilder() override;
521 
532  const GeometryContext& gctx, TrackingVolumePtr existingVolume = nullptr,
533  VolumeBoundsPtr externalBounds = nullptr) const override;
534 
538  void setConfiguration(const Config& cvbConfig);
539 
543  Config getConfiguration() const;
544 
548  void setLogger(std::unique_ptr<const Logger> newLogger);
549 
557  const GeometryContext& gctx, const LayerVector& lVector,
558  const MutableTrackingVolumeVector& mtvVector) const;
559 
560  private:
563 
567  const Logger& logger() const { return *m_logger; }
568 
570  std::unique_ptr<const Logger> m_logger;
571 
585  VolumeConfig& layerConfig,
586  const VolumeConfig& insideConfig,
587  const VolumeConfig& volumeConfig, int sign) const;
588 };
589 
592  const {
593  return m_cfg;
594 }
595 
596 } // namespace Acts