Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
RootPalette Class Reference

#include <RootPalette.h>

Public Member Functions

 RootPalette ()
 
 RootPalette (TStyle *pstyle)
 
 RootPalette (int ipal)
 
int rootPaletteIndex () const
 
unsigned int ncol () const
 
const int * colorArray () const
 
const std::vector< int > & colorVector () const
 
int getRootPalette ()
 
int getRootPalette (TStyle *pstyle)
 
int setRootPalette () const
 
int setRootPalette (TStyle *pstyle) const
 
std::vector< int > & mutableColorVector ()
 
void setFirstColors (unsigned int ncol, unsigned int icol=0)
 
void setCentralColors (unsigned int ncol, unsigned int icol=0)
 

Static Public Member Functions

static const RootPalettedefaultPalette ()
 
static const RootPalettefind (unsigned int ipal)
 
static bool set (int ipal)
 

Private Attributes

int m_rootPalette =0
 
std::vector< int > m_cols
 

Detailed Description

Definition at line 46 of file RootPalette.h.

Constructor & Destructor Documentation

RootPalette::RootPalette ( )

Definition at line 140 of file RootPalette.cxx.

140  {
141  defaultPalette();
142  getRootPalette();
143 }
static const RootPalette * defaultPalette()
Definition: RootPalette.cxx:23
int getRootPalette()
RootPalette::RootPalette ( TStyle *  pstyle)

Definition at line 147 of file RootPalette.cxx.

147  {
148  defaultPalette();
149  getRootPalette(pstyle);
150 }
static const RootPalette * defaultPalette()
Definition: RootPalette.cxx:23
int getRootPalette()
RootPalette::RootPalette ( int  ipal)

Definition at line 154 of file RootPalette.cxx.

154  {
155  defaultPalette();
156  if ( ipal > 0 && ipal < 1000 ) m_rootPalette = ipal;
157 }
static const RootPalette * defaultPalette()
Definition: RootPalette.cxx:23
int m_rootPalette
Definition: RootPalette.h:103

Member Function Documentation

const int* RootPalette::colorArray ( ) const
inline

Definition at line 78 of file RootPalette.h.

78 { return ncol() ? &m_cols[0] : nullptr; }
unsigned int ncol() const
Definition: RootPalette.h:77
std::vector< int > m_cols
Definition: RootPalette.h:106
const std::vector<int>& RootPalette::colorVector ( ) const
inline

Definition at line 79 of file RootPalette.h.

79 { return m_cols; }
std::vector< int > m_cols
Definition: RootPalette.h:106
const RootPalette * RootPalette::defaultPalette ( )
static

Definition at line 23 of file RootPalette.cxx.

23  {
24  static bool first = true;
25  if ( first ) {
26  first = false;
27  fixedPals()[0] = new RootPalette;
28  }
29  return fixedPals()[0];
30 }
const RootPalette * RootPalette::find ( unsigned int  ipal)
static

Definition at line 34 of file RootPalette.cxx.

