ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BuildGenericDetector.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BuildGenericDetector.cpp
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 
11 namespace FW {
12 
13 namespace Generic {
14 
16 std::vector<Acts::Vector3D> modulePositionsCylinder(
17  double radius, double zStagger, double moduleHalfLength, double lOverlap,
18  const std::pair<int, int>& binningSchema) {
19  int nPhiBins = binningSchema.first;
20  int nZbins = binningSchema.second;
21  // prepare the return value
22  std::vector<Acts::Vector3D> mPositions;
23  mPositions.reserve(nPhiBins * nZbins);
24  // prep work
25  double phiStep = 2 * M_PI / (nPhiBins);
26  double minPhi = -M_PI + 0.5 * phiStep;
27  double zStart = -0.5 * (nZbins - 1) * (2 * moduleHalfLength - lOverlap);
28  double zStep = 2 * std::abs(zStart) / (nZbins - 1);
29  // loop over the bins
30  for (size_t zBin = 0; zBin < size_t(nZbins); ++zBin) {
31  // prepare z and r
32  double moduleZ = zStart + zBin * zStep;
33  double moduleR =
34  (zBin % 2) ? radius - 0.5 * zStagger : radius + 0.5 * zStagger;
35  for (size_t phiBin = 0; phiBin < size_t(nPhiBins); ++phiBin) {
36  // calculate the current phi value
37  double modulePhi = minPhi + phiBin * phiStep;
38  mPositions.push_back(Acts::Vector3D(moduleR * cos(modulePhi),
39  moduleR * sin(modulePhi), moduleZ));
40  }
41  }
42  return mPositions;
43 }
44 
46 std::vector<std::vector<Acts::Vector3D>> modulePositionsDisc(
47  double z, double ringStagger, std::vector<double> phiStagger,
48  std::vector<double> phiSubStagger, double innerRadius, double outerRadius,
49  const std::vector<size_t>& discBinning,
50  const std::vector<double>& moduleHalfLength) {
51  // calculate the radii
52  std::vector<double> radii;
53  // calculate the radial borders
54  std::vector<double> radialBoarders;
55  // the radial span of the disc
56  double deltaR = outerRadius - innerRadius;
57  // quick exits
58  if (discBinning.size() == 1) {
59  radii.push_back(0.5 * (innerRadius + outerRadius));
60  radialBoarders = {innerRadius, outerRadius};
61  } else {
62  double totalLength = 0;
63  // sum up the total length
64  for (auto& mhlength : moduleHalfLength)
65  totalLength += 2 * mhlength;
66  // now calculate the overlap (equal pay)
67  double rOverlap = (totalLength - deltaR) / (moduleHalfLength.size() - 1);
68  // and now fill the radii and gaps
69  double lastR = innerRadius;
70  double lastHl = 0.;
71  double lastOl = 0.;
72  // remember the radial boarders
73  radialBoarders.push_back(innerRadius);
74  // now calculate
75  for (auto& mhlength : moduleHalfLength) {
76  // calculate the radius
77  radii.push_back(lastR + lastHl - lastOl + mhlength);
78  lastR = radii[radii.size() - 1];
79  lastOl = rOverlap;
80  lastHl = mhlength;
81  // and register the radial boarder
82  radialBoarders.push_back(lastR + 2 * lastHl - 0.5 * lastOl);
83  }
84  }
85  // now prepare the return method
86  std::vector<std::vector<Acts::Vector3D>> mPositions;
87  for (size_t ir = 0; ir < radii.size(); ++ir) {
88  // generate the z value
89  // convention inner ring is closer to origin : makes sense
90  double rz = radii.size() == 1
91  ? z
92  : (ir % 2 ? z + 0.5 * ringStagger : z - 0.5 * ringStagger);
93  // fill the ring positions
94  double psStagger = phiSubStagger.size() ? phiSubStagger[ir] : 0.;
95  mPositions.push_back(modulePositionsRing(rz, radii[ir], phiStagger[ir],
96  psStagger, discBinning[ir]));
97  }
98  return mPositions;
99 }
100 
102 std::vector<Acts::Vector3D> modulePositionsRing(double z, double radius,
103  double phiStagger,
104  double phiSubStagger,
105  int nPhiBins) {
106  // create and fill the positions
107  std::vector<Acts::Vector3D> rPositions;
108  rPositions.reserve(nPhiBins);
109  // prep work
110  double phiStep = 2 * M_PI / (nPhiBins);
111  double minPhi = -M_PI + 0.5 * phiStep;
112  // phi loop
113  for (size_t iphi = 0; iphi < size_t(nPhiBins); ++iphi) {
114  // if we have a phi sub stagger presents
115  double rzs = 0.;
116  // phi stagger affects 0 vs 1, 2 vs 3 ... etc
117  // -> only works if it is a %4
118  // phi sub stagger affects 2 vs 4, 1 vs 3 etc.
119  if (phiSubStagger != 0. && !(nPhiBins % 4)) {
120  // switch sides
121  if (!(iphi % 4)) {
122  rzs = phiSubStagger;
123  } else if (!((iphi + 1) % 4)) {
124  rzs = -phiSubStagger;
125  }
126  }
127  // the module phi
128  double phi = minPhi + iphi * phiStep;
129  // main z position depending on phi bin
130  double rz = iphi % 2 ? z - 0.5 * phiStagger : z + 0.5 * phiStagger;
131  rPositions.push_back(
132  Acts::Vector3D(radius * cos(phi), radius * sin(phi), rz + rzs));
133  }
134  return rPositions;
135 }
136 
137 } // end of namespace Generic
138 
139 } // end of namespace FW