Project
Loading...
Searching...
No Matches
Segmentation.inl
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12namespace o2
13{
14namespace mch
15{
16namespace mapping
17{
18
19inline Segmentation::Segmentation(int deid) : mDetElemId{deid}, mBending{CathodeSegmentation(deid, true)}, mNonBending{CathodeSegmentation(deid, false)}, mPadIndexOffset{mBending.nofPads()}
20{
21}
22
23inline bool Segmentation::operator==(const Segmentation& rhs) const
24{
25 return mDetElemId == rhs.mDetElemId;
26}
27
28inline bool Segmentation::operator!=(const Segmentation& rhs) const { return !(rhs == *this); }
29
31{
32 using std::swap;
33 swap(a.mDetElemId, b.mDetElemId);
34 swap(a.mPadIndexOffset, b.mPadIndexOffset);
35}
36
37inline Segmentation::Segmentation(const Segmentation& seg) = default;
38
39inline Segmentation::Segmentation(const Segmentation&& seg) : mBending{std::move(seg.mBending)}, mNonBending{std::move(seg.mNonBending)}, mDetElemId{seg.mDetElemId}, mPadIndexOffset{seg.mPadIndexOffset}
40{
41}
42
43inline Segmentation& Segmentation::operator=(Segmentation seg)
44{
45 swap(*this, seg);
46 return *this;
47}
48
49inline int Segmentation::findPadByFEE(int dualSampaId, int dualSampaChannel) const
50{
51 bool isBending = dualSampaId < 1024;
52 int catPadIndex;
53 if (isBending) {
54 catPadIndex = mBending.findPadByFEE(dualSampaId, dualSampaChannel);
55 if (!mBending.isValid(catPadIndex)) {
56 return -1;
57 }
58 } else {
59 catPadIndex = mNonBending.findPadByFEE(dualSampaId, dualSampaChannel);
60 if (!mNonBending.isValid(catPadIndex)) {
61 return -1;
62 }
63 }
64 return padC2DE(catPadIndex, isBending);
65}
66
67inline bool Segmentation::isValid(int dePadIndex) const
68{
69 return dePadIndex >= 0 && dePadIndex < nofPads();
70}
71
72inline int Segmentation::padC2DE(int catPadIndex, bool isBending) const
73{
74 if (isBending) {
75 return catPadIndex;
76 }
77 return catPadIndex + mPadIndexOffset;
78}
79
80inline void Segmentation::catSegPad(int dePadIndex, const CathodeSegmentation*& catseg, int& padcuid) const
81{
82 if (!isValid(dePadIndex)) {
83 catseg = nullptr;
84 return;
85 }
86 if (dePadIndex < mPadIndexOffset) {
87 catseg = &mBending;
88 padcuid = dePadIndex;
89 return;
90 }
91 catseg = &mNonBending;
92 padcuid = dePadIndex - mPadIndexOffset;
93}
94
95inline bool Segmentation::findPadPairByPosition(double x, double y, int& b, int& nb) const
96{
97 b = mBending.findPadByPosition(x, y);
98 nb = mNonBending.findPadByPosition(x, y);
99 if (!mBending.isValid(b)) {
100 if (mNonBending.isValid(nb)) {
101 nb = padC2DE(nb, false);
102 }
103 return false;
104 }
105 if (!mNonBending.isValid(nb)) {
106 b = padC2DE(b, true);
107 return false;
108 }
109 b = padC2DE(b, true);
110 nb = padC2DE(nb, false);
111 return true;
112}
113
114template <typename CALLABLE>
115void Segmentation::forEachPad(CALLABLE&& func) const
116{
117 mBending.forEachPad(func);
118 int offset{mPadIndexOffset};
119 mNonBending.forEachPad([&offset, &func](int catPadIndex) {
120 func(catPadIndex + offset);
121 });
122}
123
124template <typename CALLABLE>
125void Segmentation::forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const
126{
127 bool isBending = dualSampaId < 1024;
128 if (isBending) {
129 mBending.forEachPadInDualSampa(dualSampaId, func);
130 } else {
131 int offset{mPadIndexOffset};
132 mNonBending.forEachPadInDualSampa(dualSampaId, [&offset, &func](int catPadIndex) {
133 func(catPadIndex + offset);
134 });
135 }
136}
137
138template <typename CALLABLE>
139void Segmentation::forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const
140{
141 mBending.forEachPadInArea(xmin, ymin, xmax, ymax, func);
142 int offset{mPadIndexOffset};
143 mNonBending.forEachPadInArea(xmin, ymin, xmax, ymax, [&offset, &func](int catPadIndex) {
144 func(catPadIndex + offset);
145 });
146}
147
148template <typename CALLABLE>
149void Segmentation::forEachNeighbouringPad(int dePadIndex, CALLABLE&& func) const
150{
151 const CathodeSegmentation* catSeg{nullptr};
152 int catPadIndex;
153 catSegPad(dePadIndex, catSeg, catPadIndex);
154
155 int offset{0};
156 if (!isBendingPad(dePadIndex)) {
157 offset = mPadIndexOffset;
158 }
159 catSeg->forEachNeighbouringPad(catPadIndex, [&offset, &func](int cindex) {
160 func(cindex + offset);
161 });
162}
163
164inline void Segmentation::forEachDualSampa(std::function<void(int dualSampaId)> func) const
165{
166 mBending.forEachDualSampa(func);
167 mNonBending.forEachDualSampa(func);
168}
169
170inline std::string Segmentation::padAsString(int dePadIndex) const
171{
172 if (!isValid(dePadIndex)) {
173 return "invalid pad with index=" + std::to_string(dePadIndex);
174 }
175 const CathodeSegmentation* catSeg{nullptr};
176 int catPadIndex;
177 catSegPad(dePadIndex, catSeg, catPadIndex);
178 auto s = catSeg->padAsString(catPadIndex);
179 if (isBendingPad(dePadIndex)) {
180 s += " (B)";
181 } else {
182 s += " (NB)";
183 }
184 return s;
185}
186
187inline int Segmentation::padDualSampaId(int dePadIndex) const
188{
189 const CathodeSegmentation* catSeg{nullptr};
190 int catPadIndex;
191 catSegPad(dePadIndex, catSeg, catPadIndex);
192 return catSeg->padDualSampaId(catPadIndex);
193}
194
195inline int Segmentation::padDualSampaChannel(int dePadIndex) const
196{
197 const CathodeSegmentation* catSeg{nullptr};
198 int catPadIndex;
199 catSegPad(dePadIndex, catSeg, catPadIndex);
200 return catSeg->padDualSampaChannel(catPadIndex);
201}
202
203inline double Segmentation::padPositionX(int dePadIndex) const
204{
205 const CathodeSegmentation* catSeg{nullptr};
206 int catPadIndex;
207 catSegPad(dePadIndex, catSeg, catPadIndex);
208 return catSeg->padPositionX(catPadIndex);
209}
210
211inline double Segmentation::padPositionY(int dePadIndex) const
212{
213 const CathodeSegmentation* catSeg{nullptr};
214 int catPadIndex;
215 catSegPad(dePadIndex, catSeg, catPadIndex);
216 return catSeg->padPositionY(catPadIndex);
217}
218
219inline double Segmentation::padSizeX(int dePadIndex) const
220{
221 const CathodeSegmentation* catSeg{nullptr};
222 int catPadIndex;
223 catSegPad(dePadIndex, catSeg, catPadIndex);
224 return catSeg->padSizeX(catPadIndex);
225}
226
227inline double Segmentation::padSizeY(int dePadIndex) const
228{
229 const CathodeSegmentation* catSeg{nullptr};
230 int catPadIndex;
231 catSegPad(dePadIndex, catSeg, catPadIndex);
232 return catSeg->padSizeY(catPadIndex);
233}
234
235inline int Segmentation::detElemId() const { return mDetElemId; }
236inline int Segmentation::nofPads() const { return bending().nofPads() + nonBending().nofPads(); }
237inline int Segmentation::nofDualSampas() const { return bending().nofDualSampas() + nonBending().nofDualSampas(); }
238
239inline const CathodeSegmentation& Segmentation::bending() const { return mBending; }
240inline const CathodeSegmentation& Segmentation::nonBending() const { return mNonBending; }
241
242} // namespace mapping
243} // namespace mch
244} // namespace o2
o2::mch::mapping::CathodeSegmentation seg
A CathodeSegmentation lets you find pads on a given plane (cathode) of a detection element and then i...
void forEachPadInDualSampa(int dualSampaId, CALLABLE &&func) const
void forEachDualSampa(std::function< void(int dualSampaId)> func) const
Loop over dual sampas of this detection element.
void forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE &&func) const
int findPadByPosition(double x, double y) const
int findPadByFEE(int dualSampaId, int dualSampaChannel) const
bool isValid(int catPadIndex) const
Not every integer is a valid catPadIndex. This method will tell if catPadIndex is a valid one.
A Segmentation lets you find pads of a detection element and then inspect those pads.
const CathodeSegmentation & nonBending() const
const CathodeSegmentation & bending() const
bool isBendingPad(int dePadIndex) const
friend void swap(Segmentation &a, Segmentation &b)
bool isValid(int dePadIndex) const
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum func
Definition glcorearb.h:778
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLintptr offset
Definition glcorearb.h:660
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
void swap(Segmentation &a, Segmentation &b)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52