Skip to content

Commit 9c392f6

Browse files
committed
ALICE3-TRK: Detector.cxx modified to retrieve the correct Detector ID following the chosen indexing scheme
1 parent c2f066a commit 9c392f6

File tree

4 files changed

+115
-18
lines changed

4 files changed

+115
-18
lines changed

Detectors/Upgrades/ALICE3/TRK/base/include/TRKBase/GeometryTGeo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,20 @@ class GeometryTGeo : public o2::detectors::DetMatrixCache
8080
int getDisk(int index) const;
8181

8282
/// This routine computes the chip index number from the subDetID, petal, disk, layer, stave /// TODO: retrieve also from chip when chips will be available
83-
/// in substave
8483
/// \param int subDetID The subdetector ID, 0 for VD, 1 for MLOT
8584
/// \param int petalcase The petal case number for VD, from 0 to 3
8685
/// \param int disk The disk number for VD, from 0 to 5
8786
/// \param int lay The layer number. Starting from 0 both for VD and MLOT
8887
/// \param int stave The stave number for MLOT. Starting from 0
8988
int getChipIndex(int subDetID, int petalcase, int disk, int lay, int stave) const;
9089

90+
/// This routine computes the chip index number from the subDetID, volume, layer, stave /// TODO: retrieve also from chip when chips will be available
91+
/// \param int subDetID The subdetector ID, 0 for VD, 1 for MLOT
92+
/// \param int volume is needed only with the current configuration for VD where each single element is a volume. // TODO: when the geometry naming scheme will be changed, change this method
93+
/// \param int lay The layer number for the MLOT. In the current configuration for VD this is not needed. // TODO: when the geometry naming scheme will be changed, change this method
94+
/// \param int stave The stave number in each layer for MLOT. Starting from 0.
95+
int getChipIndex(int subDetID, int volume, int lay, int stave) const;
96+
9197
/// This routine computes subDetID, petal, disk, layer, stave given the chip index number /// TODO: copute also from chip when chips will be available
9298
/// \param int index The chip index number, starting from 0
9399
/// \param int subDetID The subdetector ID, 0 for VD, 1 for MLOT

Detectors/Upgrades/ALICE3/TRK/base/src/GeometryTGeo.cxx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int GeometryTGeo::getLayer(int index) const
155155
while (index > mLastChipIndex[lay]) {
156156
lay++;
157157
}
158-
return lay - mNumberOfPetalsVD; /// numeration of MLOT layesrs starting from 1
158+
return lay - mNumberOfPetalsVD; /// numeration of MLOT layesrs starting from 0
159159
}
160160
return -1; /// -1 if not found
161161
}
@@ -207,6 +207,18 @@ int GeometryTGeo::getChipIndex(int subDetID, int petalcase, int disk, int lay, i
207207
return -1; // not found
208208
}
209209

