66 return StatusCode::FAILURE;
69 ATH_MSG_INFO(
"Loading cell map associating LAr cells to FEB2s");
74 std::ifstream
file(cellMapPath.c_str());
79 std::map<std::string,Feb2MuxInfo> feb2MuxAssoc;
84 int online_id, offline_id, channel, con_num, fbr;
85 std::string assocFEB2, con_type, muxname, muxrack, cnnctr, laspname, lasprack;
88 std::getline(
file, assocFEB2);
93 file >> offline_id >> online_id >> assocFEB2 >> channel >> con_type >> con_num >> fbr >> muxname >> muxrack >> cnnctr >> laspname >> lasprack;
95 if (
file.eof())
break;
99 gblLArCell.
setMUX(muxname);
102 m_gblLArCellMap.insert(std::pair<int, GlobalSim::GlobalLArCell>(offline_id, gblLArCell));
104 int indexOnMux = fbr;
105 if (cnnctr ==
"B") indexOnMux += 24;
106 if (cnnctr ==
"C") indexOnMux += 32;
109 auto itr = feb2MuxAssoc.find(assocFEB2);
110 if (itr == feb2MuxAssoc.end()) {
111 feb2MuxAssoc.insert(std::pair<std::string,Feb2MuxInfo>(assocFEB2, {muxname, indexOnMux}));
118 ATH_MSG_ERROR(
"Could not open file containing the cell to FEB2 association");
119 return StatusCode::FAILURE;
122 ATH_MSG_DEBUG(
"Loaded FEB2 information for " << n_cells <<
" LAr cells");
128 return StatusCode::SUCCESS;
143 CHECK(h_caloCells.isValid());
144 const auto & cells = *h_caloCells;
146 ATH_MSG_DEBUG(
"Reading " << std::to_string(h_caloCells->size()) <<
" cells in input cell container");
149 if (!totalNoiseHdl.
isValid()) {
return StatusCode::FAILURE;}
150 const CaloNoise* totalNoiseCDO = *totalNoiseHdl;
152 std::map<std::string,std::vector<GlobalSim::GlobalLArCell>> gblLArCellsPerFEB2;
154 for(
const auto *cell: cells){
156 int cell_id = (cell->ID().get_identifier32()).get_compact();
163 float totalNoise = totalNoiseCDO->
getNoise(cell->ID(), cell->gain());
164 float sigma = cell->energy() / totalNoise;
167 if (sigma < 2.0)
continue;
169 if (cell->badcell())
continue;
171 std::pair<float, boost::dynamic_bitset<>> gep_energy =
encodeEnergy(cell->energy() / TMath::CosH(cell->eta()));
173 gblLArCell.
setEnergy(gep_energy.first, std::move(gep_energy.second));
176 gblLArCell.
setSize(cell->caloDDE()->deta(), cell->caloDDE()->dphi());
177 gblLArCell.
setSampling(cell->caloDDE()->getSampling());
178 gblLArCell.
setLayer(cell->caloDDE()->getLayer());
181 auto feb2_itr = gblLArCellsPerFEB2.find(gblLArCell.
getFEB2());
182 if (feb2_itr != gblLArCellsPerFEB2.end()) feb2_itr->second.push_back(std::move(gblLArCell));
184 std::vector<GlobalSim::GlobalLArCell> cellsThisFEB(1, gblLArCell);
185 gblLArCellsPerFEB2.insert(std::pair<std::string,std::vector<GlobalSim::GlobalLArCell>>(gblLArCell.
getFEB2(),cellsThisFEB));
191 auto gblLArCellContainer = std::make_unique<GlobalSim::GlobalLArCellContainer>(templateRef);
194 for (
auto& [feb2Name, cells] : gblLArCellsPerFEB2) {
197 bool inOverflow =
false;
198 bool inError =
false;
202 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.");
207 for (
auto& gblLArCell : cells){
209 gblLArCellContainer->push_back(std::move(gblLArCell),hashId);
212 gblLArCellContainer->setFeb2Flags(feb2Name, inOverflow, inError);
214 ATH_MSG_DEBUG(
"Global is receiving a total of " << gblLArCellContainer->size() <<
" LAr cells in this event");
217 ATH_CHECK( h_gblLArCellContainer.
record( std::move(gblLArCellContainer) ) );
219 return StatusCode::SUCCESS;
229 if (energy < 0)
return std::pair<float,boost::dynamic_bitset<>>(0.0,boost::dynamic_bitset<>(
m_numberOfEnergyBits.value(),0));
240 for (
int i = 1; i <= 3; ++i) {
246 float encoded_energy = -1;
256 energy_bits |= boost::dynamic_bitset<>(
m_numberOfEnergyBits.value(),
static_cast<unsigned long>(range) << n_bitsE);
258 return std::pair<float,boost::dynamic_bitset<>>(encoded_energy,energy_bits);
267 std::sort(cells.begin(), cells.end(), [](
const auto&
a,
const auto& b) {
268 return a.getChannel() < b.getChannel(); });
274 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)
const ServiceHandle< StoreGateSvc > & detStore() const
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 setSize(float deta, float dphi)
set size of cell in eta-phi space
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.
const CaloCell_ID * m_calocell_id
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.
This is a "hash" representation of an Identifier.
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.