Colors_service.cc
Go to the documentation of this file.
1 #include "nutools/EventDisplayBase/Colors.h"
2 #include <vector>
3 #include <string>
4 #include "TROOT.h"
5 #include "TStyle.h"
10 #include "nutools/EventDisplayBase/ColorScale.h"
11 
12 namespace evdb {
13 
15  {
16  this->reconfigure(p);
17  }
18 
19  //......................................................................
20 
22  {
25  for (; itr!=itrEnd; ++itr) {
26  if (itr->second) { delete itr->second; itr->second = 0; }
27  }
28  }
29 
30  //......................................................................
31 
33  {
34  int black_on_white = p.get<int>("BlackOnWhite.val");
35  if (black_on_white) this->BlackOnWhite();
36  else this->WhiteOnBlack();
37 
38  std::vector<std::string>
39  cs = p.get<std::vector<std::string> >("ColorScales.val");
40  for (unsigned int i=0; i<cs.size(); ++i) {
41  this->UnpackColorScale(p,cs[i]);
42  }
43  }
44 
45  //......................................................................
46 
48  const std::string& nm)
49  {
50  std::string palette_tag(nm); palette_tag += "_Palette.val";
51  std::string n_tag(nm); n_tag += "_N.val";
52  std::string r_tag(nm); r_tag += "_Range.val";
53  std::string scale_tag(nm); scale_tag += "_Scale.val";
54  std::string reverse_tag(nm); reverse_tag += "_Reverse.val";
55  std::string ofufc_tag(nm); ofufc_tag += "_UnderOverflowColors.val";
56  std::string hv_tag(nm); hv_tag += "_HVPairs.val";
57 
58  int n, reverse;
59  std::string palette, scale;
60  std::vector<float> r, hv;
61  std::vector<int> ofufc;
62  palette = p.get<std::string> (palette_tag);
63  n = p.get<int> (n_tag);
64  r = p.get<std::vector<float> >(r_tag);
65  scale = p.get<std::string> (scale_tag);
66  reverse = p.get<int> (reverse_tag);
67  ofufc = p.get<std::vector<int> > (ofufc_tag);
68  hv = p.get<std::vector<float> >(hv_tag);
69 
70  ColorScale* cs = new ColorScale(r[0],
71  r[1],
72  ColorScale::Palette(palette),
73  ColorScale::Scale(scale),
74  n,
75  hv[0],
76  hv[1],
77  hv[2],
78  hv[3]);
79  cs->SetUnderFlowColor(ofufc[0]);
80  cs->SetOverFlowColor(ofufc[1]);
81  if (reverse) cs->Reverse();
82  ColorScale* old = fColorScales[nm];
83  if (old) delete old;
84  fColorScales[nm] = cs;
85  }
86 
87  ///
88  /// Look up a color scale by name
89  ///
91  {
93  if (cs) return (*cs);
94 
95  static ColorScale gsDefaultCS(0,100);
96  return gsDefaultCS;
97  }
98 
99  //......................................................................
100 
102  {
103  fFG[0] = fBG[5] = kWhite;
104  fFG[1] = fBG[4] = kGray;
105  fFG[2] = fBG[3] = kGray+1;
106  fFG[3] = fBG[2] = kGray+2;
107  fFG[4] = fBG[1] = kGray+3;
108  fFG[5] = fBG[0] = kBlack;
109  this->SetStyle();
110  }
111 
112  //......................................................................
113 
115  {
116  fFG[5] = fBG[0] = kWhite;
117  fFG[4] = fBG[1] = kGray;
118  fFG[3] = fBG[2] = kGray+1;
119  fFG[2] = fBG[3] = kGray+2;
120  fFG[1] = fBG[4] = kGray+3;
121  fFG[0] = fBG[5] = kBlack;
122  this->SetStyle();
123  }
124 
125  //......................................................................
126 
128  {
129  i = std::max(0, i);
130  i = std::min(kMAX_FGBG-1,i);
131  return fFG[i];
132  }
133 
134  //......................................................................
135 
137  {
138  i = std::max(0, i);
139  i = std::min(kMAX_FGBG-1,i);
140  return fBG[i];
141  }
142 
143  //......................................................................
144 
146  {
147  int bgcolor = this->Background(0);
148  int fgcolor = this->Foreground(1);
149  gStyle->SetAxisColor(fgcolor,"XYZ");
150  gStyle->SetLabelColor(fgcolor,"XYZ");
151  gStyle->SetTitleColor(fgcolor,"XYZ");
152  gStyle->SetCanvasColor(bgcolor);
153  gStyle->SetLegendFillColor(bgcolor);
154  gStyle->SetPadColor(bgcolor);
155  gStyle->SetFuncColor(kRed);
156  gStyle->SetGridColor(fgcolor);
157  gStyle->SetFrameFillColor(bgcolor);
158  gStyle->SetFrameLineColor(bgcolor);
159  // Leave histogram fill color clear
160  // gStyle->SetHistFillColor(bgcolor);
161  gStyle->SetHistLineColor(fgcolor);
162  gStyle->SetStatColor(bgcolor);
163  gStyle->SetStatTextColor(fgcolor);
164  gStyle->SetTitleFillColor(bgcolor);
165  gStyle->SetTitleTextColor(fgcolor);
166 
167  // Force this style on all histograms
168  gROOT->ForceStyle();
169  }
170 
172 
173 } // namespace evdb
174 
175 ////////////////////////////////////////////////////////////////////////
intermediate_table::iterator iterator
std::map< std::string, ColorScale * > fColorScales
Definition: Colors.h:77
std::string string
Definition: nybbler.cc:12
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:88
int fFG[kMAX_FGBG]
Foreground colors.
Definition: Colors.h:72
Manage all things related to colors for the event display.
void UnpackColorScale(fhicl::ParameterSet const &p, const std::string &c)
int fBG[kMAX_FGBG]
Definition: Colors.h:73
int Background(int i=0)
Colors(fhicl::ParameterSet const &p)
Build an association between a numerical range and a ROOT color index for use in, eg...
Definition: ColorScale.h:44
std::void_t< T > n
ColorScale & Scale(const std::string &nm)
T get(std::string const &key) const
Definition: ParameterSet.h:231
static int Palette(const std::string &nm)
Definition: ColorScale.cxx:17
static int Scale(const std::string &nm)
Definition: ColorScale.cxx:32
static int max(int a, int b)
p
Definition: test.py:223
int Foreground(int i=0)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void reconfigure(fhicl::ParameterSet const &p)
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
Definition: qstring.cpp:11649
static Color palette[]
Definition: image.cpp:156
const char * cs
static const int kMAX_FGBG
Definition: Colors.h:71