TH1D Draw is a method in the ROOT data analysis framework's Hist package library, designed to draw histograms using C++ programming language. The TH1D Draw method uses a TCanvas object to create a graphical output display and TH1D object to store and manipulate data for a 1D histogram.
Example 1: Drawing a Basic Histogram // Load the ROOT library #include "TH1D.h" #include "TCanvas.h"
void TH1D_Demo() { // Create a TH1D object with 10 bins, a minimum value of 0, and a maximum value of 100. TH1D* h = new TH1D("histogram", "My Example Histogram; X-axis; Frequency", 10, 0, 100);
// Fill the histogram with random data. for (Int_t i = 0; i < 1000; ++i) { h->Fill(gRandom->Gaus(50, 10)); }
// Create a TCanvas object and draw the histogram. TCanvas* c = new TCanvas("canvas", "My Example Histogram"); h->Draw();
// Update the canvas. c->Update(); }
This example shows how to create a basic histogram with randomly generated data using TH1D Draw. The histogram is displayed using a TCanvas object.
Example 2: Customizing Histogram Options // Load the ROOT library #include "TH1D.h" #include "TCanvas.h"
void TH1D_Demo2() { // Create a TH1D object with 10 bins, a minimum value of 0, and a maximum value of 100. TH1D* h = new TH1D("histogram", "My Example Histogram; X-axis; Frequency", 10, 0, 100);
// Fill the histogram with random data. for (Int_t i = 0; i < 1000; ++i) { h->Fill(gRandom->Gaus(50, 10)); }
// Create a TCanvas object and set its properties. TCanvas* c = new TCanvas("canvas", "My Example Histogram", 800, 600); c->SetGrid();
This example shows how to customize options for the histogram and the TCanvas object. Customizations include changing the color of the histogram, adding a grid to the TCanvas, and adjusting the size of the axis labels.
C++ (Cpp) TH1D::Draw - 30 examples found. These are the top rated real world C++ (Cpp) examples of TH1D::Draw extracted from open source projects. You can rate examples to help us improve the quality of examples.