34  {
35  if ( ipal >= fixedPals().size() ) return nullptr;
36  if ( fixedPals()[ipal] != nullptr ) return fixedPals()[ipal];
38  if ( ipal == 0 ) {
39  return defaultPalette();
40  } else if ( ipal < 1000 ) {
41  if ( fixedPals()[ipal] == nullptr ) {
42  fixedPals()[ipal] = new RootPalette(ipal);
43  }
44  } else if ( (ipal >= 1010 && ipal < 1020) ||
45  (ipal >= 2010 && ipal < 2020) ) {
46  TStyle* pstyleSave = gStyle;
47  gStyle = dynamic_cast<TStyle*>(gStyle->Clone("TmpStyle"));
48  TStyle* pstyleTmp = gStyle;
49  const double alpha = 1.0;
50  const int nRGBs = 5;
51  const int ncol = 200;
52  Double_t stops[nRGBs] = { 0.00, 0.30, 0.44, 0.70, 1.00};
53  Double_t red[nRGBs] = { 1.00, 1.00, 1.00, 0.70, 0.00};
54  Double_t green[nRGBs] = { 1.00, 0.75, 0.55, 0.20, 0.00};
55  Double_t blue[nRGBs] = { 1.00, 0.00, 0.00, 0.10, 0.00};
56  if ( ipal > 2000 ) {
57  stops[1] = 0.20;
58  stops[2] = 0.40;
59  stops[3] = 0.70;
60  green[1] = 0.90;
61  blue[1] = 0.55;
62  green[2] = 0.60;
63  blue[2] = 0.05;
64  red[4] = 0.20;
65  }
66  TColor::CreateGradientColorTable(nRGBs, stops, red, green, blue, ncol, alpha);
67  RootPalette* ppal = new RootPalette;
68  vector<unsigned int> ncfxs = {0, 1, 2, 4, 6, 8, 10, 20, 30, 40};
69  int ipal0 = ipal < 2000 ? 1010 : 2010;
70  ppal->setFirstColors(ncfxs[ipal - ipal0]);
71  fixedPals()[ipal] = ppal;
72  gStyle = pstyleSave;
73  delete pstyleTmp;
74  } else if ( (ipal >= 1020 && ipal < 1030) ||
75  (ipal >= 2020 && ipal < 2030) ) {
76  TStyle* pstyleSave = gStyle;
77  gStyle = dynamic_cast<TStyle*>(gStyle->Clone("TmpStyle"));
78  TStyle* pstyleTmp = gStyle;
79  const double alpha = 1.0;
80  const int nRGBs = 7;
81  const int ncol = 400;
82  Double_t stops[nRGBs] = { 0.00, 0.50, 0.50, 0.65, 0.72, 0.85, 1.00};
83  Double_t red[nRGBs] = { 0.09, 0.90, 1.00, 1.00, 1.00, 0.70, 0.00};
84  Double_t green[nRGBs] = { 0.60, 0.95, 1.00, 0.75, 0.55, 0.20, 0.00};
85  Double_t blue[nRGBs] = { 0.48, 1.00, 1.00, 0.00, 0.00, 0.10, 0.00};
86  if ( ipal > 2000 ) {
87  stops[3] = 0.60;
88  stops[4] = 0.70;
89  stops[5] = 0.85;
90  green[0] = 0.30;
91  blue[0] = 0.50;
92  red[1] = 1.00;
93  green[1] = 1.00;
94  blue[1] = 1.00;
95  red[2] = 1.00;
96  green[2] = 1.00;
97  blue[2] = 1.00;
98  green[3] = 0.90;
99  blue[3] = 0.55;
100  green[4] = 0.60;
101  blue[4] = 0.05;
102  red[6] = 0.20;
103  }
104  TColor::CreateGradientColorTable(nRGBs, stops, red, green, blue, ncol, alpha);
105  RootPalette* ppal = new RootPalette;
106  vector<unsigned int> ncfxs = {0, 1, 2, 4, 6, 8, 10, 20, 30, 40};
107  int ipal0 = ipal < 2000 ? 1020 : 2020;
108  ppal->setCentralColors(ncfxs[ipal - ipal0]);
109  fixedPals()[ipal] = ppal;
110  gStyle = pstyleSave;
111  delete pstyleTmp;
112  }
113  return fixedPals()[ipal];
114 }
static const RootPalette * defaultPalette()
Definition: RootPalette.cxx:23
unsigned int ncol() const
Definition: RootPalette.h:77
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
double alpha
Definition: doAna.cpp:15
void setCentralColors(unsigned int ncol, unsigned int icol=0)
void setFirstColors(unsigned int ncol, unsigned int icol=0)
int RootPalette::getRootPalette ( )

Definition at line 161 of file RootPalette.cxx.

161  {
162  return getRootPalette(gStyle);
163 }
int getRootPalette()
int RootPalette::getRootPalette ( TStyle *  pstyle)

Definition at line 167 of file RootPalette.cxx.

167  {
168  m_cols.clear();
169  if ( pstyle == nullptr ) return 2;
170  unsigned int nscol = pstyle->GetNumberOfColors();
171  if ( nscol == 0 ) return 1;
172  for ( unsigned int icol=0; icol<nscol; ++icol ) m_cols.push_back(pstyle->GetColorPalette(icol));
173  return 0;
174 }
std::vector< int > m_cols
Definition: RootPalette.h:106
std::vector<int>& RootPalette::mutableColorVector ( )
inline

