MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | 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.
 
virtual ~MaCh3Modes ()
 KS: Empty destructor.
 
void Print ()
 KS: Print info about initialised modes.
 
int GetNModes () const
 KS: Get number of modes, keep in mind actual number is +1 greater due to unknown category.
 
MaCh3Modes_t GetMode (const std::string &name)
 KS: Get mode number based on name, if mode not known you will get UNKNOWN_BAD.
 
std::string GetMaCh3ModeName (const int Index)
 KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD.
 
int GetMaCh3ModePlotColor (const int Index)
 KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD.
 
std::string GetMaCh3ModeFancyName (const int Index)
 KS: Get fancy name of mode, if mode not known you will get UNKNOWN_BAD.
 
bool IsMaCh3ModeNC (const int Index)
 DB: Get IsNC (a check whether the given MaCh3 corresponds to a Neutral Current mode)
 
std::string GetSplineSuffixFromMaCh3Mode (const int Index)
 DB: Get binned spline mode suffic from MaCh3 Mode.
 
MaCh3Modes_t GetModeFromGenerator (const int Index)
 KS: Get MaCh3 mode from generator mode.
 
std::string GetName () const
 Get class name.
 
int GetNCCModes () const
 Return count of CC modes.
 

Private Member Functions

MaCh3Modes_t EnsureModeNameRegistered (std::string const &name)
 KS: Make sure we don't have two modes with the same name.
 
void DeclareNewMode (std::string const &name, std::string const &fancyname, int PlotColor, std::vector< int > const &GenMap, bool IsNC, std::string SplineSuffix)
 KS: Add new mode.
 
void PrepareMap ()
 KS: Fill ModeMap.
 

Private Attributes

std::map< std::string, MaCh3Modes_tMode
 KS: Handy map which helps find mode number based on string.
 
std::map< MaCh3Modes_t, MaCh3ModeInfofMode
 KS: Main map storing info about used modes.
 
std::vector< int > ModeMap
 KS: Handy map helping us find MaCh3 mode based on Generator mode value.
 
std::string Title
 KS: Name of loaded modes.
 
std::string Generator
 KS: Name of generator like NEUT, NuWro etc. this is to make stuff fancy.
 
int NModes
 KS: Number of modes, keep in mind actual number is +1 greater due to unknown category.
 
int nCCModes
 DB: Number of CC modes.
 

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()

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

KS: Initialise MaCh3 modes.

Definition at line 5 of file MaCh3Modes.cpp.

5 {
6// *******************
7 // Load config
8 YAML::Node config = M3OpenConfig(filename);
9
10 std::string GetMaCh3ModeName(const int Index);
11 NModes = 0;
12 nCCModes = 0;
13
14 Title = config["Title"].as<std::string>();
15 Generator = config["GeneratorName"].as<std::string>();
16
17 auto names = Get<std::vector<std::string>>(config["MaCh3Modes"], __FILE__, __LINE__);
18
19 for(size_t i = 0; i < names.size(); i++)
20 {
21 DeclareNewMode(names[i],
22 Get<std::string>(config[names[i]]["Name"], __FILE__, __LINE__),
23 Get<int>(config[names[i]]["PlotColor"], __FILE__, __LINE__),
24 Get<std::vector<int>>(config[names[i]]["GeneratorMaping"], __FILE__, __LINE__),
25 Get<bool>(config[names[i]]["IsNC"], __FILE__, __LINE__),
26 Get<std::string>(config[names[i]]["SplineSuffix"], __FILE__, __LINE__));
27
28 if (!Get<bool>(config[names[i]]["IsNC"], __FILE__, __LINE__)) {
29 nCCModes += 1;
30 }
31 }
32 // Add unknown category, it's better to have garbage category where all undefined modes will go rather than get random crashes
33 DeclareNewMode("UNKNOWN_BAD",
34 "UNKNOWN_BAD",
35 kBlack,
36 {},
37 false,
38 "UNKNOWN_BAD");
39 // This is hack to not have bad mode
40 NModes--;
41
42 PrepareMap();
43
44 Print();
45}
std::string config
Definition: ProcessMCMC.cpp:30
Type Get(const YAML::Node &node, const std::string File, const int Line)
Get content of config file.
Definition: YamlHelper.h:265
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:560
int nCCModes
DB: Number of CC modes.
Definition: MaCh3Modes.h:101
void DeclareNewMode(std::string const &name, std::string const &fancyname, int PlotColor, std::vector< int > const &GenMap, bool IsNC, std::string SplineSuffix)
KS: Add new mode.
Definition: MaCh3Modes.cpp:89
int NModes
KS: Number of modes, keep in mind actual number is +1 greater due to unknown category.
Definition: MaCh3Modes.h:99
void Print()
KS: Print info about initialised modes.
Definition: MaCh3Modes.cpp:48
std::string Generator
KS: Name of generator like NEUT, NuWro etc. this is to make stuff fancy.
Definition: MaCh3Modes.h:97
std::string Title
KS: Name of loaded modes.
Definition: MaCh3Modes.h:95
std::string GetMaCh3ModeName(const int Index)
KS: Get normal name of mode, if mode not known you will get UNKNOWN_BAD.
Definition: MaCh3Modes.cpp:138
void PrepareMap()
KS: Fill ModeMap.
Definition: MaCh3Modes.cpp:111

