Skip to content

Commit 843f5aa

Browse files
authoredAug 19, 2023
Merge pull request #1 from gipert/dev
Support mixtures of arbitrary ROOT files
2 parents 5162689 + c565819 commit 843f5aa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎src/HMixFit.cc

+29
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,35 @@ HMixFit::HMixFit(json outconfig) : config(outconfig) {
332332
_current_ds.comp_orig.insert({comp_idx, thh});
333333
_current_ds.comp.insert({comp_idx, utils::ReformatHistogram(thh, _current_ds.data)});
334334
}
335+
// it's a user defined file list with weights
336+
else if (!iso.value().contains("TFormula") and it.contains("root-files")) {
337+
BCLog::OutDebug("user-specified ROOT file list (with weights) detected");
338+
auto obj_name = iso.value().value("hist-name", elh.key());
339+
340+
TH1* sum = nullptr;
341+
if (it["root-files"].is_object()) {
342+
for (auto& p : it["root-files"].items()) {
343+
// get histogram
344+
BCLog::OutDebug("opening file " + p.key());
345+
BCLog::OutDebug("summing object '" + obj_name + " with weight "
346+
+ std::to_string(p.value().get<double>()));
347+
auto thh = this->GetFitComponent(p.key(), obj_name, _current_ds.data_orig);
348+
// add it with weight
349+
if (!sum) {
350+
sum = thh;
351+
sum->Scale(p.value().get<double>());
352+
}
353+
else {
354+
sum->Add(thh, p.value().get<double>());
355+
delete thh;
356+
}
357+
}
358+
}
359+
else throw std::runtime_error("\"root-files\" must be a dictionary");
360+
sum->SetName(utils::SafeROOTName(iso.key()).c_str());
361+
_current_ds.comp_orig.insert({comp_idx, sum});
362+
_current_ds.comp.insert({comp_idx, utils::ReformatHistogram(sum, _current_ds.data)});
363+
}
335364
// it's a explicit TFormula
336365
else if (iso.value().contains("TFormula")) {
337366
BCLog::OutDebug("TFormula expression detected");

0 commit comments

Comments
 (0)
Failed to load comments.