GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
VPalette.cpp
1 #include "TMath.h"
2 #include "TStyle.h"
3 
4 #include "application/gui/VPalette.h"
5 #include "utils/GGSSmartLog.h"
6 
7 const Int_t VPalette::_defNbins = 255;
8 
9 VPalette::VPalette() : TPaletteAxis() { static const std::string routineName("VPalette::VPalette"); }
10 
11 VPalette::~VPalette() {}
12 
13 void VPalette::Rebin(Double_t xmin, Double_t xmax, Int_t nbins) {
14  static const std::string routineName("VPalette::Rebin");
15 
16  _xMin = xmin;
17  _xMax = 1.001 * xmax;
18  _nBins = nbins;
19 }
20 
21 Int_t VPalette::GetValueColor2(Double_t zc) {
22  static const std::string routineName("VPalette::GetValueColor2");
23 
24  Double_t wmin = _xMin;
25  Double_t wmax = _xMax;
26  Double_t wlmin = wmin;
27  Double_t wlmax = wmax;
28 
29  if (_isLog) {
30  if (wmin <= 0 && wmax > 0)
31  wmin = TMath::Min((Double_t)1, (Double_t)0.001 * wmax);
32  wlmin = TMath::Log10(wmin);
33  wlmax = TMath::Log10(wmax);
34  }
35 
36  Int_t ncolors = gStyle->GetNumberOfColors();
37  Int_t ndivz = _nBins;
38  if (ndivz == 0)
39  return 0;
40  ndivz = TMath::Abs(ndivz);
41  Int_t theColor, color;
42  Double_t scale = ndivz / (wlmax - wlmin);
43 
44  if (_isLog)
45  zc = TMath::Log10(zc);
46  if (zc < wlmin)
47  zc = wlmin;
48 
49  color = Int_t(0.01 + (zc - wlmin) * scale);
50 
51  theColor = Int_t((color + 0.99) * Double_t(ncolors) / Double_t(ndivz));
52  // COUT(DEBUG) << color << " - " << theColor << " - " << gStyle->GetColorPalette(theColor) << ENDL;
53 
54  return gStyle->GetColorPalette(theColor);
55 }