◆ ~MaCh3Modes()

virtual MaCh3Modes::~MaCh3Modes ( )
inlinevirtual

KS: Empty destructor.

Definition at line 46 of file MaCh3Modes.h.

46{};

Member Function Documentation

◆ DeclareNewMode()

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

KS: Add new mode.

Definition at line 89 of file MaCh3Modes.cpp.

94 {
95// *******************
96 MaCh3ModeInfo newinfo;
97 newinfo.GeneratorMaping = GenMap;
98 newinfo.FancyName = fancyname;
99 newinfo.PlotColor = PlotColor;
100 newinfo.Name = name;
101 newinfo.IsNC = IsNC;
102 newinfo.SplineSuffix = SplineSuffix;
103
105
106 fMode.emplace(index, newinfo);
107 NModes++;
108}
Color_t PlotColor[]
int MaCh3Modes_t
Enumerator of MaCh3Mode.
Definition: MaCh3Modes.h:14
MaCh3Modes_t EnsureModeNameRegistered(std::string const &name)
KS: Make sure we don't have two modes with the same name.
Definition: MaCh3Modes.cpp:78
std::map< MaCh3Modes_t, MaCh3ModeInfo > fMode
KS: Main map storing info about used modes.
Definition: MaCh3Modes.h:90
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

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

Definition at line 78 of file MaCh3Modes.cpp.

78 {
79// *******************
80 if (Mode.count(name)) {
81 return Mode[name];
82 }
83 MaCh3Modes_t index = MaCh3Modes_t(Mode.size());
84 Mode[name] = index;
85 return index;
86}
std::map< std::string, MaCh3Modes_t > Mode
KS: Handy map which helps find mode number based on string.
Definition: MaCh3Modes.h:88

◆ GetMaCh3ModeFancyName()

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

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

Definition at line 169 of file MaCh3Modes.cpp.

169 {
170// *******************
171 // return UNKNOWN_BAD if out of boundary
172 if(Index < 0)
173 MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
174
175 if(Index > NModes)
176 {
177 MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode[NModes].Name);
178 return fMode[NModes].FancyName;
179 }
180 return fMode[Index].FancyName;
181}
#define MACH3LOG_CRITICAL
Definition: MaCh3Logger.h:26
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:22

◆ GetMaCh3ModeName()

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

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

Definition at line 138 of file MaCh3Modes.cpp.

138 {
139// *******************
140 if(Index < 0)
141 MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
142
143 // return UNKNOWN_BAD if out of boundary
144 if(Index > NModes)
145 {
146 MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode[NModes].Name);
147 return fMode[NModes].Name;
148 }
149 return fMode[Index].Name;
150}

◆ GetMaCh3ModePlotColor()

int MaCh3Modes::GetMaCh3ModePlotColor ( const int  Index)

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

Definition at line 211 of file MaCh3Modes.cpp.

211 {
212// *******************
213 // return UNKNOWN_BAD if out of boundary
214 if(Index < 0)
215 MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
216
217 if(Index > NModes)
218 {
219 MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode[NModes].PlotColor);
220 return fMode[NModes].PlotColor;
221 }
222 return fMode[Index].PlotColor;
223}

◆ GetMode()

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

KS: Get mode number based on name, if mode not known you will get UNKNOWN_BAD.

Definition at line 184 of file MaCh3Modes.cpp.

184 {
185// *******************
186 if (Mode.count(name)) {
187 return Mode[name];
188 }
189 MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", name, NModes, fMode[NModes].Name);
190
191 // return UNKNOWN_BAD
192 return NModes;
193}

◆ GetModeFromGenerator()

MaCh3Modes_t MaCh3Modes::GetModeFromGenerator ( const int  Index)

KS: Get MaCh3 mode from generator mode.

Definition at line 196 of file MaCh3Modes.cpp.

