Hands-on 7a Hints

First steps with ROOT, Histograms

Define an histogram in a macro - Hints

The graphical window is empty because histo is created with automatic memory allocation and it goes out of the scope after the function simple() is executed.

To fix this, histo has to be created with dynamic memory allocation:

void simple()
{
   TH1I* histo = new TH1I("Simple", "My simple histogram", 10, 0, 10);
   vector<int> numbers = {1,3,2,6,2,3,4,3,4,3,5};
   for (auto number : numbers) { histo->Fill(number); }
   histo->Draw();
}