MaCh3  2.6.1
Reference Guide
Public Member Functions | Private Member Functions | Private Attributes | List of all members
M3::Plotting::StyleManager Class Reference

EW: provides centralized styling utilities for plots, including name prettification and style application. More...

#include <Utils/Plotting/StyleManager.h>

Public Member Functions

 StyleManager (const std::string &configName)
 Constructor. More...
 
 StyleManager (const StyleManager &)=delete
 
 StyleManager (StyleManager &&)=default
 
 ~StyleManager ()
 
std::string prettifyParamName (const std::string &origName) const
 Convert hideous and vulgar internal parameter name into a beautiful presentable name. More...
 
std::string prettifySampleName (const std::string &origName) const
 Convert hideous and vulgar internal sample name into a beautiful presentable name. More...
 
std::string prettifyKinematicName (const std::string &origName) const
 Convert hideous and vulgar internal kinematics name into a beautiful presentable name. More...
 
double getBinWidthScale (const std::string &Name) const
 Get bin-width scaling factor for a given kinematic variable. More...
 
void setPalette (const int rootPlotStyle) const
 Set the root colour palette to one of the default root pallettes as defined in (root docs)[https://root.cern.ch/doc/master/classTColor.html#C05]. More...
 
void setPalette (const std::string &configStyleName) const
 Set the root colour palette to one of the ones defined in the style config. More...
 
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. More...
 

Private Member Functions

std::string prettifyName (const std::string &origName, const std::string &nameType) const
 

Private Attributes

YAML::Node _styleConfig
 

Detailed Description

EW: provides centralized styling utilities for plots, including name prettification and style application.

Author
Ewan Miller

Definition at line 21 of file StyleManager.h.

Constructor & Destructor Documentation

◆ StyleManager() [1/3]

M3::Plotting::StyleManager::StyleManager ( const std::string &  configName)

Constructor.

Parameters
configNameThe style config to read from

Definition at line 5 of file StyleManager.cpp.

5  {
6  _styleConfig = M3OpenConfig(styleConfigName);
7 }
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:590

◆ StyleManager() [2/3]

M3::Plotting::StyleManager::StyleManager ( const StyleManager )
delete

◆ StyleManager() [3/3]

M3::Plotting::StyleManager::StyleManager ( StyleManager &&  )
default

◆ ~StyleManager()

M3::Plotting::StyleManager::~StyleManager ( )
inline

Definition at line 31 of file StyleManager.h.

31  {
32  MACH3LOG_DEBUG("##### Deleting StyleManager Instance #####");
33  }
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:34

Member Function Documentation

◆ getBinWidthScale()

double M3::Plotting::StyleManager::getBinWidthScale ( const std::string &  Name) const

Get bin-width scaling factor for a given kinematic variable.

Parameters
variableName of the kinematic variable (e.g. RecoNeutrinoEnergy, TrueQ2)

Definition at line 77 of file StyleManager.cpp.

77  {
78  constexpr const double DefaultScalingFactor = 10;
79  if(!_styleConfig["BinWidthScaleFactor"]) return DefaultScalingFactor;
80 
81  return GetFromManager<double>(_styleConfig["BinWidthScaleFactor"][Name], DefaultScalingFactor, __FILE__, __LINE__);
82 }

◆ prettifyKinematicName()

std::string M3::Plotting::StyleManager::prettifyKinematicName ( const std::string &  origName) const
inline

Convert hideous and vulgar internal kinematics name into a beautiful presentable name.

The pretty kinematics names should be specified in the style config file

Parameters
origNameThe "internal" name used to uniquely identify the kinematics inside the plotting code
Returns
A beautiful formatted name that can be used in plots

Definition at line 58 of file StyleManager.h.

58  {
59  return prettifyName(origName, "kinematics");
60  };
std::string prettifyName(const std::string &origName, const std::string &nameType) const
Definition: StyleManager.cpp:9

◆ prettifyName()

std::string M3::Plotting::StyleManager::prettifyName ( const std::string &  origName,
const std::string &  nameType 
) const
private

Definition at line 9 of file StyleManager.cpp.

9  {
10  YAML::Node prettyNames = _styleConfig["PrettyNames"][nameType];
11  auto prettyName = GetFromManager<std::string>(prettyNames[origName], origName, __FILE__, __LINE__);
12 
13  return prettyName;
14 }

◆ prettifyParamName()

std::string M3::Plotting::StyleManager::prettifyParamName ( const std::string &  origName) const
inline

Convert hideous and vulgar internal parameter name into a beautiful presentable name.

The pretty parameter names should be specified in the style config file

Parameters
origNameThe "internal" name used to uniquely identify the parameter inside the plotting code
Returns
A beautiful formatted name that can be used in plots

Definition at line 40 of file StyleManager.h.

40  {
41  return prettifyName(origName, "parameters");
42  };

◆ prettifySampleName()

std::string M3::Plotting::StyleManager::prettifySampleName ( const std::string &  origName) const
inline

Convert hideous and vulgar internal sample name into a beautiful presentable name.

The pretty sample names should be specified in the style config file

Parameters
origNameThe "internal" name used to uniquely identify the sample inside the plotting code
Returns
A beautiful formatted name that can be used in plots

Definition at line 49 of file StyleManager.h.

49  {
50  return prettifyName(origName, "samples");
51  };

◆ setPalette() [1/2]

void M3::Plotting::StyleManager::setPalette ( const int  rootPlotStyle) const

Set the root colour palette to one of the default root pallettes as defined in (root docs)[https://root.cern.ch/doc/master/classTColor.html#C05].

Parameters
rootPlotStyleThe index of the palette as defined by root

Definition at line 16 of file StyleManager.cpp.

16  {
17  // set the colour palette to one of the root palettes
18  gStyle->SetPalette(rootPlotStyle);
19 }

◆ setPalette() [2/2]

void M3::Plotting::StyleManager::setPalette ( const std::string &  configStyleName) const

Set the root colour palette to one of the ones defined in the style config.

Parameters
rootPlotStyleThe name of the palette you want to use, should be the same as it appears in the style config

Definition at line 21 of file StyleManager.cpp.

21  {
22  // set the colour palette to one of the palettes defined in PlottingConfig.yaml
23 
24  // get the definition of the provided style from the config file
25  YAML::Node palettes = _styleConfig["ColorPallettes"];
26  YAML::Node styleDef;
27  if (palettes) {
28  styleDef = palettes[configStyleName];
29  }
30 
31  auto paletteDef = GetFromManager<std::vector<std::vector<double>>>(
32  styleDef,
33  std::vector<std::vector<double>>{
34  {4.0}, // NCont
35  {0.0 , 0.33 , 0.66 , 1.0}, // stops
36  {0.0 , 0.0 , 0.0 , 0.0}, // Reds
37  {0.0 , 0.0 , 1.0 , 0.0}, // Greens
38  {0.0 , 1.0 , 0.0 , 0.0} // Blues
39  }, __FILE__, __LINE__);
40  const Int_t NCont = Int_t(paletteDef[0][0]);
41 
42  std::vector<double> stopVec = paletteDef[1];
43  std::vector<double> redsVec = paletteDef[2];
44  std::vector<double> greensVec = paletteDef[3];
45  std::vector<double> bluesVec = paletteDef[4];
46 
47  // get the number of colour stops and check all vectors are same size
48  const size_t NRGBs = stopVec.size();
49  if (redsVec.size() != NRGBs || greensVec.size() != NRGBs ||
50  bluesVec.size() != NRGBs)
51  {
52  MACH3LOG_ERROR("invalid colour palette defined in style config file: {}");
53  MACH3LOG_ERROR("RGB arrays don't all have the same size, please fix that");
54  }
55 
56  // now actually set the palette
57  TColor::CreateGradientColorTable(int(NRGBs), stopVec.data(), redsVec.data(), greensVec.data(), bluesVec.data(), NCont);
58  gStyle->SetNumberContours(NCont);
59 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37

◆ setTH1Style()

void M3::Plotting::StyleManager::setTH1Style ( TH1 *  hist,
const std::string &  styleName 
) const

Set the style of a TH1 to one of the styles defined in the style config.

Parameters
histThe TH1 that you wish to modify
styleNameThe name of the style you want to use, as it appears in the config file

Definition at line 61 of file StyleManager.cpp.

61  {
62  // get the definition of the provided style from the config file
63  YAML::Node TH1Styles = _styleConfig["TH1Styles"];
64  YAML::Node styleDef ;
65  if (TH1Styles) {
66  styleDef = TH1Styles[styleName];
67  }
68 
69  hist->SetMarkerColor(GetFromManager<Color_t>(styleDef["MarkerColor"], kRed, __FILE__, __LINE__));
70  hist->SetMarkerStyle(GetFromManager<Color_t>(styleDef["MarkerStyle"], 7, __FILE__, __LINE__));
71  hist->SetFillColor(GetFromManager<Color_t>(styleDef["FillColor"], kRed, __FILE__, __LINE__));
72  hist->SetFillStyle(GetFromManager<Color_t>(styleDef["FillStyle"], 3003, __FILE__, __LINE__));
73  hist->SetLineColor(GetFromManager<Color_t>(styleDef["LineColor"], kRed, __FILE__, __LINE__));
74  hist->SetLineStyle(GetFromManager<Color_t>(styleDef["LineStyle"], 1, __FILE__, __LINE__));
75 }

Member Data Documentation

◆ _styleConfig

YAML::Node M3::Plotting::StyleManager::_styleConfig
private

Definition at line 83 of file StyleManager.h.


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