ATLAS Offline Software
Loading...
Searching...
No Matches
gFEXCompression.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4//***************************************************************************
5// gFEXCompression - Energy encoder/decoder for gFEX
6// -------------------
7// begin : 01 04 2021
8// email : cecilia.tosciri@cern.ch
9//***************************************************************************
11#include <cmath>
12
13namespace LVL1 {
14
15const int gFEXCompression::s_steps[] = {12800, 50, 25, 50, 100, 25600};//MeV
16const int gFEXCompression::s_minET[] = {-101200, -50000, -12800, 12800, 51200, 200000};//MeV
17const int gFEXCompression::s_minCode[] = {2, 6, 750, 1774, 2542, 4030};
18
19
20unsigned int gFEXCompression::compress(float floatEt) {
21
22 int Et = std::round(floatEt);
23
24 // Check for overflow
25 if (Et >= s_maxET) return s_LArOverflow;
26
27 // Find which range the ET value is in
28 int range = -1;
29 for (unsigned int i = 0; i < s_nRanges; i++) {
30 if (Et < s_minET[i]) break;
31 range = i;
32 }
33
34 // Calculate code
35 unsigned int code = 0;
36
37 if (range < 0) {
38 // Below minimum value
39 code = s_LArUnderflow;
40 }
41 else {
42 // Lies inside one of the value ranges
43 int steps = (Et - s_minET[range])/s_steps[range];
44 code = s_minCode[range] + steps;
45 }
46
47 return code;
48}
49
50int gFEXCompression::expand(unsigned int code) {
51
52 // Deal with special codes first:
53 if (code == s_NoData) return 0;
54 if (code == s_LArInvalid || (code > s_LArReserved_min && code < s_LArReserved_max) || code > s_LArMaxCode) return s_error;
55 if (code == s_LArOverflow ) return s_maxET;
56
59 int range = 0;
60 for (unsigned int i = 0; i < s_nRanges-1; ++i) {
61 if (code < (unsigned int)s_minCode[i+1]) break;
62 range++;
63 }
65 int Et = s_minET[range] + (code-s_minCode[range])*s_steps[range];
66
67 return Et;
68}
69
70
71unsigned int gFEXCompression::threshold(unsigned int code, int threshold) {
72
74 unsigned int cut = gFEXCompression::compress(threshold);
75
77 if (code < cut) code = 0;
78
79 return code;
80}
81
82
83unsigned int gFEXCompression::linearize(unsigned int code, int threshold) {
84
86 if (threshold < 0) threshold = 0;
88
90 int Et = gFEXCompression::expand(code);
91
92 // Check for overflow
93 if (Et >= s_maxET) return s_gFEXOverflow;
94
96 unsigned int gFexET = Et/s_gFEXstep;
97 return gFexET;
98}
99
100} // end of namespace bracket
static const unsigned int s_LArOverflow
LAr overflow code.
static const int s_minET[s_nRanges]
Minimum ET values in each range, MeV.
static unsigned int linearize(unsigned int code, int threshold=0)
Linearize LAr code to eFEX internal format.
static const unsigned int s_LArReserved_max
Reserved code max value.
static const unsigned int s_LArUnderflow
LAr underflow code.
static int expand(unsigned int code)
Uncompress data.
static unsigned int threshold(unsigned int code, int threshold=-101200)
Apply threshold to compressed data.
static const int s_minCode[s_nRanges]
Minimum code value in each range.
static const int s_error
Error return value.
static const unsigned int s_LArMaxCode
LAr saturated code.
static const int s_maxET
Maximum ET value that can be encoded.
static const int s_steps[s_nRanges]
Step sizes in each range, MeV.
static const int s_NoData
Indicates no data present.
static const unsigned int s_gFEXOverflow
L1Calo saturated/overflow.
static unsigned int compress(float Energy)
Compress data.
static const unsigned int s_gFEXstep
L1Calo ET digit step.
static const unsigned int s_nRanges
Number of ranges.
static const unsigned int s_LArInvalid
Invalid code value.
static const unsigned int s_LArReserved_min
Reserved code min value.
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...