Skip to content

Commit 3404588

Browse files
committed
[EMCAL-689] EMCAL/Geometry: Add function to load alignment matrix from CCDB
- Add function `SetMisalMatrixFromCcdb` to set the missalignment matrices for the EMCal via the CCDB. This way they are not laoded from the GeoManager. The function expects a path inside the ccdb, which by default is set to `"Users/m/mhemmer/EMCAL/Config/GeometryAligned"` and the timestamp. Currently in the CCDB we only have the old Run 2 alignment object. Once we have the new alignment objects we can uplaod them and via the correct time stamp load them fittingly. - Fixed cpplint errors, mostly old casting style and missing include headers
1 parent e3fdb85 commit 3404588

File tree

2 files changed

+56
-25
lines changed

2 files changed

+56
-25
lines changed

Detectors/EMCAL/base/include/EMCALBase/Geometry.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12-
#ifndef ALICEO2_EMCAL_GEOMETRY_H_
13-
#define ALICEO2_EMCAL_GEOMETRY_H_
12+
#ifndef DETECTORS_EMCAL_BASE_INCLUDE_EMCALBASE_GEOMETRY_H_
13+
#define DETECTORS_EMCAL_BASE_INCLUDE_EMCALBASE_GEOMETRY_H_
1414

1515
#include <exception>
1616
#include <string>
@@ -22,7 +22,9 @@
2222
#include <TNamed.h>
2323
#include <TParticle.h>
2424
#include <TVector3.h>
25+
#include <TObjArray.h>
2526

27+
#include "CCDB/BasicCCDBManager.h"
2628
#include "DataFormatsEMCAL/Constants.h"
2729
#include "EMCALBase/GeometryBase.h"
2830
#include "MathUtils/Cartesian.h"
@@ -57,7 +59,7 @@ class Geometry
5759
/// | EMCAL_COMPLETE12SMV1_DCAL | Full EMCAL, 10 DCAL Supermodules (not used in practice) |
5860
/// | EMCAL_COMPLETE12SMV1_DCAL_8SM | Full EMCAL, 8 DCAL Supermodules (run2) |
5961
/// | EMCAL_COMPLETE12SMV1_DCAL_DEV | Full EMCAL, DCAL development geometry (not used) |
60-
Geometry(const std::string_view name, const std::string_view mcname = "", const std::string_view mctitle = "");
62+
explicit Geometry(const std::string_view name, const std::string_view mcname = "", const std::string_view mctitle = "");
6163

6264
/// \brief Copy constructor.
6365
Geometry(const Geometry& geom);
@@ -519,7 +521,7 @@ class Geometry
519521
/// \param ddlID DDL ID
520522
/// \return CRORC ID
521523
/// \return CRORC Link
522-
std::tuple<int, int> getLinkAssignment(int ddlID) const { return std::make_tuple(mCRORCID[ddlID], mCRORCLink[ddlID]); };
524+
std::tuple<int, int> getLinkAssignment(int ddlID) const { return std::make_tuple(mCRORCID[ddlID], mCRORCLink[ddlID]); }
523525

524526
std::vector<EMCALSMType> GetEMCSystem() const { return mEMCSMSystem; } // EMC System, SM type list
525527
// Local Coordinates of SM
@@ -564,6 +566,11 @@ class Geometry
564566
///
565567
void SetMisalMatrix(const TGeoHMatrix* m, Int_t smod) const;
566568

569+
///
570+
/// Method to set shift-rotational matrixes from CCDB
571+
///
572+
void SetMisalMatrixFromCcdb(const char* path = "Users/m/mhemmer/EMCAL/Config/GeometryAligned", int timestamp = 10000) const;
573+
567574
///
568575
/// Transform clusters cell position into global with alternative method, taking into account the depth calculation.
569576
/// Input are:
@@ -710,4 +717,4 @@ inline Bool_t Geometry::CheckAbsCellId(Int_t absId) const
710717
}
711718
} // namespace emcal
712719
} // namespace o2
713-
#endif
720+
#endif // DETECTORS_EMCAL_BASE_INCLUDE_EMCALBASE_GEOMETRY_H_

Detectors/EMCAL/base/src/Geometry.cxx

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11+
#include "EMCALBase/Geometry.h"
12+
13+
#include <fairlogger/Logger.h>
14+
1115
#include <iomanip>
16+
#include <string>
17+
#include <algorithm>
18+
#include <cstdio>
19+
#include <tuple>
1220

