Superimposing 2 histograms with 2 different palettes

Dear all

I am trying to superimpose 2 differentts histograms
with 2 different palettes.

My point is that I am using an overlaid pad to get
the second histo on top of the canvas I created
I get everything fine untill at the end
I need to save in EPS/PDF/… format
my canvas that update the color I first chosse for
my first histo with the palette colors of the second histo on
the overlaid PAD.

Here is what I would like to get (what I get before
to save the image using canvas->SaveAs(“blabla.eps/pdf…”);):

lappweb.in2p3.fr/babar/people/Vi … IWant.jpeg

And now what I get right after the SaveAS commands:
lappweb.in2p3.fr/babar/people/Vi … Minute.gif

and what I overlay :
lappweb.in2p3.fr/babar/people/Vi … erlaid.gif

// DEFINE THE MAIN CANVAS
  TCanvas* contBuf = new TCanvas("contBuf","The 2 D 1-CL view of "+Style,0,0,800,800);
 
  contBuf->cd();
  contBuf->Draw();
  
  HistoMerge->GetXaxis()->CenterTitle();
  HistoMerge->GetYaxis()->CenterTitle();
  
  HistoMerge->SetYTitle(TitleY);
  HistoMerge->SetXTitle(TitleX);
  
  // Arrange Title
  HistoMerge->SetTitle("");
  gStyle->SetLineWidth(1);gStyle->SetLineColor(kBlack);
  
  HistoMerge->SetTitleSize(0.055,"x");
  HistoMerge->SetTitleSize(0.055,"y");
  HistoMerge->SetTitleOffset(0.85,"x");
  HistoMerge->SetTitleOffset(1.0,"y");
  
  
  //DEFINE THE RAINBOW Palette
  const Int_t ncol = 191;
  Int_t colors[ncol];
  TColor *col;
  Float_t r, g, b;
  Float_t  saturation = 1.;
  Float_t  lightness = 0.4;
  Float_t  maxHue =   280.;
  Float_t  minHue = 0;
  Int_t    maxPretty =ncol;
  Float_t  hue;
  const int num = ncol;
  Double_t contours[ncol];
  for (Int_t i=0 ; i< ncol+1 ; i++) 
    {
      hue = maxHue- float(i+1)*((maxHue-minHue)/maxPretty);
      TColor::HLStoRGB(hue, lightness, saturation, r, g, b);
      if (i <=0) 
	{
	  r=1.;g=1.;b=1.;
	}
      
      colors[i]= i+20;
      contours[i]=0.045+i*0.005;
      col = gROOT->GetColor(colors[i]);
      
      // cout << " #i r,g,b "<<i<<" "<<r<<" "<<g<<" "<<b<<endl;
      // cout << " hue, lightness, saturation "<<hue<< " "<< lightness<< " "<< saturation <<endl;
      col->SetRGB(r,g,b);
    }  
  
  // DRAW The Fisrt histo with Raibow contour to get the 
  // vertical color scale
  gStyle->SetPalette(ncol,colors);
  fHisCont[fCLNum]->SetContour(num, contours); 
  fHisCont[fCLNum]->Draw("col z, same");
  contBuf->Update();
  // DRAW the second histograms with the 2 gray circles
  Double_t zcontours[3] = {0.,1.,2.};
  Int_t zHistoMerge[3] = {10,18,13};
  gStyle->SetPalette(3,zHistoMerge);
  HistoMerge->SetContour(3, zcontours);
  HistoMerge->Draw("col");
  contBuf->Update();
  
  // Draw also the previously computed contours of the 2 histograms
  if (StylePlot >0)
    {     
      for (int icount=1; icount>-1;icount--) 
	{
	  TObjArray * copyMask_current;
	  copyMask_current=copyMaskTab[icount];
	  TList *ContLevelMask = 
	    (TList*)  copyMask_current->At(0);
	  TGraph* curv_Mask = 
	    (TGraph*) ContLevelMask->First();
	  for (int j=0; j<ContLevelMask->GetSize();j++) 
	    {
	      if (icount==0)
		{    
		  curv_Mask->SetLineColor(18);
		  curv_Mask->SetLineStyle(1);
		  curv_Mask->SetLineWidth(3);
		  curv_Mask->Draw("CL");
		  contBuf->Update();
		}
	      if (icount==1)
		{    
		  curv_Mask->SetLineColor(13);
		  curv_Mask->SetLineStyle(1);
		  curv_Mask->SetLineWidth(3);
		  curv_Mask->Draw("CL");
		  contBuf->Update();
		}
	      curv_Mask = (TGraph*)
		ContLevelMask->After(curv_Mask); // Get Next graph
	    }
	}
    }
  //DRAW some tex and the logo of the plot
  TLatex latex;
  Double_t size=0.04;
  latex.SetNDC(kTRUE);
  latex.SetTextAlign(13);  //align at top
  latex.SetTextSize(size);
  char my_text[300];
  sprintf(my_text,"1-CL");
  latex.DrawLatex(0.80,0.985,my_text);
  contBuf->RedrawAxis();
  DrawLogo(fConference,0.675,0.81,1.05);
  contBuf->Update();
  //
  // OverLAY a PAD to get the second palette with the raibow colors
  TPad *overlay = new TPad("overlay","",0.,0.,1.,1.);   overlay->SetFillStyle(4000);
  overlay->Draw();
  Double_t x1,y1,x2,y2;
  contBuf->GetRange(x1,y1,x2,y2);
  overlay->Range(x1,y1,x2,y2);
  //cout << x1 << " " <<x2<<" "<<y1<<" "<<y2<<" "<<endl;
  overlay->cd(); 
  gStyle->SetPalette(ncol,colors);
  fHisCont[fCLNum]->SetContour(num, contours); 
  fHisCont[fCLNum]->Draw("col,same");
  // Draw vertiwla and horizontal lines 
   if (StylePlot ==2)
    {  
      gStyle->SetLineWidth(2);gStyle->SetLineColor(kBlack);  
      TLine *l = new TLine(XMin,0.,XMax,0.0);
      l->SetLineStyle(2);
      l->Draw();
      TLine *li = new TLine(0.0,YMin,0.0,YMax);
      li->SetLineStyle(2);
      li->Draw();
      //      DrawIsospinTriangle();          // Draw UT
    }
  overlay->Update();
  // DRAW a nice purple contour for the rainow histogram 
  // to get a smooth shape
  if (StylePlot >0)
    {     
      TObjArray * copyMask_current;
      copyMask_current=copyMaskTab[fCLNum];
      
      TList *ContLevelMask = 
	(TList*)  copyMask_current->At(0);
      TGraph* curv_Mask = 
	(TGraph*) ContLevelMask->First();
      for (int j=0; j<ContLevelMask->GetSize();j++) 
	{
	  curv_Mask->SetLineColor( colors[1]);
	  curv_Mask->SetLineWidth(5);
	  curv_Mask->Draw("cl,same");
	  
	  overlay->Update();
	}
      curv_Mask = (TGraph*)
	ContLevelMask->After(curv_Mask); // Get Next graph
    }
	
  overlay->Update();
  cout << "UP to HERE I like my plot"<<endl;
  getchar();
  // TRY no w to save the canvas contBuf
  TString direct("Plots/");
  TString secondPDF(".pdf");
  TString secondEPS(".eps");
  TString secondGIF(".gif"); 
  TString allPDF(direct);
  allPDF += fPlotName;
  
  TString allEPS(allPDF);
  TString allGIF(allPDF);
  allPDF +=secondPDF;
  allEPS +=secondEPS;
  allGIF +=secondGIF; 
  contBuf->SaveAs(allPDF);
  contBuf->SaveAs(allEPS);
  contBuf->SaveAs(allGIF); 

  //getchar();
  contBuf->Close();

