Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
NormalizeHistogram.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Normalizing a Histogram

Image produced by .x NormalizeHistogram.C Two different methods of normalizing histograms are shown, each with the original histogram. next to the normalized one.

#include "TH2F.h"
#include "TRandom.h"
#include "TCanvas.h"
{
std::array<double, 6> binsx{0, 5, 10, 20, 50, 100};
TH1F *orig = new TH1F("orig", "Original histogram before normalization", binsx.size() - 1, &binsx[0]);
// Filling histogram with random entries
for (int i = 0; i < 100'000; ++i) {
double r = rand.Rndm() * 100;
orig->Fill(r);
}
TH1F *norm = (TH1F *)orig->Clone("norm");
norm->SetTitle("Normalized Histogram");
// Normalizing the Histogram by scaling by 1 / the integral and taking width into account
norm->Scale(1. / norm->Integral(), "width");
// Drawing everything
TCanvas *c1 = new TCanvas("c1", "Histogram Normalization", 700, 900);
c1->Divide(1, 2);
c1->cd(1);
orig->Draw();
c1->cd(2);
norm->Draw();
}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
Definition TRandom2.h:27
void SetTitleFontSize(Float_t size=0)
Definition TStyle.h:407
return c1
Definition legend1.C:41
Author
Advait Dhingra

Definition in file NormalizeHistogram.C.