27 class PtrVectorWrapper
37 for (
const T* elm : *m_ptr) {
43 std::vector<T*>&
operator*() {
return *m_ptr; }
44 const std::vector<const T*>&
operator*()
const {
return *m_ptr; }
46 std::vector<T*>* operator->() {
return m_ptr.get(); }
47 const std::vector<const T*>* operator->()
const {
return m_ptr.get(); }
49 std::vector<T*>*
release() {
return m_ptr.release(); }
52 std::unique_ptr<std::vector<T*>> m_ptr;
64 std::unique_ptr<const std::vector<Trk::CylinderLayer*> >
67 PtrVectorWrapper<Trk::CylinderLayer> barrelLayers;
73 const TRT_ID* trtIdHelper =
nullptr;
81 double layerPhiStep = 2*
M_PI/nBarrelPhiSectors;
83 int nTotalBarrelLayers = 0;
89 double layerZmax = 0.;
90 double layerZmin = 10e10;
93 for (
int ring=0; ring < nBarrelRings; ring++) {
96 nTotalBarrelLayers += nBarrelLayers;
99 for (
int phisec=0; phisec <nBarrelPhiSectors; ++phisec)
101 for (
int iposneg=0; iposneg<2; ++iposneg){
107 if (!elementSurface) {
108 ATH_MSG_WARNING(
"elementSurface: dynamic_cast to Trk::PlaneSurface failed - skipping ... ring/layer/phisec/iposneg = " << ring <<
"/" <<
layer <<
"/" << phisec <<
"/" << iposneg );
112 if (!elementBounds) {
113 ATH_MSG_WARNING(
"elementBounds: dynamic_cast to Trk::RectangleBounds failed - skipping ... ring/layer/phisec/iposneg = " << ring <<
"/" <<
layer <<
"/" << phisec <<
"/" << iposneg );
116 double elementZcenter = (elementSurface->
center()).
z();
117 double elementZmin = std::abs(elementZcenter - elementBounds->
halflengthY());
118 double elementZmax = std::abs(elementZcenter + elementBounds->
halflengthY());
122 double currentR = trtbar->
center().perp();
129 if (nTotalBarrelLayers==0) {
130 ATH_MSG_WARNING(
"nTotalBarrelLayers = 0 ... aborting and returning 0 !" );
135 double rDiff = std::abs(rMax-rMin);
137 double layerHalflength = layerZmax;
140 if ( std::abs(rDiff) <= 0.1 ) {
145 std::vector<double> layerRadii;
150 auto layerRadiusIter = layerRadii.begin();
151 auto layerRadiusIterEnd = layerRadii.end();
156 ATH_MSG_VERBOSE(
" -> " << layerRadii.size() <<
" cylindrical barrel layers between " << rMin <<
" and " << rMax <<
" ( at step "<< rStep <<
" )");
159 for ( ; layerRadiusIter != layerRadiusIterEnd; ++layerRadiusIter ) {
169 -(*layerRadiusIter)*
M_PI,
170 (*layerRadiusIter)*
M_PI,
173 layerBinUtility2DRPhiZ += layerBinUtility1DZ;
180 ATH_MSG_VERBOSE(
" --> Creating a layer at radius : " << *layerRadiusIter );
181 delete layerMaterial;
188 unsigned int cMaterialLayerCount = 0;
190 unsigned int cLayer=0;
195 for (
int ring=0; ring < nBarrelRings; ring++){
198 ATH_MSG_VERBOSE(
"-> Ring " << ring <<
" has " << nBarrelLayers <<
" barrel layers.");
203 ATH_MSG_VERBOSE(
"--> Layer " <<
layer <<
" is being built with " << nBarrelPhiSectors <<
" secors in phi.");
209 double layerRadius = 0.;
210 double layerRadiusMin = 10e10;
211 double layerRadiusMax = 0.;
212 double layerPhiMin = 10.;
213 double layerPhiMax = -10;
216 std::vector< std::pair<Trk::BinnedArray<Trk::Surface>*,
Amg::Vector3D > > layerSectorArrays;
220 std::vector< std::pair< Trk::SharedObject<const Trk::ApproachSurfaces>,
Amg::Vector3D > > layerApproachSurfaces;
223 for (
int phisec=0; phisec < nBarrelPhiSectors; phisec++){
225 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" gahtering the details.");
229 std::vector< Trk::SurfaceOrderPosition > strawsPerPhiSecLayer;
232 double phiMax = -10.;
234 int sectorStraws = 0;
236 for (
int posneg=0; posneg<2; ++posneg){
241 if (!elementSurface) {
242 ATH_MSG_WARNING(
"elementSurface: dynamic_cast to Trk::PlaneSurface failed - skipping ... ring/layer/phisec/posneg = " << ring <<
"/" <<
layer <<
"/" << phisec <<
"/" << posneg );
258 layerSectorPosition = elementSurface->
center();
267 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" - posneg - " << posneg <<
" - with central phi = " << elementSurface->
center().phi() );
272 for (
unsigned int istraw=0; istraw<currentElement->
nStraws(); ++istraw)
277 double currentPhi = currentStraw->
center().phi();
279 currentPhi =
M_PI + currentPhi;
304 Trk::do_not_delete<Trk::Surface>);
305 strawsPerPhiSecLayer.emplace_back(sharedSurface, strawOrderPos);
317 double phiStep =
deltaPhi/(0.5*sectorStraws-1);
318 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" - with " << 0.5*sectorStraws <<
" straws - straw phiMin/phiMax (step) = " << phiMin <<
" / " << phiMax <<
" (" << phiStep <<
")");
320 phiMin -= 0.5*phiStep;
321 phiMax += 0.5*phiStep;
328 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" - BinnedArray for straws prepared for " << strawsPerPhiSecLayer.size() <<
" straws.");
330 layerSectorArrays.emplace_back(layerStrawPhiSector, layerSectorPosition);
337 bool assignMaterial =
false;
338 if (cLayer==(
unsigned)
int((cMaterialLayerCount+1)*nMaterialLayerStep)) {
339 assignMaterial =
true;
340 ++cMaterialLayerCount;
341 ATH_MSG_VERBOSE(
"--> Creating a material+straw layer at radius : " << layerRadius );
343 ATH_MSG_VERBOSE(
"--> Creating a straw layer at radius : " << layerRadius );
349 ATH_MSG_VERBOSE(
" prepare approach description with " << nBarrelPhiSectors <<
" barrel sectors.");
350 ATH_MSG_VERBOSE(
" min phi / max phi detected : " << layerPhiMin <<
" / " << layerPhiMax );
351 double layerPhiMinCorrected = layerPhiMin-0.5*layerPhiStep;
352 double layerPhiMaxCorrected = layerPhiMax+0.5*layerPhiStep;
354 if (layerPhiMinCorrected < -
M_PI){
355 layerPhiMinCorrected += layerPhiStep;
356 layerPhiMaxCorrected += layerPhiStep;
358 ATH_MSG_VERBOSE(
" min phi / max phi corrected : " << layerPhiMinCorrected <<
" / " << layerPhiMaxCorrected );
362 auto strawArray = std::make_unique<Trk::BinnedArrayArray<Trk::Surface>>(layerSectorArrays, layerSectorBinUtility );
364 ATH_MSG_VERBOSE(
"--> Layer " <<
layer <<
" has been built with " << strawArray->arrayObjects().size() <<
" straws.");
371 auto aDescriptorBinnedArray = std::make_unique<Trk::BinnedArray2D<const Trk::ApproachSurfaces>> (layerApproachSurfaces, aDescriptorBinUtility);
374 auto approachSurface = std::make_unique<Trk::CylinderSurface> (barrelLayerBounds->
clone());
377 std::move( approachSurface));
380 if (assignMaterial) {
389 -layerRadius*
M_PI, layerRadius*
M_PI,
392 layerBinUtilityRPhiZ += layerBinUtilityZ;
397 std::move(strawArray),
400 std::make_unique<InDet::TRT_OverlapDescriptor>(trtIdHelper),
402 delete layerMaterial;
406 std::move(strawArray),
408 std::make_unique<InDet::TRT_OverlapDescriptor>(trtIdHelper),
413 ATH_MSG_VERBOSE(
" Built number of TRT barrel material layers: " << cMaterialLayerCount);
418 ATH_MSG_WARNING(
" Complex geo built incorrect # of TRT barrel material layers: "
424 return std::unique_ptr<const std::vector<Trk::CylinderLayer*> > (barrelLayers.release());
428 std::unique_ptr<const std::vector<Trk::DiscLayer*> >
435 const TRT_ID* trtIdHelper =
nullptr;
444 int numTotalLayers = 0;
453 for (
unsigned int iwheel=0; iwheel<nEndcapWheels; ++iwheel)
456 numTotalLayers += nEndcapLayers;
457 for (
unsigned int ilayer = 0; ilayer<nEndcapLayers; ++ilayer){
461 if (!sectorDiscBounds){
463 sectorDiscBounds =
dynamic_cast<const Trk::DiscBounds*
>(§orSurfaceBounds);
466 double currentZ = std::abs(sectorDiscElement->
center().z());
470 if (numTotalLayers==0) {
471 ATH_MSG_WARNING(
"numTotalLayers = 0 ... aborting and returning 0 !" );
475 if (!sectorDiscBounds) {
476 ATH_MSG_WARNING(
"fullDiscBounds do not exist ... aborting and returning 0 !" );
479 auto fullDiscBounds = std::make_unique<Trk::DiscBounds>(sectorDiscBounds->
rMin(), sectorDiscBounds->
rMax());
481 PtrVectorWrapper<Trk::DiscLayer> endcapLayers;
484 std::unique_ptr<Trk::BinnedLayerMaterial> layerMaterial;
487 fullDiscBounds->rMin(),
488 fullDiscBounds->rMax(),
492 layerMaterial = std::make_unique<Trk::BinnedLayerMaterial>(layerBinUtilityR);
499 layerBinUtilityR += layerBinUtilityPhi;
500 layerMaterial = std::make_unique<Trk::BinnedLayerMaterial>(layerBinUtilityR);
504 double zDiff = std::abs(zMax-zMin);
511 for (
int iposneg=0; iposneg<maxendcaps; ++iposneg){
514 std::vector<double> zPositions;
517 double stepdir = iposneg ? 1. : -1.;
518 double zStart = stepdir*zMin;
521 << zMin <<
" and " << zMax <<
" ( at step "<< zStep <<
" )");
525 zPositions.push_back(zStart + stepdir *
double(izpos) * zStep - 0.5 *
m_layerThickness);
528 std::vector<double>::const_iterator zPosIter = zPositions.begin();
529 std::vector<double>::const_iterator zPosIterEnd = zPositions.end();
534 for ( ; zPosIter != zPosIterEnd; ++zPosIter){
539 fullDiscBounds->clone(),
548 unsigned int cLayer = 0;
550 unsigned int cMaterialLayerCount = 0;
553 for (
unsigned int iwheel=0; iwheel<nEndcapWheels; ++iwheel)
557 for (
unsigned int ilayer = 0; ilayer < nEndcapLayers; ++ilayer){
563 int numberOfStraws = 0;
572 double discZ = fullDiscPosition.z();
575 bool assignMaterial =
false;
576 if (cLayer == (
unsigned)
int((cMaterialLayerCount+1)*nMaterialLayerStep)) {
577 assignMaterial =
true;
578 ++cMaterialLayerCount;
579 ATH_MSG_VERBOSE(
"--> Creating a material+straw layer at z-pos : " << discZ );
585 std::vector< Trk::SurfaceOrderPosition > strawPerEndcapLayer;
589 double zMax = -10e10;
591 for (
unsigned int iphisec=0; iphisec<nEndcapPhiSectors; ++iphisec){
592 ATH_MSG_VERBOSE(
"Building sector " << iphisec <<
" of endcap wheel " << iwheel );
594 unsigned int nstraws = currentElement->
nStraws();
595 for (
unsigned int istraw=0; istraw<nstraws; istraw++){
600 double zPos = currentStraw->
center().z();
617 strawPerEndcapLayer.emplace_back(sharedSurface, strawOrderPos);
622 if (!numberOfStraws){
626 auto strawArray = std::make_unique<Trk::BinnedArray1D<Trk::Surface>>(strawPerEndcapLayer, currentBinUtility);
630 discZ = 0.5*(zMin+zMax);
633 ATH_MSG_VERBOSE(
"TRT Disc being build at z Position " << discZ <<
" ( from " << zMin <<
" / " << zMax <<
" )");
636 auto aSurfaces = std::make_unique<Trk::ApproachSurfaces>();
646 aSurfaces->push_back(
new Trk::DiscSurface(asnTransform, fullDiscBounds->clone()) );
647 aSurfaces->push_back(
new Trk::DiscSurface(aspTransform, fullDiscBounds->clone()) );
649 aSurfaces->push_back(
new Trk::DiscSurface(aspTransform, fullDiscBounds->clone()) );
650 aSurfaces->push_back(
new Trk::DiscSurface(asnTransform, fullDiscBounds->clone()) );
658 fullDiscBounds->clone(),
659 std::move(strawArray),
662 std::make_unique<InDet::TRT_OverlapDescriptor>(trtIdHelper),
666 fullDiscBounds->clone(),
667 std::move(strawArray),
669 std::make_unique<InDet::TRT_OverlapDescriptor>(trtIdHelper),
672 if (currentLayer) endcapLayers->push_back(currentLayer);
677 ATH_MSG_VERBOSE(
" Built # of TRT material layers: " << cMaterialLayerCount <<
"in ispos: " << iposneg <<
"ring");
683 << cMaterialLayerCount <<
" / " <<
m_modelEndcapLayers <<
"in ispos" << iposneg <<
"ring" );
689 return std::unique_ptr<const std::vector<Trk::DiscLayer*> > (endcapLayers.release());