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
1253 lines (1070 loc) · 43.3 KB
/
GeometryTGeo.cxx
File metadata and controls
1253 lines (1070 loc) · 43.3 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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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"
#include <TMath.h>
#include <limits>
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::sPetalAssemblyName = "PETAL";
std::string GeometryTGeo::sPetalName = "PETALCASE";
std::string GeometryTGeo::sPetalDiskName = "DISK";
std::string GeometryTGeo::sPetalLayerName = "LAYER";
std::string GeometryTGeo::sStaveName = "TRKStave";
std::string GeometryTGeo::sHalfStaveName = "TRKHalfStave";
std::string GeometryTGeo::sModuleName = "TRKModule";
std::string GeometryTGeo::sChipName = "TRKChip";
std::string GeometryTGeo::sSensorName = "TRKSensor";
std::string GeometryTGeo::sDeadzoneName = "TRKDeadzone";
std::string GeometryTGeo::sMetalStackName = "TRKMetalStack";
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");
}
mLayoutMLOT = o2::trk::TRKBaseParam::Instance().getLayoutMLOT();
LOG(debug) << "Overall layout ML and OT: " << mLayoutMLOT;
mNumberOfLayersMLOT = extractNumberOfLayersMLOT();
mNumberOfPetalsVD = extractNumberOfPetalsVD();
mNumberOfActivePartsVD = extractNumberOfActivePartsVD();
mNumberOfLayersVD = extractNumberOfLayersVD();
mNumberOfDisksVD = extractNumberOfDisksVD();
mNumberOfStaves.resize(mNumberOfLayersMLOT);
mNumberOfHalfStaves.resize(mNumberOfLayersMLOT);
mNumberOfModules.resize(mNumberOfLayersMLOT);
mNumberOfChips.resize(mNumberOfLayersMLOT);
mNumberOfChipsPerLayerVD.resize(mNumberOfLayersVD);
mNumberOfChipsPerLayerMLOT.resize(mNumberOfLayersMLOT);
mNumbersOfChipPerDiskVD.resize(mNumberOfDisksVD);
mNumberOfChipsPerPetalVD.resize(mNumberOfPetalsVD);
mLastChipIndex.resize(mNumberOfPetalsVD + mNumberOfLayersMLOT);
mLastChipIndexVD.resize(mNumberOfPetalsVD);
mLastChipIndexMLOT.resize(mNumberOfLayersMLOT); /// ML and OT are part of TRK as the same detector, without disks
for (int i = 0; i < mNumberOfLayersMLOT; i++) {
mNumberOfStaves[i] = extractNumberOfStavesMLOT(i);
mNumberOfHalfStaves[i] = extractNumberOfHalfStavesMLOT(i);
mNumberOfModules[i] = extractNumberOfModulesMLOT(i);
mNumberOfChips[i] = extractNumberOfChipsMLOT(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] = mNumberOfStaves[i] * mNumberOfHalfStaves[i] * mNumberOfModules[i] * mNumberOfChips[i];
numberOfChipsTotal += mNumberOfChipsPerLayerMLOT[i];
mLastChipIndex[i + mNumberOfPetalsVD] = numberOfChipsTotal - 1;
mLastChipIndexMLOT[i] = numberOfChipsTotal - 1;
}
setSize(numberOfChipsTotal);
defineMLOTSensors();
fillTrackingFramesCacheMLOT();
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::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::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 layers 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
const int Nhs = mNumberOfHalfStaves[lay];
const int Nmod = mNumberOfModules[lay];
const int Nchip = mNumberOfChips[lay];
if (Nhs == 2) {
int chipsPerModule = Nchip;
int chipsPerHalfStave = Nmod * chipsPerModule;
int chipsPerStave = Nhs * chipsPerHalfStave;
return index / chipsPerStave;
} else if (Nhs == 1) {
int chipsPerModule = Nchip;
int chipsPerStave = Nmod * chipsPerModule;
return index / chipsPerStave;
}
}
return -1;
}
//__________________________________________________________________________
int GeometryTGeo::getHalfStave(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
const int Nhs = mNumberOfHalfStaves[lay];
const int Nmod = mNumberOfModules[lay];
const int Nchip = mNumberOfChips[lay];
int chipsPerModule = Nchip;
int chipsPerHalfStave = Nmod * chipsPerModule;
int chipsPerStave = Nhs * chipsPerHalfStave;
int rem = index % chipsPerStave;
return rem / chipsPerHalfStave; // 0 = left, 1 = right
}
return -1;
}
//__________________________________________________________________________
int GeometryTGeo::getModule(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
const int Nhs = mNumberOfHalfStaves[lay];
const int Nmod = mNumberOfModules[lay];
const int Nchip = mNumberOfChips[lay];
if (Nhs == 2) {
int chipsPerModule = Nchip;
int chipsPerHalfStave = Nmod * chipsPerModule;
int rem = index % (Nhs * chipsPerHalfStave);
rem = rem % chipsPerHalfStave;
return rem / chipsPerModule;
} else if (Nhs == 1) {
int chipsPerModule = Nchip;
int rem = index % (Nmod * chipsPerModule);
return rem / chipsPerModule;
}
}
return -1;
}
//__________________________________________________________________________
int GeometryTGeo::getChip(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
const int Nhs = mNumberOfHalfStaves[lay];
const int Nmod = mNumberOfModules[lay];
const int Nchip = mNumberOfChips[lay];
if (Nhs == 2) {
int chipsPerModule = Nchip;
return index % chipsPerModule;
} else if (Nhs == 1) {
int chipsPerModule = Nchip;
return index % chipsPerModule;
}
}
return -1;
}
//__________________________________________________________________________
unsigned short GeometryTGeo::getChipIndex(int subDetID, int petalcase, int disk, int lay, int stave, int halfstave, int mod, int chip) 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
const int Nhs = mNumberOfHalfStaves[lay]; // 1 or 2
const int Nmod = mNumberOfModules[lay]; // module per half-stave (per stave if Nhs==1)
const int Nchip = mNumberOfChips[lay]; // chips per module
if (Nhs == 2) { // staggered geometry: layer -> stave -> halfstave -> mod -> chip
int chipsPerModule = Nchip;
int chipsPerHalfStave = Nmod * chipsPerModule;
int chipsPerStave = Nhs * chipsPerHalfStave;
return getFirstChipIndex(lay, petalcase, subDetID) + stave * chipsPerStave + halfstave * chipsPerHalfStave + mod * chipsPerModule + chip;
} else if (Nhs == 1) { // turbo geometry: layer -> stave -> mod -> chip (no halfstave)
int chipsPerModule = Nchip;
int chipsPerStave = Nmod * chipsPerModule;
return getFirstChipIndex(lay, petalcase, subDetID) + stave * chipsPerStave + mod * chipsPerModule + chip;
}
}
LOGP(warning, "Chip index not found for subDetID %d, petalcase %d, disk %d, layer %d, stave %d, halfstave %d, module %d, chip %d, returning numeric limit", subDetID, petalcase, disk, lay, stave, halfstave, mod, chip);
return std::numeric_limits<unsigned short>::max(); // not found
}
//__________________________________________________________________________
unsigned short GeometryTGeo::getChipIndex(int subDetID, int volume, int lay, int stave, int halfstave, int mod, int chip) 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
const int Nhs = mNumberOfHalfStaves[lay]; // 1 or 2
const int Nmod = mNumberOfModules[lay]; // module per half-stave (per stave if Nhs==1)
const int Nchip = mNumberOfChips[lay]; // chips per module
if (Nhs == 2) { // staggered geometry: layer -> stave -> halfstave -> mod -> chip
int chipsPerModule = Nchip;
int chipsPerHalfStave = Nmod * chipsPerModule;
int chipsPerStave = Nhs * chipsPerHalfStave;
return getFirstChipIndex(lay, -1, subDetID) + stave * chipsPerStave + halfstave * chipsPerHalfStave + mod * chipsPerModule + chip;
} else if (Nhs == 1) { // turbo geometry: layer -> stave -> mod -> chip (no halfstave)
int chipsPerModule = Nchip;
int chipsPerStave = Nmod * chipsPerModule;
return getFirstChipIndex(lay, -1, subDetID) + stave * chipsPerStave + mod * chipsPerModule + chip;
}
}
LOGP(warning, "Chip index not found for subDetID %d, volume %d, layer %d, stave %d, halfstave %d, module %d, chip %d, returning numeric limit", subDetID, volume, lay, stave, halfstave, mod, chip);
return std::numeric_limits<unsigned short>::max(); // not found
}
//__________________________________________________________________________
bool GeometryTGeo::getChipID(int index, int& subDetID, int& petalcase, int& disk, int& lay, int& stave, int& halfstave, int& mod, int& chip) const
{
subDetID = getSubDetID(index);
petalcase = getPetalCase(index);
disk = getDisk(index);
lay = getLayer(index);
stave = getStave(index);
if (mNumberOfHalfStaves[lay] == 2) {
halfstave = getHalfStave(index);
} else {
halfstave = 0; // if not staggered geometry, return 0
}
halfstave = getHalfStave(index);
mod = getModule(index);
chip = getChip(index);
return kTRUE;
}
//__________________________________________________________________________
TString GeometryTGeo::getMatrixPath(int index) const
{
int subDetID, petalcase, disk, layer, stave, halfstave, mod, chip;
getChipID(index, subDetID, petalcase, disk, layer, stave, halfstave, mod, chip);
// PrintChipID(index, subDetID, petalcase, disk, layer, stave, halfstave, mod, chip);
// 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());
// handling cylindrical configuration for ML and/or OT
// needed because of the different numbering scheme in the geometry for the cylindrical case wrt the staggered and turbo ones
if (subDetID == 1) {
if ((layer < 4 && mLayoutMLOT == eMLOTLayout::kCylindrical) || (layer > 3 && mLayoutMLOT == eMLOTLayout::kCylindrical)) {
stave = 1;
mod = 1;
chip = 1;
}
}
// build the path
if (subDetID == 0) { // VD
if (disk >= 0) {
path += Form("%s_%d_%d/", getTRKPetalAssemblyPattern(), petalcase, petalcase + 1); // PETAL_n
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_%d/", getTRKPetalAssemblyPattern(), petalcase, petalcase + 1); // PETAL_n
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/", getTRKHalfStavePattern(), layer, halfstave); // TRKHalfStavex_y
}
path += Form("%s%d_%d/", getTRKModulePattern(), layer, mod); // TRKModulx_y
path += Form("%s%d_%d/", getTRKChipPattern(), layer, chip); // TRKChipx_y
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::defineMLOTSensors()
{
for (int i = 0; i < mSize; i++) {
if (getSubDetID(i) == 0) {
continue;
}
sensorsMLOT.push_back(i);
}
}
//__________________________________________________________________________
void GeometryTGeo::fillTrackingFramesCacheMLOT()
{
// fill for every sensor of ML & OT its tracking frame parameters
if (!isTrackingFrameCachedMLOT() && !sensorsMLOT.empty()) {
size_t newSize = sensorsMLOT.size();
mCacheRefXMLOT.resize(newSize);
mCacheRefAlphaMLOT.resize(newSize);
for (int i = 0; i < newSize; i++) {
int sensorId = sensorsMLOT[i];
extractSensorXAlphaMLOT(sensorId, mCacheRefXMLOT[i], mCacheRefAlphaMLOT[i]);
}
}
}
//__________________________________________________________________________
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);
}
}
// build T2L matrices for ML & OT !! VD is yet to be implemented once its geometry will be more refined
if ((mask & o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L)) && !getCacheT2L().isFilled()) {
LOGP(info, "Loading {} T2L matrices from TGeo for ML & OT", getName());
if (sensorsMLOT.size()) {
int m_Size = sensorsMLOT.size();
auto& cacheT2L = getCacheT2L();
cacheT2L.setSize(m_Size);
for (int i = 0; i < m_Size; i++) {
int sensorID = sensorsMLOT[i];
TGeoHMatrix& hm = createT2LMatrixMLOT(sensorID);
cacheT2L.setMatrix(Mat3D(hm), i); // here, sensorIDs from 0 to 374, sensorIDs shifted to 36 !
}
}
}
// TODO: build matrices for the cases T2L, T2G and T2GRot when needed
}
//__________________________________________________________________________
#ifdef ENABLE_UPGRADES
const char* GeometryTGeo::composeSymNameLayer(int d, int layer)
{
return Form("%s/%s%d", composeSymNameTRK(d), getTRKLayerPattern(), layer);
}
#endif
const char* GeometryTGeo::composeSymNameStave(int d, int layer)
{
return Form("%s/%s%d", composeSymNameLayer(d, layer), getTRKStavePattern(), layer);
}
const char* GeometryTGeo::composeSymNameModule(int d, int layer)
{
return Form("%s/%s%d", composeSymNameStave(d, layer), getTRKModulePattern(), layer);
}
const char* GeometryTGeo::composeSymNameChip(int d, int layer)
{
return Form("%s/%s%d", composeSymNameStave(d, layer), getTRKChipPattern(), layer);
}
const char* GeometryTGeo::composeSymNameSensor(int d, int layer)
{
return Form("%s/%s%d", composeSymNameChip(d, layer), getTRKSensorPattern(), layer);
}
//__________________________________________________________________________
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::extractNumberOfPetalsVD() const
{
int numberOfPetals = 0;
TGeoVolume* trkV = gGeoManager->GetVolume(getTRKVolPattern());
if (!trkV) {
LOGP(fatal, "{} volume {} is not in the geometry", getName(), getTRKVolPattern());
return 0;
}
// Loop on all TRKV nodes, count PETAL assemblies and their contents
TObjArray* nodes = trkV->GetNodes();
if (!nodes) {
LOGP(warning, "{} volume has no child nodes", getTRKVolPattern());
return 0;
}
LOGP(info, "Searching for petal assemblies in {} (pattern: {})",
getTRKVolPattern(), getTRKPetalAssemblyPattern());
for (int j = 0; j < nodes->GetEntriesFast(); j++) {
auto* nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, getTRKPetalAssemblyPattern()) != nullptr) {
numberOfPetals++;
LOGP(info, "Found petal assembly: {}", name);
// Get petal volume and its nodes for debugging
TGeoVolume* petalVol = nd->GetVolume();
if (petalVol) {
TObjArray* petalNodes = petalVol->GetNodes();
if (petalNodes) {
LOGP(debug, "Petal {} contains {} child nodes", name, petalNodes->GetEntriesFast());
// Print all nodes in this petal
for (int k = 0; k < petalNodes->GetEntriesFast(); k++) {
auto* petalNode = dynamic_cast<TGeoNode*>(petalNodes->At(k));
LOGP(debug, " Node {}: {}", k, petalNode->GetName());
}
} else {
LOGP(warning, "Petal {} has no child nodes", name);
}
} else {
LOGP(warning, "Petal {} has no volume", name);
}
}
}
if (numberOfPetals == 0) {
LOGP(warning, "No petal assemblies found in geometry");
} else {
LOGP(info, "Found {} petal assemblies", numberOfPetals);
}
return numberOfPetals;
}
//__________________________________________________________________________
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) {
LOGP(fatal, "{} volume {} is not in the geometry", getName(), getTRKVolPattern());
return 0;
}
// Find first petal to count its active parts
TObjArray* nodes = vdV->GetNodes();
if (!nodes) {
LOGP(warning, "{} volume has no child nodes", getTRKVolPattern());
return 0;
}
bool petalFound = false;
for (int j = 0; j < nodes->GetEntriesFast(); j++) {
auto* nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, getTRKPetalAssemblyPattern()) == nullptr) {
continue;
}
petalFound = true;
LOGP(info, "Counting active parts in petal: {}", name);
// Found a petal, count its layers and disks
TGeoVolume* petalVol = nd->GetVolume();
if (!petalVol) {
LOGP(warning, "Petal {} has no volume", name);
break;
}
TObjArray* petalNodes = petalVol->GetNodes();
if (!petalNodes) {
LOGP(warning, "Petal {} has no child nodes", name);
break;
}
for (int k = 0; k < petalNodes->GetEntriesFast(); k++) {
auto* petalNode = dynamic_cast<TGeoNode*>(petalNodes->At(k));
const char* nodeName = petalNode->GetName();
if (strstr(nodeName, getTRKPetalLayerPattern()) != nullptr ||
strstr(nodeName, getTRKPetalDiskPattern()) != nullptr) {
numberOfParts++;
LOGP(debug, "Found active part in {}: {}", name, nodeName);
}
}
// We only need to check one petal as they're identical
break;
}
if (!petalFound) {
LOGP(warning, "No petal assembly found matching pattern '{}'", getTRKPetalAssemblyPattern());
return 0;
}
if (numberOfParts == 0) {
LOGP(warning, "No active parts (layers/disks) found in petal");
return 0;
}
// Multiply by number of petals since all petals are identical
int totalParts = numberOfParts * mNumberOfPetalsVD;
LOGP(info, "Total number of active parts: {} ({}*{})",
totalParts, numberOfParts, mNumberOfPetalsVD);
return totalParts;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfDisksVD() const
{
// Count disks in the first petal (all petals are identical)
int numberOfDisks = 0;
TGeoVolume* vdV = gGeoManager->GetVolume(getTRKVolPattern());
if (!vdV) {
LOGP(fatal, "{} volume {} is not in the geometry", getName(), getTRKVolPattern());
return 0;
}
// Find first petal
TObjArray* nodes = vdV->GetNodes();
if (!nodes) {
LOGP(warning, "{} volume has no child nodes", getTRKVolPattern());
return 0;
}
bool petalFound = false;
for (int j = 0; j < nodes->GetEntriesFast(); j++) {
auto* nd = dynamic_cast<TGeoNode*>(nodes->At(j));
if (strstr(nd->GetName(), getTRKPetalAssemblyPattern()) == nullptr) {
continue;
}
petalFound = true;
LOGP(info, "Counting disks in petal: {}", nd->GetName());
// Count disks in this petal
TGeoVolume* petalVol = nd->GetVolume();
if (!petalVol) {
LOGP(warning, "Petal {} has no volume", nd->GetName());
break;
}
TObjArray* petalNodes = petalVol->GetNodes();
if (!petalNodes) {
LOGP(warning, "Petal {} has no child nodes", nd->GetName());
break;
}
for (int k = 0; k < petalNodes->GetEntriesFast(); k++) {
auto* petalNode = dynamic_cast<TGeoNode*>(petalNodes->At(k));
if (strstr(petalNode->GetName(), getTRKPetalDiskPattern()) != nullptr) {
numberOfDisks++;
LOGP(info, "Found disk in {} : {}", nd->GetName(), petalNode->GetName());
}
}
// One petal is enough
break;
}
if (!petalFound) {
LOGP(warning, "No petal assembly found matching pattern '{}'", getTRKPetalAssemblyPattern());
}
if (numberOfDisks == 0) {
LOGP(warning, "No disks found in VD geometry");
}
return numberOfDisks;
}
//__________________________________________________________________________
int GeometryTGeo::extractNumberOfLayersVD() const
{
// Count layers in the first petal (all petals are identical)
int numberOfLayers = 0;
TGeoVolume* vdV = gGeoManager->GetVolume(getTRKVolPattern());
if (!vdV) {
LOGP(fatal, "{} volume {} is not in the geometry", getName(), getTRKVolPattern());
return 0;
}
// Find first petal
TObjArray* nodes = vdV->GetNodes();
if (!nodes) {
LOGP(warning, "{} volume has no child nodes", getTRKVolPattern());
return 0;
}
bool petalFound = false;
for (int j = 0; j < nodes->GetEntriesFast(); j++) {
auto* nd = dynamic_cast<TGeoNode*>(nodes->At(j));
if (strstr(nd->GetName(), getTRKPetalAssemblyPattern()) == nullptr) {
continue;
}
petalFound = true;
LOGP(info, "Counting layers in petal: {}", nd->GetName());
// Count layers in this petal
TGeoVolume* petalVol = nd->GetVolume();
if (!petalVol) {
LOGP(warning, "Petal {} has no volume", nd->GetName());
break;
}
TObjArray* petalNodes = petalVol->GetNodes();
if (!petalNodes) {
LOGP(warning, "Petal {} has no child nodes", nd->GetName());
break;
}
for (int k = 0; k < petalNodes->GetEntriesFast(); k++) {
auto* petalNode = dynamic_cast<TGeoNode*>(petalNodes->At(k));
if (strstr(petalNode->GetName(), getTRKPetalLayerPattern()) != nullptr) {
numberOfLayers++;
LOGP(info, "Found layer in {} : {}", nd->GetName(), petalNode->GetName());
}
}
// One petal is enough
break;
}
if (!petalFound) {
LOGP(warning, "No petal assembly found matching pattern '{}'", getTRKPetalAssemblyPattern());
}
if (numberOfLayers == 0) {
LOGP(warning, "No layers found in VD geometry");
}
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) {
LOGP(fatal, "{} volume {} is not in the geometry", getName(), getTRKVolPattern());
return 0;
}
// Find first petal assembly
TObjArray* nodes = vdV->GetNodes();
if (!nodes) {
LOGP(warning, "{} volume has no child nodes", getTRKVolPattern());
return 0;
}
bool petalFound = false;
for (int j = 0; j < nodes->GetEntriesFast(); j++) {
auto* nd = dynamic_cast<TGeoNode*>(nodes->At(j));
const char* name = nd->GetName();
if (strstr(name, getTRKPetalAssemblyPattern()) == nullptr) {
continue;
}
petalFound = true;
LOGP(info, "Counting chips in petal: {}", name);
// Found a petal, count sensors in its layers and disks
TGeoVolume* petalVol = nd->GetVolume();
if (!petalVol) {
LOGP(warning, "Petal {} has no volume", name);
break;
}
TObjArray* petalNodes = petalVol->GetNodes();
if (!petalNodes) {
LOGP(warning, "Petal {} has no child nodes", name);
break;
}
for (int k = 0; k < petalNodes->GetEntriesFast(); k++) {
auto* petalNode = dynamic_cast<TGeoNode*>(petalNodes->At(k));
const char* nodeName = petalNode->GetName();
TGeoVolume* vol = petalNode->GetVolume();
if (!vol) {
LOGP(debug, "Node {} has no volume", nodeName);
continue;
}
// Look for sensors in this volume
TObjArray* subNodes = vol->GetNodes();
if (!subNodes) {
LOGP(debug, "Node {} has no sub-nodes", nodeName);
continue;
}
for (int i = 0; i < subNodes->GetEntriesFast(); i++) {
auto* subNode = dynamic_cast<TGeoNode*>(subNodes->At(i));
if (strstr(subNode->GetName(), getTRKChipPattern()) != nullptr) {
numberOfChips++;
LOGP(debug, "Found chip in {}: {}", nodeName, subNode->GetName());
}
}
}
// We only need one petal
break;
}
if (!petalFound) {
LOGP(warning, "No petal assembly found matching pattern '{}'", getTRKPetalAssemblyPattern());
}
if (numberOfChips == 0) {
LOGP(warning, "No chips/sensors found in VD petal");
}
LOGP(info, "Number of chips per petal: {}", numberOfChips);
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();