CbmRoot
Loading...
Searching...
No Matches
CbmOnlineParWrite.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
5#include "CbmOnlineParWrite.h"
6
7#include "CbmMcbmUtils.h"
8#include "CbmSetup.h"
9#include "CbmSinkDummy.h"
10#include "CbmSourceDummy.h"
11#include "CbmStsAddress.h"
12#include "CbmStsParAsic.h"
13#include "CbmStsParModule.h"
14#include "CbmStsParSensor.h"
15#include "CbmStsParSensorCond.h"
16#include "CbmStsParSetSensor.h"
17#include "CbmStsSetup.h"
22#include "CbmTrdParSetAsic.h"
23#include "CbmTrdParSetDigi.h"
24
25#include <FairParAsciiFileIo.h>
26#include <FairParRootFileIo.h>
27#include <FairRootFileSink.h>
28#include <FairRunAna.h>
29#include <FairRuntimeDb.h>
30
31#include <TGeoManager.h>
32#include <TObjString.h>
33#include <TStopwatch.h>
34
35#include <iostream>
36
37using namespace cbm::algo;
38
40{
41 // Add detectors here
42 AddTrd();
43 AddTof();
44 AddSts();
45}
46
47// ===========================================================================
48// TRD setup
49// ===========================================================================
51{
52 // Copied from macro/beamtime/mcbm2022/trd_hitfinder_run.C
55
56 // ----- TRD digitisation parameters -------------------------------------
57 TString geoTagTrd;
59 throw std::runtime_error{"TRD not enabled in current geometry!"};
60 }
61
62 if (!fSetup->GetGeoTag(ECbmModuleId::kTrd, geoTagTrd)) {
63 throw std::runtime_error{"Failed to get TRD geo tag from CbmSetup!"};
64 }
65
66 TString paramFilesTrd(Form("%s/parameters/trd/trd_%s", fSrcDir.Data(), geoTagTrd.Data()));
67 std::vector<TString> paramFilesVecTrd = {"asic", "digi", "gas", "gain"};
68 for (auto parIt : paramFilesVecTrd) {
69 fParList->Add(new TObjString(Form("%s.%s.par", paramFilesTrd.Data(), parIt.Data())));
70 }
71
72 for (auto parFileVecIt : *fParList) {
73 std::cout << Form("TrdParams - %s - added to parameter file list", parFileVecIt->GetName()) << std::endl;
74 }
75
76 // ----- TRD task ---------------------------------------------------------
77 auto* trdHitfinderPar = new CbmTaskTrdHitFinderParWrite{};
78 fRun->AddTask(trdHitfinderPar);
79
80
81 // Initialize input files
82 FairParAsciiFileIo asciiInput;
83 std::string digiparfile = Form("%s/parameters/trd/trd_%s.digi.par", fSrcDir.Data(), geoTagTrd.Data());
84 std::string asicparfile = Form("%s/parameters/trd/trd_%s.asic.par", fSrcDir.Data(), geoTagTrd.Data());
85
86 // Read the .digi file and store result
87 auto* digiparset = new CbmTrdParSetDigi{};
88 if (asciiInput.open(digiparfile.data())) {
89 digiparset->init(&asciiInput);
90 }
91 asciiInput.close();
92
93 // Read the .asic file and store result
94 auto* asicparset = new CbmTrdParSetAsic{};
95 if (asciiInput.open(asicparfile.data())) {
96 asicparset->init(&asciiInput);
97 }
98 asciiInput.close();
99
100 // Unpack
101 CbmTaskTrdUnpackParWrite::Pars parFilesUnpack{.asic = asicparset, .digi = digiparset, .setup = fConfig.setupType};
102 auto* trdUnpackPar = new CbmTaskTrdUnpackParWrite{parFilesUnpack};
103 fRun->AddTask(trdUnpackPar);
104}
105
106// ===========================================================================
107// TOF setup
108// ===========================================================================
110{
111 // Copied from macro/tools/tof_hitfinder_run.C
113
114 TString geoTag;
117 TObjString* tofBdfFile = new TObjString(fSrcDir + "/parameters/tof/tof_" + geoTag + ".digibdf.par");
118 fParList->Add(tofBdfFile);
119 std::cout << "-I- TOF: Using parameter file " << tofBdfFile->GetString() << std::endl;
120 }
121
122 // ----- TOF defaults ------------------------
123 Int_t calMode = 93;
124 Int_t calSel = 1;
125 Double_t dDeadtime = 50.;
126
127 TString TofFileFolder = fSrcDir + "/parameters/mcbm/";
128 bool doCalibration = false;
129 TString cCalId = "490.100.5.0";
130 Int_t iCalSet = 30040500; // calibration settings
131 TString cFname = "";
132
133 switch (fConfig.setupType) {
134 case Setup::mCBM2022:
135 doCalibration = true;
136 cCalId = "2391.5.000";
137 iCalSet = 22002500;
138 break;
139 case Setup::mCBM2024_03:
140 doCalibration = true;
141 cCalId = "2912.1";
142 iCalSet = 012032500;
143 break;
144 case Setup::mCBM2024_05:
145 doCalibration = true;
146 cFname = Form("%s/3026_1_TofCal.hst.root", TofFileFolder.Data());
147 break;
148 default: throw std::runtime_error("TOF: Unknown setup type");
149 }
150
151 if (cFname.IsNull() && doCalibration) {
152 cFname =
153 Form("%s/%s_set%09d_%02d_%01dtofClust.hst.root", TofFileFolder.Data(), cCalId.Data(), iCalSet, calMode, calSel);
154 }
155
156 auto* tofCluster = new CbmTaskTofClusterizerParWrite("Task TOF Clusterizer", 0, 1);
157 tofCluster->SetCalParFileName(cFname);
158 tofCluster->SetCalMode(calMode);
159 tofCluster->SetTotMax(20.); // Tot upper limit for walk corection
160 tofCluster->SetTotMin(0.); //(12000.); // Tot lower limit for walk correction
161 tofCluster->SetTotMean(5.); // Tot calibration target value in ns
162 tofCluster->SetMaxTimeDist(1.0); // default cluster range in ns
163 tofCluster->SetChannelDeadtime(dDeadtime); // artificial deadtime in ns
164 tofCluster->PosYMaxScal(0.75); //in % of length
165 fRun->AddTask(tofCluster);
166}
167
168// ===========================================================================
169// STS setup
170// ===========================================================================
172{
173 // Copied from macro/beamtime/mcbm2022/mcbm_reco.C
174
175 auto* recoSts = new CbmTaskStsHitFinderParWrite{};
176 // recoSts->SetMode(ECbmRecoMode::EventByEvent);
177
178 // recoSts->SetTimeCutDigisAbs(20.0); // cluster finder: time cut in ns
179 // recoSts->SetTimeCutClustersAbs(20.0); // hit finder: time cut in ns
180
181 TString geoTag;
183 LOG(info) << "STS geo tag: " << geoTag;
184
185 // Sensor params
187 sensor6cm.SetPar(0, 6.2092); // Extension in x
188 sensor6cm.SetPar(1, 6.2); // Extension in y
189 sensor6cm.SetPar(2, 0.03); // Extension in z
190 sensor6cm.SetPar(3, 5.9692); // Active size in y
191 sensor6cm.SetPar(4, 1024.); // Number of strips front side
192 sensor6cm.SetPar(5, 1024.); // Number of strips back side
193 sensor6cm.SetPar(6, 0.0058); // Strip pitch front side
194 sensor6cm.SetPar(7, 0.0058); // Strip pitch back side
195 sensor6cm.SetPar(8, 0.0); // Stereo angle front side
196 sensor6cm.SetPar(9, 7.5); // Stereo angle back side
197
198 CbmStsParSensor sensor12cm(sensor6cm); // copy all parameters, change then only the y size
199 sensor12cm.SetPar(1, 12.4); // Extension in y
200 sensor12cm.SetPar(3, 12.1692); // Active size in y
201
202 // --- Addresses for sensors
203 // --- They are defined in each station as sensor 1, module 1, halfladderD (2), ladder 1
204 // Int_t GetAddress(UInt_t unit = 0, UInt_t ladder = 0, UInt_t halfladder = 0, UInt_t module = 0, UInt_t sensor = 0,
205 // UInt_t side = 0, UInt_t version = kCurrentVersion);
206
207 // --- Now we can define the sensor parameter set and tell recoSts to use it
208 auto sensorParSet = new CbmStsParSetSensor("CbmStsParSetSensor", "STS sensor parameters"
209 "mcbm2021");
210
211 // TODO: is it possible to read these values from a parameter file?
212 if (fConfig.setupType == Setup::mCBM2022) {
213
214 Int_t stsAddress01 = CbmStsAddress::GetAddress(0, 0, 1, 0, 0, 0); // U0 L0 M0 6 cm
215 Int_t stsAddress02 = CbmStsAddress::GetAddress(0, 0, 1, 1, 0, 0); // U0 L0 M1 6 cm
216 Int_t stsAddress03 = CbmStsAddress::GetAddress(0, 1, 1, 0, 0, 0); // U0 L1 M0 6 cm
217 Int_t stsAddress04 = CbmStsAddress::GetAddress(0, 1, 1, 1, 0, 0); // U0 L1 M1 6 cm
218 Int_t stsAddress05 = CbmStsAddress::GetAddress(1, 0, 1, 0, 0, 0); // U1 L0 M0 6 cm
219 Int_t stsAddress06 = CbmStsAddress::GetAddress(1, 0, 1, 1, 0, 0); // U1 L0 M1 12 cm
220 Int_t stsAddress07 = CbmStsAddress::GetAddress(1, 1, 1, 0, 0, 0); // U1 L1 M0 6 cm
221 Int_t stsAddress08 = CbmStsAddress::GetAddress(1, 1, 1, 1, 0, 0); // U1 L1 M1 12 cm
222 Int_t stsAddress09 = CbmStsAddress::GetAddress(1, 2, 1, 0, 0, 0); // U1 L2 M0 6 cm
223 Int_t stsAddress10 = CbmStsAddress::GetAddress(1, 2, 1, 1, 0, 0); // U1 L2 M1 6 cm
224 Int_t stsAddress11 = CbmStsAddress::GetAddress(1, 2, 1, 2, 0, 0); // U1 L2 M2 6 cm
225
226 LOG(info) << "STS address01 " << CbmStsAddress::ToString(stsAddress01);
227 LOG(info) << "STS address02 " << CbmStsAddress::ToString(stsAddress02);
228 LOG(info) << "STS address03 " << CbmStsAddress::ToString(stsAddress03);
229 LOG(info) << "STS address04 " << CbmStsAddress::ToString(stsAddress04);
230 LOG(info) << "STS address05 " << CbmStsAddress::ToString(stsAddress05);
231 LOG(info) << "STS address06 " << CbmStsAddress::ToString(stsAddress06);
232 LOG(info) << "STS address07 " << CbmStsAddress::ToString(stsAddress07);
233 LOG(info) << "STS address08 " << CbmStsAddress::ToString(stsAddress08);
234 LOG(info) << "STS address09 " << CbmStsAddress::ToString(stsAddress09);
235 LOG(info) << "STS address10 " << CbmStsAddress::ToString(stsAddress10);
236 LOG(info) << "STS address11 " << CbmStsAddress::ToString(stsAddress11);
237
238 sensorParSet->SetParSensor(stsAddress01, sensor6cm);
239 sensorParSet->SetParSensor(stsAddress02, sensor6cm);
240 sensorParSet->SetParSensor(stsAddress03, sensor6cm);
241 sensorParSet->SetParSensor(stsAddress04, sensor6cm);
242 sensorParSet->SetParSensor(stsAddress05, sensor6cm);
243 sensorParSet->SetParSensor(stsAddress06, sensor12cm);
244 sensorParSet->SetParSensor(stsAddress07, sensor6cm);
245 sensorParSet->SetParSensor(stsAddress08, sensor12cm);
246 sensorParSet->SetParSensor(stsAddress09, sensor6cm);
247 sensorParSet->SetParSensor(stsAddress10, sensor6cm);
248 sensorParSet->SetParSensor(stsAddress11, sensor6cm);
249 }
250 else if (fConfig.setupType == Setup::mCBM2024_03 || fConfig.setupType == Setup::mCBM2024_05) {
251 uint32_t addr01 = 0x10008012;
252 uint32_t addr02 = 0x10018012;
253 uint32_t addr03 = 0x10008412;
254 uint32_t addr04 = 0x10018412;
255 uint32_t addr05 = 0x10008422;
256 uint32_t addr06 = 0x10018422;
257 uint32_t addr07 = 0x10008822;
258 uint32_t addr08 = 0x10018822;
259 uint32_t addr09 = 0x10028822;
260 uint32_t addr10 = 0x10008022;
261 uint32_t addr11 = 0x10018022;
262 uint32_t addr00 = 0x10000002; // New station 0 in mCBM2024
263
264 LOG(info) << "STS address01 " << CbmStsAddress::ToString(addr01);
265 LOG(info) << "STS address02 " << CbmStsAddress::ToString(addr02);
266 LOG(info) << "STS address03 " << CbmStsAddress::ToString(addr03);
267 LOG(info) << "STS address04 " << CbmStsAddress::ToString(addr04);
268 LOG(info) << "STS address05 " << CbmStsAddress::ToString(addr05);
269 LOG(info) << "STS address06 " << CbmStsAddress::ToString(addr06);
270 LOG(info) << "STS address07 " << CbmStsAddress::ToString(addr07);
271 LOG(info) << "STS address08 " << CbmStsAddress::ToString(addr08);
272 LOG(info) << "STS address09 " << CbmStsAddress::ToString(addr09);
273 LOG(info) << "STS address10 " << CbmStsAddress::ToString(addr10);
274 LOG(info) << "STS address11 " << CbmStsAddress::ToString(addr11);
275 LOG(info) << "STS address00 " << CbmStsAddress::ToString(addr00);
276
277 sensorParSet->SetParSensor(addr01, sensor6cm);
278 sensorParSet->SetParSensor(addr02, sensor6cm);
279 sensorParSet->SetParSensor(addr03, sensor6cm);
280 sensorParSet->SetParSensor(addr04, sensor6cm);
281 sensorParSet->SetParSensor(addr05, sensor6cm);
282 sensorParSet->SetParSensor(addr06, sensor12cm);
283 sensorParSet->SetParSensor(addr07, sensor6cm);
284 sensorParSet->SetParSensor(addr08, sensor6cm);
285 sensorParSet->SetParSensor(addr09, sensor6cm);
286 sensorParSet->SetParSensor(addr10, sensor6cm);
287 sensorParSet->SetParSensor(addr11, sensor12cm);
288 sensorParSet->SetParSensor(addr00, sensor6cm);
289 }
290 else {
291 throw std::runtime_error("STS: Unknown setup type");
292 }
293
294 recoSts->UseSensorParSet(sensorParSet);
295
296 // ASIC params: #ADC channels, dyn. range, threshold, time resol., dead time,
297 // noise RMS, zero-threshold crossing rate
298 auto parAsic = new CbmStsParAsic(128, 31, 75000., 3000., 5., 800., 1000., 3.9789e-3);
299
300 // Module params: number of channels, number of channels per ASIC
301 auto parMod = new CbmStsParModule(2048, 128);
302 parMod->SetAllAsics(*parAsic);
303 recoSts->UseModulePar(parMod);
304
305 // Sensor conditions: full depletion voltage, bias voltage, temperature,
306 // coupling capacitance, inter-strip capacitance
307 auto sensorCond = new CbmStsParSensorCond(70., 140., 268., 17.5, 1.);
308 recoSts->UseSensorCond(sensorCond);
309
310 fRun->AddTask(recoSts);
311}
312
314{
315 // Copied and adjusted from macro/beamtime/mcbm2022/trd_hitfinder_run.C
316
317 static bool callOnce = true;
318 if (!callOnce) {
319 throw std::runtime_error("CbmOnlineParWrite::Run() can only be called once at the moment!");
320 }
321 callOnce = false;
322
323 fConfig = config;
324
325 // ----- Environment --------------------------------------------------
326 fSrcDir = gSystem->Getenv("VMCWORKDIR"); // top source directory
327 // ------------------------------------------------------------------------
328
329 // ----- In- and output file names ------------------------------------
330
331 // --- Load the geometry setup ----
332 TString geoSetupTag = "";
333 try {
334 uint64_t runId = -1;
335 switch (fConfig.setupType) {
336 case Setup::mCBM2022: runId = 2391; break;
337 case Setup::mCBM2024_03: runId = 2724; break;
338 case Setup::mCBM2024_05: runId = 2918; break;
339 default: throw std::runtime_error("Unknown setup type");
340 }
341 geoSetupTag = cbm::mcbm::GetSetupFromRunId(runId);
342 }
343 catch (const std::invalid_argument& e) {
344 std::cout << "Error in mapping from runID to setup name: " << e.what() << std::endl;
345 return;
346 }
347
348 LOG(info) << "Using geometry setup: " << geoSetupTag;
349
350 TString geoFile = fSrcDir + "/macro/run/data/" + geoSetupTag + ".geo.root";
352 fSetup->LoadSetup(geoSetupTag);
353
354 //----- Load Parameters --------------------------------------------------
355 fParList = new TList();
356
357 // ----- FairRunAna ---------------------------------------------------
358 fRun = new FairRunAna();
359
360 // Dummy source required for the FairRunAna as it will crash without a source
361 fRun->SetSource(new CbmSourceDummy{});
362 fRun->SetSink(new CbmSinkDummy{});
363
364
365 // =========================================================================
366 // === Alignment Correction ===
367 // =========================================================================
368 if (fConfig.doAlignment) {
369
370 TString alignmentMatrixFileName = fSrcDir + "/parameters/mcbm/AlignmentMatrices_" + geoSetupTag + ".root";
371 if (alignmentMatrixFileName.Length() == 0) {
372 throw std::runtime_error{"Alignment matrix file name is empty"};
373 }
374
375 LOG(info) << "Applying alignment for file '" << alignmentMatrixFileName << "'";
376
377 // Define the basic structure which needs to be filled with information
378 // This structure is stored in the output file and later passed to the
379 // FairRoot framework to do the (miss)alignment
380 std::map<std::string, TGeoHMatrix>* matrices{nullptr};
381
382 // read matrices from disk
383 LOG(info) << "Filename: " << alignmentMatrixFileName;
384 TFile* misalignmentMatrixRootfile = new TFile(alignmentMatrixFileName, "READ");
385 if (misalignmentMatrixRootfile->IsOpen()) {
386 gDirectory->GetObject("MisalignMatrices", matrices);
387 misalignmentMatrixRootfile->Close();
388 }
389 else {
390 throw std::runtime_error{"Could not open alignment matrix file: " + alignmentMatrixFileName};
391 }
392
393 if (matrices) {
394 fRun->AddAlignmentMatrices(*matrices);
395 }
396 else {
397 throw std::runtime_error{"Could not read alignment matrices from file: " + alignmentMatrixFileName};
398 }
399 }
400
401
402 // ----- Add detectors ------------------------------------------------
403 AddDetectors();
404
405 // ----- Parameter database --------------------------------------------
406 FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
407 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
408 parIo2->setAutoWritable(false);
409 parIo2->open(fParList, "in");
410 rtdb->setSecondInput(parIo2);
411 // ------------------------------------------------------------------------
412
413 // ----- Run initialisation -------------------------------------------
414 fRun->SetGeomFile(geoFile);
415 fRun->Init();
416
417 // No need to run the event loop, parameters are written during the initialization
418
419
420 // ----- Clean up ---------------------------------------------------------
421 gGeoManager->GetListOfVolumes()->Delete();
422 gGeoManager->GetListOfShapes()->Delete();
423 delete gGeoManager;
424
425 // Delete files created by FairRun that I don't know how disable otherwise
426 gSystem->Exec("rm all_*.par");
427}
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kTrd2d
TRD-FASP Detector (FIXME)
This file contains the declaration of the CbmOnlineParWrite class.
Dummy input source.
void Run(const Config &config)
void SetActive(ECbmModuleId moduleId, Bool_t active=kTRUE)
Definition CbmSetup.cxx:185
Bool_t IsActive(ECbmModuleId moduleId)
Definition CbmSetup.cxx:169
Bool_t GetGeoTag(ECbmModuleId moduleId, TString &tag)
Definition CbmSetup.cxx:127
static CbmSetup * Instance()
Definition CbmSetup.cxx:160
void LoadSetup(const char *setupName)
Definition CbmSetup.h:64
A dummy sink class, which is to be passed to a FairRunAna, if no output is required.
Dummy input FAIR source. Doesn't create any branches or data.
Parameters of the STS readout ASIC.
Parameters for one STS module.
Parameters for operating conditions of a STS sensor.
Constructional parameters of a STS sensor.
void SetPar(UInt_t index, Float_t value)
Set a parameter.
Parameters container for CbmStsParSensor.
Describe TRD module ASIC settings (electronic gain, delays, etc)
int32_t GetAddress(uint32_t unit=0, uint32_t ladder=0, uint32_t halfladder=0, uint32_t module=0, uint32_t sensor=0, uint32_t side=0, uint32_t version=kCurrentVersion)
Construct address.
std::string ToString(int32_t address)
String output.
std::string GetSetupFromRunId(uint64_t ulRunId)