ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
th2polyUSA.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// This tutorial illustrates how to create an histogram with polygonal
4 /// bins (TH2Poly), fill it and draw it using GL. The initial data are stored
5 /// in TMultiGraphs. They represent the USA.
6 ///
7 /// The initial data have been downloaded from: http://www.maproom.psu.edu/dcw/
8 /// This database was developed in 1991/1992 and national boundaries reflect
9 /// political reality as of that time.
10 ///
11 /// \macro_code
12 ///
13 /// \author Olivier Couet
14 
15 void th2polyUSA()
16 {
17  Int_t i, bin;
18  const Int_t nx = 48;
19  const char *states [nx] = {
20  "alabama", "arizona", "arkansas", "california",
21  "colorado", "connecticut", "delaware", "florida",
22  "georgia", "idaho", "illinois", "indiana",
23  "iowa", "kansas", "kentucky", "louisiana",
24  "maine", "maryland", "massachusetts", "michigan",
25  "minnesota", "mississippi", "missouri", "montana",
26  "nebraska", "nevada", "new_hampshire", "new_jersey",
27  "new_mexico", "new_york", "north_carolina", "north_dakota",
28  "ohio", "oklahoma", "oregon", "pennsylvania",
29  "rhode_island", "south_carolina", "south_dakota", "tennessee",
30  "texas", "utah", "vermont", "virginia",
31  "washington", "west_virginia", "wisconsin", "wyoming"
32  };
33  Double_t pop[nx] = {
34  4708708, 6595778, 2889450, 36961664, 5024748, 3518288, 885122, 18537969,
35  9829211, 1545801, 12910409, 6423113, 3007856, 2818747, 4314113, 4492076,
36  1318301, 5699478, 6593587, 9969727, 5266214, 2951996, 5987580, 974989,
37  1796619, 2643085, 1324575, 8707739, 2009671, 19541453, 9380884, 646844,
38  11542645, 3687050, 3825657, 12604767, 1053209, 4561242, 812383, 6296254,
39  24782302, 2784572, 621760, 7882590, 6664195, 1819777, 5654774, 544270
40  };
41 
43  TCanvas *usa = new TCanvas("USA", "USA");
44  usa->ToggleEventStatus();
45  Double_t lon1 = -130;
46  Double_t lon2 = -65;
47  Double_t lat1 = 24;
48  Double_t lat2 = 50;
49  TH2Poly *p = new TH2Poly("USA","USA Population",lon1,lon2,lat1,lat2);
50 
51  TFile *f;
52  f = TFile::Open("http://root.cern.ch/files/usa.root");
53 
54  if (!f) {
55  printf("Cannot access usa.root. Is internet working ?\n");
56  return;
57  }
58 
59  // Define the TH2Poly bins.
60  TMultiGraph *mg;
61  TKey *key;
62  TIter nextkey(gDirectory->GetListOfKeys());
63  while ((key = (TKey*)nextkey())) {
64  TObject *obj = key->ReadObj();
65  if (obj->InheritsFrom("TMultiGraph")) {
66  mg = (TMultiGraph*)obj;
67  bin = p->AddBin(mg);
68  }
69  }
70 
71  // Fill TH2Poly.
72  for (i=0; i<nx; i++) p->Fill(states[i], pop[i]);
73 
74  gStyle->SetOptStat(11);
75  gStyle->SetPalette(1);
76  p->Draw("legogl");
77 }
const int nx
Definition: kalman.C:16
virtual void ToggleEventStatus()
Toggle event statusbar.
Definition: TCanvas.cxx:2124
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition: TMultiGraph.h:37
int Int_t
Definition: RtypesCore.h:41
TFile * f
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3851
Int_t AddBin(TObject *poly)
Adds a new bin to the histogram.
Definition: TH2Poly.cxx:202
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:337
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Mother of all ROOT objects.
Definition: TObject.h:58
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:727
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1252
#define gDirectory
Definition: TDirectory.h:221
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1445
Int_t Fill(Double_t x, Double_t y)
Increment the bin containing (x,y) by 1.
Definition: TH2Poly.cxx:564
2D Histogram with Polygonal Bins
Definition: TH2Poly.h:70