36 m_hgtdHelper(nullptr),
37 m_setLayerAssociation(true),
38 m_identification(
"HGTD"),
43 m_runGeometryValidation(true)
50 declareProperty(
"DiscMaterialBinsR" ,
m_rBins);
51 declareProperty(
"DiscMaterialBinsPhi" ,
m_phiBins);
74 return StatusCode::SUCCESS;
81 if (*readHandle==
nullptr) {
89 std::unique_ptr<const std::vector<Trk::DiscLayer*> >
93 ATH_MSG_DEBUG(
"calling HGTD_LayerBuilderCond::discLayers()" );
97 ATH_MSG_ERROR(
"HGTD Detector Manager or ID Helper could not be retrieved - giving up.");
103 if(*readHandle ==
nullptr){
115 for (; hgtdDetIter != readCdo->end(); ++hgtdDetIter){
116 Identifier currentId((*hgtdDetIter)->identify());
125 ATH_MSG_DEBUG(
"Configured to build " << nlayers <<
" *2 disc-like layers (+ additional support layers)." );
128 std::vector<float> discZpos(2*nlayers,0.);
129 std::vector< std::vector<Trk::SurfaceOrderPosition> > discSurfaces(2*nlayers, std::vector<Trk::SurfaceOrderPosition>());
132 int sumCheckhgtdModules = 0;
133 unsigned int currentlayer = 0;
138 hgtdDetIter = readCdo->begin();
139 for (; hgtdDetIter != readCdo->end(); ++hgtdDetIter){
142 if ( (*hgtdDetIter) ) {
144 Identifier currentId((*hgtdDetIter)->identify());
155 float currentZ = (*hgtdDetIter)->center().z();
159 currentlayer += currentZ > 0. ? nlayers : 0;
164 discZpos[currentlayer] = currentZ;
167 float currentRmin = (*hgtdDetIter)->rMin();
168 float currentRmax = (*hgtdDetIter)->rMax();
169 ATH_MSG_DEBUG(
" ---- rmin/rmax: " << currentRmin <<
"/" << currentRmax );
170 if (maxRmax<currentRmax)
171 maxRmax = currentRmax;
172 if (minRmin>currentRmin)
173 minRmin = currentRmin;
177 const Amg::Vector3D& orderPosition = (*hgtdDetIter)->center();
194 std::shared_ptr<Trk::Surface> sharedSurface(mutableSurace,[](
Trk::Surface*) {});
198 discSurfaces[currentlayer].push_back(surfaceOrder);
200 }
else if (!(*hgtdDetIter))
201 ATH_MSG_WARNING(
"Not valid pointer to HGTD Detector element... something wrong with the Id dictionary?");
209 auto discLayers = std::make_unique<std::vector<Trk::DiscLayer*> >();
214 for (
auto& thisDiscZpos : discZpos) {
219 ATH_MSG_DEBUG(
" -> With Rmin/Rmax (est) : " << minRmin <<
" / " << maxRmax );
223 std::vector<float> rBins = {minRmin};
224 std::vector<std::vector<float>> phiBins = {{}};
231 auto subBinUtilitiesPhi = std::vector<Trk::BinUtility>();
234 for (
unsigned int bin = 0;
bin < rBins.size()-1;
bin++) {
236 subBinUtilitiesPhi.push_back(BinUtilityY);
241 auto currentBinnedArray =
242 std::make_unique<Trk::BinnedArray1D1D<Trk::Surface>>(
243 discSurfaces[discCounter], BinUtilityR, subBinUtilitiesPhi);
247 int discSurfacesNum = (discSurfaces[discCounter]).
size();
249 ATH_MSG_DEBUG(
"Constructed BinnedArray for DiscLayer with "<< discSurfacesNum <<
" SubSurfaces." );
256 std::map< const Trk::Surface*,Amg::Vector3D > uniqueSurfaceMap;
259 std::span<Trk::Surface * const> arraySurfaces = currentBinnedArray->arrayObjects();
260 size_t dsumCheckSurfaces = 0;
262 for (
const auto & asurfIter : arraySurfaces){
265 usmIter = uniqueSurfaceMap.find(asurfIter);
266 lastPhi = asurfIter->center().phi();
267 if (usmIter != uniqueSurfaceMap.end()) {
269 << asurfIter->center().eta() <<
" / "
270 << asurfIter->center().phi());
272 uniqueSurfaceMap[asurfIter] = asurfIter->center();
276 "valid phi value was = "
277 << lastPhi <<
" --> discCounter: " << discCounter);
280 sumCheckhgtdModules += dsumCheckSurfaces;
290 auto activeLayerBounds = std::make_shared<Trk::DiscBounds>(minRmin, maxRmax);
292 auto olDescriptor = std::make_unique<HGTD_OverlapDescriptor>(
293 currentBinnedArray.get(), rBins, phiBins);
296 std::span<Trk::Surface * const> layerSurfaces = currentBinnedArray->arrayObjects();
301 std::move(currentBinnedArray),
304 std::move(olDescriptor));
313 ATH_MSG_DEBUG( hgtdModules <<
" HGTD Modules parsed for Disc Layer dimensions." );
315 ATH_MSG_DEBUG( sumCheckhgtdModules <<
" HGTD Modules filled in Disc Layer Arrays." );
316 if ( hgtdModules-sumCheckhgtdModules )
317 ATH_MSG_WARNING( hgtdModules-sumCheckhgtdModules <<
" Modules not registered properly in binned array." );
331 layerBinUtilityR += layerBinUtilityPhi;
339 for (
const auto & surfaces : layerSurfaces) {
342 (*surfaces).associateLayer(lay);
348 std::vector<float>& rBins,
float& maxRadius,
349 std::vector<std::vector<float>>& phiBins)
352 std::vector < std::pair< float, float> > centers = {};
353 centers.reserve(surfaces.size());
354 for (
auto& orderedSurface : surfaces) {
355 centers.emplace_back(orderedSurface.second.perp(), orderedSurface.second.phi());
359 std::sort(centers.begin(), centers.end(),
360 [](
const std::pair< float, float>&
a,
const std::pair< float, float>&
b) ->
bool {
361 return a.first < b.first;
369 std::vector<float> finerBinning = {};
370 finerBinning.reserve(
bins);
379 std::vector<int> phiIndices = {};
380 std::vector<float> tmpRadii = {};
382 for (
auto& center : centers) {
383 float phi = center.second;
384 const auto boundVal = std::lower_bound(finerBinning.begin(), finerBinning.end(),
phi);
388 if (
std::find(phiIndices.begin(), phiIndices.end(),
phiIndex)==phiIndices.end()) {
390 tmpRadii.push_back(center.first);
394 auto& prevRadius = tmpRadii.at(
index);
395 if ( std::abs(prevRadius - center.first)<1
e-5 ) {
396 const auto boundVal = std::lower_bound(finerBinning.begin(), finerBinning.end(),
phi);
401 float r = 0.5*(prevRadius+center.first);
403 tmpRadii = {prevRadius};
410 rBins.push_back(maxRadius);
414 std::vector< std::vector < float > > binnedCenters = {{}};
416 for (
auto& center : centers) {
417 float r = center.first;
418 float phi = center.second;
419 const auto boundVal = std::lower_bound(rBins.begin(), rBins.end(),
r);
421 if (
int(binnedCenters.size())<rIndex)
422 binnedCenters.push_back({
phi});
424 binnedCenters.back().push_back(
phi);
430 for (
auto& centersInBin : binnedCenters) {
432 std::sort(centersInBin.begin(), centersInBin.end());
434 phiBins.back().push_back(-
M_PI);
436 }
else phiBins.push_back({-
M_PI});
438 float phi = 0.5*(centersInBin.at(
index)+centersInBin.at(
index+1));
439 phiBins.back().push_back(
phi);