ATLAS Offline Software
Loading...
Searching...
No Matches
PU1SuppTools.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
16
17#include "PU1SuppTools.h"
18
19#include <array>
20#include <fstream>
21#include <iomanip>
22#include <sstream>
23#include <stdexcept>
24#include <ostream>
25
26namespace GlobalSim {
27
28void printFullNumber(const std::vector<std::bitset<64>> &number, MsgStream& msg) {
29 for (const auto &part : number) {
30 msg << MSG::DEBUG << part << endmsg; // Print each 64-bit segment
31 }
32}
33
35 const std::vector<std::bitset<64>> &number) {
36 return number[0].to_string() + number[1].to_string() + number[2].to_string() +
37 number[3].to_string(); // Concatenate all 4 segments
38}
39
40std::string remakeFullNumberToHex(const std::vector<std::bitset<64>> &number,
41 MsgStream &msg) {
42 if (number.size() != 4) {
43 msg << MSG::ERROR
44 << "remakeFullNumberToHex: TOB vector does not contain 4 elements"
45 << endmsg;
46 return "";
47 }
48 std::stringstream ss;
49 ss << std::hex << std::setfill('0');
50 for (const auto &part : number) {
51 ss << std::setw(16)
52 << part.to_ullong(); // Format each 64-bit segment as hex
53 }
54 return ss.str();
55}
56
57void writeFullNumberOut(std::ostream &outFile,
58 std::vector<std::bitset<64>> &line, MsgStream &msg) {
59 std::string remadeBinaryString = remakeFullNumberToHex(line, msg);
60 msg << MSG::DEBUG << "writeFullNumberOut: hex result: " << remadeBinaryString
61 << endmsg;
62 outFile << remadeBinaryString << std::endl; // Output to file
63}
64
65void readInputTOB(const std::bitset<64> tob_data, et_type &et_value,
66 eta_type &eta_value, phi_type &phi_value,
67 rsvd_type &rsvd_data) {
68 unsigned long long tob_data_ull = tob_data.to_ullong();
69 et_value = (tob_data_ull >> 19) & 0xFFFF; // 16-bit ET from bits 19–34
70 phi_value = tob_data_ull & 0xFF; // 8-bit phi from bits 0–7
71 eta_value = (tob_data_ull >> 8) & 0x7FF; // 11-bit eta from bits 8–18
72 rsvd_data =
73 (tob_data_ull >> 36) & 0xFFFFFFF; // 28-bit reserved from bits 36–63
74}
75
76// Designed to mimic a hardware subtractor circuit
77bool compareThresholdEt(const std::bitset<16>& tobEt,
78 const std::bitset<16>& thresholdEt) {
79 int borrow = 0;
80 for (int i=0; i < 16; ++i) {
81 int diff = (int)tobEt[i] - (int)thresholdEt[i] - borrow;
82 borrow = (diff < 0) ? 1 : 0;
83 }
84 return borrow == 0;
85}
86
88 if (eta >= 0 && eta <= 2047) {
89 if (eta >= 1900)
90 return 19; // Clamp high eta values to last bin
91 return eta / 100; // Otherwise divide by 100 for bin index
92 }
93 throw std::out_of_range("eta is out of the valid range (0 to 2047)");
94}
95
97 if (rho < 1024) {
98 rho_index_type index = rho / 20; // Compute bin index
99 return std::min(index, static_cast<rho_index_type>(
100 49)); // Clamp to max LUT index, cast to
101 // rho_index_type for min comparison
102 } else {
103 throw std::out_of_range("rho is out of the valid range (0 to 1023)");
104 }
105}
106
107StatusCode runSimulation(std::vector<std::bitset<64>> &entry,
108 const std::vector<std::vector<et_type>> &lut,
109 rho_type rho_data, MsgStream &msg) {
110 if (entry.size() != 4) {
111 msg << MSG::ERROR << "runSimulation: entry must contain exactly 4 TOBs"
112 << endmsg;
113 return StatusCode::FAILURE;
114 }
115
116 for (int i = 0; i < 4; ++i) {
117 auto &tob = entry[i];
118 et_type et_data;
119 eta_type eta_data;
120 phi_type phi_data;
121 rsvd_type rsvd_data;
122
123 readInputTOB(tob, et_data, eta_data, phi_data,
124 rsvd_data); // Decode TOB fields
125
126 rho_index_type rho_index{}; // Initialize
127 eta_index_type eta_index{};
128
129 try {
130 rho_index = Rho_to_index_Converter(rho_data);
131 eta_index = Eta_to_index_Converter(eta_data);
132 } catch (const std::out_of_range &e) {
133 msg << MSG::ERROR << "runSimulation: index conversion failed for TOB "
134 << i << ": " << e.what() << endmsg;
135 continue;
136 }
137
138 if (rho_index >= lut.size() || eta_index >= lut[rho_index].size()) {
139 msg << MSG::ERROR
140 << "runSimulation: Index out of range for MED_LUT: rho=" << rho_index
141 << ", eta=" << eta_index << endmsg;
142 continue;
143 }
144
145 int threshold = lut[rho_index][eta_index]; // Lookup ET threshold from LUT
146 std::bitset<16> etBits(et_data);
147 std::bitset<16> thresholdBits(static_cast<uint16_t>(threshold));
148
149 msg << MSG::VERBOSE << "runSimulation TOB[" << i << "]: ET=" << et_data
150 << " threshold=" << threshold << endmsg;
151
152 if (compareThresholdEt(etBits, thresholdBits)) {
153 tob.set(55); // Mark TOB as passing (set bit 55)
154 msg << MSG::DEBUG << "runSimulation TOB[" << i << "] passes (bit 55 set)"
155 << endmsg;
156 } else {
157 tob.reset(55); // Mark TOB as failing (clear bit 55)
158 msg << MSG::DEBUG << "runSimulation TOB[" << i
159 << "] does not pass (bit 55 cleared)" << endmsg;
160 }
161 }
162 return StatusCode::SUCCESS;
163}
164
165} // namespace GlobalSim
Scalar eta() const
pseudorapidity method
#define endmsg
uint16_t tobEt(const T *tob)
static Double_t ss
Header for utility functions and type definitions used in PU1 suppression logic.
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
AlgTool that to test whether expected the TIP values generated by data supplied by eEmMultTestBench c...
std::string remakeFullNumberToBinary(const std::vector< std::bitset< 64 > > &number)
Converts a vector of 4x 64-bit TOBs to a 256-bit binary string.
std::string remakeFullNumberToHex(const std::vector< std::bitset< 64 > > &number, MsgStream &msg)
Converts a vector of 4x 64-bit TOBs to a 64-character hex string.
int rsvd_type
Integer for reserved data field.
eta_index_type Eta_to_index_Converter(eta_type eta)
Converts a raw eta value to its LUT index.
uint16_t rho_type
16-bit type for pileup energy density
void printFullNumber(const std::vector< std::bitset< 64 > > &number, MsgStream &msg)
Prints a full 256-bit number (4x 64-bit).
int eta_type
Signed integer for pseudorapidity.
bool compareThresholdEt(const std::bitset< 16 > &tobEt, const std::bitset< 16 > &thresholdEt)
std::size_t rho_index_type
Index derived from rho value.
StatusCode runSimulation(std::vector< std::bitset< 64 > > &entry, const std::vector< std::vector< et_type > > &lut, rho_type rho_data, MsgStream &msg)
Applies LUT-based suppression logic to a vector of TOBs.
std::size_t eta_index_type
Index derived from eta value.
void readInputTOB(const std::bitset< 64 > tob_data, et_type &et_value, eta_type &eta_value, phi_type &phi_value, rsvd_type &rsvd_data)
Extracts ET, eta, phi, and reserved bits from a 64-bit TOB.
void writeFullNumberOut(std::ostream &outFile, std::vector< std::bitset< 64 > > &line, MsgStream &msg)
Writes a vector of TOBs as a hex string to an output stream.
uint16_t et_type
16-bit type for transverse energy
rho_index_type Rho_to_index_Converter(rho_type rho)
Converts a raw rho value to its LUT index.
uint8_t phi_type
8-bit type for azimuthal angle
Definition index.py:1
MsgStream & msg
Definition testRead.cxx:32
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186