48using namespace std::string_literals;
60 : objid(_objid), res(_res)
62 std::swap(
func, _func);
99 fWindow->SetPanelName(
"rootui5.fitpanel.view.FitPanel");
102 [
this](
unsigned connid)
106 if (!
model().fInitialized)
110 [
this](
unsigned connid,
const std::string &arg) {
ProcessData(connid, arg); },
111 [
this](unsigned) {
fConnId = 0; });
113 fWindow->SetGeometry(400, 650);
129 m.fDataSet.emplace_back(
"Panel",
"panel::"s + obj->GetName(),
Form(
"%s::%s", obj->ClassName(), obj->GetName()));
134 while ((obj = iter()) !=
nullptr) {
150 std::string
id = objid;
151 if (
id.compare(
"$$$") == 0) {
152 if (
m.fDataSet.size() > 0)
153 id =
m.fDataSet[0].id;
161 m.SetObjectKind(kind);
170 hist = ((
TGraph*)obj)->GetHistogram();
178 hist = ((
TGraph2D*)obj)->GetHistogram(
"empty");
182 hist = (
TH1 *)((
THStack *)obj)->GetHists()->First();
195 m.fSelectedData =
"";
197 m.fSelectedData =
id;
199 m.fInitialized =
true;
207 std::string selfunc =
m.fSelectedFunc;
209 if (!
m.HasFunction(selfunc)) {
210 if (
m.fFuncList.size() > 0)
211 selfunc =
m.fFuncList[0].id;
225 if (objid.compare(0,6,
"gdir::") == 0) {
226 std::string
name = objid.substr(6);
229 }
else if (objid.compare(0,7,
"panel::") == 0) {
230 std::string
name = objid.substr(7);
232 if (
name.compare(item->GetName()) == 0)
275 m.fFuncList = { {
"gaus"}, {
"gausn"}, {
"expo"}, {
"landau"}, {
"landaun"},
276 {
"pol0"},{
"pol1"},{
"pol2"},{
"pol3"},{
"pol4"},{
"pol5"},{
"pol6"},{
"pol7"},{
"pol8"},{
"pol9"},
277 {
"cheb0"}, {
"cheb1"}, {
"cheb2"}, {
"cheb3"}, {
"cheb4"}, {
"cheb5"}, {
"cheb6"}, {
"cheb7"}, {
"cheb8"}, {
"cheb9"} };
278 }
else if (
m.fDim == 2) {
279 m.fFuncList = { {
"xygaus"}, {
"bigaus"}, {
"xyexpo"}, {
"xylandau"}, {
"xylandaun"} };
283 m.fFuncList.emplace_back(
"System",
"system::"s + func->GetName(), func->GetName());
287 if (entry.objid ==
m.fSelectedData)
288 m.fFuncList.emplace_back(
"Previous",
"previous::"s + entry.func->GetName(), entry.func->GetName());
365 fModel = std::make_unique<RFitPanelModel>();
389 if (arg ==
"RELOAD") {
398 }
else if (arg.compare(0, 7,
"UPDATE:") == 0) {
403 }
else if (arg.compare(0, 6,
"DOFIT:") == 0) {
409 }
else if (arg.compare(0, 7,
"DODRAW:") == 0) {
415 }
else if (arg.compare(0, 8,
"SETPARS:") == 0) {
417 auto info = TBufferJSON::FromJSON<RFitPanelModel::RFuncParsList>(arg.substr(8));
424 info->SetParameters(func);
435 if (
id.compare(0,8,
"system::") == 0) {
436 std::string
name =
id.substr(8);
439 if (
name.compare(item->GetName()) == 0)
443 if (
id.compare(0,10,
"previous::") == 0) {
444 std::string
name =
id.substr(10);
447 if (
name.compare(entry.func->GetName()) == 0)
448 return entry.func.get();
459 if (
id.compare(0,10,
"previous::") == 0) {
460 std::string
name =
id.substr(10);
463 if (
name.compare(entry.func->GetName()) == 0)
464 return entry.res.Get();
475 std::unique_ptr<TF1> res;
481 res.reset((
TF1*) func->IsA()->New());
483 }
else if (funcname.compare(0,6,
"dflt::") == 0) {
485 std::string formula = funcname.substr(6);
492 if (
model().fDim == 1 ||
model().fDim == 0 ) {
493 res.reset(
new TF1(formula.c_str(), formula.c_str(),
xmin,
xmax));
494 }
else if (
model().fDim == 2 ) {
496 }
else if (
model().fDim == 3 ) {
512 auto m = TBufferJSON::FromJSON<RFitPanelModel>(json);
519 m->fInitialized =
true;
552 if (
dynamic_cast<TF3*
>(
f)) {
553 TF3* fnew = (
TF3*)
f->IsA()->New();
560 }
else if (
dynamic_cast<TF2*
>(
f) != 0 ) {
561 TF2* fnew = (
TF2*)
f->IsA()->New();
571 TF1* fnew = (
TF1*)
f->IsA()->New();
595 std::vector<std::string> fnames = {
"gaus" ,
"gausn",
"expo",
"landau",
596 "landaun",
"pol0",
"pol1",
"pol2",
597 "pol3",
"pol4",
"pol5",
"pol6",
598 "pol7",
"pol8",
"pol9",
"user" };
601 TIter functionsIter(
gROOT->GetListOfFunctions());
603 while( (obj = functionsIter()) !=
nullptr ) {
605 if (
TF1* func =
dynamic_cast<TF1*
>(obj) ) {
606 bool addFunction =
true;
608 for (
auto &
name : fnames) {
609 if (
name.compare(func->GetName()) == 0 ) {
627 if (!obj || (!force && (
model().fNoDrawing ||
model().fNoStoreDraw)))
632 if (!pad)
return res;
636 while (!res && (prim = next())) {
637 res = (prim == obj) ? pad : check(
dynamic_cast<TPad *
>(prim));
644 auto drawpad = check(drawcanv);
661 while ((
c = nextc())) {
662 auto drawpad = check(
dynamic_cast<TCanvas*
>(
c));
671 auto canv =
gROOT->MakeDefCanvas();
672 canv->SetName(
"fpc");
673 canv->SetTitle(
"Fit panel drawings");
691 if (!obj)
return false;
695 if (!
f1)
return false;
697 auto drange =
m.GetRanges();
698 auto minOption =
m.GetMinimizerOptions();
699 auto fitOpts =
m.GetFitOptions();
700 auto drawOpts =
m.GetDrawOption();
702 fitOpts.StoreResult = 1;
713 TH1 *hist =
dynamic_cast<TH1*
>(obj);
755 gROOT->GetListOfFunctions()->Remove(
f1.get());
757 if (
m.fSame &&
f1 && pad) {
769 if ((funcname.compare(0,4,
"prev") == 0) && (funcname.find(
"-") > 4))
770 funcname.erase(0, funcname.find(
"-") + 1);
771 funcname =
"prev"s + std::to_string(
fPrevRes.size() + 1) +
"-"s + funcname;
780 if (save && (
gPad != save))
792 if ((colorid.length() != 7) || (colorid.compare(0,1,
"#") != 0))
return 0;
822 std::vector<Double_t> ci(data->Size());
825 if (
model().fDim == 1) {
827 for (
unsigned int i = 0; i < ci.size(); ++i) {
830 g->SetPoint(i, *
x,
y);
831 g->SetPointError(i, 0, ci[i]);
836 g->SetTitle(
"Confidence Intervals with");
839 g->SetLineColor(icol);
840 g->SetFillColor(icol);
841 g->SetFillStyle(3001);
843 }
else if (
model().fDim == 2) {
845 for (
unsigned int i = 0; i < ci.size(); ++i) {
848 g->SetPoint(i,
x[0],
x[1],
y);
849 g->SetPointError(i, 0, 0, ci[i]);
855 g->SetTitle(
"Confidence Intervals with");
858 g->SetLineColor(icol);
859 g->SetFillColor(icol);
860 g->SetFillStyle(3001);
876 if (!obj)
return false;
880 bool superimpose =
true, objowner =
true;
882 if (
m.fHasAdvanced && (
m.fSelectedTab ==
"Advanced")) {
885 if (!res)
return false;
887 if (
m.fAdvancedTab ==
"Contour") {
889 superimpose =
m.fContourSuperImpose;
890 int par1 = std::stoi(
m.fContourPar1Id);
891 int par2 = std::stoi(
m.fContourPar2Id);
900 auto fillcolor =
GetColor(
m.fContourColor);
901 graph->SetFillColor(fillcolor);
902 graph->GetXaxis()->SetTitle( res->
ParName(par1).c_str() );
903 graph->GetYaxis()->SetTitle( res->
ParName(par2).c_str() );
906 drawopt = superimpose ?
"LF" :
"ALF";
908 }
else if (
m.fAdvancedTab ==
"Scan") {
910 int par = std::stoi(
m.fScanId);
912 if (!res->
Scan( par,
graph,
m.fScanMin,
m.fScanMax)) {
917 if (!linecolor) linecolor =
kBlue;
918 graph->SetLineColor(linecolor);
919 graph->SetLineWidth(2);
921 graph->GetYaxis()->SetTitle(
"FCN" );
927 }
else if (
m.fAdvancedTab ==
"Confidence") {
941 if (func && (
m.fSelectedTab.compare(
"Pars") == 0) && (
m.fSelectedFunc ==
m.fFuncPars.id))
942 m.fFuncPars.SetParameters(func);
965 drawobj->
Draw(drawopt.c_str());
#define R__LOG_ERROR(...)
char * Form(const char *fmt,...)
void Show(const std::string &where="")
show FitPanel in specified place
bool DoFit()
Perform fitting using current model settings Returns true if any action was done.
void AssignHistogram(TH1 *hist)
Assign histogram to use with fit panel - without ownership.
std::unique_ptr< TF1 > GetFitFunction(const std::string &funcid)
Creates new instance to make fitting.
void SelectFunction(const std::string &funcid)
Select fit function.
RFitPanelModel::EFitObjectType GetFitObjectType(TObject *obj)
Returns kind of object.
std::shared_ptr< RCanvas > fCanvas
! v7 canvas used to display results
void SendModel()
Send model object to the client.
std::shared_ptr< RWebWindow > fWindow
! configured display
std::string fCanvName
! v6 canvas name used to display fit, will be created if not exists
void GetFunctionsFromSystem()
Looks for all the functions registered in the current ROOT session.
std::unique_ptr< RFitPanelModel > fModel
unsigned fConnId
! client connection id
int UpdateModel(const std::string &json)
Update fit model returns -1 if JSON fails return 0 if nothing large changed return 1 if important sel...
TF1 * copyTF1(TF1 *f)
Copies f into a new TF1 to be stored in the fitpanel with it's own ownership.
TPad * GetDrawPad(TObject *obj, bool force=false)
Returns pad where histogram is drawn If canvas not exists, create new one.
std::shared_ptr< RWebWindow > GetWindow()
Returns RWebWindow instance, used to display FitPanel.
void SelectObject(const std::string &objid)
Select object for fitting.
std::string fPadName
! v6 pad name in the canvas, where object is (was) drawn
TObject * GetSelectedObject(const std::string &objid)
Returns object based on it string id Searches either in gDirectory or in internal panel list.
std::vector< TObject * > fObjects
! objects provided directly to panel for fitting
bool DoDraw()
Perform drawing using current model settings Returns true if any action was done.
Color_t GetColor(const std::string &colorid)
Extract color from string Should be coded as #ff00ff string.
void UpdateFunctionsList()
Update list of available functions.
RFitPanelModel & model()
Return reference on model object Model created if was not exists before.
std::shared_ptr< RH1D > fFitHist
! v7 histogram for fitting
TObject * MakeConfidenceLevels(TFitResult *res)
Create confidence levels drawing tab.
TF1 * FindFunction(const std::string &funcid)
Search for existing functions, ownership still belongs to FitPanel or global lists.
void ProcessData(unsigned connid, const std::string &arg)
Process data from FitPanel OpenUI5-based FitPanel sends commands or status changes.
TFitResult * FindFitResult(const std::string &funcid)
Creates new instance to make fitting.
void UpdateDataSet()
Update list of available data.
std::vector< std::unique_ptr< TF1 > > fSystemFuncs
! local copy of all internal system funcs
RFitPanel(const std::string &title="Fit panel")
Constructor.
std::list< FitRes > fPrevRes
! all previous functions used for fitting
void AssignCanvas(const std::string &cname)
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
class describing the range in the coordinates it supports multiple range in a coordinate.
void GetRange(unsigned int irange, unsigned int icoord, double &xmin, double &xmax) const
get the i-th range for given coordinate.
const BinData * FittedBinData() const
return BinData used in the fit (return a nullptr in case a different fit is done or the data are not ...
void GetConfidenceIntervals(unsigned int n, unsigned int stride1, unsigned int stride2, const double *x, double *ci, double cl=0.95, bool norm=false) const
get confidence intervals for an array of n points x.
std::string ParName(unsigned int i) const
name of the parameter
const IModelFunction * FittedFunction() const
fitting quantities
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
virtual void Copy(TObject &f1) const
Copy this F1 to a new F1.
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
virtual void SetParent(TObject *p=0)
virtual TString GetExpFormula(Option_t *option="") const
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
virtual void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax)
Save values of function in array fSave.
virtual Bool_t AddToGlobalList(Bool_t on=kTRUE)
Add to global list of functions (gROOT->GetListOfFunctions() ) return previous status (true if the fu...
A 2-Dim function with parameters.
virtual void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax)
Save values of function in array fSave.
virtual void Copy(TObject &f2) const
Copy this F2 to a new F2.
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
A 3-Dim function with parameters.
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
virtual void Copy(TObject &f3) const
Copy this F3 to a new F3.
Provides an indirection to the TFitResult class and with a semantics identical to a TFitResult pointe...
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O.
bool Contour(unsigned int ipar, unsigned int jpar, TGraph *gr, double confLevel=0.683)
Create a 2D contour around the minimum for the parameter ipar and jpar if a minimum does not exist or...
bool Scan(unsigned int ipar, TGraph *gr, double xmin=0, double xmax=0)
Scan parameter ipar between value of xmin and xmax A graph must be given which will be on return fill...
Graph 2D class with errors.
Graphics object made of three arrays X, Y and Z with the same number of points each.
A TGraphErrors is a TGraph with error bars.
A TGraph is an object made of two arrays X and Y with npoints each.
TH1 is the base class of all histogram classes in ROOT.
The Histogram stack class.
A TMultiGraph is a collection of TGraph (or derived) objects.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
virtual void Clear(Option_t *="")
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
The most important graphics class in the ROOT system.
TList * GetListOfPrimitives() const override
const char * GetName() const override
Returns name of object.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
RLogChannel & FitPanelLog()
Log channel for FitPanel diagnostics.
TFitResultPtr FitObject(TH1 *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
fitting function for a TH1 (called from TH1::Fit)
Data structure for the fit panel.
std::string fSelectedData
selected data
std::string fSelectedFunc
id of selected fit function like dflt::gaus
void UpdateAdvanced(TFitResult *res)
Update advanced parameters associated with fit function.
void SelectedFunc(const std::string &name, TF1 *func)
Select function.
std::string fTitle
title of the fit panel
ROOT::Fit::DataRange GetRanges()
std::unique_ptr< TF1 > func