Skip to content

Commit 140d0e9

Browse files
sawenzelclaude
andcommitted
Resolve the TRD chamber by name when chamber assemblies have no volume id
This fixes the TRD initialisation abort under native Geant4 navigation (G4.navmode=kG4). - The VGM conversion collapses the chamber assemblies UT00-UT29, which then have no Geant4 volume id, and buildVolumeIdTables aborted with "TRD volume UT00 has no usable volume id". - In that case the chamber is read from the assembly name that CurrentVolOffName still reports. - TGeo and VecGeom keep the integer lookup; their TRD hits are bit-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 54c13e3 commit 140d0e9

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎Detectors/TRD/simulation/include/TRDSimulation/Detector.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class Detector : public o2::base::DetImpl<Detector>
104104
// than hard-coded.
105105
int mChamberOffset = -1; //!
106106
int mSectorOffset = -1; //!
107+
// The chamber assemblies have no volume id when the engine collapses assemblies (native
108+
// Geant4 via VGM); the chamber is then read from the assembly name the VMC still reports.
109+
bool mChamberFromName = false; //!
107110

108111
template <typename Det>
109112
friend class o2::base::DetImpl;

‎Detectors/TRD/simulation/src/Detector.cxx‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <TGeoManager.h>
2626
#include <TVirtualMC.h>
2727

28+
#include <cstdio>
2829
#include <vector>
2930
#include <stdexcept>
3031
#include <string>
@@ -83,11 +84,17 @@ void Detector::buildVolumeIdTables()
8384
record(mRegionByVolId, vmc->VolId(name.c_str()), name[1] == 'J' ? kDrift : kAmplification, name.c_str());
8485
}
8586

86-
// The readout-chamber assemblies and the supermodule mother volumes
87+
// The readout-chamber assemblies and the supermodule mother volumes. An engine that
88+
// collapses assemblies gives the chamber assemblies no volume id at all.
8789
char volName[16];
88-
for (int idet = 0; idet < NLAYER * NSTACK; ++idet) {
89-
snprintf(volName, sizeof(volName), "UT%02d", idet);
90-
record(mChamberByVolId, vmc->VolId(volName), idet, volName);
90+
mChamberFromName = vmc->VolId("UT00") <= 0;
91+
if (mChamberFromName) {
92+
LOG(info) << "TRD: chamber assemblies have no volume id, resolving the chamber by name";
93+
} else {
94+
for (int idet = 0; idet < NLAYER * NSTACK; ++idet) {
95+
snprintf(volName, sizeof(volName), "UT%02d", idet);
96+
record(mChamberByVolId, vmc->VolId(volName), idet, volName);
97+
}
9198
}
9299
for (int sector = 0; sector < NSECTOR; ++sector) {
93100
snprintf(volName, sizeof(volName), "BTRD%d", sector);
@@ -137,11 +144,15 @@ bool Detector::ProcessHits(FairVolume* v)
137144
// level is added, removed, or flattened away by the transport engine's own conversion.
138145
if (mSectorOffset < 0) {
139146
for (int off = 0; off < 16; ++off) {
147+
int chamber = -1;
148+
if (mChamberOffset < 0 && mChamberFromName && std::sscanf(fMC->CurrentVolOffName(off), "UT%d", &chamber) == 1) {
149+
mChamberOffset = off;
150+
}
140151
const int oid = fMC->CurrentVolOffID(off, copy);
141152
if (oid <= 0 || oid >= (int)mChamberByVolId.size()) {
142153
continue;
143154
}
144-
if (mChamberOffset < 0 && mChamberByVolId[oid] >= 0) {
155+
if (mChamberOffset < 0 && !mChamberFromName && mChamberByVolId[oid] >= 0) {
145156
mChamberOffset = off;
146157
}
147158
if (mSectorByVolId[oid] >= 0) {
@@ -155,9 +166,16 @@ bool Detector::ProcessHits(FairVolume* v)
155166
LOG(info) << "TRD: chamber at mother offset " << mChamberOffset << ", supermodule at " << mSectorOffset;
156167
}
157168

158-
const int chamberVol = fMC->CurrentVolOffID(mChamberOffset, copy);
169+
int idChamber = -1;
170+
if (mChamberFromName) {
171+
if (std::sscanf(fMC->CurrentVolOffName(mChamberOffset), "UT%d", &idChamber) != 1) {
172+
idChamber = -1;
173+
}
174+
} else {
175+
const int chamberVol = fMC->CurrentVolOffID(mChamberOffset, copy);
176+
idChamber = (chamberVol > 0 && chamberVol < (int)mChamberByVolId.size()) ? mChamberByVolId[chamberVol] : -1;
177+
}
159178
const int sectorVol = fMC->CurrentVolOffID(mSectorOffset, copy);
160-
const int idChamber = (chamberVol > 0 && chamberVol < (int)mChamberByVolId.size()) ? mChamberByVolId[chamberVol] : -1;
161179
const int sector = (sectorVol > 0 && sectorVol < (int)mSectorByVolId.size()) ? mSectorByVolId[sectorVol] : -1;
162180
if (idChamber < 0 || sector < 0) {
163181
LOG(fatal) << "Cannot resolve TRD chamber/supermodule from volume " << fMC->CurrentVolName();

0 commit comments

Comments
 (0)