Dear rooters,
I have some problems with superimposing two TH2D histograms with different set palette in the same pad. I tried the “same” option but then the first histogram is colored with the same color of the second.
#include <iostream>
#include <fstream>
#include "stdio.h"
#include "TString.h"
#include "TStyle.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TF1.h"
#include "TArrow.h"
#include "TPad.h"
#include "TCanvas.h"
#include "TTree.h"
#include "TFile.h"
#include "TGraphErrors.h"
#include "TFitResult.h"
#include "TMath.h"
#include "TAxis.h"
#include "TROOT.h"
#include "TObjArray.h"
#include "TObject.h"
#include "TLatex.h"
using namespace std;
double function1(double omegab=.022,double Neff=3.016) {
double abund=0.;
double a[4][5] = {
{14.892, -1551.6, 70488., -1.5390e6, 1.3163e7},
{6.1889, -916.16, 56639., -1.6046e6, 1.7152e7},
{-.60319, 118.51, -8556.3, 267581., -3.0624e6},
{4.5346e-2, -8.7506, 624.51, -19402., 221200.}};
int i,k;
abund=0.;
for (i=0;i<4;i++) { for (k=0;k<5;k++) {
abund += a[i][k]*TMath::Power(omegab,(double)k)*TMath::Power(Neff,(double)i);
} }
return abund;
}
double function2(double omegab=.022,double Neff=3.016) {
double abund=0.;
double a[4][5] = {
{3.1821, -298.88, 15974., -422531., 4.4031e6},
{.57549, -91.210, 6376.7, -201070., 2.3485e6},
{-.15717, 33.689, -2651.2, 89571., -1.0998e6},
{1.4594e-2, -3.2160, 256.66, -8780.2, 109100.}};
int i,k;
abund=0.;
for (i=0;i<4;i++) { for (k=0;k<5;k++) {
abund += a[i][k]*TMath::Power(omegab,(double)k)*TMath::Power(Neff,(double)i);
} }
return abund;
}
double function3(double omegab=.021,double Neff=3.017) {
double abund=0.;
double a[4][6] = {
{.24307, -14.242, 1418.4, -65853., 1.4856e6, -1.3142e7},
{-3.6433e-2, 14.336, -1375.0, 64741., -1.4966e6, 1.3601e7},
{1.6132e-2, -4.5188, 444.13, -21353., 502610., -4.6405e6 },
{-1.6279e-3, .43352, -42.850, 2069.4, -48890., 452740.}};
int i,k;
abund=0.;
for (i=0;i<4;i++) { for (k=0;k<6;k++) {
abund +=a[i][k]*TMath::Power(omegab,(double)k)*TMath::Power(Neff,(double)i);
} }
return abund;
}
void prova(TString inputpath = "Co60_FCch0_cen.root") {
double omegab=0.,Neff=0.;
int i,j,k;
TCanvas *c0 = new TCanvas("c0","c0",200,200,1200,600);
c0->Divide(2,1);
TCanvas *c1 = new TCanvas("c1","c1",200,200,1200,600);
c1->Divide(2,1);
TCanvas *c2 = new TCanvas("c2","c2",200,200,1200,600);
c2->Divide(2,1);
TCanvas *c3 = new TCanvas("c3","c3",200,200,1200,600);
c3->Divide(2,1);
gStyle->SetOptStat(0);
gStyle->SetOptFit(0);
gStyle->SetStripDecimals(kFALSE);
TH2D *h11 = new TH2D("h11", "1;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
TH2D *h12 = new TH2D("h12"," original;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
TH2D *h13 = new TH2D("h13","#times 1.1;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
for (i=1;i<=h11->GetXaxis()->GetNbins();i++) {
for (k=1;k<=h11->GetYaxis()->GetNbins();k++) {
omegab = h11->GetXaxis()->GetBinCenter(i);
Neff = h11->GetYaxis()->GetBinCenter(k);
h11 ->SetBinContent(i,k,function1(omegab,Neff));
h12 ->SetBinContent(i,k,TMath::Abs(function1(omegab,Neff)-2.52));
h13->SetBinContent(i,k,TMath::Abs((function1(omegab,Neff)*TMath::Power(1.1,-0.32))-2.52));
}
}
c0->cd(1);
// histoCookeD->Draw("colz");
Double_t contours[4];
contours[0] = 0.00;
contours[1] = 0.04;
contours[2] = 0.08;
contours[3] = 2.;
int colorsBlue [3] = {kBlue, kBlue-10, 0};
gStyle->SetPalette(3,colorsBlue);
h12->SetContour(4, contours);
h12->Draw("CONT4");
gPad->Update();
c0->Update();
c0->cd(2);
h13->SetContour(4, contours);
h13->Draw("CONT4");
c0->Print("Histogram1i.pdf");
// Compute histogram contents.
TH2D *h21 = new TH2D("h21", "1;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
TH2D *h22 = new TH2D("h22","^{3}He original;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
TH2D *h23 = new TH2D("h23","^{3}He #times 1.1;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
for (i=1;i<=h21->GetXaxis()->GetNbins();i++) {
for (k=1;k<=h21->GetYaxis()->GetNbins();k++) {
omegab = h21->GetXaxis()->GetBinCenter(i);
Neff = h21->GetYaxis()->GetBinCenter(k);
h21 ->SetBinContent(i,k,function2(omegab,Neff));
h22 ->SetBinContent(i,k,TMath::Abs(function2(omegab,Neff)-1.01));
h23->SetBinContent(i,k,TMath::Abs((function2(omegab,Neff)*TMath::Power(1.1,-0.37))-1.01));
}
}
// ratio of two functions
TH2D *h31 = new TH2D("h31", "h;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
TH2D *h32 = new TH2D("h32"," ;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
for (i=1;i<=h31->GetXaxis()->GetNbins();i++) {
for (k=1;k<=h31->GetYaxis()->GetNbins();k++) {
omegab = h31->GetXaxis()->GetBinCenter(i);
Neff = h31->GetYaxis()->GetBinCenter(k);
h31 ->SetBinContent(i,k,((function3(omegab,Neff))*1.0078/(4.003*(1-function3(omegab,Neff)))));
h32 ->SetBinContent(i,k,TMath::Abs((((function3(omegab,Neff))*1.0078)/(4.003*(1-function3(omegab,Neff))))-0.0830)); }
}
TH2D *h41 = new TH2D("h41", "d ;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
TH2D *h42 = new TH2D("h42","original ;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
TH2D *h43 = new TH2D("h43"," #times 1.1;#Omega_{B,0}#it{h}^{2};#it{N}_{eff}",300,0.019,0.026,300,1.9,4.3);
for (i=1;i<=h41->GetXaxis()->GetNbins();i++) {
for (k=1;k<=h41->GetYaxis()->GetNbins();k++) {
omegab = h41->GetXaxis()->GetBinCenter(i);
Neff = h41->GetYaxis()->GetBinCenter(k);
h41 ->SetBinContent(i,k,(function2(omegab,Neff)/((function3(omegab,Neff))*1.0078/(4.003*(1-function3(omegab,Neff))))));
h42 ->SetBinContent(i,k,TMath::Abs((function2(omegab,Neff)/((function3(omegab,Neff))*1.0078/(4.003*(1-function3(omegab,Neff)))))-12.27));//
h43->SetBinContent(i,k,TMath::Abs(((function2(omegab,Neff)/((function3(omegab,Neff))*1.0078/(4.003*(1-function3(omegab,Neff)))))*TMath::Power(1.1,-0.39))-12.27));
}
}
c1->cd(1);
h21->Draw("colz");
Double_t contours[4];
contours[0] = 0.00;
contours[1] = 0.04;
contours[2] = 0.08;
contours[3] = 2.;
int colorsBlue [3] = {kGreen, kGreen-10, 0};
gStyle->SetPalette(3,colorsBlue);
h22->SetContour(4, contours);
h22->Draw("CONT4");
gPad->Update();
c1->Update();
c1->cd(2);
h23->SetContour(4, contours);
h23->Draw("CONT4");
c1->Print("h2i.pdf");
c2->cd(1);
h31->Draw("colz");
int colorsBlue [3] = {kGreen, kGreen-10, 0};
gStyle->SetPalette(3,colorsBlue);
h32->SetContour(4, contours);
h32->Draw("CONT4");
gPad->Update();
c2->Update();
c2->Print("h3i.pdf");
c3->cd(1);
h41->Draw("colz");
int colorsGreen [3] = {kGreen, kGreen-10, 0};
gStyle->SetPalette(3,colorsGreen);
h42->SetContour(4, contours);
h42->SetFillStyle(4000);
h42->Draw("CONT4");
gPad->Update();
c3->Update();
c3->cd(2);
h43->SetContour(4, contours);
h43->Draw("CONT4");
c3->Print("h4i.pdf")
TCanvas *c7 = new TCanvas("c7","c7",200,200,1200,600);
int colorsBlue [3] = {kBlue, kBlue-10, 0};
gStyle->SetPalette(3,colorsBlue);
h12->SetContour(4, contours);
h12->Draw("CONT4");
gStyle->SetPalette(3,colorsGreen);
h42->SetFillStyle(4000);
h42->Draw("CONT4 SAME");
c7->Print("Superimposing.eps");
}
In the Superimposing.eps file I have all in Green and actually I can’t see so well the firs histogram. What’s wrong with my code?
Thanks a lot
Eli