Formatting colour palette with threshold values

So, start to remove parts of the source code from the multipalette.C tutorial, which are missing in your own “example”, and see what happens.

This “example” draws h1 and h2 on different palettes.

void pal1();
void pal2();
int palette()
{
  TExec * ex1 = new TExec("ex1", "pal1();");
  TExec * ex2 = new TExec("ex2", "pal2();");
  TH2 * h1 = new TH2F("h1", "h1", 2, -0.5, 1.5, 2, -0.5, 1.5);
  h1 -> Fill(0.0, 0.0, 2.0);
  h1 -> Fill(0.0, 1.0, 2.5);

  h1 -> Fill(1.0, 0.0, 0.5);
  h1 -> Fill(1.0, 1.0, 1.5);
  TCanvas * c1 = new TCanvas("c1", "c1", 600, 600);
  h1 -> Draw("COLZ");
  ex1 -> Draw();
  h1 -> Draw("COLZSAME");
  TH2 * h2 = new TH2F("h2", "h2", 2, -0.5, 1.5, 2, -0.5, 1.5);
  h2 -> Fill(0.0, 0.0, 2.0);
  h2 -> Fill(0.0, 1.0, 2.5);
  h2 -> Fill(1.0, 0.0, 0.5);
  h2 -> Fill(1.0, 1.0, 1.5);
  TCanvas *c2 = new TCanvas("c2", "c2", 600, 600);
  h2 -> Draw("COLZ");
  ex2 -> Draw();
  h2 -> Draw("COLZSAME");
  return 0;
}

void pal1()
{
  const unsigned char Number = 6;
  Int_t colours[10];
  static Bool_t initialized = kFALSE;

  Double_t Red[Number]   =  {0.75, 0.75, 0.5, 0.5, 0.2, 0.2,};
  Double_t Green[Number] =  {1.0,  1.0,  1.0, 1.0, 1.0, 1.0 };
  Double_t Blue[Number]  =  {0.75, 0.75, 0.5, 0.5, 0.2, 0.2 };
  Double_t  Stops[Number] = {0.0,  0.5, 0.50001, 0.6, 0.6000001, 1.0};
  TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, 10);
}


void pal2()
{
  const unsigned char Number = 6;
  Int_t colours[10];
  Double_t Red[Number]   =  {0.75, 0.75, 0.5, 0.5, 0.2, 0.2,};
  Double_t Green[Number] =  {0.75, 0.75, 0.5, 0.5, 0.2, 0.2 };
  Double_t Blue[Number]  =  {1.0,  1.0,  1.0, 1.0, 1.0, 1.0 };
  Double_t  Stops[Number] = {0.0,  0.5, 0.50001, 0.6, 0.6000001, 1.0};
  TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, 10);
}

How should I modify pal2() to enforce the original ROOT palette on h2?

TStyle::SetPalette

1 Like

That’s very good.
However, when I turn to g++ compilation, I always get an error like this:

input_line_30:2:3: error: use of undeclared identifier 'pal2'
 (pal2())
Error in <HandleInterpreterException>: Error evaluating expression (pal2()).
Execution of your code was aborted.

For the TExec to work in a standalone compiled code, “pal1” and “pal2” need to be known to the interpreter (i.e., you need a dictionary for them).
I guess the easiest thing to try would be: root palette.cxx++

1 Like
#include <TCanvas.h>
#include <TExec.h>
#include <TH2.h>
#include <TColor.h>

void pal1();

int palette()
{
  TExec * ex1 = new TExec("ex1", "pal1()");
  TExec * ex2 = new TExec("ex2", "gStyle->SetPalette(kBird);");
  TH2 * h1 = new TH2F("h1", "h1", 2, -0.5, 1.5, 2, -0.5, 1.5);
  h1 -> Fill(0.0, 0.0, 2.0);
  h1 -> Fill(0.0, 1.0, 2.5);

  h1 -> Fill(1.0, 0.0, 0.5);
  h1 -> Fill(1.0, 1.0, 1.5);
  TCanvas * c1 = new TCanvas("c1", "c1", 600, 600);
  h1 -> Draw("COLZ");
  ex1 -> Draw();
  h1 -> Draw("COLZSAME");
  TH2 * h2 = new TH2F("h2", "h2", 2, -0.5, 1.5, 2, -0.5, 1.5);
  h2 -> Fill(0.0, 0.0, 2.0);
  h2 -> Fill(0.0, 1.0, 2.5);
  h2 -> Fill(1.0, 0.0, 0.5);
  h2 -> Fill(1.0, 1.0, 1.5);
  TCanvas *c2 = new TCanvas("c2", "c2", 600, 600);
  h2 -> Draw("COLZ");
  ex2 -> Draw();
  h2 -> Draw("COLZSAME");
  return 0;
}

void pal1()
{
  const unsigned char Number = 6;
  Int_t colours[10];
  static Bool_t initialized = kFALSE;

  Double_t Red[Number]   =  {0.75, 0.75, 0.5, 0.5, 0.2, 0.2,};
  Double_t Green[Number] =  {1.0,  1.0,  1.0, 1.0, 1.0, 1.0 };
  Double_t Blue[Number]  =  {0.75, 0.75, 0.5, 0.5, 0.2, 0.2 };
  Double_t  Stops[Number] = {0.0,  0.5, 0.50001, 0.6, 0.6000001, 1.0};
  TColor::CreateGradientColorTable(Number, Stops, Red, Green, Blue, 10);
}

Executed with:

% root palette.cxx++
   ------------------------------------------------------------------
  | Welcome to ROOT 6.25/01                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on May 12 2021, 13:05:12                      |
  | From heads/master@v6-25-01-953-g2c784fd2d4                       |
  | With Apple clang version 12.0.5 (clang-1205.0.22.9)              |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] 
Processing palette.cxx++...
Info in <TMacOSXSystem::ACLiC>: creating shared library ./palette_cxx.so
(int) 0
root [1] 

Gives:

1 Like

I managed to integrate TExec also in a C++ project.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.