ndmspc 0.20250304.0
Loading...
Searching...
No Matches
Results.cxx
1#include <TFile.h>
2#include <THnSparse.h>
3#include <TH1.h>
4#include "Results.h"
5
6#include "Core.h"
7
9ClassImp(Ndmspc::Results);
11
12namespace Ndmspc {
13Results::Results() : TObject()
14{
18}
25bool Results::LoadConfig(std::string configfilename, std::string userconfig, std::string environment,
26 std::string userConfigRaw)
27{
31
32 bool configLoaded = Core::LoadConfig(configfilename, userconfig, environment, userConfigRaw);
33 if (!gCfg["ndmspc"]["data"]["histogram"]["enabled"].is_null() ||
34 gCfg["ndmspc"]["data"]["histogram"]["enabled"].is_boolean()) {
35 if (gCfg["ndmspc"]["data"]["histogram"]["enabled"].get<bool>()) fDataSource = DataSource::histogram;
36 }
37 std::string hostUrl = gCfg["ndmspc"]["output"]["host"].get<std::string>();
38 std::string path;
39 if (!hostUrl.empty()) path = hostUrl + "/";
40 path += gCfg["ndmspc"]["output"]["dir"].get<std::string>() + "/";
41
42 for (auto & cut : gCfg["ndmspc"]["cuts"]) {
43 if (cut["enabled"].is_boolean() && cut["enabled"].get<bool>() == false) continue;
44 path += cut["axis"].get<std::string>() + "_";
45 fCuts.push_back(cut["axis"].get<std::string>());
46 }
47
48 path[path.size() - 1] = '/';
49
50 path += environment + "/";
51
53
54 return configLoaded;
55}
56void Results::Print(Option_t * option) const
57{
61 // Printf("%s", gCfg.dump(2).c_str());
62
63 int iAxis = 0;
64 for (auto & an : fAxes) {
65
66 printf("axis: %15s(%s)\t[val=%d] \t[", an.c_str(), fAxesTypes[iAxis].c_str(), fPoint[iAxis]);
67 if (fAxesLabels.find(an) == fAxesLabels.end()) {
68 Printf("]");
69 continue;
70 }
71 int iLabel = 0;
72 for (auto & al : fAxesLabels.at(an)) {
73 if (al.empty()) continue;
74 if (fAxesLabels.at(an).back() == al) {
75 printf("%s(%d)", al.c_str(), iLabel + 1);
76 }
77 else {
78 printf("%s(%d),", al.c_str(), iLabel + 1);
79 }
80 iLabel++;
81 }
82
83 Printf("]");
84 iAxis++;
85 }
86}
87
89{
93 Printf("Opening file '%s' ...", fInputFileName.c_str());
94
95 fInputFile = TFile::Open(fInputFileName.c_str());
96 if (!fInputFile) {
97
98 Printf("Error: Input file '%s' was not found !!!", fInputFileName.c_str());
99 return false;
100 }
101
102 fResultHnSparse = (THnSparse *)fInputFile->Get(fResultsHnSparseName.c_str());
103 if (!fResultHnSparse) {
104 Printf("Error: Results THnSparse histogram '%s' was not found !!!", fResultsHnSparseName.c_str());
105 return false;
106 }
107
108 fMapAxesType = (TH1 *)fInputFile->Get(fMapAxesTypeName.c_str());
109 if (!fMapAxesType) {
110 Printf("Error: 'mapAxesType' histogram was not found !!!");
111 return false;
112 }
113
114 int pointsSize = gCfg["ndmspc"]["result"]["axes"].size() + 1;
115 if (fDataSource == DataSource::histogram) pointsSize += gCfg["ndmspc"]["result"]["data"]["defaults"].size() + 1;
116 // int points[pointsSize];
117 // int iPoint = 0;
118 // points[iPoint++] = nAxisY;
119
120 fPoint.clear();
121 fAxes.clear();
122 fAxesTypes.clear();
123 fAxesLabels.clear();
124 fAxesBinSizes.clear();
125 for (int iDim = 0; iDim < fResultHnSparse->GetNdimensions(); iDim++) {
126 TAxis * a = (TAxis *)fResultHnSparse->GetAxis(iDim);
127 if (a == nullptr) {
128 Printf("Error: Axis 'id=%d' was not found !!!", iDim);
129 return false;
130 }
131 fPoint.push_back(-1);
132 std::string axisName = a->GetName();
133 fAxes.push_back(axisName);
134 if (a->IsAlphanumeric()) {
135 for (int iLabel = 0; iLabel < a->GetNbins(); iLabel++) {
136 fAxesLabels[axisName].push_back(a->GetBinLabel(iLabel));
137 }
138 }
139 fAxesBinSizes[axisName] = a->GetNbins();
140 fAxesTypes.push_back(fMapAxesType->GetXaxis()->GetBinLabel(iDim + 1));
141 }
142
143 if (fCurrentParameterName.empty()) {
144 int idxDefault = gCfg["ndmspc"]["result"]["parameters"]["default"].get<int>();
145 fCurrentParameterName = gCfg["ndmspc"]["result"]["parameters"]["labels"][idxDefault].get<std::string>();
146 }
147 Printf("Paremeter: %s", fCurrentParameterName.c_str());
148
149 TAxis * a = (TAxis *)fResultHnSparse->GetListOfAxes()->FindObject(fParametesAxisName.c_str());
150 if (a == nullptr) {
151 Printf("Error: Axis '%s' was not found !!!", fParametesAxisName.c_str());
152 return false;
153 }
154 Int_t id = fResultHnSparse->GetListOfAxes()->IndexOf(a);
155 Int_t idBin = a->FindBin(fCurrentParameterName.c_str());
156 if (idBin < 0) {
157 Printf("Could not find bin label '%s' in '%s' axis !!!", fParametesAxisName.c_str(), fCurrentParameterName.c_str());
158 return false;
159 }
160
161 Printf("Axis: %d [parameters] SetRange(%d,%d)", id, idBin, idBin);
162 fPoint[id] = idBin;
163 fResultHnSparse->GetAxis(id)->SetRange(idBin, idBin);
164
165 // int iAxisStart = 1;
166 // json axesArray = gCfg["ndmspc"]["result"]["axes"];
167 // int idTmp;
168 // bool isDataSys = true;
169 // bool hasDataMc = false;
170 // for (int iAxis = iAxisStart; iAxis < fResultHnSparse->GetNdimensions(); iAxis++) {
171 // idBin = 1;
172 // std::string axisType = fMapAxesType->GetXaxis()->GetBinLabel(iAxis + 1);
173 // // Printf("Axis: %d [%s]", iAxis, axisType.c_str());
174 // if (!hasDataMc) hasDataMc = !axisType.compare("data");
175 // if (!axisType.compare("proj")) {
176 // isDataSys = false;
177 // fProjectionAxes.push_back(iAxis);
178 // }
179 // else if (!axisType.compare("sys") || !axisType.compare("data")) {
180 // if (isDataSys) {
181 // idTmp = iAxis - iAxisStart;
182 // idBin = gCfg["ndmspc"]["result"]["data"]["defaults"][idTmp].get<int>();
183 // }
184 // else {
185 // idTmp = iAxis - iAxisStart - fNDimCuts;
186 // if (histogramEnabled) idTmp -= gCfg["ndmspc"]["result"]["data"]["defaults"].size();
187 // // Printf("%s %d", axesArray.dump().c_str(), idTmp);
188 // idBin = axesArray[idTmp]["default"].get<int>() + 1;
189 // }
190 // }
191 // a = (TAxis *)fResultHnSparse->GetAxis(iAxis);
192 // Printf("Axis: %d [%s][%s] SetRange(%d,%d)", iAxis, axisType.c_str(), a->GetName(), idBin, idBin);
193 // points[iAxis] = a->GetNbins();
194 // fParameterPoint[iAxis] = idBin;
195 // fResultHnSparse->GetAxis(iAxis)->SetRange(idBin, idBin);
196 // std::string l = a->GetBinLabel(idBin);
197 // if (l.empty()) {
198 // fMapTitle += std::to_string(a->GetBinLowEdge(idBin));
199 // }
200 // else {
201 // fMapTitle += l;
202 // }
203 // fMapTitle += " ";
204 // }
205 // fMapTitle[fMapTitle.size() - 1] = ']';
206 //
207 // for (auto & p : fParameterPoint) {
208 // printf("%d ", p);
209 // }
210 // printf("\n");
211 //
212 // Printf("fMapTitle='%s'", fMapTitle.c_str());
214 ApplyPoints();
215
216 Print();
217 return true;
218}
219
221{
225 Printf("Apply points ...");
226
227 int iAxis = 0;
228 for (auto & p : fPoint) {
229 if (p < 0) {
230 // Printf("Warning: Point[%d] is %d !!! Setting it to 1", iAxis, p);
231 p = 1;
232 }
233 Printf("ApplyPoint : %s [%s] SetRange(%d,%d)", fAxes[iAxis].c_str(), fAxesTypes[iAxis].c_str(), p, p);
234 fResultHnSparse->GetAxis(iAxis)->SetRange(p, p);
235 iAxis++;
236 }
237
238 return true;
239}
240
242{
247
248 TAxis * a;
249 for (int iAxis = 1; iAxis < fResultHnSparse->GetNdimensions(); iAxis++) {
250 a = (TAxis *)fResultHnSparse->GetAxis(iAxis);
251 std::string l = a->GetBinLabel(fPoint[iAxis]);
252 if (l.empty()) {
253 fMapTitle += std::to_string(fPoint[iAxis]);
254 }
255 else {
256 fMapTitle += l;
257 }
258 fMapTitle += " ";
259 }
260
261 fMapTitle += "]";
262
263 Printf("Map title: '%s'", fMapTitle.c_str());
264}
265
266void Results::Draw(Option_t * option)
267{
271
272 Printf("Draw results ...");
273 LoadResults();
274}
275} // namespace Ndmspc
static bool LoadConfig(std::string config, std::string userConfig, std::string &environment, std::string userConfigRaw="", std::string binning="")
Definition Core.cxx:16
Results object.
Definition Results.h:20
virtual ~Results()
Definition Results.cxx:19
std::map< std::string, std::vector< std::string > > fAxesLabels
axes labels
Definition Results.h:54
std::vector< std::string > fAxesTypes
axes types
Definition Results.h:53
std::string fMapAxesTypeName
map axes type name
Definition Results.h:45
std::map< std::string, int > fAxesBinSizes
axes map
Definition Results.h:55
std::string fInputFileName
file name
Definition Results.h:39
THnSparse * fResultHnSparse
results sparse histogram
Definition Results.h:42
std::string fCurrentParameterName
current parameter name
Definition Results.h:48
void GenerateTitle()
Definition Results.cxx:241
bool LoadConfig(std::string configfilename="config.json", std::string userconfig="", std::string environment="", std::string userConfigRaw="")
Definition Results.cxx:25
virtual void Draw(Option_t *option="")
Definition Results.cxx:266
bool ApplyPoints()
Definition Results.cxx:220
std::string fParametesAxisName
parameters axis name
Definition Results.h:47
std::string fMapTitle
map type title
Definition Results.h:49
std::string fResultsHnSparseName
results object name
Definition Results.h:41
std::vector< std::string > fCuts
cuts
Definition Results.h:50
std::vector< std::string > fAxes
axes names
Definition Results.h:52
DataSource fDataSource
data source
Definition Results.h:46
bool LoadResults()
Definition Results.cxx:88
std::vector< int > fPoint
point
Definition Results.h:51
std::string fResultFileName
results file name
Definition Results.h:43
TFile * fInputFile
input file
Definition Results.h:40
TH1 * fMapAxesType
map axes type
Definition Results.h:44
virtual void Print(Option_t *option="") const
Definition Results.cxx:56