Drawing TPaletteAxis in a different TPad

Dear all,

I would like to draw 4 2D histograms on a 2x2 canvas, and a Palette Axis on a different pad. I can retrieve the axis and draw it with the following code using a simple macro, but when I want to compile I get:

Can anyone shed a light on this problem?

Thank you!
Alex


{
   gStyle->SetPalette(1);
   /// Draw all plots on one canvas. ///

   TString date = "20150121_had_em_jets"; TString numb = "1000000"; TString suffix = "_13_1_irJ.root"; //TString suffix = "_129_1_D3d.root";	// Hardest gen jet matched to closest (phi) det jet. 

   //  TString date = "20150112_had_em_jets"; TString numb = "10000000"; TString suffix = "_173_1_iQO.root";
   /// Draw all plots on one canvas. ///

   TCanvas *can_comparison = new TCanvas("Canvas_comparison", "Canvas_comparison", 1.);   
     can_comparison->SetLeftMargin(0.18);
     can_comparison->SetRightMargin(0.01);
     can_comparison->SetBottomMargin(0.14);

   TLegend *legend = new TLegend(0.5, 0.5, 0.99, 0.99);
     legend->SetFillColor( kWhite );

   std::vector<TString> filenames;
   std::vector<TString> legendEntries;
   std::vector<TString> plotVariables;
   std::vector<TString> jetSelection;
     std::vector<TString> plotX;
     std::vector<TString> plotY;
     std::vector<TString> plotTitle;
   std::vector<int>     colours;
   std::vector<double> plot_min;

   std::vector<double> minX;
   std::vector<double> maxX;
   std::vector<double> minY;
   std::vector<double> maxY;


   cout << "Files" << endl;

     filenames.push_back("LoopRootFiles/" + date + "_Output_JetAnalyzer_radii_GEN_ak3_DET_ak5_margin_0.500000_" + numb + "_Pythia6_Z2star_Default_varyR_CastorTree_MC_7TeV_42X_53XRECOwithCorrector" + suffix);
     legendEntries.push_back("Gen (ak3) - Det (ak5)");

     filenames.push_back("LoopRootFiles/" + date + "_Output_JetAnalyzer_radii_GEN_ak3_DET_ak7_margin_0.500000_" + numb + "_Pythia6_Z2star_Default_varyR_CastorTree_MC_7TeV_42X_53XRECOwithCorrector" + suffix);
     legendEntries.push_back("Gen (ak3) - Det (ak7)");

     filenames.push_back("LoopRootFiles/" + date + "_Output_JetAnalyzer_radii_GEN_ak5_DET_ak5_margin_0.500000_" + numb + "_Pythia6_Z2star_Default_varyR_CastorTree_MC_7TeV_42X_53XRECOwithCorrector" + suffix);
     legendEntries.push_back("Gen (ak5) - Det (ak5)");

     filenames.push_back("LoopRootFiles/" + date + "_Output_JetAnalyzer_radii_GEN_ak5_DET_ak7_margin_0.500000_" + numb + "_Pythia6_Z2star_Default_varyR_CastorTree_MC_7TeV_42X_53XRECOwithCorrector" + suffix);
     legendEntries.push_back("Gen (ak5) - Det (ak7)");  

  /* Response matrices. */
  
     plotVariables.push_back("hCastorJet_responseMatrix_had_pi");
       plotX.push_back("E_{DET}");
       plotY.push_back("E_{GEN}");
       plotTitle.push_back("Response matrix for hadronic generator and detector jets");
       plot_min.push_back(0.00001);
       minX.push_back(-100.);
       maxX.push_back(2500.);
       minY.push_back(-100.);
       maxY.push_back(2500.);

   for( int plot = 0; plot < plotVariables.size(); plot++){
   
   TString variable = plotVariables[ plot ],
	htitle = plotTitle[ plot ],
	xtitle = plotX[ plot ],
	ytitle = plotY[ plot ]; 

   TCanvas *can = new TCanvas("can", "can", 900, 900);
   
   TPad *superpad = new TPad("pad", "pad", 0.05, 0.05, 0.9, 0.9);
     superpad->Draw();

   TPad *palettePad = new TPad("palette", "palette", 0.90, 0.05, 0.99, 0.95);
     palettePad->Draw();
 
   TH2D* hMatrix; 
   TH2D* hOriginal;
   TPaletteAxis *palette;

   for(int file = 0; file < filenames.size(); file++){
   
     double xmin = 0., xmax = 0., ymin = 0., ymax = 0., xscale = 0., yscale = 0.;
     
     // 2 rows, 3 columns.
     // 0 1 2
     // 3 4 5 

     int row = (file - file % 2)/2;

     int column = file - (file - file%2);

     cout << "File\t" << file << "\trow\t" << row << "\tcolumn\t" << column << endl;

     if( row == 1){ ymin = 0.,  ymax = 0.55, yscale = 45./55.;}
     if( row == 0){ ymin = 0.55, ymax = 1.0, yscale = 1.; }
     
     if( column == 0 ){ xmin = 0., xmax = 0.54; xscale = 44./54.;}
     if( column == 1 ){ xmin = 0.54, xmax = 0.98, xscale = 1.; }
     

     superpad->cd();
     TString padname = TString::Format("pad_%i", file);    

     TPad *currentPad = new TPad( padname, padname, 
			xmin, 
			ymin, 
			xmax, 
			ymax );
      
       currentPad->Draw();
       currentPad->cd();
       currentPad->SetLogz();
       currentPad->SetLeftMargin( 0 ); if( column == 0 ){ currentPad->SetLeftMargin( 0.25 ); }
       currentPad->SetRightMargin(0);
       currentPad->SetTopMargin(0);
       currentPad->SetBottomMargin( 0 ); if( row == 1 ){ currentPad->SetBottomMargin( 0.25 ); }
       currentPad->Update();

     TFile *_file0 = TFile::Open( filenames[file], "Read");

     TString histname = variable + TString::Format("_%i", file);
     cout << "Name\t" << histname << "\t" << filenames[file] << endl;
     hMatrix = (TH2D*)_file0->Get( variable );     
       hMatrix->SetName(histname);
       hMatrix->Scale( 1./hMatrix->Integral() );
       hMatrix->SetTitle( legendEntries[file] );

       hMatrix->GetXaxis()->SetTitle( xtitle);
       hMatrix->GetXaxis()->SetTitleOffset(1.0 / xscale  );
       hMatrix->GetXaxis()->SetTitleSize(0.12 * xscale);
       hMatrix->GetXaxis()->SetLabelSize(0.08 * xscale);
       hMatrix->GetXaxis()->SetLabelOffset(0.007  );
       hMatrix->GetXaxis()->SetRangeUser( minX[plot], maxX[plot] );
 
       hMatrix->GetYaxis()->SetTitle( ytitle);
       hMatrix->GetYaxis()->SetTitleOffset(1.2 /yscale);
       hMatrix->GetYaxis()->SetTitleSize(0.01 * yscale);
       hMatrix->GetYaxis()->SetLabelSize(0.08 * yscale);
       hMatrix->GetYaxis()->SetLabelOffset( 0.01 / yscale );
       hMatrix->GetYaxis()->SetRangeUser( minY[plot], maxY[plot] );
       hMatrix->Draw("colz");
       hMatrix->GetZaxis()->SetRangeUser( 1e-4, 1.);       

      if(file == 0){ 
	hOriginal = hMatrix;
	currentPad->Update();
	gPad->Update();
        //palette = (TPaletteAxis*)hOriginal->GetListOfFunctions()->FindObject("palette");
      }        
   	
   }


   superpad->cd();
      
   TLine *line = new TLine(.981,0.25*0.55,.981,1.);
   line->Draw();

   can->cd();

   // Add labels about the jet radii to the plot.

   // 2 row matrix.
   TText *text = new TText(0.04,0.25,"Gen (ak5)");
   text->SetTextSize(0.04);
   text->SetTextAngle(90);
   text->Draw();
   text = new TText(0.04,0.75,"Gen (ak3)");
   text->SetTextSize(0.04);
   text->SetTextAngle(90);
   text->Draw();

   text = new TText(0.2,0.97,"Det (ak3)");
   text->SetTextSize(0.04);
   text->Draw();
   text = new TText(0.45,0.97,"Det (ak5)");
   text->SetTextSize(0.04);
   text->Draw();
   text = new TText(0.7,0.97,"Det (ak7)");
   text->SetTextSize(0.04);
   text->Draw();

   // Add a legenda for the colours.
   
   palettePad->cd();
   palettePad->Range(0.,0.,1.,1.);   
   palettePad->SetLogz();
   palette = new TPaletteAxis(0.10,0.095,0.50, 0.94, hOriginal);

   palettePad->Update();   
//   TPaletteAxis *palette = (TPaletteAxis*)hOriginal->GetListOfFunctions()->FindObject("palette");
   
  palettePad->Update();

   palette->SetLabelSize(0.02);
   palette->SetLabelOffset(0.007);
   palette->SetLabelSize(0.25);
   palette->SetTitleOffset(1);
   palette->SetTitleSize(0.30);

   cout << "Actually drawn" << endl;
   palette->Draw();
   cout << "Saved" << endl;   

   can->SaveAs("Plots/" + date + "_" + variable + ".C");
   can->SaveAs("Plots/" + date + "_" + variable + ".pdf");

  } 
 

}

Hi Alex,

are you linking all the libraries you need?
Root offers a tool also to take care of the most common compilation flags, root-config. You can give it a try with a command like

g++ myProgram.cpp -o myProgram `root-config --cflags --libs --glibs`

Cheers,
Danilo

{
   hpxpy->Draw("colz");
   gPad->Update();
   TPaletteAxis *palette = (TPaletteAxis*)hpxpy->GetListOfFunctions()->FindObject("palette");
   TCanvas *c2 = new TCanvas();
   c2->cd();
   palette->Draw();
}