MaCh3  2.2.3
Reference Guide
styleManager.cpp
Go to the documentation of this file.
1 #include "styleManager.h"
2 
3 namespace MaCh3Plotting {
4 StyleManager::StyleManager(std::string styleConfigName) {
5  _styleConfig = M3OpenConfig(styleConfigName);
6 }
7 
8 std::string StyleManager::prettifyName(const std::string &origName, const std::string &nameType) const {
9  YAML::Node prettyNames = _styleConfig["PrettyNames"][nameType];
10  auto prettyName = GetFromManager<std::string>(prettyNames[origName], origName, __FILE__, __LINE__);
11 
12  return prettyName;
13 }
14 
15 void StyleManager::setPalette(const int rootPlotStyle) const {
16  // set the colour palette to one of the root palettes
17  gStyle->SetPalette(rootPlotStyle);
18 }
19 
20 void StyleManager::setPalette(const std::string& configStyleName) const {
21  // set the colour palette to one of the palettes defined in PlottingConfig.yaml
22 
23  // get the definition of the provided style from the config file
24  YAML::Node palettes = _styleConfig["ColorPallettes"];
25  YAML::Node styleDef;
26  if (palettes) {
27  styleDef = palettes[configStyleName];
28  }
29 
30  auto paletteDef = GetFromManager<std::vector<std::vector<double>>>(
31  styleDef["MarkerColor"],
32  std::vector<std::vector<double>>{
33  {4.0}, // NCont
34  {0.0 , 0.33 , 0.66 , 1.0}, // stops
35  {0.0 , 0.0 , 0.0 , 0.0}, // Reds
36  {0.0 , 0.0 , 1.0 , 0.0}, // Greens
37  {0.0 , 1.0 , 0.0 , 0.0} // Blues
38  }, __FILE__, __LINE__);
39  const Int_t NCont = Int_t(paletteDef[0][0]);
40 
41  std::vector<double> stopVec = paletteDef[1];
42  std::vector<double> redsVec = paletteDef[2];
43  std::vector<double> greensVec = paletteDef[3];
44  std::vector<double> bluesVec = paletteDef[4];
45 
46  // get the number of colour stops and check all vectors are same size
47  const size_t NRGBs = stopVec.size();
48  if (redsVec.size() != NRGBs || greensVec.size() != NRGBs ||
49  bluesVec.size() != NRGBs)
50  {
51  MACH3LOG_ERROR("invalid colour palette defined in style config file: {}");
52  MACH3LOG_ERROR("RGB arrays don't all have the same size, please fix that");
53  }
54 
55  // now actually set the palette
56  TColor::CreateGradientColorTable(int(NRGBs), stopVec.data(), redsVec.data(), greensVec.data(), bluesVec.data(), NCont);
57  gStyle->SetNumberContours(NCont);
58 }
59 
60 void StyleManager::setTH1Style(TH1 *hist, const std::string& styleName) const {
61  // get the definition of the provided style from the config file
62  YAML::Node TH1Styles = _styleConfig["TH1Styles"];
63  YAML::Node styleDef ;
64  if (TH1Styles) {
65  styleDef = TH1Styles[styleName];
66  }
67 
68  hist->SetMarkerColor(GetFromManager<Color_t>(styleDef["MarkerColor"], kRed, __FILE__, __LINE__));
69  hist->SetMarkerStyle(GetFromManager<Color_t>(styleDef["MarkerStyle"], 7, __FILE__, __LINE__));
70  hist->SetFillColor(GetFromManager<Color_t>(styleDef["FillColor"], kRed, __FILE__, __LINE__));
71  hist->SetFillStyle(GetFromManager<Color_t>(styleDef["FillStyle"], 3003, __FILE__, __LINE__));
72  hist->SetLineColor(GetFromManager<Color_t>(styleDef["LineColor"], kRed, __FILE__, __LINE__));
73  hist->SetLineStyle(GetFromManager<Color_t>(styleDef["LineStyle"], 1, __FILE__, __LINE__));
74 }
75 
76 } // namespace MaCh3Plotting
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:27
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:561
std::string prettifyName(const std::string &origName, const std::string &nameType) const
Definition: styleManager.cpp:8
StyleManager(std::string configName)
Constructor.
Definition: styleManager.cpp:4
void setTH1Style(TH1 *hist, const std::string &styleName) const
Set the style of a TH1 to one of the styles defined in the style config.
void setPalette(const int rootPlotStyle) const
Set the root colour palette to one of the default root pallettes as defined in (root docs)[https://ro...