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