StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
staffEx18.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 18, CERN, page35. )
6 
7  gROOT->Reset();
8  gSystem->Load("libTable");
9 
10 // Open ROOT file
11  TFileIter file("aptuple.root");
12 // Set the object name we want to get in
13  file = "Staff-data";
14 // Read the object in
15  TGenericTable *allStaff = (TGenericTable *)(*file);
16  if (allStaff) {
17  // Create ROOT Browser
18  new TBrowser("staff",allStaff);
19 
20  // Create couple of the histograms
21  TCanvas *canva = new TCanvas("Staff","CERN Population",600,600);
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 
30  TH1F* h200 = new TH1F("h200","Number of years at CERN",35,0,35);
31  h200->SetFillStyle(3013);
32  allStaff->Draw("service>>h200");
33  canva->Update();
34 
35  TH1F* h201 = new TH1F("h201","Number of years at CERN",35,0,35);
36  h201->SetXTitle("Years at CERN");
37  h201->SetYTitle("Number of staff");
38  h201->SetFillStyle(3044);
39  const int NATFR = 7;
40  allStaff->Draw("service>>h201","nation==NATFR","same");
41  canva->Update();
42 
43  const int DIVEP=5;
44  TH1F* h202 = new TH1F("h202","Number of years at CERN",35,0,35);
45  h202->SetFillStyle(1044);
46  h202->SetFillColor(kBlack);
47  allStaff->Draw("service>>h202","(nation==NATFR) && (division==DIVEP)","same");
48  canva->Update();
49  }
50 }