MaCh3  2.6.0
Reference Guide
Classes | Enumerations | Functions
ParameterStructs.h File Reference

Definitions of generic parameter structs and utility templates for MaCh3. More...

#include <set>
#include <list>
#include <unordered_map>
#include "Manager/MaCh3Exception.h"
#include "Manager/MaCh3Logger.h"
#include "Manager/Core.h"
#include "TSpline.h"
#include "TObjString.h"
#include "TFile.h"
#include "TF1.h"
#include "TH2Poly.h"
#include "TH1.h"
Include dependency graph for ParameterStructs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TypeParameterBase
 Base class storing info for parameters types, helping unify codebase. More...
 
struct  NormParameter
 ETA - Normalisations for cross-section parameters Carrier for whether you want to apply a systematic to an event or not. More...
 
struct  FunctionalParameter
 HH - Functional parameters Carrier for whether you want to apply a systematic to an event or not. More...
 
struct  SplineParameter
 KS: Struct holding info about Spline Systematics. More...
 
struct  OscillationParameter
 KS: Struct holding info about oscillation Systematics. More...
 

Enumerations

enum  RespFuncType { kTSpline3_red , kTF1_red , kRespFuncTypes }
 Make an enum of the spline interpolation type. More...
 
enum  SplineInterpolation {
  kTSpline3 , kLinear , kMonotonic , kAkima ,
  kKochanekBartels , kLinearFunc , kSplineInterpolations
}
 Make an enum of the spline interpolation type. More...
 
enum  SystType {
  kNorm , kSpline , kFunc , kOsc ,
  kSystTypes
}
 

Functions

template<typename T , size_t N>
std::vector< T > MakeVector (const T(&data)[N])
 Template to make vector out of an array of any length. More...
 
template<typename T >
void CleanVector (T &)
 Base case: do nothing for non-vector types. More...
 
template<typename T >
void CleanVector (std::vector< T > &v)
 Recursively releases memory held by a std::vector (including nested). More...
 
template<typename T >
void CleanContainer (T &)
 Base case: do nothing for non-pointer types. More...
 
template<typename T >
void CleanContainer (T *&ptr)
 Deletes an owned raw pointer and nulls it. More...
 
template<typename T >
void CleanContainer (std::vector< T > &container)
 Recursively deletes elements stored as pointers inside containers and releases the container capacity. More...
 
std::string GetTF1 (const SplineInterpolation i)
 Get function for TF1_red. More...
 
RespFuncType SplineInterpolation_ToRespFuncType (const SplineInterpolation i)
 Convert a RespFuncType type to a SplineInterpolation. More...
 
std::string SplineInterpolation_ToString (const SplineInterpolation i)
 Convert a LLH type to a string. More...
 
std::string SystType_ToString (const SystType i)
 Convert a Syst type type to a string. More...
 

Detailed Description

Definitions of generic parameter structs and utility templates for MaCh3.

Author
Asher Kaboth
Clarence Wret
Patrick Dunne
Dan Barrow
Ed Atkin
Kamil Skwarczynski

Definition in file ParameterStructs.h.

Enumeration Type Documentation

◆ RespFuncType

Make an enum of the spline interpolation type.

Enumerator
kTSpline3_red 

Uses TSpline3_red for interpolation.

kTF1_red 

Uses TF1_red for interpolation.

kRespFuncTypes 

This only enumerates.

Definition at line 146 of file ParameterStructs.h.

146  {
147  kTSpline3_red,
148  kTF1_red,
150 };
@ kTF1_red
Uses TF1_red for interpolation.
@ kTSpline3_red
Uses TSpline3_red for interpolation.
@ kRespFuncTypes
This only enumerates.

◆ SplineInterpolation

Make an enum of the spline interpolation type.

Enumerator
kTSpline3 

Default TSpline3 interpolation.

kLinear 

Linear interpolation between knots.

kMonotonic 

EM: DOES NOT make the entire spline monotonic, only the segments.

kAkima 

EM: Akima spline iis allowed to be discontinuous in 2nd derivative and coefficients in any segment.

kKochanekBartels 

KS: Kochanek-Bartels spline: allows local control of tension, continuity, and bias.

kLinearFunc 

Liner interpolation using TF1 not spline.

kSplineInterpolations 

This only enumerates.

Definition at line 153 of file ParameterStructs.h.

153  {
154  kTSpline3,
155  kLinear,
156  kMonotonic,
157  kAkima,
159  kLinearFunc,
161 };
@ kTSpline3
Default TSpline3 interpolation.
@ kMonotonic
EM: DOES NOT make the entire spline monotonic, only the segments.
@ kSplineInterpolations
This only enumerates.
@ kKochanekBartels
KS: Kochanek-Bartels spline: allows local control of tension, continuity, and bias.
@ kLinear
Linear interpolation between knots.
@ kLinearFunc
Liner interpolation using TF1 not spline.
@ kAkima
EM: Akima spline iis allowed to be discontinuous in 2nd derivative and coefficients in any segment.

◆ SystType

enum SystType

Make an enum of systematic type recognised by covariance class

Todo:
KS: Consider using enum class, it is generally recommended as safer. It will require many static_cast
Enumerator
kNorm 

For normalisation parameters.

kSpline 

For splined parameters (1D)

kFunc 

For functional parameters.

kOsc 

For oscillation parameters.

kSystTypes 

This only enumerates.

Definition at line 256 of file ParameterStructs.h.

256  {
257  kNorm,
258  kSpline,
259  kFunc,
260  kOsc,
261  kSystTypes
262 };
@ kNorm
For normalisation parameters.
@ kSpline
For splined parameters (1D)
@ kSystTypes
This only enumerates.
@ kOsc
For oscillation parameters.
@ kFunc
For functional parameters.

