CbmRoot
Loading...
Searching...
No Matches
reco/offline/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: Volker Friese [committer], Florian Uhlig */
4
10#include "Run.h"
11
12#include "CbmSetup.h"
13#include "TaskFactory.h"
14
15#include <FairEventHeader.h>
16#include <FairFileSource.h>
17#include <FairMonitor.h>
18#include <FairParRootFileIo.h>
19#include <FairRootFileSink.h>
20#include <FairRunAna.h>
21#include <FairRuntimeDb.h>
22#include <FairTask.h>
23#include <Logger.h>
24
25#include <TFile.h>
26#include <TGeoManager.h>
27#include <TStopwatch.h>
28#include <TString.h>
29#include <TTree.h>
30
31#include <cassert>
32#include <iostream>
33
34#include <sys/stat.h>
35
36namespace cbm::reco::offline
37{
38
39
40 // ----- Constructor ----------------------------------------------------
41 Run::Run() : TNamed("Run", "CBM Reconstruction Run") {}
42 // --------------------------------------------------------------------------
43
44
45 // ----- Destructor -----------------------------------------------------
46 Run::~Run() { LOG(debug) << "Destructing " << fName; }
47 // --------------------------------------------------------------------------
48
49
50 // ----- Add a reconstruction task --------------------------------------
51 void Run::AddTask(FairTask* task)
52 {
53 fRun.AddTask(task);
54 LOG(info) << GetName() << ": Added task " << task->GetName();
55 }
56 // --------------------------------------------------------------------------
57
58
59 // ----- Check a digi branch --------------------------------------------
60 void Run::CheckDigiBranch(TTree* tree, ECbmModuleId detector)
61 {
62 TString branchName = ToString(detector);
63 branchName += "Digi";
64 if (tree->GetBranchStatus(branchName.Data())) {
65 LOG(info) << GetName() << ": Found branch " << branchName;
66 fDataPresent.insert(detector);
67 }
68 }
69 // --------------------------------------------------------------------------
70
71
72 // ----- Check existence of a file --------------------------------------
73 bool Run::CheckFile(const char* fileName)
74 {
75 struct stat buffer;
76 return (stat(fileName, &buffer) == 0);
77 }
78 // --------------------------------------------------------------------------
79
80
81 // ----- Check which input digi branches are present --------------------
82 void Run::CheckInputBranches(FairFileSource* source)
83 {
84
85 TFile* inFile = source->GetInFile();
86 if (!inFile) throw std::runtime_error("No input file");
87 auto* inTree = inFile->Get<TTree>("cbmsim");
88 if (!inTree) throw std::runtime_error("No input tree");
89
90 for (ECbmModuleId detector = ECbmModuleId::kMvd; detector != ECbmModuleId::kNofSystems; ++detector)
91 CheckDigiBranch(inTree, detector);
92 }
93 // --------------------------------------------------------------------------
94
95
96 // ----- Create the topology --------------------------------------------
98 {
99
100 TaskFactory fact(this);
101
102 // --- Timeslice processing
104 fact.RegisterStsReco(); // Local reconstruction in STS
105 fact.RegisterRichHitFinder(); // Hit finding in RICH
106 fact.RegisterMuchReco(); // Local reconstruction in MUCH
107 fact.RegisterTrdReco(); // Local reconstruction in TRD
108 fact.RegisterTofReco(); // Local reconstruction in TOF
109 fact.RegisterPsdReco(); // Local reconstruction in PSD
110 fact.RegisterFsdReco(); // Local reconstruction in FSD
111 fact.RegisterCaTracking(); // CA track finder in STS and MVD
112 fact.RegisterTrackEventBuilder(); // Event building from STS tracks
113 }
114
115 // --- Event-by-event processing
117 fact.RegisterDigiEventBuilder(); // Event building from digis
118 fact.RegisterMvdReco(); // Local reconstruction in MVD
119 fact.RegisterStsReco(); // Local reconstruction in STS
120 fact.RegisterRichHitFinder(); // Hit finding in RICH
121 fact.RegisterMuchReco(); // Local reconstruction in MUCH
122 fact.RegisterTrdReco(); // Local reconstruction in TRD
123 fact.RegisterTofReco(); // Local reconstruction in TOF
124 fact.RegisterPsdReco(); // Local reconstruction in PSD
125 fact.RegisterFsdReco(); // Local reconstruction in FSD
126 fact.RegisterCaTracking(); // CA track finder in STS and MVD
127 fact.RegisterPvFinder(); // Primary vertex finding
128 fact.RegisterGlobalTracking(); // Global tracking
129 fact.RegisterTrdPid(); // PID in TRD
130 fact.RegisterRichReco(); // Local RICH reconstruction
131 fact.RegisterBmonReco(); // Reconstruction of Bmon from BMON
132 }
133
134 // --- Mode not defined
135 else
136 throw std::out_of_range("Reconstruction mode not defined");
137 }
138 // --------------------------------------------------------------------------
139
140
141 // ----- Execute reconstruction run -------------------------------------
143 {
144
145 // --- Mirror options and configuration
146 LOG(info) << GetName() << ": Output file is " << fOutput;
147 LOG(info) << GetName() << ": Digitization file is " << fRaw;
148 LOG(info) << GetName() << ": Parameter file is " << fPar;
149 LOG(info) << GetName() << ": Geometry setup is " << fSetupTag;
150 LOG(info) << "Configuration: \n" << fConfig.ToString();
151
152 // --- Timer
153 TStopwatch timer;
154 timer.Start();
155
156 // --- Run info
157 fRun.SetGenerateRunInfo(true);
158
159 // --- Logger settings
160 FairLogger::GetLogger()->SetLogScreenLevel(fConfig.f_glb_logLevel.data());
161 FairLogger::GetLogger()->SetLogVerbosityLevel(fConfig.f_glb_logVerbose.data());
162 FairLogger::GetLogger()->SetColoredLog(fConfig.f_glb_logColor.data());
163
164 // --- Check input, output and parameter files
165 if (!CheckFile(fRaw.Data())) throw std::runtime_error("Digitization (raw) file does not exist");
166 if (!CheckFile(fPar.Data())) throw std::runtime_error("Parameter file does not exist");
167 if (CheckFile(fOutput.Data()) && !fOverwrite) throw std::runtime_error("Output file already exists");
168
169 // --- Input and output
170 FairFileSource* source = new FairFileSource(fRaw);
171 fRun.SetSource(source);
172 fRun.SetSink(new FairRootFileSink(fOutput));
173
174 // --- Check presence of input (digi) branches
175 LOG(info) << GetName() << ": Checking digi input...";
176 CheckInputBranches(source);
177
178 // --- Geometry setup
179 LOG(info) << GetName() << ": Loading setup " << fSetupTag;
182 // TODO: This CbmSetup business with singleton is not nice. Should be replaced eventually.
183
184 // --- Topology
185 LOG(info) << GetName() << ": Creating topology...";
187
188 // --- Parameter database
189 LOG(info) << GetName() << ": Set runtime DB...";
190 FairRuntimeDb* rtdb = fRun.GetRuntimeDb();
191 FairParRootFileIo* parIo1 = new FairParRootFileIo();
192 parIo1->open(fPar.Data(), "UPDATE");
193 rtdb->setFirstInput(parIo1);
194
195 // --- Initialisation
196 LOG(info) << GetName() << ": Initialise FairRun..." << std::endl;
197 fRun.Init();
198 rtdb->setOutput(parIo1);
199 rtdb->saveOutput();
200 rtdb->print();
201 timer.Stop();
202 double timeInit = timer.RealTime();
203 timer.Start();
204
205 // TODO: Register light ions (see run_reco.C). But what for?
206
207 // --- Execute run
208 std::cout << std::endl << std::endl;
209 LOG(info) << GetName() << ": Starting run" << std::endl;
211
212 // --- Finish
213 timer.Stop();
214 double timeExec = timer.RealTime();
215 FairMonitor::GetMonitor()->Print();
216 std::cout << std::endl << std::endl;
217 LOG(info) << GetName() << ": Execution successful";
218 LOG(info) << GetName() << ": Digitization file was " << fRaw;
219 LOG(info) << GetName() << ": Parameter file was " << fPar;
220 LOG(info) << GetName() << ": Output file is " << fOutput;
221 LOG(info) << GetName() << ": Execution time: Init " << timeInit << " s, Exec " << timeExec << "s";
222 }
223 // --------------------------------------------------------------------------
224
225
226 // ----- Read configuration from YAML file -------------------------------
227 void Run::LoadConfig(const char* fileName)
228 {
229
230 TString file(fileName);
231 if (file.IsNull()) {
232 file = std::getenv("VMCWORKDIR");
233 file += "/reco/offline/config/RecoConfig_event_ideal.yaml";
234 }
235 LOG(info) << GetName() << ": Loading configuration from " << file;
236 fConfig.LoadYaml(file.Data());
237 }
238 // --------------------------------------------------------------------------
239
240
241} // namespace cbm::reco::offline
242
ClassImp(CbmConverterManager)
std::string ToString(ECbmModuleId modId)
Definition CbmDefs.cxx:70
ECbmModuleId
Definition CbmDefs.h:39
@ kMvd
Micro-Vertex Detector.
@ kNofSystems
For loops over active systems.
static CbmSetup * Instance()
Definition CbmSetup.cxx:160
void LoadSetup(const char *setupName)
Definition CbmSetup.h:64
std::string ToString()
String output (YAML format)
void LoadYaml(const std::string &filename)
Load from YAML file.
void LoadConfig(const char *fileName)
Set configuration file name.
bool CheckFile(const char *fileName)
Check existence of a file.
void AddTask(FairTask *task)
Add a task to the run.
std::set< ECbmModuleId > fDataPresent
void CheckDigiBranch(TTree *tree, ECbmModuleId detector)
Check and mark presence of a digi branch.
void CheckInputBranches(FairFileSource *source)
Check the presence of digi input branches.
void Exec()
Run reconstruction.
void CreateTopology()
Create the reconstruction task topology (chain)
Factory class for the instantiation of CBM reconstruction tasks.
void RegisterTrackEventBuilder()
Local reconstruction for FSD.
void RegisterTrdReco()
Event building from tracks.
void RegisterFsdReco()
Local reconstruction for PSD.
void RegisterMvdReco()
Local reconstruction for MUCH.
void RegisterPvFinder()
Local reconstruction for MVD.
void RegisterTofReco()
Local reconstruction for STS.
void RegisterStsReco()
Local reconstruction for RICH.
void RegisterGlobalTracking()
Event building from digis.
void RegisterTrdPid()
Local reconstruction for TRD.
void RegisterPsdReco()
Local reconstruction for TOF.
void RegisterRichHitFinder()
Primary vertex finding.