26 ATH_MSG_DEBUG(
"Initializing device detector description provider service ");
37 std::map<Acts::GeometryIdentifier, Identifier> actsToAthena;
38 std::unordered_map<uint64_t, Identifier> detrayToAthenaMap;
39 std::unordered_map<Identifier, uint64_t> athenaToDetrayMap;
41 int nPix = 0, nStrip = 0, nEC = 0, nBar = 0;
42 std::vector<Acts::GeometryIdentifier> actsHGTD;
55 ATH_MSG_DEBUG(
"Could not find matching Acts detector element for surface with geometryId " << surface->geometryId());
63 ATH_MSG_VERBOSE(
"Found HGTD surface with geometryId " << surface->geometryId());
64 actsHGTD.push_back(surface->geometryId());
68 ATH_MSG_DEBUG(
"Found non-pixel, non-strip detector element with geometryId " << surface->geometryId());
73 ATH_MSG_DEBUG(
"Could not find matching Athena silicon detector element for surface with geometryId " << surface->geometryId());
85 thismod.
pixel =
false;
91 athenaID = detElem->identify();
97 std::vector<traccc::scalar> row_centres;
98 std::vector<traccc::scalar> column_centres;
107 for(
int row = 0; row < p_design->rows(); row++){
109 std::array<InDetDD::PixelDiodeTree::CellIndexType, 2>
113 p_design->diodeProxyFromIdxCachePosition(diode_idx));
115 (row_centres).push_back(si_param.
position()[0]-0.5*si_param.
width()[0]);
116 if(row == p_design->rows()-1){
117 (row_centres).push_back(si_param.
position()[0]+0.5*si_param.
width()[0]);
120 float leading_edge = si_param.
position()[0] - 0.5f*si_param.
width()[0];
121 float trailing_edge = si_param.
position()[0] + 0.5f*si_param.
width()[0];
122 float midpoint = (leading_edge + trailing_edge) / 2.f;
123 if(std::abs(midpoint - si_param.
position()[0]) > 1e-6f){
125 <<
" != geometry centre " << si_param.
position()[0]
126 <<
" (diff=" << midpoint - si_param.
position()[0] <<
")");
130 for(
int col = 0; col < p_design->columns(); col++){
132 std::array<InDetDD::PixelDiodeTree::CellIndexType, 2>
136 p_design->diodeProxyFromIdxCachePosition(diode_idx));
138 (column_centres).push_back(si_param.
position()[1]-0.5*si_param.
width()[1]);
139 if(col == p_design->columns()-1){
140 (column_centres).push_back(si_param.
position()[1]+0.5*si_param.
width()[1]);
143 float leading_edge = si_param.
position()[1] - 0.5f*si_param.
width()[1];
144 float trailing_edge = si_param.
position()[1] + 0.5f*si_param.
width()[1];
145 float midpoint = (leading_edge + trailing_edge) / 2.f;
146 if(std::abs(midpoint - si_param.
position()[1]) > 1e-6f){
147 ATH_MSG_ERROR(
"Column " << col <<
" edge midpoint " << midpoint
148 <<
" != geometry centre " << si_param.
position()[1]
149 <<
" (diff=" << midpoint - si_param.
position()[1] <<
")");
161 thismod.
rows = p_design->rows();
162 thismod.
columns = p_design->columns();
169 const int side =
m_stripID->side(detElem->identify());
170 athenaID =
m_stripID->wafer_id(moduleHash + side);
172 thismod.
pixel =
false;
176 if (
m_stripID->barrel_ec(athenaID) == 0) {
182 thismod.
rows = s_design->cells();
187 const double pitch_row = annulus_design->phiPitchPhi(annulus_cell);
188 const int nDiodes = annulus_design->diodesInRow(0.);
189 const double max_phi = nDiodes * pitch_row;
194 thismod.
rows = nDiodes;
206 const auto geo_id = surface->geometryId();
207 actsToAthena[
geo_id] = athenaID;
212 ATH_MSG_DEBUG(nStrip <<
" Atlas Strip modules found, " << nBar <<
" in barrel and " << nEC <<
" in the endcap");
218 int found_detray = 0;
219 int missing_detray = 0;
220 int missing_detray_passives = 0;
223 const auto& itkDetector = hostDetector->as<traccc::itk_detector>();
224 for (
const auto& surface : itkDetector.surfaces()) {
225 const auto geo_id = surface.source;
226 const Acts::GeometryIdentifier acts_geom_id{
geo_id};
227 auto sf = detray::tracking_surface{itkDetector, surface};
228 const auto detray_id = sf.identifier().value();
230 if (
auto pIdPair = actsToAthena.find(acts_geom_id); pIdPair != actsToAthena.end()) {
231 auto athena_id = pIdPair->second;
232 detrayToAthenaMap[detray_id] = athena_id;
233 athenaToDetrayMap[athena_id] = detray_id;
236 if (std::find(actsHGTD.begin(), actsHGTD.end(), acts_geom_id) != actsHGTD.end()) {
237 ATH_MSG_VERBOSE(
"ACTS surface with key " << acts_geom_id <<
" is HGTD, detray id: " << detray_id);
240 ATH_MSG_VERBOSE(
"ACTS surface with key " << acts_geom_id <<
" was not translated to detray geometry.");
242 if (surface.is_sensitive())
continue;
243 ATH_MSG_VERBOSE(
"found this passive surface in detray: " << acts_geom_id);
244 missing_detray_passives++;
248 ATH_MSG_DEBUG(
"Traccc detector has " << found_detray <<
" surfaces matching ACTS and " << missing_detray <<
" additional surfaces, out of which " << missing_detray_passives <<
" are not sensitive.");
253 std::map<designKey, unsigned int> designLookup;
254 unsigned int nextDesignId = 0;
256 const std::size_t nSurfaces = itkDetector.surfaces().size();
259 auto idMapping = std::make_unique<ActsTrk::GeometryIdMapping>();
260 idMapping->reserve(nSurfaces);
262 for (std::size_t condIndex = 0; condIndex < nSurfaces; ++condIndex) {
263 const auto& surface = itkDetector.surfaces()[condIndex];
264 if (!surface.is_sensitive()) {
265 ATH_MSG_VERBOSE(
"Skipping passive surface with geometryId " << surface.source);
268 const auto geo_id = surface.source;
269 const Acts::GeometryIdentifier acts_geom_id{
geo_id};
270 auto sf = detray::tracking_surface{itkDetector, surface};
271 const auto detray_id = sf.identifier().value();
274 entry.detrayGeometryId = detray::geometry::identifier{detray_id};
275 entry.actsGeometryId = acts_geom_id.value();
277 auto detrayIt = detrayToAthenaMap.find(detray_id);
278 std::optional<Identifier> athenaId;
279 if (detrayIt != detrayToAthenaMap.end()) {
280 athenaId = detrayIt->second;
285 const int nBinsX = thismod.
rows;
299 const auto [it, inserted] = designLookup.try_emplace(key, nextDesignId);
300 entry.designId = it->second;
301 if (inserted) ++nextDesignId;
303 entry.athenaId = *athenaId;
304 entry.hasAthenaModule =
true;
305 entry.isPixel = thismod.
pixel;
308 if (std::find(actsHGTD.begin(), actsHGTD.end(), acts_geom_id) != actsHGTD.end()) {
309 ATH_MSG_VERBOSE(
"ACTS surface with key " << acts_geom_id <<
" is HGTD, detray id: " << detray_id);
312 ATH_MSG_ERROR(
"Could not find matching Athena module for detray surface with geometryId " << detray_id);
313 return StatusCode::FAILURE;
316 idMapping->addEntry(detray_id, acts_geom_id.value(), athenaId);
318 idMapping->addDetDescIndex(detray_id,
static_cast<unsigned int>(condIndex));
324 auto hostDesign = std::make_unique<traccc::detector_design_description::host>(*
m_MRs->hostMR());
325 hostDesign->resize(designLookup.size());
326 for (
const auto& [key,
id] : designLookup) {
327 hostDesign->design_id()[id] =
static_cast<int>(id);
329 hostDesign->dimensions()[id] = key.pixel ? 2 : 1;
332 hostDesign->bin_edges_x()[id].assign(key.edgesX.begin(), key.edgesX.end());
333 hostDesign->bin_edges_y()[id].assign(key.edgesY.begin(), key.edgesY.end());
334 hostDesign->subspace()[id] = std::array<detray::dindex_type<traccc::default_algebra>, 2u>{0u, 1u};
336 hostDesign->bin_edges_y()[id].assign(key.edgesX.begin(), key.edgesX.end());
337 hostDesign->bin_edges_x()[id].assign(key.edgesY.begin(), key.edgesY.end());
338 hostDesign->subspace()[id] = std::array<detray::dindex_type<traccc::default_algebra>, 2u>{1u, 0u};
343 std::vector<unsigned int> designSizes(hostDesign->size());
344 for (std::size_t i = 0; i < hostDesign->size(); ++i) {
345 auto thisDesign = hostDesign->at(i);
346 designSizes[i] = std::max(
347 static_cast<unsigned int>(thisDesign.bin_edges_x().size()),
348 static_cast<unsigned int>(thisDesign.bin_edges_y().size()));
351 auto initCopy =
m_copy->copy(EventContext{});
352 auto deviceDesign = std::make_unique<traccc::detector_design_description::buffer>(
353 designSizes,
m_MRs->mainMR(),
m_MRs->hostMR(),
354 vecmem::data::buffer_type::resizable);
355 (*initCopy).setup(*deviceDesign)->wait();
356 (*initCopy)(vecmem::get_data(*hostDesign), *deviceDesign)->wait();
358 constexpr bool allowMods =
false;
363 auto deviceDetector = std::make_unique<traccc::detector_buffer>();
364 deviceDetector->set<traccc::itk_detector>(
365 detray::get_buffer(itkDetector,
m_MRs->mainMR(),
const_cast<vecmem::copy&
>(*initCopy)));
372 return StatusCode::FAILURE;
376 return StatusCode::SUCCESS;