ATLAS Offline Software
Loading...
Searching...
No Matches
CrateEnergy.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4/***************************************************************************
5 CrateEnergy.h - description
6 -------------------
7 begin : 06/09/2007
8 email : Alan.Watson@cern.ch
9 ***************************************************************************/
10
11
13#include <iostream>
14#include <stdexcept>
15
16namespace LVL1 {
17
18CrateEnergy::CrateEnergy(unsigned int crate, const DataVector<ModuleEnergy>* JEMs, uint32_t maskXE, uint32_t maskTE, bool restricted):
20 m_crateEt(0),
21 m_crateEx(0),
22 m_crateEy(0),
23 m_overflowT(0),
24 m_overflowX(0),
25 m_overflowY(0),
27 m_debug(false)
28 {
30 if (m_crate > 1) return;
31
33 if ((maskXE&0xff) != 0xff || (maskTE&0xff) != 0xff) m_restricted = true;
34
40
42 unsigned int eT[2] = {0,0};
43 unsigned int eX[2] = {0,0};
44 unsigned int eY[2] = {0,0};
45 for ( const ModuleEnergy* jem : *JEMs ) {
46 int moduleInQuad = jem->module() % 8;
47 if (jem->crate() == m_crate) {
48 int quad = ( jem->module() < 8 ? 0 : 1 );
49 if ((maskTE>>moduleInQuad)&1) {
50 eT[quad] += jem->et();
51 if ( jem->et() >= m_jemEtSaturation ) m_overflowT = 1;
52 }
53 if ((maskXE>>moduleInQuad)&1) {
54 eX[quad] += jem->ex();
55 eY[quad] += jem->ey();
56 if ( jem->ex() >= m_jemEtSaturation ) m_overflowX = 1;
57 if ( jem->ey() >= m_jemEtSaturation ) m_overflowY = 1;
58 }
59 } // Right crate?
60 } // Loop over JEMs
61
63 const unsigned int mask = (1U << m_sumBits) - 1U;
64 const int overflowValue = -static_cast<int>(mask + 1U);
67 m_crateEt = eT[0] + eT[1];
68 if (m_crateEt >= mask){
69 m_overflowT = 1;
70 m_crateEt = mask;
71 }
72
73
74 if (!m_overflowX) {
75 m_crateEx = static_cast<int>(eX[0]) - static_cast<int>(eX[1]);
76 } else {
77 m_crateEx = overflowValue;
78 }
79
80 if (!m_overflowY) {
81 m_crateEy = static_cast<int>(eY[0]) - static_cast<int>(eY[1]);
82 } else {
83 m_crateEy = overflowValue;
84 }
85
86
87 if (m_debug) {
88 std::cout << "CrateEnergy: crate " << m_crate << " results "
89 << "\n Et " << m_crateEt << " overflow " << m_overflowT
90 << "\n Ex " << m_crateEx << " overflow " << m_overflowX
91 << "\n Ey " << m_crateEy << " overflow " << m_overflowY << std::endl;
92
93 }
94
95}
96
97CrateEnergy::CrateEnergy(unsigned int crate, const DataVector<EnergyCMXData>* JEMs, uint32_t maskXE, uint32_t maskTE, bool restricted):
99 m_crateEt(0),
100 m_crateEx(0),
101 m_crateEy(0),
102 m_overflowT(0),
103 m_overflowX(0),
104 m_overflowY(0),
106 m_debug(false)
107 {
109 if (m_crate > 1) return;
110
112 if ((maskXE&0xff) != 0xff || (maskTE&0xff) != 0xff) m_restricted = true;
113
119
121 unsigned int eT[2] = {0,0};
122 unsigned int eX[2] = {0,0};
123 unsigned int eY[2] = {0,0};
124 for ( const EnergyCMXData* jem : *JEMs ) {
125 int moduleInQuad = jem->module() % 8;
126 if ((unsigned int)jem->crate() == m_crate) {
127 int quad = ( jem->module() < 8 ? 0 : 1 );
128
129 if ((maskTE>>moduleInQuad)&1) {
130 eT[quad] += jem->Et();
131 if ( jem->Et() >= m_jemEtSaturation ) m_overflowT = 1;
132 }
133 if ((maskXE>>moduleInQuad)&1) {
134 eX[quad] += jem->Ex();
135 eY[quad] += jem->Ey();
136 if ( jem->Ex() >= m_jemEtSaturation ) m_overflowX = 1;
137 if ( jem->Ey() >= m_jemEtSaturation ) m_overflowY = 1;
138 }
139 }
140 }
141
143 unsigned int mask = (1<<m_sumBits) - 1;
144
145
148 m_crateEt = eT[0] + eT[1];
149 if (m_crateEt >= mask){
150 m_overflowT = 1;
151 m_crateEt = mask;
152 }
153
154 if (!m_overflowX){
155 m_crateEx = eX[0] - eX[1];
156 } else{
157 if (std::in_range<int>(-(static_cast<int>(mask) + 1))) m_crateEx = -(static_cast<int>(mask) + 1);
158 else throw std::out_of_range("m_crateEx set value is out of integer range");
159 }
160 if (!m_overflowY){
161 m_crateEy = eY[0] - eY[1];
162 }else{
163 if (std::in_range<int>(-(static_cast<int>(mask) + 1))) m_crateEy = -(static_cast<int>(mask) + 1);
164 else throw std::out_of_range("m_crateEy set value is out of integer range");
165 }
166
167 if (m_debug) {
168 std::cout << "CrateEnergy: crate " << m_crate << " results "
169 << "\n Et " << m_crateEt << " overflow " << m_overflowT
170 << "\n Ex " << m_crateEx << " overflow " << m_overflowX
171 << "\n Ey " << m_crateEy << " overflow " << m_overflowY << std::endl;
172
173 }
174
175}
176
177CrateEnergy::CrateEnergy(unsigned int crate, unsigned int et, unsigned int exTC,
178 unsigned int eyTC, unsigned int overflowT, unsigned int overflowX,
179 unsigned int overflowY, bool restricted) :
180 m_crate(crate),
181 m_crateEt(0),
182 m_crateEx(0),
183 m_crateEy(0),
184 m_overflowT(0),
185 m_overflowX(0),
186 m_overflowY(0),
188 m_debug(false)
189{
191 if (m_crate > 1) return;
192 m_crateEt = et;
195 m_overflowT = overflowT;
196 m_overflowX = overflowX;
197 m_overflowY = overflowY;
198
199 if (m_debug) {
200 std::cout << "CrateEnergy: crate " << m_crate << " results "
201 << "\n Et " << m_crateEt << " overflow " << m_overflowT
202 << "\n Ex " << m_crateEx << " overflow " << m_overflowX
203 << "\n Ey " << m_crateEy << " overflow " << m_overflowY << std::endl;
204
205 }
206}
207
208
211
213unsigned int CrateEnergy::crate() const {
214 return m_crate;
215}
216
218int CrateEnergy::et() const {
219 return m_crateEt;
220}
221
223int CrateEnergy::ex() const {
224 return m_crateEx;
225}
226
228int CrateEnergy::ey() const {
229 return m_crateEy;
230}
231
233unsigned int CrateEnergy::etOverflow() const {
234 return m_overflowT;
235}
236
238unsigned int CrateEnergy::exOverflow() const {
239 return m_overflowX;
240}
241
243unsigned int CrateEnergy::eyOverflow() const {
244 return m_overflowY;
245}
246
249 return m_restricted;
250}
251
253unsigned int CrateEnergy::exTC() const {
254 return encodeTC(m_crateEx);
255}
256
258unsigned int CrateEnergy::eyTC() const {
259 return encodeTC(m_crateEy);
260}
261
263unsigned int CrateEnergy::encodeTC(int input) const {
264 unsigned int value;
265
266 if (input > 0) {
267 value = input;
268 }
269 else {
270 value = (1<<m_sumBitsTC) + input;
271 }
272
273 int mask = (1<<m_sumBitsTC) - 1;
274 return value&mask ;
275}
276
278int CrateEnergy::decodeTC(unsigned int input) const {
279
280 int mask = (1<<m_sumBitsTC) - 1;
281 int value = input&mask;
282
283 if ((value >> (m_sumBitsTC - 1))) {
284 value += (~0U) << m_sumBitsTC;
285 }
286
287 return value;
288}
289} // end of ns
Derived DataVector<T>.
Definition DataVector.h:795
unsigned int crate() const
return crate number
int ex() const
return crate Ex
unsigned int m_overflowT
Definition CrateEnergy.h:60
int ey() const
return crate Ey
int et() const
return et, ex, ey sums
static const unsigned int m_sumBits
Definition CrateEnergy.h:66
unsigned int exOverflow() const
Overflow bits.
unsigned int m_overflowY
Definition CrateEnergy.h:62
bool restricted() const
Full or restricted eta range?
unsigned int eyOverflow() const
return Ey overflow bit
unsigned int m_crate
Definition CrateEnergy.h:56
unsigned int etOverflow() const
return Et overflow bit
CrateEnergy(unsigned int crate, const DataVector< ModuleEnergy > *modules, uint32_t maskXE=0xff, uint32_t maskTE=0xff, bool restricted=false)
unsigned int encodeTC(int input) const
encode int as 15-bit twos-complement format (hardware Ex/Ey format)
int decodeTC(unsigned int input) const
decode 15-bit twos-complement format (hardware Ex/Ey format) as int
static const unsigned int m_sumBitsTC
Definition CrateEnergy.h:65
unsigned int exTC() const
15 bit twos-complement format
unsigned int m_crateEt
Definition CrateEnergy.h:57
unsigned int eyTC() const
return crate Ey in 15-bit twos-complement format (hardware format)
unsigned int m_overflowX
Definition CrateEnergy.h:61
static const unsigned int m_jemEtSaturation
Definition CrateEnergy.h:67
The EnergyCMXData object contains the data transferred from the JEM to the EnergySum CMX in the crate...
This is an internal class, used in the Energy trigger.
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...