StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
staffEx17.C
1 {
2 // example of macro to read data from an ascii file and
3 // create a root file with an histogram and an ntuple.
4 // A'la the famous ROOT/PAW staff data example
5 // ( see PAW - Long write up,example 17, CERN, page33. )
6 
7  gROOT->Reset();
8  gSystem->Load("libTable");
9 
10 // Create ROOT file
11  TFileIter file("aptuple.root");
12  file = "Staff-data";
13  TGenericTable *allStaff = (TGenericTable *)(*file);
14  if (allStaff) {
15  // Create ROOT Browser
16  new TBrowser("staff",allStaff);
17 
18  // Create couple of the histograms
19  TCanvas *canva = new TCanvas("Staff","CERN Population",600,600);
20  canva->Divide(2,2);
21 
22 
23 // one can use 2 meta variable:
24 // n$ - the total number of the rows in the table
25 // i$ - stands for the current row index i = [0 -> (n$-1)]
26 
27  gStyle->SetHistFillColor(10);
28  gStyle->SetHistFillStyle(3013);
29  canva->cd(1);
30  allStaff->Draw("age");
31  canva->Update();
32 
33  canva->cd(2);
34  TH1F* h11 = new TH1F("h11","Age - User binning",45,20,65);
35  allStaff->Draw("age>>h11");
36  canva->Update();
37 
38  canva->cd(3);
39  allStaff->Draw("cost");
40  canva->Update();
41 
42  canva->cd(4);
43  TH1F* h12 = new TH1F("h12","Cost - User binning",50,0,20000);
44  allStaff->Draw("cost>>h12");
45  canva->Update();
46  }
47 }