ATLAS Offline Software
Loading...
Searching...
No Matches
SystemEnergy.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4/***************************************************************************
5 SystemEnergy.h - description
6 -------------------
7 begin : 06/09/2007
8 email : Alan.Watson@cern.ch
9 ***************************************************************************/
10
11
15
16using namespace TrigConf;
17
18namespace LVL1
19{
20
22 m_systemEx(0),
23 m_systemEy(0),
24 m_systemEt(0),
25 m_overflowX(0),
26 m_overflowY(0),
27 m_overflowT(0),
28 m_restricted(0),
29 m_etMissHits(0),
30 m_etSumHits(0),
31 m_metSigHits(0),
32 m_debug(false)
33{
34
35 int xyMax = 1 << (m_sumBits - 1);
36
39
40 for (const CrateEnergy* cr : *crates)
41 {
42 if (cr->crate() == 0)
43 {
44 m_systemEx += cr->ex();
45 m_systemEy += cr->ey();
46 m_systemEt += cr->et();
47 }
48 else if (cr->crate() == 1)
49 {
50 m_systemEx -= cr->ex();
51 m_systemEy += cr->ey();
52 m_systemEt += cr->et();
53 }
54
55 m_overflowX = m_overflowX | (cr->ex() == -xyMax);
56 m_overflowY = m_overflowY | (cr->ey() == -xyMax);
57 m_overflowT = m_overflowT | (cr->et() == m_maxEtSumThr);
58
59 if (cr->restricted())
60 m_restricted = 1;
61 }
62
64 if (m_overflowT != 0) {
66 }
67
68
69
70 if ((abs(m_systemEx) >= xyMax) || m_overflowX)
71 {
72 m_overflowX = 1;
73 m_systemEx = -xyMax;
74 }
75
76 if ((abs(m_systemEy) >= xyMax) || m_overflowY)
77 {
78 m_overflowY = 1;
79 m_systemEy = -xyMax;
80 }
81
82 if (m_debug)
83 {
84 std::cout << "SystemEnergy results: " << std::endl
85 << " Et " << m_systemEt << " overflow " << m_overflowT << std::endl
86 << " Ex " << m_systemEx << " overflow " << m_overflowX << std::endl
87 << " Ey " << m_systemEy << " overflow " << m_overflowY << std::endl;
88 }
89
94}
95
96SystemEnergy::SystemEnergy(unsigned int et, unsigned int exTC, unsigned int eyTC,
97 unsigned int overflowT, unsigned int overflowX,
98 unsigned int overflowY, unsigned int restricted,
99 const TrigConf::L1Menu* l1Menu) : m_L1Menu(l1Menu),
100 m_systemEx(0),
101 m_systemEy(0),
102 m_systemEt(et),
103 m_overflowX(overflowX),
104 m_overflowY(overflowY),
105 m_overflowT(overflowT),
106 m_restricted(restricted),
107 m_etMissHits(0),
108 m_etSumHits(0),
109 m_metSigHits(0),
110 m_debug(false)
111{
112
115
116 int xyMax = 1 << (m_sumBits - 1);
117
119 m_overflowX = m_systemEx == -xyMax;
120 m_overflowY = m_systemEy == -xyMax;
121
122 if (m_debug)
123 {
124 std::cout << "SystemEnergy results: " << std::endl
125 << " Et " << m_systemEt << " overflow " << m_overflowT << std::endl
126 << " Ex " << m_systemEx << " overflow " << m_overflowX << std::endl
127 << " Ey " << m_systemEy << " overflow " << m_overflowY << std::endl;
128 }
129
132 etSumTrigger();
134}
135
136
139{
140 return m_systemEt;
141}
142
145{
146 return m_systemEx;
147}
148
151{
152 return m_systemEy;
153}
154
156unsigned int SystemEnergy::etOverflow() const
157{
158 return m_overflowT & 0x1;
159}
160
162unsigned int SystemEnergy::exOverflow() const
163{
164 return m_overflowX & 0x1;
165}
166
168unsigned int SystemEnergy::eyOverflow() const
169{
170 return m_overflowY & 0x1;
171}
172
174unsigned int SystemEnergy::exTC() const
175{
176 return encodeTC(m_systemEx);
177}
178
180unsigned int SystemEnergy::eyTC() const
181{
182 return encodeTC(m_systemEy);
183}
184
186unsigned int SystemEnergy::etMissHits() const
187{
188 return m_etMissHits;
189}
190
192unsigned int SystemEnergy::etSumHits() const
193{
194 return m_etSumHits;
195}
196
198unsigned int SystemEnergy::metSigHits() const
199{
200 return m_metSigHits;
201}
202
204unsigned int SystemEnergy::roiWord0() const
205{
206 // Start by setting up header
207 unsigned int word = TrigT1CaloDefs::energyRoIType << 30;
208 word += TrigT1CaloDefs::energyRoI0 << 28;
209 // set full/restricted eta range flag
210 word += (m_restricted & 1) << 26;
211 // add MET Significance hits
212 word += metSigHits() << 16;
213 // add Ex overflow bit
214 word += exOverflow() << 15;
215 // add Ex value (twos-complement)
216 word += exTC();
217 return word;
218}
219
221unsigned int SystemEnergy::roiWord1() const
222{
223 // Start by setting up header
224 unsigned int word = TrigT1CaloDefs::energyRoIType << 30;
225 word += TrigT1CaloDefs::energyRoI1 << 28;
226 // set full/restricted eta range flag
227 word += (m_restricted & 1) << 26;
228 // add EtSum hits
229 word += etSumHits() << 16;
230 // add Ey overflow bit
231 word += eyOverflow() << 15;
232 // add Ey value (twos-complement)
233 word += eyTC();
234 return word;
235}
236
238unsigned int SystemEnergy::roiWord2() const
239{
240 // Start by setting up header
241 unsigned int word = TrigT1CaloDefs::energyRoIType << 30;
242 word += TrigT1CaloDefs::energyRoI2 << 28;
243 // set full/restricted eta range flag
244 word += (m_restricted & 1) << 26;
245 // add EtMiss hits
246 word += etMissHits() << 16;
247 // add Et overflow bit
248 word += etOverflow() << 15;
249 // add Et value (unsigned)
250 word += et();
251 return word;
252}
253
258{
260 m_etMissHits = 0;
261
264
266 if ((m_overflowX != 0) || (m_overflowY != 0))
267 {
269 return;
270 }
271
273
274 // Get thresholds
275 std::vector<std::shared_ptr<TrigConf::L1Threshold>> allThresholds = m_L1Menu->thresholds();
276
277 // get Threshold values and test
278
279 for ( const auto& thresh : allThresholds ) {
280 if ( thresh->type() == L1DataDef::typeAsString(L1DataDef::XE) ) {
281 auto thresh_Calo = static_cast<const TrigConf::L1Threshold_Calo*>(thresh.get());
282 unsigned int thresholdValue = thresh_Calo->thrValueCounts();
283 uint32_t tvQ = thresholdValue * thresholdValue;
284 int threshNumber = thresh->mapping();
285 if (m_restricted == 0 && threshNumber < 8)
286 {
287 if (m_etMissQ > tvQ)
288 m_etMissHits = m_etMissHits | (1 << threshNumber);
289 }
290 else if (m_restricted != 0 && threshNumber >= 8)
291 {
292 if (m_etMissQ > tvQ)
293 m_etMissHits = m_etMissHits | (1 << (threshNumber - 8));
294 }
295 }
296 }
297
298 return;
299}
300
303{
304 // Start cleanly
305 m_etSumHits = 0;
306
307 // Overflow of any sort automatically fires all thresholds
309 {
311 return;
312 }
313
314 // Get thresholds
315 std::vector<std::shared_ptr<TrigConf::L1Threshold>> allThresholds = m_L1Menu->thresholds();
316
317 // get Threshold values and test
318 // Since eta-dependent values are being used to disable TE in regions, must find lowest value for each threshold
319 for ( const auto& thresh : allThresholds ) {
320 if ( thresh->type() == L1DataDef::typeAsString(L1DataDef::TE) ) {
321 int threshNumber = thresh->mapping();
322 int thresholdValue = m_maxEtSumThr;
323 auto thresh_Calo = static_cast<const TrigConf::L1Threshold_Calo*>(thresh.get());
324 auto tvcs = thresh_Calo->thrValuesCounts();
325 if (tvcs.size() == 0) {
326 tvcs.addRangeValue(thresh_Calo->thrValueCounts(),-49, 49, 1, true);
327 }
328 for (const auto& tVC : tvcs) {
329 if (static_cast<int>(tVC.value()) < thresholdValue) {
330 thresholdValue = tVC.value();
331 }
332 }
333
334 if (m_restricted == 0 && threshNumber < 8)
335 {
336 if (static_cast<int>(m_systemEt) > thresholdValue)
337 m_etSumHits = m_etSumHits | (1 << threshNumber);
338 }
339 else if (m_restricted != 0 && threshNumber >= 8)
340 {
341 if (static_cast<int>(m_systemEt) > thresholdValue)
342 m_etSumHits = m_etSumHits | (1 << (threshNumber - 8));
343 }
344 }
345 }
346
347 return;
348}
349
352{
354 m_metSigHits = 0;
355
357 if (m_restricted != 0)
358 return;
359
361 auto& params = m_L1Menu->thrExtraInfo().XS();
362 unsigned int Scale = params.xsSigmaScale();
363 unsigned int Offset = params.xsSigmaOffset();
364 unsigned int XEmin = params.xeMin();
365 unsigned int XEmax = params.xeMax();
366 int sqrtTEmin = params.teSqrtMin();
367 int sqrtTEmax = params.teSqrtMax();
368
370 if ((m_overflowX > 0) || (m_overflowY > 0) || (m_etMissQ > XEmax * XEmax))
371 {
373 return;
374 }
375 else if ((m_etMissQ < XEmin * XEmin) || (m_systemEt < sqrtTEmin * sqrtTEmin) || (m_systemEt > sqrtTEmax * sqrtTEmax))
376 {
377 return;
378 }
379
383 unsigned long aQ = Scale * Scale;
384 unsigned int bQ = ceil(Offset * Offset * 1.e-6);
385 unsigned long fourbQTE = 4 * bQ * m_systemEt;
386
387 // Get thresholds
388 std::vector<std::shared_ptr<TrigConf::L1Threshold>> allThresholds = m_L1Menu->thresholds();
389
392 for ( const auto& thresh : allThresholds ) {
393 if ( thresh->type() == L1DataDef::typeAsString(L1DataDef::XS) ) {
394
395 int threshNumber = thresh->mapping();
396 auto thresh_Calo = static_cast<const TrigConf::L1Threshold_Calo*>(thresh.get());
397 unsigned int Ti = thresh_Calo->thrValueCounts();
398 unsigned long aQTiQ = (0.5 + double(aQ * 1.e-8) * Ti * Ti);
399
400 long left = aQTiQ * aQTiQ * fourbQTE;
401 long right = aQTiQ * (m_systemEt + bQ) - m_etMissQ;
402
403 if (right < 0 || left > right * right)
404 m_metSigHits = m_metSigHits | (1 << threshNumber);
405 }
406 }
407
408 return;
409}
410
412unsigned int SystemEnergy::encodeTC(int input) const
413{
414 unsigned int value;
415
416 if (input > 0)
417 {
418 value = input;
419 }
420 else
421 {
422 value = (1 << m_sumBits) + input;
423 }
424
425 int mask = (1 << m_sumBits) - 1;
426 return value & mask;
427}
428
430int SystemEnergy::decodeTC(unsigned int input) const
431{
432
433 int mask = (1 << m_sumBits) - 1;
434 int value = input & mask;
435
436 if ((value >> (m_sumBits - 1)))
437 {
438 int complement = ~value;
439 value = -((complement + 1) & mask);
440 }
441
442 return value;
443}
444
445} // end of ns
Derived DataVector<T>.
Definition DataVector.h:795
CrateEnergy class declaration Simulates behaviour of the Crate-CMM System CMM logic is done in Energy...
Definition CrateEnergy.h:29
unsigned int m_metSigHits
int ex() const
return crate Ex
unsigned int etOverflow() const
return Et overflow bit
unsigned int exOverflow() const
Overflow bits.
unsigned int etMissHits() const
Trigger Results.
void etMissTrigger()
Test Ex, Ey sums against ETmiss thresholds Regrettably not as simple as it sounds if we emulate har...
unsigned int m_restricted
unsigned int m_etMissHits
unsigned int roiWord1() const
return RoI word 1 (Ey value & overflow, EtSum hits)
int ey() const
return crate Ey
int decodeTC(unsigned int input) const
decode 15-bit twos-complement format (hardware Ex/Ey format) as int
static const unsigned int m_sumBits
unsigned int roiWord2() const
return RoI word 2 (Et value & overflow, EtMiss hits)
unsigned int eyTC() const
return crate Ey in 15-bit twos-complement format (hardware format)
unsigned int etSumHits() const
return EtSum hits
unsigned int m_overflowT
void metSigTrigger()
Test MEt Significance against METSig thresholds.
unsigned int metSigHits() const
return MEtSig hits
const TrigConf::L1Menu * m_L1Menu
unsigned int encodeTC(int input) const
encode int as 15-bit twos-complement format (hardware Ex/Ey format)
unsigned int eyOverflow() const
return Ey overflow bit
void etSumTrigger()
Test Et sum against ETsum thresholds.
unsigned int m_overflowX
unsigned int exTC() const
15 bit twos-complement format
unsigned int m_etSumHits
static const int m_maxEtSumThr
SystemEnergy(const DataVector< CrateEnergy > *crates, const TrigConf::L1Menu *l1Menu)
unsigned int roiWord0() const
RoI words.
int et() const
return global et, ex, ey sums
unsigned int m_overflowY
static const int m_etSumOverflow
static const unsigned int numOfSumEtThresholds
static const unsigned int numOfMEtSigThresholds
static const unsigned int numOfMissingEtThresholds
static std::string & typeAsString(TriggerType tt)
Definition L1DataDef.h:53
L1 menu configuration.
Definition L1Menu.h:28
virtual unsigned int thrValueCounts(int eta=0) const
virtual ValueWithEtaDependence< unsigned int > thrValuesCounts() const
access to the list of ThresholdValues in energy units
void Scale(TH1 *h, double d=1)
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22