CbmRoot
Loading...
Searching...
No Matches
CbmKfTrackingSetupBuilder.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
12#include "CbmKfOriginalField.h"
13#include "CbmKfTarget.h"
16#include "CbmSetup.h"
17#include "CbmStsFindTracks.h"
21#include "FairField.h"
22#include "FairRootManager.h"
23#include "FairRunAna.h"
24#include "KfDefs.h"
26#include "Logger.h"
27
28#include <boost/filesystem.hpp>
29
30#include <functional>
31
35
36// ---------------------------------------------------------------------------------------------------------------------
37//
39{
40 LOG(info) << "TrackingSetupBuilder: detector subsystems in geometry: ";
41 auto Check = [&](EDetectorID detID) {
42 auto modId = cbm::algo::ca::ToCbmModuleId(detID);
45 fvbDetHasHits[detID] = fvbDetInGeometry[detID] && FairRootManager::Instance()->GetObject(kDetHitBrName[detID]);
46 LOG(info) << fmt::format("\t{:6} in geometry: {:5}, has hits: {:5}", ToString(modId), fvbDetInGeometry[detID],
47 fvbDetHasHits[detID]);
48 }
49 else {
50 fvbDetHasHits[detID] = fvbDetInGeometry[detID];
51 LOG(info) << fmt::format("\t{:6} in geometry: {:5}", ToString(modId), fvbDetInGeometry[detID]);
52 }
53 };
54
55 Check(EDetectorID::kMvd);
56 Check(EDetectorID::kSts);
57 Check(EDetectorID::kMuch);
58 Check(EDetectorID::kTrd);
59 Check(EDetectorID::kTof);
60}
61
62// ---------------------------------------------------------------------------------------------------------------------
63//
64std::shared_ptr<const cbm::algo::kf::Setup<double>> TrackingSetupBuilder::GetSharedGeoSetup()
65{
68 if (!fpGeoSetup.get()) {
69 fpGeoSetup = std::make_shared<Setup<double>>(this->MakeSetup<double>(EFieldMode::Orig));
70 }
71 return fpGeoSetup;
72}
73
74// ---------------------------------------------------------------------------------------------------------------------
75//
77try {
82
84 // Magnetic field initialization
85 if (auto* pField = FairRunAna::Instance()->GetField()) {
86 LOG(info) << fabs(pField->GetBx(0., 0., 0.)) << ", " << fabs(pField->GetBy(0., 0., 0.)) << ", "
87 << fabs(pField->GetBz(0., 0., 0.)) << ", " << pField->GetType();
88 if (
89 pField->GetType() == 0
90 && fabs(pField->GetBx(0., 0., 0.)) < MinField<
91 double> && fabs(pField->GetBy(0., 0., 0.)) < MinField<double> && fabs(pField->GetBz(0., 0., 0.)) < MinField<double>) {
92 fBuilder.SetFieldFunction(cbm::kf::ZeroField(), EFieldType::Null);
93 }
94 else {
96 }
97 }
98 else {
99 fBuilder.SetFieldFunction(cbm::kf::ZeroField(), EFieldType::Null);
100 }
101
102 // Tracking station property initialization
103 auto CollectStations = [&](const auto* pIfs, EDetectorID detID) -> void {
104 if (!fvbDetInGeometry[detID]) {
105 return;
106 }
107 for (int iSt = 0; iSt < pIfs->GetNtrackingStations(); ++iSt) {
108 fBuilder.AddLayer(GeoLayer<EDetectorID>{detID, // ca::Tracking detector id scheme
109 iSt, // ca::Tracking station indexing
110 pIfs->GetZref(iSt), pIfs->GetZmin(iSt), pIfs->GetZmax(iSt),
111 std::max(std::fabs(pIfs->GetXmin(iSt)), std::fabs(pIfs->GetXmax(iSt))),
112 std::max(std::fabs(pIfs->GetYmin(iSt)), std::fabs(pIfs->GetYmax(iSt)))});
113 }
114 };
115 CollectStations(CbmMvdTrackingInterface::Instance(), EDetectorID::kMvd);
116 CollectStations(CbmStsTrackingInterface::Instance(), EDetectorID::kSts);
117 CollectStations(CbmMuchTrackingInterface::Instance(), EDetectorID::kMuch);
118 CollectStations(CbmTrdTrackingInterface::Instance(), EDetectorID::kTrd);
119 CollectStations(CbmTofTrackingInterface::Instance(), EDetectorID::kTof);
120
121 // Retrieve target properties
122 const auto* pTarget = cbm::kf::Target::Instance();
123 fBuilder.SetTargetProperty(pTarget->GetX(), pTarget->GetY(), pTarget->GetZ(), pTarget->GetDz(), pTarget->GetRmax());
124
125 // Init material map creator
126 auto pMaterialFactory = std::make_shared<MaterialMapFactory>();
127 pMaterialFactory->SetSafeMaterialInitialization(kMatCreatorSafeMode);
128 pMaterialFactory->SetDoRadialProjection(pTarget->GetZ());
129 pMaterialFactory->SetNraysPerDim(kMatCreatorNrays);
130 fBuilder.SetMaterialMapFactory(pMaterialFactory);
131
132 // Set the initialization flags back
133 fbInitialized = true;
134 LOG(info) << "ca::TrackingSetupBuilder: Tracking setup was initialized successfully";
135}
136catch (const std::exception& err) {
137 fbInitialized = false;
138 LOG(error) << "ca::TrackingSetupBuilder: Tracking setup was not initialized. Reason: " << err.what();
139}
140
141// ---------------------------------------------------------------------------------------------------------------------
142//
144{
145 namespace fs = boost::filesystem;
146 if (fpInstance == nullptr) {
147 std::lock_guard<std::mutex> lock(fMutex);
150
151 // Retrieve the geometry tag
152 auto setupTag = CbmSetup::Instance()->GetProvider()->GetSetup().GetTag();
153 if (setupTag.empty()) {
154 throw std::logic_error("The setup tag in CbmSetup is not defined");
155 }
156
157 // Retrieve the data directory (the same as for the sink file)
158 TString sinkName = FairRootManager::Instance()->GetSink()->GetFileName();
159 auto sinkPath = fs::path{sinkName.Data()};
160 std::string sDataDir = sinkPath.parent_path().string();
161 if (sDataDir.empty()) {
162 sDataDir = ".";
163 }
164
165 std::string sCacheFile = Form("%s/%s.mat.kf.bin", sDataDir.c_str(), setupTag.c_str());
166 fpInstance->SetMaterialCacheFile(sCacheFile, CbmSetup::Instance()->GetHash());
167 }
168 return fpInstance;
169}
std::string ToString(ECbmModuleId modId)
Definition CbmDefs.cxx:70
Thread-safe representation of the magnetic field (header)
Target property initialization and access in CBM (source)
Common constant definitions for the Kalman Filter library.
Utility to generate material budget map from the TGeoNavigator representation of the Setup (implement...
CbmGeoSetup & GetSetup()
Direct access to underlying geometry setup representation. Allows for fine-tuning of parameters,...
std::string GetTag()
Definition CbmGeoSetup.h:38
static CbmMuchTrackingInterface * Instance()
Gets pointer to the instance of the CbmMuchTrackingInterface.
static CbmMvdTrackingInterface * Instance()
Gets pointer to the instance of the CbmMvdTrackingInterface.
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
static CbmStsTrackingInterface * Instance()
Gets pointer to the instance of the CbmStsTrackingInterface class.
static CbmTofTrackingInterface * Instance()
Gets pointer to the instance of the CbmTofTrackingInterface.
static CbmTrdTrackingInterface * Instance()
Gets pointer to the instance of the CbmTrdTrackingInterface.
void AddLayer(const GeoLayer< EDetID > &geoLayer)
Adds material layer.
void Reset()
Resets the instance.
void SetMaterialMapFactory(const std::shared_ptr< IMaterialMapFactory > &pMaterialFactory)
Sets material map creator.
void SetFieldFunction(const FieldFn_t &fieldFn, EFieldType fieldType)
Sets magnetic field function.
void SetTargetProperty(double x, double y, double z, double dz, double r)
Sets target initialization properties.
KF-framework representation of the detector setup.
Definition KfSetup.h:33
Thread-safe representation of the magnetic field in CBM.
static Target * Instance()
Instance access.
Encapsulation of the kf::Setup initialization routines for CBM.
static constexpr bool kMatCreatorSafeMode
Safe mode of the material map creation.
cbm::algo::kf::Setup< T > MakeSetup(cbm::algo::kf::EFieldMode fldMode)
Makes setup object.
void SetMaterialCacheFile(const TString &filename, size_t geoHash)
Sets the material budget cache file name.
std::shared_ptr< const cbm::algo::kf::Setup< double > > GetSharedGeoSetup()
Gets a shared pointer to the geometry setup.
bool fbInitialized
Checks, if the setup was already initialized.
static constexpr int kMatCreatorNrays
Number of rays per dimension for the material budget.
static TrackingSetupBuilder * Instance()
Instance access.
void Init()
Initializes the instance.
cbm::algo::kf::SetupBuilder fBuilder
KF-setup builder.
std::shared_ptr< cbm::algo::kf::Setup< double > > fpGeoSetup
An instance of the tracking KF-setup in a double precision.
static constexpr DetectorIDArray_t< const char * > kDetHitBrName
Hit branch names vs. cbm::algo::ca::EDetectorID.
DetectorIDArray_t< bool > fvbDetHasHits
Does detector subsystem have hits?
void CheckDetectorPresence()
Check detector presence.
static TrackingSetupBuilder * fpInstance
bool fbIgnoreHitPresence
Ignores hit presence, when active subsystems are determined.
DetectorIDArray_t< bool > fvbDetInGeometry
Is detector subsystem in geometry?
An utility class to create a material budget map from the TGeo.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
Definition CbmDefs.h:176
ECbmModuleId ToCbmModuleId(EDetectorID detID)
Conversion map from EDetectorID to ECbmModuleId.
Definition CbmDefs.cxx:108
constexpr auto MinField
Minimal (negligible) magnetic field value [kG].
Definition KfDefs.h:110
EFieldMode
Enumiration for the magnetic field representation variants in the track fitting algorithm.
Definition KfDefs.h:27
EFieldType
Magnetic field type in different setup regions.
Definition KfDefs.h:37
A helper structure to store geometrical information of the layers.