ATLAS Offline Software
Loading...
Searching...
No Matches
L0Muon::TgcL0GoodMagMap Class Reference

Immutable sparse GoodMag map loaded from ASCII. More...

#include <TgcL0GoodMagMap.h>

Collaboration diagram for L0Muon::TgcL0GoodMagMap:

Public Member Functions

bool isGood (int etaBin, int phiFoldBin) const
 Return false for a masked or out-of-range calibration bin.
bool isGood (float eta, float phi, float absEtaMin, float absEtaMax) const
 Evaluate the map using its own eta and folded-phi binning.
const std::string & version () const
unsigned int etaBins () const
unsigned int phiBinsPerFold () const
std::size_t poorBinCount () const

Static Public Member Functions

static std::unique_ptr< TgcL0GoodMagMaploadAscii (const std::string &calibrationPath, std::string &error)

Private Member Functions

 TgcL0GoodMagMap ()=default
int etaBin (float eta, float absEtaMin, float absEtaMax) const
int phiFoldBin (float phi) const

Private Attributes

std::string m_version {}
unsigned int m_etaBins {0U}
unsigned int m_phiBinsPerFold {0U}
std::vector< bool > m_poorBins {}
std::size_t m_poorBinCount {0U}

Detailed Description

Immutable sparse GoodMag map loaded from ASCII.

Definition at line 15 of file TgcL0GoodMagMap.h.

Constructor & Destructor Documentation

◆ TgcL0GoodMagMap()

L0Muon::TgcL0GoodMagMap::TgcL0GoodMagMap ( )
privatedefault

Member Function Documentation

◆ etaBin()

int L0Muon::TgcL0GoodMagMap::etaBin ( float eta,
float absEtaMin,
float absEtaMax ) const
private

Definition at line 180 of file TgcL0GoodMagMap.cxx.

181 {
182 if (!std::isfinite(eta) || !std::isfinite(absEtaMin) ||
183 !std::isfinite(absEtaMax) || !(absEtaMax > absEtaMin)) {
184 return -1;
185 }
186 const float absEta = std::abs(eta);
187 if (absEta < absEtaMin || absEta > absEtaMax) return -1;
188 if (absEta == absEtaMax) return static_cast<int>(m_etaBins) - 1;
189 const float scaled =
190 (absEta - absEtaMin) * m_etaBins / (absEtaMax - absEtaMin);
191 const int bin = static_cast<int>(std::floor(scaled));
192 return bin >= 0 && bin < static_cast<int>(m_etaBins) ? bin : -1;
193}
Scalar eta() const
pseudorapidity method
bool absEta(const xAOD::TauJet &tau, float &out)

◆ etaBins()

unsigned int L0Muon::TgcL0GoodMagMap::etaBins ( ) const
inline

Definition at line 34 of file TgcL0GoodMagMap.h.

34{ return m_etaBins; }

◆ isGood() [1/2]

bool L0Muon::TgcL0GoodMagMap::isGood ( float eta,
float phi,
float absEtaMin,
float absEtaMax ) const

Evaluate the map using its own eta and folded-phi binning.

Parameters
etaCandidate pseudorapidity.
phiCandidate azimuth in radians.
absEtaMinLower edge of the calibrated absolute-eta range.
absEtaMaxUpper edge of the calibrated absolute-eta range.

Definition at line 207 of file TgcL0GoodMagMap.cxx.

209 {
210 return isGood(etaBin(eta, absEtaMin, absEtaMax), phiFoldBin(phi));
211}
Scalar phi() const
phi method
int phiFoldBin(float phi) const
bool isGood(int etaBin, int phiFoldBin) const
Return false for a masked or out-of-range calibration bin.
int etaBin(float eta, float absEtaMin, float absEtaMax) const

◆ isGood() [2/2]

bool L0Muon::TgcL0GoodMagMap::isGood ( int etaBin,
int phiFoldBin ) const

Return false for a masked or out-of-range calibration bin.

Definition at line 167 of file TgcL0GoodMagMap.cxx.