Above lies the code I am using

Any Ideas ???

Thanks in advance
regards
Vincent
[/url]

Example:

{
   TCanvas *c1 = new TCanvas("c1");
   TH2F *h1 = new TH2F("h1","h1",40,-4,4,40,-4,4);
   TH2F *h2 = new TH2F("h2","h2",40,-4,4,40,-4,4);
   Double_t a,b;
   for (Int_t i=0;i<5000;i++) {
      gRandom->Rannor(a,b);
      h1->Fill(a-1.5,b-1.5);
      h2->Fill(a+1.5,b+1.5);
   }
   TExec *ex1 = new TExec("ex1","gStyle->SetPalette(0);");
   TExec *ex2 = new TExec("ex2","gStyle->SetPalette(1);");
   h1->Draw("colz");
   ex1->Draw();
   h1->Draw("col same");
   ex2->Draw();
   h2->Draw("col same");
}

Dear Olivier

 //DEFINE THE RAINBOW Palette
  const Int_t ncol = 191;
  Int_t colors[ncol];
  TColor *col;
  Float_t r, g, b;
  Float_t  saturation = 1.;
  Float_t  lightness = 0.4;
  Float_t  maxHue =   280.;
  Float_t  minHue = 0;
  Int_t    maxPretty =ncol;
  Float_t  hue;
  const int num = ncol;
  Double_t contours[ncol];
  for (Int_t i=0 ; i< ncol+1 ; i++) 
    {
      hue = maxHue- float(i+1)*((maxHue-minHue)/maxPretty);
      TColor::HLStoRGB(hue, lightness, saturation, r, g, b);
      if (i <=0) 
	{
	  r=1.;g=1.;b=1.;
	}
      
      colors[i]= i+20;
      contours[i]=0.045+i*0.005;
      col = gROOT->GetColor(colors[i]);
      
      // cout << " #i r,g,b "<<i<<" "<<r<<" "<<g<<" "<<b<<endl;
      // cout << " hue, lightness, saturation "<<hue<< " "<< lightness<< " "<< saturation <<endl;
      col->SetRGB(r,g,b);
    }  
  Int_t zHistoMerge[3] = {10,18,13};
  Double_t zcontours[3] = {0.,1.,2.};
   for (Int_t i=0 ; i< ncol+1 ; i++) 
    {
      cout << colors[i]<<endl;
    }
   
  //
  TExec *ex1 = new TExec("ex1","gStyle->SetPalette(ncol,colors);");

My point is that I am defining a Palette with 191 colors as above

and if I do ex1->Draw();

Then I get the message

when running my macro…

Vincent,

Replace the line

TExec *ex1 = new TExec("ex1","gStyle->SetPalette(ncol,colors);"); by

TExec *ex1 = new TExec("ex1",Form("gStyle->SetPalette(%d,(Int_t*)0x%x);",ncol,colors));
Rene

Thanks a lot René and Olivier you solved my question