From f16ff841d81e381d953d46df8759153ac1ad84d5 Mon Sep 17 00:00:00 2001 From: Alexandru Bercuci <abercuci@niham.nipne.ro> Date: Thu, 23 Feb 2023 14:09:51 +0200 Subject: [PATCH] streamline the usage of TrdParGeo to align it to the rest of parameter sets and to take into account the alignment --- core/detectors/trd/CbmTrdParManager.cxx | 10 +++++ core/detectors/trd/CbmTrdParManager.h | 7 +++- core/detectors/trd/CbmTrdParModGeo.cxx | 21 +++++++++- core/detectors/trd/CbmTrdParModGeo.h | 1 + core/detectors/trd/CbmTrdParSetGeo.cxx | 25 ++++++++++-- core/detectors/trd/CbmTrdParSetGeo.h | 7 +++- reco/detectors/trd/CbmTrdClusterFinder.cxx | 12 +++--- reco/detectors/trd/CbmTrdHitProducer.cxx | 47 ++++++++++------------ reco/detectors/trd/CbmTrdHitProducer.h | 4 +- 9 files changed, 91 insertions(+), 43 deletions(-) diff --git a/core/detectors/trd/CbmTrdParManager.cxx b/core/detectors/trd/CbmTrdParManager.cxx index aa94a212d2..f74a687ca6 100644 --- a/core/detectors/trd/CbmTrdParManager.cxx +++ b/core/detectors/trd/CbmTrdParManager.cxx @@ -16,11 +16,13 @@ #include "CbmTrdParModDigi.h" // for CbmTrdParModDigi #include "CbmTrdParModGain.h" // for CbmTrdParModGain #include "CbmTrdParModGas.h" // for CbmTrdParModGas +#include "CbmTrdParModGeo.h" // for CbmTrdParModGeo #include "CbmTrdParSet.h" // for CbmTrdParSet #include "CbmTrdParSetAsic.h" // for CbmTrdParSetAsic #include "CbmTrdParSetDigi.h" // for CbmTrdParSetDigi #include "CbmTrdParSetGain.h" // for CbmTrdParSetGain #include "CbmTrdParSetGas.h" // for CbmTrdParSetGas +#include "CbmTrdParSetGeo.h" // for CbmTrdParSetGeo #include "CbmTrdParSpadic.h" // for CbmTrdParSpadic #include <FairParAsciiFileIo.h> // for FairParAsciiFileIo @@ -53,6 +55,7 @@ CbmTrdParManager::CbmTrdParManager(Bool_t fasp) , fDigiPar(nullptr) , fGasPar(nullptr) , fGainPar(nullptr) + , fGeoPar(nullptr) , fGeoHandler(new CbmTrdGeoHandler()) , fGeometryTag("") , fHardwareSetup() @@ -70,6 +73,7 @@ void CbmTrdParManager::SetParContainers() fDigiPar = (CbmTrdParSetDigi*) (rtdb->getContainer("CbmTrdParSetDigi")); fGasPar = (CbmTrdParSetGas*) (rtdb->getContainer("CbmTrdParSetGas")); fGainPar = (CbmTrdParSetGain*) (rtdb->getContainer("CbmTrdParSetGain")); + fGeoPar = (CbmTrdParSetGeo*) (rtdb->getContainer("CbmTrdParSetGeo")); } InitStatus CbmTrdParManager::Init() @@ -161,6 +165,10 @@ void CbmTrdParManager::CreateModuleParameters(const TString& path) Int_t moduleType = fGeoHandler->GetModuleType(path); printf("\nCbmTrdParManager::CreateModuleParameters(%s) type[%d]\n", path.Data(), moduleType); + // TODO Should move the geoHandler functionality to CbmTrdParSetGeo and remove code duplication + CbmTrdParModGeo* geo = new CbmTrdParModGeo(Form("TRD_%d", moduleAddress), path.Data()); + fGeoPar->addParam(geo); + for (Int_t i = 0; i < fst1_sect_count; i++) { sectorSizeX.AddAt(fst1_pad_type[moduleType - 1][i][0], i); sectorSizeY.AddAt(fst1_pad_type[moduleType - 1][i][1], i); @@ -417,6 +425,7 @@ void CbmTrdParManager::GetParSetList(std::vector<std::shared_ptr<CbmTrdParSet>>* case (Int_t) ECbmTrdParSets::kCbmTrdParSetDigi: parSet = std::make_shared<CbmTrdParSetDigi>(); break; case (Int_t) ECbmTrdParSets::kCbmTrdParSetGain: parSet = std::make_shared<CbmTrdParSetGain>(); break; case (Int_t) ECbmTrdParSets::kCbmTrdParSetGas: parSet = std::make_shared<CbmTrdParSetGas>(); break; + case (Int_t) ECbmTrdParSets::kCbmTrdParSetGeo: parSet = std::make_shared<CbmTrdParSetGeo>(); break; } parSetList->emplace_back(parSet); } @@ -431,6 +440,7 @@ void CbmTrdParManager::GetParFileExtensions(std::vector<std::string>* vec) case (Int_t) ECbmTrdParSets::kCbmTrdParSetDigi: vec->emplace_back("digi"); break; case (Int_t) ECbmTrdParSets::kCbmTrdParSetGain: vec->emplace_back("gas"); break; case (Int_t) ECbmTrdParSets::kCbmTrdParSetGas: vec->emplace_back("gain"); break; + case (Int_t) ECbmTrdParSets::kCbmTrdParSetGeo: vec->emplace_back("geo"); break; } } } diff --git a/core/detectors/trd/CbmTrdParManager.h b/core/detectors/trd/CbmTrdParManager.h index 51e5e19dc0..33e68afa24 100644 --- a/core/detectors/trd/CbmTrdParManager.h +++ b/core/detectors/trd/CbmTrdParManager.h @@ -34,6 +34,7 @@ class CbmTrdParSetAsic; class CbmTrdParSetDigi; class CbmTrdParSetGain; class CbmTrdParSetGas; +class CbmTrdParSetGeo; /** * \class CbmTrdParManager @@ -48,7 +49,8 @@ public: kCbmTrdParSetDigi, kCbmTrdParSetGain, kCbmTrdParSetGas, - kEnd = kCbmTrdParSetGas + kCbmTrdParSetGeo, + kEnd = kCbmTrdParSetGeo }; /** * @brief enumerator for organising the existing parameter sets of the trd @@ -115,6 +117,7 @@ private: CbmTrdParSetDigi* fDigiPar; ///< The set of read-out description parameters CbmTrdParSetGas* fGasPar; ///< The set of gas description parameters CbmTrdParSetGain* fGainPar; ///< The set of gain conversion parameters + CbmTrdParSetGeo* fGeoPar; ///< The set of gain conversion parameters CbmTrdGeoHandler* fGeoHandler; @@ -124,6 +127,6 @@ private: CbmTrdParManager(const CbmTrdParManager&); CbmTrdParManager& operator=(const CbmTrdParManager&); - ClassDef(CbmTrdParManager, 2) + ClassDef(CbmTrdParManager, 3) }; #endif // CBMTRDPARMANAGER_H diff --git a/core/detectors/trd/CbmTrdParModGeo.cxx b/core/detectors/trd/CbmTrdParModGeo.cxx index 7b58aab4e7..f91d4611ef 100644 --- a/core/detectors/trd/CbmTrdParModGeo.cxx +++ b/core/detectors/trd/CbmTrdParModGeo.cxx @@ -4,6 +4,8 @@ #include "CbmTrdParModGeo.h" +#include <Logger.h> + #include <TGeoBBox.h> // for TGeoBBox #include <TGeoMatrix.h> // for TGeoHMatrix #include <TGeoPhysicalNode.h> // for TGeoPhysicalNode @@ -13,7 +15,8 @@ //___________________________________________________________________ CbmTrdParModGeo::CbmTrdParModGeo(const char* name, const char* title) : CbmTrdParMod(name, title), fNode(nullptr) { - fNode = new TGeoPhysicalNode(title); + // AB : Do not initialize the physical node (alignment aware) at this point as the alignment is not applied yet + // fNode = new TGeoPhysicalNode(title); } //___________________________________________________________________ @@ -44,4 +47,20 @@ void CbmTrdParModGeo::GetXYZ(Double_t xyz[3]) const memcpy(xyz, gxyz, 3 * sizeof(Double_t)); } +//___________________________________________________________________ +bool CbmTrdParModGeo::SetNode() +{ + if (fNode) { + LOG(warn) << "CbmTrdParModGeo::SetNode: Aligned info already loaded. Updating"; + delete fNode; + } + fNode = new TGeoPhysicalNode(GetTitle()); + if (!fNode) return false; + + LOG(info) << GetName() << " : " << GetTitle(); + fNode->GetMatrix()->Print(); + + return true; +} + ClassImp(CbmTrdParModGeo) diff --git a/core/detectors/trd/CbmTrdParModGeo.h b/core/detectors/trd/CbmTrdParModGeo.h index 531b2b721f..42a4da3d66 100644 --- a/core/detectors/trd/CbmTrdParModGeo.h +++ b/core/detectors/trd/CbmTrdParModGeo.h @@ -41,6 +41,7 @@ public: return xyz[2]; } virtual void LocalToMaster(Double_t in[3], Double_t out[3]) const; + bool SetNode(); private: CbmTrdParModGeo(const CbmTrdParModGeo&); diff --git a/core/detectors/trd/CbmTrdParSetGeo.cxx b/core/detectors/trd/CbmTrdParSetGeo.cxx index b51bbe2319..39e099fea5 100644 --- a/core/detectors/trd/CbmTrdParSetGeo.cxx +++ b/core/detectors/trd/CbmTrdParSetGeo.cxx @@ -33,16 +33,17 @@ CbmTrdParSetGeo::CbmTrdParSetGeo(const char* name, const char* title, const char CbmTrdParSetGeo::~CbmTrdParSetGeo(void) {} //________________________________________________________________________________________ -Bool_t CbmTrdParSetGeo::Init() +bool CbmTrdParSetGeo::Init() { CbmTrdGeoHandler geo; TGeoNode* topNode = gGeoManager->GetTopNode(); TObjArray* nodes = topNode->GetNodes(); if (!nodes) { LOG(fatal) << "CbmTrdParSetGeo::Init: nodes is null!"; - return kFALSE; + return false; } + CbmTrdParModGeo* pGeo(nullptr); for (Int_t iNode = 0; iNode < nodes->GetEntriesFast(); iNode++) { TGeoNode* node = static_cast<TGeoNode*>(nodes->At(iNode)); if (!TString(node->GetName()).Contains("trd", TString::kIgnoreCase)) @@ -72,8 +73,10 @@ Bool_t CbmTrdParSetGeo::Init() LOG(debug) << "Adding detector with path " << path.Data(); // Generate a physical node which has all needed information gGeoManager->cd(path.Data()); - Int_t address = geo.GetModuleAddress(); - fModuleMap[address] = new CbmTrdParModGeo(Form("TRD_%d", address), path.Data()); + Int_t address = geo.GetModuleAddress(); + pGeo = new CbmTrdParModGeo(Form("TRD_%d", address), path.Data()); + pGeo->SetModuleId(address); + addParam(pGeo); } } } @@ -81,6 +84,20 @@ Bool_t CbmTrdParSetGeo::Init() return true; } +//________________________________________________________________________________________ +bool CbmTrdParSetGeo::LoadAlignVolumes() +{ + if (!GetNrOfModules()) { + LOG(error) << "CbmTrdParSetGeo::LoadAlignVolumes: No modules initialized. Nothing to do."; + return false; + } + + for (auto mod : fModuleMap) + if (!((CbmTrdParModGeo*) mod.second)->SetNode()) return false; + + return true; +} + //________________________________________________________________________________________ void CbmTrdParSetGeo::Print(Option_t*) const { diff --git a/core/detectors/trd/CbmTrdParSetGeo.h b/core/detectors/trd/CbmTrdParSetGeo.h index 72f92d247f..73540048b4 100644 --- a/core/detectors/trd/CbmTrdParSetGeo.h +++ b/core/detectors/trd/CbmTrdParSetGeo.h @@ -15,9 +15,12 @@ public: CbmTrdParSetGeo(const char* name = "CbmTrdParSetGeo", const char* title = "Trd Geometry Parameters", const char* context = "TestDefaultContext"); virtual ~CbmTrdParSetGeo(void); - /** \brief Fill map with full geometrical description for each detector to be distributed to all processing modules + /** \brief Fill map with full geometrical description for each detector to be distributed to all processing modules. Refer to the constructor of \class CbmTrdParModGeo for the details of using this description. */ - Bool_t Init(); + bool Init(); + /** \brief Trigger loading alignment information for all nodes registered */ + bool LoadAlignVolumes(); + virtual void Print(Option_t* opt = "") const; private: diff --git a/reco/detectors/trd/CbmTrdClusterFinder.cxx b/reco/detectors/trd/CbmTrdClusterFinder.cxx index f3caa4eb49..10aad5baa8 100644 --- a/reco/detectors/trd/CbmTrdClusterFinder.cxx +++ b/reco/detectors/trd/CbmTrdClusterFinder.cxx @@ -202,12 +202,12 @@ CbmTrdModuleRec* CbmTrdClusterFinder::AddModule(const CbmTrdDigi* digi) //_____________________________________________________________________ void CbmTrdClusterFinder::SetParContainers() { - fAsicPar = static_cast<CbmTrdParSetAsic*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetAsic")); - fGasPar = static_cast<CbmTrdParSetGas*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGas")); - fDigiPar = static_cast<CbmTrdParSetDigi*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetDigi")); - fGainPar = static_cast<CbmTrdParSetGain*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGain")); - // Get the full geometry information of the TRD modules - fGeoPar = new CbmTrdParSetGeo(); + FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb(); + fAsicPar = static_cast<CbmTrdParSetAsic*>(rtdb->getContainer("CbmTrdParSetAsic")); + fGasPar = static_cast<CbmTrdParSetGas*>(rtdb->getContainer("CbmTrdParSetGas")); + fDigiPar = static_cast<CbmTrdParSetDigi*>(rtdb->getContainer("CbmTrdParSetDigi")); + fGainPar = static_cast<CbmTrdParSetGain*>(rtdb->getContainer("CbmTrdParSetGain")); + fGeoPar = static_cast<CbmTrdParSetGeo*>(rtdb->getContainer("CbmTrdParSetGeo")); } //_____________________________________________________________________ diff --git a/reco/detectors/trd/CbmTrdHitProducer.cxx b/reco/detectors/trd/CbmTrdHitProducer.cxx index f7a2e68cae..0a9ab6b829 100644 --- a/reco/detectors/trd/CbmTrdHitProducer.cxx +++ b/reco/detectors/trd/CbmTrdHitProducer.cxx @@ -84,17 +84,17 @@ UInt_t CbmTrdHitProducer::addModuleHits(CbmTrdModuleRec* mod, CbmEvent* event) } //____________________________________________________________________________________ -CbmTrdModuleRec* CbmTrdHitProducer::AddModule(Int_t address, TGeoPhysicalNode* node) +CbmTrdModuleRec* CbmTrdHitProducer::AddModule(Int_t address, const CbmTrdParModGeo* pg) { CbmTrdGeoHandler geoHandler; - Int_t moduleAddress = geoHandler.GetModuleAddress(node->GetName()), - moduleType = geoHandler.GetModuleType(node->GetName()), lyId = CbmTrdAddress::GetLayerId(address); + Int_t moduleAddress = geoHandler.GetModuleAddress(pg->GetTitle()), + moduleType = geoHandler.GetModuleType(pg->GetTitle()), lyId = CbmTrdAddress::GetLayerId(address); if (moduleAddress != address) { LOG(error) << "CbmTrdHitProducer::AddModule: Module ID " << address << " does not match geometry definition " << moduleAddress << ". Module init failed!"; return NULL; } - LOG(info) << GetName() << "::AddModule(" << node->GetName() << " " << (moduleType < 9 ? '1' : '2') << "D] mod[" + LOG(info) << GetName() << "::AddModule(" << pg->GetName() << " " << (moduleType < 9 ? '1' : '2') << "D] mod[" << moduleAddress << "] ly[" << lyId << "] det[" << moduleAddress << "]"; CbmTrdModuleRec* module(nullptr); @@ -106,14 +106,8 @@ CbmTrdModuleRec* CbmTrdHitProducer::AddModule(Int_t address, TGeoPhysicalNode* n module = fModules[address] = new CbmTrdModuleRecR(address); } - // Try to load geometry parameters for the module - const CbmTrdParModGeo* pGeo = nullptr; - if (!fGeoPar) LOG(warn) << GetName() << ": No geometry parameter container!"; - else - pGeo = (const CbmTrdParModGeo*) fGeoPar->GetModulePar(address); - if (!pGeo) LOG(warn) << GetName() << ": No geometry parameters for module " << address; - else - module->SetGeoPar(pGeo); + // Load geometry parameters for the module + module->SetGeoPar(pg); // try to load read-out parameters for module @@ -267,21 +261,21 @@ InitStatus CbmTrdHitProducer::Init() // Get the full geometry information of the detector gas layers and store // them with the CbmTrdModuleRec. This information can then be used for // transformation calculations - CbmTrdGeoHandler geoHandler; - std::map<Int_t, TGeoPhysicalNode*> moduleMap = geoHandler.FillModuleMap(); + if (!fGeoPar->LoadAlignVolumes()) { + LOG(error) << GetName() << "::Init: " + << "GEO info for modules unavailable !"; + return kFATAL; + } Int_t nrModules = fDigiPar->GetNrOfModules(); - Int_t nrNodes = moduleMap.size(); + Int_t nrNodes = fGeoPar->GetNrOfModules(); if (nrModules != nrNodes) LOG(fatal) << "CbmTrdHitProducer::Init() - Geometry(" << nrNodes << ") and parameter files(" << nrModules << ") have different number of modules."; for (Int_t loop = 0; loop < nrModules; ++loop) { - Int_t address = fDigiPar->GetModuleId(loop); - std::map<Int_t, TGeoPhysicalNode*>::iterator it = moduleMap.find(address); - if (it == moduleMap.end()) { - LOG(fatal) << "Expected module with address " << address << " wasn't found in the map with TGeoNode information."; - } - AddModule(address, it->second); + int address = fGeoPar->GetModuleId(loop); + const CbmTrdParModGeo* par = (const CbmTrdParModGeo*) fGeoPar->GetModulePar(address); + AddModule(address, par); } return kSUCCESS; } @@ -370,11 +364,12 @@ void CbmTrdHitProducer::Finish() //________________________________________________________________________________________ void CbmTrdHitProducer::SetParContainers() { - fAsicPar = static_cast<CbmTrdParSetAsic*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetAsic")); - fGasPar = static_cast<CbmTrdParSetGas*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGas")); - fDigiPar = static_cast<CbmTrdParSetDigi*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetDigi")); - fGainPar = static_cast<CbmTrdParSetGain*>(FairRunAna::Instance()->GetRuntimeDb()->getContainer("CbmTrdParSetGain")); - fGeoPar = new CbmTrdParSetGeo(); + FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb(); + fAsicPar = static_cast<CbmTrdParSetAsic*>(rtdb->getContainer("CbmTrdParSetAsic")); + fGasPar = static_cast<CbmTrdParSetGas*>(rtdb->getContainer("CbmTrdParSetGas")); + fDigiPar = static_cast<CbmTrdParSetDigi*>(rtdb->getContainer("CbmTrdParSetDigi")); + fGainPar = static_cast<CbmTrdParSetGain*>(rtdb->getContainer("CbmTrdParSetGain")); + fGeoPar = static_cast<CbmTrdParSetGeo*>(rtdb->getContainer("CbmTrdParSetGeo")); } diff --git a/reco/detectors/trd/CbmTrdHitProducer.h b/reco/detectors/trd/CbmTrdHitProducer.h index f3781cb1d8..9cd1c6e2b3 100644 --- a/reco/detectors/trd/CbmTrdHitProducer.h +++ b/reco/detectors/trd/CbmTrdHitProducer.h @@ -26,7 +26,7 @@ #include <limits> -class TGeoPhysicalNode; +class CbmTrdParModGeo; class CbmTrdParSetAsic; class CbmTrdParSetGas; class CbmTrdParSetDigi; @@ -65,7 +65,7 @@ private: CbmTrdHitProducer(const CbmTrdHitProducer&); CbmTrdHitProducer& operator=(const CbmTrdHitProducer&); - CbmTrdModuleRec* AddModule(Int_t address, TGeoPhysicalNode* node); + CbmTrdModuleRec* AddModule(Int_t address, const CbmTrdParModGeo* pg); /** * @brief Process all clusters found in the TrdClusters branch -- GitLab