Belle II Software development
SVDCoGCalibrationFunction.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/utilities/MathHelpers.h>
12
13#include <TObject.h>
14
15#include <cmath>
16#include <vector>
17
18namespace Belle2 {
23
25 class SVDCoGCalibrationFunction : public TObject {
26
27 public:
28
30 typedef double (SVDCoGCalibrationFunction::*cogFunction)(double, int) const;
31
33 typedef double (SVDCoGCalibrationFunction::*cogFunctionErr)(double, double, int) const;
34
36 double calibratedValue(double raw_time, int trigger_bin) const
37 {
39 return (this->*f)(raw_time, trigger_bin) ;
40 }
41
42 double calibratedValueError(double raw_time, double raw_timeErr, int trigger_bin) const
43 {
45 return (this->*fErr)(raw_time, raw_timeErr, trigger_bin) ;
46 }
47
50 {
51 // The m_implementations vector is static.
52 // We have to initialize it just once.
53 if (m_implementations.size() == 0) {
58 //m_implementations.push_back(
59 // &SVDCoGCalibrationFunction::betterVersion);
60 }
61
62 // The m_implementationsErr vector is static.
63 // We have to initialize it just once.
64 if (m_implementationsErr.size() == 0) {
69 //m_implementationsErr.push_back(
70 // &SVDCoGCalibrationFunction::betterVersion);
71 }
72
73 m_current = m_implementations.size() - 1;
74
75 };
76
78 void set_current(int current)
79 {
80 m_current = current;
81 }
82
83 //SETTERS FOR function ID = 0 (pol1TBdep)
85 void set_bias(double tb0, double tb1, double tb2, double tb3)
86 {
87 m_bias[0] = tb0;
88 m_bias[1] = tb1;
89 m_bias[2] = tb2;
90 m_bias[3] = tb3;
91 }
92
93 void set_scale(double tb0, double tb1, double tb2, double tb3)
94 {
95 m_scale[0] = tb0;
96 m_scale[1] = tb1;
97 m_scale[2] = tb2;
98 m_scale[3] = tb3;
99 }
100
101
102 //SETTERS FOR function ID = 1 (pol3TBindep)
104 void set_pol3parameters(double a, double b, double c, double d)
105 {
106 m_par[ 0 ] = a;
107 m_par[ 1 ] = b;
108 m_par[ 2 ] = c;
109 m_par[ 3 ] = d;
110 }
111
112 //SETTERS FOR function ID = 2 (pol5TBindep)
114 void set_pol5parameters(double a, double b, double c, double d, double e, double f)
115 {
116 m_par[ 0 ] = a;
117 m_par[ 1 ] = b;
118 m_par[ 2 ] = c;
119 m_par[ 3 ] = d;
120 m_par[ 4 ] = e;
121 m_par[ 5 ] = f;
122 }
123
124 //SETTERS FOR function ID = 3 (elsTBindep)
126 void set_elsparameters(double a, double b, double c, double d)
127 {
128 m_par[ 0 ] = a;
129 m_par[ 1 ] = b;
130 m_par[ 2 ] = c;
131 m_par[ 3 ] = d;
132 }
133
136
139
140 private:
141
143 static const int nTriggerBins = 4;
144
146
148 double m_bias[ nTriggerBins ] = {0};
149 double m_scale[ nTriggerBins ] = {0};
151 double pol1TBdep(double raw_time, int tb) const
152 {
153 return raw_time * m_scale[ tb % nTriggerBins] +
154 m_bias[ tb % nTriggerBins ];
155 };
156
157 double pol1TBdepErr(double, double raw_timeErr, int tb) const
158 {
159 return raw_timeErr * m_scale[ tb % nTriggerBins];
160 };
161
162 //data member useful for polynomials
163 static const int m_nPar = 6;
164 double m_par[ m_nPar ] = {0};
165
168 double pol3TBindep(double raw_time, int) const
169 {
170 return m_par[0] + m_par[1] * raw_time + m_par[2] * square(raw_time) + m_par[3] * cube(raw_time);
171 };
172
173 double pol3TBindepErr(double raw_time, double raw_timeErr, int) const
174 {
175 return raw_timeErr * (m_par[1] + 2 * m_par[2] * raw_time + 3 * m_par[3] * square(raw_time));
176 };
177
178
181 double pol5TBindep(double raw_time, int) const
182 {
183 return m_par[0] + m_par[1] * raw_time + m_par[2] * square(raw_time) + m_par[3] * cube(raw_time) + m_par[4] * pow4(
184 raw_time) + m_par[5] * pow5(raw_time);
185 };
186
187 double pol5TBindepErr(double raw_time, double raw_timeErr, int) const
188 {
189 return raw_timeErr * (m_par[1] + 2 * m_par[2] * raw_time + 3 * m_par[3] * square(raw_time) + 4 * m_par[4] * cube(
190 raw_time) + 5 * m_par[5] * pow4(raw_time));
191 };
192
198 double elsTBindep(double raw_time, int) const
199 {
200 if (raw_time > m_par[3] - sqrt(-m_par[2]) / 4)
201 return std::numeric_limits<float>::quiet_NaN();
202
203 return m_par[0] + m_par[1] * raw_time + m_par[2] / (raw_time - m_par[3]);
204 };
205
207 double elsTBindepErr(double raw_time, double raw_timeErr, int) const
208 {
209 if (raw_time > m_par[3] - sqrt(-m_par[2]) / 4)
210 return std::numeric_limits<float>::quiet_NaN();
211
212 return raw_timeErr * (m_par[1] - m_par[2] / square(raw_time - m_par[3]));
213 };
214
217
219 static std::vector < cogFunction > m_implementations;
220
222 static std::vector < cogFunctionErr > m_implementationsErr;
223
224
225 ClassDef(SVDCoGCalibrationFunction, 6)
226 };
227
229}
class to contain the CoG Time calibrations
static const int nTriggerBins
total number of trigger bins
static std::vector< cogFunction > m_implementations
vector of functions for time calibration, we use the m_current
double pol3TBindep(double raw_time, int) const
ID = 1, pol3TBindep VERSION: (TB independent) correctedValue = par[0] + t * par[1] + t^2 * par[2] + t...
double pol1TBdep(double raw_time, int tb) const
pol1 TB dep version implementation
void set_elsparameters(double a, double b, double c, double d)
set the parameters for the ELS TB independent function
double m_bias[nTriggerBins]
function parameters & implementations
double pol5TBindep(double raw_time, int) const
ID = 2, pol5TBindep VERSION: (TB independent) correctedValue = par[0] + t * par[1] + t^2 * par[2] + t...
double m_scale[nTriggerBins]
trigger-bin dependent scale
double pol3TBindepErr(double raw_time, double raw_timeErr, int) const
implementation of pol3 TB indep error
static const int m_nPar
number of parameters of highest-order implemented pol (5)
SVDCoGCalibrationFunction & operator=(const Belle2::SVDCoGCalibrationFunction &a)
operator =
double pol1TBdepErr(double, double raw_timeErr, int tb) const
implementation of pol1 TB dep error
static std::vector< cogFunctionErr > m_implementationsErr
Do not stream this, please throw it in the WC.
double(SVDCoGCalibrationFunction::* cogFunctionErr)(double, double, int) const
typedef of the return value of the calibration function ERROR
double calibratedValue(double raw_time, int trigger_bin) const
returns the calibrated value of raw_time, depending on the trigger bin
double calibratedValueError(double raw_time, double raw_timeErr, int trigger_bin) const
returns the error of the calibrated value of raw_time, depending on the trigger bin
double pol5TBindepErr(double raw_time, double raw_timeErr, int) const
implementation of pol5 TB indep error
double elsTBindep(double raw_time, int) const
ID = 3, elsTBindep VERSION: (TB independent) correctedValue = par[0] + t * par[1] + par[2]/(t - par[3...
double elsTBindepErr(double raw_time, double raw_timeErr, int) const
implementation of els TB indep error
void set_scale(double tb0, double tb1, double tb2, double tb3)
set the trigger bin dependent scale
double m_par[m_nPar]
vector of parameters
void set_pol5parameters(double a, double b, double c, double d, double e, double f)
set the pol5 TB independent parameters
void set_current(int current)
allows to choose the function version
void set_pol3parameters(double a, double b, double c, double d)
set the pol3 TB independent parameters
double(SVDCoGCalibrationFunction::* cogFunction)(double, int) const
typedef of the return value of the calibration function
void set_bias(double tb0, double tb1, double tb2, double tb3)
set the trigger bin dependent shift
constexpr T cube(const T &x)
Calculate the cube of the input.
Definition MathHelpers.h:29
constexpr T square(const T &x)
Calculate the square of the input.
Definition MathHelpers.h:21
constexpr T pow5(const T &x)
Calculate the fifth power of the input.
Definition MathHelpers.h:46
constexpr T pow4(const T &x)
Calculate the fourth power of the input.
Definition MathHelpers.h:37
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28
Abstract base class for different kinds of events.