#include#include void fill_histogram(){ TH1D* hist = new TH1D("hist", "Example Histogram", 100, 0, 10); //create histogram with 100 bins from 0 to 10 TRandom3 rand; for(int i=0; i<10000; i++){ double data = rand.Gaus(5, 1); //generate data from a Gaussian distribution with mean of 5 and standard deviation of 1 hist->Fill(data); //fill histogram with generated data } hist->Draw(); //draw histogram }
#includeThe package/library used is ROOT.#include #include void fill_histogram(){ TH1D* hist = new TH1D("hist", "Example Histogram", 100, 0, 10); //create histogram with 100 bins from 0 to 10 TFile* file = new TFile("data.root", "READ"); //open input file "data.root" TTree* tree = (TTree*)file->Get("tree"); //get TTree "tree" from input file double data; tree->SetBranchAddress("variable", &data); //set address of variable to read from tree for(int i=0; i GetEntries(); i++){ tree->GetEntry(i); //read entry from tree and set value of "data" hist->Fill(data); //fill histogram with value of "data" } hist->Draw(); //draw histogram }