18 #include "boost/chrono/chrono.hpp"
19 #include "boost/chrono/thread_clock.hpp"
28 m_hasBeenInitialized(false)
30 declareInterface<ICaloClusterGPUConstantTransformer> (
this);
38 return StatusCode::SUCCESS;
47 return StatusCode::SUCCESS;
52 ATH_MSG_ERROR(
"BasicConstantGPUDataExporter (" << this->
name() <<
") must be used with the "
53 "GPU data preparation happening on the first event.");
55 return StatusCode::FAILURE;
60 using clock_type = boost::chrono::thread_clock;
61 auto time_cast = [](
const auto & before,
const auto & after)
63 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
71 cd.m_geometry.allocate();
84 max_eta_pos[
i] = std::numeric_limits<float>::lowest();
86 max_eta_neg[
i] = std::numeric_limits<float>::lowest();
88 max_phi_pos[
i] = std::numeric_limits<float>::lowest();
90 max_phi_neg[
i] = std::numeric_limits<float>::lowest();
99 const Identifier cell_identifier = calo_id->cell_id((IdentifierHash)
cell);
101 const int sampling = calo_id->calo_sample(cell_identifier);
102 const int intra_calo_sampling = calo_id->sampling(cell_identifier);
103 const int subcalo = caloElement->
getSubCalo();
104 const int region = calo_id->region(cell_identifier);
112 ConstantEnumConversion::from_intra_calorimeter_sampling_enum(intra_calo_sampling),
113 ConstantEnumConversion::from_subcalo_enum(subcalo),
114 ConstantEnumConversion::from_region_enum(region),
117 cd.m_geometry->x[
cell] = caloElement->
x();
118 cd.m_geometry->y[
cell] = caloElement->
y();
119 cd.m_geometry->z[
cell] = caloElement->
z();
120 cd.m_geometry->r[
cell] = caloElement->
r();
121 cd.m_geometry->eta[
cell] = caloElement->
eta();
122 cd.m_geometry->phi[
cell] = caloElement->
phi();
124 cd.m_geometry->dx[
cell] = caloElement->
dx();
125 cd.m_geometry->dy[
cell] = caloElement->
dy();
126 cd.m_geometry->dz[
cell] = caloElement->
dz();
127 cd.m_geometry->dr[
cell] = caloElement->
dr();
128 cd.m_geometry->deta[
cell] = caloElement->
deta();
129 cd.m_geometry->dphi[
cell] = caloElement->
dphi();
132 cd.m_geometry->neighbours.offsets[
cell] = 0;
134 if (caloElement->
eta() >= 0)
136 min_eta_pos[sampling] =
std::min(min_eta_pos[sampling], caloElement->
eta() - caloElement->
deta() / 2);
137 min_phi_pos[sampling] =
std::min(min_phi_pos[sampling], caloElement->
phi() - caloElement->
dphi() / 2);
138 max_eta_pos[sampling] =
std::max(max_eta_pos[sampling], caloElement->
eta() + caloElement->
deta() / 2);
139 max_phi_pos[sampling] =
std::max(max_phi_pos[sampling], caloElement->
phi() + caloElement->
dphi() / 2);
143 min_eta_neg[sampling] =
std::min(min_eta_neg[sampling], caloElement->
eta() - caloElement->
deta() / 2);
144 min_phi_neg[sampling] =
std::min(min_phi_neg[sampling], caloElement->
phi() - caloElement->
dphi() / 2);
145 max_eta_neg[sampling] =
std::max(max_eta_neg[sampling], caloElement->
eta() + caloElement->
deta() / 2);
146 max_phi_neg[sampling] =
std::max(max_phi_neg[sampling], caloElement->
phi() + caloElement->
dphi() / 2);
148 min_deta[sampling] =
std::min(min_deta[sampling], caloElement->
deta());
149 min_dphi[sampling] =
std::min(min_dphi[sampling], caloElement->
dphi());
155 constexpr
float corrective_factor = 0.99f;
156 cd.m_geometry->etaPhiToCell.initialize(
i, min_eta_neg[
i], min_phi_neg[
i], max_eta_neg[
i], max_phi_neg[
i],
157 min_eta_pos[
i], min_phi_pos[
i], max_eta_pos[
i], max_phi_pos[
i],
158 min_deta[
i]*corrective_factor, min_dphi[
i]*corrective_factor);
161 cd.m_geometry->fill_eta_phi_map();
163 std::vector<IdentifierHash> neighbour_vector, full_neighs, prev_neighs;
167 for (
int neigh_bit_set = 0; neigh_bit_set <
NumNeighOptions; ++neigh_bit_set)
169 const unsigned int curr_neigh_opt = (1U << neigh_bit_set);
181 calo_id->get_neighbours((IdentifierHash)
cell,
187 calo_id->get_neighbours((IdentifierHash)
cell,
190 calo_id->get_neighbours((IdentifierHash)
cell,
198 std::sort(neighbour_vector.begin(), neighbour_vector.end());
199 std::sort(prev_neighs.begin(), prev_neighs.end());
203 std::set_difference( prev_neighs.begin(), prev_neighs.end(),
204 neighbour_vector.begin(), neighbour_vector.end(),
205 std::back_inserter(full_neighs) );
209 prev_neighs.resize(
cd.m_geometry->neighbours.get_total_number_of_neighbours(
cell));
212 for (
size_t neigh = 0; neigh < prev_neighs.size(); ++neigh)
214 prev_neighs[neigh] =
cd.m_geometry->neighbours.get_neighbour(
cell, neigh);
217 std::sort(full_neighs.begin(), full_neighs.end());
218 std::sort(prev_neighs.begin(), prev_neighs.end());
220 neighbour_vector.clear();
222 std::set_difference( full_neighs.begin(), full_neighs.end(),
223 prev_neighs.begin(), prev_neighs.end(),
224 std::back_inserter(neighbour_vector) );
231 std::sort(neighbour_vector.begin(), neighbour_vector.end());
233 const int neighs_start =
cd.m_geometry->neighbours.get_total_number_of_neighbours(
cell);
235 for (
size_t neigh_num = 0; neigh_num < neighbour_vector.size(); ++neigh_num)
237 cd.m_geometry->neighbours.set_neighbour(
cell, neighs_start + neigh_num, neighbour_vector[neigh_num]);
240 cd.m_geometry->neighbours.offsets[
cell] += NeighOffset::offset_delta(neigh_bit_set) * neighbour_vector.size();
245 #if CALORECGPU_ADD_FULL_PAIRS_LIST_TO_CONSTANT_INFORMATION
254 auto add_neighbours = [&](
const int cell,
const unsigned int curr_neigh_opt)
258 const int num_neighs =
cd.m_geometry->neighbours.get_neighbours(curr_neigh_opt,
cell, neighbours);
260 for (
int neigh = 0; neigh < num_neighs; ++neigh)
262 cd.m_geometry->neighPairs.cell_A[num_pairs] =
cell;
263 cd.m_geometry->neighPairs.cell_B[num_pairs] = neighbours[neigh];
268 for (
int neigh_bit_set = 0; neigh_bit_set <
NumNeighOptions; ++neigh_bit_set)
270 const unsigned int curr_neigh_opt = (1U << neigh_bit_set);
274 if (
cd.m_geometry->is_PS(
cell) ||
cd.m_geometry->is_HECIW_or_FCal(
cell))
279 add_neighbours(
cell, curr_neigh_opt);
286 if (!
cd.m_geometry->is_PS(
cell))
291 add_neighbours(
cell, curr_neigh_opt);
298 if (!
cd.m_geometry->is_HECIW_or_FCal(
cell))
303 add_neighbours(
cell, curr_neigh_opt);
345 const CaloNoise * noise_tool = *noise_handle;
347 IdentifierHash t_start, t_end;
361 cd.m_cell_noise.allocate();
365 cd.m_cell_noise->noise_properties = CellNoiseProperties::invalid_value();
372 cd.m_cell_noise->luminosity = noise_tool->
getLumi();
378 cd.m_cell_noise->noise[
cell][gain_state] = noise_tool->
larStorage()[(gain_state > 2 ? 0 : gain_state)][
cell];
386 cd.m_cell_noise->double_gaussian_constants[0][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 2);
387 cd.m_cell_noise->double_gaussian_constants[1][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 3);
388 cd.m_cell_noise->double_gaussian_constants[2][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 4);
389 cd.m_cell_noise->double_gaussian_constants[3][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 1);
396 cd.m_cell_noise->noise[
cell][gain_state] = 0;
410 time_cast(after_geo, after_noise),
411 time_cast(after_noise, after_send)
415 return StatusCode::SUCCESS;
424 print_times(
"Geometry Geometry_Correction Noise Transfer_to_GPU", 3 );
426 return StatusCode::SUCCESS;