MaCh3  2.4.2
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.

The class provides a translation layer between generator-specific interaction mode definitions and the analysis-level categories used inside MaCh3.

Different neutrino generators use different numbering and naming conventions. Additionally, an analysis may wish to group or redefine these modes. MaCh3Modes allows the user to define an experiment-specific mapping via a YAML configuration file.

The class builds:

Configuration Example

Example YAML configuration used to initialise the modes:

#########################################
Title: "T2K Interaction modes"
GeneratorName: "NEUT"
MaCh3Modes: [
"CCQE",
"CC1pipm",
"2p2h",
]
CCQE:
Name: "CCQE"
GeneratorMaping: [1] # 1 = CCQE
CC1pipm:
Name: "CC 1#pi^{#pm}"
GeneratorMaping: [11, 13] # 11 = CC1pi+1p, 13 = CC1pi+1n
2p2h:
Name: "2p2h"
GeneratorMaping: [2] # 2 = (Nieves) MEC / 2p2h

Example Initialisation Dump

After loading the configuration, MaCh3 produces a mapping table like:

Printing MaCh3 Modes Called: T2K Interaction modes
===============================================================
# | Name | FancyName | NEUT Modes
---------------------------------------------------------------
0 | CCQE | CCQE | 1
1 | CC1pipm | CC 1#pi^{#pm} | 11 13
2 | 2p2h | 2p2h | 2
===============================================================
NEUT Modes | Name
---------------------------
0 | UNKNOWN_BAD
1 | CCQE
2 | 2p2h
3–10 | UNKNOWN_BAD
11 | CC1pipm
12 | UNKNOWN_BAD
13 | CC1pipm
===============================================================

Unknown Category Handling

Generators such as NEUT define many interaction codes that may not be used in a given analysis. Any generator mode not explicitly mapped is assigned to UNKNOWN_BAD.

This behaviour:

Usage Examples

Access a specific mode:

MaCh3Modes_t kMaCh3_CCQE = Modes->GetMode("CCQE");
int MaCh3Modes_t
Enumerator of MaCh3Mode.
Definition: MaCh3Modes.h:14

Loop over all defined modes:

for (int j = 0; j < Modes->GetNModes() + 1; ++j) {
Modes->GetMaCh3ModeName(j);
}
Note
If you attempt to access a mode outside the defined range, the class will return the UNKNOWN_BAD category instead of throwing.
Author
Kamil Skwarczynski
Daniel Barrow

Definition at line 135 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:30
#define M3OpenConfig(filename)
Macro to simplify calling LoadYaml with file and line info.
Definition: YamlHelper.h:589
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 142 of file MaCh3Modes.h.

142 {};

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 }
constexpr Color_t PlotColor[]
int NModes
KS: Number of modes, keep in mind actual number is +1 greater due to unknown category.
Definition: MaCh3Modes.h:201
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:192
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:190

◆ 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:38
#define MACH3LOG_DEBUG
Definition: MaCh3Logger.h:34

◆ 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:194

◆ GetName()

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

Get class name.

Definition at line 165 of file MaCh3Modes.h.

165 {return "MaCh3Modes";};

◆ GetNCCModes()

int MaCh3Modes::GetNCCModes ( ) const
inline

Return count of CC modes.

Definition at line 167 of file MaCh3Modes.h.

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

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

148 {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:291
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:199
std::string Title
KS: Name of loaded modes.
Definition: MaCh3Modes.h:197
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:37
Custom exception class used throughout MaCh3.

◆ 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:35

Member Data Documentation

◆ fMode

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

KS: Main map storing info about used modes.

Definition at line 192 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 199 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 190 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 194 of file MaCh3Modes.h.

◆ nCCModes

int MaCh3Modes::nCCModes
private

DB: Number of CC modes.

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

◆ Title

std::string MaCh3Modes::Title
private

KS: Name of loaded modes.

Definition at line 197 of file MaCh3Modes.h.


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