Skip to content

Commit 966097b

Browse files
committed
Possibility to define AlignParam as Local Delta
The constructors got extra argument convertLocalToGlobal (by default true) which tells that if the provided parameters correspond to the local delta (i.e. argument global == false), then it should be converted to global delta. Otherwise, the delta being local or global is fully defined by the value of the global argument. The AlignParam::applyToGeometry() accounts for the type of persistent type of delta and avoids extra global -> local conversion if mIsGlobalDelta is false.
1 parent dc60e35 commit 966097b

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/AlignParam.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ class AlignParam
3737
AlignParam(const char* symname, int algID, // volume symbolic name and its alignable ID
3838
double x, double y, double z, // delta translation
3939
double psi, double theta, double phi, // delta rotation
40-
bool global = true); // global (preferable) or local delta definition
40+
bool global = true, // global (preferable) or local delta definition
41+
bool convertLocalToGlobal = true); // if local is provided, convert it to global
4142

42-
AlignParam(const char* symname, int algID, TGeoMatrix& m, bool global = true);
43+
AlignParam(const char* symname, int algID, TGeoMatrix& m,
44+
bool global = true, // global (preferable) or local delta definition
45+
bool convertLocalToGlobal = true); // if local is provided, convert it to global
4346

4447
/// return symbolic name of the volume
4548
const std::string& getSymName() const { return mSymName; }
@@ -70,6 +73,9 @@ class AlignParam
7073
void setAlignableID(int id) { mAlignableID = id; }
7174
/// ================ methods for direct setting of delta params
7275

76+
/// set parameters
77+
void setParams(double x, double y, double z, double psi, double theta, double phi);
78+
7379
/// set parameters of global delta
7480
void setGlobalParams(double x, double y, double z, double psi, double theta, double phi);
7581

@@ -114,6 +120,9 @@ class AlignParam
114120

115121
int rectify(double zero = 1e-13);
116122

123+
bool isGlobal() const { return mIsGlobal; }
124+
void setIsGlobal(bool v) { mIsGlobal = v; }
125+
117126
protected:
118127
bool matrixToAngles(const double* rot, double& psi, double& theta, double& phi) const;
119128
void anglesToMatrix(double psi, double theta, double phi, double* rot) const;
@@ -123,8 +132,8 @@ class AlignParam
123132
private:
124133
std::string mSymName{};
125134

135+
bool mIsGlobal = true; /// is this global delta?
126136
int mAlignableID = -1; /// alignable ID (set for sensors only)
127-
128137
double mX = 0.; ///< X translation of global delta
129138
double mY = 0.; ///< Y translation of global delta
130139
double mZ = 0.; ///< Z translation of global delta
@@ -133,7 +142,7 @@ class AlignParam
133142
double mTheta = 0.; ///< "roll" : Euler angle of rotation around Y axis after 1st rotation (radians)
134143
double mPhi = 0.; ///< "yaw" : Euler angle of rotation around Z axis (radians)
135144

136-
ClassDefNV(AlignParam, 1);
145+
ClassDefNV(AlignParam, 2);
137146
};
138147

139148
} // namespace detectors

DataFormats/Detectors/Common/src/AlignParam.cxx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@ using namespace o2::detectors;
2626
AlignParam::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
//_____________________________________________________________________________
363371
void AlignParam::setRotation(double psi, double theta, double phi)
364372
{

0 commit comments

Comments
 (0)