Function Documentation

◆ CleanContainer() [1/3]

template<typename T >
void CleanContainer ( std::vector< T > &  container)

Recursively deletes elements stored as pointers inside containers and releases the container capacity.

This is required for structures like std::vector<T*> or deeply nested pointer containers. Without deleting first, memory is leaked; without shrink_to_fit(), capacity is retained.

Definition at line 86 of file ParameterStructs.h.

86  {
87  // *******************
88  for (auto& element : container)
89  CleanContainer(element);
90 
91  container.clear();
92  container.shrink_to_fit();
93 }
void CleanContainer(T &)
Base case: do nothing for non-pointer types.

◆ CleanContainer() [2/3]

template<typename T >
void CleanContainer ( T &  )

Base case: do nothing for non-pointer types.

Definition at line 64 of file ParameterStructs.h.

64 {}

◆ CleanContainer() [3/3]

template<typename T >
void CleanContainer ( T *&  ptr)

Deletes an owned raw pointer and nulls it.

Only use when ownership is explicit (allocated with new).

Definition at line 72 of file ParameterStructs.h.

72  {
73  // *******************
74  delete ptr;
75  ptr = nullptr;
76 }

◆ CleanVector() [1/2]

template<typename T >
void CleanVector ( std::vector< T > &  v)

Recursively releases memory held by a std::vector (including nested).

Recursively clears a vector and requests release of its unused capacity. clear() or vec = {} only destroy elements but keep the allocated buffer. For deeply nested vectors we must clean children first, then call shrink_to_fit() to ask the implementation to return the capacity.

Definition at line 52 of file ParameterStructs.h.

52  {
53 // *******************
54  for (auto& x : v)
55  CleanVector(x);
56 
57  v.clear();
58  v.shrink_to_fit();
59 }
void CleanVector(T &)
Base case: do nothing for non-vector types.

◆ CleanVector() [2/2]

template<typename T >
void CleanVector ( T &  )

Base case: do nothing for non-vector types.

Definition at line 42 of file ParameterStructs.h.

42 {}

◆ GetTF1()

std::string GetTF1 ( const SplineInterpolation  i)
inline

Get function for TF1_red.

Parameters
iInterpolation type

Definition at line 166 of file ParameterStructs.h.

166  {
167  // **************************************************
168  std::string Func = "";
169  switch(i) {
171  Func = "([1]+[0]*x)";
172  break;
179  MACH3LOG_ERROR("Interpolation type {} not supported for TF1!", static_cast<int>(i));
180  throw MaCh3Exception(__FILE__, __LINE__);
181  default:
182  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
183  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
184  throw MaCh3Exception(__FILE__ , __LINE__ );
185  }
186  return Func;
187 }
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:37
Custom exception class used throughout MaCh3.

◆ MakeVector()

template<typename T , size_t N>
std::vector<T> MakeVector ( const T(&)  data[N])

Template to make vector out of an array of any length.

Definition at line 35 of file ParameterStructs.h.

35  {
36 // *******************
37  return std::vector<T>(data, data+N);
38 }

◆ SplineInterpolation_ToRespFuncType()

RespFuncType SplineInterpolation_ToRespFuncType ( const SplineInterpolation  i)
inline

Convert a RespFuncType type to a SplineInterpolation.

Parameters
iInterpolation type

Definition at line 192 of file ParameterStructs.h.

192  {
193 // **************************************************
195  switch(i) {
202  break;
204  Type = RespFuncType::kTF1_red;
205  break;
207  MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
208  throw MaCh3Exception(__FILE__, __LINE__);
209  default:
210  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
211  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
212  throw MaCh3Exception(__FILE__, __LINE__);
213  }
214  return Type;
215 }
RespFuncType
Make an enum of the spline interpolation type.

◆ SplineInterpolation_ToString()

std::string SplineInterpolation_ToString ( const SplineInterpolation  i)
inline

Convert a LLH type to a string.

Definition at line 219 of file ParameterStructs.h.

219  {
220 // **************************************************
221  std::string name = "";
222  switch(i) {
223  // TSpline3 (third order spline in ROOT)
225  name = "TSpline3";
226  break;
228  name = "Linear";
229  break;
231  name = "Monotonic";
232  break;
233  // (Experimental) Akima_Spline (crd order spline which is allowed to be discontinuous in 2nd deriv)
235  name = "Akima";
236  break;
238  name = "KochanekBartels";
239  break;
241  name = "LinearFunc";
242  break;
244  MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
245  throw MaCh3Exception(__FILE__, __LINE__);
246  default:
247  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
248  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
249  throw MaCh3Exception(__FILE__ , __LINE__ );
250  }
251  return name;
252 }

◆ SystType_ToString()

std::string SystType_ToString ( const SystType  i)
inline

Convert a Syst type type to a string.

Definition at line 285 of file ParameterStructs.h.

285  {
286 // **************************************************
287  std::string name = "";
288  switch(i) {
289  case SystType::kNorm:
290  name = "Norm";
291  break;
292  case SystType::kSpline:
293  name = "Spline";
294  break;
295  case SystType::kFunc:
296  name = "Functional";
297  break;
298  case SystType::kOsc:
299  name = "Oscillation";
300  break;
302  MACH3LOG_ERROR("kSystTypes is not a valid SystType!");
303  throw MaCh3Exception(__FILE__, __LINE__);
304  default:
305  MACH3LOG_ERROR("UNKNOWN SYST TYPE SPECIFIED!");
306  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
307  throw MaCh3Exception(__FILE__ , __LINE__ );
308  }
309  return name;
310 }