Skip to content

Commit 52b5044

Browse files
authored
Revision of material/medium index access; Simplifications in Base/Detector
* remove virtual keyword from some functions * do not use pointers to containers * use map instead of vector for index lookup, since the index might be sparse * rename getMaterial ---> getMaterialID for better clarity * remove getter to underlying container (not used) * corresponding changes in EMCAL, TOF, TPC detector classes
1 parent 0175d3f commit 52b5044

5 files changed

Lines changed: 143 additions & 129 deletions

File tree

Detectors/Base/include/DetectorsBase/Detector.h

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#ifndef ALICEO2_BASE_DETECTOR_H_
1515
#define ALICEO2_BASE_DETECTOR_H_
1616

17-
#include <vector>
17+
#include <map>
1818
#include <memory>
1919

2020
#include "FairDetector.h" // for FairDetector
@@ -38,15 +38,15 @@ class Detector : public FairDetector
3838
~Detector() override;
3939

4040
// Module composition
41-
virtual void Material(Int_t imat, const char *name, Float_t a, Float_t z, Float_t dens, Float_t radl, Float_t absl,
42-
Float_t *buf = nullptr, Int_t nwbuf = 0) const;
41+
void Material(Int_t imat, const char *name, Float_t a, Float_t z, Float_t dens, Float_t radl, Float_t absl,
42+
Float_t *buf = nullptr, Int_t nwbuf = 0);
4343

44-
virtual void Mixture(Int_t imat, const char *name, Float_t *a, Float_t *z, Float_t dens, Int_t nlmat,
45-
Float_t *wmat) const;
44+
void Mixture(Int_t imat, const char *name, Float_t *a, Float_t *z, Float_t dens, Int_t nlmat,
45+
Float_t *wmat);
4646

47-
virtual void Medium(Int_t numed, const char *name, Int_t nmat, Int_t isvol, Int_t ifield, Float_t fieldm,
48-
Float_t tmaxfd, Float_t stemax, Float_t deemax, Float_t epsil, Float_t stmin, Float_t *ubuf = nullptr,
49-
Int_t nbuf = 0) const;
47+
void Medium(Int_t numed, const char *name, Int_t nmat, Int_t isvol, Int_t ifield, Float_t fieldm,
48+
Float_t tmaxfd, Float_t stemax, Float_t deemax, Float_t epsil, Float_t stmin, Float_t *ubuf = nullptr,
49+
Int_t nbuf = 0);
5050

5151
/// Define a rotation matrix. angles are in degrees.
5252
/// \param nmat on output contains the number assigned to the rotation matrix
@@ -56,8 +56,8 @@ class Detector : public FairDetector
5656
/// \param phi1 azimuthal angle for axis I
5757
/// \param phi2 azimuthal angle for axis II
5858
/// \param phi3 azimuthal angle for axis III
59-
virtual void Matrix(Int_t &nmat, Float_t theta1, Float_t phi1, Float_t theta2, Float_t phi2, Float_t theta3,
60-
Float_t phi3) const;
59+
void Matrix(Int_t &nmat, Float_t theta1, Float_t phi1, Float_t theta2, Float_t phi2, Float_t theta3,
60+
Float_t phi3) const;
6161

6262
static void setDensityFactor(Float_t density)
6363
{
@@ -82,11 +82,25 @@ class Detector : public FairDetector
8282
Double_t width, Double_t tilt, Double_t lthick = 0., Double_t dthick = 0.,
8383
UInt_t detType = 0, Int_t buildFlag = 0);
8484

85-
int getMaterial(int imat) const { return (*mMapMaterial.get())[imat]; }
86-
int getMedium (int imed) const { return (*mMapMedium .get())[imed]; }
85+
// returns global material ID given a "local" material ID for this detector
86+
// returns -1 in case local ID not found
87+
int getMaterialID(int imat) const {
88+
auto iter = mMapMaterial.find(imat);
89+
if (iter != mMapMaterial.end()){
90+
return iter->second;
91+
}
92+
return -1;
93+
}
8794

