1212#include < IOTOFBase/GeometryTGeo.h>
1313#include < IOTOFBase/IOTOFBaseParam.h>
1414#include < TGeoManager.h>
15+ #include < TMath.h>
1516
1617namespace 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
268292void 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
291360GeometryTGeo* GeometryTGeo::Instance ()
0 commit comments