CbmRoot
Loading...
Searching...
No Matches
sim/response/steer/Run.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Frederic Linz [committer], Volker Friese, Florian Uhlig */
4
10#include "Run.h"
11
12#include "CbmDigitization.h"
13#include "CbmSetup.h"
14
15#include <FairEventHeader.h>
16#include <FairMonitor.h>
17#include <Logger.h>
18
19#include <TFile.h>
20#include <TGeoManager.h>
21#include <TStopwatch.h>
22#include <TString.h>
23#include <TTree.h>
24
25#include <cassert>
26#include <iostream>
27
28#include <sys/stat.h>
29
31{
32
33
34 // ----- Constructor ----------------------------------------------------
35 Run::Run() : TNamed("Run", "CBM AnalysisTree Converter Run") {}
36 // --------------------------------------------------------------------------
37
38
39 // ----- Destructor -----------------------------------------------------
40 Run::~Run() { LOG(debug) << "Destructing " << fName; }
41 // --------------------------------------------------------------------------
42
43
44 // ----- Check existence of a file --------------------------------------
45 bool Run::CheckFile(const char* fileName)
46 {
47 struct stat buffer;
48 return (stat(fileName, &buffer) == 0);
49 }
50 // --------------------------------------------------------------------------
51
52
53 // ----- Execute reconstruction run -------------------------------------
54 void Run::Exec()
55 {
56 // --- Mirror options and configuration
57 LOG(info) << GetName() << ": Output file is " << fOutput;
58 if (CheckFile(fOutput.Data()) && !fOverwrite) throw std::runtime_error("Output file already exists");
59 for (auto trafile : fTra) {
60 LOG(info) << GetName() << ": Transport input source is " << trafile;
61 if (!CheckFile(trafile.Data())) throw std::runtime_error("Transport file does not exist");
62 }
63 LOG(info) << GetName() << ": Parameter file is " << fPar;
64 if (!CheckFile(fPar.Data())) throw std::runtime_error("Parameter file does not exist");
65 LOG(info) << GetName() << ": Geometry setup is " << fSetupTag;
66 LOG(info) << "Configuration: \n" << fConfig.ToString() << "\n";
67
68 // --- Timer
69 TStopwatch timer;
70 timer.Start();
71
72 // --- Logger settings
73 FairLogger::GetLogger()->SetLogScreenLevel(fConfig.f_glb_logLevel.data());
74 FairLogger::GetLogger()->SetLogVerbosityLevel(fConfig.f_glb_logVerbose.data());
75 FairLogger::GetLogger()->SetColoredLog(fConfig.f_glb_logColor.data());
76
77 // --- Input sources
78 int sourceId = 0;
79 for (auto trafile : fTra) {
80 if (fConfig.f_src_embedToId.at(sourceId) > 0) {
81 LOG(info) << GetName() << ": Embeding input " << trafile << " (Rate will be ignored)";
82 fRun.EmbedInput(fConfig.f_src_id.at(sourceId), trafile, fConfig.f_src_embedToId.at(sourceId));
83 }
84 else {
86 throw std::runtime_error("Event mixing is not possible in event-by-event mode!");
87
88 LOG(info) << GetName() << ": Adding input " << trafile;
89 fRun.AddInput(fConfig.f_src_id.at(sourceId), trafile, fConfig.f_ts_timeDist, fConfig.f_src_rate.at(sourceId),
90 fConfig.f_src_treeAccessMode.at(sourceId));
91 }
92 }
94 fRun.SetMonitorFile((GetFileName(fOutput) + ".moni_digi.root").c_str());
96
97 // --- Set digitization parameters
103 }
105
106 // --- Geometry setup
107 LOG(info) << GetName() << ": Loading setup " << fSetupTag;
110
113
114 for (auto det : fConfig.f_det_deactivate) {
115 if (det != ECbmModuleId::kNotExist) fRun.Deactivate(det);
116 }
117
118 timer.Stop();
119 double timeInit = timer.RealTime();
120 timer.Start();
121
122 // --- Execute run
123 std::cout << std::endl << std::endl;
124 LOG(info) << GetName() << ": Starting run" << std::endl;
126
127 // --- Finish
128 timer.Stop();
129 double timeExec = timer.RealTime();
130 FairMonitor::GetMonitor()->Print();
131 std::cout << std::endl << std::endl;
132 LOG(info) << GetName() << ": Execution successful";
133 for (auto trafile : fTra)
134 LOG(info) << GetName() << ": Transport file was " << trafile;
135 LOG(info) << GetName() << ": Parameter file was " << fPar;
136 LOG(info) << GetName() << ": Output file is " << fOutput;
137 LOG(info) << GetName() << ": Execution time: Init " << timeInit << " s, Exec " << timeExec << "s";
138 }
139 // --------------------------------------------------------------------------
140
141
142 // ----- Get file name without extension ---------------------------------
143 std::string Run::GetFileName(const TString file)
144 {
145 std::string temp(file.Data());
146 size_t index = temp.find_last_of(".");
147 temp = temp.substr(0, index);
148 std::transform(temp.begin(), temp.end(), temp.begin(), [](unsigned char c) { return c; });
149 return temp;
150 }
151 // --------------------------------------------------------------------------
152
153
154 // ----- Read configuration from YAML file -------------------------------
155 void Run::LoadConfig(const char* fileName)
156 {
157 TString file(fileName);
158 if (file.IsNull()) {
159 file = std::getenv("VMCWORKDIR");
160 file += "/sim/response/config/DigiConfig_event.yaml";
161 }
162 LOG(info) << GetName() << ": Loading configuration from " << file;
163 fConfig.LoadYaml(file.Data());
164 }
165 // --------------------------------------------------------------------------
166
167
168 // ---- Set input sources -------------------------------------------------
169 void Run::SetTraFiles(const std::vector<std::string> files)
170 {
171 for (auto file : files) {
172 fTra.push_back(file.c_str());
173 }
174 }
175 // --------------------------------------------------------------------------
176
177} // namespace cbm::sim::digitization
178
ClassImp(CbmConverterManager)
@ kNotExist
If not found.
void EmbedInput(UInt_t inputId, TString fileName, UInt_t targetInputId, ECbmTreeAccess mode=ECbmTreeAccess::kRegular)
Embed an input file into another one.
void SetParameterRootFile(TString fileName)
Set the parameter file name.
void SetStartTime(Double_t time)
Set the start time of the run.
void DeactivateAllBut(ECbmModuleId system)
Deactivate all systems except the specified one.
void SetMonitorFile(const char *fileName)
Set the monitor file name.
void Run()
Process all events from input.
void SetOutputFile(TString fileName, Bool_t overwrite=kFALSE)
Set the output file name.
void SetTimeSliceLength(Double_t length)
Set length of the time-slices.
void StoreAllTimeSlices(Bool_t choice=kTRUE)
Store all time-slices.
void SetProduceNoise(Bool_t choice=kTRUE)
Set production of inter-event noise.
void Deactivate(ECbmModuleId system)
Deactivate a system for digitisation.
void SetMode(cbm::sim::Mode mode)
Set event-by-event mode.
void AddInput(UInt_t inputId, TString fileName, cbm::sim::TimeDist dist=cbm::sim::TimeDist::Poisson, Double_t eventRate=0., ECbmTreeAccess mode=ECbmTreeAccess::kRegular)
Add an input file.
static CbmSetup * Instance()
Definition CbmSetup.cxx:160
void LoadSetup(const char *setupName)
Definition CbmSetup.h:64
std::string ToString()
String output (YAML format)
std::vector< ECbmModuleId > f_det_deactivate
void LoadYaml(const std::string &filename)
Load from YAML file.
std::vector< ECbmTreeAccess > f_src_treeAccessMode
std::string GetFileName(const TString file)
Get file name without ending.
void SetTraFiles(const std::vector< std::string > files)
Set transport file name.
bool CheckFile(const char *fileName)
Check existence of a file.
void LoadConfig(const char *fileName)
Set configuration file name.