@@ -26,32 +26,32 @@ using namespace o2::detectors;
2626AlignParam::AlignParam (const char * symname, int algID, // volume symbolic name and its alignable ID
2727 double x, double y, double z, // delta translation
2828 double psi, double theta, double phi, // delta rotation
29- bool global) // global (preferable) or local delta definition
30- : mSymName(symname), mAlignableID(algID)
29+ bool global, // global (preferable) or local delta definition
30+ bool convertLocalToGlobal) // if local is provided, convert it to global
31+ : mSymName(symname), mIsGlobal(global || convertLocalToGlobal), mAlignableID(algID)
3132{
3233 // / standard constructor with 3 translation + 3 rotation parameters
3334 // / If the user explicitly sets the global variable to false then the
3435 // / parameters are interpreted as giving the local transformation.
3536 // / This requires to have a gGeoMenager active instance, otherwise the
3637 // / constructor will fail (no object created)
3738
38- if (global) {
39- setGlobalParams (x, y, z, psi, theta, phi);
40- } else {
39+ setParams (x, y, z, psi, theta, phi);
40+ if (!global && convertLocalToGlobal) {
4141 setLocalParams (x, y, z, psi, theta, phi);
4242 }
4343}
4444
4545// ___________________________________________________
46- AlignParam::AlignParam (const char * symname, int algID, TGeoMatrix& m, bool global)
47- : mSymName(symname), mAlignableID(algID)
46+ AlignParam::AlignParam (const char * symname, int algID, TGeoMatrix& m, bool global, bool convertLocalToGlobal )
47+ : mSymName(symname), mIsGlobal(global || convertLocalToGlobal), mAlignableID(algID)
4848{
4949 setTranslation (m);
5050 if (!setRotation (m)) {
5151 const double * rot = m.GetRotationMatrix ();
5252 throw std::runtime_error (fmt::format (" Failed to extract roll-pitch-yall angles from [[{},{},{}], [{},{},{}], [{},{},{}] for {}" , rot[0 ], rot[1 ], rot[2 ], rot[3 ], rot[4 ], rot[5 ], rot[6 ], rot[7 ], rot[8 ], symname));
5353 }
54- if (!global && !setLocalParams (mX , mY , mZ , mPsi , mTheta , mPhi )) {
54+ if (!global && convertLocalToGlobal && !setLocalParams (mX , mY , mZ , mPsi , mTheta , mPhi )) {
5555 throw std::runtime_error (fmt::format (" Alignment creation for {} failed: geomManager is absent" , symname));
5656 }
5757}
@@ -223,6 +223,10 @@ bool AlignParam::createLocalMatrix(TGeoHMatrix& m) const
223223 // In case that the TGeo was not initialized or not closed,
224224 // returns false and the object parameters are not set.
225225 //
226+ m = createMatrix ();
227+ if (!mIsGlobal ) {
228+ return true ;
229+ }
226230 if (!gGeoManager || !gGeoManager ->IsClosed ()) {
227231 LOG (error) << " Can't get the local alignment object parameters! gGeoManager doesn't exist or it is still open!" ;
228232 return false ;
@@ -247,7 +251,6 @@ bool AlignParam::createLocalMatrix(TGeoHMatrix& m) const
247251 LOG (error) << " Volume name or path " << symname << " is not valid!" ;
248252 return false ;
249253 }
250- m = createMatrix ();
251254 TGeoHMatrix gprime, gprimeinv;
252255 gprime = *node->GetMatrix ();
253256 gprimeinv = gprime.Inverse ();
@@ -302,18 +305,15 @@ bool AlignParam::applyToGeometry() const
302305 }
303306
304307 // double threshold = 0.001;
305-
306- TGeoHMatrix gprime = *node->GetMatrix ();
307- TGeoHMatrix align = createMatrix ();
308- gprime.MultiplyLeft (&align);
309- TGeoHMatrix* ginv = new TGeoHMatrix; // TGeoPhysicalNode takes and manages raw pointer, need naked new!
310- TGeoHMatrix* g = node->GetMatrix (node->GetLevel () - 1 );
311- *ginv = g->Inverse ();
312- *ginv *= gprime;
313-
308+ TGeoHMatrix* align = new TGeoHMatrix (createMatrix ());
309+ if (mIsGlobal ) {
310+ align->Multiply (node->GetMatrix ());
311+ TGeoHMatrix* g = node->GetMatrix (node->GetLevel () - 1 );
312+ align->MultiplyLeft (node->GetMatrix (node->GetLevel () - 1 )->Inverse ());
313+ }
314314 LOG (debug) << " Aligning volume " << symname;
315315
316- node->Align (ginv );
316+ node->Align (align );
317317
318318 return true ;
319319}
@@ -359,6 +359,14 @@ void AlignParam::setGlobalParams(double x, double y, double z, double psi, doubl
359359 setRotation (psi, theta, phi);
360360}
361361
362+ // _____________________________________________________________________________
363+ void AlignParam::setParams (double x, double y, double z, double psi, double theta, double phi)
364+ {
365+ // / set parameters of global delta
366+ setTranslation (x, y, z);
367+ setRotation (psi, theta, phi);
368+ }
369+
362370// _____________________________________________________________________________
363371void AlignParam::setRotation (double psi, double theta, double phi)
364372{
0 commit comments