Project
Loading...
Searching...
No Matches
Cell.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
13#include <iostream>
14#include <bitset>
15
16using namespace o2::phos;
17
18// split 40 bits as following:
19// 14 bits: address, normal cells from 1 to NmaxCell=4*56*64-1792=14 336-1792=12544 will be
20// TRU cells (3 136) addresses from 12545 to 15680
21// 10 bits: time
22// 15 bits: Energy
23// 1 bit: High/low gain
24
25Cell::Cell(short absId, float energy, float time, ChannelType_t ctype)
26{
27 setAbsId(absId);
29 setType(ctype);
30 setEnergy(energy);
31}
32
33void Cell::setAbsId(short absId)
34{
35 // 14 bits available
36 if (absId < kOffset) {
37 absId = kOffset;
38 }
39 ULong_t t = (ULong_t)(absId - kOffset);
40
41 ULong_t b = getLong() & 0xffffffc000; // 1111 1111 1111 1111 1111 1111 1100 0000 0000 0000
42 mBits = b + t;
43}
44short Cell::getAbsId() const
45{
46 ULong_t t = getLong() & 0x3fff; // 14 bits
47 short a = kOffset + (short)t;
48 if (a <= kNmaxCell) { // readout cells
49 return a;
50 } else { // TRU cells
51 return 0;
52 }
53}
54
55short Cell::getTRUId() const
56{
57 ULong_t t = getLong() & 0x3fff; // 14 bits
58 short a = kOffset + (short)t;
59 return a;
60}
61
63{
64 // 13 bits available for time
65 // -Underflow
66 // -1500<t<-800 ns, 1. ns binning => 700 bin
67 // -800<t<-200 ns, 0.6 ns binning => 1000 bin
68 // -200<t< 200 ns, 0.2 ns binning => 2000 bin
69 // 200<t< 800 ns, 0.6 ns binning => 1000 bin
70 // 800<t<4290 ns, 1 ns binning => 3490 bin
71 // + overflow total 8192
72
73 ULong_t t = 0;
74 // Convert time to long
75 if (time < kTime0) {
76 t = 0; // underflow
77 } else {
78 if (time < kTime1) {
79 t = ULong_t(1.5 + (time - kTime0) / kTimeAccuracy1);
80 } else {
81 if (time < kTime2) {
82 t = kTimeOffset1 + ULong_t(0.5 + (time - kTime1) / kTimeAccuracy2);
83 } else {
84 if (time < kTime3) {
85 t = kTimeOffset2 + ULong_t(0.5 + (time - kTime2) / kTimeAccuracy3);
86 } else {
87 if (time < kTime4) {
88 t = kTimeOffset3 + ULong_t(0.5 + (time - kTime3) / kTimeAccuracy4);
89 } else {
90 t = kTimeOffset4 + ULong_t(0.5 + (time - kTime4) / kTimeAccuracy5);
91 if (t > 8191) {
92 t = 8191; // overflow
93 }
94 }
95 }
96 }
97 }
98 }
99 t <<= 14;
100 ULong_t b = getLong() & 0xfff8003fff; // 1111 1111 1111 1000 0000 0000 0011 1111 1111 1111
101 mBits = b + t;
102}
103float Cell::getTime() const
104{
105 ULong_t t = getLong();
106 t >>= 14;
107 t &= 0x1fff;
108 // Convert back long to float
109 if (t == 0) {
110 return kTime0 - 1.e-9; // First bin- underflow
111 }
112 if (t < kTimeOffset1) {
113 return float((t - 1) * kTimeAccuracy1) + kTime0; // First bin- underflow
114 } else {
115 if (t < kTimeOffset2) {
116 return float((t - kTimeOffset1) * kTimeAccuracy2) + kTime1;
117 } else {
118 if (t < kTimeOffset3) {
119 return float((t - kTimeOffset2) * kTimeAccuracy3) + kTime2;
120 } else {
121 if (t < kTimeOffset4) {
122 return float((t - kTimeOffset3) * kTimeAccuracy4) + kTime3;
123 } else {
124 return float((t - kTimeOffset4) * kTimeAccuracy5) + kTime4;
125 }
126 }
127 }
128 }
129}
130
131void Cell::setEnergy(float amp)
132{
133 // 12 bits
134 ULong_t a;
135 if (getType() == HIGH_GAIN) {
136 a = static_cast<ULong_t>(amp * 4);
137 } else {
138 a = static_cast<ULong_t>(amp);
139 }
140 a = a & 0xfff; // 12 bits
141
142 a <<= 27;
143 ULong_t b = getLong() & 0x8007ffffff; // 1000 0000 0000 0111 1111 1111 1111 1111 1111 1111
144 mBits = b + a;
145}
146
147float Cell::getEnergy() const
148{
149 ULong_t a = getLong();
150 a >>= 27;
151 a &= 0xfff;
152 if (getType() == HIGH_GAIN) {
153 return float(0.25 * a);
154 } else {
155 return float(a);
156 }
157}
158
160{
161 switch (ctype) {
164 setHighGain();
165 break;
168 setLowGain();
169 break;
170 default:;
171 };
172}
173
175{
176 if (getTRU()) {
177 if (getHighGain()) {
179 } else {
181 }
182 } else {
183 if (getHighGain()) {
185 } else {
187 }
188 }
189}
190
192{
193 std::bitset<40> b(0x7fffffffff); // 0111111111111111111111111111111111111111
194 mBits = (mBits & b);
195}
196
197Bool_t Cell::getLowGain() const
198{
199 ULong_t t = (getLong() >> 39);
200 if (t) {
201 return false;
202 }
203 return true;
204}
205
207{
208 ULong_t b = getLong() & 0x7fffffffff; // 0111111111111111111111111111111111111111
209 mBits = b + 0x8000000000; // 1000000000000000000000000000000000000000
210}
211
212Bool_t Cell::getHighGain() const
213{
214 ULong_t t = (getLong() >> 39);
215 if (t == 1) {
216 return true;
217 }
218 return false;
219}
220
221Bool_t Cell::getTRU() const
222{
223 ULong_t t = getLong();
224 t &= 0x3fff; // 14 bits
225 int a = kOffset + (int)t;
226 return (a > kNmaxCell); // TRU addresses
227}
228
229void Cell::setLong(ULong_t l)
230{
231 std::bitset<40> b(l);
232 mBits = b;
233}
234
235void Cell::PrintStream(std::ostream& stream) const
236{
237 stream << "PHOS Cell: Type " << getType() << ", Energy " << getEnergy() << ", Time " << getTime() << ", absId " << getAbsId() << ", Bits " << mBits;
238}
239
240std::ostream& operator<<(std::ostream& stream, const Cell& c)
241{
242 c.PrintStream(stream);
243 return stream;
244}
int16_t time
Definition RawEventData.h:4
uint32_t c
Definition RawData.h:2
short getTRUId() const
Definition Cell.cxx:55
void setType(ChannelType_t ctype)
Definition Cell.cxx:159
Cell()=default
void setAbsId(short absId)
Definition Cell.cxx:33
ULong_t getLong() const
Definition Cell.h:92
ChannelType_t getType() const
Definition Cell.cxx:174
void setHighGain()
Definition Cell.cxx:206
short getAbsId() const
Definition Cell.cxx:44
bool getHighGain() const
Definition Cell.cxx:212
bool getLowGain() const
Definition Cell.cxx:197
float getTime() const
Definition Cell.cxx:103
void setLowGain()
Definition Cell.cxx:191
bool getTRU() const
Definition Cell.cxx:221
float getEnergy() const
Definition Cell.cxx:147
void PrintStream(std::ostream &stream) const
Definition Cell.cxx:235
void setTime(float time)
Definition Cell.cxx:62
void setLong(ULong_t l)
Definition Cell.cxx:229
void setEnergy(float energy)
Definition Cell.cxx:131
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLuint GLuint stream
Definition glcorearb.h:1806
constexpr uint16_t kTimeOffset3
Definition Cell.h:48
constexpr uint16_t kTimeOffset2
Definition Cell.h:47
constexpr uint16_t kTimeOffset4
Definition Cell.h:49
constexpr float kTimeAccuracy4
Definition Cell.h:39
constexpr float kTimeAccuracy5
Definition Cell.h:40
std::ostream & operator<<(std::ostream &in, const BadChannelsMap &bcm)
Printing bad channel map on the stream.
constexpr float kTimeAccuracy3
Definition Cell.h:38
constexpr float kTime4
Definition Cell.h:45
ChannelType_t
Definition Cell.h:51
@ TRU4x4
TRU channel, 4x4 trigger.
Definition Cell.h:55
@ LOW_GAIN
Low gain channel.
Definition Cell.h:52
@ HIGH_GAIN
High gain channel.
Definition Cell.h:53
@ TRU2x2
TRU channel, 2x2 trigger.
Definition Cell.h:54
constexpr float kTime3
Definition Cell.h:44
constexpr int kNmaxCell
Definition Cell.h:30
constexpr float kTimeAccuracy1
Definition Cell.h:36
constexpr int kOffset
Definition Cell.h:29
constexpr float kTime2
Definition Cell.h:43
constexpr uint16_t kTimeOffset1
Definition Cell.h:46
constexpr float kTimeAccuracy2
Definition Cell.h:37
constexpr float kTime0
Definition Cell.h:41
constexpr float kTime1
Definition Cell.h:42