Skip to content

Commit fb06b06

Browse files
maciaccoGiorgioAlbertoLucia
authored andcommitted
add tracking matrix cache
1 parent 1a866c4 commit fb06b06

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

Detectors/Upgrades/ALICE3/IOTOF/base/include/IOTOFBase/GeometryTGeo.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class GeometryTGeo : public o2::detectors::DetMatrixCache
2323
{
2424
public:
2525
using DetMatrixCache::getMatrixL2G;
26+
using DetMatrixCache::getMatrixT2L;
2627

2728
GeometryTGeo(bool build = false, int loadTrans = 0);
2829
void Build(int loadTrans);
@@ -94,8 +95,31 @@ class GeometryTGeo : public o2::detectors::DetMatrixCache
9495
/// for a given chip 'index' by querying the TGeoManager
9596
TGeoHMatrix* extractMatrixSensor(int index) const;
9697

98+
// sensor ref X and alpha
99+
void extractSensorXAlpha(int, float&, float&);
100+
101+
// create matrix for tracking to local frame for IOTOF
102+
TGeoHMatrix& createT2LMatrix(int);
103+
97104
TString getMatrixPath(int index) const;
98105

106+
// cache for tracking frames
107+
void defineSensors();
108+
bool isTrackingFrameCached() const { return !mCacheRefX.empty(); }
109+
void fillTrackingFramesCache();
110+
111+
float getSensorRefAlpha(int chipId) const
112+
{
113+
const int local = chipId;
114+
return mCacheRefAlpha[local];
115+
}
116+
117+
float getSensorX(int chipId) const
118+
{
119+
const int local = chipId;
120+
return mCacheRefX[local];
121+
}
122+
99123
protected:
100124
// Determine the number of active parts in the geometry
101125
int extractNumberOfStavesIOTOF(int lay) const;
@@ -145,6 +169,10 @@ class GeometryTGeo : public o2::detectors::DetMatrixCache
145169
// Backward TOF
146170
int mNumberOfChipsBTOF;
147171

172+
std::vector<int> sensors;
173+
std::vector<float> mCacheRefX; /// cache for X of IOTOF
174+
std::vector<float> mCacheRefAlpha; /// cache for sensor ref alpha IOTOF
175+
148176
private:
149177
static std::unique_ptr<o2::iotof::GeometryTGeo> sInstance;
150178
};

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <IOTOFBase/GeometryTGeo.h>
1313
#include <IOTOFBase/IOTOFBaseParam.h>
1414
#include <TGeoManager.h>
15+
#include <TMath.h>
1516

1617
namespace o2
1718
{
@@ -261,8 +262,31 @@ void GeometryTGeo::Build(int loadTrans)
261262
LOG(info) << "numberOfChipsITOF = " << mNumberOfChipsIOTOF[0] << ", numberOfChipsOTOF = " << mNumberOfChipsIOTOF[1] << ", numberOfChips = " << numberOfChips << ", mNumberOfChipesPerStaveITOF" << mNumberOfChipsPerStaveIOTOF[0];
262263

263264
setSize(numberOfChips);
265+
defineSensors();
266+
fillTrackingFramesCache();
264267
fillMatrixCache(loadTrans);
265-
// fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
268+
// fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::L2G));
269+
}
270+
271+
void GeometryTGeo::defineSensors()
272+
{
273+
for (int i = 0; i < mSize; i++) {
274+
sensors.push_back(i);
275+
}
276+
}
277+
278+
void GeometryTGeo::fillTrackingFramesCache()
279+
{
280+
// fill for every sensor of IOTOF its tracking frame parameters
281+
if (!isTrackingFrameCached() && !sensors.empty()) {
282+
size_t newSize = sensors.size();
283+
mCacheRefX.resize(newSize);
284+
mCacheRefAlpha.resize(newSize);
285+
for (int i = 0; i < newSize; i++) {
286+
int sensorId = sensors[i];
287+
extractSensorXAlpha(sensorId, mCacheRefX[i], mCacheRefAlpha[i]);
288+
}
289+
}
266290
}
267291

268292
void GeometryTGeo::fillMatrixCache(int mask)
@@ -286,6 +310,51 @@ void GeometryTGeo::fillMatrixCache(int mask)
286310
cacheL2G.setMatrix(o2::math_utils::Transform3D(*hm), i);
287311
}
288312
}
313+
314+
// build T2L matrices for IOTOF
315+
if ((mask & o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L)) && !getCacheT2L().isFilled()) {
316+
LOGP(info, "Loading {} T2L matrices from TGeo for IOTOF", getName());
317+
if (sensors.size()) {
318+
int m_Size = sensors.size();
319+
auto& cacheT2L = getCacheT2L();
320+
cacheT2L.setSize(m_Size);
321+
for (int i = 0; i < m_Size; i++) {
322+
int sensorID = sensors[i];
323+
TGeoHMatrix& hm = createT2LMatrix(sensorID);
324+
cacheT2L.setMatrix(Mat3D(hm), i);
325+
}
326+
}
327+
}
328+
}
329+
330+
void GeometryTGeo::extractSensorXAlpha(int chipID, float& x, float& alp)
331+
{
332+
double locA[3] = {-100., 0., 0.}, locB[3] = {100., 0., 0.}, gloA[3], gloB[3];
333+
double xp{0}, yp{0};
334+
335+
const TGeoHMatrix* matL2G = extractMatrixSensor(chipID);
336+
matL2G->LocalToMaster(locA, gloA);
337+
matL2G->LocalToMaster(locB, gloB);
338+
double dx = gloB[0] - gloA[0], dy = gloB[1] - gloA[1];
339+
double t = (gloB[0] * dx + gloB[1] * dy) / (dx * dx + dy * dy);
340+
xp = gloB[0] - dx * t;
341+
yp = gloB[1] - dy * t;
342+
343+
alp = std::atan2(yp, xp);
344+
x = std::hypot(xp, yp);
345+
o2::math_utils::bringTo02Pi(alp);
346+
}
347+
348+
TGeoHMatrix& GeometryTGeo::createT2LMatrix(int chipID)
349+
{
350+
static TGeoHMatrix t2l;
351+
t2l.Clear();
352+
float alpha = getSensorRefAlpha(chipID);
353+
t2l.RotateZ(alpha * TMath::RadToDeg());
354+
const TGeoHMatrix* matL2G = extractMatrixSensor(chipID);
355+
const TGeoHMatrix& matL2Gi = matL2G->Inverse();
356+
t2l.MultiplyLeft(&matL2Gi);
357+
return t2l;
289358
}
290359

291360
GeometryTGeo* GeometryTGeo::Instance()

0 commit comments

Comments
 (0)