CbmRoot
Loading...
Searching...
No Matches
CbmDigitizationConfig.cxx
Go to the documentation of this file.
1/* Copyright (C) 2021 National Research Nuclear University MEPhI (Moscow Engineering Physics Institute), Moscow
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Oleg Golosov [committer] */
4
6
7#include "CbmDigitization.h"
8
9using namespace std;
10
11string CbmDigitizationConfig::GetModuleTag() { return "digitization"; }
12
14{
15 return {"logScreenLevel",
16 "logVerbosityLevel",
17 "generateRunInfo",
18 "storeAllTimeSlices",
19 "eventMode",
20 "startTime",
21 "timeSliceLength",
22 "produceNoise",
23 "timeDist",
24 "input.id",
25 "input.path",
26 "input.rate",
27 "input.embedToId",
28 "input.treeAccessMode",
29 "input.parameterSource",
30 "output.overwrite",
31 "output.path",
32 "geometry.path",
33 "geometry.sourceId",
34 "geometry.deactivate",
35 "geometry.deactivateAllBut"};
36}
37
38bool CbmDigitizationConfig::SetIO(CbmDigitization& obj, const pt::ptree& moduleTree)
39{
40 map<string, ECbmTreeAccess> stringToECbmTreeAccess = {{"regular", ECbmTreeAccess::kRegular},
41 {"repeat", ECbmTreeAccess::kRepeat},
42 {"random", ECbmTreeAccess::kRandom}};
43 map<string, cbm::sim::TimeDist> stringToCbmSimTimeDist = {{"poisson", cbm::sim::TimeDist::Poisson},
44 {"uniform", cbm::sim::TimeDist::Uniform}};
45 bool eventMode = moduleTree.get<bool>("eventMode", false);
46 auto inputs = moduleTree.get_child("input");
47 uint inputCounter = 0;
48 vector<string> paths;
49 bool parametersSet = false;
50 string parametersPath = "";
51 ECbmTreeAccess treeAccessMode;
52 string timeDistString = moduleTree.get<string>("timeDist");
54 if (stringToCbmSimTimeDist.find(timeDistString) != stringToCbmSimTimeDist.end()) {
55 timeDist = stringToCbmSimTimeDist.at(timeDistString);
56 }
57 else {
58 LOG(error) << "CbmDigitizationConfig: undefined event time distribution " << timeDistString
59 << " - use: poisson or uniform";
60 return false;
61 }
62
63 for (auto& input : inputs) {
64 pt::ptree pt_input = input.second;
65 int id = pt_input.get<int>("id", inputCounter);
66 string path = GetStringValue(pt_input, "path", "");
67 auto configRate = pt_input.get_optional<float>("rate");
68 string treeAccessModeString = pt_input.get<string>("treeAccessMode", "regular");
69 bool parameterSource = pt_input.get<bool>("parameterSource", false);
70 auto configEmbedToId = pt_input.get_optional<int>("embedToId");
71
72 if (id < 0) continue;
73 if (path == "") {
74 LOG(error) << "CbmDigitizationConfig: no path specified for input #" << id;
75 return false;
76 }
77 paths.push_back(path);
78 string traFileName = path + ".tra.root";
79 if (stringToECbmTreeAccess.find(treeAccessModeString) != stringToECbmTreeAccess.end())
80 treeAccessMode = stringToECbmTreeAccess.at(treeAccessModeString);
81 else {
82 LOG(error) << "CbmDigitizationConfig: invalid tree access mode: " << treeAccessModeString;
83 cout << "Available access modes:\n";
84 for (auto& p : stringToECbmTreeAccess)
85 cout << p.first << endl;
86 return false;
87 }
88
89 if (configEmbedToId) {
90 if (configRate) {
91 LOG(error) << "CbmDigitizationConfig: input.embedToId and input.rate should not be used simultaneously!";
92 return false;
93 }
94 else {
95 int embedToId = configEmbedToId.get();
96 LOG(info) << "CbmDigitizationConfig: Embedding input: " << traFileName;
97 obj.EmbedInput(id, traFileName, embedToId);
98 }
99 }
100 else {
101 if (eventMode && inputCounter > 0) {
102 LOG(error) << "CbmDigitizationConfig: event mixing is not possible in event-by-event mode!";
103 return false;
104 }
105 float rate = pt_input.get<float>("rate", -1.);
106 LOG(info) << "CbmDigitizationConfig: Adding input: " << traFileName << " (time distribution: " << timeDistString
107 << ")";
108 obj.AddInput(id, path + ".tra.root", timeDist, rate, treeAccessMode);
109 }
110 if (parameterSource) {
111 if (!parametersSet) {
112 parametersPath = path;
113 parametersSet = true;
114 }
115 else {
116 LOG(error) << "CbmDigitizationConfig: only one parameter source is allowed!";
117 return false;
118 }
119 }
120 inputCounter++;
121 }
122
123 string outputPath = GetStringValue(moduleTree, "output.path", paths.at(0));
124 bool overwrite = moduleTree.get<bool>("output.overwrite", false);
125
126 if (!parametersSet) parametersPath = outputPath;
127 LOG(info) << "CbmDigitizationConfig: Parameter source:\n" << parametersPath;
128 obj.SetParameterRootFile(parametersPath + ".par.root");
129 LOG(info) << "CbmDigitizationConfig: Output path:\n" << outputPath;
130 if (overwrite) LOG(info) << "CbmDigitizationConfig: Overwrite output!";
131 obj.SetOutputFile(outputPath + ".raw.root", overwrite);
132 obj.SetMonitorFile((outputPath + ".moni_digi.root").c_str());
133
134 return true;
135}
136
138{
139
140 auto produceNoise = moduleTree.get_optional<bool>("produceNoise");
141 bool eventMode = moduleTree.get<bool>("eventMode", false);
142 auto storeAllTimeSlices = moduleTree.get_optional<bool>("storeAllTimeSlices");
143 auto timeSliceLength = moduleTree.get_optional<float>("timeSliceLength");
144 auto startTime = moduleTree.get_optional<float>("startTime");
145
146 if (eventMode) {
147 if (storeAllTimeSlices || timeSliceLength) {
148 LOG(error) << "CbmDigitizationConfig: time slice settings should not be used in event mode!";
149 return false;
150 }
151 }
153
154 if (timeSliceLength) obj.SetTimeSliceLength(timeSliceLength.get());
155 if (startTime) obj.SetStartTime(startTime.get());
156 if (produceNoise) obj.SetProduceNoise(produceNoise.get());
157 return true;
158}
159
160bool CbmDigitizationConfig::SetGeometry(CbmDigitization& obj, const pt::ptree& moduleTree)
161{
162 auto modulesToDeactivate = moduleTree.get_child_optional("geometry.deactivate");
163 auto deactivateAllBut = moduleTree.get_optional<string>("geometry.deactivateAllBut");
164
165 if (modulesToDeactivate && deactivateAllBut) {
166 LOG(error)
167 << "CbmDigitizationConfig: geometry.deactivate and geometry.deactivateAllBut should not be used simultaneously!";
168 return false;
169 }
170
171 if (deactivateAllBut && deactivateAllBut.get() != "")
172 obj.DeactivateAllBut(stringToECbmModuleId(deactivateAllBut.get()));
173
174 if (modulesToDeactivate)
175 for (auto& module : modulesToDeactivate.get())
176 if (module.second.data() != "") obj.Deactivate(stringToECbmModuleId(module.second.data()));
177 return true;
178}
179
180bool CbmDigitizationConfig::LoadImpl(CbmDigitization& obj, const pt::ptree& moduleTree)
181{
182 return SetIO(obj, moduleTree) && SetDigitizationParameters(obj, moduleTree) && SetGeometry(obj, moduleTree);
183}
184
ClassImp(CbmConverterManager)
ECbmTreeAccess
Definition CbmDefs.h:192
static std::string GetStringValue(boost::optional< std::string > opt)
static ECbmModuleId stringToECbmModuleId(std::string s)
static std::string GetModuleTag()
static bool LoadImpl(CbmDigitization &obj, const pt::ptree &moduleTree)
static bool SetGeometry(CbmDigitization &obj, const pt::ptree &moduleTree)
CbmConfigBase< CbmDigitizationConfig, CbmDigitization >::TagSet_t TagSet_t
static TagSet_t GetValidationTags()
static bool SetDigitizationParameters(CbmDigitization &obj, const pt::ptree &moduleTree)
static bool SetIO(CbmDigitization &obj, const pt::ptree &moduleTree)
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 SetOutputFile(TString fileName, Bool_t overwrite=kFALSE)
Set the output file name.
void SetTimeSliceLength(Double_t length)
Set length of the 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.
TimeDist
Definition Defs.h:29
@ EventByEvent
Definition Defs.h:23
Hash for CbmL1LinkKey.