Hello World example for TH1.
Shows how to create, fill and write a histogram to a ROOT file.
void hist000_TH1_first()
{
auto outFile = std::unique_ptr<TFile>(
TFile::Open(
"outfile.root",
"RECREATE"));
int nBins = 30;
double rangeMin = 0.0;
double rangeMax = 10.0;
TH1D histogram(
"histogram",
"My first ROOT histogram", nBins, rangeMin, rangeMax);
const std::array values{1, 2, 3, 3, 3, 4, 3, 2, 1, 0};
for (double val : values) {
histogram.Fill(val);
}
outFile->WriteObject(&histogram, histogram.GetName());
}
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.
1-D histogram with a double per channel (see TH1 documentation)
- Date
- November 2024
- Author
- Giacomo Parolini (CERN)
Definition in file hist000_TH1_first.C.