Project
Loading...
Searching...
No Matches
CathodeSegmentation.h
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
17#ifndef O2_MCH_MAPPING_CATHODESEGMENTATION_H
18#define O2_MCH_MAPPING_CATHODESEGMENTATION_H
19
21#include <stdexcept>
22#include <memory>
23#include <iostream>
24#include <vector>
25#include <sstream>
26#include <functional>
27#include <iomanip>
28
29namespace o2
30{
31namespace mch
32{
33namespace mapping
34{
35
62
64{
65 public:
68 : mImpl{nullptr},
69 mDualSampaIds{},
70 mDetElemId{detElemId},
71 mIsBendingPlane{isBendingPlane}
72 {
73 if (&mchCathodeSegmentationConstruct == nullptr) {
74 throw std::runtime_error("no mch mapping implementaion found : did you forget to link with an actual implementation library (e.g. O2MCHMappingImpl4) ? ");
75 }
77 if (!mImpl) {
78 throw std::runtime_error("Can not create segmentation for DE " + std::to_string(detElemId) +
79 (mIsBendingPlane ? " Bending" : " NonBending"));
80 }
81 std::vector<int> dpid;
82 auto addDualSampaId = [&dpid](int dualSampaId) { dpid.push_back(dualSampaId); };
83 auto callback = [](void* data, int dualSampaId) {
84 auto fn = static_cast<decltype(&addDualSampaId)>(data);
85 (*fn)(dualSampaId);
86 };
87 mchCathodeSegmentationForEachDualSampa(mImpl, callback, &addDualSampaId);
88 mDualSampaIds = dpid;
89 int n{0};
90 for (auto i = 0; i < nofDualSampas(); ++i) {
91 forEachPadInDualSampa(dualSampaId(i), [&n](int /*catPadIndex*/) { ++n; });
92 }
93 mNofPads = n;
94 }
95
96 bool operator==(const CathodeSegmentation& rhs) const
97 {
98 return mDetElemId == rhs.mDetElemId && mIsBendingPlane == rhs.mIsBendingPlane;
99 }
100
101 bool operator!=(const CathodeSegmentation& rhs) const { return !(rhs == *this); }
102
104 {
105 using std::swap;
106
107 swap(a.mImpl, b.mImpl);
108 swap(a.mDualSampaIds, b.mDualSampaIds);
109 swap(a.mDetElemId, b.mDetElemId);
110 swap(a.mIsBendingPlane, b.mIsBendingPlane);
111 swap(a.mNofPads, b.mNofPads);
112 }
113
115 {
116 mDetElemId = seg.mDetElemId;
117 mIsBendingPlane = seg.mIsBendingPlane;
118 mImpl = mchCathodeSegmentationConstruct(mDetElemId, mIsBendingPlane);
119 mDualSampaIds = seg.mDualSampaIds;
120 mNofPads = seg.mNofPads;
121 }
122
124 {
125 swap(*this, seg);
126 return *this;
127 }
128
130
139 bool isValid(int catPadIndex) const { return mchCathodeSegmentationIsPadValid(mImpl, catPadIndex) > 0; }
141
150
151 int findPadByPosition(double x, double y) const { return mchCathodeSegmentationFindPadByPosition(mImpl, x, y); }
152
154 int findPadByFEE(int dualSampaId, int dualSampaChannel) const
155 {
156 if (dualSampaChannel < 0 || dualSampaChannel > 63) {
157 throw std::out_of_range("dualSampaChannel should be between 0 and 63");
158 }
159 return mchCathodeSegmentationFindPadByFEE(mImpl, dualSampaId, dualSampaChannel);
160 }
162
167 double padPositionX(int catPadIndex) const { return mchCathodeSegmentationPadPositionX(mImpl, catPadIndex); }
168 double padPositionY(int catPadIndex) const { return mchCathodeSegmentationPadPositionY(mImpl, catPadIndex); }
169 double padSizeX(int catPadIndex) const { return mchCathodeSegmentationPadSizeX(mImpl, catPadIndex); }
170 double padSizeY(int catPadIndex) const { return mchCathodeSegmentationPadSizeY(mImpl, catPadIndex); }
171 int padDualSampaId(int catPadIndex) const { return mchCathodeSegmentationPadDualSampaId(mImpl, catPadIndex); }
172 int padDualSampaChannel(int catPadIndex) const { return mchCathodeSegmentationPadDualSampaChannel(mImpl, catPadIndex); }
173 std::string padAsString(int catPadIndex) const;
175
178 bool isBendingPlane() const { return mIsBendingPlane; }
179 int nofDualSampas() const { return mDualSampaIds.size(); }
180 int nofPads() const { return mNofPads; }
183 int dualSampaId(int dualSampaIndex) const { return mDualSampaIds[dualSampaIndex]; }
185
187 void forEachDualSampa(std::function<void(int dualSampaId)> func) const;
188
194 template <typename CALLABLE>
195 void forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const;
196
197 template <typename CALLABLE>
198 void forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const;
199
200 template <typename CALLABLE>
201 void forEachPad(CALLABLE&& func) const;
202
203 template <typename CALLABLE>
204 void forEachNeighbouringPad(int catPadIndex, CALLABLE&& func) const;
206 private:
208 std::vector<int> mDualSampaIds;
209 int mDetElemId;
210 bool mIsBendingPlane;
211 int mNofPads = 0;
212};
213
214template <typename CALLABLE>
215void CathodeSegmentation::forEachPadInDualSampa(int dualSampaId, CALLABLE&& func) const
216{
217 auto callback = [](void* data, int catPadIndex) {
218 auto fn = static_cast<decltype(&func)>(data);
219 (*fn)(catPadIndex);
220 };
222}
223
224template <typename CALLABLE>
225void CathodeSegmentation::forEachPadInArea(double xmin, double ymin, double xmax, double ymax, CALLABLE&& func) const
226{
227 auto callback = [](void* data, int catPadIndex) {
228 auto fn = static_cast<decltype(&func)>(data);
229 (*fn)(catPadIndex);
230 };
231 mchCathodeSegmentationForEachPadInArea(mImpl, xmin, ymin, xmax, ymax, callback, &func);
232}
233
234template <typename CALLABLE>
236{
237 for (auto i = 0; i < nofPads(); i++) {
238 func(i);
239 }
240}
241
242template <typename CALLABLE>
243void CathodeSegmentation::forEachNeighbouringPad(int catPadIndex, CALLABLE&& func) const
244{
245 auto callback = [](void* data, int puid) {
246 auto fn = static_cast<decltype(&func)>(data);
247 (*fn)(puid);
248 };
249 mchCathodeSegmentationForEachNeighbouringPad(mImpl, catPadIndex, callback, &func);
250}
251
252inline void CathodeSegmentation::forEachDualSampa(std::function<void(int dualSampaId)> func) const
253{
254 auto callback = [](void* data, int dualSampaId) {
255 auto fn = static_cast<decltype(&func)>(data);
256 (*fn)(dualSampaId);
257 };
259}
260
262template <typename CALLABLE>
264{
265 auto callback = [](void* data, int detElemId) {
266 auto fn = static_cast<decltype(&func)>(data);
267 (*fn)(detElemId);
268 };
270}
271
273template <typename CALLABLE>
275{
276 auto callback = [](void* data, int detElemId) {
277 auto fn = static_cast<decltype(&func)>(data);
278 (*fn)(detElemId);
279 };
281}
282
284inline std::string CathodeSegmentation::padAsString(int catPadIndex) const
285{
286 if (!isValid(catPadIndex)) {
287 return "invalid pad with uid=" + std::to_string(catPadIndex);
288 }
289 std::stringstream s;
290
291 s << "FEC " << std::setw(4) << padDualSampaId(catPadIndex)
292 << "CH " << std::setw(2) << padDualSampaChannel(catPadIndex)
293 << "X " << std::setw(7) << std::setprecision(2) << padPositionX(catPadIndex)
294 << "Y " << std::setw(7) << std::setprecision(2) << padPositionY(catPadIndex)
295 << "SX " << std::setw(7) << std::setprecision(2) << padSizeX(catPadIndex)
296 << "SY " << std::setw(7) << std::setprecision(2) << padSizeY(catPadIndex);
297
298 return s.str();
299}
300
301} // namespace mapping
302} // namespace mch
303} // namespace o2
304#endif
o2::mch::mapping::CathodeSegmentation seg
O2MCHMAPPINGIMPL3_EXPORT double mchCathodeSegmentationPadPositionY(MchCathodeSegmentationHandle segHandle, int catPadIndex)
O2MCHMAPPINGIMPL3_EXPORT double mchCathodeSegmentationPadSizeY(MchCathodeSegmentationHandle segHandle, int catPadIndex)
O2MCHMAPPINGIMPL3_EXPORT int mchCathodeSegmentationPadDualSampaId(MchCathodeSegmentationHandle segHandle, int catPadIndex)
O2MCHMAPPINGIMPL3_EXPORT int mchCathodeSegmentationIsPadValid(MchCathodeSegmentationHandle segHandle, int catPadIndex)
Return > 0 if catPadIndex is a valid one or <= 1 if not.
O2MCHMAPPINGIMPL3_EXPORT int mchCathodeSegmentationFindPadByPosition(MchCathodeSegmentationHandle segHandle, double x, double y)
Find the pad at position (x,y) (in cm).
O2MCHMAPPINGIMPL3_EXPORT void mchCathodeSegmentationForEachNeighbouringPad(MchCathodeSegmentationHandle segHandle, int catPadIndex, MchPadHandler handler, void *userData)
O2MCHMAPPINGIMPL3_EXPORT void mchCathodeSegmentationForEachPadInArea(MchCathodeSegmentationHandle segHandle, double xmin, double ymin, double xmax, double ymax, MchPadHandler handler, void *clientData)
O2MCHMAPPINGIMPL3_EXPORT double mchCathodeSegmentationPadSizeX(MchCathodeSegmentationHandle segHandle, int catPadIndex)
O2MCHMAPPINGIMPL3_EXPORT int mchCathodeSegmentationFindPadByFEE(MchCathodeSegmentationHandle segHandle, int dualSampaId, int dualSampaChannel)
Find the pad connected to the given channel of the given dual sampa.
O2MCHMAPPINGIMPL3_EXPORT void mchCathodeSegmentationForEachDualSampa(MchCathodeSegmentationHandle segHandle, MchDualSampaHandler handler, void *clientData)
O2MCHMAPPINGIMPL3_EXPORT double mchCathodeSegmentationPadPositionX(MchCathodeSegmentationHandle segHandle, int catPadIndex)
O2MCHMAPPINGIMPL3_EXPORT void mchCathodeSegmentationForOneDetectionElementOfEachSegmentationType(MchDetectionElementHandler handler, void *clientData)
O2MCHMAPPINGIMPL3_EXPORT void mchCathodeSegmentationForEachDetectionElement(MchDetectionElementHandler handler, void *clientData)
O2MCHMAPPINGIMPL3_EXPORT void mchCathodeSegmentationDestruct(MchCathodeSegmentationHandle sh)
Delete a segmentation handle.
O2MCHMAPPINGIMPL3_EXPORT void mchCathodeSegmentationForEachPadInDualSampa(MchCathodeSegmentationHandle segHandle, int dualSampaId, MchPadHandler handler, void *clientData)
O2MCHMAPPINGIMPL3_EXPORT MchCathodeSegmentationHandle mchCathodeSegmentationConstruct(int detElemId, bool isBendingPlane)
Create a handle to a segmentation for a given plane of a detection element.
O2MCHMAPPINGIMPL3_EXPORT int mchCathodeSegmentationPadDualSampaChannel(MchCathodeSegmentationHandle segHandle, int catPadIndex)
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
A CathodeSegmentation lets you find pads on a given plane (cathode) of a detection element and then i...
int dualSampaId(int dualSampaIndex) const
CathodeSegmentation(const CathodeSegmentation &seg)
double padSizeY(int catPadIndex) const
double padSizeX(int catPadIndex) const
void forEachPadInDualSampa(int dualSampaId, CALLABLE &&func) const
std::string padAsString(int catPadIndex) const
CathodeSegmentation(int detElemId, bool isBendingPlane)
This ctor throws if detElemId is invalid.
bool operator!=(const CathodeSegmentation &rhs) const
int padDualSampaChannel(int catPadIndex) const
int padDualSampaId(int catPadIndex) 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
double padPositionY(int catPadIndex) const
int findPadByFEE(int dualSampaId, int dualSampaChannel) const
double padPositionX(int catPadIndex) const
CathodeSegmentation & operator=(CathodeSegmentation seg)
void forEachNeighbouringPad(int catPadIndex, CALLABLE &&func) const
bool isValid(int catPadIndex) const
Not every integer is a valid catPadIndex. This method will tell if catPadIndex is a valid one.
bool operator==(const CathodeSegmentation &rhs) const
friend void swap(CathodeSegmentation &a, CathodeSegmentation &b)
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum func
Definition glcorearb.h:778
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
constexpr std::array< std::string_view, BasicOp::Conditional+1 > mapping
a map between BasicOp and tokens in string expressions
void forOneDetectionElementOfEachSegmentationType(CALLABLE &&func)
void forEachDetectionElement(CALLABLE &&func)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52