63 return StatusCode::SUCCESS;
71 return StatusCode::SUCCESS;
74 std::unique_ptr<std::vector< Trk::DiscLayer*> >
78 unsigned int endcapLayers = 0;
87 ATH_MSG_DEBUG(
"Configured to build " << endcapLayers <<
" *2 disc-like layers (+ additional support layers)." );
90 std::vector<double> discZmin(2*endcapLayers,10e10);
91 std::vector<double> discZmax(2*endcapLayers,-10e10);
92 std::vector<double> discZpos(2*endcapLayers,0.);
93 std::vector<double> discRmin(2*endcapLayers,10e10);
94 std::vector<double> discRmax(2*endcapLayers,0);
95 std::vector<double> discThickness(2*endcapLayers,0.);
96 std::vector<int> discPhiSectors(2*endcapLayers,-1);
97 std::vector<double> discPhiMin(2*endcapLayers,10e10);
98 std::vector<double> discPhiMax(2*endcapLayers,-10e10);
99 std::vector< std::vector<Trk::SurfaceOrderPosition> > discSurfaces(2*endcapLayers, std::vector<Trk::SurfaceOrderPosition>());
102 std::map< double, int> discZposLayerIndex;
104 int endcapModules = 0;
105 int sumCheckEndcapModules = 0;
106 unsigned int currentdisk = 0;
107 unsigned int currentring = 0;
108 unsigned int currentlayer = 0;
112 const InDetDD::SiDetectorElementCollection::const_iterator sidetBegin = siDetElementCollection.begin();
113 const InDetDD::SiDetectorElementCollection::const_iterator sidetEnd = siDetElementCollection.end();
114 InDetDD::SiDetectorElementCollection::const_iterator sidetIter = sidetBegin;
115 for (; sidetIter != sidetEnd; ++sidetIter){
119 if ( (*sidetIter) && (*sidetIter)->isEndcap() ){
121 Identifier currentId((*sidetIter)->identify());
126 double currentZ = (*sidetIter)->center().z();
128 currentlayer = currentdisk;
129 for (
unsigned int i = 0;
i < currentring;
i++) {
137 currentlayer += currentZ > 0. ? endcapLayers : 0;
145 double currentRmin = (*sidetIter)->rMin();
146 double currentRmax = (*sidetIter)->rMax();
149 double currentPhi = (*sidetIter)->center().phi();
151 takeBigger( discRmax[currentlayer],currentRmax);
154 if (discPhiSectors[currentlayer]<0){
155 ATH_MSG_VERBOSE(
"Pre-processing Elements from Disk/Layer (id from idHelper): " << currentring <<
"/" << currentdisk );
159 discPhiSectors[currentlayer]=phiSectorsRing;
164 takeBigger(discPhiMax[currentlayer],currentPhi);
183 Trk::do_not_delete<Trk::Surface>);
185 discSurfaces[currentlayer].push_back(surfaceOrder);
187 }
else if (!(*sidetIter))
188 ATH_MSG_WARNING(
"nullptr to Endcap module given by SCT_DetectorManager! Please check db & dict.xml");
191 ATH_MSG_VERBOSE(
"Estimating the average z position and the radius for each disk.");
193 for (
unsigned int iec=0; iec<2*endcapLayers; ++iec){
195 discZpos[iec] = 0.5 * (discZmin[iec] + discZmax[iec]);
196 discThickness[iec] = std::abs(discZmax[iec]-discZmin[iec]);
198 discZposLayerIndex.insert(std::make_pair(discZpos[iec],iec));
203 auto discLayers = std::make_unique<std::vector< Trk::DiscLayer*> >();
207 for ( ; discZposIter != discZpos.end(); ++discZposIter){
212 ATH_MSG_DEBUG(
"Building a DiscLayer with single R sectors. " );
213 ATH_MSG_DEBUG(
" -> At Z - Position : " << discZpos[discCounter] );
215 ATH_MSG_DEBUG(
" -> With Rmin/Rmax (est) : " << discRmin[discCounter] <<
" / " << discRmax[discCounter] );
218 std::unique_ptr<Trk::BinnedArray<Trk::Surface>> currentBinnedArray =
nullptr;
220 double halfPhiStep =
M_PI/discPhiSectors[discCounter];
222 if (std::abs(discPhiMin[discCounter]+discPhiMax[discCounter])< halfPhiStep && std::abs(discPhiMin[discCounter]) < 0.5*halfPhiStep ){
223 ATH_MSG_VERBOSE(
"Detected module fluctuation around +/- M_PI, correcting for it.");
224 ATH_MSG_VERBOSE(
" [0 - ] min phi / max phi detected : " << discPhiMin[discCounter] <<
" / " <<discPhiMax[discCounter]);
225 discPhiMin[discCounter] += 2*halfPhiStep;
229 ATH_MSG_VERBOSE(
" [1 - ] min phi / max phi detected : " << discPhiMin[discCounter] <<
" / " << discPhiMax[discCounter] );
230 double minPhiCorrected = discPhiMin[discCounter]-halfPhiStep;
231 double maxPhiCorrected = discPhiMax[discCounter]+halfPhiStep;
233 if (minPhiCorrected < -
M_PI){
234 minPhiCorrected += 2*halfPhiStep;
235 maxPhiCorrected += 2*halfPhiStep;
238 ATH_MSG_VERBOSE(
" min phi / max phi corrected : " << minPhiCorrected <<
" / " << maxPhiCorrected );
239 ATH_MSG_VERBOSE(
"Constructing a one-dimensional BinnedArray with phiMin / phiMax (bins) = "
240 << minPhiCorrected <<
" / " << maxPhiCorrected
241 <<
" (" << discPhiSectors[discCounter] <<
")");
250 currentBinnedArray = std::make_unique<Trk::BinnedArray1D<Trk::Surface>>(discSurfaces[discCounter],currentBinUtility);
252 int discSurfacesNum = (discSurfaces[discCounter]).
size();
253 ATH_MSG_DEBUG(
"Constructed BinnedArray for DiscLayer with "<< discSurfacesNum <<
" SubSurfaces." );
260 std::map< Trk::Surface*,Amg::Vector3D > uniqueSurfaceMap;
264 size_t dsumCheckSurfaces = 0;
266 for (
const auto & asurfIter : arraySurfaces){
269 usmIter = uniqueSurfaceMap.find(asurfIter);
270 lastPhi = asurfIter->center().phi();
271 if ( usmIter != uniqueSurfaceMap.end() )
272 ATH_MSG_WARNING(
"Non-unique surface found with eta/phi = " << asurfIter->center().eta() <<
" / " << asurfIter->center().phi());
273 else uniqueSurfaceMap[asurfIter] = asurfIter->center();
275 ATH_MSG_WARNING(
"Zero-pointer in array detected in this ring, last valid phi value was = " << lastPhi);
277 sumCheckEndcapModules += dsumCheckSurfaces;
279 ATH_MSG_DEBUG(
" -> With Rmin/Rmax : " << discRmin[discCounter] <<
" / " << discRmax[discCounter] );
289 std::vector<Trk::BinUtility*>* binUtils =
new std::vector<Trk::BinUtility*>;
291 auto olDescriptor = std::make_unique<InDet::DiscOverlapDescriptor>(currentBinnedArray.get(), binUtils,
true);
296 activeLayerTransform, activeLayerBounds, std::move(currentBinnedArray),
297 layerMaterial, thickness, std::move(olDescriptor));
301 discLayers->push_back(activeLayer);
306 ATH_MSG_DEBUG( endcapModules <<
" Endcap Modules parsed for Disc Layer dimensions." );
307 ATH_MSG_DEBUG( sumCheckEndcapModules <<
" Endcap Modules filled in Disc Layer Arrays." );
308 if ( endcapModules-sumCheckEndcapModules )
309 ATH_MSG_WARNING( endcapModules-sumCheckEndcapModules <<
" Modules not registered properly in binned array." );
316 std::sort(sortIter, sortEnd, zSorter);
325 sortIter = discLayers->begin();
326 sortEnd = discLayers->end();
328 double lastRmin = 0.;
329 double lastRmax = 0.;
331 for ( ; sortIter != sortEnd || addLayerIter != addLayerIterEnd; ){
333 double layerRmin = lastRmin;
334 double layerRmax = lastRmax;
335 double layerZposition = 0.;
337 if ( sortIter != sortEnd){
339 layerZposition = (*sortIter)->surfaceRepresentation().center().z();
342 lastRmin = currentBounds ? currentBounds->
rMin() : 0.;
343 lastRmax = currentBounds ? currentBounds->
rMax() : 0.;
346 if ( addLayerIter != addLayerIterEnd){
348 double rMin = layerZposition > 0. ? layerRmin : lastRmin;
349 double rMax = layerZposition > 0. ? layerRmax : lastRmax;
354 if (*addLayerTypeIter) {
355 ATH_MSG_DEBUG(
"Building an additional DiscLayer w/o sensitive modules at");
360 passiveLayerMaterial,
368 ATH_MSG_DEBUG(
" -> With Rmin/Rmax (corr) : " << rMin <<
" / " << rMax );
372 discLayers->push_back(passiveLayer);
377 sortIter = discLayers->begin();
378 sortEnd = discLayers->end();
379 std::sort(sortIter, sortEnd, zSorter);
382 ATH_MSG_DEBUG(
"Returning: " << discLayers->size() <<
" disk-like layers to the volume builder");
383 for (
const auto&
dl : (*discLayers)){
384 ATH_MSG_VERBOSE(
" ----> Disk layer located at : " <<
dl->surfaceRepresentation().center().z());
391 std::unique_ptr<std::vector< Trk::DiscLayer*> >
395 bool isDBM = (discLayers!=
nullptr);
398 unsigned int endcapLayers = 0;
401 ATH_MSG_DEBUG(
"Configured to build " << endcapLayers <<
"*2 disc-like DBM layers" );
405 ATH_MSG_DEBUG(
"Configured to build " << endcapLayers <<
" *2 disc-like layers (+ additional support layers)." );
409 std::vector<double> discZmin(2*endcapLayers,10e10);
410 std::vector<double> discZmax(2*endcapLayers,-10e10);
411 std::vector<double> discZpos(2*endcapLayers,0.);
412 std::vector<double> discRmin(2*endcapLayers,10e10);
413 std::vector<double> discRmax(2*endcapLayers,0);
414 std::vector<double> discThickness(2*endcapLayers,0.);
416 std::vector< std::vector<Trk::SurfaceOrderPosition> > discSurfaces;
417 std::vector< std::vector<int> > discPhiSectors;
418 std::vector< std::vector<double> > discPhiMin;
419 std::vector< std::vector<double> > discPhiMax;
420 std::vector< std::vector<double> > discRingMinR;
421 std::vector< std::vector<double> > discRingMaxR;
424 std::map< double, int> discZposLayerIndex;
427 discPhiMin.reserve(2*endcapLayers);
428 discPhiMax.reserve(2*endcapLayers);
429 discPhiSectors.reserve(2*endcapLayers);
430 discSurfaces.reserve(2*endcapLayers);
431 discRingMinR.reserve(2*endcapLayers);
432 discRingMaxR.reserve(2*endcapLayers);
435 for (
unsigned int endcap=0; endcap<2*endcapLayers; endcap++){
436 discPhiMin.emplace_back();
437 discPhiMax.emplace_back();
438 discPhiSectors.emplace_back();
439 discSurfaces.emplace_back( );
441 discRingMinR.emplace_back();
442 discRingMaxR.emplace_back();
445 int endcapModules = 0;
446 int sumCheckEndcapModules = 0;
447 unsigned int currentlayer = 0;
448 unsigned int currentdisk = 0;
449 unsigned int currentring = 0;
453 const InDetDD::SiDetectorElementCollection::const_iterator sidetBegin = siDetElementCollection.begin();
454 const InDetDD::SiDetectorElementCollection::const_iterator sidetEnd = siDetElementCollection.end();
455 InDetDD::SiDetectorElementCollection::const_iterator sidetIter = sidetBegin;
456 for (; sidetIter != sidetEnd; ++sidetIter){
461 if ( (*sidetIter) && ( (!
isDBM && (*sidetIter)->isEndcap()) || (
isDBM && (*sidetIter)->isDBM())) ){
466 double currentZ = (*sidetIter)->center().z();
468 Identifier currentId((*sidetIter)->identify());
470 currentlayer = currentdisk;
471 currentlayer += currentZ > 0. ? endcapLayers : 0;
479 double currentRmin = (*sidetIter)->rMin();
480 double currentRmax = (*sidetIter)->rMax();
483 unsigned int diskRings =
isDBM ?
488 double currentPhi = (*sidetIter)->center().phi();
490 takeBigger( discRmax[currentlayer],currentRmax);
493 if (discPhiSectors[currentlayer].
empty()){
494 ATH_MSG_VERBOSE(
"Pre-processing Elements from Disk/Layer (id from idHelper): " << currentdisk <<
"/" << currentlayer );
496 discPhiMin[currentlayer] = std::vector<double>(diskRings,100.);
497 discPhiMax[currentlayer] = std::vector<double>(diskRings,-100.);
498 discRingMinR[currentlayer] = std::vector<double>(diskRings,1e10);
499 discRingMaxR[currentlayer] = std::vector<double>(diskRings,0);
501 ATH_MSG_VERBOSE(
"-> The current disk has " << diskRings <<
" ring(s)");
502 for (
unsigned int iring=0; iring < diskRings; ++iring){
503 unsigned int phiSectorsRing =
isDBM ?
507 ATH_MSG_VERBOSE(
"--> Ring " << iring <<
" has " << phiSectorsRing <<
" phi sectors");
508 discPhiSectors[currentlayer].push_back(phiSectorsRing);
512 if ( !(*sidetIter)->otherSide() || std::abs(currentZ) < std::abs((*sidetIter)->otherSide()->center().z())){
514 takeSmaller(discPhiMin[currentlayer][currentring],currentPhi);
515 takeBigger(discPhiMax[currentlayer][currentring],currentPhi);
517 takeSmaller(discRingMinR[currentlayer][currentring],currentRmin);
518 takeBigger(discRingMaxR[currentlayer][currentring],currentRmax);
520 }
else if (!(*sidetIter))
521 ATH_MSG_WARNING(
"nullptr to Endcap module given by SCT_DetectorManager! Please check db & dict.xml");
524 double minRmin = 10e10;
525 double maxRmax = -10e10;
527 ATH_MSG_VERBOSE(
"Estimating the average z position and the radius for each disk.");
529 for (
unsigned int iec=0; iec<2*endcapLayers; ++iec){
532 discZpos[iec] = 0.5 * (discZmin[iec] + discZmax[iec]);
533 discThickness[iec] =
isDBM ? 1. : std::abs(discZmax[iec]-discZmin[iec]);
535 discZposLayerIndex.insert(std::make_pair(discZpos[iec],iec));
540 sidetIter = sidetBegin;
541 for (; sidetIter != sidetEnd; ++sidetIter){
543 if ( ((*sidetIter) && ((!
isDBM && (*sidetIter)->isEndcap()) || (
isDBM && (*sidetIter)->isDBM()))) ){
545 Identifier currentId((*sidetIter)->identify());
547 currentlayer = currentdisk;
548 currentlayer += (*sidetIter)->center().z() > 0. ? endcapLayers : 0;
551 bool takeIt = (!otherSide || std::abs((*sidetIter)->center().z()) < std::abs(otherSide->
center().z()) );
572 if (takeIt) (discSurfaces[currentlayer]).push_back(surfaceOrder);
579 discLayers = std::make_unique<std::vector< Trk::DiscLayer* > >();
584 for ( ; discZposIter != discZpos.end(); ++discZposIter){
586 size_t discRsectors = (discPhiSectors[discCounter]).
size();
590 std::vector<double> discRingMinRcopy = discRingMinR[discCounter];
591 std::sort(discRingMinRcopy.begin(), discRingMinRcopy.end());
592 bool reverseRsectors = !(discRingMinRcopy == discRingMinR[discCounter]);
595 if (reverseRsectors){
596 ATH_MSG_VERBOSE(
"Auto-detect: rings in R are in " << ( reverseRsectors ?
"reversed" :
"standard") <<
" order.");
603 std::vector<float> discRboundaries;
604 discRboundaries.push_back(
float(*discRingMinRcopy.begin()));
605 for (
double & ringMaxRIter : discRingMaxR[discCounter])
606 discRboundaries.push_back(
float(ringMaxRIter));
609 ATH_MSG_DEBUG(
"Building a DiscLayer with " << discRsectors <<
" R sectors. " );
610 ATH_MSG_DEBUG(
" -> At Z - Position : " << discZpos[discCounter] );
612 ATH_MSG_DEBUG(
" -> With Rmin/Rmax (est) : " << discRmin[discCounter] <<
" / " << discRmax[discCounter] );
615 for (
size_t irings=0; irings<discRsectors; ++irings)
616 ATH_MSG_DEBUG(
" --> " << irings <<
" R sector has " << discPhiSectors[discCounter][irings] <<
" phi sectors. " );
619 std::unique_ptr<Trk::BinnedArray<Trk::Surface>> currentBinnedArray =
nullptr;
620 std::vector<Trk::BinUtility*>* singleBinUtils =
new std::vector<Trk::BinUtility*>;
621 bool weOwnSingleBinUtils{
true};
622 if (discRsectors==1){
623 double halfPhiStep =
M_PI/discPhiSectors[discCounter][0];
625 if (std::abs(discPhiMin[discCounter][0]+discPhiMax[discCounter][0])< halfPhiStep && std::abs(discPhiMin[discCounter][0]) < 0.5*halfPhiStep ){
626 ATH_MSG_VERBOSE(
"Detected module fluctuation around +/- M_PI, correcting for it.");
627 ATH_MSG_VERBOSE(
" min phi / max phi detected : " << discPhiMin[discCounter][0] <<
" / " <<discPhiMax[discCounter][0] );
628 discPhiMin[discCounter][0] += 2*halfPhiStep;
631 ATH_MSG_VERBOSE(
" min phi / max phi detected : " << discPhiMin[discCounter][0] <<
" / " << discPhiMax[discCounter][0] );
632 double minPhiCorrected = discPhiMin[discCounter][0]-halfPhiStep;
633 double maxPhiCorrected = discPhiMax[discCounter][0]+halfPhiStep;
635 if (minPhiCorrected < -
M_PI){
636 minPhiCorrected += 2*halfPhiStep;
637 maxPhiCorrected += 2*halfPhiStep;
639 ATH_MSG_VERBOSE(
" min phi / max phi corrected : " << minPhiCorrected <<
" / " << maxPhiCorrected );
641 ATH_MSG_VERBOSE(
"Constructing a one-dimensional BinnedArray with phiMin / phiMax (bins) = "
642 << minPhiCorrected <<
" / " << maxPhiCorrected
643 <<
" (" << discPhiSectors[discCounter][0] <<
")");
651 currentBinnedArray = std::make_unique<Trk::BinnedArray1D<Trk::Surface>>(discSurfaces[discCounter],currentBinUtility);
665 discRmin[discCounter],
666 discRmax[discCounter],
669 ATH_MSG_VERBOSE(
"Steering bin utility constructed as : " << *currentSteerBinUtility);
672 singleBinUtils->reserve(discRsectors);
673 for (
size_t irings=0; irings < discRsectors; ++irings){
674 double halfPhiStep =
M_PI/discPhiSectors[discCounter][irings];
675 ATH_MSG_VERBOSE(
" min phi / max phi detected : " << discPhiMin[discCounter][irings] <<
" / " << discPhiMax[discCounter][irings] );
676 double minPhiCorrected = discPhiMin[discCounter][irings]-halfPhiStep;
677 double maxPhiCorrected = discPhiMax[discCounter][irings]+halfPhiStep;
679 if (minPhiCorrected < -
M_PI){
680 minPhiCorrected += 2*halfPhiStep;
681 maxPhiCorrected += 2*halfPhiStep;
683 ATH_MSG_VERBOSE(
" min phi / max phi corrected : " << minPhiCorrected <<
" / " << maxPhiCorrected );
684 ATH_MSG_VERBOSE(
"Constructing for ring " << irings <<
" phi utility with phiMin / phiMax (bins) = "
685 << minPhiCorrected <<
" / " << maxPhiCorrected <<
" (" << discPhiSectors[discCounter][irings] <<
")") ;
686 singleBinUtils->push_back(
new Trk::BinUtility(discPhiSectors[discCounter][irings],
693 weOwnSingleBinUtils =
false;
695 std::make_unique<Trk::BinnedArray1D1D<Trk::Surface>>(
696 discSurfaces[discCounter], currentSteerBinUtility,
700 int discSurfacesNum = (discSurfaces[discCounter]).
size();
701 ATH_MSG_DEBUG(
"Constructed BinnedArray for DiscLayer with "<< discSurfacesNum <<
" SubSurfaces." );
708 std::map< const Trk::Surface*,Amg::Vector3D > uniqueSurfaceMap;
712 size_t dsumCheckSurfaces = 0;
714 for (
const auto & asurfIter : arraySurfaces){
717 usmIter = uniqueSurfaceMap.find(asurfIter);
718 lastPhi = asurfIter->center().phi();
719 if ( usmIter != uniqueSurfaceMap.end() )
720 ATH_MSG_WARNING(
"Non-unique surface found with eta/phi = " << asurfIter->center().eta() <<
" / " << asurfIter->center().phi());
721 else uniqueSurfaceMap[asurfIter] = asurfIter->center();
723 ATH_MSG_WARNING(
"Zero-pointer in array detected in this ring, last valid phi value was = " << lastPhi);
725 sumCheckEndcapModules += dsumCheckSurfaces;
727 ATH_MSG_DEBUG(
" -> With Rmin/Rmax (corr) : " << minRmin <<
" / " << maxRmax );
738 std::unique_ptr<Trk::OverlapDescriptor> olDescriptor =
nullptr;
740 olDescriptor = std::make_unique<InDet::PixelOverlapDescriptor>();
742 std::vector<Trk::BinUtility*>* binUtils =
743 new std::vector<Trk::BinUtility*>;
744 if (singleBinUtils) {
746 singleBinUtils->begin();
747 for (; binIter != singleBinUtils->end(); ++binIter) {
748 binUtils->push_back((*binIter)->clone());
755 std::make_unique<InDet::DiscOverlapDescriptor>(currentBinnedArray.get(), binUtils);
764 std::move(currentBinnedArray), layerMaterial,
765 thickness, std::move(olDescriptor));
767 discLayers->push_back(activeLayer);
770 if (weOwnSingleBinUtils){
771 delete singleBinUtils;
772 singleBinUtils=
nullptr;
778 ATH_MSG_DEBUG( endcapModules <<
" Endcap Modules parsed for Disc Layer dimensions." );
779 ATH_MSG_DEBUG( sumCheckEndcapModules <<
" Endcap Modules filled in Disc Layer Arrays." );
780 if ( endcapModules-sumCheckEndcapModules )
781 ATH_MSG_WARNING( endcapModules-sumCheckEndcapModules <<
" Modules not registered properly in binned array." );
788 std::sort(sortIter, sortEnd, zSorter);
797 sortIter = discLayers->begin();
798 sortEnd = discLayers->end();
800 double lastRmin = 0.;
801 double lastRmax = 0.;
803 for ( ; sortIter != sortEnd || addLayerIter != addLayerIterEnd; ){
805 double layerRmin = lastRmin;
806 double layerRmax = lastRmax;
807 double layerZposition = 0.;
809 if ( sortIter != sortEnd){
811 layerZposition = (*sortIter)->surfaceRepresentation().center().z();
814 lastRmin = currentBounds ? currentBounds->
rMin() : 0.;
815 lastRmax = currentBounds ? currentBounds->
rMax() : 0.;
818 if ( addLayerIter != addLayerIterEnd){
820 double rMin = layerZposition > 0. ? layerRmin : lastRmin;
821 double rMax = layerZposition > 0. ? layerRmax : lastRmax;
827 if (*addLayerTypeIter) {
829 "Building an additional DiscLayer w/o sensitive modules at");
836 passiveLayerMaterial,
842 ATH_MSG_DEBUG(
" -> With Rmin/Rmax (corr) : " << rMin <<
" / " << rMax );
846 discLayers->push_back(passiveLayer);
851 sortIter = discLayers->begin();
852 sortEnd = discLayers->end();
853 std::sort(sortIter, sortEnd, zSorter);
860 std::unique_ptr<const std::vector<Trk::CylinderLayer*> >
865 ATH_MSG_ERROR(
"Neither Pixel nor SCT Detector Manager or ID Helper could be retrieved - giving up.");
873 size_t barrelLayers = 0;
876 if (siNumerology.
useLayer(
i)) barrelLayers++;
882 ATH_MSG_DEBUG(
"Configured to build " << barrelLayers <<
" (active) barrel layers (out of " << siNumerology.
numLayers() <<
" )" );
887 std::vector<double> layerRadius(barrelLayers,0.);
888 std::vector<double> layerRmin(barrelLayers,10e10);
889 std::vector<double> layerRmax(barrelLayers,0.);
890 std::vector<double> layerThickness(barrelLayers,0.);
891 std::vector<double> layerMinZ(barrelLayers,0.);
892 std::vector<double> layerMaxZ(barrelLayers,0.);
893 std::vector<double> layerHalfLength(barrelLayers,0.);
894 std::vector<double> layerMinPhi(barrelLayers,0.);
895 std::vector<double> layerMaxPhi(barrelLayers,0.);
896 std::vector<size_t> layerPhiSectors(barrelLayers,0);
897 std::vector<size_t> layerZsectors(barrelLayers,0);
898 std::vector< std::vector<float> > layerZboundaries(barrelLayers, std::vector<float>());
899 std::vector< std::vector< Trk::SurfaceOrderPosition > > layerSurfaces(barrelLayers, std::vector< Trk::SurfaceOrderPosition >());
902 double minHalflengthZ = 10e10;
903 double maxHalflengthZ = 0;
904 size_t sumCheckBarrelModules = 0;
905 size_t barrelModules = 0;
909 const InDetDD::SiDetectorElementCollection::const_iterator sidetBegin = siDetElementCollection.begin();
910 const InDetDD::SiDetectorElementCollection::const_iterator sidetEnd = siDetElementCollection.end();
911 InDetDD::SiDetectorElementCollection::const_iterator sidetIter = sidetBegin;
912 for (; sidetIter != sidetEnd; ++sidetIter){
914 if ((*sidetIter) && (*sidetIter)->isBarrel()){
916 Identifier currentId((*sidetIter)->identify());
931 if (layerPhiSectors[currentlayer] == 0){
932 ATH_MSG_VERBOSE(
"Pre-processing Elements from Layer (id from idHelper): " << currentlayer );
940 double lastModuleZ = 0.;
941 std::vector<float> zboundaries;
942 zboundaries.reserve(layerZsectors[currentlayer]+1);
946 layerMinZ[currentlayer] = countPtr->
center().z() - 0.5*std::abs(countPtr->
length());
947 zboundaries.push_back(layerMinZ[currentlayer]);
948 lastModuleZ = countPtr->
center().z();
954 double currentModuleZ = countPtr->
center().z();
955 double currentZboundary = 0.5*(lastModuleZ+currentModuleZ);
956 zboundaries.push_back(currentZboundary);
957 lastModuleZ = currentModuleZ;
959 layerMaxZ[currentlayer] = std::abs(countPtr->
center().z()) + 0.5*std::abs(countPtr->
length());
960 zboundaries.push_back(layerMaxZ[currentlayer]);
963 layerZboundaries[currentlayer] = zboundaries;
965 layerHalfLength[currentlayer] = layerMinZ[currentlayer]*layerMinZ[currentlayer] > layerMaxZ[currentlayer]*layerMaxZ[currentlayer] ?
966 std::abs(layerMinZ[currentlayer]) : layerMaxZ[currentlayer];
968 takeSmaller( minHalflengthZ, layerHalfLength[currentlayer]);
969 takeBigger( maxHalflengthZ, layerHalfLength[currentlayer]);
970 ATH_MSG_VERBOSE(
" -> Determined Layer z range with : " << layerMinZ[currentlayer] <<
" / " << layerMaxZ[currentlayer] );
971 ATH_MSG_VERBOSE(
" -> Symmetric half length taken : " << layerHalfLength[currentlayer]);
978 double currentR = (*sidetIter)->
center().perp();
979 double currentRmax = (*sidetIter)->rMax();
980 double currentRmin = (*sidetIter)->rMin();
981 layerRadius[currentlayer] = (currentR > layerRadius[currentlayer]) ? currentR : layerRadius[currentlayer];
983 takeBigger( currentRmax, (otherSide)->rMax() );
986 takeSmaller( layerRmin[currentlayer], currentRmin );
987 takeBigger( layerRmax[currentlayer], currentRmax );
991 double currentPhi = orderPosition.phi();
992 takeSmaller( layerMinPhi[currentlayer], currentPhi);
993 takeBigger( layerMaxPhi[currentlayer], currentPhi);
996 bool takeIt = (!otherSide || (*sidetIter)->
center().perp() < otherSide->
center().perp() );
997 const Trk::Surface* moduleSurface = takeIt ? (&((*sidetIter)->surface())) : (&(otherSide->
surface()));
1012 Trk::do_not_delete<Trk::Surface>);
1015 if (takeIt) (layerSurfaces[currentlayer]).push_back(surfaceOrder);
1017 }
else if (!(*sidetIter))
1018 ATH_MSG_WARNING(
"nullptr to Barrel module given by SiDetectorManager! Please check db & dict.xml");
1026 std::vector< Trk::CylinderLayer* > cylinderDetectionLayers;
1027 int layerCounter = 0;
1028 double currentLayerExtend = 0.;
1031 for (
auto& layerRadiusIter : layerRadius) {
1035 bool nonEquidistantBinning =
false;
1038 const double averageBinSize = (layerMaxZ[layerCounter]-layerMinZ[layerCounter])/(layerZsectors[layerCounter]);
1039 const double inv_averageBinSize2 = 1. / (averageBinSize*averageBinSize);
1041 auto bIter = layerZboundaries[layerCounter].begin();
1042 auto bIterE = layerZboundaries[layerCounter].end();
1043 for ( ++bIter; bIter != bIterE; ++bIter ){
1044 float cZ = (*bIter);
1045 float pZ = (*(bIter-1));
1047 if (nonEquidistantBinning){
1048 ATH_MSG_VERBOSE(
"Non-equidistant binning for (Silicon) Surfaces on this layer with radius " << layerRadiusIter <<
" detected. ");
1057 double halfPhiStep =
M_PI/layerPhiSectors[layerCounter];
1059 if (std::abs(layerMinPhi[layerCounter]+layerMaxPhi[layerCounter])< halfPhiStep && std::abs(
M_PI+layerMinPhi[layerCounter]) < 0.5*halfPhiStep ){
1060 ATH_MSG_VERBOSE(
"Detected module fluctuation around +/- M_PI, correcting for it.");
1061 ATH_MSG_VERBOSE(
" min phi / max phi detected : " << layerMinPhi[layerCounter] <<
" / " << layerMaxPhi[layerCounter] );
1062 layerMinPhi[layerCounter] += 2*halfPhiStep;
1065 ATH_MSG_VERBOSE(
"Preparing the Phi-binning for : " << layerPhiSectors[layerCounter] <<
" sectors.");
1066 ATH_MSG_VERBOSE(
" min phi / max phi detected : " << layerMinPhi[layerCounter] <<
" / " << layerMaxPhi[layerCounter] );
1067 double minPhiCorrected = layerMinPhi[layerCounter]-halfPhiStep;
1068 double maxPhiCorrected = layerMaxPhi[layerCounter]+halfPhiStep;
1070 if (minPhiCorrected < -
M_PI){
1071 minPhiCorrected += 2*halfPhiStep;
1072 maxPhiCorrected += 2*halfPhiStep;
1074 ATH_MSG_VERBOSE(
" min phi / max phi corrected : " << minPhiCorrected <<
" / " << maxPhiCorrected );
1081 if (nonEquidistantBinning)
1082 (*currentBinUtility) +=
Trk::BinUtility(layerZboundaries[layerCounter],
1087 layerMinZ[layerCounter],
1088 layerMaxZ[layerCounter],
1092 ATH_MSG_VERBOSE(
"Creating the binned array for the sensitive detector elements with BinUtility :");
1095 auto currentBinnedArray =
1096 std::make_unique<Trk::BinnedArray2D<Trk::Surface>>(
1097 layerSurfaces[layerCounter], currentBinUtility);
1105 std::map< const Trk::Surface*,Amg::Vector3D > uniqueSurfaceMap;
1106 auto usmIter = uniqueSurfaceMap.end();
1108 auto asurfIter = arraySurfaces.begin();
1109 auto asurfIterEnd = arraySurfaces.end();
1110 for ( ; asurfIter != asurfIterEnd; ++asurfIter){
1111 if ( (*asurfIter) ) {
1112 ++sumCheckBarrelModules;
1113 usmIter = uniqueSurfaceMap.find(*asurfIter);
1114 if ( usmIter != uniqueSurfaceMap.end() )
1115 ATH_MSG_WARNING(
"Non-unique surface found with eta/phi = " << (*asurfIter)->center().eta() <<
" / " << (*asurfIter)->center().phi());
1116 else uniqueSurfaceMap[(*asurfIter)] = (*asurfIter)->center();
1119 ATH_MSG_WARNING(
"Null surface defined in BinUtility ArraySurfaces vector");
1124 currentLayerExtend = layerHalfLength[layerCounter];
1127 layerRadius[layerCounter] = 0.5*(layerRmax[layerCounter] + layerRmin[layerCounter]);
1128 layerThickness[layerCounter] = layerRmax[layerCounter] - layerRmin[layerCounter];
1132 double currentLayerThickness = layerThickness[layerCounter]+
m_barrelEnvelope;
1135 ATH_MSG_DEBUG(
"Construct BinnedArray for CylinderLayer with "<< (layerSurfaces[layerCounter]).
size() <<
" SubSurfaces." );
1136 ATH_MSG_DEBUG(
"Building a CylinderLayer with " << layerPhiSectors[layerCounter]
1137 <<
" / " << ( nonEquidistantBinning ? layerZboundaries[layerCounter].
size() : layerZsectors[layerCounter] ) <<
" phi/z bins. " );
1138 ATH_MSG_DEBUG(
" -> With Radius : " << layerRadius[layerCounter] );
1140 ATH_MSG_DEBUG(
" -> With Zmin/Zmax : " << -currentLayerExtend <<
" / " << currentLayerExtend );
1142 if ( nonEquidistantBinning && !layerZboundaries[layerCounter].
empty() ){
1145 double currentZ = -currentLayerExtend;
1147 for (
size_t zbin = 0; zbin < layerZboundaries[layerCounter].size(); ++zbin) {
1148 currentZ += layerZboundaries[layerCounter][zbin];
1150 if (zbin < layerZboundaries[layerCounter].
size()-1)
1156 std::unique_ptr<Trk::OverlapDescriptor> olDescriptor =
nullptr;
1158 olDescriptor = std::make_unique<InDet::PixelOverlapDescriptor>(
m_addMoreSurfaces);
1161 olDescriptor = std::make_unique<InDet::SCT_OverlapDescriptor>(
m_addMoreSurfaces);
1168 currentLayerExtend),
1169 std::move(currentBinnedArray), layerMaterial,
1170 currentLayerThickness, std::move(olDescriptor));
1175 cylinderDetectionLayers.push_back(activeLayer);
1183 ATH_MSG_DEBUG(
"Creating the final CylinderLayer collection with (potentially) additional layers.");
1184 std::unique_ptr<std::vector< Trk::CylinderLayer* > > cylinderLayers
1189 ATH_MSG_DEBUG( barrelModules <<
" Barrel Modules parsed for Cylinder Layer dimenstions." );
1190 ATH_MSG_DEBUG( sumCheckBarrelModules <<
" Barrel Modules filled in Cylinder Layer Arrays." );
1191 if ( barrelModules-sumCheckBarrelModules )
1192 ATH_MSG_WARNING( barrelModules-sumCheckBarrelModules <<
" Modules not registered properly in binned array." );
1194 ATH_MSG_DEBUG(
"Returning " << cylinderLayers->size() <<
" cylinder layers.");
1195 return cylinderLayers;
1199 std::unique_ptr<std::vector<Trk::CylinderLayer*> >
1203 auto cylinderLayers = std::make_unique<std::vector<Trk::CylinderLayer*> >();
1207 auto cylLayerIter = detectionLayers.begin();
1208 auto cylLayerIterEnd = detectionLayers.end();
1213 double cylLayerExtend = 0;
1214 for ( ; addLayerIter != addLayerIterEnd &&
1215 addLayerTypeIter != addLayerTypeIterEnd; ) {
1218 if ( cylLayerIter == cylLayerIterEnd ||
1219 (*addLayerIter) < (*cylLayerIter)->bounds().r() ) {
1220 cylLayerExtend = (cylLayerIter == cylLayerIterEnd)
1222 : (*cylLayerIter)->bounds().halflengthZ() ;
1223 if ((*addLayerTypeIter)) {
1224 ATH_MSG_DEBUG(
"[- M -] Building an additional CylinderLayer w/o "
1225 "sensitive modules");
1232 passiveLayerMaterial,
1237 ATH_MSG_DEBUG(
"[- N -] Building an additional NavigationLayer for "
1238 "volume dimension control");
1242 *addLayerIter,cylLayerExtend),
nullptr));
1250 ATH_MSG_DEBUG(
"[- D -] Registering detection CylinderLayer");
1251 ATH_MSG_DEBUG(
" -> With Radius : " << (*cylLayerIter)->bounds().r());
1252 cylinderLayers->push_back(*cylLayerIter);
1256 for (
const auto & cylLayerIter : detectionLayers ) {
1257 ATH_MSG_DEBUG(
"[- D -] Registering detection CylinderLayer");
1258 ATH_MSG_DEBUG(
" -> With Radius : " << cylLayerIter->bounds().r() );
1259 cylinderLayers->push_back(cylLayerIter);
1261 return cylinderLayers;
1270 auto & layerBinUtility(layerBinUtilityZ);
1276 layerBinUtilityRPhiZ += layerBinUtilityZ;
1277 layerBinUtility = layerBinUtilityRPhiZ;
1291 layerBinUtilityR += layerBinUtilityPhi;
1305 auto laySurfIter = layerSurfaces.begin();
1306 const auto laySurfIterEnd = layerSurfaces.end();
1308 for (; laySurfIter != laySurfIterEnd; ++laySurfIter){
1311 (**laySurfIter).associateLayer(lay);
1316 const Trk::Surface* otherSideSurface = otherSideElement ? &(otherSideElement->
surface()) :
nullptr;
1317 if (otherSideSurface) {
1320 (
const_cast<Trk::Surface&
>(*otherSideSurface)).associateLayer(lay);