Definition at line 92 of file RootPalette.h.

92 { return m_cols; }
std::vector< int > m_cols
Definition: RootPalette.h:106
unsigned int RootPalette::ncol ( ) const
inline

Definition at line 77 of file RootPalette.h.

77 { return m_cols.size(); }
std::vector< int > m_cols
Definition: RootPalette.h:106
int RootPalette::rootPaletteIndex ( ) const
inline

Definition at line 76 of file RootPalette.h.

76 { return m_rootPalette; }
int m_rootPalette
Definition: RootPalette.h:103
bool RootPalette::set ( int  ipal)
static

Definition at line 118 of file RootPalette.cxx.

118  {
119  unsigned int ipal = ipalin >= 0 ? ipalin : -ipalin;
120  defaultPalette();
121  if ( ipal >= fixedPals().size() ) return false;
122  // Use predfined map if it exists.
123  const RootPalette* ppal = RootPalette::find(ipal);
124  // Otherwise, treat this as a Root palette index.
125  if ( ppal == nullptr && ipal > 0 && ipal < 1000 ) {
126  ppal = new RootPalette(ipal);
127  fixedPals()[ipal] = ppal;
128  }
129  if ( ppal != nullptr && ppal->setRootPalette() == 0 ) {
130  if ( ipalin < 0 ) TColor::InvertPalette();
131  return true;
132  }
133  return false;
134 }
static const RootPalette * defaultPalette()
Definition: RootPalette.cxx:23
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
int setRootPalette() const
static const RootPalette * find(unsigned int ipal)
Definition: RootPalette.cxx:34
void RootPalette::setCentralColors ( unsigned int  ncol,
unsigned int  icol = 0 
)

Definition at line 207 of file RootPalette.cxx.

207  {
208  unsigned int icz = ncol()/2;
209  unsigned int icfx1 = icz > ncfx ? icz - ncfx : 0;
210  unsigned int icfx2 = icz + ncfx;
211  if ( 2*icz + ncol() ) icfx2 -= 1; // Handle odd # colors.
212  if ( icfx2 > ncol() ) icfx2 = ncol();
213  for ( unsigned int icfx=icfx1; icfx<icz+ncfx; ++icfx ) mutableColorVector()[icfx] = icol;
214 }
std::vector< int > & mutableColorVector()
Definition: RootPalette.h:92
unsigned int ncol() const
Definition: RootPalette.h:77
void RootPalette::setFirstColors ( unsigned int  ncol,
unsigned int  icol = 0 
)

Definition at line 201 of file RootPalette.cxx.

201  {
202  for ( unsigned int icfx=0; icfx<ncfx; ++icfx ) mutableColorVector()[icfx] = icol;
203 }
std::vector< int > & mutableColorVector()
Definition: RootPalette.h:92
int RootPalette::setRootPalette ( ) const

Definition at line 178 of file RootPalette.cxx.

178  {
179  return setRootPalette(gStyle);
180 }
int setRootPalette() const
int RootPalette::setRootPalette ( TStyle *  pstyle) const

Definition at line 184 of file RootPalette.cxx.

184  {
185  if ( pstyle == nullptr ) return 2;
186  int ipal = rootPaletteIndex();
187  if ( ipal >0 && ipal < 1000 ) {
188  pstyle->SetPalette(ipal);
189  } else if ( ncol() == 0 ) {
190  return 1;
191  } else {
192  vector<int> cols(ncol());
193  for ( unsigned int icol=0; icol<ncol(); ++icol ) cols[icol] = m_cols[icol];
194  pstyle->SetPalette(ncol(), &cols[0]);
195  }
196  return 0;
197 }
unsigned int ncol() const
Definition: RootPalette.h:77
std::vector< int > m_cols
Definition: RootPalette.h:106
int rootPaletteIndex() const
Definition: RootPalette.h:76

Member Data Documentation

std::vector<int> RootPalette::m_cols
private

Definition at line 106 of file RootPalette.h.

int RootPalette::m_rootPalette =0
private

Definition at line 103 of file RootPalette.h.


The documentation for this class was generated from the following files: