void th2polyEurope(Int_t npoints=500000) { Int_t i,j; Double_t lon1 = -25; Double_t lon2 = 35; Double_t lat1 = 34; Double_t lat2 = 72; Double_t R = (lat2-lat1)/(lon2-lon1); Int_t W = 800; Int_t H = (Int_t)(R*800); gStyle->SetStatX(0.28); gStyle->SetStatY(0.45); gStyle->SetStatW(0.15); // Canvas used to draw TH2Poly (the map) TCanvas *ce = new TCanvas("ce", "ce",0,0,W,H); ce->ToggleEventStatus(); ce->SetGridx(); ce->SetGridy(); // Real surfaces taken from Wikipedia. const Int_t nx = 36; // see http://en.wikipedia.org/wiki/Area_and_population_of_European_countries 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]); h->LabelsDeflate(); TFile::SetCacheFileDir("."); TFile *f; f = TFile::Open("http://root.cern.ch/files/europe.root","cacheread"); if (!f) { printf("Cannot access europe.root. Is internet working ?\n"); return; } TH2Poly *p = new TH2Poly( "Europe", "Europe (bin contents are normalized to the surfaces in km^{2})", lon1,lon2,lat1,lat2); p->GetXaxis()->SetNdivisions(520); p->GetXaxis()->SetTitle("longitude"); p->GetYaxis()->SetTitle("latitude"); p->SetContour(100); TMultiGraph *mg; TKey *key; TIter nextkey(gDirectory->GetListOfKeys()); while ((key = (TKey*)nextkey())) { TObject *obj = key->ReadObj(); if (obj->InheritsFrom("TMultiGraph")) { mg = (TMultiGraph*)obj; p->AddBin(mg); } } TRandom r; Double_t longitude, latitude; Double_t x, y, pi4 = TMath::Pi()/4, alpha = TMath::Pi()/360; gBenchmark->Start("Partitioning"); p->ChangePartition(100, 100); gBenchmark->Show("Partitioning"); // Fill TH2Poly according to a Mercator projection. gBenchmark->Start("Filling"); for (i=0; i<npoints; i++) { longitude = r.Uniform(lon1,lon2); latitude = r.Uniform(lat1,lat2); x = longitude; y = 38*TMath::Log(TMath::Tan(pi4+alpha*latitude)); p->Fill(x,y); } gBenchmark->Show("Filling"); Int_t nbins = p->GetNumberOfBins(); Double_t maximum = p->GetMaximum(); // h2 contains the surfaces computed from TH2Poly. TH1F *h2 = (TH1F *)h->Clone("h2"); h2->Reset(); for (j=0; j<nx; j++) { for (i=0; i<nbins; i++) { if (strstr(countries[j],p->GetBinName(i+1))) { h2->Fill(countries[j],p->GetBinContent(i+1)); h2->SetBinError(j, p->GetBinError(i+1)); } } } // Normalize the TH2Poly bin contents to the real surfaces. Double_t scale = surfaces[0]/maximum; for (i=0; i<nbins; i++) p->SetBinContent(i+1, scale*p->GetBinContent(i+1)); gStyle->SetOptStat(1111); p->Draw("COLZ"); TCanvas *c1 = new TCanvas("c1", "c1",W+10,0,W-20,H); c1->SetRightMargin(0.047); scale = h->GetMaximum()/h2->GetMaximum(); h->SetStats(0); h->SetLineColor(kRed-3); h->SetLineWidth(2); h->SetMarkerStyle(20); h->SetMarkerColor(kBlue); h->SetMarkerSize(0.8); h->Draw("LP"); h->GetXaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.03); h->GetYaxis()->SetLabelFont(42); h2->Scale(scale); Double_t scale2=TMath::Sqrt(scale); for (i=0; i<nx; i++) h2->SetBinError(i+1, scale2*h2->GetBinError(i+1)); h2->Draw("E SAME"); h2->SetMarkerStyle(20); h2->SetMarkerSize(0.8); TLegend *leg = new TLegend(0.5,0.67,0.92,0.8,NULL,"NDC"); leg->SetTextFont(42); leg->SetTextSize(0.025); leg->AddEntry(h,"Real countries surfaces from Wikipedia (in km^{2})","lp"); leg->AddEntry(h2,"Countries surfaces from TH2Poly (with errors)","lp"); leg->Draw(); leg->Draw(); Double_t wikiSum = h->Integral(); Double_t polySum = h2->Integral(); Double_t error = TMath::Abs(wikiSum-polySum)/wikiSum; printf("THPoly Europe surface estimation error wrt wikipedia = %f per cent when using %d points\n",100*error,npoints); }
void plotScaleFactor(string label) { TFile *inf = new TFile(Form("data/ScaleFactors/RazorMADD2015/RazorScaleFactors_%s.root",label.c_str()),"READ"); inf->ls(); TH2Poly *ttbarNominal = (TH2Poly*)inf->Get("TTJetsScaleFactors"); TH2Poly *ttbarUp = (TH2Poly*)inf->Get("TTJetsScaleFactorsUp"); TH2Poly *ttbarDown = (TH2Poly*)inf->Get("TTJetsScaleFactorsDown"); TH2Poly *wNominal = (TH2Poly*)inf->Get("WJetsScaleFactors"); TH2Poly *wUp = (TH2Poly*)inf->Get("WJetsScaleFactorsUp"); TH2Poly *wDown = (TH2Poly*)inf->Get("WJetsScaleFactorsDown"); TH2Poly *wInvNominal = (TH2Poly*)inf->Get("WJetsInvScaleFactors"); TH2Poly *wInvUp = (TH2Poly*)inf->Get("WJetsInvScaleFactorsUp"); TH2Poly *wInvDown = (TH2Poly*)inf->Get("WJetsInvScaleFactorsDown"); TH2Poly *GJetInvNominal = (TH2Poly*)inf->Get("GJetsInvScaleFactors"); TCanvas *cv = 0; gStyle->SetPaintTextFormat("4.2f"); //**************************************************** //Plot GJetsInv Scale Factors //**************************************************** cv = new TCanvas("cv","cv", 800,600); cv->cd(); gStyle->SetPalette(53); GJetInvNominal->Draw("colztexte1"); cv->SetLogx(); cv->SetLogy(); cv->SetRightMargin(0.175); cv->SetBottomMargin(0.12); GJetInvNominal->GetXaxis()->SetRangeUser(400,4000); GJetInvNominal->GetYaxis()->SetRangeUser(0.25,1.5); GJetInvNominal->GetZaxis()->SetTitle("Data to MC Correction Factor"); GJetInvNominal->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]"); GJetInvNominal->GetYaxis()->SetTitle("R^{2}"); GJetInvNominal->SetTitle(""); GJetInvNominal->GetZaxis()->SetLabelSize(0.05); GJetInvNominal->GetZaxis()->SetTitleSize(0.05); GJetInvNominal->GetXaxis()->SetLabelSize(0.05); GJetInvNominal->GetXaxis()->SetTitleSize(0.05); GJetInvNominal->GetXaxis()->SetTitleOffset(0.8); GJetInvNominal->GetYaxis()->SetLabelSize(0.05); GJetInvNominal->GetYaxis()->SetTitleSize(0.05); GJetInvNominal->GetYaxis()->SetTitleOffset(0.8); GJetInvNominal->SetStats(false); GJetInvNominal->SetMaximum(1.8); GJetInvNominal->SetMinimum(0.35); lumi_13TeV = "35.9 fb^{-1}"; writeExtraText = true; relPosX = 0.13; lumiTextSize = 0.5; cmsTextSize = 0.6; extraOverCmsTextSize = 0.85; CMS_lumi(cv,4,0); cv->SaveAs(Form("GJetsInvScaleFactor_CorrectedToMultiJet_%s.png",label.c_str())); cv->SaveAs(Form("GJetsInvScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str())); TH2Poly *GJetInvUncertainties = (TH2Poly*)GJetInvNominal->Clone("GJetInvUncertainties"); for (int i=1; i<GJetInvUncertainties->GetNumberOfBins()+1; ++i) { GJetInvUncertainties->SetBinContent(i,100*GJetInvNominal->GetBinError(i) / GJetInvNominal->GetBinContent(i)); cout << i << " : " << GJetInvNominal->GetBinError(i) << " " << GJetInvNominal->GetBinContent(i) << " : " << GJetInvNominal->GetBinError(i) / GJetInvNominal->GetBinContent(i) << "\n"; } cv = new TCanvas("cv","cv", 800,600); gStyle->SetPalette(1); gStyle->SetPaintTextFormat("4.0f"); GJetInvUncertainties->Draw("colztext"); cv->SetLogx(); cv->SetLogy(); cv->SetRightMargin(0.175); cv->SetBottomMargin(0.12); GJetInvUncertainties->SetMarkerSize(2.0); GJetInvUncertainties->SetTitle(""); GJetInvUncertainties->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]"); GJetInvUncertainties->GetYaxis()->SetTitle("R^{2}"); GJetInvUncertainties->GetXaxis()->SetRangeUser(400,4000); GJetInvUncertainties->GetYaxis()->SetRangeUser(0.25,1.5); GJetInvUncertainties->GetZaxis()->SetTitle("Systematic Uncertainty (%)"); GJetInvUncertainties->GetZaxis()->SetLabelSize(0.05); GJetInvUncertainties->GetZaxis()->SetTitleSize(0.05); GJetInvUncertainties->GetXaxis()->SetLabelSize(0.05); GJetInvUncertainties->GetXaxis()->SetTitleSize(0.05); GJetInvUncertainties->GetXaxis()->SetTitleOffset(0.8); GJetInvUncertainties->GetYaxis()->SetLabelSize(0.05); GJetInvUncertainties->GetYaxis()->SetTitleSize(0.05); GJetInvUncertainties->GetYaxis()->SetTitleOffset(0.8); GJetInvUncertainties->SetStats(false); GJetInvUncertainties->SetMaximum(50); GJetInvUncertainties->SetMinimum(0.0); lumi_13TeV = "35.9 fb^{-1}"; writeExtraText = true; relPosX = 0.13; lumiTextSize = 0.5; cmsTextSize = 0.6; extraOverCmsTextSize = 0.85; CMS_lumi(cv,4,0); cv->SaveAs(Form("GJetsInvScaleFactorUncertainty_%s.png",label.c_str())); cv->SaveAs(Form("GJetsInvScaleFactorUncertainty_%s.pdf",label.c_str())); //**************************************************** //Plot WJetsInv Scale Factors //**************************************************** cv = new TCanvas("cv","cv", 800,600); gStyle->SetPalette(53); gStyle->SetPaintTextFormat("4.2f"); wInvNominal->Draw("colztexte1"); cv->SetLogx(); cv->SetLogy(); cv->SetRightMargin(0.175); cv->SetBottomMargin(0.12); wInvNominal->GetXaxis()->SetRangeUser(300,4000); wInvNominal->GetYaxis()->SetRangeUser(0.15,1.5); wInvNominal->GetZaxis()->SetTitle("Data to MC Correction Factor"); wInvNominal->GetZaxis()->SetLabelSize(0.05); wInvNominal->GetZaxis()->SetTitleSize(0.05); wInvNominal->GetXaxis()->SetLabelSize(0.05); wInvNominal->GetXaxis()->SetTitleSize(0.05); wInvNominal->GetXaxis()->SetTitleOffset(0.8); wInvNominal->GetYaxis()->SetLabelSize(0.05); wInvNominal->GetYaxis()->SetTitleSize(0.05); wInvNominal->GetYaxis()->SetTitleOffset(0.8); wInvNominal->SetStats(false); wInvNominal->SetMaximum(1.8); wInvNominal->SetMinimum(0.0); lumi_13TeV = "35.9 fb^{-1}"; writeExtraText = true; relPosX = 0.13; lumiTextSize = 0.5; cmsTextSize = 0.6; extraOverCmsTextSize = 0.85; CMS_lumi(cv,4,0); cv->SaveAs(Form("WJetsInvScaleFactor_CorrectedToMultiJet_%s.png",label.c_str())); cv->SaveAs(Form("WJetsInvScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str())); //**************************************************** //Plot WJets Scale Factors //**************************************************** cv = new TCanvas("cv","cv", 800,600); gStyle->SetPalette(53); wNominal->Draw("colztexte1"); cv->SetLogx(); cv->SetLogy(); cv->SetRightMargin(0.175); cv->SetBottomMargin(0.12); wNominal->GetXaxis()->SetRangeUser(300,4000); wNominal->GetYaxis()->SetRangeUser(0.15,1.5); wNominal->GetZaxis()->SetTitle("Data to MC Correction Factor"); wNominal->GetZaxis()->SetLabelSize(0.05); wNominal->GetZaxis()->SetTitleSize(0.05); wNominal->GetXaxis()->SetLabelSize(0.05); wNominal->GetXaxis()->SetTitleSize(0.05); wNominal->GetXaxis()->SetTitleOffset(0.8); wNominal->GetYaxis()->SetLabelSize(0.05); wNominal->GetYaxis()->SetTitleSize(0.05); wNominal->GetYaxis()->SetTitleOffset(0.8); wNominal->SetStats(false); wNominal->SetMaximum(1.8); wNominal->SetMinimum(0.35); lumi_13TeV = "35.9 fb^{-1}"; writeExtraText = true; relPosX = 0.13; lumiTextSize = 0.5; cmsTextSize = 0.6; extraOverCmsTextSize = 0.85; CMS_lumi(cv,4,0); cv->SaveAs(Form("WJetsScaleFactor_CorrectedToMultiJet_%s.png",label.c_str())); cv->SaveAs(Form("WJetsScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str())); TH2Poly *WJetsUncertainties = (TH2Poly*)wNominal->Clone("WJetsUncertainties"); for (int i=1; i<WJetsUncertainties->GetNumberOfBins()+1; ++i) { WJetsUncertainties->SetBinContent(i,100*wNominal->GetBinError(i) / wNominal->GetBinContent(i)); } cv = new TCanvas("cv","cv", 800,600); gStyle->SetPalette(1); gStyle->SetPaintTextFormat("4.0f"); WJetsUncertainties->Draw("colztext"); cv->SetLogx(); cv->SetLogy(); cv->SetRightMargin(0.175); cv->SetBottomMargin(0.12); WJetsUncertainties->SetMarkerSize(2.0); WJetsUncertainties->SetTitle(""); WJetsUncertainties->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]"); WJetsUncertainties->GetYaxis()->SetTitle("R^{2}"); WJetsUncertainties->GetXaxis()->SetRangeUser(300,4000); WJetsUncertainties->GetYaxis()->SetRangeUser(0.15,1.5); WJetsUncertainties->GetZaxis()->SetTitle("Systematic Uncertainty (%)"); WJetsUncertainties->GetZaxis()->SetLabelSize(0.05); WJetsUncertainties->GetZaxis()->SetTitleSize(0.05); WJetsUncertainties->GetXaxis()->SetLabelSize(0.05); WJetsUncertainties->GetXaxis()->SetTitleSize(0.05); WJetsUncertainties->GetXaxis()->SetTitleOffset(0.8); WJetsUncertainties->GetYaxis()->SetLabelSize(0.05); WJetsUncertainties->GetYaxis()->SetTitleSize(0.05); WJetsUncertainties->GetYaxis()->SetTitleOffset(0.8); WJetsUncertainties->SetStats(false); WJetsUncertainties->SetMaximum(50); WJetsUncertainties->SetMinimum(0.0); lumi_13TeV = "35.9 fb^{-1}"; writeExtraText = true; relPosX = 0.13; lumiTextSize = 0.5; cmsTextSize = 0.6; extraOverCmsTextSize = 0.85; CMS_lumi(cv,4,0); cv->SaveAs(Form("WJetsScaleFactorUncertainty_%s.png",label.c_str())); cv->SaveAs(Form("WJetsScaleFactorUncertainty_%s.pdf",label.c_str())); //**************************************************** //Plot TTBar Scale Factors //**************************************************** cv = new TCanvas("cv","cv", 800,600); gStyle->SetPalette(53); gStyle->SetPaintTextFormat("4.2f"); ttbarNominal->Draw("colztexte1"); cv->SetLogx(); cv->SetLogy(); cv->SetRightMargin(0.175); cv->SetBottomMargin(0.12); ttbarNominal->GetXaxis()->SetRangeUser(400,4000); ttbarNominal->GetYaxis()->SetRangeUser(0.25,1.5); ttbarNominal->GetZaxis()->SetTitle("Data to MC Correction Factor"); ttbarNominal->GetZaxis()->SetLabelSize(0.05); ttbarNominal->GetZaxis()->SetTitleSize(0.05); ttbarNominal->GetXaxis()->SetLabelSize(0.05); ttbarNominal->GetXaxis()->SetTitleSize(0.05); ttbarNominal->GetXaxis()->SetTitleOffset(0.8); ttbarNominal->GetYaxis()->SetLabelSize(0.05); ttbarNominal->GetYaxis()->SetTitleSize(0.05); ttbarNominal->GetYaxis()->SetTitleOffset(0.8); ttbarNominal->SetStats(false); // ttbarNominal->SetMaximum(10000); // ttbarNominal->SetMinimum(0.0); ttbarNominal->SetMaximum(1.8); ttbarNominal->SetMinimum(0.35); lumi_13TeV = "35.9 fb^{-1}"; writeExtraText = true; relPosX = 0.13; lumiTextSize = 0.5; cmsTextSize = 0.6; extraOverCmsTextSize = 0.85; CMS_lumi(cv,4,0); cv->SaveAs(Form("TTBarScaleFactor_CorrectedToMultiJet_%s.png",label.c_str())); cv->SaveAs(Form("TTBarScaleFactor_CorrectedToMultiJet_%s.pdf",label.c_str())); TH2Poly *TTBarUncertainties = (TH2Poly*)ttbarNominal->Clone("TTBarUncertainties"); for (int i=1; i<TTBarUncertainties->GetNumberOfBins()+1; ++i) { TTBarUncertainties->SetBinContent(i,100*ttbarNominal->GetBinError(i) / ttbarNominal->GetBinContent(i)); } cv = new TCanvas("cv","cv", 800,600); gStyle->SetPalette(1); gStyle->SetPaintTextFormat("4.0f"); TTBarUncertainties->Draw("colztext"); cv->SetLogx(); cv->SetLogy(); cv->SetRightMargin(0.175); cv->SetBottomMargin(0.12); TTBarUncertainties->SetMarkerSize(2.0); TTBarUncertainties->SetTitle(""); TTBarUncertainties->GetXaxis()->SetTitle("M_{R} [GeV/c^{2}]"); TTBarUncertainties->GetYaxis()->SetTitle("R^{2}"); TTBarUncertainties->GetXaxis()->SetRangeUser(300,4000); TTBarUncertainties->GetYaxis()->SetRangeUser(0.15,1.5); TTBarUncertainties->GetZaxis()->SetTitle("Systematic Uncertainty (%)"); TTBarUncertainties->GetZaxis()->SetLabelSize(0.05); TTBarUncertainties->GetZaxis()->SetTitleSize(0.05); TTBarUncertainties->GetXaxis()->SetLabelSize(0.05); TTBarUncertainties->GetXaxis()->SetTitleSize(0.05); TTBarUncertainties->GetXaxis()->SetTitleOffset(0.8); TTBarUncertainties->GetYaxis()->SetLabelSize(0.05); TTBarUncertainties->GetYaxis()->SetTitleSize(0.05); TTBarUncertainties->GetYaxis()->SetTitleOffset(0.8); TTBarUncertainties->SetStats(false); TTBarUncertainties->SetMaximum(50); TTBarUncertainties->SetMinimum(0.0); lumi_13TeV = "35.9 fb^{-1}"; writeExtraText = true; relPosX = 0.13; lumiTextSize = 0.5; cmsTextSize = 0.6; extraOverCmsTextSize = 0.85; CMS_lumi(cv,4,0); cv->SaveAs(Form("TTBarScaleFactorUncertainty_%s.png",label.c_str())); cv->SaveAs(Form("TTBarScaleFactorUncertainty_%s.pdf",label.c_str())); }