48using namespace std::string_literals;
64 std::swap(
func, _func);
75 if (func && func->IsZombie())
106 fWindow->SetPanelName(
"rootui5.fitpanel.view.FitPanel");
109 [
this](
unsigned connid)
113 if (!
model().fInitialized)
117 [
this](
unsigned connid,
const std::string &arg) {
ProcessData(connid, arg); },
118 [
this](unsigned) {
fConnId = 0; });
120 fWindow->SetGeometry(400, 650);
136 m.fDataSet.emplace_back(
"Panel",
"panel::"s + obj->GetName(),
Form(
"%s::%s", obj->ClassName(), obj->GetName()));
141 while ((obj = iter()) !=
nullptr) {
157 std::string
id = objid;
158 if (
id.compare(
"$$$") == 0) {
159 if (
m.fDataSet.size() > 0)
160 id =
m.fDataSet[0].id;
168 m.SetObjectKind(kind);
177 hist = ((
TGraph*)obj)->GetHistogram();
185 hist = ((
TGraph2D*)obj)->GetHistogram(
"empty");
189 hist = (
TH1 *)((
THStack *)obj)->GetHists()->First();
202 m.fSelectedData =
"";
204 m.fSelectedData =
id;
206 m.fInitialized =
true;
214 std::string
selfunc =
m.fSelectedFunc;
217 if (
m.fFuncList.size() > 0)
232 if (objid.compare(0,6,
"gdir::") == 0) {
233 std::string
name = objid.substr(6);
236 }
else if (objid.compare(0,7,
"panel::") == 0) {
237 std::string
name = objid.substr(7);
239 if (
name.compare(
item->GetName()) == 0)
282 m.fFuncList = { {
"gaus"}, {
"gausn"}, {
"expo"}, {
"landau"}, {
"landaun"},
283 {
"pol0"},{
"pol1"},{
"pol2"},{
"pol3"},{
"pol4"},{
"pol5"},{
"pol6"},{
"pol7"},{
"pol8"},{
"pol9"},
284 {
"cheb0"}, {
"cheb1"}, {
"cheb2"}, {
"cheb3"}, {
"cheb4"}, {
"cheb5"}, {
"cheb6"}, {
"cheb7"}, {
"cheb8"}, {
"cheb9"} };
285 }
else if (
m.fDim == 2) {
286 m.fFuncList = { {
"xygaus"}, {
"bigaus"}, {
"xyexpo"}, {
"xylandau"}, {
"xylandaun"} };
290 m.fFuncList.emplace_back(
"System",
"system::"s + func->GetName(), func->GetName());
294 if (
entry.objid ==
m.fSelectedData)
295 m.fFuncList.emplace_back(
"Previous",
"previous::"s +
entry.func->GetName(),
entry.func->GetName());
364 fModel = std::make_unique<RFitPanelModel>();
388 if (arg ==
"RELOAD") {
397 }
else if (arg.compare(0, 7,
"UPDATE:") == 0) {
402 }
else if (arg.compare(0, 6,
"DOFIT:") == 0) {
408 }
else if (arg.compare(0, 7,
"DODRAW:") == 0) {
414 }
else if (arg.compare(0, 8,
"SETPARS:") == 0) {
416 auto info = TBufferJSON::FromJSON<RFitPanelModel::RFuncParsList>(arg.substr(8));
423 info->SetParameters(func);
434 if (
id.compare(0,8,
"system::") == 0) {
435 std::string
name =
id.substr(8);
438 if (
name.compare(
item->GetName()) == 0)
442 if (
id.compare(0,10,
"previous::") == 0) {
443 std::string
name =
id.substr(10);
446 if (
name.compare(
entry.func->GetName()) == 0)
447 return entry.func.get();
458 if (
id.compare(0,10,
"previous::") == 0) {
459 std::string
name =
id.substr(10);
462 if (
name.compare(
entry.func->GetName()) == 0)
463 return entry.res.Get();
474 std::unique_ptr<TF1> res;
482 }
else if (
funcname.compare(0,6,
"dflt::") == 0) {
484 std::string formula =
funcname.substr(6);
491 if (
model().fDim == 1 ||
model().fDim == 0 ) {
492 res.reset(
new TF1(formula.c_str(), formula.c_str(),
xmin,
xmax));
493 }
else if (
model().fDim == 2 ) {
495 }
else if (
model().fDim == 3 ) {
511 auto m = TBufferJSON::FromJSON<RFitPanelModel>(
json);
518 m->fInitialized =
true;
522 if (
model().fSelectedData !=
m->fSelectedData) {
526 if (
model().fSelectedFunc !=
m->fSelectedFunc) {
551 if (
dynamic_cast<TF3*
>(
f)) {
556 fnew->SetParent(
nullptr );
557 fnew->AddToGlobalList(
false);
559 }
else if (
dynamic_cast<TF2*
>(
f) != 0 ) {
565 fnew->SetParent(
nullptr );
566 fnew->AddToGlobalList(
false);
576 if (
'\0' !=
fnew->GetExpFormula()[0] )
578 fnew->SetParent(
nullptr );
579 fnew->AddToGlobalList(
false);
594 std::vector<std::string>
fnames = {
"gaus" ,
"gausn",
"expo",
"landau",
595 "landaun",
"pol0",
"pol1",
"pol2",
596 "pol3",
"pol4",
"pol5",
"pol6",
597 "pol7",
"pol8",
"pol9",
"user" };
604 if (
TF1* func =
dynamic_cast<TF1*
>(obj) ) {
608 if (
name.compare(func->GetName()) == 0 ) {
631 if (!
pad)
return res;
633 TIter next(
pad->GetListOfPrimitives());
635 while (!res && (
prim = next())) {
671 canv->SetName(
"fpc");
672 canv->SetTitle(
"Fit panel drawings");
690 if (!obj)
return false;
694 if (!
f1)
return false;
712 TH1 *hist =
dynamic_cast<TH1*
>(obj);
754 gROOT->GetListOfFunctions()->Remove(
f1.get());
756 if (
m.fSame &&
f1 &&
pad) {
785 if ((
colorid.length() != 7) || (
colorid.compare(0,1,
"#") != 0))
return 0;
803 const auto *function =
result->FittedFunction();
815 std::vector<Double_t>
ci(
data->Size());
818 if (
model().fDim == 1) {
820 for (
unsigned int i = 0; i <
ci.size(); ++i) {
823 g->SetPoint(i, *
x,
y);
824 g->SetPointError(i, 0,
ci[i]);
829 g->SetTitle(
"Confidence Intervals with");
832 g->SetLineColor(
icol);
833 g->SetFillColor(
icol);
834 g->SetFillStyle(3001);
836 }
else if (
model().fDim == 2) {
838 for (
unsigned int i = 0; i <
ci.size(); ++i) {
841 g->SetPoint(i,
x[0],
x[1],
y);
842 g->SetPointError(i, 0, 0,
ci[i]);
848 g->SetTitle(
"Confidence Intervals with");
851 g->SetLineColor(
icol);
852 g->SetFillColor(
icol);
853 g->SetFillStyle(3001);
869 if (!obj)
return false;
875 if (
m.fHasAdvanced && (
m.fSelectedTab ==
"Advanced")) {
878 if (!res)
return false;
880 if (
m.fAdvancedTab ==
"Contour") {
883 int par1 = std::stoi(
m.fContourPar1Id);
884 int par2 = std::stoi(
m.fContourPar2Id);
901 }
else if (
m.fAdvancedTab ==
"Scan") {
903 int par = std::stoi(
m.fScanId);
905 if (!res->
Scan( par, graph,
m.fScanMin,
m.fScanMax)) {
920 }
else if (
m.fAdvancedTab ==
"Confidence") {
934 if (func && (
m.fSelectedTab.compare(
"Pars") == 0) && (
m.fSelectedFunc ==
m.fFuncPars.id))
935 m.fFuncPars.SetParameters(func);
958 drawobj->Draw(drawopt.c_str());
#define R__LOG_ERROR(...)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
RFitPanel(const std::string &title="Fit panel")
Constructor.
TPad * GetDrawPad(TObject *obj, bool force=false)
Returns pad where histogram is drawn If canvas not exists, create new one.
void UpdateDataSet()
Update list of available data.
void UpdateFunctionsList()
Update list of available functions.
void SelectFunction(const std::string &funcid)
Select fit function.
void GetFunctionsFromSystem()
Looks for all the functions registered in the current ROOT session.
void ClearOnClose(const std::shared_ptr< void > &handle)
Set handle which will be cleared when connection is closed.
RFitPanelModel::EFitObjectType GetFitObjectType(TObject *obj)
Returns kind of object.
std::shared_ptr< RCanvas > fCanvas
! v7 canvas used to display results
TF1 * FindFunction(const std::string &funcid)
Search for existing functions, ownership still belongs to FitPanel or global lists.
std::string fCanvName
! v6 canvas name used to display fit, will be created if not exists
std::unique_ptr< RFitPanelModel > fModel
Color_t GetColor(const std::string &colorid)
Extract color from string Should be coded as #ff00ff string.
unsigned fConnId
! client connection id
std::string fPadName
! v6 pad name in the canvas, where object is (was) drawn
bool DoFit()
Perform fitting using current model settings Returns true if any action was done.
std::shared_ptr< ROOT::RWebWindow > fWindow
! configured display
TObject * MakeConfidenceLevels(TFitResult *res)
Create confidence levels drawing tab.
std::vector< TObject * > fObjects
! objects provided directly to panel for fitting
std::unique_ptr< TF1 > GetFitFunction(const std::string &funcid)
Creates new instance to make fitting.
void AssignHistogram(TH1 *hist)
Assign histogram to use with fit panel - without ownership.
TFitResult * FindFitResult(const std::string &funcid)
Creates new instance to make fitting.
TObject * GetSelectedObject(const std::string &objid)
Returns object based on it string id Searches either in gDirectory or in internal panel list.
void SendModel()
Send model object to the client.
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...
void DoPadUpdate(TPad *pad)
Mark pad modified and do update For web canvas set async mode first to avoid blocking here.
void Show(const RWebDisplayArgs &args="")
show FitPanel in specified place
RFitPanelModel & model()
Return reference on model object Model created if was not exists before.
TF1 * copyTF1(TF1 *f)
Copies f into a new TF1 to be stored in the fitpanel with it's own ownership.
std::vector< std::unique_ptr< TF1 > > fSystemFuncs
! local copy of all internal system funcs
std::list< FitRes > fPrevRes
! all previous functions used for fitting
void ProcessData(unsigned connid, const std::string &arg)
Process data from FitPanel OpenUI5-based FitPanel sends commands or status changes.
void AssignCanvas(const std::string &cname)
bool DoDraw()
Perform drawing using current model settings Returns true if any action was done.
void SelectObject(const std::string &objid)
Select object for fitting.
std::shared_ptr< ROOT::RWebWindow > GetWindow()
Returns RWebWindow instance, used to display FitPanel.
class describing the range in the coordinates it supports multiple range in a coordinate.
std::string ParName(unsigned int i) const
name of the parameter
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static unsigned ShowWindow(std::shared_ptr< RWebWindow > window, const RWebDisplayArgs &args="")
Static method to show web window Has to be used instead of RWebWindow::Show() when window potentially...
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
void Copy(TObject &f1) const override
Copy this F1 to a new F1.
void Draw(Option_t *option="") override
Draw this function with its current attributes.
TClass * IsA() const override
A 2-Dim function with parameters.
A 3-Dim function with parameters.
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.
TAxis * GetXaxis() const
Get x axis of the graph.
TAxis * GetYaxis() const
Get y axis of the graph.
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 SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
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.
small helper class to store/restore gPad context in TPad methods
ROOT::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.
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