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 "input.id",
24 "input.path",
25 "input.rate",
26 "input.embedToId",
27 "input.treeAccessMode",
28 "input.parameterSource",
29 "output.overwrite",
30 "output.path",
31 "geometry.path",
32 "geometry.sourceId",
33 "geometry.deactivate",
34 "geometry.deactivateAllBut"};
35}
36
37bool CbmDigitizationConfig::SetIO(CbmDigitization& obj, const pt::ptree& moduleTree)
38{
39 map<string, ECbmTreeAccess> stringToECbmTreeAccess = {{"regular", ECbmTreeAccess::kRegular},
40 {"repeat", ECbmTreeAccess::kRepeat},
41 {"random", ECbmTreeAccess::kRandom}};
42 bool eventMode = moduleTree.get<bool>("eventMode", false);
43 auto inputs = moduleTree.get_child("input");
44 uint inputCounter = 0;
45 vector<string> paths;
46 bool parametersSet = false;
47 string parametersPath = "";
48 ECbmTreeAccess treeAccessMode;
49 for (auto& input : inputs) {
50 pt::ptree pt_input = input.second;
51 int id = pt_input.get<int>("id", inputCounter);
52 string path = GetStringValue(pt_input, "path", "");
53 auto configRate = pt_input.get_optional<float>("rate");
54 string treeAccessModeString = pt_input.get<string>("treeAccessMode", "regular");
55 bool parameterSource = pt_input.get<bool>("parameterSource", false);
56 auto configEmbedToId = pt_input.get_optional<int>("embedToId");
57
58 if (id < 0) continue;
59 if (path == "") {
60 LOG(error) << "CbmDigitizationConfig: no path specified for input #" << id;
61 return false;
62 }
63 paths.push_back(path);
64 string traFileName = path + ".tra.root";
65 if (stringToECbmTreeAccess.find(treeAccessModeString) != stringToECbmTreeAccess.end())
66 treeAccessMode = stringToECbmTreeAccess.at(treeAccessModeString);
67 else {
68 LOG(error) << "CbmDigitizationConfig: invalid tree access mode: " << treeAccessModeString;
69 cout << "Available access modes:\n";
70 for (auto& p : stringToECbmTreeAccess)
71 cout << p.first << endl;
72 return false;
73 }
74
75 if (configEmbedToId) {
76 if (configRate) {
77 LOG(error) << "CbmDigitizationConfig: input.embedToId and input.rate should not be used simultaneously!";
78 return false;
79 }
80 else {
81 int embedToId = configEmbedToId.get();
82 LOG(info) << "CbmDigitizationConfig: Embedding input: " << traFileName;
83 obj.EmbedInput(id, traFileName, embedToId);
84 }
85 }
86 else {
87 if (eventMode && inputCounter > 0) {
88 LOG(error) << "CbmDigitizationConfig: event mixing is not possible in event-by-event mode!";
89 return false;
90 }
91 float rate = pt_input.get<float>("rate", -1.);
92 LOG(info) << "CbmDigitizationConfig: Adding input: " << traFileName;
93 obj.AddInput(id, path + ".tra.root", cbm::sim::TimeDist::Poisson, rate, treeAccessMode);
94 }
95 if (parameterSource) {
96 if (!parametersSet) {
97 parametersPath = path;
98 parametersSet = true;
99 }
100 else {
101 LOG(error) << "CbmDigitizationConfig: only one parameter source is allowed!";
102 return false;
103 }
104 }
105 inputCounter++;
106 }
107
108 string outputPath = GetStringValue(moduleTree, "output.path", paths.at(0));
109 bool overwrite = moduleTree.get<bool>("output.overwrite", false);
110
111 if (!parametersSet) parametersPath = outputPath;
112 LOG(info) << "CbmDigitizationConfig: Parameter source:\n" << parametersPath;
113 obj.SetParameterRootFile(parametersPath + ".par.root");
114 LOG(info) << "CbmDigitizationConfig: Output path:\n" << outputPath;
115 if (overwrite) LOG(info) << "CbmDigitizationConfig: Overwrite output!";
116 obj.SetOutputFile(outputPath + ".raw.root", overwrite);
117 obj.SetMonitorFile((outputPath + ".moni_digi.root").c_str());
118
119 return true;
120}
121
123{
124
125 auto produceNoise = moduleTree.get_optional<bool>("produceNoise");
126 bool eventMode = moduleTree.get<bool>("eventMode", false);
127 auto storeAllTimeSlices = moduleTree.get_optional<bool>("storeAllTimeSlices");
128 auto timeSliceLength = moduleTree.get_optional<float>("timeSliceLength");
129 auto startTime = moduleTree.get_optional<float>("startTime");
130
131 if (eventMode) {
132 if (storeAllTimeSlices || timeSliceLength) {
133 LOG(error) << "CbmDigitizationConfig: time slice settings should not be used in event mode!";
134 return false;
135 }
136 }
138
139 if (timeSliceLength) obj.SetTimeSliceLength(timeSliceLength.get());
140 if (startTime) obj.SetStartTime(startTime.get());
141 if (produceNoise) obj.SetProduceNoise(produceNoise.get());
142 return true;
143}
144
145bool CbmDigitizationConfig::SetGeometry(CbmDigitization& obj, const pt::ptree& moduleTree)
146{
147 auto modulesToDeactivate = moduleTree.get_child_optional("geometry.deactivate");
148 auto deactivateAllBut = moduleTree.get_optional<string>("geometry.deactivateAllBut");
149
150 if (modulesToDeactivate && deactivateAllBut) {
151 LOG(error)
152 << "CbmDigitizationConfig: geometry.deactivate and geometry.deactivateAllBut should not be used simultaneously!";
153 return false;
154 }
155
156 if (deactivateAllBut && deactivateAllBut.get() != "")
157 obj.DeactivateAllBut(stringToECbmModuleId(deactivateAllBut.get()));
158
159 if (modulesToDeactivate)
160 for (auto& module : modulesToDeactivate.get())
161 if (module.second.data() != "") obj.Deactivate(stringToECbmModuleId(module.second.data()));
162 return true;
163}
164
165bool CbmDigitizationConfig::LoadImpl(CbmDigitization& obj, const pt::ptree& moduleTree)
166{
167 return SetIO(obj, moduleTree) && SetDigitizationParameters(obj, moduleTree) && SetGeometry(obj, moduleTree);
168}
169
ClassImp(CbmConverterManager)
ECbmTreeAccess
Mode to read entries from a ROOT TTree.
Definition CbmDefs.h:152
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.
Hash for CbmL1LinkKey.