1321
#include <TGeoBBox.h>
1422
#include <TGeoManager.h>
1523
#include <TGeoMatrix.h>
1624
#include <TList.h>
1725

18-
#include <fairlogger/Logger.h>
19-
20-
#include "EMCALBase/Geometry.h"
2126
#include "EMCALBase/ShishKebabTrd1Module.h"
2227

2328
#include <boost/algorithm/string/predicate.hpp>
@@ -265,8 +270,7 @@ Geometry* Geometry::GetInstanceFromRunNumber(Int_t runNumber, const std::string_
265270
"<<EMCAL_COMPLETE12SMV1>>";
266271
}
267272
return Geometry::GetInstance("EMCAL_COMPLETE12SMV1", mcname, mctitle);
268-
} else // Run 2
269-
{
273+
} else { // Run 2
270274
// EMCAL + DCAL geometry, 20 SM. Year 2015 and on
271275

272276
if (contains(geoName, "DCAL_8SM") && geoName != std::string("")) {
@@ -562,8 +566,8 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
562566
mNPhiSuperModule = 1;
563567
}
564568

565-
mPhiTileSize = mPhiModuleSize / double(mNPHIdiv) - mLateralSteelStrip; // 13-may-05
566-
mEtaTileSize = mEtaModuleSize / double(mNETAdiv) - mLateralSteelStrip; // 13-may-05
569+
mPhiTileSize = mPhiModuleSize / static_cast<double>(mNPHIdiv) - mLateralSteelStrip; // 13-may-05
570+
mEtaTileSize = mEtaModuleSize / static_cast<double>(mNETAdiv) - mLateralSteelStrip; // 13-may-05
567571

568572
mLongModuleSize = mNECLayers * (mECScintThick + mECPbRadThickness);
569573
if (contains(mGeoName, "V1")) {
@@ -626,7 +630,7 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
626630
break;
627631
default:
628632
break;
629-
};
633+
}
630634
}
631635
mPhiCentersOfSM[i] = (mPhiBoundariesOfSM[2 * i] + mPhiBoundariesOfSM[2 * i + 1]) / 2.;
632636
mPhiCentersOfSMSec[i] = mPhiBoundariesOfSM[2 * i] + TMath::ATan2(mParSM[1], mIPDistance);
@@ -665,7 +669,7 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
665669
default:
666670
LOG(error) << "Unkown SM Type!!\n";
667671
break;
668-
};
672+
}
669673
}
670674
// for compatible reason
671675
// if(fNumberOfSuperModules == 4) {fEMCALPhiMax = fArm1PhiMax ;}
@@ -762,7 +766,7 @@ int Geometry::GetAbsCellId(int supermoduleID, int moduleID, int phiInModule, int
762766
break;
763767
default:
764768
throw InvalidSupermoduleTypeException();
765-
};
769+
}
766770
}
767771

768772
cellid += mNCellsInModule * moduleID;
@@ -947,7 +951,7 @@ Int_t Geometry::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi) const
947951
default:
948952
// All other supermodules have full number of cells in phi
949953
break;
950-
};
954+
}
951955

952956
Double_t dmin = TMath::Abs(mPhiCentersOfCells[0] - phiLoc),
953957
d = 0.;
@@ -1027,7 +1031,7 @@ std::tuple<int, int, int, int> Geometry::CalculateCellIndex(Int_t absId) const
10271031
break;
10281032
default:
10291033
throw InvalidSupermoduleTypeException();
1030-
};
1034+
}
10311035
}
10321036

10331037
Int_t nModule = tmp / mNCellsInModule;
@@ -1060,8 +1064,8 @@ std::tuple<int, int> Geometry::GetModulePhiEtaIndexInSModule(int supermoduleID,
10601064
default:
10611065
nModulesInPhi = mNPhi; // full SM
10621066
break;
1063-
};
1064-
return std::make_tuple(int(moduleID % nModulesInPhi), int(moduleID / nModulesInPhi));
1067+
}
1068+
return std::make_tuple(static_cast<int>(moduleID % nModulesInPhi), static_cast<int>(moduleID / nModulesInPhi));
10651069
}
10661070

