Project
Loading...
Searching...
No Matches
GeometryTGeo.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include <TGeoManager.h>
15
16namespace o2
17{
18namespace iotof
19{
20std::unique_ptr<o2::iotof::GeometryTGeo> GeometryTGeo::sInstance;
21
22// Common i/oTOF
23std::string GeometryTGeo::sIOTOFVolumeName = "IOTOFV";
24
25// Inner TOF
26std::string GeometryTGeo::sITOFLayerName = "ITOFLayer";
27std::string GeometryTGeo::sITOFStaveName = "ITOFStave";
28std::string GeometryTGeo::sITOFModuleName = "ITOFModule";
29std::string GeometryTGeo::sITOFChipName = "ITOFChip";
30std::string GeometryTGeo::sITOFSensorName = "ITOFSensor";
31
32// Outer TOF
33std::string GeometryTGeo::sOTOFLayerName = "OTOFLayer";
34std::string GeometryTGeo::sOTOFStaveName = "OTOFStave";
35std::string GeometryTGeo::sOTOFModuleName = "OTOFModule";
36std::string GeometryTGeo::sOTOFChipName = "OTOFChip";
37std::string GeometryTGeo::sOTOFSensorName = "OTOFSensor";
38
39// Forward TOF
40std::string GeometryTGeo::sFTOFLayerName = "FTOFLayer";
41std::string GeometryTGeo::sFTOFChipName = "FTOFChip";
42std::string GeometryTGeo::sFTOFSensorName = "FTOFSensor";
43
44// Backward TOF
45std::string GeometryTGeo::sBTOFLayerName = "BTOFLayer";
46std::string GeometryTGeo::sBTOFChipName = "BTOFChip";
47std::string GeometryTGeo::sBTOFSensorName = "BTOFSensor";
48
49GeometryTGeo::GeometryTGeo(bool build, int loadTrans) : DetMatrixCache()
50{
51 if (sInstance) {
52 LOGP(fatal, "Invalid use of public constructor: o2::iotof::GeometryTGeo instance exists");
53 }
54 if (build) {
55 Build(loadTrans);
56 }
57}
58
60{
61 int numberOfStaves{0};
62
63 std::string layName = lay == 0 ? GeometryTGeo::getITOFLayerPattern() : GeometryTGeo::getOTOFLayerPattern();
64 TGeoVolume* layV = gGeoManager->GetVolume(layName.c_str());
65 if (layV == nullptr) {
66 LOG(fatal) << "Can't find volume " << layName;
67 return -1;
68 }
69
70 TObjArray* nodes = layV->GetNodes();
71 int nNodes = nodes->GetEntriesFast();
72
73 for (int j{0}; j < nNodes; ++j) {
74 if (strstr(nodes->At(j)->GetName(), lay == 0 ? GeometryTGeo::getITOFStavePattern() : GeometryTGeo::getOTOFStavePattern()) != nullptr) {
75 numberOfStaves++;
76 }
77 }
78
79 return numberOfStaves;
80}
81
83{
84 int numberOfModules{0};
85
86 std::string staveName = lay == 0 ? GeometryTGeo::getITOFStavePattern() : GeometryTGeo::getOTOFStavePattern();
87 TGeoVolume* staveV = gGeoManager->GetVolume(staveName.c_str());
88 if (staveV == nullptr) {
89 LOG(fatal) << "Can't find volume " << staveName;
90 return -1;
91 }
92
93 TObjArray* nodes = staveV->GetNodes();
94 int nNodes = nodes->GetEntriesFast();
95
96 for (int j{0}; j < nNodes; ++j) {
97 if (strstr(nodes->At(j)->GetName(), lay == 0 ? GeometryTGeo::getITOFModulePattern() : GeometryTGeo::getOTOFModulePattern()) != nullptr) {
98 numberOfModules++;
99 }
100 }
101
102 return numberOfModules;
103}
104
106{
107 int numberOfChips{0};
108
109 std::string moduleName = lay == 0 ? GeometryTGeo::getITOFModulePattern() : GeometryTGeo::getOTOFModulePattern();
110 TGeoVolume* moduleV = gGeoManager->GetVolume(moduleName.c_str());
111 if (moduleV == nullptr) {
112 LOG(fatal) << "Can't find volume " << moduleName;
113 return -1;
114 }
115
116 TObjArray* nodes = moduleV->GetNodes();
117 int nNodes = nodes->GetEntriesFast();
118
119 for (int j{0}; j < nNodes; ++j) {
120 if (strstr(nodes->At(j)->GetName(), lay == 0 ? GeometryTGeo::getITOFChipPattern() : GeometryTGeo::getOTOFChipPattern()) != nullptr) {
121 numberOfChips++;
122 }
123 }
124
125 return numberOfChips;
126}
127
129{
130 return 0;
131}
132
134{
135 return 0;
136}
137
139{
140 return lay == 0 ? 0 : mLastChipIndex[0] + 1;
141}
142
144{
145 if (index < 0 || index > mLastChipIndex[1]) {
146 LOG(fatal) << "Invalid chip index " << index;
147 return -1;
148 }
149 return index > mLastChipIndex[0] ? 1 : 0;
150}
151
152int GeometryTGeo::getIOTOFChipIndex(int lay, int sta, int mod, int chip) const
153{
154 return getIOTOFFirstChipIndex(lay) + (sta - 1) * mNumberOfChipsPerStaveIOTOF[lay] + (mod - 1) * mNumberOfChipsPerModuleIOTOF[lay] + (chip - 1);
155}
156
157bool GeometryTGeo::getIOTOFChipId(int index, int& lay, int& sta, int& mod, int& chip) const
158{
159 lay = getIOTOFLayer(index);
161 sta = mNumberOfStavesIOTOF[lay] > 0 ? index / mNumberOfChipsPerStaveIOTOF[lay] : -1;
163 mod = mNumberOfModulesIOTOF[lay] > 0 ? index / mNumberOfChipsPerModuleIOTOF[lay] : -1;
165 return true;
166}
167
169{
170 int lay, sta, mod, chip;
171 getIOTOFChipId(index, lay, sta, mod, chip);
172
173 TString path = Form("/cave_1/barrel_1/%s_2/", GeometryTGeo::getIOTOFVolPattern());
174 sta += 1;
175 mod += 1;
176 chip += 1;
177
178 if (lay == 0) {
179 path += Form("%s_1/", GeometryTGeo::getITOFLayerPattern());
180 if (mNumberOfStavesIOTOF[lay] > 0)
181 path += Form("%s_%d/", GeometryTGeo::getITOFStavePattern(), sta);
182 if (mNumberOfModulesIOTOF[lay] > 0)
183 path += Form("%s_%d/", GeometryTGeo::getITOFModulePattern(), mod);
184 if (mNumberOfChipsPerModuleIOTOF[lay] > 0)
186 } else {
187 path += Form("%s_1/", GeometryTGeo::getOTOFLayerPattern());
188 if (mNumberOfStavesIOTOF[lay] > 0)
189 path += Form("%s_%d/", GeometryTGeo::getOTOFStavePattern(), sta);
190 if (mNumberOfModulesIOTOF[lay] > 0)
191 path += Form("%s_%d/", GeometryTGeo::getOTOFModulePattern(), mod);
192 if (mNumberOfChipsPerModuleIOTOF[lay] > 0)
194 }
195
196 return path;
197}
198
200{
201 auto path = getMatrixPath(index);
202
203 static TGeoHMatrix matTmp;
204 gGeoManager->PushPath();
205
206 if (!gGeoManager->cd(path.Data())) {
207 gGeoManager->PopPath();
208 LOG(error) << "Error in cd-ing to " << path.Data();
209 return nullptr;
210 }
211
212 matTmp = *gGeoManager->GetCurrentMatrix();
213 // LOG(info) << "Path = " << path.Data();
214
215 // Restore the modeler state
216 gGeoManager->PopPath();
217
218 // account for the difference between physical sensitive layer (where charge collection is simulated) and effective sensor thicknesses
219 // TODO: apply translation by the effective sensor thickness, not yet done (see ITS)
220
221 return &matTmp;
222}
223
224void GeometryTGeo::Build(int loadTrans)
225{
226 if (isBuilt()) {
227 LOGP(warning, "Already built");
228 return; // already initialized
229 }
230
231 if (!gGeoManager) {
232 LOGP(fatal, "Geometry is not loaded");
233 }
234
235 auto& iotofPars = IOTOFBaseParam::Instance();
236 if (!iotofPars.segmentedInnerTOF && !iotofPars.segmentedOuterTOF) {
237 return;
238 }
239
240 // Inner/outer TOF
241 for (int j{0}; j < 2; ++j) {
245 }
246
247 // Forward TOF
249
250 // Backward TOF
252
253 int numberOfChips{0};
254 for (int j{0}; j < 2; ++j) {
257 numberOfChips += mNumberOfChipsIOTOF[j];
258 mLastChipIndex[j] = numberOfChips - 1;
259 }
260
261 LOG(info) << "numberOfChipsITOF = " << mNumberOfChipsIOTOF[0] << ", numberOfChipsOTOF = " << mNumberOfChipsIOTOF[1] << ", numberOfChips = " << numberOfChips << ", mNumberOfChipesPerStaveITOF" << mNumberOfChipsPerStaveIOTOF[0];
262
263 setSize(numberOfChips);
264 fillMatrixCache(loadTrans);
265 // fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
266}
267
269{
270 if (mSize < 1) {
271 LOG(warning) << "The method Build was not called yet";
272 Build(mask);
273 return;
274 }
275
276 if ((mask & o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G)) && !getCacheL2G().isFilled()) {
277 // Matrices for Local (Sensor!!! rather than the full chip) to Global frame transformation
278 LOG(info) << "Loading " << getName() << " L2G matrices from TGeo; there are " << mSize << " matrices";
279 auto& cacheL2G = getCacheL2G();
280 cacheL2G.setSize(mSize);
281
282 for (int i = 0; i < mSize; i++) {
283 TGeoHMatrix* hm = extractMatrixSensor(i);
284 cacheL2G.setMatrix(o2::math_utils::Transform3D(*hm), i);
285 }
286 }
287}
288
290{
291 if (!sInstance) {
292 sInstance = std::unique_ptr<GeometryTGeo>(new GeometryTGeo(true, 0));
293 }
294 return sInstance.get();
295}
296
297} // namespace iotof
298} // namespace o2
int32_t i
uint32_t j
Definition RawData.h:0
const char * getName() const
int mSize
prebooked number of sensors
const MatrixCache< Mat3D > & getCacheL2G() const
static const char * getITOFChipPattern()
static std::string sFTOFSensorName
TString getMatrixPath(int index) const
static std::string sOTOFLayerName
static const char * getIOTOFVolPattern()
static const char * getOTOFLayerPattern()
bool getIOTOFChipId(int index, int &lay, int &sta, int &mod, int &chip) const
static const char * getOTOFModulePattern()
static std::string sOTOFSensorName
static std::string sIOTOFVolumeName
static const char * getITOFModulePattern()
void fillMatrixCache(int mask)
static const char * getOTOFSensorPattern()
static std::string sITOFStaveName
static std::string sFTOFChipName
int extractNumberOfModulesIOTOF(int lay) const
static std::string sOTOFChipName
static std::string sITOFModuleName
static const char * getITOFStavePattern()
static std::string sFTOFLayerName
int extractNumberOfChipsFTOF() const
static const char * getITOFSensorPattern()
static const char * getOTOFStavePattern()
int getIOTOFLayer(int index) const
int getIOTOFFirstChipIndex(int lay) const
GeometryTGeo(bool build=false, int loadTrans=0)
static std::string sBTOFSensorName
static std::string sBTOFChipName
static const char * getOTOFChipPattern()
static std::string sITOFChipName
int extractNumberOfChipsPerModuleIOTOF(int lay) const
void Build(int loadTrans)
static std::string sOTOFModuleName
int extractNumberOfStavesIOTOF(int lay) const
static std::string sOTOFStaveName
static std::string sITOFSensorName
static GeometryTGeo * Instance()
static const char * getITOFLayerPattern()
TGeoHMatrix * extractMatrixSensor(int index) const
static std::string sITOFLayerName
int getIOTOFChipIndex(int lay, int sta, int mod, int chip) const
int extractNumberOfChipsBTOF() const
static std::string sBTOFLayerName
GLuint index
Definition glcorearb.h:781
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLint GLuint mask
Definition glcorearb.h:291
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static constexpr int L2G
Definition Cartesian.h:54
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"