Logo ROOT   6.14/05
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
8 /// is welcome!
9 /// \author Axel Naumann <axel@cern.ch>
10 
11 /*************************************************************************
12  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
13  * All rights reserved. *
14  * *
15  * For the licensing terms see $ROOTSYS/LICENSE. *
16  * For the list of contributors see $ROOTSYS/README/CREDITS. *
17  *************************************************************************/
18 
19 #include "ROOT/THist.hxx"
20 #include "ROOT/TFit.hxx"
21 #include "ROOT/TFile.hxx"
22 
23 void simple()
24 {
25  using namespace ROOT;
26 
27  // Create a 2D histogram with an X axis with equidistant bins, and a y axis
28  // with irregular binning.
29  Experimental::TAxisConfig xAxis(100, 0., 1.);
30  Experimental::TAxisConfig yAxis({0., 1., 2., 3., 10.});
31  Experimental::TH2D histFromVars(xAxis, yAxis);
32 
33  // Or the short in-place version:
34  // Create a 2D histogram with an X axis with equidistant bins, and a y axis
35  // with irregular binning.
36  Experimental::TH2D hist({100, 0., 1.}, {{0., 1., 2., 3., 10.}});
37 
38  // Fill weight 1. at the coordinate 0.01, 1.02.
39  hist.Fill({0.01, 1.02});
40 
41  // Fit the histogram.
42  Experimental::TFunction<2> func([](const std::array<double, 2> &x, const std::span<double> par) {
43  return par[0] * x[0] * x[0] + (par[1] - x[1]) * x[1];
44  });
45 
46  Experimental::TFitResult fitResult = Experimental::FitTo(hist, func, {{0., 1.}});
47 
49  file->Write("TheHist", hist);
50 }
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TFitResult FitTo(const THist< DIMENSIONS, PRECISION, STAT... > &hist, const TFunction< DIMENSIONS > &func, std::span< double > paramInit)
Definition: TFit.hxx:39
Double_t x[n]
Definition: legend1.C:17
Objects used to configure the different axis types.
Definition: TAxis.hxx:300
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:171
Points to an object that stores or reads objects in ROOT&#39;s binary format.
Definition: TFile.hxx:186
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:138