Project
Loading...
Searching...
No Matches
ClusterPattern.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
17#include "Framework/Logger.h"
18#include <iostream>
19
21
22namespace o2
23{
24namespace itsmft
25{
27
28ClusterPattern::ClusterPattern(int nRow, int nCol, const unsigned char patt[MaxPatternBytes])
29{
30 setPattern(nRow, nCol, patt);
31}
32
33unsigned char ClusterPattern::getByte(int n) const
34{
35 if (n < 0 || n > MaxPatternBytes + 1) {
36 LOG(error) << "Invalid element of the pattern";
37 return -1;
38 } else {
39 return mBitmap[n];
40 }
41}
42
44{
45 int nBits = (int)mBitmap[0] * (int)mBitmap[1];
46 int nBytes = nBits / 8;
47 if (nBits % 8 != 0) {
48 nBytes++;
49 }
50 return nBytes;
51}
52
53void ClusterPattern::setPattern(int nRow, int nCol, const unsigned char patt[MaxPatternBytes])
54{
55 mBitmap[0] = (unsigned char)nRow;
56 mBitmap[1] = (unsigned char)nCol;
57 int nBytes = nRow * nCol / 8;
58 if (((nRow * nCol) % 8) != 0) {
59 nBytes++;
60 }
61 memcpy(&mBitmap[2], patt, nBytes);
62}
63
65{
66 memcpy(&mBitmap[0], patt, ClusterPattern::kExtendedPatternBytes);
67}
68
69std::ostream& operator<<(std::ostream& os, const ClusterPattern& pattern)
70{
71 os << "rowSpan: " << pattern.getRowSpan() << " columnSpan: " << pattern.getColumnSpan()
72 << " #bytes: " << pattern.getUsedBytes() << std::endl;
73 unsigned char tempChar = 0;
74 int s = 0;
75 int ic = 0;
76 for (int i = 2; i < pattern.getUsedBytes() + 2; i++) {
77 tempChar = pattern.mBitmap[i];
78 s = 128; // 0b10000000
79 while (s > 0) {
80 if (ic % pattern.getColumnSpan() == 0) {
81 os << "|";
82 }
83 ic++;
84 if ((tempChar & s) != 0) {
85 os << '+';
86 } else {
87 os << ' ';
88 }
89 s /= 2;
90 if (ic % pattern.getColumnSpan() == 0) {
91 os << "|" << std::endl;
92 }
93 if (ic == (pattern.getRowSpan() * pattern.getColumnSpan())) {
94 break;
95 }
96 }
97 if (ic == (pattern.getRowSpan() * pattern.getColumnSpan())) {
98 break;
99 }
100 }
101 os << std::endl;
102 return os;
103}
104
106{
107 std::cout << *this << "\n";
108}
109
111{
112 int n = 0, nBytes = getUsedBytes();
113 const auto* patt = mBitmap.data() + 2;
114 for (int i = 0; i < nBytes; i++) {
115 auto p = patt[i];
116 if (p) {
117 p = ((p & 0xAA) >> 1) + (p & 0x55);
118 p = ((p & 0xCC) >> 2) + (p & 0x33);
119 p = ((p & 0xF0) >> 4) + (p & 0x0f);
120 n += p;
121 }
122 }
123 return n;
124}
125
126int ClusterPattern::getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float& xCOG, float& zCOG)
127{
128 int tempxCOG = 0, tempzCOG = 0, tempFiredPixels = 0, ic = 0, ir = 0;
129 int nBits = rowSpan * colSpan;
130 int nBytes = nBits / 8;
131 if (nBits % 8 != 0) {
132 nBytes++;
133 }
134 for (int i = 0; i < nBytes; i++) {
135 unsigned char tempChar = patt[i];
136 int s = 128; // 0b10000000
137 while (s > 0) {
138 if ((tempChar & s) != 0) {
139 tempFiredPixels++;
140 tempxCOG += ir;
141 tempzCOG += ic;
142 }
143 ic++;
144 s /= 2;
145 if ((ir + 1) * ic == nBits) {
146 break;
147 }
148 if (ic == colSpan) {
149 ic = 0;
150 ir++;
151 }
152 }
153 if ((ir + 1) * ic == nBits) {
154 break;
155 }
156 }
157 xCOG = float(tempxCOG) / tempFiredPixels;
158 zCOG = float(tempzCOG) / tempFiredPixels;
159
160 return tempFiredPixels;
161}
162
163} // namespace itsmft
164} // namespace o2
ClassImp(o2::itsmft::ClusterPattern)
Definition of the ClusterTopology class.
int32_t i
static constexpr int MaxPatternBytes
static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float &xCOG, float &zCOG)
Static: Compute pattern's COG position. Returns the number of fired pixels.
void setPattern(int nRow, int nCol, const unsigned char patt[MaxPatternBytes])
Sets the pattern.
ClusterPattern()
Default constructor.
static constexpr int kExtendedPatternBytes
Maximum number of bytes for the cluster puttern + 2 bytes respectively for the number of rows and col...
unsigned char getByte(int n) const
Returns a specific byte of the pattern.
int getNPixels() const
Returns the number of fired pixels.
int getUsedBytes() const
Returns the number of bytes used for the pattern.
GLdouble n
Definition glcorearb.h:1982
std::ostream & operator<<(std::ostream &os, const ClusterPattern &pattern)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)
std::array< uint16_t, 5 > pattern