Skip to content

Commit 1bcde3f

Browse files
committed
something with ITS3
Signed-off-by: Felix Schlepper <[email protected]>
1 parent 65090ad commit 1bcde3f

File tree

15 files changed

+409
-461
lines changed

15 files changed

+409
-461
lines changed

Detectors/ITSMFT/ITS/simulation/include/ITSSimulation/Detector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class Detector : public o2::base::DetImpl<Detector>
216216

217217
/// Return Chip Volume UID
218218
/// \param id volume id
219-
Int_t chipVolUID(Int_t id) const { return o2::base::GeometryManager::getSensID(o2::detectors::DetID::ITS, id); }
219+
Int_t chipVolUID(Int_t id) const { return o2::base::GeometryManager::getSensID(o2::detectors::DetID(GetName()), id); }
220220

221221
void EndOfEvent() override;
222222

Detectors/Upgrades/ITS3/alignment/include/ITS3Align/Deformations.h

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "ITS3Align/MisalignmentParameters.h"
1616
#include "MathUtils/LegendrePols.h"
17+
#include "GPUCommonMath.h"
1718

1819
#include <filesystem>
1920

@@ -26,57 +27,31 @@ class Deformations
2627
// init deformations from the parameter file
2728
void init(const std::filesystem::path&);
2829

29-
double getDeformationX(unsigned int id, double u, double v) const { return getDeformation<0>(id, u, v); }
30-
double getDeformationY(unsigned int id, double u, double v) const { return getDeformation<1>(id, u, v); }
31-
double getDeformationZ(unsigned int id, double u, double v) const { return getDeformation<2>(id, u, v); }
32-
double getDeformation(unsigned int id, unsigned int axis, double u, double v) const
30+
std::tuple<double, double, double> getDeformation(unsigned int id, double radius, double phi, double z, double u, double v, double fac = 1.0) const
3331
{
34-
if (axis == 0) {
35-
return mLegX[id](u, v);
36-
} else if (axis == 1) {
37-
return mLegY[id](u, v);
38-
} else {
39-
return mLegZ[id](u, v);
40-
}
32+
// Calculate f_def(phi,z) = ((r+dr)*cos(phi), (r+dr)*sin(phi), z)^T + (dx, dy, dz)^T
33+
const double dr = mLegendre[id](u, v);
34+
const double drr = radius + dr * fac;
35+
double sn, cs;
36+
o2::gpu::GPUCommonMath::SinCosd(phi, sn, cs);
37+
const auto& global = mParams.getGlobal(id);
38+
return {drr * cs + global.getX() * fac, drr * sn + global.getY() * fac, z + global.getZ() * fac};
4139
}
42-
std::array<double, 3> getDeformation(unsigned int id, double u, double v) const
43-
{
44-
return {getDeformation<0>(id, u, v),
45-
getDeformation<1>(id, u, v),
46-
getDeformation<2>(id, u, v)};
47-
}
48-
std::array<unsigned int, 3> getOrders(unsigned int id) const
49-
{
50-
return {mLegX[id].NOrder(), mLegY[id].NOrder(), mLegZ[id].NOrder()};
51-
}
52-
const o2::math_utils::Legendre2DPolynominal& getLegendre(unsigned int id, unsigned int axis) const
40+
41+
double getDeformation(unsigned int id, double u, double v)
5342
{
54-
if (axis == 0) {
55-
return mLegX[id];
56-
} else if (axis == 1) {
57-
return mLegY[id];
58-
} else {
59-
return mLegZ[id];
60-
}
43+
return mLegendre[id](u, v);
6144
}
6245

46+
const o2::math_utils::Legendre2DPolynominal& getLegendre(unsigned int id) { return mLegendre[id]; }
47+
48+
unsigned int getOrder(unsigned int id) { return mLegendre[id].NOrder(); }
49+
6350
private:
64-
template <int axis>
65-
double getDeformation(unsigned int id, double u, double v) const
66-
{
67-
if constexpr (axis == 0) {
68-
return mLegX[id](u, v);
69-
} else if constexpr (axis == 1) {
70-
return mLegY[id](u, v);
71-
} else {
72-
return mLegZ[id](u, v);
73-
}
74-
}
51+
MisalignmentParameters mParams;
7552