88-
const std::vector<int>& getMapMaterial() const { return *mMapMaterial.get(); }
89-
const std::vector<int>& getMapMedium() const { return *mMapMedium .get(); }
95+
// returns global medium ID given a "local" medium ID for this detector
96+
// returns -1 in case local ID not found
97+
int getMediumID(int imed) const {
98+
auto iter = mMapMedium.find(imed);
99+
if (iter != mMapMedium.end()){
100+
return iter->second;
101+
}
102+
return -1;
103+
}
90104

91105
protected:
92106
Detector(const Detector &origin);
@@ -95,18 +109,18 @@ class Detector : public FairDetector
95109

96110

97111
/// Mapping of the ALICE internal material number to the one
98-
/// automatically assigned by geant.
99-
/// This is required for easily being able to copy the geometry setup
112+
/// automatically assigned by geant/TGeo.
113+
/// This is required to easily being able to copy the geometry setup
100114
/// used in AliRoot
101-
std::unique_ptr<std::vector<int>> mMapMaterial; //!< material mapping
115+
std::map<int, int> mMapMaterial; //!< material mapping
102116

103117
/// See comment for mMapMaterial
104-
std::unique_ptr<std::vector<int>> mMapMedium; //!< medium mapping
118+
std::map<int, int> mMapMedium; //!< medium mapping
105119

106120
static Float_t mDensityFactor; //! factor that is multiplied to all material densities (ONLY for
107121
// systematic studies)
108122

109-
ClassDefOverride(Detector, 0) // Base class for ALICE Modules
123+
ClassDefOverride(Detector, 1) // Base class for ALICE Modules
110124
};
111125
}
112126
}

Detectors/Base/src/Detector.cxx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ Float_t Detector::mDensityFactor = 1.0;
2727

2828
Detector::Detector()
2929
: FairDetector(),
30-
mMapMaterial(new std::vector<int>(100)),
31-
mMapMedium(new std::vector<int>(100))
30+
mMapMaterial(),
31+
mMapMedium()
3232
{
3333
}
3434

3535
Detector::Detector(const char *name, Bool_t Active, Int_t DetId)
3636
: FairDetector(name, Active, DetId),
37-
mMapMaterial(new std::vector<int>(100)),
38-
mMapMedium(new std::vector<int>(100))
37+
mMapMaterial(),
38+
mMapMedium()
3939
{
4040
}
4141

4242
Detector::Detector(const Detector &rhs)
4343
: FairDetector(rhs),
44-
mMapMaterial(new std::vector<int>(*rhs.mMapMaterial.get())),
45-
mMapMedium(new std::vector<int>(*rhs.mMapMedium.get()))
44+
mMapMaterial(rhs.mMapMaterial),
45+
mMapMedium(rhs.mMapMedium)
4646
{ }
4747

4848
Detector::~Detector()
@@ -60,7 +60,7 @@ Detector &Detector::operator=(const Detector &rhs)
6060
}
6161

