MaCh3  2.2.3
Reference Guide
Public Member Functions | List of all members
MaCh3Modes Class Reference

KS: Class describing MaCh3 modes used in the analysis, it is being initialised from config. More...

#include <Manager/MaCh3Modes.h>

Collaboration diagram for MaCh3Modes:
[legend]

Public Member Functions

 MaCh3Modes (std::string const &filename)
 KS: Initialise MaCh3 modes using path to config. More...
 
 MaCh3Modes (const YAML::Node &config)
 KS: Initialise MaCh3 modes using config. More...
 
virtual ~MaCh3Modes ()
 KS: Empty destructor. More...
 
void Print () const
 KS: Print info about initialised modes. More...
 
int GetNModes () const
 KS: Get number of modes, keep in mind actual number is +1 greater due to unknown category. More...
 

of MaCh3 mode

KS: Make sure we don't have two modes with the same name

std::map< std::string, MaCh3Modes_tMode
 KS: Handy map which helps find mode number based on string. More...
 
std::map< MaCh3Modes_t, MaCh3ModeInfofMode
 KS: Main map storing info about used modes. More...
 
std::vector< int > ModeMap
 KS: Handy map helping us find MaCh3 mode based on Generator mode value. More...
 
std::string Title
 KS: Name of loaded modes. More...
 
std::string Generator
 KS: Name of generator like NEUT, NuWro etc. this is to make stuff fancy. More...
 
int NModes
 KS: Number of modes, keep in mind actual number is +1 greater due to unknown category. More...
 
int nCCModes
 DB: Number of CC modes. More...
 
MaCh3Modes_t GetMode (const std::string &name) const
 
std::string GetMaCh3ModeName (const int Index) const
 KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD. More...
 
int GetMaCh3ModePlotColor (const int Index) const
 KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD. More...
 
std::string GetMaCh3ModeFancyName (const int Index) const
 KS: Get fancy name of mode, if mode not known you will get UNKNOWN_BAD. More...
 
bool IsMaCh3ModeNC (const int Index) const
 DB: Get IsNC (a check whether the given MaCh3 corresponds to a Neutral Current mode) More...
 
std::string GetSplineSuffixFromMaCh3Mode (const int Index)
 DB: Get binned spline mode suffic from MaCh3 Mode. More...
 
MaCh3Modes_t GetModeFromGenerator (const int Index) const
 KS: Get MaCh3 mode from generator mode. More...
 
std::string GetName () const
 Get class name. More...
 
int GetNCCModes () const
 Return count of CC modes. More...
 
void Initialise (const YAML::Node &config)
 KS: Initialise MaCh3 modes based on provided config. More...
 
MaCh3Modes_t EnsureModeNameRegistered (std::string const &name)
 
void DeclareNewMode (std::string const &name, std::string const &fancyname, int PlotColor, std::vector< int > const &GenMap, const bool IsNC, const std::string &SplineSuffix)
 KS: Add new mode. More...
 
void PrepareMap ()
 KS: Fill ModeMap. More...
 

Detailed Description

KS: Class describing MaCh3 modes used in the analysis, it is being initialised from config.

See also
For more details, visit the Wiki.
Author
Kamil Skwarczynski
Daniel Barrow

Definition at line 41 of file MaCh3Modes.h.

Constructor & Destructor Documentation

◆ MaCh3Modes() [1/2]

MaCh3Modes::MaCh3Modes ( std::string const &  filename)

KS: Initialise MaCh3 modes using path to config.

Definition at line 5 of file MaCh3Modes.cpp.

5  {
6 // *******************
7  // Load config
8  YAML::Node config = M3OpenConfig(filename);
10 }
std::string config
Definition: ProcessMCMC.cpp:29
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:561
void Initialise(const YAML::Node &config)
KS: Initialise MaCh3 modes based on provided config.
Definition: MaCh3Modes.cpp:19

◆ MaCh3Modes() [2/2]

MaCh3Modes::MaCh3Modes ( const YAML::Node &  config)

KS: Initialise MaCh3 modes using config.

Definition at line 13 of file MaCh3Modes.cpp.

13  {
14 // *******************
16 }

◆ ~MaCh3Modes()

virtual MaCh3Modes::~MaCh3Modes ( )
inlinevirtual

KS: Empty destructor.

Definition at line 48 of file MaCh3Modes.h.

48 {};

Member Function Documentation

◆ DeclareNewMode()

void MaCh3Modes::DeclareNewMode ( std::string const &  name,
std::string const &  fancyname,
int  PlotColor,
std::vector< int > const &  GenMap,
const bool  IsNC,
const std::string &  SplineSuffix 
)
inlineprivate

KS: Add new mode.

Definition at line 107 of file MaCh3Modes.cpp.

112  {
113 // *******************
114  MaCh3ModeInfo newinfo;
115  newinfo.GeneratorMaping = GenMap;
116  newinfo.FancyName = fancyname;
117  newinfo.PlotColor = PlotColor;
118  newinfo.Name = name;
119  newinfo.IsNC = IsNC;
120  newinfo.SplineSuffix = SplineSuffix;
121 
123 
124  fMode.emplace(index, newinfo);
125  NModes++;
126 }
Color_t PlotColor[]
int MaCh3Modes_t
Enumerator of MaCh3Mode.
Definition: MaCh3Modes.h:14
int NModes
KS: Number of modes, keep in mind actual number is +1 greater due to unknown category.
Definition: MaCh3Modes.h:107
MaCh3Modes_t EnsureModeNameRegistered(std::string const &name)
Definition: MaCh3Modes.cpp:96
std::map< MaCh3Modes_t, MaCh3ModeInfo > fMode
KS: Main map storing info about used modes.
Definition: MaCh3Modes.h:98
KS: Class containing information for a single MaCh3Mode.
Definition: MaCh3Modes.h:17
std::vector< int > GeneratorMaping
Mapping between mode and generator integers.
Definition: MaCh3Modes.h:25
std::string SplineSuffix
Spline suffix.
Definition: MaCh3Modes.h:29
std::string FancyName
Mode fancy name.
Definition: MaCh3Modes.h:21
std::string Name
Mode name.
Definition: MaCh3Modes.h:19
bool IsNC
IsNC check.
Definition: MaCh3Modes.h:27
int PlotColor
Mode color for plotting purposes.
Definition: MaCh3Modes.h:23

◆ EnsureModeNameRegistered()

MaCh3Modes_t MaCh3Modes::EnsureModeNameRegistered ( std::string const &  name)
inlineprivate

Definition at line 96 of file MaCh3Modes.cpp.

96  {
97 // *******************
98  if (Mode.count(name)) {
99  return Mode[name];
100  }
101  MaCh3Modes_t index = MaCh3Modes_t(Mode.size());
102  Mode[name] = index;
103  return index;
104 }
std::map< std::string, MaCh3Modes_t > Mode
KS: Handy map which helps find mode number based on string.
Definition: MaCh3Modes.h:96

◆ GetMaCh3ModeFancyName()

std::string MaCh3Modes::GetMaCh3ModeFancyName ( const int  Index) const

KS: Get fancy name of mode, if mode not known you will get UNKNOWN_BAD.

Definition at line 186 of file MaCh3Modes.cpp.

186  {
187 // *******************
188  // return UNKNOWN_BAD if out of boundary
189  if(Index < 0)
190  MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
191 
192  if(Index > NModes)
193  {
194  MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode.at(NModes).Name);
195  return fMode.at(NModes).FancyName;
196  }
197  return fMode.at(Index).FancyName;
198 }
#define MACH3LOG_CRITICAL
Definition: MaCh3Logger.h:28
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:24

◆ GetMaCh3ModeName()

std::string MaCh3Modes::GetMaCh3ModeName ( const int  Index) const

KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD.

Definition at line 156 of file MaCh3Modes.cpp.

156  {
157 // *******************
158  if(Index < 0)
159  MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
160 
161  // return UNKNOWN_BAD if out of boundary
162  if(Index > NModes)
163  {
164  MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode.at(NModes).Name);
165  return fMode.at(NModes).Name;
166  }
167  return fMode.at(Index).Name;
168 }

◆ GetMaCh3ModePlotColor()

int MaCh3Modes::GetMaCh3ModePlotColor ( const int  Index) const

KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD.

Definition at line 228 of file MaCh3Modes.cpp.

228  {
229 // *******************
230  // return UNKNOWN_BAD if out of boundary
231  if(Index < 0)
232  MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
233 
234  if(Index > NModes)
235  {
236  MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode.at(NModes).PlotColor);
237  return fMode.at(NModes).PlotColor;
238  }
239  return fMode.at(Index).PlotColor;
240 }

◆ GetMode()

MaCh3Modes_t MaCh3Modes::GetMode ( const std::string &  name) const

Definition at line 201 of file MaCh3Modes.cpp.

201  {
202 // *******************
203  if (Mode.count(name)) {
204  return Mode.at(name);
205  }
206  MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", name, NModes, fMode.at(NModes).Name);
207 
208  // return UNKNOWN_BAD
209  return NModes;
210 }

◆ GetModeFromGenerator()

MaCh3Modes_t MaCh3Modes::GetModeFromGenerator ( const int  Index) const

KS: Get MaCh3 mode from generator mode.

Definition at line 213 of file MaCh3Modes.cpp.

213  {
214 // *******************
215  if(Index < 0)
216  MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
217 
218  if(Index >= static_cast<int>(ModeMap.size()))
219  {
220  MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode.at(NModes).Name);
221  return NModes;
222  }
223 
224  return ModeMap[Index];
225 }
std::vector< int > ModeMap
KS: Handy map helping us find MaCh3 mode based on Generator mode value.
Definition: MaCh3Modes.h:100

◆ GetName()

std::string MaCh3Modes::GetName ( ) const
inline

Get class name.

Definition at line 71 of file MaCh3Modes.h.

71 {return "MaCh3Modes";};

◆ GetNCCModes()

int MaCh3Modes::GetNCCModes ( ) const
inline

Return count of CC modes.

Definition at line 73 of file MaCh3Modes.h.

73 {return nCCModes;};
int nCCModes
DB: Number of CC modes.
Definition: MaCh3Modes.h:109

◆ GetNModes()

int MaCh3Modes::GetNModes ( ) const
inline

KS: Get number of modes, keep in mind actual number is +1 greater due to unknown category.

Definition at line 54 of file MaCh3Modes.h.

54 {return NModes;}

◆ GetSplineSuffixFromMaCh3Mode()

std::string MaCh3Modes::GetSplineSuffixFromMaCh3Mode ( const int  Index)

DB: Get binned spline mode suffic from MaCh3 Mode.

Definition at line 243 of file MaCh3Modes.cpp.

243  {
244  // *******************
245  // return UNKNOWN_BAD if out of boundary
246  if(Index < 0)
247  MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
248 
249  if(Index > NModes) {
250  MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode[NModes].SplineSuffix);
251  return fMode[NModes].SplineSuffix;
252  }
253 
254  return fMode[Index].SplineSuffix;
255 }

◆ Initialise()

void MaCh3Modes::Initialise ( const YAML::Node &  config)
inlineprivate

KS: Initialise MaCh3 modes based on provided config.

Parameters
configYAML-based config used for class initialisation

Definition at line 19 of file MaCh3Modes.cpp.

19  {
20 // *******************
21  NModes = 0;
22  nCCModes = 0;
23 
24  Title = config["Title"].as<std::string>();
25  Generator = config["GeneratorName"].as<std::string>();
26 
27  auto names = Get<std::vector<std::string>>(config["MaCh3Modes"], __FILE__, __LINE__);
28 
29  for(size_t i = 0; i < names.size(); i++)
30  {
31  DeclareNewMode(names[i],
32  Get<std::string>(config[names[i]]["Name"], __FILE__, __LINE__),
33  Get<int>(config[names[i]]["PlotColor"], __FILE__, __LINE__),
34  Get<std::vector<int>>(config[names[i]]["GeneratorMaping"], __FILE__, __LINE__),
35  Get<bool>(config[names[i]]["IsNC"], __FILE__, __LINE__),
36  Get<std::string>(config[names[i]]["SplineSuffix"], __FILE__, __LINE__));
37 
38  if (!Get<bool>(config[names[i]]["IsNC"], __FILE__, __LINE__)) {
39  nCCModes += 1;
40  }
41  }
42  // Add unknown category, it's better to have garbage category where all undefined modes will go rather than get random crashes
43  DeclareNewMode("UNKNOWN_BAD",
44  "UNKNOWN_BAD",
45  kBlack,
46  {},
47  false,
48  "UNKNOWN_BAD");
49  // This is hack to not have bad mode
50  NModes--;
51 
52  PrepareMap();
53 
54  Print();
55 }
Type Get(const YAML::Node &node, const std::string File, const int Line)
Get content of config file.
Definition: YamlHelper.h:266
void DeclareNewMode(std::string const &name, std::string const &fancyname, int PlotColor, std::vector< int > const &GenMap, const bool IsNC, const std::string &SplineSuffix)
KS: Add new mode.
Definition: MaCh3Modes.cpp:107
void Print() const
KS: Print info about initialised modes.
Definition: MaCh3Modes.cpp:58
std::string Generator
KS: Name of generator like NEUT, NuWro etc. this is to make stuff fancy.
Definition: MaCh3Modes.h:105
std::string Title
KS: Name of loaded modes.
Definition: MaCh3Modes.h:103
void PrepareMap()
KS: Fill ModeMap.
Definition: MaCh3Modes.cpp:129

◆ IsMaCh3ModeNC()

bool MaCh3Modes::IsMaCh3ModeNC ( const int  Index) const

DB: Get IsNC (a check whether the given MaCh3 corresponds to a Neutral Current mode)

Definition at line 171 of file MaCh3Modes.cpp.

171  {
172 // *******************
173  if(Index < 0)
174  MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
175 
176  // return UNKNOWN_BAD if out of boundary
177  if(Index > NModes)
178  {
179  MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode.at(NModes).Name);
180  return fMode.at(NModes).IsNC;
181  }
182  return fMode.at(Index).IsNC;
183 }

◆ PrepareMap()

void MaCh3Modes::PrepareMap ( )
inlineprivate

KS: Fill ModeMap.

Definition at line 129 of file MaCh3Modes.cpp.

129  {
130 // *******************
131  int maxElement = 0;
132  for(int i = 0; i < NModes; ++i) {
133  for(size_t j = 0; j < fMode[i].GeneratorMaping.size(); j++) {
134  maxElement = std::max(maxElement, fMode[i].GeneratorMaping[j]);
135  }
136  }
137  ModeMap.resize(maxElement+1, Mode["UNKNOWN_BAD"]);
138 
139  for(int m = 0; m < NModes; ++m) {
140  for(size_t i = 0; i < fMode[m].GeneratorMaping.size(); ++i) {
141  if(fMode[m].GeneratorMaping[i] < 0) {
142  MACH3LOG_ERROR("Negative value of Mode {} for mode {}", fMode[m].GeneratorMaping[i], fMode[m].Name);
143  throw MaCh3Exception(__FILE__ , __LINE__ );
144  }
145  if(ModeMap[fMode[m].GeneratorMaping[i]] != Mode["UNKNOWN_BAD"])
146  {
147  MACH3LOG_ERROR("Generator mode {} already defined in mode {} can't do this for mode {}", fMode[m].GeneratorMaping[i], fMode[ModeMap[fMode[m].GeneratorMaping[i]]].Name, fMode[m].Name);
148  throw MaCh3Exception(__FILE__ , __LINE__ );
149  }
150  ModeMap[fMode[m].GeneratorMaping[i]] = m;
151  }
152  }
153 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:27
Custom exception class for MaCh3 errors.

◆ Print()

void MaCh3Modes::Print ( ) const

KS: Print info about initialised modes.

Definition at line 58 of file MaCh3Modes.cpp.

58  {
59 // *******************
60  MACH3LOG_INFO("Printing MaCh3 Modes Called: {}", Title);
61 
62  MACH3LOG_INFO("========================================================================");
63  MACH3LOG_INFO("{:<5} {:2} {:<20} {:2} {:<20} {:2} {:<30}", "#", "|", "Name", "|", "FancyName", "|", Generator+" Modes");
64  MACH3LOG_INFO("------------------------------------------------------------------------");
65  for(int i = 0; i < NModes; ++i) {
66  try {
67  auto Name = fMode.at(i).Name;
68  auto FancyName = fMode.at(i).FancyName;
69  auto Values = fMode.at(i).GeneratorMaping;
70  std::string generatorModes;
71  for (const int& element : Values) {
72  generatorModes += std::to_string(element) + " ";
73  }
74  MACH3LOG_INFO("{:<5} {:2} {:<20} {:2} {:<20} {:2} {:<30}", i, "|", Name, "|", FancyName, "|", generatorModes);
75  } catch (const std::out_of_range& e) {
76  MACH3LOG_ERROR("Index {} is out of bounds for fMode. Check NModes or fMode size.", i);
77  throw MaCh3Exception(__FILE__ , __LINE__ );
78  }
79  }
80  MACH3LOG_INFO("========================================================================");
81  MACH3LOG_INFO("==========================");
82  MACH3LOG_INFO("{:<10} {:2} {:<30}", Generator + " Modes", "|", "Name");
83  MACH3LOG_INFO("--------------------------");
84  for (size_t i = 0; i < ModeMap.size(); ++i) {
85  try {
86  MACH3LOG_INFO("{:<10} {:2} {:<30}", i, "|", fMode.at(ModeMap[i]).Name);
87  } catch (const std::out_of_range& e) {
88  MACH3LOG_ERROR("ModeMap[{}] = {} is out of bounds for fMode. Check ModeMap or fMode size.", i, ModeMap[i]);
89  throw MaCh3Exception(__FILE__ , __LINE__ );
90  }
91  }
92  MACH3LOG_INFO("==========================");
93 }
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:25

Member Data Documentation

◆ fMode

std::map<MaCh3Modes_t, MaCh3ModeInfo> MaCh3Modes::fMode
private

KS: Main map storing info about used modes.

Definition at line 98 of file MaCh3Modes.h.

◆ Generator

std::string MaCh3Modes::Generator
private

KS: Name of generator like NEUT, NuWro etc. this is to make stuff fancy.

Definition at line 105 of file MaCh3Modes.h.

◆ Mode

std::map<std::string, MaCh3Modes_t> MaCh3Modes::Mode
private

KS: Handy map which helps find mode number based on string.

Definition at line 96 of file MaCh3Modes.h.

◆ ModeMap

std::vector<int> MaCh3Modes::ModeMap
private

KS: Handy map helping us find MaCh3 mode based on Generator mode value.

Definition at line 100 of file MaCh3Modes.h.

◆ nCCModes

int MaCh3Modes::nCCModes
private

DB: Number of CC modes.

Definition at line 109 of file MaCh3Modes.h.

◆ NModes

int MaCh3Modes::NModes
private

KS: Number of modes, keep in mind actual number is +1 greater due to unknown category.

Definition at line 107 of file MaCh3Modes.h.

◆ Title

std::string MaCh3Modes::Title
private

KS: Name of loaded modes.

Definition at line 103 of file MaCh3Modes.h.


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