CbmRoot
Loading...
Searching...
No Matches
CbmGenerateMaterialMaps.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 "CbmKfTarget.h"
15#include "KfRootUtils.h"
16#include "TFile.h"
17#include "TH2F.h"
18
19// ---------------------------------------------------------------------------------------------------------------------
20//
22
23// ---------------------------------------------------------------------------------------------------------------------
24//
25CbmGenerateMaterialMaps::CbmGenerateMaterialMaps(const char* name, int verbose) : FairTask(name, verbose) {}
26
27// ---------------------------------------------------------------------------------------------------------------------
28//
30
31// ---------------------------------------------------------------------------------------------------------------------
32//
34{
35 // ----- Init configuration
36 if (!fsUserConfig.empty()) {
38 }
39 else {
40 LOG(info) << fName << ": configuration file was not provided. Using default settings";
41 }
42
44
45 fpMaterialFactory = std::make_unique<::kf::tools::MaterialMapFactory>();
47 fpMaterialFactory->SetDoRadialProjection(fTargetZ);
48 }
49 fpMaterialFactory->SetSafeMaterialInitialization(true);
50 fpMaterialFactory->SetNraysPerDim(fConfig.fNofRays);
51
53 std::set<MaterialSlice> mSlice;
54 // Loop over stations
56 if (pIfs) {
57 for (const auto* pIf : pIfs->GetActiveInterfaces()) {
58 auto detName = pIf->GetDetectorName();
59 LOG(info) << fName << ": Generating material budget map for " << detName;
60 int nSt = pIf->GetNtrackingStations();
61 for (int iSt = 0; iSt < nSt; ++iSt) {
62 MaterialSlice slice;
63 slice.fName = detName + Form("_station_%d", iSt);
64 slice.fRefZ = pIf->GetZref(iSt);
65 slice.fMinZ = pIf->GetZmin(iSt);
66 slice.fMaxZ = pIf->GetZmax(iSt);
67 slice.fMaxXY = std::max(std::fabs(pIf->GetXmax(iSt)), std::fabs(pIf->GetYmax(iSt)));
68 mSlice.insert(slice);
69 }
70 }
71 double zLast = fTargetZ + 1.;
72 // Run material helper
73 for (auto it = mSlice.begin(); it != mSlice.end(); ++it) {
74 LOG(info) << "Creating material map for " << it->fName;
75 double z1 = it->fMaxZ;
76 double z2 = z1;
77 auto itNext = std::next(it, 1);
78 if (itNext != mSlice.end()) {
79 z2 = itNext->fMinZ;
80 }
81 double zRef = it->fRefZ;
82 double zNew = 0.5 * (z1 + z2);
83 double xyMax = kXYoffset * it->fMaxXY;
84 int nBins = static_cast<int>(std::ceil(2. * xyMax / fConfig.fPitch));
85 if (nBins < 1) {
86 LOG(fatal) << fName << ": selected pitch " << fConfig.fPitch << " gives wrong number of bins = " << nBins;
87 }
88 if (nBins > fConfig.fMaxNofBins) {
89 nBins = fConfig.fMaxNofBins;
90 }
91 fmMaterial[it->fName] = std::move(fpMaterialFactory->GenerateMaterialMap(zRef, zLast, zNew, xyMax, nBins));
92 zLast = zNew;
93 }
94 }
95 else {
96 LOG(error) << fName << ": tracking detector interfaces are not defined, so the materials maps cannot be "
97 << "generated for the tracking stations";
98 }
99 }
100
101 // Loop over user-defined slices
102 for (const auto& slice : fConfig.fvUserSlices) {
103 LOG(info) << "Creating material map for " << slice.fName;
104 if (fmMaterial.find(slice.fName) != fmMaterial.end()) {
105 LOG(warn) << fName << ": Material for slice " << slice.fName << " was already prepared. "
106 << "Please, check your configuration file";
107 continue;
108 }
109 double xyMax = kXYoffset * slice.fMaxXY;
110 double zMin = slice.fMinZ;
111 double zMax = slice.fMaxZ;
112 double zRef = slice.fRefZ;
113
114 int nBins = static_cast<int>(std::ceil(2. * xyMax / fConfig.fPitch));
115
116 if (nBins < 1) {
117 LOG(fatal) << fName << ": selected pitch " << fConfig.fPitch << " gives wrong number of bins = " << nBins;
118 }
119 if (nBins > fConfig.fMaxNofBins) {
120 nBins = fConfig.fMaxNofBins;
121 }
122 fmMaterial[slice.fName] = fpMaterialFactory->GenerateMaterialMap(zRef, zMin, zMax, xyMax, nBins);
123 }
124
126 return kSUCCESS;
127}
128
129// ---------------------------------------------------------------------------------------------------------------------
130//
131InitStatus CbmGenerateMaterialMaps::ReInit() { return kSUCCESS; }
132
133// ---------------------------------------------------------------------------------------------------------------------
134//
136{
137 auto f = TFile(fsOutputFile.c_str(), "RECREATE");
138 f.cd();
139 for (const auto& [name, material] : fmMaterial) {
140 double zMin = material.GetZmin();
141 double zMax = material.GetZmax();
142 std::string title = Form("Material thickness in X_{0}, z region [%.2f,%.2f] cm (%s)", zMin, zMax, name.c_str());
144 title += "; horizontal projection";
145 }
146 else {
147 title += Form("; radial projection from z=%f cm", fTargetZ);
148 }
149 auto* h = ::kf::tools::RootUtils::ToHistogram(material, name.c_str(), title.c_str());
150 h->SetDirectory(&f);
151 }
152 f.Write();
153}
A FAIR-task to generate material maps (header)
Target property initialization and access in CBM (source)
Base abstract class for tracking detector interface to L1 (implementation of Checker)
Different ROOT utility functions for the KF-framework (header)
Steer class for executing the material budget maps generator independently from tracking.
InitStatus ReInit()
Re-initializer.
Config fConfig
Offset from target to start generating mat. maps [cm].
std::map< std::string, MaterialMap > fmMaterial
Material budget maps.
CbmGenerateMaterialMaps()
Default constructor.
static constexpr double kXYoffset
std::string fsOutputFile
Output file name.
double fTargetZ
z-coordinate of the target center
std::unique_ptr<::kf::tools::MaterialMapFactory > fpMaterialFactory
Material factory instance.
InitStatus Init()
Initializer.
void WriteMaterialMaps()
Writes material budget maps to file.
std::string fsUserConfig
User configuration file.
Data class with information on a STS local track.
static CbmTrackingDetectorInterfaceInit * Instance()
Returns a pointer to the class instance.
static Target * Instance()
Instance access.
double GetZ() const
Gets target center z-coordinate [cm].
Definition CbmKfTarget.h:34
T ReadFromFile(fs::path path)
Definition Yaml.h:51
bool fbParallelRays
Rays mode (false - radial, true - parallel to z-axis)
std::vector< MaterialSlice > fvUserSlices
Material slices defined by user.
bool fbTrackingStations
Generates material maps for the actual geometry stations.
double fPitch
Minimal bin size (cm)
int fNofRays
Number of rays per dimension in each bin.
int fMaxNofBins
Number of bins in material budged map (x and y axes)
Input parameters for the material map generation.
double fMinZ
Lower bound along z-axis [cm].
double fRefZ
Reference z-coordinate [cm].
double fMaxZ
Upper bound along z-axis [cm].
double fMaxXY
Size in the transverse plane [cm].
static TH2F * ToHistogram(const cbm::algo::kf::MaterialMap &material, const TString &name, const TString &title)
Converts a material budget map into a TH2D histogram.