forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometryTGeo.cxx
More file actions
714 lines (620 loc) · 26.4 KB
/
GeometryTGeo.cxx
File metadata and controls
714 lines (620 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <TRKBase/GeometryTGeo.h>
#include <TGeoManager.h>
#include "TRKBase/SegmentationChip.h"
using Segmentation = o2::trk::SegmentationChip;
namespace o2
{
namespace trk
{
std::unique_ptr<o2::trk::GeometryTGeo> GeometryTGeo::sInstance;
// Names
std::string GeometryTGeo::sVolumeName = "TRKV";
std::string GeometryTGeo::sLayerName = "TRKLayer";
std::string GeometryTGeo::sPetalName = "PETALCASE";
std::string GeometryTGeo::sPetalDiskName = "DISK";
std::string GeometryTGeo::sPetalLayerName = "LAYER";
std::string GeometryTGeo::sStaveName = "TRKStave";
std::string GeometryTGeo::sChipName = "TRKChip";
std::string GeometryTGeo::sSensorName = "TRKSensor";
std::string GeometryTGeo::sWrapperVolumeName = "TRKUWrapVol"; ///< Wrapper volume name, not implemented at the moment
o2::trk::GeometryTGeo::~GeometryTGeo()
{
if (!mOwner) {
mOwner = true;
sInstance.release();
}
}
GeometryTGeo::GeometryTGeo(bool build, int loadTrans) : DetMatrixCache(detectors::DetID::TRK)
{
if (sInstance) {
LOGP(fatal, "Invalid use of public constructor: o2::trk::GeometryTGeo instance exists");
}
mLayerToWrapper.fill(-1);
if (build) {
Build(loadTrans);
}
}
//__________________________________________________________________________
void GeometryTGeo::Build(int loadTrans)
{
///// current geometry organization:
///// total elements = x staves (*2 half staves if staggered geometry) * 8 layers ML+OT + 4 petal cases * (3 layers + 6 disks)
///// indexing from 0 to 35: VD petals -> layers -> disks
///// indexing from 36 to y: MLOT staves
if (isBuilt()) {
LOGP(warning, "Already built");
return; // already initialized
}
if (gGeoManager == nullptr) {
LOGP(fatal, "Geometry is not loaded");
}
mNumberOfLayersMLOT = extractNumberOfLayersMLOT();
mNumberOfActivePartsVD = extractNumberOfActivePartsVD();
mNumberOfLayersVD = extractNumberOfLayersVD();
mNumberOfPetalsVD = extractNumberOfPetalsVD();
mNumberOfDisksVD = extractNumberOfDisksVD();
mNumberOfStaves.resize(mNumberOfLayersMLOT);
mNumberOfHalfStaves.resize(mNumberOfLayersMLOT);
mLastChipIndex.resize(mNumberOfPetalsVD + mNumberOfLayersMLOT);
mLastChipIndexVD.resize(mNumberOfPetalsVD);
mLastChipIndexMLOT.resize(mNumberOfLayersMLOT); /// ML and OT are part of TRK as the same detector, without disks
mNumberOfChipsPerLayerVD.resize(mNumberOfLayersVD);
mNumberOfChipsPerLayerMLOT.resize(mNumberOfLayersMLOT);
mNumbersOfChipPerDiskVD.resize(mNumberOfDisksVD);
mNumberOfChipsPerPetalVD.resize(mNumberOfPetalsVD);
for (int i = 0; i < mNumberOfLayersMLOT; i++) {
std::cout << "Layer MLOT: " << i << std::endl;
mNumberOfStaves[i] = extractNumberOfStavesMLOT(i);
mNumberOfHalfStaves[i] = extractNumberOfHalfStavesMLOT(i);
}
int numberOfChipsTotal = 0;
/// filling the information for the VD
for (int i = 0; i < mNumberOfPetalsVD; i++) {
mNumberOfChipsPerPetalVD[i] = extractNumberOfChipsPerPetalVD();
numberOfChipsTotal += mNumberOfChipsPerPetalVD[i];
mLastChipIndex[i] = numberOfChipsTotal - 1;
mLastChipIndexVD[i] = numberOfChipsTotal - 1;
}
/// filling the information for the MLOT
for (int i = 0; i < mNumberOfLayersMLOT; i++) {
mNumberOfChipsPerLayerMLOT[i] = extractNumberOfStavesMLOT(i) * extractNumberOfHalfStavesMLOT(i); // for the moment, considering 1 half stave = 1 chip. TODO: add the final segmentation in chips
numberOfChipsTotal += mNumberOfChipsPerLayerMLOT[i];
mLastChipIndex[i + mNumberOfPetalsVD] = numberOfChipsTotal - 1;
mLastChipIndexMLOT[i] = numberOfChipsTotal - 1;
}
setSize(numberOfChipsTotal); /// temporary, number of chips = number of staves and active parts
fillMatrixCache(loadTrans);
}
//__________________________________________________________________________
int GeometryTGeo::getSubDetID(int index) const
{
if (index <= mLastChipIndexVD[mLastChipIndexVD.size() - 1]) {
return 0;
} else if (index > mLastChipIndexVD[mLastChipIndexVD.size() - 1]) {
return 1;
}
return -1; /// not found
}
//__________________________________________________________________________
int GeometryTGeo::getPetalCase(int index) const
{
int petalcase = 0;
int subDetID = getSubDetID(index);
if (subDetID == 1) {
return -1;
}
else if (index <= mLastChipIndexVD[mNumberOfPetalsVD - 1]) {
while (index > mLastChipIndexVD[petalcase]) {
petalcase++;
}
}
return petalcase;
}
//__________________________________________________________________________
int GeometryTGeo::getLayer(int index) const
{
int subDetID = getSubDetID(index);
int petalcase = getPetalCase(index);
int lay = 0;
if (subDetID == 0) { /// VD
if (index % mNumberOfChipsPerPetalVD[petalcase] >= mNumberOfLayersVD) {
return -1; /// disks
}
return index % mNumberOfChipsPerPetalVD[petalcase];
} else if (subDetID == 1) { /// MLOT
while (index > mLastChipIndex[lay]) {
lay++;
}
return lay - mNumberOfPetalsVD; /// numeration of MLOT layesrs starting from 0
}
return -1; /// -1 if not found
}
//__________________________________________________________________________
int GeometryTGeo::getStave(int index) const
{
int subDetID = getSubDetID(index);
int lay = getLayer(index);
int petalcase = getPetalCase(index);
if (subDetID == 0) { /// VD
return -1;
} else if (subDetID == 1) { /// MLOT
int lay = getLayer(index);
index -= getFirstChipIndex(lay, petalcase, subDetID); // get the index of the sensing element in the layer
return index / mNumberOfHalfStaves[lay];
}
return -1; /// not found
}
//__________________________________________________________________________
int GeometryTGeo::getHalfStave(int index) const
{
int subDetID = getSubDetID(index);
int lay = getLayer(index);
int petalcase = getPetalCase(index);
int stave = getStave(index);
if (subDetID == 0) { /// VD
return -1;
} else if (subDetID == 1) { /// MLOT
int lay = getLayer(index);
index -= getFirstChipIndex(lay, petalcase, subDetID); // get the index of the sensing element in the layer
return index % 2; /// 0 = half stave left, 1 = half stave right, as geometry is filled /// TODO: generalize once chips will be in place. Can it be working also with chips?
}
return -1; /// not found
}
//__________________________________________________________________________
int GeometryTGeo::getDisk(int index) const
{
int subDetID = getSubDetID(index);
int petalcase = getPetalCase(index);
if (subDetID == 0) { /// VD
if (index % mNumberOfChipsPerPetalVD[petalcase] < mNumberOfLayersVD) {
return -1; /// layers
}
return (index % mNumberOfChipsPerPetalVD[petalcase]) - mNumberOfLayersVD;
}
return -1; /// not found or ML/OT
}
//__________________________________________________________________________
int GeometryTGeo::getChipIndex(int subDetID, int petalcase, int disk, int lay, int stave, int halfstave) const
{
if (subDetID == 0) { // VD
if (lay == -1) { // disk
return getFirstChipIndex(lay, petalcase, subDetID) + mNumberOfLayersVD + disk;
} else { // layer
return getFirstChipIndex(lay, petalcase, subDetID) + lay;
}
} else if (subDetID == 1) { // MLOT
if (mNumberOfHalfStaves[lay] == 2) { // staggered geometry
return getFirstChipIndex(lay, petalcase, subDetID) + stave * mNumberOfHalfStaves[lay] + halfstave;
} else if (mNumberOfHalfStaves[lay] == 1) { // turbo geometry
return getFirstChipIndex(lay, petalcase, subDetID) + stave;
}
}
return -1; // not found
}
//__________________________________________________________________________
int GeometryTGeo::getChipIndex(int subDetID, int volume, int lay, int stave, int halfstave) const
{
if (subDetID == 0) { // VD
return volume; /// In the current configuration for VD, each volume is the sensor element = chip. // TODO: when the geometry naming scheme will be changed, change this method
} else if (subDetID == 1) { // MLOT
if (mNumberOfHalfStaves[lay] == 2) { // staggered geometry
return getFirstChipIndex(lay, -1, subDetID) + stave * mNumberOfHalfStaves[lay] + halfstave;
} else if (mNumberOfHalfStaves[lay] == 1) { // turbo geometry
return getFirstChipIndex(lay, -1, subDetID) + stave;
}
}
return -1; // not found
}
//__________________________________________________________________________
bool GeometryTGeo::getChipID(int index, int& subDetID, int& petalcase, int& disk, int& lay, int& stave, int& halfstave) const
{
subDetID = getSubDetID(index);
petalcase = getPetalCase(index);
disk = getDisk(index);
lay = getLayer(index);
stave = getStave(index);
halfstave = getHalfStave(index);
return kTRUE;
}
//__________________________________________________________________________
TString GeometryTGeo::getMatrixPath(int index) const
{
int subDetID, petalcase, disk, layer, stave, halfstave; //// TODO: add chips in a second step
getChipID(index, subDetID, petalcase, disk, layer, stave, halfstave);
// PrintChipID(index, subDetID, petalcase, disk, layer, stave, halfstave);
// TString path = "/cave_1/barrel_1/TRKV_2/TRKLayer0_1/TRKStave0_1/TRKChip0_1/TRKSensor0_1/"; /// dummy path, to be used for tests
TString path = Form("/cave_1/barrel_1/%s_2/", GeometryTGeo::getTRKVolPattern());
if (subDetID == 0) { // VD
if (disk >= 0) {
path += Form("%s%d_%s%d_1/", getTRKPetalPattern(), petalcase, getTRKPetalDiskPattern(), disk); // PETALCASEx_DISKy_1
path += Form("%s%d_%s%d_%s%d_1/", getTRKPetalPattern(), petalcase, getTRKPetalDiskPattern(), disk, getTRKChipPattern(), disk); // PETALCASEx_DISKy_TRKChipy_1
path += Form("%s%d_%s%d_%s%d_1/", getTRKPetalPattern(), petalcase, getTRKPetalDiskPattern(), disk, getTRKSensorPattern(), disk); // PETALCASEx_DISKy_TRKSensory_1
} else if (layer >= 0) {
path += Form("%s%d_%s%d_1/", getTRKPetalPattern(), petalcase, getTRKPetalLayerPattern(), layer); // PETALCASEx_LAYERy_1
path += Form("%s%d_%s%d_%s%d_1/", getTRKPetalPattern(), petalcase, getTRKPetalLayerPattern(), layer, getTRKStavePattern(), layer); // PETALCASEx_LAYERy_TRKStavey_1
path += Form("%s%d_%s%d_%s%d_1/", getTRKPetalPattern(), petalcase, getTRKPetalLayerPattern(), layer, getTRKChipPattern(), layer); // PETALCASEx_LAYERy_TRKChipy_1
path += Form("%s%d_%s%d_%s%d_1/", getTRKPetalPattern(), petalcase, getTRKPetalLayerPattern(), layer, getTRKSensorPattern(), layer); // PETALCASEx_LAYERy_TRKSensory_1
}
} else if (subDetID == 1) { // MLOT
path += Form("%s%d_1/", getTRKLayerPattern(), layer); // TRKLayerx_1
path += Form("%s%d_%d/", getTRKStavePattern(), layer, stave); // TRKStavex_y
if (mNumberOfHalfStaves[layer] == 2) { // staggered geometry
path += Form("%s%d_%d/", getTRKChipPattern(), layer, halfstave); // TRKChipx_0/1
} else if (mNumberOfHalfStaves[layer] == 1) { // turbo geometry
path += Form("%s%d_1/", getTRKChipPattern(), layer); // TRKChipx_1
}
path += Form("%s%d_1/", getTRKSensorPattern(), layer); // TRKSensorx_1
}
return path;
}
//__________________________________________________________________________
TGeoHMatrix* GeometryTGeo::extractMatrixSensor(int index) const
{
// extract matrix transforming from the PHYSICAL sensor frame to global one
// Note, the if the effective sensitive layer thickness is smaller than the
// total physical sensor tickness, this matrix is biased and connot be used
// directly for transformation from sensor frame to global one.
// Therefore we need to add a shift
auto path = getMatrixPath(index);
static TGeoHMatrix matTmp;
gGeoManager->PushPath(); // Preserve the modeler state.
if (!gGeoManager->cd(path.Data())) {
gGeoManager->PopPath();
LOG(error) << "Error in cd-ing to " << path.Data();
return nullptr;
} // end if !gGeoManager
matTmp = *gGeoManager->GetCurrentMatrix(); // matrix may change after cd
// RSS
// matTmp.Print();
// Restore the modeler state.
gGeoManager->PopPath();
static int chipInGlo{0};
/// TODO:
// account for the difference between physical sensitive layer (where charge collection is simulated) and effective sensor thicknesses
// in the VD case this will be accounted by specialized functions during the clusterization (following what it is done for ITS3)
// this can be done once the right sensor thickness is in place in the geometry
// double delta = 0.;
// if (getSubDetID(index) == 1){ /// ML/OT
// delta = Segmentation::SensorLayerThicknessVD - Segmentation::SiliconTickness;
// static TGeoTranslation tra(0., 0.5 * delta, 0.);
// matTmp *= tra;
// }
// std::cout<<"-----"<<std::endl;
// matTmp.Print();
return &matTmp;
}
//__________________________________________________________________________
void GeometryTGeo::fillMatrixCache(int mask)
{
if (mSize < 1) {
LOG(warning) << "The method Build was not called yet";
Build(mask);
return;
}
// build matrices
if ((mask & o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G)) && !getCacheL2G().isFilled()) {
// Matrices for Local (Sensor!!! rather than the full chip) to Global frame transformation
LOGP(info, "Loading {} L2G matrices from TGeo; there are {} matrices", getName(), mSize);
auto& cacheL2G = getCacheL2G();
cacheL2G.setSize(mSize);
for (int i = 0; i < mSize; i++) { /// here get the matrices for det ID between 0 and 257 (mSize = 258 at the moment)
TGeoHMatrix* hm = extractMatrixSensor(i);
cacheL2G.setMatrix(Mat3D(*hm), i);
}
}
// TODO: build matrices for the cases T2L, T2G and T2GRot when needed
}
//__________________________________________________________________________
#ifdef ENABLE_UPGRADES
const char* GeometryTGeo::composeSymNameLayer(int d, int lr)
{
return Form("%s/%s%d", composeSymNameTRK(d), getTRKLayerPattern(), lr);
}
#endif
const char* GeometryTGeo::composeSymNameStave(int d, int lr)
{
return Form("%s/%s%d", composeSymNameLayer(d, lr), getTRKStavePattern(), lr);
}
const char* GeometryTGeo::composeSymNameChip(int d, int lr)
{
return Form("%s/%s%d", composeSymNameStave(d, lr), getTRKChipPattern(), lr);
}
const char* GeometryTGeo::composeSymNameSensor(int d, int lr)
{
return Form("%s/%s%d", composeSymNameChip(d, lr), getTRKSensorPattern(), lr);
}
//__________________________________________________________________________
int GeometryTGeo::extractVolumeCopy(const char* name, const char* prefix) const
{
TString nms = name;
if (!nms.BeginsWith(prefix)) {
return -1;
}
nms.Remove(0, strlen(prefix));
if (!isdigit(nms.Data()[0])) {
return -1;
}
return nms.Atoi();
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfLayersMLOT()
{
int numberOfLayers = 0;
TGeoVolume* trkV = gGeoManager->GetVolume(getTRKVolPattern());
if (trkV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
}
// Loop on all TRKV nodes, count Layer volumes by checking names
// Build on the fly layer - wrapper correspondence
TObjArray* nodes = trkV->GetNodes();
// nodes->Print();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
int lrID = -1;
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, getTRKLayerPattern()) != nullptr) {
numberOfLayers++;
if ((lrID = extractVolumeCopy(name, GeometryTGeo::getTRKLayerPattern())) < 0) {
LOG(fatal) << "Failed to extract layer ID from the " << name;
}
mLayerToWrapper[lrID] = -1; // not wrapped
} else if (strstr(name, getTRKWrapVolPattern()) != nullptr) { // this is a wrapper volume, may cointain layers
int wrID = -1;
if ((wrID = extractVolumeCopy(name, GeometryTGeo::getTRKWrapVolPattern())) < 0) {
LOG(fatal) << "Failed to extract wrapper ID from the " << name;
}
TObjArray* nodesW = nd->GetNodes();
int nNodesW = nodesW->GetEntriesFast();
for (int jw = 0; jw < nNodesW; jw++) {
auto ndW = dynamic_cast<TGeoNode*>(nodesW->At(jw))->GetName();
if (strstr(ndW, getTRKLayerPattern()) != nullptr) {
if ((lrID = extractVolumeCopy(ndW, GeometryTGeo::getTRKLayerPattern())) < 0) {
LOGP(fatal, "Failed to extract layer ID from wrapper volume '{}' from one of its nodes '{}'", name, ndW);
}
numberOfLayers++;
mLayerToWrapper[lrID] = wrID;
}
}
}
}
return numberOfLayers;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfActivePartsVD() const
{
// The number of active parts returned here is 36 = 4 petals * (3 layers + 6 disks)
int numberOfParts = 0;
TGeoVolume* vdV = gGeoManager->GetVolume(getTRKVolPattern());
if (vdV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
}
// Loop on all TRKV nodes, count Layer volumes by checking names
TObjArray* nodes = vdV->GetNodes();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
int lrID = -1;
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, getTRKPetalPattern()) != nullptr && (strstr(name, getTRKPetalLayerPattern()) != nullptr || strstr(name, getTRKPetalDiskPattern()) != nullptr)) {
numberOfParts++;
if ((lrID = extractVolumeCopy(name, GeometryTGeo::getTRKPetalPattern())) < 0) {
LOG(fatal) << "Failed to extract layer ID from the " << name;
}
}
}
return numberOfParts;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfDisksVD() const
{
// The number of disks returned here is 6
int numberOfDisks = 0;
TGeoVolume* vdV = gGeoManager->GetVolume(getTRKVolPattern());
if (vdV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
}
// Loop on all TRKV nodes, count Layer volumes by checking names
TObjArray* nodes = vdV->GetNodes();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
int lrID = -1;
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, Form("%s%s", getTRKPetalPattern(), "0")) != nullptr && (strstr(name, getTRKPetalDiskPattern()) != nullptr)) {
numberOfDisks++;
if ((lrID = extractVolumeCopy(name, GeometryTGeo::getTRKPetalPattern())) < 0) {
LOG(fatal) << "Failed to extract layer ID from the " << name;
}
}
}
return numberOfDisks;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfPetalsVD() const
{
// The number of petals returned here is 4 = number of petals
int numberOfChips = 0;
TGeoVolume* vdV = gGeoManager->GetVolume(getTRKVolPattern());
if (vdV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
}
// Loop on all TRKV nodes, count Layer volumes by checking names
TObjArray* nodes = vdV->GetNodes();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
int lrID = -1;
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, getTRKPetalPattern()) != nullptr && (strstr(name, Form("%s%s", getTRKPetalLayerPattern(), "0")) != nullptr)) {
numberOfChips++;
if ((lrID = extractVolumeCopy(name, GeometryTGeo::getTRKPetalPattern())) < 0) {
LOG(fatal) << "Failed to extract layer ID from the " << name;
}
}
}
return numberOfChips;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfLayersVD() const
{
// The number of layers returned here is 3
int numberOfLayers = 0;
TGeoVolume* vdV = gGeoManager->GetVolume(getTRKVolPattern());
if (vdV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
}
// Loop on all TRKV nodes, count Layer volumes by checking names
TObjArray* nodes = vdV->GetNodes();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
int lrID = -1;
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, Form("%s%s", getTRKPetalPattern(), "0")) != nullptr && strstr(name, getTRKPetalLayerPattern()) != nullptr) {
numberOfLayers++;
if ((lrID = extractVolumeCopy(name, GeometryTGeo::getTRKPetalPattern())) < 0) {
LOG(fatal) << "Failed to extract layer ID from the " << name;
}
}
}
return numberOfLayers;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfChipsPerPetalVD() const
{
// The number of chips per petal returned here is 9 for each layer = number of layers + number of quarters of disks per petal
int numberOfChips = 0;
TGeoVolume* vdV = gGeoManager->GetVolume(getTRKVolPattern());
if (vdV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
}
// Loop on all TRKV nodes, count Layer volumes by checking names
TObjArray* nodes = vdV->GetNodes();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
int lrID = -1;
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, Form("%s%s", getTRKPetalPattern(), "0")) != nullptr && (strstr(name, getTRKPetalLayerPattern()) != nullptr || strstr(name, getTRKPetalDiskPattern()) != nullptr)) {
numberOfChips++;
if ((lrID = extractVolumeCopy(name, GeometryTGeo::getTRKPetalPattern())) < 0) {
LOG(fatal) << "Failed to extract layer ID from the " << name;
}
}
}
return numberOfChips;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfStavesMLOT(int lay) const
{
int numberOfStaves = 0;
std::string layName = Form("%s%d", getTRKLayerPattern(), lay);
TGeoVolume* layV = gGeoManager->GetVolume(layName.c_str());
if (layV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKLayerPattern() << " is not in the geometry";
}
// Loop on all layV nodes, count Layer volumes by checking names
TObjArray* nodes = layV->GetNodes();
// std::cout << "Printing nodes for layer " << lay << std::endl;
// nodes->Print();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
int lrID = -1;
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j)); /// layer node
const char* name = nd->GetName();
if (strstr(name, getTRKStavePattern()) != nullptr) {
numberOfStaves++;
}
}
return numberOfStaves;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfHalfStavesMLOT(int lay) const
{
int numberOfHalfStaves = 0;
std::string staveName = Form("%s%d", getTRKStavePattern(), lay);
TGeoVolume* staveV = gGeoManager->GetVolume(staveName.c_str());
if (staveV == nullptr) {
LOG(fatal) << getName() << " volume " << getTRKStavePattern() << " is not in the geometry";
}
// Loop on all layV nodes, count Layer volumes by checking names
TObjArray* nodes = staveV->GetNodes();
// std::cout << "Printing nodes for layer " << lay << std::endl;
// nodes->Print();
int nNodes = nodes->GetEntriesFast();
for (int j = 0; j < nNodes; j++) {
auto nd = dynamic_cast<TGeoNode*>(nodes->At(j)); /// layer node
const char* name = nd->GetName();
if (strstr(name, getTRKChipPattern()) != nullptr) {
numberOfHalfStaves++;
}
}
return numberOfHalfStaves;
}
//__________________________________________________________________________
void GeometryTGeo::PrintChipID(int index, int subDetID, int petalcase, int disk, int lay, int stave, int halfstave) const
{
std::cout << "\nindex = " << index << std::endl;
std::cout << "subDetID = " << subDetID << std::endl;
std::cout << "petalcase = " << petalcase << std::endl;
std::cout << "layer = " << lay << std::endl;
std::cout << "disk = " << disk << std::endl;
std::cout << "first chip index = " << getFirstChipIndex(lay, petalcase, subDetID) << std::endl;
std::cout << "stave = " << stave << std::endl;
std::cout << "halfstave = " << halfstave << std::endl;
}
//__________________________________________________________________________
void GeometryTGeo::Print(Option_t*) const
{
if (!isBuilt()) {
LOGF(info, "Geometry not built yet!");
return;
}
std::cout << "Detector ID: " << sInstance.get()->getDetID() << std::endl;
LOGF(info, "Summary of GeometryTGeo: %s", getName());
LOGF(info, "Number of layers ML + OL: %d", mNumberOfLayersMLOT);
LOGF(info, "Number of active parts VD: %d", mNumberOfActivePartsVD);
LOGF(info, "Number of layers VD: %d", mNumberOfLayersVD);
LOGF(info, "Number of petals VD: %d", mNumberOfPetalsVD);
LOGF(info, "Number of disks VD: %d", mNumberOfDisksVD);
LOGF(info, "Number of chips per petal VD: ");
for (int i = 0; i < mNumberOfPetalsVD; i++) {
LOGF(info, "%d", mNumberOfChipsPerPetalVD[i]);
}
LOGF(info, "Number of staves and half staves per layer MLOT: ");
for (int i = 0; i < mNumberOfLayersMLOT; i++) {
std::string mlot = "";
mlot = (i < 4) ? "ML" : "OT";
LOGF(info, "Layer: %d, %s, %d staves, %d half staves per stave", i, mlot.c_str(), mNumberOfStaves[i], mNumberOfHalfStaves[i]);
}
LOGF(info, "Total number of chips: %d", getNumberOfChips());
std::cout << "mLastChipIndex = [";
for (int i = 0; i < mLastChipIndex.size(); i++) {
std::cout << mLastChipIndex[i];
if (i < mLastChipIndex.size() - 1) {
std::cout << ", ";
}
}
std::cout << "]" << std::endl;
std::cout << "mLastChipIndexVD = [";
for (int i = 0; i < mLastChipIndexVD.size(); i++) {
std::cout << mLastChipIndexVD[i];
if (i < mLastChipIndexVD.size() - 1) {
std::cout << ", ";
}
}
std::cout << "]" << std::endl;
}
} // namespace trk
} // namespace o2