MaCh3  2.4.2
Reference Guide
Classes | Typedefs | 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...
 

Typedefs

using FuncParFuncType = std::function< void(const double *, std::size_t)>
 HH - a shorthand type for funcpar functions. 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.

Typedef Documentation

◆ FuncParFuncType

using FuncParFuncType = std::function<void (const double*, std::size_t)>

HH - a shorthand type for funcpar functions.

Definition at line 134 of 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 169 of file ParameterStructs.h.

169  {
170  kTSpline3_red,
171  kTF1_red,
173 };
@ 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 176 of file ParameterStructs.h.

176  {
177  kTSpline3,
178  kLinear,
179  kMonotonic,
180  kAkima,
182  kLinearFunc,
184 };
@ 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 279 of file ParameterStructs.h.

279  {
280  kNorm,
281  kSpline,
282  kFunc,
283  kOsc,
284  kSystTypes
285 };
@ 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 189 of file ParameterStructs.h.

189  {
190  // **************************************************
191  std::string Func = "";
192  switch(i) {
194  Func = "([1]+[0]*x)";
195  break;
202  MACH3LOG_ERROR("Interpolation type {} not supported for TF1!", static_cast<int>(i));
203  throw MaCh3Exception(__FILE__, __LINE__);
204  default:
205  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
206  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
207  throw MaCh3Exception(__FILE__ , __LINE__ );
208  }
209  return Func;
210 }
#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 215 of file ParameterStructs.h.

215  {
216 // **************************************************
218  switch(i) {
225  break;
227  Type = RespFuncType::kTF1_red;
228  break;
230  MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
231  throw MaCh3Exception(__FILE__, __LINE__);
232  default:
233  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
234  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
235  throw MaCh3Exception(__FILE__, __LINE__);
236  }
237  return Type;
238 }
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 242 of file ParameterStructs.h.

242  {
243 // **************************************************
244  std::string name = "";
245  switch(i) {
246  // TSpline3 (third order spline in ROOT)
248  name = "TSpline3";
249  break;
251  name = "Linear";
252  break;
254  name = "Monotonic";
255  break;
256  // (Experimental) Akima_Spline (crd order spline which is allowed to be discontinuous in 2nd deriv)
258  name = "Akima";
259  break;
261  name = "KochanekBartels";
262  break;
264  name = "LinearFunc";
265  break;
267  MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
268  throw MaCh3Exception(__FILE__, __LINE__);
269  default:
270  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
271  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
272  throw MaCh3Exception(__FILE__ , __LINE__ );
273  }
274  return name;
275 }

◆ SystType_ToString()

std::string SystType_ToString ( const SystType  i)
inline

Convert a Syst type type to a string.

Definition at line 305 of file ParameterStructs.h.

305  {
306 // **************************************************
307  std::string name = "";
308  switch(i) {
309  case SystType::kNorm:
310  name = "Norm";
311  break;
312  case SystType::kSpline:
313  name = "Spline";
314  break;
315  case SystType::kFunc:
316  name = "Functional";
317  break;
318  case SystType::kOsc:
319  name = "Oscillation";
320  break;
322  MACH3LOG_ERROR("kSystTypes is not a valid SystType!");
323  throw MaCh3Exception(__FILE__, __LINE__);
324  default:
325  MACH3LOG_ERROR("UNKNOWN SYST TYPE SPECIFIED!");
326  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
327  throw MaCh3Exception(__FILE__ , __LINE__ );
328  }
329  return name;
330 }