Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist001_TH1_fillrandom.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Fill a 1D histogram with random values using predefined functions

{
// Create a one dimensional histogram and fill it with a gaussian distribution
int nBins = 200;
double rangeMin = 0.0;
double rangeMax = 10.0;
TH1D h1d("h1d", "Test random numbers", nBins, rangeMin, rangeMax);
// "gaus" is a predefined ROOT function. Here we are filling the histogram with
// 10000 values sampled from that distribution.
h1d.FillRandom("gaus", 10000);
// Open a ROOT file and save the histogram
auto myfile = std::unique_ptr<TFile>(TFile::Open("fillrandom.root", "RECREATE"));
myfile->WriteObject(&h1d, h1d.GetName());
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:693
Date
November 2024
Author
Giacomo Parolini

Definition in file hist001_TH1_fillrandom.C.