2.5.1. Histogram

The histogram is present in ROOT but it needs to be encapsulated when the user wants to choose an automatic method determining the number of bins. By default, the number of bins is given in the variable of the configuration file of ROOT .rootrc of the directory $ROOTSYS/etc. This information can be overloaded by an user file .rootrc in its home directory ($HOME), or in a local file where ROOT is executed. Several methods exist to determine the number of “bins” according to the characteristics of the variable to be visualised.

Again we consider the TDataServer built from the geyser.dat file, to which we add the attribute xnorm, then the histograms will be plotted using the different methods of this new attribute.

    TCanvas *c2 = new TCanvas();
    TPad *apad = new TPad("apad","apad",0, 0.03, 1, 1);

    TDataServer * tdsGeyser = new TDataServer("tdsgeyser", "Database of the geyser");
    tdsGeyser->fileDataRead("geyser.dat");
    tdsGeyser->addAttribute("xnorm", "sqrt(x1*x1+x2*x2)");

    apad->Divide(2,2);

    apad->cd(1); tdsGeyser->draw("xnorm","","nclass=root");
    apad->cd(2); tdsGeyser->draw("xnorm","","nclass=sturges");
    apad->cd(3); tdsGeyser->draw("xnorm","","nclass=fd");
    apad->cd(4); tdsGeyser->draw("xnorm","","nclass=scott");

../../_images/geyser_histograms.png

Figure 2.42 Different histograms of the same attribute xnorm depending on the method for computing bins. The values are respectively 100(root), 8 from sturges, 7 from fd and scoot.