62 return StatusCode::FAILURE;
65 ATH_MSG_INFO(
"Loading cell map associating LAr cells to FEB2s");
70 std::ifstream
file(cellMapPath.c_str());
75 std::map<std::string,Feb2MuxInfo> feb2MuxAssoc;
80 int online_id, offline_id, channel, con_num, fbr;
81 std::string assocFEB2, con_type, muxname, muxrack, cnnctr, laspname, lasprack;
84 std::getline(
file, assocFEB2);
89 file >> offline_id >> online_id >> assocFEB2 >> channel >> con_type >> con_num >> fbr >> muxname >> muxrack >> cnnctr >> laspname >> lasprack;
91 if (
file.eof())
break;
95 gblLArCell.
setMUX(muxname);
98 m_gblLArCellMap.insert(std::pair<int, GlobalSim::GlobalLArCell>(offline_id, gblLArCell));
100 int indexOnMux = fbr;
101 if (cnnctr ==
"B") indexOnMux += 24;
102 if (cnnctr ==
"C") indexOnMux += 32;
105 auto itr = feb2MuxAssoc.find(assocFEB2);
106 if (itr == feb2MuxAssoc.end()) {
107 feb2MuxAssoc.insert(std::pair<std::string,Feb2MuxInfo>(assocFEB2, {muxname, indexOnMux}));
114 ATH_MSG_ERROR(
"Could not open file containing the cell to FEB2 association");
115 return StatusCode::FAILURE;
118 ATH_MSG_DEBUG(
"Loaded FEB2 information for " << n_cells <<
" LAr cells");
124 return StatusCode::SUCCESS;
139 CHECK(h_caloCells.isValid());
140 const auto & cells = *h_caloCells;
142 ATH_MSG_DEBUG(
"Reading " << std::to_string(h_caloCells->size()) <<
" cells in input cell container");
145 if (!totalNoiseHdl.
isValid()) {
return StatusCode::FAILURE;}
146 const CaloNoise* totalNoiseCDO = *totalNoiseHdl;
148 std::map<std::string,std::vector<GlobalSim::GlobalLArCell>> gblLArCellsPerFEB2;
150 for(
const auto *cell: cells){
152 int cell_id = (cell->ID().get_identifier32()).get_compact();
159 float totalNoise = totalNoiseCDO->
getNoise(cell->ID(), cell->gain());
160 float sigma = cell->energy() / totalNoise;
163 if (sigma < 2.0)
continue;
165 if (cell->badcell())
continue;
167 std::pair<float, boost::dynamic_bitset<>> gep_energy =
encodeEnergy(cell->energy() / TMath::CosH(cell->eta()));
169 gblLArCell.
setEnergy(gep_energy.first, std::move(gep_energy.second));
172 gblLArCell.
setSampling(cell->caloDDE()->getSampling());
173 gblLArCell.
setLayer(cell->caloDDE()->getLayer());
176 auto feb2_itr = gblLArCellsPerFEB2.find(gblLArCell.
getFEB2());
177 if (feb2_itr != gblLArCellsPerFEB2.end()) feb2_itr->second.push_back(std::move(gblLArCell));
179 std::vector<GlobalSim::GlobalLArCell> cellsThisFEB(1, gblLArCell);
180 gblLArCellsPerFEB2.insert(std::pair<std::string,std::vector<GlobalSim::GlobalLArCell>>(gblLArCell.
getFEB2(),cellsThisFEB));
186 auto gblLArCellContainer = std::make_unique<GlobalSim::GlobalLArCellContainer>(templateRef);
189 for (
auto& [feb2Name, cells] : gblLArCellsPerFEB2) {
192 bool inOverflow =
false;
193 bool inError =
false;
197 ATH_MSG_INFO(
"FEB " << feb2Name <<
" is sending " << cells.size() <<
" cells, which is more cells than GEP can receive. Removing all but the possible " <<
m_maxCellsPerFEB <<
" cells.");
202 for (
auto& gblLArCell : cells)
203 gblLArCellContainer->push_back(std::move(gblLArCell));
205 gblLArCellContainer->setFeb2Flags(feb2Name, inOverflow, inError);
207 ATH_MSG_DEBUG(
"Global is receiving a total of " << gblLArCellContainer->size() <<
" LAr cells in this event");
210 ATH_CHECK( h_gblLArCellContainer.
record( std::move(gblLArCellContainer) ) );
212 return StatusCode::SUCCESS;
222 if (energy < 0)
return std::pair<float,boost::dynamic_bitset<>>(0.0,boost::dynamic_bitset<>(
m_numberOfEnergyBits.value(),0));
233 for (
int i = 1; i <= 3; ++i) {
239 float encoded_energy = -1;
249 energy_bits |= boost::dynamic_bitset<>(
m_numberOfEnergyBits.value(),
static_cast<unsigned long>(range) << n_bitsE);
251 return std::pair<float,boost::dynamic_bitset<>>(encoded_energy,energy_bits);
260 std::sort(cells.begin(), cells.end(), [](
const auto&
a,
const auto& b) {
261 return a.getChannel() < b.getChannel(); });
267 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define CHECK(...)
Evaluate an expression and check for errors.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
void setEnergy(float energy)
copy & move c'tor, assignment, and destructor are automatically generated
void setSampling(int sampling)
set sampling of cell
void setBoardConnector(std::string connector, std::string type, int number, int fiber)
set properties of associated board connector
void setMUX(std::string muxname)
set name of associated MUX
void setSigma(float sigma)
set significancy of energy deposit
void setLASP(std::string laspname)
set name of associated LASP
void setLayer(int layer)
set layer of cell
const std::string & getFEB2() const
get the name of the FEB2 this cell is associated with
void setPosition(float eta, float phi)
set position of cell in eta-phi space
virtual StatusCode execute(const EventContext &) const override
execute function running for every event
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Key for the EventInfo object.
Gaudi::Property< int > m_numberOfEnergyBits
Parameters defining the multilinear energy encoding scheme.
Gaudi::Property< std::string > m_LArCellMap
Path to the LAr cell map in the CVMFS GroupData space.
std::pair< float, boost::dynamic_bitset<> > encodeEnergy(float energy) const
Function to simulate the cell energy as seen by Global.
std::map< int, GlobalSim::GlobalLArCell > m_gblLArCellMap
LAr cell map where the key is the offline cell ID.
Gaudi::Property< int > m_valueGainFactor
virtual StatusCode initialize() override
initialize function running before first event
int m_readoutRanges[5]
array holding the energy edges of the multilinear encoding
int m_stepsPerRange
number of discrete values per multilinear energy encoding range
StatusCode removeCellsFromOverloadedFEB(std::vector< GlobalSim::GlobalLArCell > &cells) const
Function to simulate the truncation of overflowing FEB2s.
std::unique_ptr< GlobalSim::GlobalLArCellContainer > m_gblLArCellContainerTemplate
GlobalLArCellContainer template which is constructed in initialize and used in execute.
SG::ReadCondHandleKey< CaloNoise > m_totalNoiseKey
Key to the total noise used for each CaloCell.
Gaudi::Property< int > m_valueLSB
unsigned m_maxCellsPerFEB
maximum number of cells that can be send to Global for each FEB2
SG::ReadHandleKey< CaloCellContainer > m_caloCellsKey
Key to the CaloCell container.
SG::WriteHandleKey< GlobalSim::GlobalLArCellContainer > m_LArCellContainerKey
Key to writing the GlobalLArCellContainer to StoreGate.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AlgTool that to test whether expected the TIP values generated by data supplied by eEmMultTestBench c...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.