Logo ROOT   6.10/09
Reference Guide
simple.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/THist.hxx"
19 #include "ROOT/TFit.hxx"
20 #include "ROOT/TFile.hxx"
21 
22 void simple() {
23  using namespace ROOT;
24 
25  // Create a 2D histogram with an X axis with equidistant bins, and a y axis
26  // with irregular binning.
27  Experimental::TAxisConfig xAxis(100, 0., 1.);
28  Experimental::TAxisConfig yAxis({0., 1., 2., 3.,10.});
29  Experimental::TH2D histFromVars(xAxis, yAxis);
30 
31  // Or the short in-place version:
32  // Create a 2D histogram with an X axis with equidistant bins, and a y axis
33  // with irregular binning.
34  Experimental::TH2D hist({100, 0., 1.}, {{0., 1., 2., 3.,10.}});
35 
36  // Fill weight 1. at the coordinate 0.01, 1.02.
37  hist.Fill({0.01, 1.02});
38 
39  // Fit the histogram.
40  Experimental::TFunction<2> func([](const std::array<double,2>& x,
41  const std::array_view<double>& par)
42  { return par[0]*x[0]*x[0] + (par[1]-x[1])*x[1]; });
43 
44  Experimental::TFitResult fitResult = Experimental::FitTo(hist, func, {{0., 1.}});
45 
47  file->Write("TheHist", hist);
48 }
double par[1]
Definition: unuranDistr.cxx:38
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Double_t x[n]
Definition: legend1.C:17
TFitResult FitTo(const THist< DIMENSIONS, PRECISION, STAT... > &hist, const TFunction< DIMENSIONS > &func, std::array_view< double > paramInit)
Definition: TFit.hxx:41
Objects used to configure the different axis types.
Definition: TAxis.hxx:311
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
Definition: THist.hxx:33
static TFilePtr Recreate(std::string_view name, const Options_t &opts=Options_t())
Open a file with name for reading and writing.
Definition: TFile.cxx:173
Points to an object that stores or reads objects in ROOT&#39;s binary format.
Definition: TFile.hxx:187
double func(double *x, double *p)
Definition: stressTF1.cxx:213
Definition: file.py:1
void Fill(const CoordArray_t &x, Weight_t weight=(Weight_t) 1) noexcept
Add weight to the bin containing coordinate x.
Definition: THist.hxx:152