76-
// 3 Legendre polynominals to model deformations in x,y,z; parameterized by normalized phi (u) and z (v) coordinates
77-
std::array<o2::math_utils::Legendre2DPolynominal, 6> mLegX;
78-
std::array<o2::math_utils::Legendre2DPolynominal, 6> mLegY;
79-
std::array<o2::math_utils::Legendre2DPolynominal, 6> mLegZ;
53+
// Legendre polynominals to model deformations in radius; parameterized by normalized phi (u) and z (v) coordinates
54+
std::array<o2::math_utils::Legendre2DPolynominal, 6> mLegendre;
8055
};
8156

8257
} // namespace o2::its3::align

Detectors/Upgrades/ITS3/alignment/include/ITS3Align/MisalignmentHits.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ class MisAlignmentHits
120120

121121
bool deformHit(WorkingHit::HitType t);
122122

123-
auto getDeformation(unsigned int id, double u, double v) const
124-
{
125-
return mDeformations.getDeformation(id, u, v);
126-
}
127-
128123
// Mimize function assuming a straight line
129124
// given in the parametric representation by y_v = t * d_x + x_s
130125
// assuming no offset is needed

Detectors/Upgrades/ITS3/alignment/include/ITS3Align/MisalignmentParameters.h

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define ITS3_MISALIGNMENTPARAMETERS_H_
1717

1818
#include "ITS3Base/SpecsV2.h"
19+
#include "DetectorsCommonDataFormats/AlignParam.h"
1920

2021
#include "TNamed.h"
2122
#include "TFile.h"
@@ -31,37 +32,23 @@ class MisalignmentParameters : public TNamed
3132
{
3233
public:
3334
MisalignmentParameters();
35+
MisalignmentParameters(const MisalignmentParameters&) = default;
36+
MisalignmentParameters(MisalignmentParameters&&) = delete;
37+
MisalignmentParameters& operator=(MisalignmentParameters&&) = delete;
38+
MisalignmentParameters& operator=(const MisalignmentParameters& o);
3439

3540
// IO
3641
bool store(const std::string& file) const;
3742
static MisalignmentParameters* load(const std::string& file);
3843

3944
/// Global getters
40-
double getGloTransX(unsigned int detID) const { return mGloTransX[detID]; }
41-
double getGloTransY(unsigned int detID) const { return mGloTransY[detID]; }
42-
double getGloTransZ(unsigned int detID) const { return mGloTransZ[detID]; }
43-
double getGloRotX(unsigned int detID) const { return mGloRotX[detID]; }
44-
double getGloRotY(unsigned int detID) const { return mGloRotY[detID]; }
45-
double getGloRotZ(unsigned int detID) const { return mGloRotZ[detID]; }
46-
/// Global setters
47-
void setGloTransX(unsigned int detID, double v) { mGloTransX[detID] = v; }
48-
void setGloTransY(unsigned int detID, double v) { mGloTransY[detID] = v; }
49-
void setGloTransZ(unsigned int detID, double v) { mGloTransZ[detID] = v; }
50-
void setGloRotX(unsigned int detID, double v) { mGloRotX[detID] = v; }
51-
void setGloRotY(unsigned int detID, double v) { mGloRotY[detID] = v; }
52-
void setGloRotZ(unsigned int detID, double v) { mGloRotZ[detID] = v; }
53-
54-
/// Legendre Coeff. getters
55-
const TMatrixD& getLegendreCoeffX(unsigned int sensorID) const { return mLegCoeffX[sensorID]; }
56-
const TMatrixD& getLegendreCoeffY(unsigned int sensorID) const { return mLegCoeffY[sensorID]; }
57-
const TMatrixD& getLegendreCoeffZ(unsigned int sensorID) const { return mLegCoeffZ[sensorID]; }
58-
/// Legendre Coeff. setters
59-
void setLegendreCoeffX(unsigned int sensorID, const TMatrixD& m) { setMatrix(mLegCoeffX[sensorID], m); }
60-
void setLegendreCoeffY(unsigned int sensorID, const TMatrixD& m) { setMatrix(mLegCoeffY[sensorID], m); }
61-
void setLegendreCoeffZ(unsigned int sensorID, const TMatrixD& m) { setMatrix(mLegCoeffZ[sensorID], m); }
45+
const o2::detectors::AlignParam& getGlobal(unsigned int detID) const { return mGlobal[detID]; }
46+
void setGlobal(unsigned int detID, const o2::detectors::AlignParam& param) { mGlobal[detID] = param; }
47+
48+
const TMatrixD& getLegendreCoeff(unsigned int sensorID) const { return mLegCoeff[sensorID]; }
49+
void setLegendreCoeff(unsigned int sensorID, const TMatrixD& m) { setMatrix(mLegCoeff[sensorID], m); }
6250

6351
void printParams(unsigned int detID) const;
64-
void printLegendreParams(unsigned int sensorID) const;
6552

6653
private:
6754
inline void setMatrix(TMatrixD& o, const TMatrixD& n)
@@ -71,21 +58,10 @@ class MisalignmentParameters : public TNamed
7158
}
7259

