Logo ROOT   6.14/05
Reference Guide
fitpanel.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// \macro_code
5 ///
6 /// \date 2015-03-22
7 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
8 /// \author Axel Naumann <axel@cern.ch>
9 
10 /*************************************************************************
11  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
12  * All rights reserved. *
13  * *
14  * For the licensing terms see $ROOTSYS/LICENSE. *
15  * For the list of contributors see $ROOTSYS/README/CREDITS. *
16  *************************************************************************/
17 
18 R__LOAD_LIBRARY(libGpad);
19 
20 #include "ROOT/THist.hxx"
21 #include "ROOT/TCanvas.hxx"
22 #include "ROOT/TFitPanel.hxx"
23 #include "ROOT/TDirectory.hxx"
24 
25 
26 void fitpanel0() {
27  using namespace ROOT;
28 
29  // Create the histogram.
30  Experimental::TAxisConfig xaxis(10, 0., 10.);
31  auto pHist = std::make_shared<Experimental::TH1D>(xaxis);
32 
33  // Fill a few points.
34  pHist->Fill(1);
35  pHist->Fill(2);
36  pHist->Fill(2);
37  pHist->Fill(3);
38 
39 
40  auto panel = std::make_shared<ROOT::Experimental::TFitPanel>("FitPanel Title");
41  panel->Show();
42 
43  // Register the histogram with ROOT: now it lives even after draw() ends.
44  Experimental::TDirectory::Heap().Add("fitpanel", panel);
45 
46 
47  // Create a canvas to be displayed.
48  // auto canvas = Experimental::TCanvas::Create("Canvas Title");
49  // canvas->Draw(pHist)->SetLineColor(Experimental::TColor::kRed);
50  // canvas->Draw(pHist2)->SetLineColor(Experimental::TColor::kBlue);
51 
52  // canvas->Show();
53 }
54 
55 void fitpanel() {
56 
57  using namespace ROOT;
58 
59  // TODO - also keep axis correctly in the help
60  auto xaxis = std::make_shared<Experimental::TAxisConfig>(10, 0., 10.);
61  // Create the histogram.
62  auto pHist = std::make_shared<Experimental::TH1D>(*xaxis.get());
63 
64  // Fill a few points.
65  pHist->Fill(1);
66  pHist->Fill(2);
67  pHist->Fill(2);
68  pHist->Fill(3);
69 
70  auto canvas = Experimental::TCanvas::Create("Canvas Title");
71  canvas->Draw(pHist)->SetLineColor(Experimental::TColor::kRed);
72 
73  canvas->Show();
74  canvas->Update(); // need to ensure canvas is drawn
75 
76  auto panel = std::make_shared<ROOT::Experimental::TFitPanel>("FitPanel Title");
77 
78  Experimental::TDirectory::Heap().Add("fitpanel", panel);
79  Experimental::TDirectory::Heap().Add("firsthisto", pHist);
80  Experimental::TDirectory::Heap().Add("firstaxis", xaxis);
81 
82  // TODO: how combine there methods together
83  // here std::shread_ptr<> on both sides
84 
85  panel->UseCanvas(canvas);
86 
87  canvas->AddPanel(panel);
88 }
89 
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Definition: Rtypes.h:59
void Add(std::string_view name, const std::shared_ptr< T > &ptr)
Add an existing object (rather a shared_ptr to it) to the TDirectory.
Definition: TDirectory.hxx:172
static TDirectory & Heap()
Dedicated, process-wide TDirectory.
Definition: TFile.cxx:23
Objects used to configure the different axis types.
Definition: TAxis.hxx:300
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:467
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:74