Skip to content

Commit 574d826

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 574d826

File tree

2 files changed

+61
-26
lines changed

2 files changed

+61
-26
lines changed

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

Lines changed: 14 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:
@@ -696,6 +703,8 @@ class Geometry
696703
mutable const TGeoHMatrix* SMODULEMATRIX[EMCAL_MODULES]; ///< Orientations of EMCAL super modules
697704
std::vector<std::tuple<int, int, int, int>> mCellIndexLookup; ///< Lookup table for cell indices
698705

706+
o2::ccdb::BasicCCDBManager* mCcdbManager;
707+
699708
private:
700709
static Geometry* sGeom; ///< Pointer to the unique instance of the singleton
701710
};
@@ -710,4 +719,4 @@ inline Bool_t Geometry::CheckAbsCellId(Int_t absId) const
710719
}
711720
} // namespace emcal
712721
} // namespace o2
713-
#endif
722+
#endif // DETECTORS_EMCAL_BASE_INCLUDE_EMCALBASE_GEOMETRY_H_

Detectors/EMCAL/base/src/Geometry.cxx

Lines changed: 47 additions & 21 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>
@@ -85,7 +90,8 @@ Geometry::Geometry(const Geometry& geo)
8590
mILOSS(geo.mILOSS),
8691
mIHADR(geo.mIHADR),
8792
mSteelFrontThick(geo.mSteelFrontThick), // obsolete data member?
88-
mCellIndexLookup(geo.mCellIndexLookup)
93+
mCellIndexLookup(geo.mCellIndexLookup),
94+
mCcdbManager(&o2::ccdb::BasicCCDBManager::instance())
8995
{
9096
memcpy(mEnvelop, geo.mEnvelop, sizeof(Float_t) * 3);
9197
memcpy(mParSM, geo.mParSM, sizeof(Float_t) * 3);
@@ -164,6 +170,9 @@ Geometry::Geometry(const std::string_view name, const std::string_view mcname, c
164170

165171
memset(SMODULEMATRIX, 0, sizeof(TGeoHMatrix*) * EMCAL_MODULES);
166172

173+
mCcdbManager = &o2::ccdb::BasicCCDBManager::instance();
174+
mCcdbManager->setURL(o2::base::NameConf::getCCDBServer());
175+
167176
LOG(debug) << "Name <<" << name << ">>";
168177
}
169178

@@ -265,8 +274,7 @@ Geometry* Geometry::GetInstanceFromRunNumber(Int_t runNumber, const std::string_
265274
"<<EMCAL_COMPLETE12SMV1>>";
266275
}
267276
return Geometry::GetInstance("EMCAL_COMPLETE12SMV1", mcname, mctitle);
268-
} else // Run 2
269-
{
277+
} else { // Run 2
270278
// EMCAL + DCAL geometry, 20 SM. Year 2015 and on
271279

272280
if (contains(geoName, "DCAL_8SM") && geoName != std::string("")) {
@@ -562,8 +570,8 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
562570
mNPhiSuperModule = 1;
563571
}
564572

565-
mPhiTileSize = mPhiModuleSize / double(mNPHIdiv) - mLateralSteelStrip; // 13-may-05
566-
mEtaTileSize = mEtaModuleSize / double(mNETAdiv) - mLateralSteelStrip; // 13-may-05
573+
mPhiTileSize = mPhiModuleSize / static_cast<double>(mNPHIdiv) - mLateralSteelStrip; // 13-may-05
574+
mEtaTileSize = mEtaModuleSize / static_cast<double>(mNETAdiv) - mLateralSteelStrip; // 13-may-05
567575

568576
mLongModuleSize = mNECLayers * (mECScintThick + mECPbRadThickness);
569577
if (contains(mGeoName, "V1")) {
@@ -626,7 +634,7 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
626634
break;
627635
default:
628636
break;
629-
};
637+
}
630638
}
631639
mPhiCentersOfSM[i] = (mPhiBoundariesOfSM[2 * i] + mPhiBoundariesOfSM[2 * i + 1]) / 2.;
632640
mPhiCentersOfSMSec[i] = mPhiBoundariesOfSM[2 * i] + TMath::ATan2(mParSM[1], mIPDistance);
@@ -665,7 +673,7 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
665673
default:
666674
LOG(error) << "Unkown SM Type!!\n";
667675
break;
668-
};
676+
}
669677
}
670678
// for compatible reason
671679
// if(fNumberOfSuperModules == 4) {fEMCALPhiMax = fArm1PhiMax ;}
@@ -762,7 +770,7 @@ int Geometry::GetAbsCellId(int supermoduleID, int moduleID, int phiInModule, int
762770
break;
763771
default:
764772
throw InvalidSupermoduleTypeException();
765-
};
773+
}
766774
}
767775

768776
cellid += mNCellsInModule * moduleID;
@@ -947,7 +955,7 @@ Int_t Geometry::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi) const
947955
default:
948956
// All other supermodules have full number of cells in phi
949957
break;
950-
};
958+
}
951959