7360
static constexpr unsigned int nDetectors{constants::detID::nChips}; ///! for now just the IB
61+
std::array<o2::detectors::AlignParam, nDetectors> mGlobal; ///< Array to hold the global misalignment
62+
std::array<TMatrixD, constants::nSensorsIB> mLegCoeff; // Legendre Polynominals coefficients
7463

75-
// Global parameters
76-
std::array<double, nDetectors> mGloTransX; ///< Array to hold the global misalignment in x-direction
77-
std::array<double, nDetectors> mGloTransY; ///< Array to hold the global misalignment in y-direction
78-
std::array<double, nDetectors> mGloTransZ; ///< Array to hold the global misalignment in z-direction
79-
std::array<double, nDetectors> mGloRotX; ///< Array to hold the global misalignment in x-direction
80-
std::array<double, nDetectors> mGloRotY; ///< Array to hold the global misalignment in y-direction
81-
std::array<double, nDetectors> mGloRotZ; ///< Array to hold the global misalignment in z-direction
82-
83-
// Legendre Polynominals coefficients
84-
std::array<TMatrixD, constants::nSensorsIB> mLegCoeffX;
85-
std::array<TMatrixD, constants::nSensorsIB> mLegCoeffY;
86-
std::array<TMatrixD, constants::nSensorsIB> mLegCoeffZ;
87-
88-
ClassDefOverride(MisalignmentParameters, 1);
64+
ClassDefOverride(MisalignmentParameters, 2);
8965
};
9066

9167
} // namespace o2::its3::align

Detectors/Upgrades/ITS3/alignment/src/Deformations.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ void Deformations::init(const fs::path& path)
2727
LOGP(fatal, "File {} does not exists!", path.c_str());
2828
}
2929

30-
auto params = MisalignmentParameters::load(path.string());
30+
mParams = *MisalignmentParameters::load(path.string());
3131
LOGP(info, "Loaded Parameters");
3232

3333
// Set the legendre pols
3434
for (int iSensor{0}; iSensor < 6; ++iSensor) {
35-
mLegX[iSensor] = o2::math_utils::Legendre2DPolynominal(params->getLegendreCoeffX(iSensor));
36-
mLegY[iSensor] = o2::math_utils::Legendre2DPolynominal(params->getLegendreCoeffY(iSensor));
37-
mLegZ[iSensor] = o2::math_utils::Legendre2DPolynominal(params->getLegendreCoeffZ(iSensor));
35+
mLegendre[iSensor] = o2::math_utils::Legendre2DPolynominal(mParams.getLegendreCoeff(iSensor));
3836
}
3937
}
4038

Detectors/Upgrades/ITS3/alignment/src/MisalignmentHits.cxx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// or submit itself to any jurisdiction.
1111

1212
#include "ITS3Align/MisalignmentHits.h"
13+
#include "ITS3Base/SegmentationMosaix.h"
1314
#include "ITS3Base/ITS3Params.h"
1415
#include "SimConfig/DigiParams.h"
1516
#include "DetectorsBase/Propagator.h"
@@ -309,10 +310,8 @@ double MisAlignmentHits::StraightLine::DoEval(const double* x) const
309310
zline = mStart.Z() + t * mD[2];
310311

311312
// Find the point of the deformed geometry given a certain phi' and z'
312-
double xideal = mRadius * std::cos(phi), yideal = mRadius * std::sin(phi),
313-
zideal = z;
314-
const auto [dx, dy, dz] = mMis->getDeformation(mSensorID, nphi, nz);
315-
double xdef = xideal + dx, ydef = yideal + dy, zdef = zideal + dz;
313+
const double xideal = mRadius * std::cos(phi), yideal = mRadius * std::sin(phi), zideal = z;
314+
const auto [xdef, ydef, zdef] = mMis->mDeformations.getDeformation(mSensorID, mRadius, phi, z, nphi, nz);
316315

