CbmRoot
Loading...
Searching...
No Matches
CbmTaskStsHitFinderParWrite.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer] */
4
6
7#include "CbmAddress.h"
8#include "CbmStsModule.h"
10#include "CbmStsParSetSensor.h"
12#include "CbmStsParSim.h"
13#include "CbmStsPhysics.h"
14#include "CbmStsRecoModule.h"
15#include "CbmStsSetup.h"
16#include "sts/HitfinderPars.h"
17#include "yaml/Yaml.h"
18
19#include <FairField.h>
20#include <FairRootManager.h>
21#include <FairRun.h>
22#include <FairRuntimeDb.h>
23
24#include <TGeoBBox.h>
25#include <TGeoPhysicalNode.h>
26
27#include <iomanip>
28
29// ----- Constructor ---------------------------------------------------
30CbmTaskStsHitFinderParWrite::CbmTaskStsHitFinderParWrite() : FairTask("CbmTaskStsHitFinderParWrite", 1) {}
31// -------------------------------------------------------------------------
32
33
34// ----- Destructor ----------------------------------------------------
36// -------------------------------------------------------------------------
37
38
39// ----- Initialise the cluster finding modules ------------------------
41{
42 assert(fSetup);
43
44 std::vector<cbm::algo::sts::HitfinderPars::Module> gpuModules; // for gpu reco
45
46 LOG(info) << GetName() << ": Creating modules";
47 LOG(info) << fParSetSensor->ToString();
48
49 for (Int_t iModule = 0; iModule < fSetup->GetNofModules(); iModule++) {
50
51 // --- Setup module and sensor
52 CbmStsModule* setupModule = fSetup->GetModule(iModule);
53 assert(setupModule);
54 Int_t moduleAddress = Int_t(setupModule->GetAddress());
55 assert(setupModule->GetNofDaughters() == 1);
56 CbmStsElement* setupSensor = setupModule->GetDaughter(0);
57 assert(setupSensor);
58 Int_t sensorAddress = Int_t(setupSensor->GetAddress());
59
60 // --- Module parameters
61 const CbmStsParModule& modPar = fParSetModule->GetParModule(moduleAddress);
62 const CbmStsParSensor& sensPar = fParSetSensor->GetParSensor(sensorAddress);
63 const CbmStsParSensorCond& sensCond = fParSetCond->GetParSensor(sensorAddress);
64
65 // --- Calculate and set average Lorentz shift
66 // --- This will be used in hit finding for correcting the position.
67 Double_t lorentzF = 0.;
68 Double_t lorentzB = 0.;
69 if (fParSim->LorentzShift()) {
70
71 TGeoBBox* shape = dynamic_cast<TGeoBBox*>(setupSensor->GetPnode()->GetShape());
72 assert(shape);
73 Double_t dZ = 2. * shape->GetDZ(); // Sensor thickness
74
75 // Get the magnetic field in the sensor centre
76 Double_t by = 0.;
77 if (FairRun::Instance()->GetField()) {
78 Double_t local[3] = {0., 0., 0.}; // sensor centre in local C.S.
79 Double_t global[3]; // sensor centre in global C.S.
80 setupSensor->GetPnode()->GetMatrix()->LocalToMaster(local, global);
81 Double_t field[3] = {0., 0., 0.}; // magnetic field components
82 FairRun::Instance()->GetField()->Field(global, field);
83 by = field[1] / 10.; // kG->T
84 } //? field present
85
86 // Calculate average Lorentz shift on sensor sides.
87 // This is needed in hit finding for correcting the cluster position.
88 auto lorentzShift = LorentzShift(sensCond, dZ, by);
89 lorentzF = lorentzShift.first;
90 lorentzB = lorentzShift.second;
91 } //? Lorentz-shift correction
92
93 // --- Create reco module
94 CbmStsRecoModule recoModule{setupModule, modPar, sensPar, lorentzF, lorentzB};
95
96 // Get Transformation Matrix
98 TGeoHMatrix* matrix = recoModule.getMatrix();
99 std::copy_n(matrix->GetRotationMatrix(), 9, localToGlobal.rotation.begin());
100 std::copy_n(matrix->GetTranslation(), 3, localToGlobal.translation.begin());
101
102 // Collect GPU parameters
104 .address = moduleAddress,
105 .dY = sensPar.GetPar(3),
106 .pitch = sensPar.GetPar(6),
107 .stereoF = sensPar.GetPar(8),
108 .stereoB = sensPar.GetPar(9),
109 .lorentzF = float(lorentzF),
110 .lorentzB = float(lorentzB),
111 .localToGlobal = localToGlobal,
112 };
113 gpuModules.emplace_back(gpuModulePars);
114 }
115
116 const CbmStsParModule& firstModulePars = fParSetModule->GetParModule(gpuModules[0].address);
117
118 CbmStsParAsic asic = firstModulePars.GetParAsic(0);
120 .nAdc = asic.GetNofAdc(),
121 .dynamicRange = float(asic.GetDynRange()),
122 .threshold = float(asic.GetThreshold()),
123 .timeResolution = float(asic.GetTimeResol()),
124 .deadTime = float(asic.GetDeadTime()),
125 .noise = float(asic.GetNoise()),
126 .zeroNoiseRate = float(asic.GetZeroNoiseRate()),
127 };
128
129 int nChannels = firstModulePars.GetNofChannels();
130
131 auto [landauValues, landauStepSize] = CbmStsPhysics::Instance()->GetLandauWidthTable();
132 std::vector<float> landauValuesF;
133 std::copy(landauValues.begin(), landauValues.end(), std::back_inserter(landauValuesF));
135 .asic = algoAsic,
136 .nChannels = nChannels,
137 .modules = gpuModules,
138 .landauTable =
139 {
140 .values = landauValuesF,
141 .stepSize = float(landauStepSize),
142 },
143 };
144
145 // Write to file
146 std::string filename = "StsHitfinder.yaml";
147 std::ofstream{filename} << cbm::algo::yaml::Dump{}(pars, 4);
148
149 return pars.modules.size();
150}
151// -------------------------------------------------------------------------
152
153
154// ----- Initialisation ------------------------------------------------
156{
157
158 // --- Something for the screen
159 LOG(info) << "==========================================================";
160 LOG(info) << GetName() << ": Initialising ";
161
162 // --- Check IO-Manager
163 FairRootManager* ioman = FairRootManager::Instance();
164 assert(ioman);
165
166 // --- Simulation settings
167 assert(fParSim); // Set from SetParContainers()
168 LOG(info) << GetName() << ": Sim settings " << fParSim->ToString();
169
170 // --- Parameters
171 InitParams();
172
173 // --- Initialise STS setup
175 fSetup->Init(nullptr);
176 //fSetup->SetSensorParameters(fParSetSensor);
177
178 // --- Create reconstruction modules
179 UInt_t nModules = CreateModules();
180 LOG(info) << GetName() << ": Created " << nModules << " modules";
181
182 LOG(info) << GetName() << ": Initialisation successful.";
183 LOG(info) << "==========================================================";
184
185 return kSUCCESS;
186}
187// -------------------------------------------------------------------------
188
189
190// ----- Parameter initialisation --------------------------------------
192{
193
194 // --- Module parameters
195 TString sourceModu = "database";
196 assert(fParSetModule);
197 if (fUserParSetModule) {
200 fParSetModule->setChanged();
201 fParSetModule->setInputVersion(-2, 1);
202 sourceModu = "user-defined";
203 }
204 if (fUserParModule) { // global settings override
207 fParSetModule->setChanged();
208 fParSetModule->setInputVersion(-2, 1);
209 sourceModu = "user-defined, global";
210 }
211 LOG(info) << GetName() << ": Module parameters (" << sourceModu << ") " << fParSetModule->ToString();
212
213 // --- Sensor parameters
214 TString sourceSens = "database";
215 assert(fParSetSensor);
216 if (fUserParSetSensor) {
219 fParSetSensor->setChanged();
220 fParSetSensor->setInputVersion(-2, 1);
221 sourceSens = "user-defined";
222 }
223 if (fUserParSensor) { // global settings override
226 fParSetSensor->setChanged();
227 fParSetSensor->setInputVersion(-2, 1);
228 sourceSens = "user-defined, global";
229 }
230 LOG(info) << GetName() << ": Sensor parameters (" << sourceSens << ")" << fParSetSensor->ToString();
231
232 // --- Sensor conditions
233 TString sourceCond = "database";
234 assert(fParSetCond);
235 if (fUserParSetCond) {
238 fParSetCond->setChanged();
239 fParSetCond->setInputVersion(-2, 1);
240 sourceSens = "user-defined";
241 }
242 if (fUserParCond) { // global settings override
245 fParSetCond->setChanged();
246 fParSetCond->setInputVersion(-2, 1);
247 sourceCond = "user-defined, global";
248 }
249 LOG(info) << GetName() << ": Sensor conditions (" << sourceCond << ")" << fParSetCond->ToString();
250}
251// -------------------------------------------------------------------------
252
253// ----- Calculate the mean Lorentz shift in a sensor ------------------
254std::pair<Double_t, Double_t> CbmTaskStsHitFinderParWrite::LorentzShift(const CbmStsParSensorCond& conditions,
255 Double_t dZ, Double_t bY)
256{
257
258 Double_t vBias = conditions.GetVbias(); // Bias voltage
259 Double_t vFd = conditions.GetVfd(); // Full-depletion voltage
260 Double_t eField = (vBias + vFd) / dZ; // Electric field
261
262 // --- Integrate in 1000 steps over the sensor thickness
263 Int_t nSteps = 1000;
264 Double_t deltaZ = dZ / nSteps;
265 Double_t dxMeanE = 0.;
266 Double_t dxMeanH = 0.;
267 for (Int_t j = 0; j <= nSteps; j++) {
268 eField -= 2 * vFd / dZ * deltaZ / dZ; // Electric field [V/cm]
269 Double_t muHallE = conditions.GetHallMobility(eField, 0);
270 Double_t muHallH = conditions.GetHallMobility(eField, 1);
271 dxMeanE += muHallE * (dZ - Double_t(j) * deltaZ);
272 dxMeanH += muHallH * Double_t(j) * deltaZ;
273 }
274 dxMeanE /= Double_t(nSteps);
275 dxMeanH /= Double_t(nSteps);
276 Double_t shiftF = dxMeanE * bY * 1.e-4;
277 Double_t shiftB = dxMeanH * bY * 1.e-4;
278 // The factor 1.e-4 is because bZ is in T = Vs/m**2, but muHall is in
279 // cm**2/(Vs) and z in cm.
280
281 return {shiftF, shiftB};
282}
283// -------------------------------------------------------------------------
284
285// ----- Connect parameter container -----------------------------------
287{
288 FairRuntimeDb* db = FairRun::Instance()->GetRuntimeDb();
289 fParSim = dynamic_cast<CbmStsParSim*>(db->getContainer("CbmStsParSim"));
290 fParSetModule = dynamic_cast<CbmStsParSetModule*>(db->getContainer("CbmStsParSetModule"));
291 fParSetSensor = dynamic_cast<CbmStsParSetSensor*>(db->getContainer("CbmStsParSetSensor"));
292 fParSetCond = dynamic_cast<CbmStsParSetSensorCond*>(db->getContainer("CbmStsParSetSensorCond"));
293}
294// -------------------------------------------------------------------------
Class representing an element of the STS setup.
Int_t GetAddress() const
TGeoPhysicalNode * GetPnode() const
Int_t GetNofDaughters() const
CbmStsElement * GetDaughter(Int_t index) const
Class representing an instance of a readout unit in the CBM-STS.
Parameters of the STS readout ASIC.
double GetDynRange() const
Dynamic range of ADC.
uint16_t GetNofAdc() const
Number of ADC channels.
double GetZeroNoiseRate() const
Zero-crossing noise rate.
double GetNoise() const
Electronic noise RMS.
double GetThreshold() const
ADC Threshold.
double GetTimeResol() const
Time resolution.
double GetDeadTime() const
Single-channel dead time.
Parameters for one STS module.
uint32_t GetNofChannels() const
Number of channels.
const CbmStsParAsic & GetParAsic(uint32_t channel) const
ASIC parameters for a given channel.
Parameters for operating conditions of a STS sensor.
Double_t GetVbias() const
Bias voltage.
Double_t GetHallMobility(Double_t eField, Int_t chargeType) const
Hall mobility.
Constructional parameters of a STS sensor.
Float_t GetPar(UInt_t index) const
Get a parameter.
Parameters container for CbmStsParModule.
void SetGlobalPar(const CbmStsParModule &params)
Set global parameters (for all modules)
const CbmStsParModule & GetParModule(UInt_t address)
Get condition parameters of a sensor.
virtual void clear()
Reset all parameters.
std::string ToString() const
Info to string.
Parameters container for CbmStsParSensorCond.
std::string ToString()
Info to string.
void SetGlobalPar(Double_t vDep, Double_t vBias, Double_t temperature, Double_t cCoupling, Double_t cInterstrip)
Set global conditions (for all sensors)
virtual void clear()
Reset all parameters.
const CbmStsParSensorCond & GetParSensor(UInt_t address)
Get condition parameters of a sensor.
Parameters container for CbmStsParSensor.
std::string ToString() const
Info to string.
void SetGlobalPar(const CbmStsParSensor &params)
Set global parameters (for all modules)
const CbmStsParSensor & GetParSensor(UInt_t address)
Get condition parameters of a sensor.
virtual void clear()
Reset all parameters.
Settings for STS simulation (digitizer)
Bool_t LorentzShift() const
Check whether Lorentz shift is applied.
std::string ToString() const
String output.
std::pair< std::vector< double >, double > GetLandauWidthTable() const
Raw values of landau width interpolation table.
static CbmStsPhysics * Instance()
Accessor to singleton instance.
Class for reconstruction in one STS module.
Bool_t Init(const char *geometryFile=nullptr)
Initialise the setup.
CbmStsModule * GetModule(Int_t index) const
Get a module from the module array.
Definition CbmStsSetup.h:72
static CbmStsSetup * Instance()
Int_t GetNofModules() const
Definition CbmStsSetup.h:86
CbmStsParSetSensorCond * fParSetCond
Sensor conditions.
virtual void SetParContainers()
Define the needed parameter containers.
void InitParams()
Initialise parameters.
std::pair< Double_t, Double_t > LorentzShift(const CbmStsParSensorCond &conditions, Double_t dZ, Double_t bY)
Average Lorentz Shift in a sensor.
UInt_t CreateModules()
Instantiate reconstruction modules @value Number of modules created.
CbmStsParSetModule * fParSetModule
Module parameters.
CbmStsParSim * fParSim
Instance of STS setup.
virtual ~CbmTaskStsHitFinderParWrite()
Destructor
CbmStsParSetSensor * fParSetSensor
Sensor parameters.
virtual InitStatus Init()
Initialisation.