10671071
std::tuple<int, int> Geometry::GetCellPhiEtaIndexInSModule(int supermoduleID, int moduleID, int phiInModule,
@@ -1334,8 +1338,8 @@ void Geometry::CreateListOfTrd1Modules()
13341338
auto indexinsm = GetCellPhiEtaIndexInSModule(0, nModule, 0, ic);
13351339
ieta = std::get<1>(indexinsm);
13361340
}
1337-
mCentersOfCellsXDir[ieta] = float(xr) - mParSM[0];
1338-
mCentersOfCellsEtaDir[ieta] = float(zr) - mParSM[2];
1341+
mCentersOfCellsXDir[ieta] = static_cast<float>(xr) - mParSM[0];
1342+
mCentersOfCellsEtaDir[ieta] = static_cast<float>(zr) - mParSM[2];
13391343
// Define grid on eta direction for each bin in phi
13401344
for (int iphi = 0; iphi < mCentersOfCellsPhiDir.size(); iphi++) {
13411345
x = xr + trd1.GetRadius();
@@ -1557,6 +1561,7 @@ const TGeoHMatrix* Geometry::GetMatrixForSuperModule(Int_t smod) const
15571561

15581562
if (!SMODULEMATRIX[smod]) {
15591563
if (gGeoManager) {
1564+
LOG(info) << "Loading EMCAL misalignment matrix for SM " << smod << " from GeoManager.";
15601565
SetMisalMatrix(GetMatrixForSuperModuleFromGeoManager(smod), smod);
15611566
} else {
15621567
LOG(fatal) << "Cannot find EMCAL misalignment matrices! Recover them either: \n"
@@ -1582,8 +1587,8 @@ const TGeoHMatrix* Geometry::GetMatrixForSuperModuleFromArray(Int_t smod) const
15821587

15831588
const TGeoHMatrix* Geometry::GetMatrixForSuperModuleFromGeoManager(Int_t smod) const
15841589
{
1585-
const Int_t buffersize = 255;
1586-
char path[buffersize];
1590+
constexpr Int_t kBufferSize = 255;
1591+
char path[kBufferSize];
15871592
Int_t tmpType = -1;
15881593
Int_t smOrder = 0;
15891594

@@ -1614,7 +1619,7 @@ const TGeoHMatrix* Geometry::GetMatrixForSuperModuleFromGeoManager(Int_t smod) c
16141619
LOG(error) << "Unkown SM Type!!\n";
16151620
}
16161621

1617-
snprintf(path, buffersize, "/cave/barrel_1/%s_%d", smName.Data(), smOrder);
1622+
snprintf(path, kBufferSize, "/cave/barrel_1/%s_%d", smName.Data(), smOrder);
16181623

16191624
if (!gGeoManager->cd(path)) {
16201625
LOG(fatal) << "Geo manager can not find path " << path << "!\n";
@@ -1690,7 +1695,7 @@ void Geometry::RecalculateTowerPosition(Float_t drow, Float_t dcol, const Int_t
16901695
return;
16911696
}
16921697

1693-
istrip = int((dcol + 0.5) / 2);
1698+
istrip = static_cast<int>((dcol + 0.5) / 2);
16941699

16951700
// tapering angle
16961701
teta1 = TMath::DegToRad() * istrip * 1.5;
@@ -1762,6 +1767,25 @@ void Geometry::SetMisalMatrix(const TGeoHMatrix* m, Int_t smod) const
17621767
}
17631768
}
17641769

1770+
void Geometry::SetMisalMatrixFromCcdb(const char* path, int timestamp) const
1771+
{
1772+
LOG(info) << "Using CCDB to obtain EMCal alignment.";
1773+
auto& mCcdbManager = o2::ccdb::BasicCCDBManager::instance();
1774+
mCcdbManager.setURL(o2::base::NameConf::getCCDBServer());
1775+
mCcdbManager.setTimestamp(timestamp);
1776+
TObjArray* matrices = mCcdbManager.get<TObjArray>(path);
1777+
1778+
for (int iSM = 0; iSM < mNumberOfSuperModules; ++iSM) {
1779+
TGeoHMatrix* mat = reinterpret_cast<TGeoHMatrix*>(matrices->At(iSM));
1780+
if (mat) {
1781+
1782+
SetMisalMatrix(mat, iSM);
1783+
} else {
1784+
LOG(info) << "Could not obtain Alignment Matrix for SM " << iSM;
1785+
}
1786+
}
1787+
}
1788+
17651789
Bool_t Geometry::IsDCALSM(Int_t iSupMod) const
17661790
{
17671791
if (mEMCSMSystem[iSupMod] == DCAL_STANDARD || mEMCSMSystem[iSupMod] == DCAL_EXT) {

0 commit comments

Comments
 (0)