th2polyUSA.C

Go to the documentation of this file.
00001 //This tutorial illustrates how to create an histogram with polygonal
00002 //bins (TH2Poly), fill it and draw it using GL. The initial data are stored
00003 //in TMultiGraphs. They represent the USA.
00004 //
00005 //The initial data have been downloaded from: http://www.maproom.psu.edu/dcw/
00006 //This database was developed in 1991/1992 and national boundaries reflect
00007 //political reality as of that time.
00008 //
00009 //Author: Olivier Couet
00010 
00011 void th2polyUSA()
00012 {
00013    Int_t i, bin;
00014    const Int_t nx = 48;
00015    char *states [nx] = {
00016       "alabama",      "arizona",        "arkansas",       "california",
00017       "colorado",     "connecticut",    "delaware",       "florida",
00018       "georgia",      "idaho",          "illinois",       "indiana",
00019       "iowa",         "kansas",         "kentucky",       "louisiana",
00020       "maine",        "maryland",       "massachusetts",  "michigan",
00021       "minnesota",    "mississippi",    "missouri",       "montana",
00022       "nebraska",     "nevada",         "new_hampshire",  "new_jersey",
00023       "new_mexico",   "new_york",       "north_carolina", "north_dakota",
00024       "ohio",         "oklahoma",       "oregon",         "pennsylvania",
00025       "rhode_island", "south_carolina", "south_dakota",   "tennessee",
00026       "texas",        "utah",           "vermont",        "virginia",
00027       "washington",   "west_virginia",  "wisconsin",      "wyoming"
00028    };
00029    Float_t pop[nx] = {
00030     4708708, 6595778,  2889450, 36961664, 5024748,  3518288,  885122, 18537969,
00031     9829211, 1545801, 12910409,  6423113, 3007856,  2818747, 4314113,  4492076,
00032     1318301, 5699478,  6593587,  9969727, 5266214,  2951996, 5987580,   974989,
00033     1796619, 2643085,  1324575,  8707739, 2009671, 19541453, 9380884,   646844,
00034    11542645, 3687050,  3825657, 12604767, 1053209,  4561242,  812383,  6296254,
00035    24782302, 2784572,   621760,  7882590, 6664195,  1819777, 5654774,   544270
00036    };
00037 
00038    gStyle->SetCanvasPreferGL(true);
00039    TCanvas *usa = new TCanvas("USA", "USA");
00040    usa->ToggleEventStatus();
00041    Double_t lon1 = -130;
00042    Double_t lon2 = -65;
00043    Double_t lat1 = 24;
00044    Double_t lat2 = 50;
00045    TH2Poly *p = new TH2Poly("USA","USA Population",lon1,lon2,lat1,lat2);
00046 
00047    TFile *f;
00048    f = TFile::Open("http://root.cern.ch/files/usa.root");
00049 
00050    // Define the TH2Poly bins.
00051    TMultiGraph *mg;
00052    TKey *key;
00053    TIter nextkey(gDirectory->GetListOfKeys());
00054    while (key = (TKey*)nextkey()) {
00055       obj = key->ReadObj();
00056       if (obj->InheritsFrom("TMultiGraph")) {
00057          mg = (TMultiGraph*)obj;
00058          bin = p->AddBin(mg);
00059       }
00060    }
00061 
00062    // Fill TH2Poly.
00063    for (i=0; i<nx; i++) p->Fill(states[i], pop[i]);
00064 
00065    gStyle->SetOptStat(11);
00066    gStyle->SetPalette(1);
00067    p->Draw("gllego");
00068 }

Generated on Tue Jul 5 15:44:30 2011 for ROOT_528-00b_version by  doxygen 1.5.1