ATLAS Offline Software
MuonSectorMapping.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUON_MUONSECTORMAPPING_H
6 #define MUON_MUONSECTORMAPPING_H
7 
8 #include <math.h>
9 
10 #include <array>
11 #include <iostream>
12 #include <vector>
13 
15 
17 
18 namespace Muon {
19 
21  public:
23  bool insideSector(int sector, double phi) const;
24 
26  int getSector(double phi) const;
27 
29  void getSectors(double phi, std::vector<int>& sectors) const;
30 
32  double sectorPhi(int sector) const;
33 
35  double transformPhiToSector(double phi, int sector, bool toSector = true) const;
36 
38  double transformRToSector(double r, double phi, int sector, bool toSector = true) const;
39 
41  double sectorOverlapPhi(int sector1, int sector2) const;
42 
44  bool closeToSectorBoundary(double phi) const;
45 
47  double transformRToNeighboringSector(double r, int sectorHit, int sectorTarget) const;
48 
50  double sectorSize(int sector) const;
51 
53  double sectorWidth(int sector) const;
54 
55  private:
56  static constexpr double s_oneEightsOfPi{M_PI / 8.}; // pi/8
57  static constexpr double s_inverseOneEightsOfPi{8. / M_PI}; // 8/pi
58  static constexpr std::array<double, 2> s_sectorSize{0.4 * s_oneEightsOfPi, 0.6 * s_oneEightsOfPi}; // side of a sector in radiants
59  static constexpr double s_sectorOverlap{0.1 * s_oneEightsOfPi}; // size of the overlap between small and large sectors
60  static bool s_debug ATLAS_THREAD_SAFE; // if true addition cout is enabled
61  };
62 
63  inline double MuonSectorMapping::sectorSize(int sector) const {
64  const int idx = sector % 2;
65  return s_sectorSize[idx];
66  }
67 
68  inline double MuonSectorMapping::sectorWidth(int sector) const { return sectorSize(sector) + s_sectorOverlap; }
69 
70  inline bool MuonSectorMapping::insideSector(int sector, double phi) const {
71  double phiInSec = transformPhiToSector(phi, sector);
72  if (phiInSec < -sectorWidth(sector)) return false;
73  if (phiInSec > sectorWidth(sector)) return false;
74  return true;
75  }
76 
77  inline double MuonSectorMapping::sectorPhi(int sector) const {
78  if (sector < 10) return M_PI * (sector - 1) / 8.;
79  return -M_PI * (2 - (sector - 1) / 8.);
80  }
81 
82  inline int MuonSectorMapping::getSector(double phi) const {
83  // remap phi onto sector structure
84  double val = (phi + sectorSize(1)) * s_inverseOneEightsOfPi; // convert to value between -8 and 8, shift by width first sector
85  if (val < 0) val += 16;
86  int sliceIndex = static_cast<int>(val / 2); // large/small wedge
87  double valueInSlice = val - 2 * sliceIndex;
88  int sector = 2 * sliceIndex + 1;
89  if (valueInSlice > 1.2) ++sector;
90  return sector;
91  }
92 
93  inline void MuonSectorMapping::getSectors(double phi, std::vector<int>& sectors) const {
94  int sector = getSector(phi);
95  int sectorNext = sector != 16 ? sector + 1 : 1;
96  int sectorBefore = sector != 1 ? sector - 1 : 16;
97  if (insideSector(sectorBefore, phi)) sectors.push_back(sectorBefore);
98  if (insideSector(sector, phi)) sectors.push_back(sector);
99  if (insideSector(sectorNext, phi)) sectors.push_back(sectorNext);
100  }
101 
102  inline bool MuonSectorMapping::closeToSectorBoundary(double phi) const {
103  std::vector<int> sectors;
104  getSectors(phi, sectors);
105  return sectors.size() > 1;
106  }
107 
108  inline double MuonSectorMapping::transformPhiToSector(double phi, int sector, bool toSector) const {
109  double sign = toSector ? -1 : 1;
110  double dphi = phi + sign * sectorPhi(sector);
111  if (dphi > M_PI) dphi -= 2 * M_PI;
112  if (dphi < -M_PI) dphi += 2 * M_PI;
113  return dphi;
114  }
115 
116  inline double MuonSectorMapping::sectorOverlapPhi(int sector1, int sector2) const {
117  if (sector1 == sector2) return sectorPhi(sector1);
118 
119  int s1 = sector1 < sector2 ? sector1 : sector2;
120  int s2 = sector1 > sector2 ? sector1 : sector2;
121  if (s2 == 16 && s1 == 1) {
122  s1 = 16;
123  s2 = 1;
124  } else if (std::abs(s1 - s2) > 1) {
125  if (s_debug) std::cout << " bad sector combination: not neighbouring " << s1 << " " << s2 << std::endl;
126  return 0;
127  }
128 
129  double phi1 = sectorPhi(s1);
130  double phio1 = phi1 + sectorSize(s1);
131  if (phio1 > M_PI) phio1 -= 2 * M_PI;
132 
133  return phio1;
134  }
135 
136  inline double MuonSectorMapping::transformRToSector(double r, double phi, int sector, bool toSector) const {
137  double dphi = transformPhiToSector(phi, sector);
138  if (std::abs(dphi) > 0.3 && s_debug) {
139  std::cout << " large dphi detected!!: phi " << phi << " sector " << sector << " phi " << sectorPhi(sector) << " " << phi
140  << " dphi " << dphi << std::endl;
141  }
142  if (toSector)
143  return r * std::cos(dphi);
144  else
145  return r / std::cos(dphi);
146  }
147 
148  inline double MuonSectorMapping::transformRToNeighboringSector(double r, int sectorHit, int sector) const {
149  double phi = sectorPhi(sectorHit);
150  double phio = sectorOverlapPhi(sectorHit, sector);
151  double dphio = phi - phio;
152  if (dphio < -M_PI) dphio += 2 * M_PI;
153  double redge = r / std::cos(dphio);
154  double phi_sec = sectorPhi(sector);
155  double dphi = phio - phi_sec;
156  if (dphi < -M_PI) dphi += 2 * M_PI;
157  if (std::abs(dphi) > 0.3 && s_debug) {
158  std::cout << " large dphi detected!!: sector " << sector << " of hit " << sectorHit << " phi ref sector " << phi_sec << " hit "
159  << phi << " dphi " << dphi << std::endl;
160  }
161  return redge * std::cos(dphi);
162  }
163 
164 } // namespace Muon
165 
166 #endif
beamspotman.r
def r
Definition: beamspotman.py:676
Muon::MuonSectorMapping::sectorSize
double sectorSize(int sector) const
sector size (exclusive) in radians
Definition: MuonSectorMapping.h:63
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
Muon::MuonSectorMapping::sectorWidth
double sectorWidth(int sector) const
sector width (with overlap) in radians
Definition: MuonSectorMapping.h:68
Muon::MuonSectorMapping::transformRToSector
double transformRToSector(double r, double phi, int sector, bool toSector=true) const
expresses a radial position from and to the sector coordinate frame, the phi position should always b...
Definition: MuonSectorMapping.h:136
Muon::MuonSectorMapping::closeToSectorBoundary
bool closeToSectorBoundary(double phi) const
checks whether the phi position is close to a sector boundary
Definition: MuonSectorMapping.h:102
Muon::MuonSectorMapping::getSectors
void getSectors(double phi, std::vector< int > &sectors) const
returns the main sector plus neighboring if the phi position is in an overlap region
Definition: MuonSectorMapping.h:93
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Muon::MuonSectorMapping::transformPhiToSector
double transformPhiToSector(double phi, int sector, bool toSector=true) const
transforms a phi position from and to the sector coordinate system in radians
Definition: MuonSectorMapping.h:108
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
Muon::MuonSectorMapping::s_sectorSize
static constexpr std::array< double, 2 > s_sectorSize
Definition: MuonSectorMapping.h:58
Muon::MuonSectorMapping::getSector
int getSector(double phi) const
returns the sector corresponding to the phi position
Definition: MuonSectorMapping.h:82
ATLAS_CHECK_FILE_THREAD_SAFETY
ATLAS_CHECK_FILE_THREAD_SAFETY
Definition: MuonSectorMapping.h:16
Muon::MuonSectorMapping::insideSector
bool insideSector(int sector, double phi) const
checks whether the phi position is consistent with sector
Definition: MuonSectorMapping.h:70
Muon::MuonSectorMapping::s_oneEightsOfPi
static constexpr double s_oneEightsOfPi
Definition: MuonSectorMapping.h:56
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:127
Muon::MuonSectorMapping::sectorPhi
double sectorPhi(int sector) const
returns the centeral phi position of a sector in radians
Definition: MuonSectorMapping.h:77
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
Muon::MuonSectorMapping::s_inverseOneEightsOfPi
static constexpr double s_inverseOneEightsOfPi
Definition: MuonSectorMapping.h:57
Muon::MuonSectorMapping
Definition: MuonSectorMapping.h:20
Muon::MuonSectorMapping::transformRToNeighboringSector
double transformRToNeighboringSector(double r, int sectorHit, int sectorTarget) const
transform a radial position from one sector frame into another
Definition: MuonSectorMapping.h:148
Muon::MuonSectorMapping::s_sectorOverlap
static constexpr double s_sectorOverlap
Definition: MuonSectorMapping.h:59
Muon::MuonSectorMapping::sectorOverlapPhi
double sectorOverlapPhi(int sector1, int sector2) const
returns the phi position of the overlap between the two sectors (which have to be neighboring) in rad...
Definition: MuonSectorMapping.h:116
checker_macros.h
Define macros for attributes used to control the static checker.
Muon::MuonSectorMapping::ATLAS_THREAD_SAFE
static bool s_debug ATLAS_THREAD_SAFE
Definition: MuonSectorMapping.h:60