168 {
169 if (etaBin < 0 || phiFoldBin < 0 ||
170 etaBin >= static_cast<int>(m_etaBins) ||
171 phiFoldBin >= static_cast<int>(m_phiBinsPerFold)) {
172 return false;
173 }
174 const std::size_t index = static_cast<std::size_t>(etaBin) *
176 static_cast<std::size_t>(phiFoldBin);
177 return !m_poorBins[index];
178}
std::vector< bool > m_poorBins
str index
Definition DeMoScan.py:362

◆ loadAscii()

std::unique_ptr< TgcL0GoodMagMap > L0Muon::TgcL0GoodMagMap::loadAscii ( const std::string & calibrationPath,
std::string & error )
static

Definition at line 42 of file TgcL0GoodMagMap.cxx.

43 {
44 error.clear();
45 std::ifstream input{calibrationPath};
46 if (!input) {
47 error = "cannot open ASCII GoodMag map: " + calibrationPath;
48 return nullptr;
49 }
50
51 auto map = std::unique_ptr<TgcL0GoodMagMap>{new TgcL0GoodMagMap};
52 unsigned int schemaVersion = 0U;
53 bool schemaVersionSeen = false;
54 bool payloadVersionSeen = false;
55 bool etaBinsSeen = false;
56 bool phiBinsSeen = false;
57 bool mapRecordsStarted = false;
58 std::string line;
59 std::size_t lineNumber = 0U;
60 while (std::getline(input, line)) {
61 ++lineNumber;
62 if (line.empty() || line[0] == '#') continue;
63 if (hasEmptyCsvField(line)) {
64 error = "empty CSV field at line " + std::to_string(lineNumber);
65 return nullptr;
66 }
67 const auto fields = CxxUtils::tokenize(line, ',');
68 if (fields.empty()) continue;
69 const std::string& record = fields[0];
70 if (record == "META") {
71 if (mapRecordsStarted) {
72 error = "META row after map records at line " +
73 std::to_string(lineNumber);
74 return nullptr;
75 }
76 if (fields.size() != 3U) {
77 error = "invalid META row at line " + std::to_string(lineNumber);
78 return nullptr;
79 }
80 const std::string& key = fields[1];
81 if (key == "schemaVersion") {
82 if (schemaVersionSeen ||
83 !parseUnsignedInteger(fields[2], schemaVersion)) {
84 error = "invalid or duplicate schemaVersion";
85 return nullptr;
86 }
87 schemaVersionSeen = true;
88 } else if (key == "payloadVersion") {
89 if (payloadVersionSeen || fields[2].empty()) {
90 error = "invalid or duplicate payloadVersion";
91 return nullptr;
92 }
93 map->m_version = fields[2];
94 payloadVersionSeen = true;
95 } else if (key == "etaBins") {
96 if (etaBinsSeen ||
97 !parseUnsignedInteger(fields[2], map->m_etaBins)) {
98 error = "invalid or duplicate etaBins";
99 return nullptr;
100 }
101 etaBinsSeen = true;
102 } else if (key == "phiBinsPerFold") {
103 if (phiBinsSeen ||
104 !parseUnsignedInteger(fields[2], map->m_phiBinsPerFold)) {
105 error = "invalid or duplicate phiBinsPerFold";
106 return nullptr;
107 }
108 phiBinsSeen = true;
109 } else {
110 error = "unknown metadata key at line " +
111 std::to_string(lineNumber) + ": " + key;
112 return nullptr;
113 }
114 continue;
115 }
116
117 mapRecordsStarted = true;
118 if (record != "POOR") {
119 error = "unknown map record at line " + std::to_string(lineNumber) +
120 ": " + record;
121 return nullptr;
122 }
123 if (fields.size() != 3U || map->m_etaBins == 0U ||
124 map->m_phiBinsPerFold == 0U) {
125 error = "invalid POOR row at line " + std::to_string(lineNumber);
126 return nullptr;
127 }
128 int etaBin = -1;
129 int phiFoldBin = -1;
130 if (!parseInteger(fields[1], etaBin) ||
131 !parseInteger(fields[2], phiFoldBin) || etaBin < 0 ||
132 phiFoldBin < 0 || etaBin >= static_cast<int>(map->m_etaBins) ||
133 phiFoldBin >= static_cast<int>(map->m_phiBinsPerFold)) {
134 error = "invalid map bin at line " + std::to_string(lineNumber);
135 return nullptr;
136 }
137 if (map->m_poorBins.empty()) {
138 const std::size_t count = static_cast<std::size_t>(map->m_etaBins) *
139 map->m_phiBinsPerFold;
140 map->m_poorBins.assign(count, false);
141 }
142 const std::size_t index = static_cast<std::size_t>(etaBin) *
143 map->m_phiBinsPerFold +
144 static_cast<std::size_t>(phiFoldBin);
145 if (map->m_poorBins[index]) {
146 error = "duplicate POOR bin at line " + std::to_string(lineNumber);
147 return nullptr;
148 }
149 map->m_poorBins[index] = true;
150 ++map->m_poorBinCount;
151 }
152
153 if (!schemaVersionSeen || schemaVersion != 1U || !payloadVersionSeen ||
154 !etaBinsSeen || !phiBinsSeen || map->m_etaBins == 0U ||
155 map->m_phiBinsPerFold == 0U) {
156 error = "incomplete or unsupported ASCII GoodMag metadata";
157 return nullptr;
158 }
159 if (map->m_poorBins.empty()) {
160 const std::size_t count = static_cast<std::size_t>(map->m_etaBins) *
161 map->m_phiBinsPerFold;
162 map->m_poorBins.assign(count, false);
163 }
164 return map;
165}
static const Attributes_t empty
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.

