37 m_hgtdHelper(nullptr),
38 m_setLayerAssociation(true),
39 m_identification(
"HGTD"),
44 m_runGeometryValidation(true)
46 declareInterface<Trk::ILayerBuilderCond>(
this);
76 return StatusCode::SUCCESS;
83 if (*readHandle==
nullptr) {
91 std::unique_ptr<const std::vector<Trk::DiscLayer*> >
95 ATH_MSG_DEBUG(
"calling HGTD_LayerBuilderCond::discLayers()" );
99 ATH_MSG_ERROR(
"HGTD Detector Manager or ID Helper could not be retrieved - giving up.");
105 if(*readHandle ==
nullptr){
111 InDetDD::HGTD_DetectorElementCollection::const_iterator hgtdDetIter = readCdo->begin();
117 for (; hgtdDetIter != readCdo->end(); ++hgtdDetIter){
118 Identifier currentId((*hgtdDetIter)->identify());
127 ATH_MSG_DEBUG(
"Configured to build " << nlayers <<
" *2 disc-like layers (+ additional support layers)." );
130 std::vector<float> discZpos(2*nlayers,0.);
131 std::vector< std::vector<Trk::SurfaceOrderPosition> > discSurfaces(2*nlayers, std::vector<Trk::SurfaceOrderPosition>());
134 int sumCheckhgtdModules = 0;
135 unsigned int currentlayer = 0;
140 hgtdDetIter = readCdo->begin();
141 for (; hgtdDetIter != readCdo->end(); ++hgtdDetIter){
144 if ( (*hgtdDetIter) ) {
146 Identifier currentId((*hgtdDetIter)->identify());
157 float currentZ = (*hgtdDetIter)->center().z();
161 currentlayer += currentZ > 0. ? nlayers : 0;
166 discZpos[currentlayer] = currentZ;
169 float currentRmin = (*hgtdDetIter)->rMin();
170 float currentRmax = (*hgtdDetIter)->rMax();
171 ATH_MSG_DEBUG(
" ---- rmin/rmax: " << currentRmin <<
"/" << currentRmax );
172 if (maxRmax<currentRmax)
173 maxRmax = currentRmax;
174 if (minRmin>currentRmin)
175 minRmin = currentRmin;
179 const Amg::Vector3D& orderPosition = (*hgtdDetIter)->center();
193 const_cast<Trk::Surface*
>(&((*hgtdDetIter)->surface())),
197 discSurfaces[currentlayer].push_back(surfaceOrder);
199 }
else if (!(*hgtdDetIter))
200 ATH_MSG_WARNING(
"Not valid pointer to HGTD Detector element... something wrong with the Id dictionary?");
208 auto discLayers = std::make_unique<std::vector<Trk::DiscLayer*> >();
213 for (
auto& thisDiscZpos : discZpos) {
218 ATH_MSG_DEBUG(
" -> With Rmin/Rmax (est) : " << minRmin <<
" / " << maxRmax );
222 std::vector<float> rBins = {minRmin};
223 std::vector<std::vector<float>> phiBins = {{}};
230 std::vector<Trk::BinUtility*>* subBinUtilitiesPhi =
new std::vector<Trk::BinUtility*>;
233 for (
unsigned int bin = 0;
bin < rBins.size()-1;
bin++) {
235 subBinUtilitiesPhi->push_back(BinUtilityY);
240 auto currentBinnedArray =
241 std::make_unique<Trk::BinnedArray1D1D<Trk::Surface>>(
242 discSurfaces[discCounter], BinUtilityR, subBinUtilitiesPhi);
246 int discSurfacesNum = (discSurfaces[discCounter]).
size();
248 ATH_MSG_DEBUG(
"Constructed BinnedArray for DiscLayer with "<< discSurfacesNum <<
" SubSurfaces." );
255 std::map< const Trk::Surface*,Amg::Vector3D > uniqueSurfaceMap;
259 size_t dsumCheckSurfaces = 0;
261 for (
const auto & asurfIter : arraySurfaces){
264 usmIter = uniqueSurfaceMap.find(asurfIter);
265 lastPhi = asurfIter->center().phi();
266 if (usmIter != uniqueSurfaceMap.end()) {
268 << asurfIter->center().eta() <<
" / "
269 << asurfIter->center().phi());
271 uniqueSurfaceMap[asurfIter] = asurfIter->center();
275 "valid phi value was = "
276 << lastPhi <<
" --> discCounter: " << discCounter);
279 sumCheckhgtdModules += dsumCheckSurfaces;
291 auto olDescriptor = std::make_unique<HGTD_OverlapDescriptor>(
292 currentBinnedArray.get(), rBins, phiBins);
300 std::move(currentBinnedArray),
303 std::move(olDescriptor));
312 ATH_MSG_DEBUG( hgtdModules <<
" HGTD Modules parsed for Disc Layer dimensions." );
314 ATH_MSG_DEBUG( sumCheckhgtdModules <<
" HGTD Modules filled in Disc Layer Arrays." );
315 if ( hgtdModules-sumCheckhgtdModules )
316 ATH_MSG_WARNING( hgtdModules-sumCheckhgtdModules <<
" Modules not registered properly in binned array." );
330 layerBinUtilityR += layerBinUtilityPhi;
338 for (
const auto & surfaces : layerSurfaces) {
341 (*surfaces).associateLayer(lay);
347 std::vector<float>& rBins,
float& maxRadius,
348 std::vector<std::vector<float>>& phiBins)
351 std::vector < std::pair< float, float> > centers = {};
352 centers.reserve(surfaces.size());
353 for (
auto& orderedSurface : surfaces) {
354 centers.emplace_back(orderedSurface.second.perp(), orderedSurface.second.phi());
358 std::sort(centers.begin(), centers.end(),
359 [](
const std::pair< float, float>&
a,
const std::pair< float, float>&
b) ->
bool {
360 return a.first < b.first;
368 std::vector<float> finerBinning = {};
369 finerBinning.reserve(
bins);
378 std::vector<int> phiIndices = {};
379 std::vector<float> tmpRadii = {};
381 for (
auto& center : centers) {
382 float phi = center.second;
383 const auto boundVal = std::lower_bound(finerBinning.begin(), finerBinning.end(),
phi);
387 if (
std::find(phiIndices.begin(), phiIndices.end(),
phiIndex)==phiIndices.end()) {
389 tmpRadii.push_back(center.first);
393 auto& prevRadius = tmpRadii.at(
index);
394 if ( std::abs(prevRadius - center.first)<1
e-5 ) {
395 const auto boundVal = std::lower_bound(finerBinning.begin(), finerBinning.end(),
phi);
400 float r = 0.5*(prevRadius+center.first);
402 tmpRadii = {prevRadius};
409 rBins.push_back(maxRadius);
413 std::vector< std::vector < float > > binnedCenters = {{}};
415 for (
auto& center : centers) {
416 float r = center.first;
417 float phi = center.second;
418 const auto boundVal = std::lower_bound(rBins.begin(), rBins.end(),
r);
420 if (
int(binnedCenters.size())<rIndex)
421 binnedCenters.push_back({
phi});
423 binnedCenters.back().push_back(
phi);
429 for (
auto& centersInBin : binnedCenters) {
431 std::sort(centersInBin.begin(), centersInBin.end());
433 phiBins.back().push_back(-
M_PI);
435 }
else phiBins.push_back({-
M_PI});
437 float phi = 0.5*(centersInBin.at(
index)+centersInBin.at(
index+1));
438 phiBins.back().push_back(
phi);