210+
//__________________________________________________________________________
211+
int GeometryTGeo::getChipIndex(int subDetID, int volume, int lay, int stave) const
212+
{
213+
if (subDetID == 0) { // VD
214+
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
215+
216+
} else if (subDetID == 1) { // MLOT
217+
return getFirstChipIndex(lay, -1, subDetID) + stave;
218+
}
219+
return -1; // not found
220+
}
221+
210222
//__________________________________________________________________________
211223
bool GeometryTGeo::getChipID(int index, int& subDetID, int& petalcase, int& disk, int& lay, int& stave) const
212224
{
@@ -291,7 +303,7 @@ TGeoHMatrix* GeometryTGeo::extractMatrixSensor(int index) const
291303
auto path = getMatrixPath(index);
292304

293305
static TGeoHMatrix matTmp;
294-
gGeoManager->PushPath();
306+
// gGeoManager->PushPath(); // Preserve the modeler state.
295307

296308
// if (!gGeoManager->cd(path.Data())) {
297309
// gGeoManager->PopPath();
@@ -440,7 +452,6 @@ int GeometryTGeo::extractNumberOfActivePartsVD() const
440452
if (vdV == nullptr) {
441453
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
442454
}
443-
LOG(info) << "Volume name: " << getTRKVolPattern();
444455

445456
// Loop on all TRKV nodes, count Layer volumes by checking names
446457
TObjArray* nodes = vdV->GetNodes();
@@ -470,7 +481,6 @@ int GeometryTGeo::extractNumberOfDisksVD() const
470481
if (vdV == nullptr) {
471482
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
472483
}
473-
LOG(info) << "Volume name: " << getTRKVolPattern();
474484

475485
// Loop on all TRKV nodes, count Layer volumes by checking names
476486
TObjArray* nodes = vdV->GetNodes();
@@ -500,7 +510,6 @@ int GeometryTGeo::extractNumberOfPetalsVD() const
500510
if (vdV == nullptr) {
501511
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
502512
}
503-
LOG(info) << "Volume name: " << getTRKVolPattern();
504513

505514
// Loop on all TRKV nodes, count Layer volumes by checking names
506515
TObjArray* nodes = vdV->GetNodes();
@@ -530,7 +539,6 @@ int GeometryTGeo::extractNumberOfLayersVD() const
530539
if (vdV == nullptr) {
531540
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
532541
}
533-
LOG(info) << "Volume name: " << getTRKVolPattern();
534542

535543
// Loop on all TRKV nodes, count Layer volumes by checking names
536544
TObjArray* nodes = vdV->GetNodes();
@@ -560,7 +568,6 @@ int GeometryTGeo::extractNumberOfChipsPerPetalVD() const
560568
if (vdV == nullptr) {
561569
LOG(fatal) << getName() << " volume " << getTRKVolPattern() << " is not in the geometry";
562570
}
563-
LOG(info) << "Volume name: " << getTRKVolPattern();
564571

565572
// Loop on all TRKV nodes, count Layer volumes by checking names
566573
TObjArray* nodes = vdV->GetNodes();

Detectors/Upgrades/ALICE3/TRK/simulation/include/TRKSimulation/Detector.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ namespace trk
3131
class Detector : public o2::base::DetImpl<Detector>
3232
{
3333
public:
34+
static constexpr Int_t mNumberOfVolumes = 44; /// hardcoded for the current geometry = 8 MLOT layers + 36 volumes in the VD. TODO: automatize or change according to the current geometry
35+
static constexpr Int_t mNumberOfVolumesVD = 36; /// hardcoded for the current geometry = 36 volumes in the VD. TODO: automatize or change according to the current geometry
36+
3437
Detector(bool active);
3538
Detector();
3639
~Detector();
@@ -96,6 +99,18 @@ class Detector : public o2::base::DetImpl<Detector>
9699

97100
void defineSensitiveVolumes();
98101

102+
protected:
103+
std::vector<int> mSensorID; //! layer identifiers
104+
std::vector<TString> mSensorName; //! layer names
105+
106+
public:
107+
static constexpr Int_t sNumberVDPetalCases = 4; //! Number of VD petals
108+
int getNumberOfLayers() const { return mLayers.size(); } //! Number of TRK layers
109+
int getNumberOfLayersVD() const { return mPetalCases[0].mPetalLayers.size(); }
110+
int getNumberOfDisksVD() const { return mPetalCases[0].mPetalDisks.size(); }
111+
112+
void Print(FairVolume* vol, int volume, int subDetID, int layer, int stave, int halfstave, int chipID) const;
113+
99114
template <typename Det>
100115
friend class o2::base::DetImpl;
101116
ClassDefOverride(Detector, 1);

Detectors/Upgrades/ALICE3/TRK/simulation/src/Detector.cxx

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ Detector::Detector(bool active)
5353
configServices();
5454
}
5555

56+
mSensorName.resize(mNumberOfVolumes); // hardcoded. TODO: change size when a different naming scheme for VD is in place. Ideally could be 4 petals + 8 layers = 12
57+
int VDvolume = 0;
58+
for (int i = 0; i < 4; i++) { /// VD
59+
for (int j = 0; j < 3; j++) {
60+
mSensorName[VDvolume].Form("%s%d_%s%d_%s%d", GeometryTGeo::getTRKPetalPattern(), i, GeometryTGeo::getTRKPetalLayerPattern(), j, GeometryTGeo::getTRKSensorPattern(), j);
61+
VDvolume++;
62+
}
63+
for (int j = 0; j < 6; j++) {
64+
mSensorName[VDvolume].Form("%s%d_%s%d_%s%d", GeometryTGeo::getTRKPetalPattern(), i, GeometryTGeo::getTRKPetalDiskPattern(), j, GeometryTGeo::getTRKSensorPattern(), j);
65+
VDvolume++;
66+
}
67+
}
68+
69+
for (int i = 0; i < 8; i++) { /// MLOT
70+
mSensorName[VDvolume].Form("%s%d", GeometryTGeo::getTRKSensorPattern(), i);
71+
VDvolume++;
72+
}
73+
74+
for (auto vd : mSensorName) {
75+
std::cout << "Volume name: " << vd << std::endl;
76+
}
77+
5678
LOGP(info, "Summary of TRK configuration:");
5779
for (auto& layer : mLayers) {
5880
LOGP(info, "Layer: {} name: {} r: {} cm | z: {} cm | thickness: {} cm", layer.getNumber(), layer.getName(), layer.getInnerRadius(), layer.getZ(), layer.getChipThickness());
@@ -241,7 +263,7 @@ void Detector::createGeometry()
241263
mPetalCases.clear();
242264
// Add petal cases (the sensitive layers inside the petal cases get constructed here too)
243265
auto& trkPars = TRKBaseParam::Instance();
244-
for (Int_t petalCaseNumber = 0; petalCaseNumber < 4; ++petalCaseNumber) {
266+
for (Int_t petalCaseNumber = 0; petalCaseNumber < sNumberVDPetalCases; ++petalCaseNumber) {
245267
mPetalCases.emplace_back(petalCaseNumber, vTRK, trkPars.irisOpen);
246268
mServices.excavateFromVacuum(mPetalCases[petalCaseNumber].getFullName());
247269
}
@@ -253,6 +275,12 @@ void Detector::InitializeO2Detector()
253275
LOG(info) << "Initialize TRK O2Detector";
254276
mGeometryTGeo = GeometryTGeo::Instance();
255277
defineSensitiveVolumes();
278+
279+
mSensorID.resize(mNumberOfVolumes); // hardcoded. TODO: change size when a different namingh scheme for VD is in place. Ideally could be 4 petals + 8 layers = 12
280+
for (int i = 0; i < mNumberOfVolumes; i++) {
281+
mSensorID[i] = gMC ? TVirtualMC::GetMC()->VolId(mSensorName[i]) : 0; // Volume ID from the Geant geometry
282+
LOGP(info, "{}: mSensorID={}", i, mSensorID[i]);
283+
}
256284
}
257285

258286
void Detector::defineSensitiveVolumes()
@@ -264,7 +292,7 @@ void Detector::defineSensitiveVolumes()
264292
LOGP(info, "Adding TRK Sensitive Volumes");
265293

266294
// Add petal case sensitive volumes
267-
for (int petalCase = 0; petalCase < 4; ++petalCase) {
295+
for (int petalCase = 0; petalCase < sNumberVDPetalCases; ++petalCase) {
268296
// Petal layers
269297
for (int petalLayer = 0; petalLayer < mPetalCases[petalCase].mPetalLayers.size(); ++petalLayer) {
270298
volumeName = mPetalCases[petalCase].mPetalLayers[petalLayer].getSensorName();
@@ -338,17 +366,36 @@ bool Detector::ProcessHits(FairVolume* vol)
338366
return false;
339367
}
340368

341-
int lay = vol->getVolumeId();
369+
int subDetID = -1;
370+
int layer = -1;
371+
int volume = 0;
372+
int stave = -1;
342373
int volID = vol->getMCid();
343374

375+
bool notSens = false;
376+
while ((volume < mNumberOfVolumes) && (notSens = (volID != mSensorID[volume]))) {
377+
++volume; /// there are 44 volumes, 36 for the VD (1 for each sensing element) and 8 for the MLOT (1 for each layer)
378+
}
379+
380+
if (notSens) {
381+
return kFALSE; // RS: can this happen? This method must be called for sensors only?
382+
}
383+
384+
if (volume < mNumberOfVolumesVD) {
385+
subDetID = 0; // VD. For the moment each "chip" is a volume./// TODO: change this logic once the naming scheme is changed
386+
} else {
387+
subDetID = 1; // MLOT
388+
layer = volume - mNumberOfVolumesVD;
389+
}
390+
344391
// Is it needed to keep a track reference when the outer ITS volume is encountered?
345392
auto stack = (o2::data::Stack*)fMC->GetStack();
346393
// if (fMC->IsTrackExiting() && (lay == 0 || lay == mLayers.size() - 1)) {
347394
if (fMC->IsTrackExiting() && InsideFirstOrLastLayer(vol->GetName())) {
348395
// Keep the track refs for the innermost and outermost layers only
349396
o2::TrackReference tr(*fMC, GetDetId());
350397
tr.setTrackID(stack->GetCurrentTrackNumber());
351-
tr.setUserId(lay);
398+
tr.setUserId(volume);
352399
stack->addTrackReference(tr);
353400
}
354401
bool startHit = false, stopHit = false;
@@ -398,13 +445,18 @@ bool Detector::ProcessHits(FairVolume* vol)
398445
TLorentzVector positionStop;
399446
fMC->TrackPosition(positionStop);
400447
// Retrieve the indices with the volume path
401-
int stave(0), halfstave(0), chipinmodule(0), module;
402-
fMC->CurrentVolOffID(1, chipinmodule);
403-
fMC->CurrentVolOffID(2, module);
404-
fMC->CurrentVolOffID(3, halfstave);
405-
fMC->CurrentVolOffID(4, stave);
448+
// int subDetID, int petalcase, int disk, int lay, int stave
449+
int petal(0), ll(0), stave(0), halfstave(0);
450+
if (subDetID == 1) {
451+
fMC->CurrentVolOffID(1, halfstave);
452+
fMC->CurrentVolOffID(2, stave);
453+
} /// if VD, for the moment the volume is the "chipID" so no need to retrieve other elments
406454

407-
Hit* p = addHit(stack->GetCurrentTrackNumber(), lay, mTrackData.mPositionStart.Vect(), positionStop.Vect(),
455+
int chipID = mGeometryTGeo->getChipIndex(subDetID, volume, layer, stave);
456+
457+
Print(vol, volume, subDetID, layer, stave, halfstave, chipID);
458+
459+
Hit* p = addHit(stack->GetCurrentTrackNumber(), chipID, mTrackData.mPositionStart.Vect(), positionStop.Vect(),
408460
mTrackData.mMomentumStart.Vect(), mTrackData.mMomentumStart.E(), positionStop.T(),
409461
mTrackData.mEnergyLoss, mTrackData.mTrkStatusStart, status);
410462
// p->SetTotalEnergy(vmc->Etot());
@@ -424,6 +476,23 @@ o2::itsmft::Hit* Detector::addHit(int trackID, int detID, const TVector3& startP
424476
mHits->emplace_back(trackID, detID, startPos, endPos, startMom, startE, endTime, eLoss, startStatus, endStatus);
425477
return &(mHits->back());
426478
}
479+
480+
void Detector::Print(FairVolume* vol, int volume, int subDetID, int layer, int stave, int halfstave, int chipID) const
481+
{
482+
int currentVol(0);
483+
LOG(INFO) << "Current volume name: " << fMC->CurrentVolName() << " and ID " << fMC->CurrentVolID(currentVol);
484+
LOG(INFO) << "volume: " << volume << "/" << mNumberOfVolumes - 1;
485+
if (subDetID == 1) {
486+
LOG(INFO) << "off volume name 1 " << fMC->CurrentVolOffName(1) << " halfstave: " << halfstave;
487+
LOG(INFO) << "off volume name 2 " << fMC->CurrentVolOffName(2) << " stave: " << stave;
488+
LOG(INFO) << "SubDetector ID: " << subDetID << " Layer: " << layer << " staveinLayer: " << stave << " Chip ID: " << chipID;
489+
490+
} else {
491+
LOG(INFO) << "SubDetector ID: " << subDetID << " Chip ID: " << chipID;
492+
}
493+
LOG(INFO);
494+
}
495+
427496
} // namespace trk
428497
} // namespace o2
429498

0 commit comments

Comments
 (0)