Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
simple.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_exp
3///
4/// \macro_code
5///
6/// \date 2015-03-22
7/// \warning This is part of the experimental API, which might change in the future. 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/RFit.hxx"
20#include "ROOT/RFile.hxx"
21
22void simple()
23{
24 using namespace ROOT::Experimental;
25
26 // Create a 2D histogram with an X axis with equidistant bins, and a y axis
27 // with irregular binning.
28 RAxisConfig xAxis(100, 0., 1.);
29 RAxisConfig yAxis({0., 1., 2., 3., 10.});
31
32 // Or the short in-place version:
33 // Create a 2D histogram with an X axis with equidistant bins, and a y axis
34 // with irregular binning.
35 RH2D hist({100, 0., 1.}, {{0., 1., 2., 3., 10.}});
36
37 // Fill weight 1. at the coordinate 0.01, 1.02.
38 hist.Fill({0.01, 1.02});
39
40 // Fit the histogram.
41 RFunction<2> func([](const std::array<double, 2> &x, const std::span<const double> par) {
42 return par[0] * x[0] * x[0] + (par[1] - x[1]) * x[1];
43 });
44
45 auto fitResult = FitTo(hist, func, {{0., 1.}});
46
47 auto file = RFile::Recreate("hist.root");
48 file->Write("TheHist", hist);
49}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Objects used to configure the different axis types.
Double_t x[n]
Definition legend1.C:17
RFitResult FitTo(const RHist< DIMENSIONS, PRECISION, STAT... > &hist, const RFunction< DIMENSIONS > &func, std::span< const double > paramInit)
Definition RFit.hxx:39