6262
void Detector::Material(Int_t imat, const char *name, Float_t a, Float_t z, Float_t dens,
63-
Float_t radl, Float_t absl, Float_t *buf, Int_t nwbuf) const
63+
Float_t radl, Float_t absl, Float_t *buf, Int_t nwbuf)
6464
{
6565
TString uniquename = GetName();
6666
uniquename.Append("_");
@@ -69,11 +69,11 @@ void Detector::Material(Int_t imat, const char *name, Float_t a, Float_t z, Floa
6969
// Check this!!!
7070
int kmat=-1;
7171
TVirtualMC::GetMC()->Material(kmat, uniquename.Data(), a, z, dens * mDensityFactor, radl, absl, buf, nwbuf);
72-
(*mMapMaterial.get())[imat] = kmat;
72+
mMapMaterial[imat] = kmat;
7373
}
7474

7575
void Detector::Mixture(Int_t imat, const char *name, Float_t *a, Float_t *z, Float_t dens,
76-
Int_t nlmat, Float_t *wmat) const
76+
Int_t nlmat, Float_t *wmat)
7777
{
7878
TString uniquename = GetName();
7979
uniquename.Append("_");
@@ -82,23 +82,23 @@ void Detector::Mixture(Int_t imat, const char *name, Float_t *a, Float_t *z, Flo
8282
// Check this!!!
8383
int kmat=-1;
8484
TVirtualMC::GetMC()->Mixture(kmat, uniquename.Data(), a, z, dens * mDensityFactor, nlmat, wmat);
85-
(*mMapMaterial.get())[imat] = kmat;
85+
mMapMaterial[imat] = kmat;
8686
}
8787

8888
void Detector::Medium(Int_t numed, const char *name, Int_t nmat, Int_t isvol, Int_t ifield,
8989
Float_t fieldm, Float_t tmaxfd, Float_t stemax, Float_t deemax, Float_t epsil,
90-
Float_t stmin, Float_t *ubuf, Int_t nbuf) const
90+
Float_t stmin, Float_t *ubuf, Int_t nbuf)
9191
{
9292
TString uniquename = GetName();
9393
uniquename.Append("_");
9494
uniquename.Append(name);
9595

9696
// Check this!!!
9797
int kmed = -1;
98-
const int kmat = (*mMapMaterial.get())[nmat];
98+
const int kmat = mMapMaterial[nmat];
9999
TVirtualMC::GetMC()->Medium(kmed, uniquename.Data(), kmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax, epsil,
100100
stmin, ubuf, nbuf);
101-
(*mMapMedium.get())[numed] = kmed;
101+
mMapMedium[numed] = kmed;
102102
}
103103

