66 {
68 PtrVectorWrapper<Trk::CylinderLayer> barrelLayers;
69
70
72
73
74 const TRT_ID* trtIdHelper = nullptr;
77 return nullptr;
78 }
79
82 double layerPhiStep = 2*
M_PI/nBarrelPhiSectors;
83
84 int nTotalBarrelLayers = 0;
85
86
87 double rMin = 10e10;
88 double rMax = 0.;
89
90 double layerZmax = 0.;
91 double layerZmin = 10e10;
92
93
94 for (int ring=0; ring < nBarrelRings; ring++) {
95
97 nTotalBarrelLayers += nBarrelLayers;
98
99 for (
int layer=0;
layer < nBarrelLayers;
layer++){
100 for (int phisec=0; phisec <nBarrelPhiSectors; ++phisec)
101 {
102 for (int iposneg=0; iposneg<2; ++iposneg){
103
104 const InDetDD::TRT_BarrelElement* trtbar = trtContainer->
getBarrelDetElement(iposneg, ring, phisec, layer);
105
106
107 const Trk::PlaneSurface* elementSurface =
dynamic_cast<const Trk::PlaneSurface*
>(&(trtbar->
surface()));
108 if (!elementSurface) {
109 ATH_MSG_WARNING(
"elementSurface: dynamic_cast to Trk::PlaneSurface failed - skipping ... ring/layer/phisec/iposneg = " << ring <<
"/" << layer <<
"/" << phisec <<
"/" << iposneg );
110 continue;
111 }
112 const Trk::RectangleBounds* elementBounds =
dynamic_cast<const Trk::RectangleBounds*
>(&(trtbar->
bounds()));
113 if (!elementBounds) {
114 ATH_MSG_WARNING(
"elementBounds: dynamic_cast to Trk::RectangleBounds failed - skipping ... ring/layer/phisec/iposneg = " << ring <<
"/" << layer <<
"/" << phisec <<
"/" << iposneg );
115 continue;
116 }
117 double elementZcenter = (elementSurface->
center()).z();
118 double elementZmin = std::abs(elementZcenter - elementBounds->
halflengthY());
119 double elementZmax = std::abs(elementZcenter + elementBounds->
halflengthY());
120
122
123 double currentR = trtbar->
center().perp();
125 }
126 }
127 }
128 }
129
130 if (nTotalBarrelLayers==0) {
131 ATH_MSG_WARNING(
"nTotalBarrelLayers = 0 ... aborting and returning 0 !" );
132 return nullptr;
133 }
134
135
136 double rDiff = std::abs(rMax-rMin);
138 double layerHalflength = layerZmax;
139
140
141 if ( std::abs(rDiff) <= 0.1 ) {
142 return nullptr;
143 }
144
145
146 std::vector<double> layerRadii;
150
151 auto layerRadiusIter = layerRadii.begin();
152 auto layerRadiusIterEnd = layerRadii.end();
153
154
156
157 ATH_MSG_VERBOSE(
" -> " << layerRadii.size() <<
" cylindrical barrel layers between " << rMin <<
" and " << rMax <<
" ( at step "<< rStep <<
" )");
158
159
160 for ( ; layerRadiusIter != layerRadiusIterEnd; ++layerRadiusIter ) {
161
162 Trk::BinnedLayerMaterial* layerMaterial = nullptr;
163
166
167 layerMaterial =new Trk::BinnedLayerMaterial(layerBinUtility1DZ);
168 } else {
170 -(*layerRadiusIter)*
M_PI,
171 (*layerRadiusIter)*
M_PI,
174 layerBinUtility2DRPhiZ += layerBinUtility1DZ;
175 layerMaterial =new Trk::BinnedLayerMaterial(layerBinUtility2DRPhiZ);
176 }
177
178 barrelLayers->push_back(
179 new Trk::CylinderLayer(std::make_shared<Trk::CylinderBounds>(
180 *layerRadiusIter, layerHalflength),
182 ATH_MSG_VERBOSE(
" --> Creating a layer at radius : " << *layerRadiusIter);
183 delete layerMaterial;
184 }
185 } else {
186
187
189
190 unsigned int cMaterialLayerCount = 0;
191
192 unsigned int cLayer=0;
193
194
196
197 for (int ring=0; ring < nBarrelRings; ring++){
198
200 ATH_MSG_VERBOSE(
"-> Ring " << ring <<
" has " << nBarrelLayers <<
" barrel layers.");
201
202 for (
int layer=0;
layer < nBarrelLayers;
layer++){
203
204
205 ATH_MSG_VERBOSE(
"--> Layer " << layer <<
" is being built with " << nBarrelPhiSectors <<
" secors in phi.");
206
207
208 ++cLayer;
209
210
211 double layerRadius = 0.;
212 double layerRadiusMin = 10e10;
213 double layerRadiusMax = 0.;
214 double layerPhiMin = 10.;
215 double layerPhiMax = -10;
216
217
218 std::vector< std::pair<Trk::BinnedArray2D<Trk::Surface>,
Amg::Vector3D > > layerSectorArrays;
220
221
222 std::vector< std::pair< std::shared_ptr<const Trk::ApproachSurfaces>,
Amg::Vector3D > > layerApproachSurfaces;
223
224
225 for (int phisec=0; phisec < nBarrelPhiSectors; phisec++){
226
227 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" gahtering the details.");
228
229
230
231 std::vector< Trk::SurfaceOrderPosition > strawsPerPhiSecLayer;
232
233 double phiMin = 10.;
234 double phiMax = -10.;
235
236 int sectorStraws = 0;
237
238 for (int posneg=0; posneg<2; ++posneg){
239
240 const InDetDD::TRT_BarrelElement* currentElement = trtContainer->
getBarrelDetElement(posneg, ring, phisec, layer);
241
242 const Trk::PlaneSurface* elementSurface =
dynamic_cast<const Trk::PlaneSurface*
>(&(currentElement->
surface()));
243 if (!elementSurface) {
244 ATH_MSG_WARNING(
"elementSurface: dynamic_cast to Trk::PlaneSurface failed - skipping ... ring/layer/phisec/posneg = " << ring <<
"/" << layer <<
"/" << phisec <<
"/" << posneg );
245 continue;
246 }
247
248
249
250 Trk::ApproachSurfaces* aSurfaces = new Trk::ApproachSurfaces;
255
258
259
260 layerSectorPosition = elementSurface->
center();
261
262
265
266
267 layerApproachSurfaces.emplace_back( std::shared_ptr<const Trk::ApproachSurfaces>(aSurfaces),elementCenter);
268
269 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" - posneg - " << posneg <<
" - with central phi = " << elementSurface->
center().phi() );
270
272
273
274 for (
unsigned int istraw=0; istraw<currentElement->
nStraws(); ++istraw)
275 {
276 Identifier strawId = trtIdHelper->
straw_id(currentElement->
identify(), istraw);
277 const Trk::Surface* currentStraw = &(currentElement->
surface(strawId));
278
279 double currentPhi = currentStraw->
center().phi();
281 currentPhi =
M_PI + currentPhi;
283 }
284
287
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305 std::shared_ptr<Trk::Surface> sharedSurface(const_cast<Trk::Surface*>(currentStraw),
307 strawsPerPhiSecLayer.emplace_back(sharedSurface, strawOrderPos);
308
309 ++sectorStraws;
310 }
311 }
312
313
314
315 if (!sectorStraws) {
316 return nullptr;
317 }
319 double phiStep =
deltaPhi/(0.5*sectorStraws-1);
320 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" - with " << 0.5*sectorStraws <<
" straws - straw phiMin/phiMax (step) = " << phiMin <<
" / " << phiMax <<
" (" << phiStep <<
")");
321
322 phiMin -= 0.5*phiStep;
323 phiMax += 0.5*phiStep;
324
325
326 auto layerStrawPhiZUtility = Trk::BinUtility(sectorStraws/2,phiMin,phiMax,
Trk::open,
Trk::binPhi);
327 layerStrawPhiZUtility += Trk::BinUtility(2,-layerZmax, layerZmax,
Trk::open,
Trk::binZ);
328
329 Trk::BinnedArray2D<Trk::Surface> layerStrawPhiSector(strawsPerPhiSecLayer,layerStrawPhiZUtility);
330 ATH_MSG_VERBOSE(
"---> Sector " << phisec <<
" - BinnedArray for straws prepared for " << strawsPerPhiSecLayer.size() <<
" straws.");
331
332 layerSectorArrays.emplace_back(std::move(layerStrawPhiSector), layerSectorPosition);
333
334 }
335
336
338
339 bool assignMaterial = false;
340 if (cLayer==(unsigned)int((cMaterialLayerCount+1)*nMaterialLayerStep)) {
341 assignMaterial = true;
342 ++cMaterialLayerCount;
343 ATH_MSG_VERBOSE(
"--> Creating a material+straw layer at radius : " << layerRadius );
344 } else
345 ATH_MSG_VERBOSE(
"--> Creating a straw layer at radius : " << layerRadius );
346
347
348 auto barrelLayerBounds = std::make_shared<Trk::CylinderBounds>(layerRadius, layerHalflength);
349
350
351 ATH_MSG_VERBOSE(
" prepare approach description with " << nBarrelPhiSectors <<
" barrel sectors.");
352 ATH_MSG_VERBOSE(
" min phi / max phi detected : " << layerPhiMin <<
" / " << layerPhiMax );
353 double layerPhiMinCorrected = layerPhiMin-0.5*layerPhiStep;
354 double layerPhiMaxCorrected = layerPhiMax+0.5*layerPhiStep;
355
356 if (layerPhiMinCorrected < -
M_PI){
357 layerPhiMinCorrected += layerPhiStep;
358 layerPhiMaxCorrected += layerPhiStep;
359 }
360 ATH_MSG_VERBOSE(
" min phi / max phi corrected : " << layerPhiMinCorrected <<
" / " << layerPhiMaxCorrected );
361
362
363 auto layerSectorBinUtility = Trk::BinUtility(nBarrelPhiSectors,layerPhiMinCorrected,layerPhiMaxCorrected,
Trk::closed,
Trk::binPhi);
364 auto strawArray = std::make_unique<Trk::BinnedArrayArray2D<Trk::Surface>>(std::move(layerSectorArrays), layerSectorBinUtility );
365
366 ATH_MSG_VERBOSE(
"--> Layer " << layer <<
" has been built with " << strawArray->arrayObjects().size() <<
" straws.");
367
368
369
370 auto aDescriptorBinUtility = Trk::BinUtility(nBarrelPhiSectors,layerPhiMinCorrected,layerPhiMaxCorrected,
Trk::closed,
Trk::binPhi);
371 aDescriptorBinUtility += Trk::BinUtility(2,-layerHalflength,layerHalflength,
Trk::open,
Trk::binZ);
372
373 auto aDescriptorBinnedArray = std::make_unique<Trk::BinnedArray2D<const Trk::ApproachSurfaces>> (layerApproachSurfaces, aDescriptorBinUtility);
374
375
376 auto approachSurface = std::make_unique<Trk::CylinderSurface>(
377 std::make_shared<Trk::CylinderBounds>(*barrelLayerBounds));
378 Trk::ApproachDescriptor* aDescritpor = new Trk::ApproachDescriptor(
379 std::move(aDescriptorBinnedArray), std::move(approachSurface));
380
381
382 if (assignMaterial) {
383
384 Trk::BinnedLayerMaterial* layerMaterial = nullptr;
385
388 layerMaterial =new Trk::BinnedLayerMaterial(layerBinUtilityZ);
389 } else {
391 -layerRadius*
M_PI, layerRadius*
M_PI,
394 layerBinUtilityRPhiZ += layerBinUtilityZ;
395 layerMaterial =new Trk::BinnedLayerMaterial(layerBinUtilityRPhiZ);
396 }
397
398 barrelLayers->push_back(new Trk::CylinderLayer(barrelLayerBounds,
399 std::move(strawArray),
400 *layerMaterial,
402 std::make_unique<InDet::TRT_OverlapDescriptor>(trtIdHelper),
403 aDescritpor));
404 delete layerMaterial;
405
406 } else
407 barrelLayers->push_back(new Trk::CylinderLayer(barrelLayerBounds,
408 std::move(strawArray),
410 std::make_unique<InDet::TRT_OverlapDescriptor>(trtIdHelper),
411 aDescritpor));
412 }
413 }
414
415 ATH_MSG_VERBOSE(
" Built number of TRT barrel material layers: " << cMaterialLayerCount);
416
417
418
420 ATH_MSG_WARNING(
" Complex geo built incorrect # of TRT barrel material layers: "
422 }
423 }
424
425
426 return std::unique_ptr<const std::vector<Trk::CylinderLayer*> > (barrelLayers.release());
427}
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define takeSmaller(current, test)
#define takeSmallerBigger(cSmallest, cBiggest, test)
#define takeBigger(current, test)
const ServiceHandle< StoreGateSvc > & detStore() const
unsigned int nStraws() const
Number of straws in the element.
virtual const Trk::SurfaceBounds & bounds() const override final
Straw layer bounds.
virtual Identifier identify() const override final
identifier of this detector element:
virtual const Trk::Surface & surface() const override final
Element Surface: access to the Surface (straw layer)
virtual const Amg::Vector3D & center() const override final
Element Surface: center of a straw layer.
const TRT_BarrelElement * getBarrelDetElement(unsigned int positive, unsigned int moduleIndex, unsigned int phiIndex, unsigned int strawLayerIndex) const
const TRT_Numerology * getTRTNumerology() const
unsigned int getNBarrelPhi() const
unsigned int getNBarrelRings() const
unsigned int getNBarrelLayers(unsigned int iMod) const
DoubleProperty m_layerThickness
modelled layer thickness
UnsignedIntegerProperty m_barrelLayerBinsPhi
Bins for the Barrel material - in phi.
UnsignedIntegerProperty m_modelBarrelLayers
model barrel layers with material
IntegerProperty m_barrelSectorAtPiBoundary
this is the barrel Sector where +pi/-pi is within
BooleanProperty m_registerStraws
register the straws
BooleanProperty m_modelGeometry
Build the geometry with model layers.
double m_layerStrawRadius
straw radius
UnsignedIntegerProperty m_barrelLayerBinsZ
Bins for the Barrel material - in z.
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
double halflengthY() const
for consitant naming
virtual const Amg::Vector3D & normal() const
Returns the normal vector of the Surface (i.e.
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Amg::Transform3D getTransformFromRotTransl(Amg::RotationMatrix3D rot, Amg::Vector3D transl_vec)
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
retrieve(aClass, aKey=None)