Logo ROOT   6.16/01
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#include "ROOT/RHist.hxx"
19#include "ROOT/RCanvas.hxx"
20#include "ROOT/RFitPanel.hxx"
21#include "ROOT/TDirectory.hxx"
22
23void fitpanel0() {
24
25 using namespace ROOT::Experimental;
26
27 // Create the histogram.
28 RAxisConfig xaxis(10, 0., 10.);
29 auto pHist = std::make_shared<RH1D>(xaxis);
30
31 // Fill a few points.
32 pHist->Fill(1);
33 pHist->Fill(2);
34 pHist->Fill(2);
35 pHist->Fill(3);
36
37
38 auto panel = std::make_shared<RFitPanel>("FitPanel Title");
39 panel->Show();
40
41 // Register the histogram with ROOT: now it lives even after draw() ends.
42 ROOT::Experimental::TDirectory::Heap().Add("fitpanel", panel);
43
44
45 // Create a canvas to be displayed.
46 // auto canvas = Experimental::RCanvas::Create("Canvas Title");
47 // canvas->Draw(pHist)->SetLineColor(Experimental::TColor::kRed);
48 // canvas->Draw(pHist2)->SetLineColor(Experimental::TColor::kBlue);
49
50 // canvas->Show();
51}
52
53void fitpanel() {
54
55 using namespace ROOT::Experimental;
56
57 // TODO - also keep axis correctly in the help
58 auto xaxis = std::make_shared<RAxisConfig>(10, 0., 10.);
59 // Create the histogram.
60 auto pHist = std::make_shared<RH1D>(*xaxis.get());
61
62 // Fill a few points.
63 pHist->Fill(1);
64 pHist->Fill(2);
65 pHist->Fill(2);
66 pHist->Fill(3);
67
68 auto canvas = RCanvas::Create("Canvas Title");
69 canvas->Draw(pHist)->SetLineColor(RColor::kRed);
70
71 canvas->Show();
72 canvas->Update(); // need to ensure canvas is drawn
73
74 auto panel = std::make_shared<RFitPanel>("FitPanel Title");
75
76 ROOT::Experimental::TDirectory::Heap().Add("fitpanel", panel);
77 ROOT::Experimental::TDirectory::Heap().Add("firsthisto", pHist);
78 ROOT::Experimental::TDirectory::Heap().Add("firstaxis", xaxis);
79
80 // TODO: how combine there methods together
81 // here std::shread_ptr<> on both sides
82
83 panel->UseCanvas(canvas);
84
85 canvas->AddPanel(panel);
86}
87
@ kRed
Definition: Rtypes.h:63
Objects used to configure the different axis types.
Definition: RAxis.hxx:300
static TDirectory & Heap()
Dedicated, process-wide TDirectory.
Definition: TFile.cxx:23
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