ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalLArCellContainer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <ranges>
7#include <algorithm>
8
9namespace GlobalSim {
10
11 // Main constructor setting up FEB2 LUTs
12 GlobalLArCellContainer::GlobalLArCellContainer(const std::map<std::string,Feb2MuxInfo>& febMap) {
13
14 std::map<std::string, std::vector<std::pair<int,std::string>>> tempMap;
15
16 // Loop over map of FEB2s to establish LUTs and lists
17 for (const auto & [feb2, muxInfo] : febMap) {
18 m_feb2Flags.insert({feb2, {false, false}});
19 m_feb2Keys.insert(feb2);
20 m_muxKeys.insert(muxInfo.muxName);
21 m_muxFlags.insert({muxInfo.muxName, {false, false}});
22 m_feb2ToMux.insert({feb2, muxInfo.muxName});
23
24 tempMap[muxInfo.muxName].emplace_back(muxInfo.indexOnMux, feb2);
25 }
26
27 // Sort FEB2 vectors for each MUX
28 for (auto& [muxName, vec] : tempMap) {
29 std::sort(vec.begin(), vec.end(), [](const auto& a, const auto& b) {
30 return a.first < b.first; // sort by indexOnMux
31 });
32
33 // Copy only the FEB2 names into m_muxToFeb2Ordered
34 std::vector<std::string> orderedFeb2s;
35 orderedFeb2s.reserve(vec.size());
36 for (const auto& [idx, feb2] : vec) {
37 orderedFeb2s.push_back(feb2);
38 }
39 m_muxToFeb2Ordered[muxName] = std::move(orderedFeb2s);
40 }
41 }
42
43
44 // Copy constructor
47 {
48 // Deep-copy DataVector elements
49 for (const auto cellPtr : other) {
50 DataVector<GlobalLArCell>::push_back(std::make_unique<GlobalLArCell>(*cellPtr));
51 }
52
53 // Copy the maps and sets
54 m_feb2Flags = other.m_feb2Flags;
55 m_feb2Keys = other.m_feb2Keys;
56 m_muxKeys = other.m_muxKeys;
57 m_muxFlags = other.m_muxFlags;
58 m_maxCellsPerFeb2 = other.m_maxCellsPerFeb2;
59 m_muxToFeb2Ordered = other.m_muxToFeb2Ordered;
60 m_feb2ToMux = other.m_feb2ToMux;
61 }
62
63
64 // Reimplementation of the push_back function to fill GlobalLArCells
66 auto cell = std::make_unique<GlobalLArCell>(theCell);
67 auto* cellPtr = cell.get();
69
70 m_feb2ToCells[cellPtr->getFEB2()].push_back(std::make_shared<GlobalLArCell>(*cellPtr));
71 m_hashToCells.insert({hashId, std::make_shared<GlobalLArCell>(*cellPtr)});
72 }
73
74
75 // Function to get all GlobalLArCells for a given FEB2 name
76 const std::vector<std::shared_ptr<GlobalLArCell>>& GlobalLArCellContainer::getCellsForFeb2(const std::string& feb2) const {
77
78 static const std::vector<std::shared_ptr<GlobalLArCell>> emptyCellVector; // fallback if not found
79 auto it = m_feb2ToCells.find(feb2);
80
81 if (it != m_feb2ToCells.end()) {
82 return it->second;
83 }
84
85 return emptyCellVector;
86 }
87
88 // Function to get all GlobalLArCells for a given IdentifierHash
89 const std::shared_ptr<GlobalLArCell> GlobalLArCellContainer::getCellFromHash(IdentifierHash hashId) const {
90
91 const std::shared_ptr<GlobalLArCell> emptyCell;// fallback if not found
92 auto it = m_hashToCells.find(hashId);
93
94 if (it != m_hashToCells.end()) {
95 return it->second;
96 }
97
98 return emptyCell;
99 }
100
101 // Function to get all GlobalLArCells for a given IdentifierHash
103
104 Identifier emptyID;
105 for (auto& [location, ID] : m_cellLocationToID) {
106 float etamin = location.eta - (0.5*location.deta);
107 float etamax = location.eta + (0.5*location.deta);
108
109 float phimin = location.phi - (0.5*location.dphi);
110 float phimax = location.phi + (0.5*location.dphi);
111
112 if(etamin < eta && eta < etamax && phimin < phi && phi < phimax){
113 // Return the cellID if we find a match
114 return ID;
115 }
116
117 }
118 return emptyID;
119 }
120
121 // Function to get ordered list of FEB2s for a given MUX name
122 const std::vector<std::string>& GlobalLArCellContainer::getOrderedFeb2sForMux(const std::string& mux) const {
123
124 static const std::vector<std::string> emptyMux;
125 auto it = m_muxToFeb2Ordered.find(mux);
126 if (it != m_muxToFeb2Ordered.end()) {
127 return it->second;
128 }
129
130 return emptyMux;
131 }
132
133
134 // Function to get the associated MUX name for a given FEB2
135 const std::string& GlobalLArCellContainer::getMuxForFeb2(const std::string& feb2Key) const {
136 auto it = m_feb2ToMux.find(feb2Key);
137 if (it == m_feb2ToMux.end()) {
138 throw std::runtime_error("Unknown FEB2 key: " + feb2Key);
139 }
140 return it->second;
141 }
142
143
144 // Function to set overflow and error flag for a FEB2
145 void GlobalLArCellContainer::setFeb2Flags(const std::string& feb2Key, bool overflow, bool error) {
146 auto& flags = m_feb2Flags[feb2Key];
147 flags.overflow = overflow;
148 flags.error = error;
149
150 // Propagate FEB2 flags to the MUX
151 if (overflow) {
152 auto& muxFlags = m_muxFlags[m_feb2ToMux[feb2Key]];
153 muxFlags.overflow = overflow;
154 }
155 if (error) {
156 auto& muxFlags = m_muxFlags[m_feb2ToMux[feb2Key]];
157 muxFlags.error = error;
158 }
159 }
160
161 // Function to fill a map with the location and size of incoming cells
163 LocSize cell_LocSize = {cell->eta(), cell->phi(),cell->caloDDE()->deta(),cell->caloDDE()->dphi()};
164 m_cellLocationToID.insert({cell_LocSize, ID});
165 }
166
167 // Function to check whether a given FEB2 is in overflow
168 bool GlobalLArCellContainer::feb2InOverflow(const std::string& feb2Key) const {
169 auto it = m_feb2Flags.find(feb2Key);
170 return (it != m_feb2Flags.end()) ? it->second.overflow : false;
171 }
172
173
174 // Function to check if a given FEB2 is in error
175 bool GlobalLArCellContainer::feb2InError(const std::string& feb2Key) const {
176 auto it = m_feb2Flags.find(feb2Key);
177 return (it != m_feb2Flags.end()) ? it->second.error : false;
178 }
179
180
181 // Function to check whether a given MUX is in overflow
182 bool GlobalLArCellContainer::muxInOverflow(const std::string& muxKey) const {
183 auto it = m_muxFlags.find(muxKey);
184 return (it != m_muxFlags.end()) ? it->second.overflow : false;
185 }
186
187
188 // Function to check if a given MUX is in error
189 bool GlobalLArCellContainer::muxInError(const std::string& muxKey) const {
190 auto it = m_muxFlags.find(muxKey);
191 return (it != m_muxFlags.end()) ? it->second.error : false;
192 }
193
194} // namespace GlobalSim
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
std::vector< size_t > vec
static Double_t a
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
bool muxInError(const std::string &muxKey) const
Check if a given MUX is in error.
void push_back(const GlobalLArCell &theCell, IdentifierHash hashId)
Reimplementation of the push_back function to fill LArCells.
std::unordered_set< std::string > m_muxKeys
vector of all MUX names
void setFeb2Flags(const std::string &feb2Key, bool overflow, bool error)
Set overflow and error flag for a FEB2.
GlobalLArCellContainer()=default
Default constructor.
std::map< std::string, std::string > m_feb2ToMux
map which acts as lookuptable to get the associated MUX from a FEB2 name
std::map< LocSize, Identifier > m_cellLocationToID
map for cell HashID lookup from position
const std::vector< std::shared_ptr< GlobalLArCell > > & getCellsForFeb2(const std::string &feb2) const
Function to get all GlobalLArCells for a given FEB2 name.
bool feb2InOverflow(const std::string &feb2Key) const
Check if a given FEB2 is in overflow.
Identifier getIDFromLoc(float eta, float phi) const
Get the HashID from an input cell position.
std::unordered_set< std::string > m_feb2Keys
vector of all FEB2 names
std::map< std::string, StatusFlags > m_muxFlags
map which stores overflow and error bits for each MUX
const std::string & getMuxForFeb2(const std::string &feb2Key) const
Function to get the associated MUX name for a given FEB2.
bool muxInOverflow(const std::string &muxKey) const
Check if a given MUX is in overflow.
bool feb2InError(const std::string &feb2Key) const
Check if a given FEB2 is in error.
void fillLocToIDMap(Identifier ID, const CaloCell *&cell)
Fill the location to HashId map.
std::map< std::string, StatusFlags > m_feb2Flags
map which stores overflow and error bits for each FEB2
std::map< std::string, std::vector< std::string > > m_muxToFeb2Ordered
map which holds the ordered list of FEB2s for each MUX
std::map< IdentifierHash, std::shared_ptr< GlobalLArCell > > m_hashToCells
map for fast look up of cells
const std::vector< std::string > & getOrderedFeb2sForMux(const std::string &mux) const
Function to get ordered list of FEB2s for a given MUX name.
std::map< std::string, std::vector< std::shared_ptr< GlobalLArCell > > > m_feb2ToCells
map which keeps track of which cells are associated with which FEB2
const std::shared_ptr< GlobalLArCell > getCellFromHash(IdentifierHash hashId) const
Function to get the GlobalLArCell for a given hash identifier.
std::size_t m_maxCellsPerFeb2
Maximum number of cells per FEB2 in given energy encoding scheme.
This is a "hash" representation of an Identifier.
AlgTool to read in LArStripNeighborhoods, and run the eRatio Algorithm.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Helper struct to hold cell's eta/phi location and size.