104104
void Detector::Matrix(Int_t &nmat, Float_t theta1, Float_t phi1, Float_t theta2, Float_t phi2,

Detectors/EMCAL/simulation/src/Detector.cxx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void Detector::ConstructGeometry()
8585
envelopA[1] = 30;
8686
envelopA[2] = 20;
8787

88-
TVirtualMC::GetMC()->Gsvolu("XEN1", "BOX", getMapMedium()[ID_SC], envelopA, 3) ;
88+
TVirtualMC::GetMC()->Gsvolu("XEN1", "BOX", getMediumID(ID_SC), envelopA, 3) ;
8989
mEnvelop1.Set(3);
9090

9191
for(Int_t i=0; i<3; i++) mEnvelop1[i] = envelopA[i]; // 23-may-05
@@ -108,7 +108,7 @@ void Detector::ConstructGeometry()
108108
envelopA[9] = envelopA[6] ;
109109
// radii are the same.
110110

111-
TVirtualMC::GetMC()->Gsvolu("XEN1", "PGON", getMapMedium()[ID_AIR], envelopA, 10) ; // Polygone filled with air
111+
TVirtualMC::GetMC()->Gsvolu("XEN1", "PGON", getMediumID(ID_AIR), envelopA, 10) ; // Polygone filled with air
112112
mEnvelop1.Set(10, envelopA);
113113

114114
LOG(DEBUG2) << "ConstructGeometry: XEN1 = " << envelopA[5] << ", " << envelopA[6] << FairLogger::endl;
@@ -201,15 +201,15 @@ void Detector::CreateShiskebabGeometry()
201201
for (Int_t i = 0; i < 3; i++)
202202
parSCM0[i] = mParEMOD[i] - wallThickness;
203203
parSCM0[3] = mParEMOD[3];
204-
TVirtualMC::GetMC()->Gsvolu("SCM0", "TRD1", getMapMedium()[ID_AIR], parSCM0, 4);
204+
TVirtualMC::GetMC()->Gsvolu("SCM0", "TRD1", getMediumID(ID_AIR), parSCM0, 4);
205205
TVirtualMC::GetMC()->Gspos("SCM0", 1, "EMOD", 0., 0., 0., 0, "ONLY");
206206
} else {
207207
Double_t wTh = g->GetLateralSteelStrip();
208208
parSCM0[0] = mParEMOD[0] - wTh + tanTrd1 * g->GetTrd1AlFrontThick();
209209
parSCM0[1] = mParEMOD[1] - wTh;
210210
parSCM0[2] = mParEMOD[2] - wTh;
211211
parSCM0[3] = mParEMOD[3] - g->GetTrd1AlFrontThick() / 2.;
212-
TVirtualMC::GetMC()->Gsvolu("SCM0", "TRD1", getMapMedium()[ID_AIR], parSCM0, 4);
212+
TVirtualMC::GetMC()->Gsvolu("SCM0", "TRD1", getMediumID(ID_AIR), parSCM0, 4);
213213
Double_t zshift = g->GetTrd1AlFrontThick() / 2.;
214214
TVirtualMC::GetMC()->Gspos("SCM0", 1, "EMOD", 0., 0., zshift, 0, "ONLY");
215215
//
@@ -243,7 +243,7 @@ void Detector::CreateShiskebabGeometry()
243243
LOG(DEBUG3) << " par[" << std::setw(2) << std::setprecision(2) << i << "] " << std::setw(9)
244244
<< std::setprecision(4) << parTRAP[i] << FairLogger::endl;
245245

246-
TVirtualMC::GetMC()->Gsvolu("SCMX", "TRAP", getMapMedium()[ID_SC], parTRAP, 11);
246+
TVirtualMC::GetMC()->Gsvolu("SCMX", "TRAP", getMediumID(ID_SC), parTRAP, 11);
247247
xpos = +(parSCM0[1] + parSCM0[0]) / 4.;
248248
TVirtualMC::GetMC()->Gspos("SCMX", 1, "SCMY", xpos, 0.0, 0.0, 0, "ONLY");
249249

@@ -262,7 +262,7 @@ void Detector::CreateShiskebabGeometry()
262262
if (!gn.Contains("V1")) {
263263
par[1] = parSCM0[2] / 2; // y
264264
par[2] = g->GetECPbRadThick() / 2.; // z
265-
TVirtualMC::GetMC()->Gsvolu("PBTI", "BOX", getMapMedium()[ID_PB], dummy, 0);
265+
TVirtualMC::GetMC()->Gsvolu("PBTI", "BOX", getMediumID(ID_PB), dummy, 0);
266266

267267
zpos = -mSampleWidth * g->GetNECLayers() / 2. + g->GetECPbRadThick() / 2.;
268268
LOG(DEBUG2) << " Pb tiles \n";
@@ -282,7 +282,7 @@ void Detector::CreateShiskebabGeometry()
282282
par[1] = parSCM0[2] / 2.; // y
283283
par[2] = g->GetTrd1BondPaperThick() / 2.; // z
284284
par[0] = parSCM0[0] / 2.; // x
285-
TVirtualMC::GetMC()->Gsvolu("PAP1", "BOX", getMapMedium()[ID_PAPER], par, 3);
285+
TVirtualMC::GetMC()->Gsvolu("PAP1", "BOX", getMediumID(ID_PAPER), par, 3);
286286

287287
xpos = par[0] - xCenterSCMX;
288288
zpos = -parSCM0[3] + g->GetTrd1BondPaperThick() / 2.;
@@ -296,7 +296,7 @@ void Detector::CreateShiskebabGeometry()
296296
par[2] = g->GetECPbRadThick() / 2. + g->GetTrd1BondPaperThick(); // z
297297
par[0] = (parSCM0[0] + tanBetta * dz) / 2.;
298298
TString pa(Form("PA%2.2i", nr));
299-
TVirtualMC::GetMC()->Gsvolu(pa.Data(), "BOX", getMapMedium()[ID_PAPER], par, 3);
299+
TVirtualMC::GetMC()->Gsvolu(pa.Data(), "BOX", getMediumID(ID_PAPER), par, 3);
300300

301301
xpos = par[0] - xCenterSCMX;
302302
zpos = -parSCM0[3] + dz + par[2];
@@ -305,7 +305,7 @@ void Detector::CreateShiskebabGeometry()
305305
// Pb
306306
TString pb(Form("PB%2.2i", nr));
307307
par[2] = g->GetECPbRadThick() / 2.; // z
308-
TVirtualMC::GetMC()->Gsvolu(pb.Data(), "BOX", getMapMedium()[ID_PB], par, 3);
308+
TVirtualMC::GetMC()->Gsvolu(pb.Data(), "BOX", getMediumID(ID_PB), par, 3);
309309
TVirtualMC::GetMC()->Gspos(pb.Data(), 1, pa.Data(), 0.0, 0.0, 0.0, 0, "ONLY");
310310
}
311311
}
@@ -441,9 +441,9 @@ void Detector::CreateSmod(const char* mother)
441441
par[1] = g->GetShellThickness() / 2.;
442442
par[2] = g->GetEtaModuleSize() * g->GetNZ() / 2. + 5;
443443

