CbmRoot
Loading...
Searching...
No Matches
CbmKfTrackingGeoSetupFactory.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024-2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
12#include "CbmKfTarget.h"
13#include "CbmRecoSetupManager.h"
14#include "CbmSetup.h"
15#include "CbmStsFindTracks.h"
16#include "KfDefs.h"
18#include "KfToolsField.h"
19
20#include <FairField.h>
21#include <FairRootManager.h>
22#include <FairRunAna.h>
23#include <Logger.h>
24
25#include <boost/filesystem.hpp>
26
27#include <functional>
28
31using kf::tools::MaterialMapFactory;
32
33// FIXME: provide a validation function to ensure, that all necessary input is properly initialized:
34// 1) Det. interfaces
35// 2) Magnetic field
36// 3) Target
37// 4) GeoManager
38
39// ---------------------------------------------------------------------------------------------------------------------
40//
42try {
46 LOG(info) << "cbm::kf::TrackingGeoSetupFactory: initializing ...";
47
48 CheckDetectorPresence(requireHitPresence);
49
50 // Reco setup instance
51 if (!RecoSetupManager::Instance()->IsInitialized()) {
52 throw std::runtime_error("cbm::RecoSetupManager not initialized");
53 }
54
55 // Magnetic field initialization
57
58 fBuilder.SetFieldFunction(GlobalField::fgOriginalField, GlobalField::fgOriginalFieldType);
59
60 // NOTE: assigning a field type for a station: a field on the station is Normal, the field value in the middle
61 // of the station is above the threshold.
62 auto GuessFieldType = [&](double z) -> EFieldType {
63 auto [Bx, By, Bz] = GlobalField::fgOriginalField(0., 0., z);
64 double absBsq = Bx * Bx + By * By + Bz * Bz;
65 return absBsq < MinField<double> * MinField<double> ? EFieldType::Null : EFieldType::Normal;
66 };
67
68 // Set tracking station properties
69 auto CollectStations = [&](const auto* pIfs, EDetectorID detID) -> void {
70 if (!fvbDetInGeometry[detID]) {
71 return;
72 }
73 for (int iSt = 0; iSt < pIfs->GetNofTrackingStations(); ++iSt) {
74 const auto& actVol = pIfs->GetActiveVolume(iSt);
75 const auto& fullVol = pIfs->GetFullVolume(iSt);
76 fBuilder.AddLayer({
77 .detId = static_cast<int>(detID), // detector ID (ca::EDetectorID)
78 .locId = iSt, // local station ID
79 .zRef = actVol.GetCenterZ(), // ref. z-position [cm]
80 .zMin = fullVol.GetMinZ(), // lower bound in z-direction [cm]
81 .zMax = fullVol.GetMaxZ(), // upper bound in z-direction [cm]
82 .xMinFull = fullVol.GetMinX(), // lower bound of full volume in x-direction [cm]
83 .xMaxFull = fullVol.GetMaxX(), // upper bound of full volume in x-direction [cm]
84 .yMinFull = fullVol.GetMinY(), // lower bound of full volume in y-direction [cm]
85 .yMaxFull = fullVol.GetMaxY(), // upper bound of full volume in y-direction [cm]
86 .xMinAct = actVol.GetMinX(), // lower bound of active volume in x-direction [cm]
87 .xMaxAct = actVol.GetMaxX(), // lower bound of active volume in x-direction [cm]
88 .yMinAct = actVol.GetMinY(), // lower bound of active volume in x-direction [cm]
89 .yMaxAct = actVol.GetMaxY(), // lower bound of active volume in x-direction [cm]
90 .fieldType = GuessFieldType(actVol.GetCenterZ()), // field type
91 .timeInfo = pIfs->IsTimeInfoProvided(iSt) // time measurement flag
92 });
93 }
94 };
95
96 const auto& recoSetup = RecoSetupManager::Instance()->GetSetup();
97 CollectStations(recoSetup.GetMvd(), EDetectorID::kMvd);
98 CollectStations(recoSetup.GetSts(), EDetectorID::kSts);
99 CollectStations(recoSetup.GetMuch(), EDetectorID::kMuch);
100 CollectStations(recoSetup.GetTrd(), EDetectorID::kTrd);
101 CollectStations(recoSetup.GetTof(), EDetectorID::kTof);
102
103 // Set target properties
104 const auto* pTarget = cbm::kf::Target::Instance();
105 fBuilder.SetTargetProperty(pTarget->GetX(), pTarget->GetY(), pTarget->GetZ(), pTarget->GetDz(), pTarget->GetRmax());
106
107 // Set material map creator
108 auto pMaterialFactory = std::make_shared<MaterialMapFactory>();
109 pMaterialFactory->SetSafeMaterialInitialization(kMatCreatorSafeMode);
110 pMaterialFactory->SetDoRadialProjection(pTarget->GetZ());
111 pMaterialFactory->SetNraysPerDim(kMatCreatorNrays);
112 fBuilder.SetMaterialMapFactory(pMaterialFactory);
113 fBuilder.SetMaterialCacheFile(MaterialCacheFile(), CbmSetup::Instance()->GetHash());
114 fBuilder.Init();
115 LOG(info) << "cbm::kf::TrackingGeoSetupFactory: initializing ... done";
116}
117catch (const std::exception& err) {
118 LOG(fatal) << "cbm::kf::TrackingGeoSetupFactory: initializing ... failed. Reason: " << err.what();
119}
120
121
122// ---------------------------------------------------------------------------------------------------------------------
123//
125{
126 LOG(info) << "TrackingGeoSetupFactory: detector subsystems in geometry: ";
127 auto Check = [&](EDetectorID detID) {
128 auto modId = cbm::algo::ca::ToCbmModuleId(detID);
130 if (requireHitPresence) {
131 fvbDetHasHits[detID] = fvbDetInGeometry[detID] && FairRootManager::Instance()->GetObject(kDetHitBrName[detID]);
132 LOG(info) << fmt::format("\t{:6} in geometry: {:5}, has hits: {:5}", std::string(cbm::util::ToString(modId)),
133 fvbDetInGeometry[detID], fvbDetHasHits[detID]);
134 }
135 else {
136 fvbDetHasHits[detID] = fvbDetInGeometry[detID];
137 LOG(info) << fmt::format("\t{:6} in geometry: {:5}", std::string(cbm::util::ToString(modId)),
138 fvbDetInGeometry[detID]);
139 }
140 };
141
142 Check(EDetectorID::kMvd);
143 Check(EDetectorID::kSts);
144 Check(EDetectorID::kMuch);
145 Check(EDetectorID::kTrd);
146 Check(EDetectorID::kTof);
147}
148
149// ---------------------------------------------------------------------------------------------------------------------
150//
152{
153 namespace fs = boost::filesystem;
154
155 auto setupTag = CbmSetup::Instance()->GetProvider()->GetSetup().GetTag();
156 if (setupTag.empty()) {
157 throw std::logic_error("The setup tag in CbmSetup is not defined");
158 }
159
160 TString sinkName = FairRootManager::Instance()->GetSink()->GetFileName();
161 auto sinkPath = fs::path{sinkName.Data()};
162 std::string sDataDir = sinkPath.parent_path().string();
163 if (sDataDir.empty()) {
164 sDataDir = ".";
165 }
166
167 return Form("%s/%s.mat.kf.bin", sDataDir.c_str(), setupTag.c_str());
168}
Target property initialization and access in CBM (source)
A manager for setup representation in CBM reconstruction.
Common constant definitions for the Kalman Filter library.
Utility to generate material budget map from the TGeoNavigator representation of the Setup (implement...
Tracking Field class (header)
CbmGeoSetup & GetSetup()
Direct access to underlying geometry setup representation. Allows for fine-tuning of parameters,...
std::string GetTag()
Definition CbmGeoSetup.h:38
Bool_t IsActive(ECbmModuleId moduleId)
Definition CbmSetup.cxx:169
static CbmSetup * Instance()
Definition CbmSetup.cxx:160
CbmGeoSetupProvider * GetProvider()
Get the geo setup provider.
Definition CbmSetup.h:197
TrackingGeoSetupFactory(bool requireHitPresence=false)
Constructor (RAII)
const algo::RecoSetup & GetSetup() const
Setup accessor.
static RecoSetupManager * Instance()
Instance access.
Handler for the global magnetic field related functions.
static Target * Instance()
Instance access.
A factory for geometry tracking KF-setup in CBM.
algo::kf::SetupBuilder fBuilder
KF-setup builder.
static constexpr DetectorIDArray_t< const char * > kDetHitBrName
Hit branch names vs. EDetectorID.
DetectorIDArray_t< bool > fvbDetHasHits
Does detector subsystem have hits?
static constexpr int kMatCreatorNrays
Number of rays per dimension for the material budget.
DetectorIDArray_t< bool > fvbDetInGeometry
Is detector subsystem in geometry?
void CheckDetectorPresence(bool requireHitPresence)
Check detector presence.
static constexpr bool kMatCreatorSafeMode
Safe mode of the material map creation.
std::string MaterialCacheFile() const
Gets the material budget cache-file.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
Definition CbmDefs.h:216
constexpr ECbmModuleId ToCbmModuleId(EDetectorID detID)
Conversion map from EDetectorID to ECbmModuleId.
Definition CbmDefs.h:228
constexpr auto MinField
Minimal (negligible) magnetic field value [kG].
Definition KfDefs.h:213
EFieldType
Magnetic field type in different setup regions.
Definition KfDefs.h:126
void SetOriginalCbmField()
pass the original magnetic field to L1Algo
std::string_view ToString(T t)
Definition CbmEnumDict.h:64