Skip to content

Commit b45c1e1

Browse files
mfasDashahor02
authored andcommitted
[EMCAL-551] Move cell format to bitfield
- Move underlying structure to bitfield and expand to 48 bit (min. size) - Increase number of time bits from 9 to 11, and use an internal time shift of 600 ns in order to cover the time range from -600 ns to 900 ns with 0.7 ns precision - Add truncations for time and energy - Make truncations and resolution constants, and calculate based on the range and the max. integer number representable with the amount of bits assigned. - Add doxygen documentation for cell class - Fixes in test: - Default cell type: High gain(0) instead of LowGain(1) - Test of times should reflect negative values as time can be shifted - In practice cells with E > 16 GeV are low gain cells, energy test should reflect this
1 parent 871151b commit b45c1e1

3 files changed

Lines changed: 195 additions & 220 deletions

File tree

DataFormats/Detectors/EMCAL/include/DataFormatsEMCAL/Cell.h

Lines changed: 141 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#define ALICEO2_EMCAL_CELL_H_
1313

1414
#include <bitset>
15-
#include "Rtypes.h"
1615
#include "DataFormatsEMCAL/Constants.h"
1716

1817
namespace o2
@@ -22,62 +21,162 @@ namespace emcal
2221

2322
/// \class Cell
2423
/// \brief EMCAL compressed cell information
24+
/// \author Anders Knospe, University of Houston
25+
/// \author Markus Fasel <markus.fasel@cern.ch>, Oak Ridge National Laboratory
26+
/// \since March 6, 2019
2527
/// \ingroup EMCALDataFormat
2628
///
27-
/// Structure:
28-
/// Bits 38-39: Cell type: 00=Low Gain, 01=High Gain, 10=LED mon, 11=TRU
29-
/// Bits 24-37: Energy (input/output in GeV/c^2, resolution 1/16 ADC count)
30-
/// Bits 15-23: Time (ns)
31-
/// Bits 0-14: Tower ID
29+
/// # Base format for EMCAL cell information in the Compressed Timeframe
30+
///
31+
/// The cell class contains the relevant information for each tower per event
32+
/// - Tower ID
33+
/// - Energy of the raw fit
34+
/// - Time of the raw fit
35+
/// - Type of the cell
36+
/// While cell type and tower ID have a predefined range based on the hardware
37+
/// design, energy and time have a finite resolution influenced by the resolution
38+
/// of the digitizer. This is used in order to compress the information stored
39+
/// in the compressed timeframe by not storing the full double values but instead
40+
/// assigning a certain amount of bits to each information. Therefore for certain
41+
/// information (energy, time) precision loss has to be taken into account.
42+
///
43+
/// # Internal structure and resolution
44+
///
45+
/// The internal structure is a bit field compressing the information to
46+
/// 48 bits. The definition of the bit field as well as the value range and the resolution
47+
/// is listed in the table below:
48+
///
49+
/// | Bits | Content | Resolution | Range |
50+
/// |-------|---------------|---------------|-----------------------------|
51+
/// | 0-14 | Tower ID | - | 0 to 17644 |
52+
/// | 15-26 | Time (ns) | 0.73 ns | -600 to 900 ns |
53+
/// | 27-40 | Energy (GeV) | 0.0153 GeV | 0 to 250 GeV |
54+
/// | 41-42 | Cell type | - | 0=LG, 1=HG, 2=LEMon, 4=TRU |
55+
///
56+
/// The remaining bits are 0
3257
class Cell
3358
{
3459
public:
35-
Cell() = default;
36-
Cell(Short_t tower, Double_t energy, Double_t time, ChannelType_t ctype = ChannelType_t::LOW_GAIN);
60+
Cell();
61+
Cell(short tower, float energy, float time, ChannelType_t ctype = ChannelType_t::LOW_GAIN);
3762
~Cell() = default; // override
3863

39-
void setTower(Short_t tower);
40-
Short_t getTower() const;
41-
42-
void setTimeStamp(Double_t time);
43-
Short_t getTimeStamp() const;
44-
45-
void setEnergyBits(Short_t ebits);
46-
Short_t getEnergyBits() const;
47-
48-
void setEnergy(Double_t energy);
49-
Double_t getEnergy() const;
50-
51-
void setAmplitude(Double_t energy) { setEnergy(energy); }
52-
Double_t getAmplitude() const { return getEnergy(); }
53-
54-
void setType(ChannelType_t ctype);
55-
ChannelType_t getType() const;
56-
57-
void setLowGain();
58-
Bool_t getLowGain() const;
59-
60-
void setHighGain();
61-
Bool_t getHighGain() const;
62-
63-
void setLEDMon();
64-
Bool_t getLEDMon() const;
65-
66-
void setTRU();
67-
Bool_t getTRU() const;
68-
69-
void setLong(ULong_t l);
70-
ULong_t getLong() const { return mBits.to_ulong(); }
64+
void setTower(short tower) { getDataRepresentation()->mTowerID = tower; }
65+
short getTower() const { return getDataRepresentation()->mTowerID; }
66+
67+
/// \brief Set the time stamp
68+
/// \param time Time in ns
69+
///
70+
/// The time stamp is expressed in ns and has
71+
/// a resolution of 1 ns. The time range which can
72+
/// be stored is from -1023 to 1023 ns. In case the
73+
/// range is exceeded the time is set to the limit
74+
/// of the range.
75+
void setTimeStamp(float time);
76+
77+
/// \brief Get the time stamp
78+
/// \return Time in ns
79+
///
80+
/// Time has a resolution of 1 ns and can cover
81+
/// a range from -1023 to 1023 ns
82+
float getTimeStamp() const;
83+
84+
/// \brief Set the energy of the cell
85+
/// \brief Energy of the cell in GeV
86+
///
87+
/// The energy range covered by the cell
88+
/// is 0 - 250 GeV, with a resolution of
89+
/// 0.0153 GeV. In case an energy exceeding
90+
/// the limits is provided the energy is
91+
/// set to the limits (0 in case of negative
92+
/// energy, 250. in case of energies > 250 GeV)
93+
void setEnergy(float energy);
94+
95+
/// \brief Get the energy of the cell
96+
/// \return Energy of the cell
97+
///
98+
/// The energy is truncated to a range
99+
/// covering 0 to 250 GeV with a resolution
100+
/// of 0.0153 GeV
101+
float getEnergy() const;
102+
103+
/// \brief Set the amplitude of the cell
104+
/// \param amplitude Cell amplitude
105+
///
106+
/// See setEnergy for more information
107+
void setAmplitude(float amplitude) { setEnergy(amplitude); }
108+
109+
/// \brief Get cell amplitude
110+
/// \return cell Amplitude
111+
///
112+
/// Set getEnergy for more information
113+
float getAmplitude() const { return getEnergy(); }
114+
115+
/// \brief Set the type of the cell
116+
/// \param ctype Type of the cell (HIGH_GAIN, LOW_GAIN, LEDMON, TRU)
117+
void setType(ChannelType_t ctype) { getDataRepresentation()->mCellStatus = static_cast<uint16_t>(ctype); }
118+
119+
/// \brief Get the type of the cell
120+
/// \return Type of the cell (HIGH_GAIN, LOW_GAIN, LEDMON, TRU)
121+
ChannelType_t getType() const { return static_cast<ChannelType_t>(getDataRepresentation()->mCellStatus); }
122+
123+
/// \brief Check whether the cell is of a given type
124+
/// \param ctype Type of the cell (HIGH_GAIN, LOW_GAIN, LEDMON, TRU)
125+
/// \return True if the type of the cell matches the requested type, false otherwise
126+
bool isChannelType(ChannelType_t ctype) const { return getType() == ctype; }
127+
128+
/// \brief Mark cell as low gain cell
129+
void setLowGain() { setType(ChannelType_t::LOW_GAIN); }
130+
131+
/// \brief Check whether the cell is a low gain cell
132+
/// \return True if the cell type is low gain, false otherwise
133+
Bool_t getLowGain() const { return isChannelType(ChannelType_t::LOW_GAIN); }
134+
135+
/// \brief Mark cell as high gain cell
136+
void setHighGain() { setType(ChannelType_t::HIGH_GAIN); }
137+
138+
/// \brief Check whether the cell is a high gain cell
139+
/// \return True if the cell type is high gain, false otherwise
140+
Bool_t getHighGain() const { return isChannelType(ChannelType_t::HIGH_GAIN); };
141+
142+
/// \brief Mark cell as LED monitor cell
143+
void setLEDMon() { setType(ChannelType_t::LEDMON); }
144+
145+
/// \brief Check whether the cell is a LED monitor cell
146+
/// \return True if the cell type is LED monitor, false otherwise
147+
Bool_t getLEDMon() const { return isChannelType(ChannelType_t::LEDMON); }
148+
149+
/// \brief Mark cell as TRU cell
150+
void setTRU() { setType(ChannelType_t::TRU); }
151+
152+
/// \brief Check whether the cell is a TRU cell
153+
/// \return True if the cell type is TRU, false otherwise
154+
Bool_t getTRU() const { return isChannelType(ChannelType_t::TRU); }
71155

72156
void PrintStream(std::ostream& stream) const;
73157

74158
private:
75-
std::bitset<40> mBits;
159+
struct __attribute__((packed)) CellData {
160+
uint16_t mTowerID : 15; ///< bits 0-14 Tower ID
161+
uint16_t mTime : 11; ///< bits 15-25: Time (signed, can become negative after calibration)
162+
uint16_t mEnergy : 14; ///< bits 26-39: Energy
163+
uint16_t mCellStatus : 2; ///< bits 40-41: Cell status
164+
uint16_t mZerod : 6; ///< bits 42-47: Zerod
165+
};
166+
167+
CellData* getDataRepresentation() { return reinterpret_cast<CellData*>(mCellWords); }
168+
const CellData* getDataRepresentation() const { return reinterpret_cast<const CellData*>(mCellWords); }
169+
170+
uint16_t mCellWords[3]; ///< data word
76171

77172
ClassDefNV(Cell, 1);
78173
};
79174

80-
std::ostream& operator<<(std::ostream& stream, const Cell& c);
175+
/// \brief Stream operator for EMCAL cell
176+
/// \param stream Stream where to print the EMCAL cell
177+
/// \param cell Cell to be printed
178+
/// \return Stream after printing
179+
std::ostream& operator<<(std::ostream& stream, const Cell& cell);
81180
} // namespace emcal
82181
} // namespace o2
83182

0 commit comments

Comments
 (0)