The initial data are stored in TMultiGraphs. They represent the european countries. The histogram filling is done according to a Mercator projection, therefore the bin contains should be proportional to the real surface of the countries.
The script is shooting npoints (script argument) randomly over the Europe area. The number of points inside the countries should be proportional to the country surface The estimated surface is compared to the surfaces taken from wikipedia.
void hist040_TH2Poly_europe(
Int_t npoints = 500000)
{
const char *countries[nx] = {
"france", "spain", "sweden", "germany", "finland", "norway", "poland", "italy",
"yugoslavia", "united_kingdom", "romania", "belarus", "greece", "czechoslovakia", "bulgaria", "iceland",
"hungary", "portugal", "austria", "ireland", "lithuania", "latvia", "estonia", "denmark",
"netherlands", "switzerland", "moldova", "belgium", "albania", "cyprus", "luxembourg", "andorra",
"malta", "liechtenstein", "san_marino", "monaco"};
Float_t surfaces[nx] = {547030, 505580, 449964, 357021, 338145, 324220, 312685, 301230, 255438,
244820, 237500, 207600, 131940, 127711, 110910, 103000, 93030, 89242,
83870, 70280, 65200, 64589, 45226, 43094, 41526, 41290, 33843,
30528, 28748, 9250, 2586, 468, 316, 160, 61, 2};
TH1F *
h =
new TH1F(
"h",
"Countries surfaces (in km^{2})", 3, 0, 3);
for (i = 0; i < nx; i++)
h->Fill(countries[i], surfaces[i]);
f =
TFile::Open(
"http://root.cern/files/europe.root",
"cacheread");
printf("Cannot access europe.root. Is internet working ?\n");
return;
}
new TH2Poly(
"Europe",
"Europe (bin contents are normalized to the surfaces in km^{2})", lon1, lon2, lat1, lat2);
while ((key = (
TKey *)nextkey())) {
}
}
for (i = 0; i < npoints; i++) {
longitude =
r.Uniform(lon1, lon2);
latitude =
r.Uniform(lat1, lat2);
}
for (j = 0; j < nx; j++) {
for (i = 0; i < nbins; i++) {
}
}
}
for (i = 0; i < nbins; i++)
c1->SetRightMargin(0.047);
h->SetLineColor(
kRed - 3);
h->GetXaxis()->SetLabelFont(42);
h->GetXaxis()->SetLabelSize(0.03);
h->GetYaxis()->SetLabelFont(42);
for (i = 0; i < nx; i++)
leg->AddEntry(
h,
"Real countries surfaces from Wikipedia (in km^{2})",
"lp");
leg->AddEntry(h2,
"Countries surfaces from TH2Poly (with errors)",
"lp");
printf("THPoly Europe surface estimation error wrt wikipedia = %f per cent when using %d points\n", 100 * error,
npoints);
}
#define R(a, b, c, d, e, f, g, h, i)
int Int_t
Signed integer 4 bytes (int).
float Float_t
Float 4 bytes (float).
double Double_t
Double 8 bytes.
externTBenchmark * gBenchmark
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
virtual void ToggleEventStatus()
Toggle event statusbar.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
1-D histogram with a float per channel (see TH1 documentation)
void Reset(Option_t *option="") override
virtual Double_t Integral(Option_t *option="") const
virtual void Scale(Double_t c1=1, Option_t *option="")
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
virtual void SetContour(Int_t nlevels, const Double_t *levels=nullptr)
void Draw(Option_t *option="") override
Default Draw method for all objects.
virtual void SetBinError(Int_t bin, Double_t error)
virtual Int_t Fill(Double_t x)
virtual Double_t GetBinError(Int_t bin) const
2D Histogram with Polygonal Bins
Double_t GetBinContent(Int_t bin) const override
Returns the content of the input bin Bin numbers are from [1,nbins] and for the overflow/underflow/se...
Int_t Fill(Double_t x, Double_t y) override
Increment the bin containing (x,y) by 1.
Int_t GetNumberOfBins() const
Return the number of bins : it should be the size of the bin list.
void ChangePartition(Int_t n, Int_t m)
Changes the number of partition cells in the histogram.
const char * GetBinName(Int_t bin) const
Returns the bin name.
virtual Int_t AddBin(TObject *poly)
Adds a new bin to the histogram.
Double_t GetBinError(Int_t bin) const override
Returns the value of error associated to bin number bin.
void SetBinContent(Int_t bin, Double_t content) override
Sets the contents of the input bin to the input content Negative values between -1 and -9 are for the...
Double_t GetMaximum() const
Returns the maximum value of the histogram.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
virtual TObject * ReadObj()
To read a TObject* from the file.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Mother of all ROOT objects.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
void SetGridx(Int_t value=1) override
void SetGridy(Int_t value=1) override
This is the base class for the ROOT Random number generators.
Double_t Log(Double_t x)
Returns the natural logarithm of x.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Double_t Tan(Double_t)
Returns the tangent of an angle of x radians.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.