◆ phiBinsPerFold()

unsigned int L0Muon::TgcL0GoodMagMap::phiBinsPerFold ( ) const
inline

Definition at line 35 of file TgcL0GoodMagMap.h.

35{ return m_phiBinsPerFold; }

◆ phiFoldBin()

int L0Muon::TgcL0GoodMagMap::phiFoldBin ( float phi) const
private

Definition at line 195 of file TgcL0GoodMagMap.cxx.

195 {
196 if (!std::isfinite(phi)) return -1;
197 const float period = 2.F * std::numbers::pi_v<float> / 8.F;
198 float folded = std::fmod(phi, period);
199 if (folded < 0.F) folded += period;
200 float fraction = folded / period;
201 if (fraction >= 1.F) fraction = 0.F;
202 return std::clamp(
203 static_cast<int>(std::floor(fraction * m_phiBinsPerFold)), 0,
204 static_cast<int>(m_phiBinsPerFold) - 1);
205}

◆ poorBinCount()

std::size_t L0Muon::TgcL0GoodMagMap::poorBinCount ( ) const
inline

Definition at line 36 of file TgcL0GoodMagMap.h.

36{ return m_poorBinCount; }

◆ version()

const std::string & L0Muon::TgcL0GoodMagMap::version ( ) const
inline

Definition at line 33 of file TgcL0GoodMagMap.h.

33{ return m_version; }

Member Data Documentation

◆ m_etaBins

unsigned int L0Muon::TgcL0GoodMagMap::m_etaBins {0U}
private

Definition at line 45 of file TgcL0GoodMagMap.h.

45{0U};

◆ m_phiBinsPerFold

unsigned int L0Muon::TgcL0GoodMagMap::m_phiBinsPerFold {0U}
private

Definition at line 46 of file TgcL0GoodMagMap.h.

46{0U};

◆ m_poorBinCount

std::size_t L0Muon::TgcL0GoodMagMap::m_poorBinCount {0U}
private

Definition at line 48 of file TgcL0GoodMagMap.h.

48{0U};

◆ m_poorBins

std::vector<bool> L0Muon::TgcL0GoodMagMap::m_poorBins {}
private

Definition at line 47 of file TgcL0GoodMagMap.h.

47{};

◆ m_version

std::string L0Muon::TgcL0GoodMagMap::m_version {}
private

Definition at line 44 of file TgcL0GoodMagMap.h.

44{};

The documentation for this class was generated from the following files: