MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MaCh3Plotting::StyleManager Class Reference

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

#include <Plotting/plottingUtils/styleManager.h>

Public Member Functions

 StyleManager (std::string configName)
 Constructor.
 
 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.
 
std::string prettifySampleName (const std::string &origName) const
 Convert hideous and vulgar internal sample name into a beautiful presentable name.
 
void setPalette (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].
 
void setPalette (std::string configStyleName) const
 Set the root colour palette to one of the ones defined in the style config.
 
void setTH1Style (TH1 *hist, std::string styleName) const
 Set the style of a TH1 to one of the styles defined in the style config.
 

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 25 of file styleManager.h.

Constructor & Destructor Documentation

◆ StyleManager() [1/3]

MaCh3Plotting::StyleManager::StyleManager ( std::string  configName)

Constructor.

Parameters
configNameThe style config to read from

Definition at line 4 of file styleManager.cpp.

4 {
5 _styleConfig = YAML::LoadFile(styleConfigName);
6}

◆ StyleManager() [2/3]

MaCh3Plotting::StyleManager::StyleManager ( const StyleManager )
delete

◆ StyleManager() [3/3]

MaCh3Plotting::StyleManager::StyleManager ( StyleManager &&  )
default

◆ ~StyleManager()

MaCh3Plotting::StyleManager::~StyleManager ( )
inline

Definition at line 35 of file styleManager.h.

35 {
36 MACH3LOG_DEBUG("##### Deleting StyleManager Instance #####");
37 }
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:22

Member Function Documentation

◆ prettifyName()

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

Definition at line 8 of file styleManager.cpp.

8 {
9 std::string prettyName = origName;
10
11 YAML::Node prettyNames = _styleConfig["PrettyNames"][nameType];
12
13 if (prettyNames[origName])
14 {
15 prettyName = prettyNames[origName].as<std::string>();
16 }
17
18 return prettyName;
19}

◆ prettifyParamName()

std::string MaCh3Plotting::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 44 of file styleManager.h.

44 {
45 return prettifyName(origName, "parameters");
46 };
std::string prettifyName(const std::string &origName, const std::string &nameType) const
Definition: styleManager.cpp:8

◆ prettifySampleName()

std::string MaCh3Plotting::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 53 of file styleManager.h.

53 {
54 return prettifyName(origName, "samples");
55 };

◆ setPalette() [1/2]

void MaCh3Plotting::StyleManager::setPalette ( 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 21 of file styleManager.cpp.

21 {
22 // set the colour palette to one of the root palettes
23 gStyle->SetPalette(rootPlotStyle);
24}

◆ setPalette() [2/2]

void MaCh3Plotting::StyleManager::setPalette ( 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 26 of file styleManager.cpp.

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

◆ setTH1Style()

void MaCh3Plotting::StyleManager::setTH1Style ( TH1 *  hist,
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 55 of file styleManager.cpp.

55 {
56 // get the definition of the provided style from the config file
57 YAML::Node TH1Styles = _styleConfig["TH1Styles"];
58 YAML::Node styleDef = TH1Styles[styleName];
59
60 if (styleDef["MarkerColor"])
61 {
62 hist->SetMarkerColor(styleDef["MarkerColor"].as<Color_t>());
63 }
64 if (styleDef["MarkerStyle"])
65 {
66 hist->SetMarkerStyle(styleDef["MarkerStyle"].as<Color_t>());
67 }
68 if (styleDef["FillColor"])
69 {
70 hist->SetFillColor(styleDef["FillColor"].as<Color_t>());
71 }
72 if (styleDef["FillStyle"])
73 {
74 hist->SetFillStyle(styleDef["FillStyle"].as<Color_t>());
75 }
76 if (styleDef["LineColor"])
77 {
78 hist->SetLineColor(styleDef["LineColor"].as<Color_t>());
79 }
80 if (styleDef["LineStyle"])
81 {
82 hist->SetLineStyle(styleDef["LineStyle"].as<Color_t>());
83 }
84}

Member Data Documentation

◆ _styleConfig

YAML::Node MaCh3Plotting::StyleManager::_styleConfig
private

Definition at line 74 of file styleManager.h.


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