-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathSector.h
More file actions
151 lines (125 loc) · 4.58 KB
/
Sector.h
File metadata and controls
151 lines (125 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// @file Sector.h
/// @author Jens Wiechula, Jens.Wiechula@ikf.uni-frankfurt.de
///
/// @brief Sector type
///
/// This class represents a Sector
/// Sectors are counted
/// from 0-17 (A-Side)
/// and 18-35 (C-Side)
///
/// origin: TPC
/// @author Jens Wiechula, Jens.Wiechula@ikf.uni-frankfurt.de
#ifndef AliceO2_TPC_Sector_H
#define AliceO2_TPC_Sector_H
#include "DataFormatsTPC/Constants.h"
#include "DataFormatsTPC/Defs.h"
//using namespace AliceO2::TPC;
namespace o2
{
namespace tpc
{
// enum RocType {ISector=0, OSector=1};
class Sector
{
public:
// the number of sectors
static constexpr int MAXSECTOR = constants::MAXSECTOR;
/// constructor
Sector() = default;
/// construction
/// @param [in] sec sector number
Sector(unsigned char sec) : mSector(sec % MAXSECTOR) { ; }
/// get Sector to the left of the current one
/// \param s Sector of interest
/// \return Sector left of the current one taking into account that the sector left of 17 (35) is 0 (18)
static Sector getLeft(const Sector s);
/// get Sector to the right of the current one
/// \param s Sector of interest
/// \return Sector right of the current one taking into account that the sector right of 0 (18) is 17 (35)
static Sector getRight(const Sector s);
/// comparison operator
bool operator==(const Sector& other) const { return mSector == other.mSector; }
/// unequal operator
bool operator!=(const Sector& other) const { return mSector != other.mSector; }
/// smaller operator
bool operator<(const Sector& other) const { return mSector < other.mSector; }
/// increment operator
/// This operator can be used to iterate over all sectors e.g.
/// Sector sec;
/// while (++sec) { std::cout << "Sector: " << sec.getSector() << std::endl; }
bool operator++()
{
mLoop = ++mSector >= MAXSECTOR;
mSector %= MAXSECTOR;
return mLoop;
}
/// int return operator to use similar as integer
/// \return sector number
operator int() const { return int(mSector); }
/// assignment operator with int
Sector& operator=(int sector)
{
mSector = sector % MAXSECTOR;
return *this;
}
unsigned char getSector() const { return mSector; }
Side side() const { return (mSector < MAXSECTOR / 2) ? Side::A : Side::C; }
bool looped() const { return mLoop; }
double phi() const { return (mSector % SECTORSPERSIDE) * SECPHIWIDTH + SECPHIWIDTH / 2.; }
/// helper function to retrieve a TPC sector given cartesian coordinates
/// \param x x position
/// \param y y position
/// \param z z position
template <typename T>
static int ToSector(T x, T y, T z)
{
static const T invangle(static_cast<T>(180) / static_cast<T>(M_PI * 20.)); // the angle describing one sector
// force positive angle for conversion
auto s = (std::atan2(-y, -x) + static_cast<T>(M_PI)) * invangle;
// detect if on C size
if (z < static_cast<T>(0.)) {
s += Sector::MAXSECTOR / 2;
}
return s;
}
/// helper function to retrieve a TPC sector given cartesian coordinates
/// the sector counting is shifte by -10deg in this case, so sector 0 will
/// be from -10 deg to +10 deg instead of 0-20
/// \param x x position
/// \param y y position
/// \param z z position
template <typename T>
static int ToShiftedSector(T x, T y, T z)
{
// static int ToSector(T x, T y, T z) {
constexpr T invangle{180. / (M_PI * 20.)}; // the angle describing one sector
constexpr T offset{M_PI + M_PI / 180. * 10.};
// force positive angle for conversion
auto s = static_cast<int>((std::atan2(-y, -x) + offset) * invangle) % 18;
// detect if on C size
if (z < static_cast<T>(0.)) {
s += Sector::MAXSECTOR / 2;
}
return s;
}
private:
unsigned char mSector{}; /// Sector representation 0-MAXSECTOR
bool mLoop{}; /// if operator execution resulted in looping
};
inline Sector Sector::getLeft(const Sector s) { return Sector((s + 1) % 18 + (s > 17) * 18); }
inline Sector Sector::getRight(const Sector s) { return Sector((s + 18 - 1) % 18 + (s > 17) * 18); }
} // namespace tpc
} // namespace o2
#endif