ROOT logo

From $ROOTSYS/tutorials/hist/th2polyUSA.C

//This tutorial illustrates how to create an histogram with polygonal
//bins (TH2Poly), fill it and draw it using GL. The initial data are stored
//in TMultiGraphs. They represent the USA.
//
//The initial data have been downloaded from: http://www.maproom.psu.edu/dcw/
//This database was developed in 1991/1992 and national boundaries reflect
//political reality as of that time.
//
//Author: Olivier Couet

void th2polyUSA()
{
   Int_t i, bin;
   const Int_t nx = 48;
   char *states [nx] = {
      "alabama",      "arizona",        "arkansas",       "california",
      "colorado",     "connecticut",    "delaware",       "florida",
      "georgia",      "idaho",          "illinois",       "indiana",
      "iowa",         "kansas",         "kentucky",       "louisiana",
      "maine",        "maryland",       "massachusetts",  "michigan",
      "minnesota",    "mississippi",    "missouri",       "montana",
      "nebraska",     "nevada",         "new_hampshire",  "new_jersey",
      "new_mexico",   "new_york",       "north_carolina", "north_dakota",
      "ohio",         "oklahoma",       "oregon",         "pennsylvania",
      "rhode_island", "south_carolina", "south_dakota",   "tennessee",
      "texas",        "utah",           "vermont",        "virginia",
      "washington",   "west_virginia",  "wisconsin",      "wyoming"
   };
   Float_t pop[nx] = {
    4708708, 6595778,  2889450, 36961664, 5024748,  3518288,  885122, 18537969,
    9829211, 1545801, 12910409,  6423113, 3007856,  2818747, 4314113,  4492076,
    1318301, 5699478,  6593587,  9969727, 5266214,  2951996, 5987580,   974989,
    1796619, 2643085,  1324575,  8707739, 2009671, 19541453, 9380884,   646844,
   11542645, 3687050,  3825657, 12604767, 1053209,  4561242,  812383,  6296254,
   24782302, 2784572,   621760,  7882590, 6664195,  1819777, 5654774,   544270
   };

   gStyle->SetCanvasPreferGL(true);
   TCanvas *usa = new TCanvas("USA", "USA");
   usa->ToggleEventStatus();
   Double_t lon1 = -130;
   Double_t lon2 = -65;
   Double_t lat1 = 24;
   Double_t lat2 = 50;
   TH2Poly *p = new TH2Poly("USA","USA Population",lon1,lon2,lat1,lat2);

   TFile *f;
   f = TFile::Open("http://root.cern.ch/files/usa.root");

   // Define the TH2Poly bins.
   TMultiGraph *mg;
   TKey *key;
   TIter nextkey(gDirectory->GetListOfKeys());
   while (key = (TKey*)nextkey()) {
      obj = key->ReadObj();
      if (obj->InheritsFrom("TMultiGraph")) {
         mg = (TMultiGraph*)obj;
         bin = p->AddBin(mg);
      }
   }

   // Fill TH2Poly.
   for (i=0; i<nx; i++) p->Fill(states[i], pop[i]);

   gStyle->SetOptStat(11);
   gStyle->SetPalette(1);
   p->Draw("gllego");
}
 th2polyUSA.C:1
 th2polyUSA.C:2
 th2polyUSA.C:3
 th2polyUSA.C:4
 th2polyUSA.C:5
 th2polyUSA.C:6
 th2polyUSA.C:7
 th2polyUSA.C:8
 th2polyUSA.C:9
 th2polyUSA.C:10
 th2polyUSA.C:11
 th2polyUSA.C:12
 th2polyUSA.C:13
 th2polyUSA.C:14
 th2polyUSA.C:15
 th2polyUSA.C:16
 th2polyUSA.C:17
 th2polyUSA.C:18
 th2polyUSA.C:19
 th2polyUSA.C:20
 th2polyUSA.C:21
 th2polyUSA.C:22
 th2polyUSA.C:23
 th2polyUSA.C:24
 th2polyUSA.C:25
 th2polyUSA.C:26
 th2polyUSA.C:27
 th2polyUSA.C:28
 th2polyUSA.C:29
 th2polyUSA.C:30
 th2polyUSA.C:31
 th2polyUSA.C:32
 th2polyUSA.C:33
 th2polyUSA.C:34
 th2polyUSA.C:35
 th2polyUSA.C:36
 th2polyUSA.C:37
 th2polyUSA.C:38
 th2polyUSA.C:39
 th2polyUSA.C:40
 th2polyUSA.C:41
 th2polyUSA.C:42
 th2polyUSA.C:43
 th2polyUSA.C:44
 th2polyUSA.C:45
 th2polyUSA.C:46
 th2polyUSA.C:47
 th2polyUSA.C:48
 th2polyUSA.C:49
 th2polyUSA.C:50
 th2polyUSA.C:51
 th2polyUSA.C:52
 th2polyUSA.C:53
 th2polyUSA.C:54
 th2polyUSA.C:55
 th2polyUSA.C:56
 th2polyUSA.C:57
 th2polyUSA.C:58
 th2polyUSA.C:59
 th2polyUSA.C:60
 th2polyUSA.C:61
 th2polyUSA.C:62
 th2polyUSA.C:63
 th2polyUSA.C:64
 th2polyUSA.C:65
 th2polyUSA.C:66
 th2polyUSA.C:67
 th2polyUSA.C:68
 th2polyUSA.C:69
thumb