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);
44 fvbDetHasHits[detID] = fvbDetInGeometry[detID] && FairRootManager::Instance()->GetObject(kDetHitBrName[detID]);
45 LOG(info) << fmt::format("\t{:6} in geometry: {:5}, has hits: {:5}", ToString(modId), fvbDetInGeometry[detID],
46 fvbDetHasHits[detID]);
47 };
48
49 Check(EDetectorID::kMvd);
50 Check(EDetectorID::kSts);
51 Check(EDetectorID::kMuch);
52 Check(EDetectorID::kTrd);
53 Check(EDetectorID::kTof);
54}
55
56// ---------------------------------------------------------------------------------------------------------------------
57//
58std::shared_ptr<const cbm::algo::kf::Setup<double>> TrackingSetupBuilder::GetSharedGeoSetup()
59{
62 if (!fpGeoSetup.get()) {
63 fpGeoSetup = std::make_shared<Setup<double>>(this->MakeSetup<double>(EFieldMode::Orig));
64 }
65 return fpGeoSetup;
66}
67
68// ---------------------------------------------------------------------------------------------------------------------
69//
71try {
76
78 // Magnetic field initialization
79 if (auto* pField = FairRunAna::Instance()->GetField()) {
80 LOG(info) << fabs(pField->GetBx(0., 0., 0.)) << ", " << fabs(pField->GetBy(0., 0., 0.)) << ", "
81 << fabs(pField->GetBz(0., 0., 0.)) << ", " << pField->GetType();
82 if (
83 pField->GetType() == 0
84 && fabs(pField->GetBx(0., 0., 0.)) < MinField<
85 double> && fabs(pField->GetBy(0., 0., 0.)) < MinField<double> && fabs(pField->GetBz(0., 0., 0.)) < MinField<double>) {
86 fBuilder.SetFieldFunction(cbm::kf::ZeroField(), EFieldType::Null);
87 }
88 else {
90 }
91 }
92 else {
93 fBuilder.SetFieldFunction(cbm::kf::ZeroField(), EFieldType::Null);
94 }
95
96 // Tracking station property initialization
97 auto CollectStations = [&](const auto* pIfs, EDetectorID detID) -> void {
98 if (!fvbDetInGeometry[detID]) {
99 return;
100 }
101 for (int iSt = 0; iSt < pIfs->GetNtrackingStations(); ++iSt) {
102 fBuilder.AddLayer(GeoLayer<EDetectorID>{detID, // ca::Tracking detector id scheme
103 iSt, // ca::Tracking station indexing
104 pIfs->GetZref(iSt), pIfs->GetZmin(iSt), pIfs->GetZmax(iSt),
105 std::max(std::fabs(pIfs->GetXmin(iSt)), std::fabs(pIfs->GetXmax(iSt))),
106 std::max(std::fabs(pIfs->GetYmin(iSt)), std::fabs(pIfs->GetYmax(iSt)))});
107 }
108 };
109 CollectStations(CbmMvdTrackingInterface::Instance(), EDetectorID::kMvd);
110 CollectStations(CbmStsTrackingInterface::Instance(), EDetectorID::kSts);
111 CollectStations(CbmMuchTrackingInterface::Instance(), EDetectorID::kMuch);
112 CollectStations(CbmTrdTrackingInterface::Instance(), EDetectorID::kTrd);
113 CollectStations(CbmTofTrackingInterface::Instance(), EDetectorID::kTof);
114
115 // Retrieve target properties
116 const auto* pTarget = cbm::kf::Target::Instance();
117 fBuilder.SetTargetProperty(pTarget->GetX(), pTarget->GetY(), pTarget->GetZ(), pTarget->GetDz(), pTarget->GetRmax());
118
119 // Init material map creator
120 auto pMaterialFactory = std::make_shared<MaterialMapFactory>();
121 pMaterialFactory->SetSafeMaterialInitialization(kMatCreatorSafeMode);
122 pMaterialFactory->SetDoRadialProjection(pTarget->GetZ());
123 pMaterialFactory->SetNraysPerDim(kMatCreatorNrays);
124 fBuilder.SetMaterialMapFactory(pMaterialFactory);
125
126 // Set the initialization flags back
127 fbInitialized = true;
128 LOG(info) << "ca::TrackingSetupBuilder: Tracking setup was initialized successfully";
129}
130catch (const std::exception& err) {
131 fbInitialized = false;
132 LOG(error) << "ca::TrackingSetupBuilder: Tracking setup was not initialized. Reason: " << err.what();
133}
134
135// ---------------------------------------------------------------------------------------------------------------------
136//
138{
139 namespace fs = boost::filesystem;
140 if (fpInstance == nullptr) {
141 std::lock_guard<std::mutex> lock(fMutex);
144
145 // Retrieve the geometry tag
146 auto setupTag = CbmSetup::Instance()->GetProvider()->GetSetup().GetTag();
147 if (setupTag.empty()) {
148 throw std::logic_error("The setup tag in CbmSetup is not defined");
149 }
150
151 // Retrieve the data directory (the same as for the sink file)
152 TString sinkName = FairRootManager::Instance()->GetSink()->GetFileName();
153 auto sinkPath = fs::path{sinkName.Data()};
154 std::string sDataDir = sinkPath.parent_path().string();
155 if (sDataDir.empty()) {
156 sDataDir = ".";
157 }
158
159 std::string sCacheFile = Form("%s/%s.mat.kf.bin", sDataDir.c_str(), setupTag.c_str());
160 fpInstance->SetMaterialCacheFile(sCacheFile, CbmSetup::Instance()->GetHash());
161 }
162 return fpInstance;
163}
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
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.