Belle II Software  release-08-01-10
ARICHGeoDetectorPlane.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <arich/dbobjects/ARICHGeoDetectorPlane.h>
10 #include <math.h>
11 #include <iostream>
12 
13 using namespace std;
14 using namespace Belle2;
15 
16 void ARICHGeoDetectorPlane::setRingPar(const std::vector<std::pair<double, double>>& ringPar)
17 {
18  m_ringPar = ringPar;
19 
20  for (auto ring : m_ringPar) {
21  double iPhi = ring.second / 2.;
22  while (iPhi < 2 * M_PI) {
23  m_slotPar.push_back({ring.first, iPhi});
24  iPhi += ring.second;
25  }
26  }
27 
28  m_nRings = m_ringPar.size();
29  m_nSlots = m_slotPar.size();
30 
31 }
32 
33 unsigned ARICHGeoDetectorPlane::getSlotRing(unsigned slotID) const
34 {
35 
36  if (slotID > m_nSlots) B2ERROR("ARICHGeoDetectorPlane: invalid module slot ID number!");
37  unsigned iRing = 1;
38  unsigned nSlots = 0;
39  for (auto dphi : m_ringPar) {
40  nSlots += static_cast<int>(2 * M_PI / dphi.second + 0.5);
41  if (slotID < nSlots + 1) return iRing;
42  iRing++;
43  }
44  return 0;
45 }
46 
47 
48 unsigned ARICHGeoDetectorPlane::pointSlotID(double x, double y) const
49 {
50  double r = sqrt(x * x + y * y);
51  double phi = atan2(y, x);
52  if (phi < 0) phi += 2 * M_PI;
53  if (r < (m_ringPar[0].first - (m_ringPar[1].first - m_ringPar[0].first) / 2.)) return 0;
54 
55  if (r > (m_ringPar[m_nRings - 1].first + (m_ringPar[m_nRings - 1].first - m_ringPar[m_nRings - 2].first) / 2.)) return 0;
56 
57  unsigned nslot = 0;
58  for (unsigned i = 1; i < m_nRings; i++) {
59  if (r < (m_ringPar[i - 1].first + m_ringPar[i].first) / 2.) {
60  nslot += phi / m_ringPar[i - 1].second;
61  return nslot + 1;
62  }
63  nslot += static_cast<int>(2 * M_PI / m_ringPar[i - 1].second + 0.5);
64  }
65  nslot += phi / m_ringPar[m_nRings - 1].second;
66  return nslot + 1;
67 }
68 
69 bool ARICHGeoDetectorPlane::isConsistent() const
70 {
71  if (m_outerR < m_innerR) return false;
72  if (m_thickness <= 0) return false;
73  if (m_moduleHoleSize < 0) return false;
74  if (m_supportBackWallHeight < 0) return false;
75  if (m_supportBackWallThickness < 0) return false;
76  if (m_supportZPosition < 0) return false;
77  if (m_ringPar.size() == 0 || m_slotPar.size() == 0) return false;
78  return true;
79 }
80 
81 unsigned ARICHGeoDetectorPlane::getSlotIDFromSRF(unsigned sector, unsigned ring, unsigned azimuth) const
82 {
83 
84  if (azimuth > static_cast<unsigned>(2 * M_PI / m_ringPar[ring - 1].second + 0.5) / 6 || ring > getNRings() || sector > 6)
85  { B2ERROR("ARICHGeoDetectorPlane::getSlotIDFromSRF: invalid slot position parameters!"); return 0;}
86 
87  unsigned moduleID = 0;
88  for (unsigned i = 1; i < ring; i++) {
89  moduleID += static_cast<int>(2 * M_PI / m_ringPar[i - 1].second + 0.5);
90  }
91  moduleID += (sector - 1) * static_cast<int>(2 * M_PI / m_ringPar[ring - 1].second + 0.5) / 6 + (azimuth - 1);
92  if (moduleID + 1 > m_nSlots) {B2ERROR("ARICHGeoDetectorPlane::getSlotIDFromSRF: invalid slot position parameters!"); return 0;}
93  return moduleID + 1;
94 }
95 
96 
97 void ARICHGeoDetectorPlane::print(const std::string& title) const
98 {
99  ARICHGeoBase::print(title);
100  cout << "Configuration of module slots:" << endl;
101  int i = 0;
102  cout << " There are " << getNRings() << " module rings." << endl;
103  for (auto ring : m_ringPar) {
104  cout << " ring: " << i + 1 << " has " << static_cast<int>(2 * M_PI / ring.second + 0.5) << " module slots, at radius: " <<
105  ring.first << " cm" << endl;
106  i++;
107  }
108 
109  cout << " Support plate inner radius: " << getSupportInnerR() << " " << s_unitName << endl;
110  cout << " Support plate outer radius: " << getSupportOuterR() << " " << s_unitName << endl;
111  cout << " Support plate thickness: " << getSupportThickness() << " " << s_unitName << endl;
112  cout << " Support plate Z position: " << getSupportZPosition() << " " << s_unitName << endl;
113  cout << " Support plate backwalls height: " << getSupportBackWallHeight() << " " << s_unitName << endl;
114  cout << " Support plate backwall thickness: " << getSupportBackWallThickness() << " " << s_unitName << endl;
115  cout << " Support plate module hole size: " << getModuleHoleSize() << " X " << getModuleHoleSize() << " " << s_unitName << endl;
116  cout << " Support plate material: " << getSupportMaterial() << endl;
117 
118  cout << "Positioning parameters (in local ARICH frame)" << endl;
119  ARICHGeoBase::printPlacement(m_x, m_y, m_z, m_rx, m_ry, m_rz);
120 
121 }
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.