196 {
197// *******************
198 if(Index < 0)
199 MACH3LOG_CRITICAL("Mode you look for is smaller than 0 and equal to {}", Index);
200
201 if(Index >= static_cast<int>(ModeMap.size()))
202 {
203 MACH3LOG_DEBUG("Asking for mode {}, while I only have {}, returning {} mode", Index, NModes, fMode[NModes].Name);
204 return NModes;
205 }
206
207 return ModeMap[Index];
208}
std::vector< int > ModeMap
KS: Handy map helping us find MaCh3 mode based on Generator mode value.
Definition: MaCh3Modes.h:92

◆ GetName()

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

Get class name.

Definition at line 68 of file MaCh3Modes.h.

68{return "MaCh3Modes";};

◆ GetNCCModes()

int MaCh3Modes::GetNCCModes ( ) const
inline

Return count of CC modes.

Definition at line 70 of file MaCh3Modes.h.

70{return nCCModes;};

◆ 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 52 of file MaCh3Modes.h.

52{return NModes;}

◆ GetSplineSuffixFromMaCh3Mode()

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

DB: Get binned spline mode suffic from MaCh3 Mode.

Definition at line 226 of file MaCh3Modes.cpp.

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

◆ IsMaCh3ModeNC()

bool MaCh3Modes::IsMaCh3ModeNC ( const int  Index)

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

Definition at line 153 of file MaCh3Modes.cpp.

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

◆ PrepareMap()

void MaCh3Modes::PrepareMap ( )
inlineprivate

KS: Fill ModeMap.

Definition at line 111 of file MaCh3Modes.cpp.

111 {
112// *******************
113 int maxElement = 0;
114 for(int i = 0; i < NModes; ++i) {
115 for(size_t j = 0; j < fMode[i].GeneratorMaping.size(); j++) {
116 maxElement = std::max(maxElement, fMode[i].GeneratorMaping[j]);
117 }
118 }
119 ModeMap.resize(maxElement+1, Mode["UNKNOWN_BAD"]);
120
121 for(int m = 0; m < NModes; ++m) {
122 for(size_t i = 0; i < fMode[m].GeneratorMaping.size(); ++i) {
123 if(fMode[m].GeneratorMaping[i] < 0) {
124 MACH3LOG_ERROR("Negative value of Mode {} for mode {}", fMode[m].GeneratorMaping[i], fMode[m].Name);
125 throw MaCh3Exception(__FILE__ , __LINE__ );
126 }
127 if(ModeMap[fMode[m].GeneratorMaping[i]] != Mode["UNKNOWN_BAD"])
128 {
129 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);
130 throw MaCh3Exception(__FILE__ , __LINE__ );
131 }
132 ModeMap[fMode[m].GeneratorMaping[i]] = m;
133 }
134 }
135}
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:25
Custom exception class for MaCh3 errors.

◆ Print()

void MaCh3Modes::Print ( )

KS: Print info about initialised modes.

Definition at line 48 of file MaCh3Modes.cpp.

48 {
49// *******************
50 MACH3LOG_INFO("Printing MaCh3 Modes Called: {}", Title);
51
52 MACH3LOG_INFO("========================================================================");
53 MACH3LOG_INFO("{:<5} {:2} {:<20} {:2} {:<20} {:2} {:<30}", "#", "|", "Name", "|", "FancyName", "|", Generator+" Modes");
54 MACH3LOG_INFO("------------------------------------------------------------------------");
55 for(int i = 0; i < NModes; ++i) {
56 auto Name = fMode[i].Name;
57 auto FancyName = fMode[i].FancyName;
58 auto Values = fMode[i].GeneratorMaping;
59
60 std::string generatorModes;
61 for (const int& element : Values) {
62 generatorModes += std::to_string(element) + " ";
63 }
64 MACH3LOG_INFO("{:<5} {:2} {:<20} {:2} {:<20} {:2} {:<30}", i, "|", Name, "|", FancyName, "|", generatorModes);
65 }
66 MACH3LOG_INFO("========================================================================");
67
68 MACH3LOG_INFO("==========================");
69 MACH3LOG_INFO("{:<10} {:2} {:<30}", Generator + " Modes", "|", "Name");
70 MACH3LOG_INFO("--------------------------");
71 for (size_t i = 0; i < ModeMap.size(); ++i) {
72 MACH3LOG_INFO("{:<10} {:2} {:<30}", i, "|", fMode[ModeMap[i]].Name);
73 }
74 MACH3LOG_INFO("==========================");
75}
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:23

Member Data Documentation

◆ fMode

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

KS: Main map storing info about used modes.

Definition at line 90 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 97 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 88 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 92 of file MaCh3Modes.h.

◆ nCCModes

int MaCh3Modes::nCCModes
private

DB: Number of CC modes.

Definition at line 101 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 99 of file MaCh3Modes.h.

◆ Title

std::string MaCh3Modes::Title
private

KS: Name of loaded modes.

Definition at line 95 of file MaCh3Modes.h.


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