Skip to content
Snippets Groups Projects
Commit a101d32e authored by Sergey Linev's avatar Sergey Linev Committed by Axel Naumann
Browse files

web fitpanel: provide combobox for available historgams

* Use gDirectory and fHist provided to fitpanel. 
* Use string identifiers with hsitogram names
* Extract list of available TF1 objects, let sort them (do it by UI5?)
* Use std::string_literals where it make scence
* Use more compact c++11 intializer for large vectors
parent 187dc6e6
No related merge requests found
......@@ -30,6 +30,7 @@ struct RComboBoxItem {
std::string fSet;
RComboBoxItem() = default;
RComboBoxItem(const std::string &id, const std::string &set) : fId(id), fSet(set) {}
bool operator<(const RComboBoxItem& right) const { return fSet.compare(right.fSet) < 0; }
};
struct RFitFuncParameter {
......@@ -128,6 +129,8 @@ struct RFitPanel6Model {
int fScanMax{0};
void Initialize(TH1 *hist);
TH1* FindHistogram(const std::string &id, TH1 *hist = nullptr);
};
} // namespace Experimental
......
......@@ -34,6 +34,8 @@
#include <iostream>
#include <iomanip>
using namespace std::string_literals;
/** \class ROOT::Experimental::RFitPanel
\ingroup webdisplay
......@@ -52,7 +54,7 @@ std::shared_ptr<ROOT::Experimental::RWebWindow> ROOT::Experimental::RFitPanel6::
fWindow->SetDataCallBack([this](unsigned connid, const std::string &arg) { ProcessData(connid, arg); });
fWindow->SetGeometry(400, 650); // configure predefined geometry
fWindow->SetGeometry(380, 750); // configure predefined geometry
}
return fWindow;
......@@ -93,7 +95,7 @@ void ROOT::Experimental::RFitPanel6::ProcessData(unsigned connid, const std::str
// Communication with the JSONModel in JS
TString json = TBufferJSON::ToJSON(&model);
fWindow->Send(fConnId, std::string("MODEL:") + json.Data());
fWindow->Send(fConnId, "MODEL:"s + json.Data());
} else if (arg == "CONN_CLOSED") {
printf("FitPanel connection closed\n");
......@@ -133,7 +135,7 @@ void ROOT::Experimental::RFitPanel6::ProcessData(unsigned connid, const std::str
}
TString json = TBufferJSON::ToJSON(&info);
fWindow->Send(fConnId, std::string("PARS:") + json.Data());
fWindow->Send(fConnId, "PARS:"s + json.Data());
} else if (arg.compare(0, 8, "SETPARS:") == 0) {
......@@ -179,7 +181,7 @@ void ROOT::Experimental::RFitPanel6::ProcessData(unsigned connid, const std::str
}
TString jsonModel = TBufferJSON::ToJSON(&modelAdv);
fWindow->Send(fConnId, std::string("ADVANCED:") + jsonModel.Data());
fWindow->Send(fConnId, "ADVANCED:"s + jsonModel.Data());
}
}
......@@ -311,10 +313,14 @@ void ROOT::Experimental::RFitPanel6::DoFit(const std::string &model)
obj->fOption = "";
}
TH1 *h1 = obj->FindHistogram(obj->fSelectDataId, fHist);
printf("Fit histogram %s %p\n", obj->fSelectDataId.c_str(), h1);
// Assign the options to Fitting function
if (fHist && (obj->fSelectDataId == "0")) {
if (h1) {
fHist->Fit(obj->fRealFunc.c_str(), obj->fOption.c_str(), "*", obj->fUpdateRange[0], obj->fUpdateRange[1]);
h1->Fit(obj->fRealFunc.c_str(), obj->fOption.c_str(), "*", obj->fUpdateRange[0], obj->fUpdateRange[1]);
gPad->Update();
}
}
......
......@@ -17,26 +17,54 @@
#include <ROOT/RFitPanel6Model.hxx>
#include "TH1.h"
#include "TDirectory.h"
#include "TF1.h"
#include "TF2.h"
using namespace std::string_literals;
TH1* ROOT::Experimental::RFitPanel6Model::FindHistogram(const std::string &id, TH1 *hist)
{
if (id == "__hist__") return hist;
if ((id.compare(0,6,"gdir::") != 0) || !gDirectory) return nullptr;
std::string hname = id.substr(6);
return dynamic_cast<TH1*> (gDirectory->GetList()->FindObject(hname.c_str()));
}
void ROOT::Experimental::RFitPanel6Model::Initialize(TH1 *hist)
{
if (hist) {
fDataSet.emplace_back("0", Form("%s::%s", hist->ClassName(), hist->GetName()));
fSelectDataId = "0";
// build list of available histograms, as id use name from gdir
std::string histid;
if (gDirectory) {
TIter iter(gDirectory->GetList());
TObject *item = nullptr;
while ((item = iter()) != nullptr)
if (item->InheritsFrom(TH1::Class())) {
std::string dataid = "gdir::"s + item->GetName();
if (hist && (hist == item)) histid = dataid;
fDataSet.emplace_back(dataid, Form("%s::%s", item->ClassName(), item->GetName()));
}
}
// if (gDirectory) {
// TIter iter(gDirectory->GetList());
// TObject *item = nullptr;
if (hist && histid.empty()) {
histid = "__hist__";
fDataSet.emplace_back(histid, Form("%s::%s", hist->ClassName(), hist->GetName()));
}
fSelectDataId = histid;
// while ((item = iter()) != nullptr)
// if (item->InheritsFrom(TH1::Class()))
// fDataSet.emplace_back(item->GetName(), Form("%s::%s", item->ClassName(), item->GetName()));
// }
// build list of available functions
// ComboBox for Fit Function --- Type
fTypeFunc.emplace_back("0", "Predef-1D");
fTypeFunc.emplace_back("1", "User Func");
fTypeFunc.emplace_back("1", "Predef-2D");
fTypeFunc.emplace_back("2", "User");
fSelectTypeId = "0";
// Sub ComboBox for Type Function
......@@ -44,47 +72,29 @@ void ROOT::Experimental::RFitPanel6Model::Initialize(TH1 *hist)
// corresponds when Type == Predef-1D (fSelectedTypeID == 0)
fTypeXYAll.emplace_back();
auto &vec0 = fTypeXYAll.back();
vec0.emplace_back("1", "gaus");
vec0.emplace_back("2", "gausn");
vec0.emplace_back("3", "expo");
vec0.emplace_back("4", "landau");
vec0.emplace_back("5", "landaun");
vec0.emplace_back("6", "pol0");
vec0.emplace_back("7", "pol1");
vec0.emplace_back("8", "pol2");
vec0.emplace_back("9", "pol3");
vec0.emplace_back("10", "pol4");
vec0.emplace_back("11", "pol5");
vec0.emplace_back("12", "pol6");
vec0.emplace_back("13", "pol7");
vec0.emplace_back("14", "pol8");
vec0.emplace_back("15", "pol9");
vec0.emplace_back("16", "cheb0");
vec0.emplace_back("17", "cheb1");
vec0.emplace_back("18", "cheb2");
vec0.emplace_back("19", "cheb3");
vec0.emplace_back("20", "cheb4");
vec0.emplace_back("21", "cheb5");
vec0.emplace_back("22", "cheb6");
vec0.emplace_back("23", "cheb7");
vec0.emplace_back("24", "cheb8");
vec0.emplace_back("25", "cheb9");
vec0.emplace_back("26", "user");
fTypeXYAll.emplace_back();
auto &vec1d = fTypeXYAll[0];
auto &vec2d = fTypeXYAll[1];
TIter iter(gROOT->GetListOfFunctions());
TObject *func = nullptr;
int cnt1 = 1, cnt2 = 1;
while ((func = iter()) != nullptr) {
if (dynamic_cast<TF2 *>(func))
vec2d.emplace_back(std::to_string(cnt2++), func->GetName());
else if (dynamic_cast<TF1 *>(func))
vec1d.emplace_back(std::to_string(cnt1++), func->GetName());
}
if (vec1d.empty()) vec1d.emplace_back("1","none");
if (vec2d.empty()) vec2d.emplace_back("1","none");
std::sort(vec1d.begin(), vec1d.end());
std::sort(vec2d.begin(), vec2d.end());
// corresponds when Type == User Func (fSelectedTypeID == 1)
fTypeXYAll.emplace_back();
auto &vec1 = fTypeXYAll.back();
vec1.emplace_back("1", "chebyshev0");
vec1.emplace_back("2", "chebyshev1");
vec1.emplace_back("3", "chebyshev2");
vec1.emplace_back("4", "chebyshev3");
vec1.emplace_back("5", "chebyshev4");
vec1.emplace_back("6", "chebyshev5");
vec1.emplace_back("7", "chebyshev6");
vec1.emplace_back("8", "chebyshev7");
vec1.emplace_back("9", "chebyshev8");
vec1.emplace_back("10", "chebyshev9");
fTypeXYAll.back().emplace_back("1", "user");
// ComboBox for General Tab --- Method
fMethod.emplace_back("1", "Linear Chi-square");
......@@ -100,35 +110,22 @@ void ROOT::Experimental::RFitPanel6Model::Initialize(TH1 *hist)
// corresponds to library == 0
fMethodMinAll.emplace_back();
auto &methods0 = fMethodMinAll.back();
methods0.emplace_back("1", "MIGRAD");
methods0.emplace_back("2", "SIMPLEX");
methods0.emplace_back("3", "SCAN");
methods0.emplace_back("4", "Combination");
fMethodMinAll.back() = {{ "1", "MIGRAD" }, {"2", "SIMPLEX"}, {"3", "SCAN"}, {"4", "Combination"}};
// corresponds to library == 1
fMethodMinAll.emplace_back();
auto &methods1 = fMethodMinAll.back();
methods1.emplace_back("1", "MIGRAD");
methods1.emplace_back("2", "SIMPLEX");
methods1.emplace_back("3", "SCAN");
methods1.emplace_back("4", "Combination");
fMethodMinAll.back() = {{ "1", "MIGRAD" }, {"2", "SIMPLEX"}, {"3", "SCAN"}, {"4", "Combination"}};
// corresponds to library == 2
fMethodMinAll.emplace_back();
auto &methods2 = fMethodMinAll.back();
methods2.emplace_back("1", "FUMILI");
fMethodMinAll.back() = {{ "1", "FUMILI" }};
// corresponds to library == 3
fMethodMinAll.emplace_back();
// auto &methods3 = fMethodMinAll.back();
// methods3.emplace_back("1", "Lib3_1");
// methods3.emplace_back("2", "Lib3_2");
// corresponds to library == 4
fMethodMinAll.emplace_back();
auto &methods4 = fMethodMinAll.back();
methods4.emplace_back("1", "TMVA Genetic Algorithm");
fMethodMinAll.back() = {{ "1", "TMVA Genetic Algorithm" }};
if (hist) {
fUpdateMinRange = fMinRange = hist->GetXaxis()->GetXmin();
......
<mvc:View
class="sapUiSizeCompact"
height="100%"
width="450px"
width="100%"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns="sap.m"
......@@ -9,7 +9,7 @@
xmlns:form="sap.ui.layout.form"
controllerName="rootui5.fitpanel.controller.FitPanel">
<Page id="simplefitpanel_page" title="Simple Fit Panel" showHeader="false">
<VBox class="sapUiSizeCompact sapUiBody fitPanelStyle sapUiSmallMarginStart">
<VBox class="sapUiSizeCompact sapUiBody fitPanelStyle sapUiSmallMarginStart">
<form:Form id="FormToolbar"
editable="true"
ariaLabelledBy="Title1">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment