MaCh3  2.5.0
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 M3::float_t *, 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 M3::float_t*, std::size_t)>

HH - a shorthand type for funcpar functions.

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

154  {
155  kTSpline3_red,
156  kTF1_red,
158 };
@ 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 161 of file ParameterStructs.h.

161  {
162  kTSpline3,
163  kLinear,
164  kMonotonic,
165  kAkima,
167  kLinearFunc,
169 };
@ 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 264 of file ParameterStructs.h.

264  {
265  kNorm,
266  kSpline,
267  kFunc,
268  kOsc,
269  kSystTypes
270 };
@ 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 174 of file ParameterStructs.h.

174  {
175  // **************************************************
176  std::string Func = "";
177  switch(i) {
179  Func = "([1]+[0]*x)";
180  break;
187  MACH3LOG_ERROR("Interpolation type {} not supported for TF1!", static_cast<int>(i));
188  throw MaCh3Exception(__FILE__, __LINE__);
189  default:
190  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
191  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
192  throw MaCh3Exception(__FILE__ , __LINE__ );
193  }
194  return Func;
195 }
#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 200 of file ParameterStructs.h.

200  {
201 // **************************************************
203  switch(i) {
210  break;
212  Type = RespFuncType::kTF1_red;
213  break;
215  MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
216  throw MaCh3Exception(__FILE__, __LINE__);
217  default:
218  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
219  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
220  throw MaCh3Exception(__FILE__, __LINE__);
221  }
222  return Type;
223 }
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 227 of file ParameterStructs.h.

227  {
228 // **************************************************
229  std::string name = "";
230  switch(i) {
231  // TSpline3 (third order spline in ROOT)
233  name = "TSpline3";
234  break;
236  name = "Linear";
237  break;
239  name = "Monotonic";
240  break;
241  // (Experimental) Akima_Spline (crd order spline which is allowed to be discontinuous in 2nd deriv)
243  name = "Akima";
244  break;
246  name = "KochanekBartels";
247  break;
249  name = "LinearFunc";
250  break;
252  MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
253  throw MaCh3Exception(__FILE__, __LINE__);
254  default:
255  MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
256  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
257  throw MaCh3Exception(__FILE__ , __LINE__ );
258  }
259  return name;
260 }

◆ SystType_ToString()

std::string SystType_ToString ( const SystType  i)
inline

Convert a Syst type type to a string.

Definition at line 293 of file ParameterStructs.h.

293  {
294 // **************************************************
295  std::string name = "";
296  switch(i) {
297  case SystType::kNorm:
298  name = "Norm";
299  break;
300  case SystType::kSpline:
301  name = "Spline";
302  break;
303  case SystType::kFunc:
304  name = "Functional";
305  break;
306  case SystType::kOsc:
307  name = "Oscillation";
308  break;
310  MACH3LOG_ERROR("kSystTypes is not a valid SystType!");
311  throw MaCh3Exception(__FILE__, __LINE__);
312  default:
313  MACH3LOG_ERROR("UNKNOWN SYST TYPE SPECIFIED!");
314  MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
315  throw MaCh3Exception(__FILE__ , __LINE__ );
316  }
317  return name;
318 }