Project
Loading...
Searching...
No Matches
ClusterOriginal.cxx
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
16
17#include "ClusterOriginal.h"
18
19#include <cassert>
20#include <numeric>
21#include <set>
22#include <stdexcept>
23
24#include "PadOriginal.h"
25
26namespace o2
27{
28namespace mch
29{
30
31//_________________________________________________________________________________________________
32bool shouldUsePad(const PadOriginal& pad, int plane, int statusMask, bool matchMask)
33{
36
37 if (pad.plane() == plane && pad.isReal() && !pad.isSaturated()) {
38 bool test = (statusMask != 0) ? ((pad.status() & statusMask) != 0) : (pad.status() == PadOriginal::kZero);
39 if ((test && matchMask) || (!test && !matchMask)) {
40 return true;
41 }
42 }
43
44 return false;
45}
46
47//_________________________________________________________________________________________________
49{
51
52 mPads.clear();
53
54 mMultiplicity[0] = 0;
55 mMultiplicity[1] = 0;
56
57 mCharge[0] = 0.;
58 mCharge[1] = 0.;
59
60 mIsSaturated[0] = false;
61 mIsSaturated[1] = false;
62}
63
64//_________________________________________________________________________________________________
65void ClusterOriginal::addPad(double x, double y, double dx, double dy, double charge, bool isSaturated, int plane, int digitIdx, int status)
66{
68
69 assert(plane == 0 || plane == 1);
70
71 mPads.emplace_back(x, y, dx, dy, charge, isSaturated, plane, digitIdx, status);
72
73 ++mMultiplicity[plane];
74 mCharge[plane] += charge;
75 if (isSaturated) {
76 mIsSaturated[plane] = true;
77 }
78}
79
80//_________________________________________________________________________________________________
82{
84
85 assert(iPad < mPads.size());
86
87 mPads.erase(mPads.begin() + iPad);
88
89 mMultiplicity[0] = 0;
90 mMultiplicity[1] = 0;
91 mCharge[0] = 0.;
92 mCharge[1] = 0.;
93 mIsSaturated[0] = false;
94 mIsSaturated[1] = false;
95 for (const auto& pad : mPads) {
96 ++mMultiplicity[pad.plane()];
97 mCharge[pad.plane()] += pad.charge();
98 if (pad.isSaturated()) {
99 mIsSaturated[pad.plane()] = true;
100 }
101 }
102}
103
104//_________________________________________________________________________________________________
106{
109 std::sort(mPads.begin(), mPads.end(), [precision](const PadOriginal& pad1, const PadOriginal& pad2) {
110 return (pad1.plane() < pad2.plane() ||
111 (pad1.plane() == pad2.plane() && (pad1.y() < pad2.y() - precision ||
112 (pad1.y() < pad2.y() + precision && pad1.x() < pad2.x() - precision))));
113 });
114}
115
116//_________________________________________________________________________________________________
117size_t ClusterOriginal::multiplicity(int plane) const
118{
120 assert(plane == 0 || plane == 1);
121 return mMultiplicity[plane];
122}
123
124//_________________________________________________________________________________________________
125std::pair<double, double> ClusterOriginal::minPadDimensions(int statusMask, bool matchMask) const
126{
129
130 auto dim0(minPadDimensions(0, statusMask, matchMask));
131 auto dim1(minPadDimensions(1, statusMask, matchMask));
132
133 return std::make_pair(TMath::Min(dim0.first, dim1.first), TMath::Min(dim0.second, dim1.second));
134}
135
136//_________________________________________________________________________________________________
137std::pair<double, double> ClusterOriginal::minPadDimensions(int plane, int statusMask, bool matchMask) const
138{
141
142 assert(plane == 0 || plane == 1);
143
144 double xmin(std::numeric_limits<float>::max());
145 double ymin(std::numeric_limits<float>::max());
146
147 if (mMultiplicity[plane] == 0) {
148 return std::make_pair(xmin, ymin);
149 }
150
151 for (const auto& pad : mPads) {
152 if (shouldUsePad(pad, plane, statusMask, matchMask)) {
153 xmin = TMath::Min(xmin, pad.dx());
154 ymin = TMath::Min(ymin, pad.dy());
155 }
156 }
157
158 return std::make_pair(xmin, ymin);
159}
160
161//_________________________________________________________________________________________________
162void ClusterOriginal::area(int plane, double area[2][2]) const
163{
166
167 assert(plane == 0 || plane == 1);
168
169 area[0][0] = std::numeric_limits<float>::max();
170 area[0][1] = -std::numeric_limits<float>::max();
171 area[1][0] = std::numeric_limits<float>::max();
172 area[1][1] = -std::numeric_limits<float>::max();
173
174 for (const auto& pad : mPads) {
175 if (pad.plane() == plane) {
176 area[0][0] = TMath::Min(area[0][0], pad.x() - pad.dx());
177 area[0][1] = TMath::Max(area[0][1], pad.x() + pad.dx());
178 area[1][0] = TMath::Min(area[1][0], pad.y() - pad.dy());
179 area[1][1] = TMath::Max(area[1][1], pad.y() + pad.dy());
180 }
181 }
182}
183
184//_________________________________________________________________________________________________
185std::pair<int, int> ClusterOriginal::sizeInPads(int statusMask) const
186{
189
190 std::pair<double, double> dim0 = minPadDimensions(0, statusMask, true);
191 std::pair<double, double> dim1 = minPadDimensions(1, statusMask, true);
192
193 std::pair<int, int> npad0 = sizeInPads(0, statusMask);
194 std::pair<int, int> npad1 = sizeInPads(1, statusMask);
195
196 int nx(0);
197 if (TMath::Abs(dim0.first - dim1.first) < 1.e-3) {
198 nx = TMath::Max(npad0.first, npad1.first);
199 } else {
200 nx = dim0.first < dim1.first ? npad0.first : npad1.first;
201 }
202
203 int ny(0);
204 if (TMath::Abs(dim0.second - dim1.second) < 1.e-3) {
205 ny = TMath::Max(npad0.second, npad1.second);
206 } else {
207 ny = dim0.second < dim1.second ? npad0.second : npad1.second;
208 }
209
210 return std::make_pair(nx, ny);
211}
212
213//_________________________________________________________________________________________________
214std::pair<int, int> ClusterOriginal::sizeInPads(int plane, int statusMask) const
215{
217
218 assert(plane == 0 || plane == 1);
219
220 if (mMultiplicity[plane] == 0) {
221 return std::make_pair(0, 0);
222 }
223
224 // order pads in x and y directions considering positions closer than 0.01 cm as equal
225 auto cmp = [](double a, double b) { return a < b - 0.01; };
226 std::set<double, decltype(cmp)> padx(cmp);
227 std::set<double, decltype(cmp)> pady(cmp);
228
229 for (const auto& pad : mPads) {
230 if (shouldUsePad(pad, plane, statusMask, true)) {
231 padx.emplace(pad.x());
232 pady.emplace(pad.y());
233 }
234 }
235
236 return std::make_pair(padx.size(), pady.size());
237}
238
239} // namespace mch
240} // namespace o2
Definition of the cluster used by the original cluster finder algorithm.
uint32_t pad2
uint32_t pad1
int16_t charge
Definition RawEventData.h:5
Definition of the pad used by the original cluster finder algorithm.
size_t multiplicity() const
return the total number of pads associated to this cluster
bool isSaturated() const
return whether there are saturated pads on both plane or not
void addPad(double x, double y, double dx, double dy, double charge, bool isSaturated, int plane, int digitIdx, int status)
float charge() const
return the total charge of this cluster
PadOriginal & pad(size_t i)
return the ith pad (no bound checking)
void sortPads(double precision)
std::pair< int, int > sizeInPads(int statusMask) const
std::pair< double, double > minPadDimensions(int statusMask, bool matchMask) const
void removePad(size_t iPad)
void area(int plane, double area[2][2]) const
pad for internal use
Definition PadOriginal.h:33
double x() const
return position in x (cm)
Definition PadOriginal.h:59
double dy() const
return half dimension in y (cm)
Definition PadOriginal.h:72
@ kZero
pad "basic" state
Definition PadOriginal.h:36
bool isSaturated() const
return whether this pad is saturated or not
Definition PadOriginal.h:95
bool isReal() const
return whether this is a real pad or a virtual pad
Definition PadOriginal.h:87
int status() const
return the status word
Definition PadOriginal.h:92
int plane() const
return 0 if bending pad, 1 if non-bending pad or -1 if none (e.g. pixel)
Definition PadOriginal.h:82
double dx() const
return half dimension in x (cm)
Definition PadOriginal.h:70
double charge() const
return the charge
Definition PadOriginal.h:79
double y() const
return position in y (cm)
Definition PadOriginal.h:61
GLint GLenum GLint x
Definition glcorearb.h:403
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLenum GLint GLint * precision
Definition glcorearb.h:1899
bool shouldUsePad(const PadOriginal &pad, int plane, int statusMask, bool matchMask)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
FIXME: do not use data model tables.
char const *restrict const cmp
Definition x9.h:96