Implement colored pallete

dear experts. Supposing I have file called filename.C

// sets nice plotting settings
int rootlogon ()
{
  gStyle->SetDrawBorder(0);
  gStyle->SetCanvasColor(kWhite);     
  gStyle->SetCanvasDefH(800);
  gStyle->SetCanvasDefW(800);
  gStyle->SetCanvasBorderMode(0);     
  gStyle->SetPadBorderMode(0);
  gStyle->SetPaintTextFormat("5.2f"); 
  gStyle->SetLineWidth(2);
  gStyle->SetTextSize(1.1);
  gStyle->SetLabelSize(0.04,"xy");
  gStyle->SetTitleSize(0.05,"xy");
  gStyle->SetTitleOffset(1.0,"x");
  gStyle->SetTitleOffset(1.6,"y");
  gStyle->SetPadTopMargin(0.05);
  gStyle->SetPadRightMargin(0.05);
  gStyle->SetPadBottomMargin(0.15);
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetLegendBorderSize(1);
  gStyle->SetFrameBorderMode(0);
  gStyle->SetFrameFillColor(kWhite);
  gStyle->SetTitleFillColor(kWhite);
  gStyle->SetStatFontSize(0.03);
  gStyle->SetStatBorderSize(1);
  gStyle->SetStatFormat("6.4g");
  gStyle->SetStatX(0.95);
  gStyle->SetStatY(0.95);
  gStyle->SetStatW(0.2);
  gStyle->SetStatH(0.2);
  gStyle->SetStatColor(kWhite);
  gStyle->SetTitleX(0.3);
  gStyle->SetTitleY(0.98);
  gStyle->SetTitleBorderSize(1);
  gStyle->SetTitleFontSize(0.06);
  gStyle->SetLegendBorderSize(1);
  gROOT->SetStyle("Default");



  TColor::InitializeColors();
  const Int_t NRGBs = 5;
  const Int_t NCont = 90;

  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
  Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
  Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
  gStyle->SetNumberContours(NCont);


  gROOT->ForceStyle();
        
  return 0;

}

TH2F *h2 ( ) {

 //here I want to do histograming.....

}

How do i implement the colored pallete I defined in the first function if I want to draw the histogram in function h2( )?
Also, how should it be written if i want to have a grayscale pallate
Many thanks

The palette is a global gStyle object and is know everywhere.

Grey palette:

   UInt_t Number = 2;
   Double_t Red[Number]   = { 0.00, 1.00};
   Double_t Green[Number] = { 0.00, 1.00};
   Double_t Blue[Number]  = { 0.00, 1.00};
   Double_t Stops[Number] = { 0.00, 1.00};

   Int_t nb=50;
   TColor::CreateGradientColorTable(Number,Stops,Red,Green,Blue,nb);

or gStyle-SetPalette(52);

see root.cern.ch/root/html/TColor.ht … SetPalette

Thanks.
gStyle-SetPalette(50,0) works for me for grayscale.

gStyle-SetPalette(52) gives me blue

It is because you are using a to old version of ROOT.
SetPalette has been updated:
root.cern.ch/root/html/TColor.ht … SetPalette

ok, thanks