CbmRoot
Loading...
Searching...
No Matches
CbmOnlineParWrite.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024-2025 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Felix Weiglhofer [committer], Sergei Zharko */
4
5#include "CbmOnlineParWrite.h"
6
8#include "CbmMcbmUtils.h"
9#include "CbmMuchGeoScheme.h"
10#include "CbmRecoSetupManager.h"
12#include "CbmSetup.h"
13#include "CbmSinkDummy.h"
14#include "CbmSourceDummy.h"
15#include "CbmStsAddress.h"
16#include "CbmStsParAsic.h"
17#include "CbmStsParModule.h"
18#include "CbmStsParSensor.h"
19#include "CbmStsParSensorCond.h"
20#include "CbmStsParSetSensor.h"
21#include "CbmStsSetup.h"
26#include "CbmTrdParSetAsic.h"
27#include "CbmTrdParSetDigi.h"
28
29#include <FairParAsciiFileIo.h>
30#include <FairParRootFileIo.h>
31#include <FairRootFileSink.h>
32#include <FairRunAna.h>
33#include <FairRuntimeDb.h>
34
35#include <TGeoManager.h>
36#include <TObjString.h>
37#include <TStopwatch.h>
38
39#include <boost/filesystem.hpp>
40
41#include <array>
42#include <fstream>
43#include <iostream>
44#include <sstream>
45
46using namespace cbm::algo;
47
48namespace fs = boost::filesystem;
49
50// ---------------------------------------------------------------------------------------------------------------------
51//
53{
54 // Add detectors here
55 AddTrd();
56 AddTof(); // NOTE: BMON as well
57 AddSts();
58}
59
60// ---------------------------------------------------------------------------------------------------------------------
61//
63{
64 // Copied from macro/beamtime/mcbm2022/trd_hitfinder_run.C
65 fSetup->SetActive(ECbmModuleId::kTrd, kTRUE);
66 fSetup->SetActive(ECbmModuleId::kTrd2d, kTRUE);
67
68 // ----- TRD digitisation parameters -------------------------------------
69 TString geoTagTrd;
70 if (!fSetup->IsActive(ECbmModuleId::kTrd)) {
71 throw std::runtime_error{"TRD not enabled in current geometry!"};
72 }
73
74 if (!fSetup->GetGeoTag(ECbmModuleId::kTrd, geoTagTrd)) {
75 throw std::runtime_error{"Failed to get TRD geo tag from CbmSetup!"};
76 }
77
78 TString paramFilesTrd(Form("%s/parameters/trd/trd_%s", fSrcDir.Data(), geoTagTrd.Data()));
79 std::vector<TString> paramFilesVecTrd = {"asic", "digi", "gas", "gain"};
80 for (auto parIt : paramFilesVecTrd) {
81 fParList->Add(new TObjString(Form("%s.%s.par", paramFilesTrd.Data(), parIt.Data())));
82 }
83
84 for (auto parFileVecIt : *fParList) {
85 std::cout << Form("TrdParams - %s - added to parameter file list", parFileVecIt->GetName()) << std::endl;
86 }
87
88 // ----- TRD task ---------------------------------------------------------
89 auto* trdHitfinderPar = new CbmTaskTrdHitFinderParWrite{};
90 trdHitfinderPar->SetRecoParOutputDir(fOutDirReco.string());
91 fRun->AddTask(trdHitfinderPar);
92
93 fParFiles.timesliceReco->trd = std::make_optional(RecoParFiles::Trd{
94 .hitfinder = "TrdHitfinderPar.yaml",
95 });
96
97 fParFiles.timesliceReco->trd2d = std::make_optional(RecoParFiles::Trd2d{
98 .hitfinder = "TrdHitfinder2DPar.yaml",
99 });
100
101 // Initialize input files
102 // FairParAsciiFileIo asciiInput;
103 // std::string digiparfile = Form("%s/parameters/trd/trd_%s.digi.par", fSrcDir.Data(), geoTagTrd.Data());
104 // std::string asicparfile = Form("%s/parameters/trd/trd_%s.asic.par", fSrcDir.Data(), geoTagTrd.Data());
105
106 // // Read the .digi file and store result
107 // auto* digiparset = new CbmTrdParSetDigi{};
108 // if (asciiInput.open(digiparfile.data())) {
109 // digiparset->init(&asciiInput);
110 // }
111 // asciiInput.close();
112
113 // // Read the .asic file and store result
114 // auto* asicparset = new CbmTrdParSetAsic{};
115 // if (asciiInput.open(asicparfile.data())) {
116 // asicparset->init(&asciiInput);
117 // }
118 // asciiInput.close();
119
120 // // Unpack
121 // CbmTaskTrdUnpackParWrite::Pars parFilesUnpack{.asic = asicparset, .digi = digiparset, .runId = fConfig.runId};
122 // auto* trdUnpackPar = new CbmTaskTrdUnpackParWrite{parFilesUnpack};
123 // fRun->AddTask(trdUnpackPar);
124}
125
126// ---------------------------------------------------------------------------------------------------------------------
127//
129{
130 // Copied from macro/tools/tof_hitfinder_run.C
131 fSetup->SetActive(ECbmModuleId::kTof, kTRUE);
132
133 TString geoTag;
134 if (fSetup->IsActive(ECbmModuleId::kTof)) {
135 fSetup->GetGeoTag(ECbmModuleId::kTof, geoTag);
136 TObjString* tofBdfFile = new TObjString(fSrcDir + "/parameters/tof/tof_" + geoTag + ".digibdf.par");
137 fParList->Add(tofBdfFile);
138 std::cout << "-I- TOF: Using parameter file " << tofBdfFile->GetString() << std::endl;
139 }
140
141 // ----- TOF defaults ------------------------
142 Int_t calMode = 93;
143 Int_t calSel = 1;
144 Double_t dDeadtime = 50.;
145
146 TString TofFileFolder = fSrcDir + "/parameters/mcbm/";
147 bool doCalibration = true;
148 TString cCalId = "490.100.5.0";
149 Int_t iCalSet = 30040500; // calibration settings
150 TString cFname = "";
151
152 // Select calibration setting (NOTE: legacy support)
153 if (fConfig.runId >= 2350 && fConfig.runId < 2724) { // mCBM2022
154 iCalSet = 22002500;
155 }
156 else if (fConfig.runId >= 2724 && fConfig.runId < 2918) { // mCBM2024_03
157 iCalSet = 012032500;
158 }
159
161 cFname = Form("%s/%s1_TofCal.hst.root", TofFileFolder.Data(), tofCalTag.c_str());
162
163 if (cFname.IsNull() && doCalibration) {
164 cFname =
165 Form("%s/%s_set%09d_%02d_%01dtofClust.hst.root", TofFileFolder.Data(), cCalId.Data(), iCalSet, calMode, calSel);
166 }
167
168 auto* tofCluster = new CbmTaskTofClusterizerParWrite("Task TOF Clusterizer", 0, 1);
169 tofCluster->SetCalParFileName(cFname);
170 tofCluster->SetCalMode(calMode);
171 tofCluster->SetTotMax(20.); // Tot upper limit for walk corection
172 tofCluster->SetTotMin(0.); //(12000.); // Tot lower limit for walk correction
173 tofCluster->SetTotMean(5.); // Tot calibration target value in ns
174 tofCluster->SetMaxTimeDist(1.0); // default cluster range in ns
175 tofCluster->SetChannelDeadtime(dDeadtime); // artificial deadtime in ns
176 tofCluster->PosYMaxScal(0.75); //in % of length
177 tofCluster->SetRunId(fConfig.runId);
178 tofCluster->SetRecoParOutputDir(fOutDirReco.string());
179 fRun->AddTask(tofCluster);
180
181 fParFiles.timesliceReco->tof = std::make_optional(RecoParFiles::Tof{
182 .calibrate = "TofCalibratePar.yaml",
183 .hitfinder = "TofHitfinderPar.yaml",
184 });
185
186 fParFiles.timesliceReco->bmon = std::make_optional(RecoParFiles::Bmon{
187 .calibrate = "BmonCalibratePar.yaml",
188 .hitfinder = "BmonHitfinderPar.yaml",
189 });
190}
191
192// ---------------------------------------------------------------------------------------------------------------------
193//
195{
196 // Copied from macro/beamtime/mcbm2022/mcbm_reco.C
197
198 auto* recoSts = new CbmTaskStsHitFinderParWrite{};
199 // recoSts->SetMode(ECbmRecoMode::EventByEvent);
200
201 // recoSts->SetTimeCutDigisAbs(20.0); // cluster finder: time cut in ns
202 // recoSts->SetTimeCutClustersAbs(20.0); // hit finder: time cut in ns
203
204 TString geoTag;
205 fSetup->GetGeoTag(ECbmModuleId::kTof, geoTag);
206 LOG(info) << "STS geo tag: " << geoTag;
207
208 // Sensor params
210 sensor6cm.SetPar(0, 6.2092); // Extension in x
211 sensor6cm.SetPar(1, 6.2); // Extension in y
212 sensor6cm.SetPar(2, 0.03); // Extension in z
213 sensor6cm.SetPar(3, 5.9692); // Active size in y
214 sensor6cm.SetPar(4, 1024.); // Number of strips front side
215 sensor6cm.SetPar(5, 1024.); // Number of strips back side
216 sensor6cm.SetPar(6, 0.0058); // Strip pitch front side
217 sensor6cm.SetPar(7, 0.0058); // Strip pitch back side
218 sensor6cm.SetPar(8, 0.0); // Stereo angle front side
219 sensor6cm.SetPar(9, 7.5); // Stereo angle back side
220
221 CbmStsParSensor sensor12cm(sensor6cm); // copy all parameters, change then only the y size
222 sensor12cm.SetPar(1, 12.4); // Extension in y
223 sensor12cm.SetPar(3, 12.1692); // Active size in y
224
225 // --- Addresses for sensors
226 // --- They are defined in each station as sensor 1, module 1, halfladderD (2), ladder 1
227 // Int_t GetAddress(UInt_t unit = 0, UInt_t ladder = 0, UInt_t halfladder = 0, UInt_t module = 0, UInt_t sensor = 0,
228 // UInt_t side = 0, UInt_t version = kCurrentVersion);
229
230 // --- Now we can define the sensor parameter set and tell recoSts to use it
231 auto sensorParSet = new CbmStsParSetSensor("CbmStsParSetSensor", "STS sensor parameters"
232 "mcbm2021");
233
234 // TODO: is it possible to read these values from a parameter file?
235 if (fConfig.runId < 2918) {
236
237 Int_t stsAddress01 = CbmStsAddress::GetAddress(0, 0, 1, 0, 0, 0); // U0 L0 M0 6 cm
238 Int_t stsAddress02 = CbmStsAddress::GetAddress(0, 0, 1, 1, 0, 0); // U0 L0 M1 6 cm
239 Int_t stsAddress03 = CbmStsAddress::GetAddress(0, 1, 1, 0, 0, 0); // U0 L1 M0 6 cm
240 Int_t stsAddress04 = CbmStsAddress::GetAddress(0, 1, 1, 1, 0, 0); // U0 L1 M1 6 cm
241 Int_t stsAddress05 = CbmStsAddress::GetAddress(1, 0, 1, 0, 0, 0); // U1 L0 M0 6 cm
242 Int_t stsAddress06 = CbmStsAddress::GetAddress(1, 0, 1, 1, 0, 0); // U1 L0 M1 12 cm
243 Int_t stsAddress07 = CbmStsAddress::GetAddress(1, 1, 1, 0, 0, 0); // U1 L1 M0 6 cm
244 Int_t stsAddress08 = CbmStsAddress::GetAddress(1, 1, 1, 1, 0, 0); // U1 L1 M1 12 cm
245 Int_t stsAddress09 = CbmStsAddress::GetAddress(1, 2, 1, 0, 0, 0); // U1 L2 M0 6 cm
246 Int_t stsAddress10 = CbmStsAddress::GetAddress(1, 2, 1, 1, 0, 0); // U1 L2 M1 6 cm
247 Int_t stsAddress11 = CbmStsAddress::GetAddress(1, 2, 1, 2, 0, 0); // U1 L2 M2 6 cm
248
249 LOG(info) << "STS address01 " << CbmStsAddress::ToString(stsAddress01);
250 LOG(info) << "STS address02 " << CbmStsAddress::ToString(stsAddress02);
251 LOG(info) << "STS address03 " << CbmStsAddress::ToString(stsAddress03);
252 LOG(info) << "STS address04 " << CbmStsAddress::ToString(stsAddress04);
253 LOG(info) << "STS address05 " << CbmStsAddress::ToString(stsAddress05);
254 LOG(info) << "STS address06 " << CbmStsAddress::ToString(stsAddress06);
255 LOG(info) << "STS address07 " << CbmStsAddress::ToString(stsAddress07);
256 LOG(info) << "STS address08 " << CbmStsAddress::ToString(stsAddress08);
257 LOG(info) << "STS address09 " << CbmStsAddress::ToString(stsAddress09);
258 LOG(info) << "STS address10 " << CbmStsAddress::ToString(stsAddress10);
259 LOG(info) << "STS address11 " << CbmStsAddress::ToString(stsAddress11);
260
261 sensorParSet->SetParSensor(stsAddress01, sensor6cm);
262 sensorParSet->SetParSensor(stsAddress02, sensor6cm);
263 sensorParSet->SetParSensor(stsAddress03, sensor6cm);
264 sensorParSet->SetParSensor(stsAddress04, sensor6cm);
265 sensorParSet->SetParSensor(stsAddress05, sensor6cm);
266 sensorParSet->SetParSensor(stsAddress06, sensor12cm);
267 sensorParSet->SetParSensor(stsAddress07, sensor6cm);
268 sensorParSet->SetParSensor(stsAddress08, sensor12cm);
269 sensorParSet->SetParSensor(stsAddress09, sensor6cm);
270 sensorParSet->SetParSensor(stsAddress10, sensor6cm);
271 sensorParSet->SetParSensor(stsAddress11, sensor6cm);
272 }
273 else {
274 uint32_t addr01 = 0x10008012;
275 uint32_t addr02 = 0x10018012;
276 uint32_t addr03 = 0x10008412;
277 uint32_t addr04 = 0x10018412;
278 uint32_t addr05 = 0x10008422;
279 uint32_t addr06 = 0x10018422;
280 uint32_t addr07 = 0x10008822;
281 uint32_t addr08 = 0x10018822;
282 uint32_t addr09 = 0x10028822;
283 uint32_t addr10 = 0x10008022;
284 uint32_t addr11 = 0x10018022;
285 uint32_t addr00 = 0x10000002; // New station 0 in mCBM2024
286
287 LOG(info) << "STS address01 " << CbmStsAddress::ToString(addr01);
288 LOG(info) << "STS address02 " << CbmStsAddress::ToString(addr02);
289 LOG(info) << "STS address03 " << CbmStsAddress::ToString(addr03);
290 LOG(info) << "STS address04 " << CbmStsAddress::ToString(addr04);
291 LOG(info) << "STS address05 " << CbmStsAddress::ToString(addr05);
292 LOG(info) << "STS address06 " << CbmStsAddress::ToString(addr06);
293 LOG(info) << "STS address07 " << CbmStsAddress::ToString(addr07);
294 LOG(info) << "STS address08 " << CbmStsAddress::ToString(addr08);
295 LOG(info) << "STS address09 " << CbmStsAddress::ToString(addr09);
296 LOG(info) << "STS address10 " << CbmStsAddress::ToString(addr10);
297 LOG(info) << "STS address11 " << CbmStsAddress::ToString(addr11);
298 LOG(info) << "STS address00 " << CbmStsAddress::ToString(addr00);
299
300 sensorParSet->SetParSensor(addr01, sensor6cm);
301 sensorParSet->SetParSensor(addr02, sensor6cm);
302 sensorParSet->SetParSensor(addr03, sensor6cm);
303 sensorParSet->SetParSensor(addr04, sensor6cm);
304 sensorParSet->SetParSensor(addr05, sensor6cm);
305 sensorParSet->SetParSensor(addr06, sensor12cm);
306 sensorParSet->SetParSensor(addr07, sensor6cm);
307 sensorParSet->SetParSensor(addr08, sensor6cm);
308 sensorParSet->SetParSensor(addr09, sensor6cm);
309 sensorParSet->SetParSensor(addr10, sensor6cm);
310 sensorParSet->SetParSensor(addr11, sensor12cm);
311 sensorParSet->SetParSensor(addr00, sensor6cm);
312 }
313 //else {
314 // throw std::runtime_error("STS: Unknown setup type");
315 //}
316
317 recoSts->UseSensorParSet(sensorParSet);
318
319 // ASIC params: #ADC channels, dyn. range, threshold, time resol., dead time,
320 // noise RMS, zero-threshold crossing rate
321 auto parAsic = new CbmStsParAsic(128, 31, 75000., 3000., 5., 800., 1000., 3.9789e-3);
322
323 // Module params: number of channels, number of channels per ASIC
324 auto parMod = new CbmStsParModule(2048, 128);
325 parMod->SetAllAsics(*parAsic);
326 recoSts->UseModulePar(parMod);
327
328 // Sensor conditions: full depletion voltage, bias voltage, temperature,
329 // coupling capacitance, inter-strip capacitance
330 auto sensorCond = new CbmStsParSensorCond(70., 140., 268., 17.5, 1.);
331 recoSts->UseSensorCond(sensorCond);
332 recoSts->SetRecoParOutputDir(fOutDirReco.string());
333
334 fRun->AddTask(recoSts);
335
336 fParFiles.timesliceReco->sts = std::make_optional(RecoParFiles::Sts{
337 .hitfinder = "StsHitfinder.yaml",
338 });
339}
340
341// ---------------------------------------------------------------------------------------------------------------------
342//
344{
348
349 // ----- MuCh digi parameters initialization --------------------------------------
350 if (CbmSetup::Instance()->IsActive(ECbmModuleId::kMuch)) {
351 // Parameter file name
352 TString geoTag;
354 Int_t muchFlag = (geoTag.Contains("mcbm") ? 1 : 0);
355 TString parFile = gSystem->Getenv("VMCWORKDIR");
356 parFile += "/parameters/much/much_" + geoTag(0, 4) + "_digi_sector.root";
357
358 // Initialization of the geometry scheme
359 auto muchGeoScheme = CbmMuchGeoScheme::Instance();
360 if (!muchGeoScheme->IsInitialized()) {
361 muchGeoScheme->Init(parFile, muchFlag);
362 }
363 }
364 // --------------------------------------------------------------------------------
365
366 std::string caParFilename = Form("%s.ca.par", fGeoSetupTag.Data());
367 fs::path mainCfgPath = fs::absolute(fs::weakly_canonical(fOutDirReco)) / "MainConfig.yaml";
368 fs::path caParPath = fs::absolute(fs::weakly_canonical(fOutDirReco)) / caParFilename;
369 if (!fs::exists(mainCfgPath)) {
370 throw std::runtime_error("Could not locate MainConfig.yaml");
371 }
372
373 // Tracking parameters handler
374 auto& pCaParHandler = cbm::ca::ParametersHandler::Instance();
375 pCaParHandler.SetIgnoreHitPresence(true);
376 pCaParHandler.SetMainConfig(mainCfgPath.string());
377 pCaParHandler.StoreParameters(caParPath.string());
378 pCaParHandler.SetFieldMode(cbm::algo::kf::EFieldMode::Interpolated);
379 fRun->AddTask(&pCaParHandler);
380
381 // Update the config
382 fParFiles.timesliceReco->tracking = std::make_optional(RecoParFiles::Tracking{.capar = caParFilename});
383}
384
385// ---------------------------------------------------------------------------------------------------------------------
386//
388{
389
390 std::string srcDirName = TString(gSystem->Getenv("VMCWORKDIR")).Data();
391 if (srcDirName.empty()) {
392 LOG(fatal) << "Cannot copy parameters: the VMCWORKDIR environmental variable is not specified";
393 }
394
395 const auto& cbmRunDb = cbm::RunDatabaseContainer::Instance();
396 fs::path srcDir = srcDirName + "/" + cbmRunDb.GetRecoParDir();
397 if (!fs::exists(srcDir)) {
398 LOG(fatal) << "Source directory " << srcDir.string()
399 << " for the parameter files does not exist (runId=" << fConfig.runId << "). "
400 << "Maybe, the run ID was not defined in the CbmRunDatabase.yaml";
401 }
402
403 fs::path dstDir = fs::absolute(fs::weakly_canonical(fOutDirReco));
404 if (!fs::exists(dstDir)) {
405 fs::create_directories(dstDir);
406 }
407 LOG(info) << "Copying parameters from " << srcDir.string() << " to " << dstDir.string();
408 for (fs::directory_iterator it(srcDir); it != fs::directory_iterator{}; ++it) {
409 fs::path srcFile = it->path();
410 fs::path dstFile = fs::absolute(fs::weakly_canonical(dstDir / srcFile.filename()));
411 if (fs::exists(dstFile)) {
412 fs::remove(dstFile);
413 }
414 fs::copy_file(srcFile, dstFile);
415 LOG(info) << " - copying " << srcFile.string() << " -> " << dstFile.string();
416 }
417}
418
419// ---------------------------------------------------------------------------------------------------------------------
420//
422{
423 // Copied and adjusted from macro/beamtime/mcbm2022/trd_hitfinder_run.C
424
425 static bool callOnce = true;
426 if (!callOnce) {
427 throw std::runtime_error("CbmOnlineParWrite::Run() can only be called once at the moment!");
428 }
429 callOnce = false;
430
431 fConfig = config;
432
433 // ----- Environment --------------------------------------------------
434 fSrcDir = gSystem->Getenv("VMCWORKDIR"); // top source directory
435 // ------------------------------------------------------------------------
436
437 // --- CBM run database -----------
438 auto& cbmRunDb = cbm::RunDatabaseContainer::Instance();
439 cbmRunDb.LoadRun(fConfig.runId);
440
441 // Terminate, if alignment was required, but no alignment was found for the run ID
442 if (config.doAlignment && cbmRunDb.GetAlignmentTag().empty()) {
443 std::stringstream msg;
444 msg << "LOGIC ERROR: alignment application was required, but no alignment tag was defined in the "
445 << "data-base. Please, re-run the application with \"--no-alignment\" option";
446 throw std::logic_error(msg.str());
447 }
448
449 // --- Output path ----------------
450 fOutDir = fs::absolute(fs::weakly_canonical(fConfig.outputDir));
451 if (!fConfig.experimental && !cbmRunDb.GetRecoParTag().empty()) {
452 fOutDirReco = fOutDir / cbmRunDb.GetRecoParTag();
453 fs::create_directories(fOutDirReco);
454 }
455 else if (fConfig.experimental) {
457 }
458 else {
459 LOG(warn) << "A tag for reconstruction parameters was not defined in the CBM run database. The parameters "
460 << "will be stored in the output directory, but please provide a valid tag for this run ID";
462 }
463
464 TString geoSetupTag = cbm::RunDatabaseContainer::Instance().GetGeoSetupTag();
465
466 LOG(info) << "Using geometry setup: " << geoSetupTag;
467 fGeoSetupTag = geoSetupTag;
468
469 auto geoFilePath = fs::absolute(fs::weakly_canonical(fConfig.geoFileDir)) / (geoSetupTag + ".geo.root").Data();
470 if (!fs::exists(geoFilePath)) {
471 throw std::runtime_error{"Geometry file " + geoFilePath.string() + " does not exist"};
472 }
473
474 TString geoFile = geoFilePath.string();
475 LOG(info) << "Using geometry file: " << geoFile;
477 fSetup->LoadSetup(geoSetupTag);
478
479 //----- Load Parameters --------------------------------------------------
480 fParList = new TList();
481
482 // ----- FairRunAna ---------------------------------------------------
483 fRun = new FairRunAna();
484
485 // Dummy source required for the FairRunAna as it will crash without a source
486 fRun->SetSource(new CbmSourceDummy{});
487 fRun->SetSink(new CbmSinkDummy{});
488
489
490 // =========================================================================
491 // === Alignment Correction ===
492 // =========================================================================
493 if (fConfig.doAlignment) {
494 TString alignmentTag = cbm::RunDatabaseContainer::Instance().GetAlignmentTag();
495 TString alignmentMatrixFileName = fSrcDir + "/parameters/mcbm/AlignmentMatrices_" + alignmentTag + ".root";
496 if (alignmentMatrixFileName.Length() == 0) {
497 throw std::runtime_error{"Alignment matrix file name is empty"};
498 }
499
500 LOG(info) << "Applying alignment for file '" << alignmentMatrixFileName << "'";
501
502 // Define the basic structure which needs to be filled with information
503 // This structure is stored in the output file and later passed to the
504 // FairRoot framework to do the (miss)alignment
505 std::map<std::string, TGeoHMatrix>* matrices{nullptr};
506
507 // read matrices from disk
508 LOG(info) << "Filename: " << alignmentMatrixFileName;
509 TFile* misalignmentMatrixRootfile = new TFile(alignmentMatrixFileName, "READ");
510 if (misalignmentMatrixRootfile->IsOpen()) {
511 gDirectory->GetObject("MisalignMatrices", matrices);
512 misalignmentMatrixRootfile->Close();
513 }
514 else {
515 throw std::runtime_error{"Could not open alignment matrix file: " + alignmentMatrixFileName};
516 }
517
518 if (matrices) {
519 fRun->AddAlignmentMatrices(*matrices);
520 }
521 else {
522 throw std::runtime_error{"Could not read alignment matrices from file: " + alignmentMatrixFileName};
523 }
524 }
525
526 // ----- Create ParFiles instance -----------------------------------
527 fParFiles.timesliceReco = std::make_optional<cbm::algo::RecoParFiles>();
528 fRecoParTopDir = Form("recoPar/%s/", cbm::RunDatabaseContainer::Instance().GetRecoParTag().c_str());
529
530
531 // ----- Add detectors ------------------------------------------------
532 if (fConfig.experimental) {
534 }
535
536 AddDetectors();
537
538 fParFiles.eventReco = fParFiles.timesliceReco;
539 fParFiles.recoSetupPath = std::make_optional<std::string>(Form("%s.crs", fGeoSetupTag.Data()));
540
541 auto* pRecoSetupManager = cbm::RecoSetupManager::Instance();
542 pRecoSetupManager->StoreSetup((fOutDirReco / *(fParFiles.recoSetupPath)).string());
543 fRun->AddTask(pRecoSetupManager);
544
545 AddCa();
546
547 if (fConfig.experimental) {
549 }
550
551 // ----- Parameter database --------------------------------------------
552 FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
553 FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo();
554 parIo2->setAutoWritable(false);
555 parIo2->open(fParList, "in");
556 rtdb->setSecondInput(parIo2);
557 // ------------------------------------------------------------------------
558
559 // ----- Run initialisation -------------------------------------------
560 fRun->SetGeomFile(geoFile);
561 fRun->Init();
562
563
564
565 // ----- Clean up ---------------------------------------------------------
566 gGeoManager->GetListOfVolumes()->Delete();
567 gGeoManager->GetListOfShapes()->Delete();
568 delete gGeoManager;
569
570 // Delete files created by FairRun that I don't know how disable otherwise
571 gSystem->Exec("rm all_*.par *.mat.kf.bin");
572}
573
574
575// ---------------------------------------------------------------------------------------------------------------------
576//
578{
579 namespace fs = boost::filesystem;
580
581 fs::path mainCfgPath = fs::absolute(fs::weakly_canonical(fOutDirReco)) / "MainConfig.yaml";
582 if (!fs::exists(mainCfgPath)) {
583 throw std::runtime_error("Cannot find the main config " + mainCfgPath.string() + " in the output directory ");
584 }
585
586 // The following approach is needed to preserve the comments and formatting in the MainConfig.yaml for the
587 // rest of the nodes. It reads the file in three streams:
588 // iStream == 0 (head): everything before the parFiles node
589 // iStream == 1 (body): the parFiles node itself, which will be parsed and rewritten
590 // iStream == 2 (tail): everything after the parFiles node
591 std::array<std::stringstream, 3> content;
592 {
593 int iStream{0};
594 int nFound{0}; // number of lines, which contain "parFiles:" entry in order to catch a potential error
595 std::ifstream in(mainCfgPath.string());
596 for (std::string line; std::getline(in, line, '\n');) {
597 bool bFound = line.find("parFiles:") != std::string::npos;
598 if (bFound) ++nFound;
599 if (nFound > 1) {
600 throw std::runtime_error("CbmOnlineParWrite::UpdateParFiles(): found more than one lines with \"parFiles:\"");
601 }
602 if (iStream == 1 && line[0] != ' ' && line[0] != '\t') iStream = 2;
603 if (iStream == 0 && bFound) iStream = 1;
604 content[iStream] << line << '\n';
605 }
606 }
607
608 // Read the ParFiles node and update it with timesliceReco, eventReco and recoSetupPath
609 auto parFilesNode = YAML::Load(content[1])["parFiles"];
610 auto parFiles = yaml::Read<ParFiles>(parFilesNode);
611 parFiles.timesliceReco = fParFiles.timesliceReco;
612 parFiles.eventReco = fParFiles.eventReco;
613 parFiles.recoSetupPath = fParFiles.recoSetupPath;
614
615 // Store the updated config
616 std::ofstream out(mainCfgPath.string());
617 out << content[0].str() << '\n';
618 {
620 YAML::Emitter yamlEmitter;
621 yamlEmitter << YAML::BeginMap;
622 yamlEmitter << YAML::Key << std::string{"parFiles"};
623 yamlEmitter << YAML::Value;
624 dump.DoDump(parFiles, yamlEmitter);
625 yamlEmitter << YAML::EndMap;
626 out << yamlEmitter.c_str() << '\n';
627 }
628 out << content[2].str();
629 out.close();
630}
Handles an instance of the CA-parameters as a shared pointer (header)
@ kTrd
Transition Radiation Detector.
Definition CbmDefs.h:51
@ kTof
Time-of-flight Detector.
Definition CbmDefs.h:52
@ kTrd2d
TRD-FASP Detector (FIXME)
Definition CbmDefs.h:58
@ kMuch
Muon detection system.
Definition CbmDefs.h:50
This file contains the declaration of the CbmOnlineParWrite class.
A manager for setup representation in CBM reconstruction.
A singleton helper class for keeping the CbmRunDatabase instance in ROOT environment.
A dummy FairSink class for the FairRunAna instance, if no output is really needed.
Dummy input source.
int Int_t
static CbmMuchGeoScheme * Instance()
fs::path fOutDirReco
Output directory for reconstruction parameters.
void Run(const Config &config)
TString fGeoSetupTag
Geometry setup tag.
CbmSetup * fSetup
Global Geometry setup.
std::string fRecoParTopDir
Top directory for reco parameters.
FairRunAna * fRun
FairRunAna object.
cbm::algo::ParFiles fParFiles
Parameter files output.
TString fSrcDir
CbmRoot Source directory.
void CopyParameters()
Copies the parameters from source (if these parameters are original)
TList * fParList
List of parameter files, opened with FairRuntimeDb.
void UpdateParFiles()
Updates the parFiles node in the main config.
fs::path fOutDir
Output directory.
Bool_t GetGeoTag(ECbmModuleId moduleId, TString &tag)
Definition CbmSetup.cxx:127
static CbmSetup * Instance()
Definition CbmSetup.cxx:160
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.
void SetRecoParOutputDir(const std::string &dirname)
Sets a path to the hitfinder configuration file.
Class to handle QA-objects in the online reconstruction.
Definition QaData.h:27
static RecoSetupManager * Instance()
Instance access.
static RunDatabaseContainer & Instance()
Instance access.
const std::string & GetTofCalibrationTag() const
Returns tag of TOF calibration for a provided run ID.
const std::string & GetAlignmentTag() const
Returns tag of alignment matrices (geoSetup + ref. run ID)
const std::string & GetGeoSetupTag() const
Returns tag of the geometry setup for a provided run ID.
static ParametersHandler & Instance()
Instance.
void DoDump(const T &object, YAML::Emitter &ss, std::optional< YAML::EMITTER_MANIP > formatEntries={})
Definition CbmYaml.h:232
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.
EFieldMode
Enumiration for the magnetic field representation variants in the track fitting algorithm.
Definition KfDefs.h:108
@ Interpolated
Interpolated magnetic field.
Definition KfDefs.h:109
BMON parameter files.
STS parameter files.
TOF parameter files.
Tracking configuration and parameter files.
TRD2D parameter files.
TRD parameter files.
A class for loading/storing the Parameters objects.
A floating-point tag for tag dispatching.
Definition KfDefs.h:117