ROOT
master
Reference Guide
Loading...
Searching...
No Matches
hist001_TH1_fillrandom.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_hist
3
/// \notebook
4
/// Fill a 1D histogram with random values using predefined functions
5
///
6
/// \macro_image
7
/// \macro_code
8
///
9
/// \date November 2024
10
/// \author Giacomo Parolini
11
12
void
hist001_TH1_fillrandom
()
13
{
14
// Create a one dimensional histogram and fill it with a gaussian distribution
15
int
nBins = 200;
16
double
rangeMin
= 0.0;
17
double
rangeMax
= 10.0;
18
TH1D
h1d
(
"h1d"
,
"Test random numbers"
, nBins,
rangeMin
,
rangeMax
);
19
20
// "gaus" is a predefined ROOT function. Here we are filling the histogram with
21
// 10000 values sampled from that distribution.
22
h1d
.FillRandom(
"gaus"
, 10000);
23
24
// Open a ROOT file and save the histogram
25
auto
myfile
= std::unique_ptr<TFile>(
TFile::Open
(
"fillrandom.root"
,
"RECREATE"
));
26
myfile
->WriteObject(&
h1d
,
h1d
.GetName());
27
}
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TFile::Open
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition
TFile.cxx:4088
TH1D
1-D histogram with a double per channel (see TH1 documentation)
Definition
TH1.h:693
hist001_TH1_fillrandom
Definition
hist001_TH1_fillrandom.py:1
tutorials
hist
hist001_TH1_fillrandom.C
ROOT master - Reference Guide Generated on Fri Jan 24 2025 04:37:19 (GVA Time) using Doxygen 1.10.0