952960
Double_t dmin = TMath::Abs(mPhiCentersOfCells[0] - phiLoc),
953961
d = 0.;
@@ -1027,7 +1035,7 @@ std::tuple<int, int, int, int> Geometry::CalculateCellIndex(Int_t absId) const
10271035
break;
10281036
default:
10291037
throw InvalidSupermoduleTypeException();
1030-
};
1038+
}
10311039
}
10321040

10331041
Int_t nModule = tmp / mNCellsInModule;
@@ -1060,8 +1068,8 @@ std::tuple<int, int> Geometry::GetModulePhiEtaIndexInSModule(int supermoduleID,
10601068
default:
10611069
nModulesInPhi = mNPhi; // full SM
10621070
break;
1063-
};
1064-
return std::make_tuple(int(moduleID % nModulesInPhi), int(moduleID / nModulesInPhi));
1071+
}
1072+
return std::make_tuple(static_cast<int>(moduleID % nModulesInPhi), static_cast<int>(moduleID / nModulesInPhi));
10651073
}
10661074

10671075
std::tuple<int, int> Geometry::GetCellPhiEtaIndexInSModule(int supermoduleID, int moduleID, int phiInModule,
@@ -1334,8 +1342,8 @@ void Geometry::CreateListOfTrd1Modules()
13341342
auto indexinsm = GetCellPhiEtaIndexInSModule(0, nModule, 0, ic);
13351343
ieta = std::get<1>(indexinsm);
13361344
}
1337-
mCentersOfCellsXDir[ieta] = float(xr) - mParSM[0];
1338-
mCentersOfCellsEtaDir[ieta] = float(zr) - mParSM[2];
1345+
mCentersOfCellsXDir[ieta] = static_cast<float>(xr) - mParSM[0];
1346+
mCentersOfCellsEtaDir[ieta] = static_cast<float>(zr) - mParSM[2];
13391347
// Define grid on eta direction for each bin in phi
13401348
for (int iphi = 0; iphi < mCentersOfCellsPhiDir.size(); iphi++) {
13411349
x = xr + trd1.GetRadius();
@@ -1557,6 +1565,7 @@ const TGeoHMatrix* Geometry::GetMatrixForSuperModule(Int_t smod) const
15571565

15581566
if (!SMODULEMATRIX[smod]) {
15591567
if (gGeoManager) {
1568+
LOG(info) << "Loading EMCAL misalignment matrix for SM " << smod << " from GeoManager.";
15601569
SetMisalMatrix(GetMatrixForSuperModuleFromGeoManager(smod), smod);
15611570
} else {
15621571
LOG(fatal) << "Cannot find EMCAL misalignment matrices! Recover them either: \n"
@@ -1582,8 +1591,8 @@ const TGeoHMatrix* Geometry::GetMatrixForSuperModuleFromArray(Int_t smod) const
15821591

15831592
const TGeoHMatrix* Geometry::GetMatrixForSuperModuleFromGeoManager(Int_t smod) const
15841593
{
1585-
const Int_t buffersize = 255;
1586-
char path[buffersize];
1594+
constexpr Int_t kBufferSize = 255;
1595+
char path[kBufferSize];
15871596
Int_t tmpType = -1;
15881597
Int_t smOrder = 0;
15891598

@@ -1614,7 +1623,7 @@ const TGeoHMatrix* Geometry::GetMatrixForSuperModuleFromGeoManager(Int_t smod) c
16141623
LOG(error) << "Unkown SM Type!!\n";
16151624
}
16161625

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

16191628
if (!gGeoManager->cd(path)) {
16201629
LOG(fatal) << "Geo manager can not find path " << path << "!\n";
@@ -1690,7 +1699,7 @@ void Geometry::RecalculateTowerPosition(Float_t drow, Float_t dcol, const Int_t
16901699
return;
16911700
}
16921701

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

16951704
// tapering angle
16961705
teta1 = TMath::DegToRad() * istrip * 1.5;
@@ -1762,6 +1771,23 @@ void Geometry::SetMisalMatrix(const TGeoHMatrix* m, Int_t smod) const
17621771
}
17631772
}
17641773

1774+
void Geometry::SetMisalMatrixFromCcdb(const char* path, int timestamp) const
1775+
{
1776+
LOG(info) << "Using CCDB to obtain EMCal alignment.";
1777+
mCcdbManager->setTimestamp(timestamp);
1778+
TObjArray* matrices = mCcdbManager->get<TObjArray>(path);
1779+
1780+
for (int iSM = 0; iSM < mNumberOfSuperModules; ++iSM) {
1781+
TGeoHMatrix* mat = reinterpret_cast<TGeoHMatrix*>(matrices->At(iSM));
1782+
if (mat) {
1783+
1784+
SetMisalMatrix(mat, iSM);
1785+
} else {
1786+
LOG(info) << "Could not obtain Alignment Matrix for SM " << iSM;
1787+
}
1788+
}
1789+
}
1790+
17651791
Bool_t Geometry::IsDCALSM(Int_t iSupMod) const
17661792
{
17671793
if (mEMCSMSystem[iSupMod] == DCAL_STANDARD || mEMCSMSystem[iSupMod] == DCAL_EXT) {

0 commit comments

Comments
 (0)