444-
TVirtualMC::GetMC()->Gsvolu("SMOD", "BOX", getMapMedium()[ID_AIR], par, 3);
444+
TVirtualMC::GetMC()->Gsvolu("SMOD", "BOX", getMediumID(ID_AIR), par, 3);
445445

446-
LOG(DEBUG2) << "SMOD in WSUC : tmed " << getMapMedium()[ID_AIR] << " | dx " << std::setw(7) << std::setprecision(2)
446+
LOG(DEBUG2) << "SMOD in WSUC : tmed " << getMediumID(ID_AIR) << " | dx " << std::setw(7) << std::setprecision(2)
447447
<< par[0] << " dy " << std::setw(7) << std::setprecision(2) << par[1] << " dz " << std::setw(7)
448448
<< std::setprecision(2) << par[2] << " (SMOD, BOX)\n";
449449
mSmodPar0 = par[0];
@@ -514,7 +514,7 @@ void Detector::CreateSmod(const char* mother)
514514
LOG(ERROR) << "Unkown SM Type!!\n";
515515

516516
if (SMOrder == 1) { // first time, create the SM
517-
TVirtualMC::GetMC()->Gsvolu(smName.Data(), "BOX", getMapMedium()[ID_AIR], parC, 3);
517+
TVirtualMC::GetMC()->Gsvolu(smName.Data(), "BOX", getMediumID(ID_AIR), parC, 3);
518518

519519
LOG(DEBUG2) << R"( Super module with name \")" << smName << R"(\" was created in \"box\" with: par[0] = )" << parC[0]
520520
<< ", par[1] = " << parC[1] << ", par[2] = " << parC[2] << FairLogger::endl;
@@ -544,9 +544,9 @@ void Detector::CreateSmod(const char* mother)
544544
// Steel plate
545545
if (g->GetSteelFrontThickness() > 0.0) { // 28-mar-05
546546
par[0] = g->GetSteelFrontThickness() / 2.;
547-
TVirtualMC::GetMC()->Gsvolu("STPL", "BOX", getMapMedium()[ID_STEEL], par, 3);
547+
TVirtualMC::GetMC()->Gsvolu("STPL", "BOX", getMediumID(ID_STEEL), par, 3);
548548

549-
LOG(DEBUG1) << "tmed " << getMapMedium()[ID_STEEL] << " | dx " << std::setw(7) << std::setprecision(2) << par[0]
549+
LOG(DEBUG1) << "tmed " << getMediumID(ID_STEEL) << " | dx " << std::setw(7) << std::setprecision(2) << par[0]
550550
<< " dy " << std::setw(7) << std::setprecision(2) << par[1] << " dz " << std::setw(7)
551551
<< std::setprecision(2) << par[2] << " (STPL) \n";
552552

@@ -573,7 +573,7 @@ void Detector::CreateEmod(const char* mother, const char* child)
573573
mParEMOD[2] = g->GetPhiModuleSize() / 2.;
574574
; // dy
575575
mParEMOD[3] = g->GetLongModuleSize() / 2.; // dz
576-
TVirtualMC::GetMC()->Gsvolu(child, "TRD1", getMapMedium()[ID_STEEL], mParEMOD, 4);
576+
TVirtualMC::GetMC()->Gsvolu(child, "TRD1", getMediumID(ID_STEEL), mParEMOD, 4);
577577
}
578578

579579
Int_t nr = 0;
@@ -663,7 +663,7 @@ void Detector::CreateAlFrontPlate(const char* mother, const char* child)
663663
parALFP[2] = g->GetPhiModuleSize() / 2. - g->GetLateralSteelStrip(); // dy
664664
parALFP[3] = g->GetTrd1AlFrontThick() / 2.; // dz
665665

666-
TVirtualMC::GetMC()->Gsvolu(child, "TRD1", getMapMedium()[ID_AL], parALFP, 4);
666+
TVirtualMC::GetMC()->Gsvolu(child, "TRD1", getMediumID(ID_AL), parALFP, 4);
667667

668668
zposALFP = -mParEMOD[3] + g->GetTrd1AlFrontThick() / 2.;
669669
TVirtualMC::GetMC()->Gspos(child, 1, mother, 0.0, 0.0, zposALFP, 0, "ONLY");
@@ -681,14 +681,14 @@ void Detector::Trd1Tower1X1(Double_t* parSCM0)
681681
// and as consequence the same abs is scheme
682682
LOG(DEBUG2) << "Trd1Tower1X1() : Create SCMX(SCMY) as SCM0\n";
683683

684-
TVirtualMC::GetMC()->Gsvolu("SCMY", "TRD1", getMapMedium()[ID_AIR], parSCM0, 4);
684+
TVirtualMC::GetMC()->Gsvolu("SCMY", "TRD1", getMediumID(ID_AIR), parSCM0, 4);
685685
TVirtualMC::GetMC()->Gspos("SCMY", 1, "SCM0", 0.0, 0.0, 0.0, 0, "ONLY");
686-
TVirtualMC::GetMC()->Gsvolu("SCMX", "TRD1", getMapMedium()[ID_SC], parSCM0, 4);
686+
TVirtualMC::GetMC()->Gsvolu("SCMX", "TRD1", getMediumID(ID_SC), parSCM0, 4);
687687
TVirtualMC::GetMC()->Gspos("SCMX", 1, "SCMY", 0.0, 0.0, 0.0, 0, "ONLY");
688688

689689
// should be defined once
690690
Double_t* dummy = nullptr;
691-
TVirtualMC::GetMC()->Gsvolu("PBTI", "BOX", getMapMedium()[ID_PB], dummy, 0);
691+
TVirtualMC::GetMC()->Gsvolu("PBTI", "BOX", getMediumID(ID_PB), dummy, 0);
692692

693693
PbInTrd1(parSCM0, "SCMX");
694694

@@ -719,7 +719,7 @@ void Detector::Trd1Tower3X3(const Double_t* parSCM0)
719719
Double_t ndiv = 3., xpos = 0.0;
720720

721721
// should be defined once
722-
TVirtualMC::GetMC()->Gsvolu("PBTI", "BOX", getMapMedium()[ID_PB], dummy, 0);
722+
TVirtualMC::GetMC()->Gsvolu("PBTI", "BOX", getMediumID(ID_PB), dummy, 0);
723723

724724
for (Int_t ix = 1; ix <= 3; ix++) { // 3X3
725725
scmx = "SCX"; // Nov 10,2006
@@ -757,7 +757,7 @@ void Detector::Trd1Tower3X3(const Double_t* parSCM0)
757757
<< std::setprecision(4) << parTRAP[i] << FairLogger::endl;
758758

759759
scmx += ix;
760-
TVirtualMC::GetMC()->Gsvolu(scmx.Data(), "TRAP", getMapMedium()[ID_SC], parTRAP, 11);
760+
TVirtualMC::GetMC()->Gsvolu(scmx.Data(), "TRAP", getMediumID(ID_SC), parTRAP, 11);
761761
TVirtualMC::GetMC()->Gspos(scmx.Data(), 1, "SCMY", xpos, 0.0, 0.0, 0, "ONLY");
762762

763763
PbInTrap(parTRAP, scmx);

0 commit comments

Comments
 (0)