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
10671075std::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
15831592const 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+
17651791Bool_t Geometry::IsDCALSM (Int_t iSupMod) const
17661792{
17671793 if (mEMCSMSystem [iSupMod] == DCAL_STANDARD || mEMCSMSystem [iSupMod] == DCAL_EXT) {
0 commit comments