317316
// Minimize the euclidean distance of the line point and the deformed point
318317
return std::hypot(xline - xdef, yline - ydef, zline - zdef);
@@ -356,10 +355,7 @@ double MisAlignmentHits::Propagator::DoEval(const double* x) const
356355
const auto glo = trc.getXYZGlo();
357356

358357
// Find the point of the deformed geometry given a certain phi' and z'
359-
double xideal = mRadius * std::cos(phi), yideal = mRadius * std::sin(phi),
360-
zideal = z;
361-
const auto [dx, dy, dz] = mMis->getDeformation(mSensorID, nphi, nz);
362-
double xdef = xideal + dx, ydef = yideal + dy, zdef = zideal + dz;
358+
const auto [xdef, ydef, zdef] = mMis->mDeformations.getDeformation(mSensorID, mRadius, phi, z, nphi, nz);
363359

364360
// Minimize the euclidean distance of the propagator point and the deformed point
365361
return std::hypot(glo.X() - xdef, glo.Y() - ydef, glo.Z() - zdef);

Detectors/Upgrades/ITS3/alignment/src/MisalignmentParameters.cxx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ MisalignmentParameters::MisalignmentParameters()
3030
SetTitle("ITS3 MisalignmentParameters");
3131
}
3232

33+
MisalignmentParameters& MisalignmentParameters::operator=(const MisalignmentParameters& o)
34+
{
35+
if (this != &o) {
36+
SetName(o.GetName());
37+
SetTitle(o.GetTitle());
38+
mGlobal = o.mGlobal;
39+
for (unsigned int s{0}; s < constants::nSensorsIB; ++s) {
40+
o.mLegCoeff[s].Print();
41+
setMatrix(mLegCoeff[s], o.mLegCoeff[s]);
42+
}
43+
}
44+
return *this;
45+
}
46+
3347
bool MisalignmentParameters::store(const std::string& file) const
3448
{
3549
std::unique_ptr<TFile> fOut(TFile::Open(file.c_str(), "RECREATE"));
@@ -43,6 +57,7 @@ bool MisalignmentParameters::store(const std::string& file) const
4357

4458
MisalignmentParameters* MisalignmentParameters::load(const std::string& file)
4559
{
60+
LOGP(info, "Loading Parameters from {}", file);
4661
std::unique_ptr<TFile> fIn(TFile::Open(file.c_str(), "READ"));
4762
auto p = fIn->Get<MisalignmentParameters>("ccdb_object");
4863
if (p == nullptr) {
@@ -54,27 +69,13 @@ MisalignmentParameters* MisalignmentParameters::load(const std::string& file)
5469
void MisalignmentParameters::printParams(unsigned int detID) const
5570
{
5671
LOGP(info, "Parameters for ID={}:", detID);
57-
LOGP(info, " - Global Trans: X={} Y={} Z={}", getGloTransX(detID), getGloTransY(detID), getGloTransZ(detID));
58-
LOGP(info, " - Global Rots: X={} Y={} Z={}", getGloRotX(detID), getGloRotY(detID), getGloRotZ(detID));
72+
const auto& glo = mGlobal[detID];
73+
LOGP(info, " - Global Trans: X={} Y={} Z={}", glo.getX(), glo.getY(), glo.getZ());
74+
LOGP(info, " - Global Rots: Phi={} Psi={} Theta={}", glo.getPhi(), glo.getPsi(), glo.getTheta());
5975
if (constants::detID::isDetITS3(detID)) {
6076
auto sensorID = constants::detID::getSensorID(detID);
61-
LOGP(info, " - Legendre Pol X:");
62-
getLegendreCoeffX(sensorID).Print();
63-
LOGP(info, " - Legendre Pol Y:");
64-
getLegendreCoeffY(sensorID).Print();
65-
LOGP(info, " - Legendre Pol Z:");
66-
getLegendreCoeffZ(sensorID).Print();
77+
mLegCoeff[sensorID].Print();
6778
}
6879
}
6980

70-
void MisalignmentParameters::printLegendreParams(unsigned int sensorID) const
71-
{
72-
LOGP(info, " - Legendre Pol X:");
73-
getLegendreCoeffX(sensorID).Print();
74-
LOGP(info, " - Legendre Pol Y:");
75-
getLegendreCoeffY(sensorID).Print();
76-
LOGP(info, " - Legendre Pol Z:");
77-
getLegendreCoeffZ(sensorID).Print();
78-
}
79-
8081
} // namespace o2::its3::align

Detectors/Upgrades/ITS3/macros/align/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ its3_add_macro(TestLegendrePol.C)
1515
its3_add_macro(CreateMisalignmentITS3.C)
1616
its3_add_macro(ShowCoefficients.C)
1717
its3_add_macro(CheckResidualsITS3.C)
18+
its3_add_macro(ITS3Misaligner.C)

Detectors/Upgrades/ITS3/macros/align/CheckResidualsITS3.C

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@
3636

3737
#include <optional>
3838
#include <tuple>
39+
#include <filesystem>
40+
#include <cstdlib>
3941
#endif
4042

43+
namespace fs = std::filesystem;
44+
4145
// Refit ITS3 tracks by using the clusters from the OB only then propagate the
4246
// tracks to the IB clusters and calculate their residuals.
4347

@@ -66,11 +70,16 @@ std::optional<Cluster> propagateTo(Track& trk, const o2::itsmft::CompClusterExt&
6670
++cTotal;
6771
auto chipID = clus.getSensorID();
6872
float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
69-
auto isITS3 = o2::its3::constants::detID::isDetITS3(chipID);
7073
const float alpha = o2::its::GeometryTGeo::Instance()->getSensorRefAlpha(clus.getSensorID()); // alpha for the tracking frame
7174
const auto locC = o2::its3::ioutils::extractClusterData(clus, pattIt, mDict, sigmaY2, sigmaZ2); // get cluster in sensor local frame with errors
72-
Point3D trkC = o2::its::GeometryTGeo::Instance()->getMatrixT2L(chipID) ^ (locC); // cluster position in the tracking frame
73-
const auto gloC = o2::its::GeometryTGeo::Instance()->getMatrixL2G(chipID)(locC); // global cluster position
75+
Point3D trkC;
76+
auto isITS3 = o2::its3::constants::detID::isDetITS3(chipID);
77+
if (isITS3) {
78+
trkC = o2::its::GeometryTGeo::Instance()->getT2LMatrixITS3(chipID, alpha) ^ (locC); // cluster position in the tracking frame
79+
} else {
80+
trkC = o2::its::GeometryTGeo::Instance()->getMatrixT2L(chipID) ^ (locC); // cluster position in the tracking frame
81+
}
82+
const auto gloC = o2::its::GeometryTGeo::Instance()->getMatrixL2G(chipID)(locC); // global cluster position
7483
const auto bz = o2::base::Propagator::Instance()->getNominalBz();
7584

7685
// rotate the parameters to the tracking frame then propagate to the clusters'x
@@ -111,7 +120,7 @@ std::optional<Cluster> propagateTo(Track& trk, const o2::itsmft::CompClusterExt&
111120

112121
void CheckResidualsITS3(bool plotOnly = false,
113122
bool useITS = false,
114-
const std::string& dictFileName = "../ccdb/IT3/Calib/ClusterDictionary/snapshot.root",
123+
std::string dictFileName = "IT3dictionary.root",
115124
const std::string& collisioncontextFileName = "collisioncontext.root",
116125
const std::string& itsTracksFileName = "o2trac_its.root",
117126
const std::string& itsClustersFileName = "o2clus_its.root",
@@ -122,6 +131,17 @@ void CheckResidualsITS3(bool plotOnly = false,
122131
std::array<TH3F*, 6> hIBDx, hIBDy, hIBDz, hIBDr;
123132

124133
if (!plotOnly) {
134+
if (fs::exists(dictFileName)) {
135+
LOGP(info, "Using local dictionary file");
136+
} else {
137+
const std::string ccdb = std::getenv("ALICEO2_CCDB_LOCALCACHE");
138+
dictFileName = ccdb + "/IT3/Calib/ClusterDictionary/snapshot.root";
139+
if (fs::exists(dictFileName)) {
140+
LOGP(info, "Loading from local ccdb cache");
141+
} else {
142+
LOGP(fatal, "Provide dictionary!");
143+
}
144+
}
125145
mDict = new o2::its3::TopologyDictionary(dictFileName);
126146

127147
o2::base::GeometryManager::loadGeometry(geomFileName);

0 commit comments

Comments
 (0)