ATLAS Offline Software
Loading...
Searching...
No Matches
jFEXCompression.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 jFEXCompression.cxx - description
6 -------------------
7 begin : 07-02-2019
8 email : Alan.Watson@cern.ch antonio.jacques.costa@cern.ch
9 ***************************************************************************/
10
12#include <cmath>
13
14namespace LVL1 {
15
16const int jFEXCompression::s_steps[] = {25, 50, 100, 200, 400};
17const int jFEXCompression::s_minET[] = {-3150, 6400, 25600, 102400, 409600};
18const int jFEXCompression::s_minCode[] = {2, 384, 768, 1536, 3072};
19
20unsigned int jFEXCompression::Compress(float floatEt, bool empty) {
21
22 //If all Scells are masked, then send empty/data not available
23 if(empty) return s_NoData;
24
25 int Et = std::round(floatEt);
26
27 // Check for overflow
28 if (Et >= s_maxET) return s_LArOverflow;
29
30 // Find which range the ET value is in
31 int range = -1;
32 for (unsigned int i = 0; i < s_nRanges; i++) {
33 if (Et < s_minET[i]) break;
34 range = i;
35 }
36
37 // Calculate code
38 unsigned int code = 0;
39
40 if (range < 0) {
41 // Below minimum value
42 code = s_LArUnderflow;
43 }
44 else {
45 // Lies inside one of the value ranges
46 int steps = std::round( (Et - s_minET[range])/s_steps[range] );
47 code = static_cast<int>(s_minCode[range] + steps);
48 }
49
50 return code;
51}
52
53int jFEXCompression::Expand(unsigned int code) {
54
55 // Deal with special codes first:
56 if (code == s_NoData) return 0;
57 if (code == s_LArInvalid) return 0;
58 if (code > s_LArOverflow && code < s_LArInvalid) return s_error;
59 if (code == s_LArOverflow) return s_maxET;
60
63 int range = 0;
64 for (unsigned int i = 0; i < s_nRanges-1; ++i) {
65 if (code < (unsigned int)s_minCode[i+1]) break;
66 range++;
67 }
69 int minEt = s_minET[range];
70 int valEt = (code-s_minCode[range])*s_steps[range];
71
72 int Et = minEt+valEt;
73 return Et;
74}
75
76
77unsigned int jFEXCompression::Threshold(unsigned int code, int threshold) {
78
80 unsigned int cut = jFEXCompression::Compress(threshold);
81
83 if (code < cut) code = 0;
84
85 return code;
86}
87
88
89unsigned int jFEXCompression::Linearize(unsigned int code, int threshold) {
90
92 if (threshold < 0) threshold = 0;
94
96 int Et = jFEXCompression::Expand(code);
97
98 // Check for overflow
99 if (Et >= s_maxET) return s_jFEXOverflow;
100
102 unsigned int jFexET = Et/s_jFEXstep;
103 return jFexET;
104}
105
106} // end of namespace bracket
static const Attributes_t empty
static const int s_minET[s_nRanges]
Minimum ET values in each range, MeV.
static const int s_NoData
Indicates no data present.
static const int s_maxET
Maximum ET value that can be encoded.
static int Expand(unsigned int code)
Uncompress data.
static unsigned int Linearize(unsigned int code, int threshold=0)
Linearize LAr code to jFEX internal format.
static const int s_error
Error return value.
static const unsigned int s_nRanges
Number of ranges.
static unsigned int Threshold(unsigned int code, int threshold=-800)
Apply threshold to compressed data.
static const unsigned int s_LArInvalid
Invalid code value.
static const unsigned int s_LArUnderflow
LAr underflow code.
static const int s_minCode[s_nRanges]
Minimum code value in each range.
static const int s_steps[s_nRanges]
Step sizes in each range, MeV.
static const unsigned int s_jFEXstep
L1Calo ET digit step.
static const unsigned int s_jFEXOverflow
L1Calo saturated/overflow.
static const unsigned int s_LArOverflow
LAr overflow code.
static unsigned int Compress(float floatEt, bool empty=false)
Compress data.
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...