48using namespace std::string_literals;
 
   62   : objid(_objid), res(_res)
 
   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;
 
  216   if (!
m.HasFunction(selfunc)) {
 
  217      if (
m.fFuncList.size() > 0)
 
  218         selfunc = 
m.fFuncList[0].id;
 
  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());
 
  372      fModel = std::make_unique<RFitPanelModel>();
 
  396   if (arg == 
"RELOAD") {
 
  405   } 
else if (arg.compare(0, 7, 
"UPDATE:") == 0) {
 
  410   } 
else if (arg.compare(0, 6, 
"DOFIT:") == 0) {
 
  416   } 
else if (arg.compare(0, 7, 
"DODRAW:") == 0) {
 
  422   } 
else if (arg.compare(0, 8, 
"SETPARS:") == 0) {
 
  424      auto info = TBufferJSON::FromJSON<RFitPanelModel::RFuncParsList>(arg.substr(8));
 
  431            info->SetParameters(func);
 
  442   if (
id.compare(0,8,
"system::") == 0) {
 
  443      std::string 
name = 
id.substr(8);
 
  446         if (
name.compare(item->GetName()) == 0)
 
  450   if (
id.compare(0,10,
"previous::") == 0) {
 
  451      std::string 
name = 
id.substr(10);
 
  454         if (
name.compare(entry.func->GetName()) == 0)
 
  455            return entry.func.get();
 
  466   if (
id.compare(0,10,
"previous::") == 0) {
 
  467      std::string 
name = 
id.substr(10);
 
  470         if (
name.compare(entry.func->GetName()) == 0)
 
  471            return entry.res.Get();
 
  482   std::unique_ptr<TF1> res;
 
  490   } 
else if (funcname.compare(0,6,
"dflt::") == 0) {
 
  492      std::string formula = funcname.substr(6);
 
  499      if ( 
model().fDim == 1 || 
model().fDim == 0 ) {
 
  500         res.reset(
new TF1(formula.c_str(), formula.c_str(), 
xmin, 
xmax));
 
  501      } 
else if ( 
model().fDim == 2 ) {
 
  503      } 
else if ( 
model().fDim == 3 ) {
 
  519   auto m = TBufferJSON::FromJSON<RFitPanelModel>(
json);
 
  526   m->fInitialized = 
true;
 
  530   if (
model().fSelectedData != 
m->fSelectedData) {
 
  534   if (
model().fSelectedFunc != 
m->fSelectedFunc) {
 
  559   if ( 
dynamic_cast<TF3*
>(
f)) {
 
  567   } 
else if ( 
dynamic_cast<TF2*
>(
f) != 0 ) {
 
  602   std::vector<std::string> fnames = { 
"gaus" ,   
"gausn", 
"expo", 
"landau",
 
  603                                       "landaun", 
"pol0",  
"pol1", 
"pol2",
 
  604                                       "pol3",    
"pol4",  
"pol5", 
"pol6",
 
  605                                       "pol7",    
"pol8",  
"pol9", 
"user" };
 
  608   TIter functionsIter(
gROOT->GetListOfFunctions());
 
  610   while( (obj = functionsIter()) != 
nullptr ) {
 
  612      if ( 
TF1* func = 
dynamic_cast<TF1*
>(obj) ) {
 
  613         bool addFunction = 
true;
 
  615         for ( 
auto &
name : fnames) {
 
  616            if ( 
name.compare(func->GetName()) == 0 ) {
 
  634   if (!obj || (!force && (
model().fNoDrawing || 
model().fNoStoreDraw)))
 
  639      if (!pad) 
return res;
 
  643      while (!res && (prim = next())) {
 
  644         res = (prim == obj) ? pad : check(
dynamic_cast<TPad *
>(prim));
 
  651      auto drawpad = check(drawcanv);
 
  668   while ((
c = nextc())) {
 
  669      auto drawpad = check(
dynamic_cast<TCanvas* 
>(
c));
 
  678   auto canv = 
gROOT->MakeDefCanvas();
 
  679   canv->SetName(
"fpc");
 
  680   canv->SetTitle(
"Fit panel drawings");
 
  698   if (!obj) 
return false;
 
  702   if (!
f1) 
return false;
 
  704   auto drange = 
m.GetRanges();
 
  705   auto minOption = 
m.GetMinimizerOptions();
 
  706   auto fitOpts = 
m.GetFitOptions();
 
  709   fitOpts.StoreResult = 1;
 
  720         TH1 *hist = 
dynamic_cast<TH1*
>(obj);
 
  762      gROOT->GetListOfFunctions()->Remove(
f1.get());
 
  764   if (
m.fSame && 
f1 && pad) {
 
  776   if ((funcname.compare(0,4,
"prev") == 0) && (funcname.find(
"-") > 4))
 
  777      funcname.erase(0, funcname.find(
"-") + 1);
 
  778   funcname = 
"prev"s + std::to_string(
fPrevRes.size() + 1) + 
"-"s + funcname;
 
  796   if ((colorid.length() != 7) || (colorid.compare(0,1,
"#") != 0)) 
return 0;
 
  814   const auto *function = 
result->FittedFunction();
 
  826   std::vector<Double_t> ci(
data->Size());
 
  827   result->GetConfidenceIntervals(*
data, &ci[0], 
model().fConfidenceLevel);
 
  829   if (
model().fDim == 1) {
 
  831      for (
unsigned int i = 0; i < ci.size(); ++i) {
 
  834         g->SetPoint(i, *
x, 
y);
 
  835         g->SetPointError(i, 0, ci[i]);
 
  840      g->SetTitle(
"Confidence Intervals with");
 
  843      g->SetLineColor(icol);
 
  844      g->SetFillColor(icol);
 
  845      g->SetFillStyle(3001);
 
  847   } 
else if (
model().fDim == 2) {
 
  849      for (
unsigned int i = 0; i < ci.size(); ++i) {
 
  852         g->SetPoint(i, 
x[0], 
x[1], 
y);
 
  853         g->SetPointError(i, 0, 0, ci[i]);
 
  859      g->SetTitle(
"Confidence Intervals with");
 
  862      g->SetLineColor(icol);
 
  863      g->SetFillColor(icol);
 
  864      g->SetFillStyle(3001);
 
  880   if (!obj) 
return false;
 
  884   bool superimpose = 
true, objowner = 
true;
 
  886   if (
m.fHasAdvanced && (
m.fSelectedTab == 
"Advanced")) {
 
  889      if (!res) 
return false;
 
  891      if (
m.fAdvancedTab == 
"Contour") {
 
  893         superimpose = 
m.fContourSuperImpose;
 
  894         int par1 = std::stoi(
m.fContourPar1Id);
 
  895         int par2 = std::stoi(
m.fContourPar2Id);
 
  904         auto fillcolor = 
GetColor(
m.fContourColor);
 
  905         graph->SetFillColor(fillcolor);
 
  906         graph->GetXaxis()->SetTitle( res->
ParName(par1).c_str() );
 
  907         graph->GetYaxis()->SetTitle( res->
ParName(par2).c_str() );
 
  910         drawopt = superimpose ? 
"LF" : 
"ALF";
 
  912      } 
else if (
m.fAdvancedTab == 
"Scan") {
 
  914         int par = std::stoi(
m.fScanId);
 
  916         if (!res->
Scan( par, 
graph, 
m.fScanMin, 
m.fScanMax)) {
 
  921         if (!linecolor) linecolor = 
kBlue;
 
  922         graph->SetLineColor(linecolor);
 
  923         graph->SetLineWidth(2);
 
  925         graph->GetYaxis()->SetTitle(
"FCN" );
 
  931      } 
else if (
m.fAdvancedTab == 
"Confidence") {
 
  945       if (func && (
m.fSelectedTab.compare(
"Pars") == 0) && (
m.fSelectedFunc == 
m.fFuncPars.id))
 
  946           m.fFuncPars.SetParameters(func);
 
  969   drawobj->
Draw(drawopt.c_str());
 
#define R__LOG_ERROR(...)
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.
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::shared_ptr< RWebWindow > fWindow
! configured display
std::string fCanvName
! v6 canvas name used to display fit, will be created if not exists
std::unique_ptr< RFitPanelModel > fModel
void Show(const std::string &where="")
show FitPanel in specified place
std::shared_ptr< RWebWindow > GetWindow()
Returns RWebWindow instance, used to display FitPanel.
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.
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...
std::shared_ptr< RH1D > fFitHist
! v7 histogram for fitting
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.
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.
std::string ParName(unsigned int i) const
name of the parameter
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",...
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
virtual TString GetExpFormula(Option_t *option="") const
virtual void SetParent(TObject *p=nullptr)
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.
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.
TClass * IsA() const override
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.
TClass * IsA() const override
void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax) override
Save values of function in array fSave.
void SetRange(Double_t xmin, Double_t xmax) override
Initialize the upper and lower bounds to draw the function.
A 3-Dim function with parameters.
TClass * IsA() const override
void SetRange(Double_t xmin, Double_t xmax) override
Initialize the upper and lower bounds to draw the function.
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.
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 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 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.
TList * GetListOfPrimitives() const override
const char * GetName() const override
Returns name of object.
small helper class to store/restore gPad context in TPad methods
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