59 using clock_type = boost::chrono::thread_clock;
60 auto time_cast = [](
const auto & before,
const auto & after)
62 return boost::chrono::duration_cast<boost::chrono::microseconds>(after - before).count();
70 cd.m_geometry.allocate();
74 #if CALORECGPU_ETA_PHI_MAP_DEBUG
88 max_eta_pos[
i] = std::numeric_limits<float>::lowest();
90 max_eta_neg[
i] = std::numeric_limits<float>::lowest();
92 max_phi_pos[
i] = std::numeric_limits<float>::lowest();
94 max_phi_neg[
i] = std::numeric_limits<float>::lowest();
97 max_deta [
i] = std::numeric_limits<float>::lowest();
98 max_dphi [
i] = std::numeric_limits<float>::lowest();
103 max_dr [
i] = std::numeric_limits<float>::lowest();
104 max_dz [
i] = std::numeric_limits<float>::lowest();
106 cd.m_geometry->nCellsPerSampling[
i] = 0;
114 max_eta[
i] = std::numeric_limits<float>::lowest();
116 cd.m_geometry->nCellsPerSampling[
i] = 0;
124 const Identifier cell_identifier = calo_id->cell_id((IdentifierHash)
cell);
126 const int sampling = calo_id->calo_sample(cell_identifier);
127 const int intra_calo_sampling = calo_id->sampling(cell_identifier);
128 const int subcalo = caloElement->
getSubCalo();
129 const int region = calo_id->region(cell_identifier);
137 ConstantEnumConversion::from_intra_calorimeter_sampling_enum(intra_calo_sampling),
138 ConstantEnumConversion::from_subcalo_enum(subcalo),
139 ConstantEnumConversion::from_region_enum(region),
142 cd.m_geometry->x[
cell] = caloElement->
x();
143 cd.m_geometry->y[
cell] = caloElement->
y();
144 cd.m_geometry->z[
cell] = caloElement->
z();
145 cd.m_geometry->r[
cell] = caloElement->
r();
146 cd.m_geometry->eta[
cell] = caloElement->
eta();
147 cd.m_geometry->phi[
cell] = caloElement->
phi();
149 cd.m_geometry->dx[
cell] = caloElement->
dx();
150 cd.m_geometry->dy[
cell] = caloElement->
dy();
151 cd.m_geometry->dz[
cell] = caloElement->
dz();
152 cd.m_geometry->dr[
cell] = caloElement->
dr();
153 cd.m_geometry->deta[
cell] = caloElement->
deta();
154 cd.m_geometry->dphi[
cell] = caloElement->
dphi();
157 cd.m_geometry->neighbours.offsets[
cell] = 0;
159 #if CALORECGPU_ETA_PHI_MAP_DEBUG
160 const float eta_minus = caloElement->
eta() - caloElement->
deta() / 2;
161 const float eta_plus = caloElement->
eta() + caloElement->
deta() / 2;
162 const float phi_minus = caloElement->
phi() - caloElement->
dphi() / 2;
163 const float phi_plus = caloElement->
phi() + caloElement->
dphi() / 2;
165 if (caloElement->
eta() >= 0)
167 min_eta_pos[sampling] =
std::min({min_eta_pos[sampling], eta_minus, eta_plus});
168 min_phi_pos[sampling] =
std::min({min_phi_pos[sampling], phi_minus, phi_plus});
169 max_eta_pos[sampling] =
std::max({max_eta_pos[sampling], eta_minus, eta_plus});
170 max_phi_pos[sampling] =
std::max({max_phi_pos[sampling], phi_minus, phi_plus});
174 min_eta_neg[sampling] =
std::min({min_eta_neg[sampling], eta_minus, eta_plus});
175 min_phi_neg[sampling] =
std::min({min_phi_neg[sampling], phi_minus, phi_plus});
176 max_eta_neg[sampling] =
std::max({max_eta_neg[sampling], eta_minus, eta_plus});
177 max_phi_neg[sampling] =
std::max({max_phi_neg[sampling], phi_minus, phi_plus});
179 min_deta[sampling] =
std::min(min_deta[sampling], caloElement->
deta());
180 min_dphi[sampling] =
std::min(min_dphi[sampling], caloElement->
dphi());
181 max_deta[sampling] =
std::max(max_deta[sampling], caloElement->
deta());
182 max_dphi[sampling] =
std::max(max_dphi[sampling], caloElement->
dphi());
184 min_dz [sampling] =
std::min(min_dz [sampling], caloElement->
dz ());
185 max_dr [sampling] =
std::max(max_dr [sampling], caloElement->
dr ());
186 max_dz [sampling] =
std::max(max_dz [sampling], caloElement->
dz ());
188 avg_deta[sampling] += caloElement->
deta();
189 avg_dphi[sampling] += caloElement->
dphi();
191 const float eta_below = fabsf(caloElement->
eta() - caloElement->
deta() / 2);
192 const float eta_above = fabsf(caloElement->
eta() + caloElement->
deta() / 2);
197 cd.m_geometry->nCellsPerSampling[sampling] += 1;
204 #if CALORECGPU_ETA_PHI_MAP_DEBUG
205 avg_deta[
i] /=
cd.m_geometry->nCellsPerSampling[
i];
206 avg_dphi[
i] /=
cd.m_geometry->nCellsPerSampling[
i];
207 if (
cd.m_geometry->nCellsPerSampling[
i] > 0)
209 printf(
"CALORECGPU ETA PHI MAP DEBUG OUTPUT: %d | %f %f %f %f | %f %f %f %f | %f %f | %f %f | %f %f %d | %f %f | %f %f\n",
210 i, min_eta_neg[
i], min_phi_neg[
i], max_eta_neg[
i], max_phi_neg[
i],
211 min_eta_pos[
i], min_phi_pos[
i], max_eta_pos[
i], max_phi_pos[
i],
212 min_deta[
i], min_dphi[
i], max_deta[
i], max_dphi[
i],
213 avg_deta[
i], avg_dphi[
i],
cd.m_geometry->nCellsPerSampling[
i],
216 const float this_min_eta =
std::min(fabsf(max_eta_neg[
i]), fabsf(min_eta_pos[
i]));
217 const float this_max_eta =
std::max(fabsf(min_eta_neg[
i]), fabsf(max_eta_pos[
i]));
219 const float this_min_eta =
min_eta[
i];
220 const float this_max_eta =
max_eta[
i];
223 if (
cd.m_geometry->nCellsPerSampling[
i] <= 0)
225 cd.m_geometry->etaPhiToCell.initialize(
i, -1, 1);
230 cd.m_geometry->etaPhiToCell.initialize(
i, this_min_eta, this_max_eta);
234 cd.m_geometry->fill_eta_phi_map();
236 #if CALORECGPU_ETA_PHI_MAP_DEBUG
239 auto printer = [&](
const auto &
entry)
241 printf(
"CALORECGPU ETA PHI MAP DEBUG OUTPUT: %d | %d\n",
i,
entry.get_max_real_overlap());
244 cd.m_geometry->etaPhiToCell.apply_to_sampling(
i, printer);
250 std::vector<IdentifierHash> neighbour_vector, full_neighs, prev_neighs;
254 for (
int neigh_bit_set = 0; neigh_bit_set <
NumNeighOptions; ++neigh_bit_set)
256 const unsigned int curr_neigh_opt = (1U << neigh_bit_set);
268 calo_id->get_neighbours((IdentifierHash)
cell,
274 calo_id->get_neighbours((IdentifierHash)
cell,
277 calo_id->get_neighbours((IdentifierHash)
cell,
285 std::sort(neighbour_vector.begin(), neighbour_vector.end());
286 std::sort(prev_neighs.begin(), prev_neighs.end());
290 std::set_difference( prev_neighs.begin(), prev_neighs.end(),
291 neighbour_vector.begin(), neighbour_vector.end(),
292 std::back_inserter(full_neighs) );
296 prev_neighs.resize(
cd.m_geometry->neighbours.get_total_number_of_neighbours(
cell));
299 for (
size_t neigh = 0; neigh < prev_neighs.size(); ++neigh)
301 prev_neighs[neigh] =
cd.m_geometry->neighbours.get_neighbour(
cell, neigh);
304 std::sort(full_neighs.begin(), full_neighs.end());
305 std::sort(prev_neighs.begin(), prev_neighs.end());
307 neighbour_vector.clear();
309 std::set_difference( full_neighs.begin(), full_neighs.end(),
310 prev_neighs.begin(), prev_neighs.end(),
311 std::back_inserter(neighbour_vector) );
318 std::sort(neighbour_vector.begin(), neighbour_vector.end());
320 const int neighs_start =
cd.m_geometry->neighbours.get_total_number_of_neighbours(
cell);
322 for (
size_t neigh_num = 0; neigh_num < neighbour_vector.size(); ++neigh_num)
324 cd.m_geometry->neighbours.set_neighbour(
cell, neighs_start + neigh_num, neighbour_vector[neigh_num]);
327 cd.m_geometry->neighbours.offsets[
cell] += NeighOffset::offset_delta(neigh_bit_set) * neighbour_vector.size();
332 #if CALORECGPU_ADD_FULL_PAIRS_LIST_TO_CONSTANT_INFORMATION
341 auto add_neighbours = [&](
const int cell,
const unsigned int curr_neigh_opt)
345 const int num_neighs =
cd.m_geometry->neighbours.get_neighbours(curr_neigh_opt,
cell, neighbours);
347 for (
int neigh = 0; neigh < num_neighs; ++neigh)
349 cd.m_geometry->neighPairs.cell_A[num_pairs] =
cell;
350 cd.m_geometry->neighPairs.cell_B[num_pairs] = neighbours[neigh];
355 for (
int neigh_bit_set = 0; neigh_bit_set <
NumNeighOptions; ++neigh_bit_set)
357 const unsigned int curr_neigh_opt = (1U << neigh_bit_set);
361 if (
cd.m_geometry->is_PS(
cell) ||
cd.m_geometry->is_HECIW_or_FCal(
cell))
366 add_neighbours(
cell, curr_neigh_opt);
373 if (!
cd.m_geometry->is_PS(
cell))
378 add_neighbours(
cell, curr_neigh_opt);
385 if (!
cd.m_geometry->is_HECIW_or_FCal(
cell))
390 add_neighbours(
cell, curr_neigh_opt);
432 const CaloNoise * noise_tool = *noise_handle;
434 IdentifierHash t_start, t_end;
448 cd.m_cell_noise.allocate();
452 cd.m_cell_noise->noise_properties = CellNoiseProperties::invalid_value();
459 cd.m_cell_noise->luminosity = noise_tool->
getLumi();
465 cd.m_cell_noise->noise[
cell][gain_state] = noise_tool->
larStorage()[(gain_state > 2 ? 0 : gain_state)][
cell];
473 cd.m_cell_noise->double_gaussian_constants[0][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 2);
474 cd.m_cell_noise->double_gaussian_constants[1][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 3);
475 cd.m_cell_noise->double_gaussian_constants[2][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 4);
476 cd.m_cell_noise->double_gaussian_constants[3][
cell - t_start][gain_state] =
blob->getData(
cell - t_start, gain_state, 1);
483 cd.m_cell_noise->noise[
cell][gain_state] = 0;
497 time_cast(
start, after_geo),
498 time_cast(after_geo, after_eta_phi),
499 time_cast(after_eta_phi, after_pairs),
500 time_cast(after_pairs, after_noise),
501 time_cast(after_noise, after_send)
505 return StatusCode::SUCCESS;