Belle II Software  release-05-02-19
SVDCoGCalibrationFunction.h
1 /**************************************************************************
2 \ * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Eugenio Paoloni, Giulia Casarosa *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <TObject.h>
14 
15 #include <cmath>
16 #include <vector>
17 
18 namespace Belle2 {
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  }
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  }
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 
137 
138  private:
139 
141  static const int nTriggerBins = 4;
142 
146  double m_bias[ nTriggerBins ] = {0};
147  double m_scale[ nTriggerBins ] = {0};
149  double pol1TBdep(double raw_time, int tb) const
150  {
151  return raw_time * m_scale[ tb % nTriggerBins] +
152  m_bias[ tb % nTriggerBins ];
153  };
155  double pol1TBdepErr(double , double raw_timeErr, int tb) const
156  {
157  return raw_timeErr * m_scale[ tb % nTriggerBins];
158  };
159 
160  //data member usefule for polinomials
161  static const int m_nPar = 6;
162  double m_par[ m_nPar ] = {0};
166  double pol3TBindep(double raw_time, int) const
167  {
168  return m_par[0] + m_par[1] * raw_time + m_par[2] * pow(raw_time, 2) + m_par[3] * pow(raw_time, 3);
169  };
171  double pol3TBindepErr(double raw_time, double raw_timeErr, int) const
172  {
173  return raw_timeErr * (m_par[1] + 2 * m_par[2] * raw_time + 3 * m_par[3] * pow(raw_time, 2));
174  };
175 
176 
179  double pol5TBindep(double raw_time, int) const
180  {
181  return m_par[0] + m_par[1] * raw_time + m_par[2] * pow(raw_time, 2) + m_par[3] * pow(raw_time, 3) + m_par[4] * pow(raw_time,
182  4) + m_par[5] * pow(raw_time, 5);
183  };
185  double pol5TBindepErr(double raw_time, double raw_timeErr, int) const
186  {
187  return raw_timeErr * (m_par[1] + 2 * m_par[2] * raw_time + 3 * m_par[3] * pow(raw_time, 2) + 4 * m_par[4] * pow(raw_time,
188  3) + 5 * m_par[5] * pow(raw_time, 4));
189  };
190 
196  double elsTBindep(double raw_time, int) const
197  {
198  if (raw_time > m_par[3] - sqrt(-m_par[2]) / 4)
199  return std::numeric_limits<float>::quiet_NaN();
200 
201  return m_par[0] + m_par[1] * raw_time + m_par[2] / (raw_time - m_par[3]);
202  };
203 
205  double elsTBindepErr(double raw_time, double raw_timeErr, int) const
206  {
207  if (raw_time > m_par[3] - sqrt(-m_par[2]) / 4)
208  return std::numeric_limits<float>::quiet_NaN();
209 
210  return raw_timeErr * (m_par[1] - m_par[2] / pow(raw_time - m_par[3], 2));
211  };
212 
214  int m_current;
215 
217  static std::vector < cogFunction > m_implementations;
218 
220  static std::vector < cogFunctionErr > m_implementationsErr;
221 
222 
223  ClassDef(SVDCoGCalibrationFunction, 6)
224  };
225 
227 }
Belle2::SVDCoGCalibrationFunction::pol1TBdep
double pol1TBdep(double raw_time, int tb) const
pol1 TB dep version implementation
Definition: SVDCoGCalibrationFunction.h:157
Belle2::SVDCoGCalibrationFunction::m_current
int m_current
current function ID
Definition: SVDCoGCalibrationFunction.h:219
Belle2::SVDCoGCalibrationFunction::cogFunction
double(SVDCoGCalibrationFunction::* cogFunction)(double, int) const
typedef of the return value of the calibration function
Definition: SVDCoGCalibrationFunction.h:38
Belle2::SVDCoGCalibrationFunction::set_scale
void set_scale(double tb0, double tb1, double tb2, double tb3)
set the trigger bin dependent scale
Definition: SVDCoGCalibrationFunction.h:101
Belle2::SVDCoGCalibrationFunction::m_bias
double m_bias[nTriggerBins]
function parameters & implementations
Definition: SVDCoGCalibrationFunction.h:154
Belle2::SVDCoGCalibrationFunction::SVDCoGCalibrationFunction
SVDCoGCalibrationFunction()
constructor
Definition: SVDCoGCalibrationFunction.h:57
Belle2::SVDCoGCalibrationFunction::pol3TBindep
double pol3TBindep(double raw_time, int) const
ID = 1, pol3TBindep VERSION: (TB independent) correctedValue = par[0] + t * par[1] + t^2 * par[2] + t...
Definition: SVDCoGCalibrationFunction.h:174
Belle2::SVDCoGCalibrationFunction::m_implementationsErr
static std::vector< cogFunctionErr > m_implementationsErr
Do not stream this, please throw it in the WC.
Definition: SVDCoGCalibrationFunction.h:228
Belle2::SVDCoGCalibrationFunction::m_nPar
static const int m_nPar
number of parameters of highest-order implemented pol (5)
Definition: SVDCoGCalibrationFunction.h:169
Belle2::SVDCoGCalibrationFunction::set_bias
void set_bias(double tb0, double tb1, double tb2, double tb3)
set the trigger bin dependent shift
Definition: SVDCoGCalibrationFunction.h:93
Belle2::SVDCoGCalibrationFunction::set_elsparameters
void set_elsparameters(double a, double b, double c, double d)
set the parameters for the ELS TB independent function
Definition: SVDCoGCalibrationFunction.h:134
Belle2::SVDCoGCalibrationFunction::cogFunctionErr
double(SVDCoGCalibrationFunction::* cogFunctionErr)(double, double, int) const
typedef of the return value of the calibration function ERROR
Definition: SVDCoGCalibrationFunction.h:41
Belle2::SVDCoGCalibrationFunction::pol3TBindepErr
double pol3TBindepErr(double raw_time, double raw_timeErr, int) const
implementation of pol3 TB indep error
Definition: SVDCoGCalibrationFunction.h:179
Belle2::SVDCoGCalibrationFunction::calibratedValueError
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
Definition: SVDCoGCalibrationFunction.h:50
Belle2::SVDCoGCalibrationFunction::pol5TBindep
double pol5TBindep(double raw_time, int) const
ID = 2, pol5TBindep VERSION: (TB independent) correctedValue = par[0] + t * par[1] + t^2 * par[2] + t...
Definition: SVDCoGCalibrationFunction.h:187
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDCoGCalibrationFunction::set_pol3parameters
void set_pol3parameters(double a, double b, double c, double d)
set the pol3 TB independent parameters
Definition: SVDCoGCalibrationFunction.h:112
Belle2::SVDCoGCalibrationFunction::set_current
void set_current(int current)
allows to choose the function version
Definition: SVDCoGCalibrationFunction.h:86
Belle2::SVDCoGCalibrationFunction::m_par
double m_par[m_nPar]
vector of parameters
Definition: SVDCoGCalibrationFunction.h:170
Belle2::SVDCoGCalibrationFunction::elsTBindepErr
double elsTBindepErr(double raw_time, double raw_timeErr, int) const
implementation of els TB indep error
Definition: SVDCoGCalibrationFunction.h:213
Belle2::SVDCoGCalibrationFunction::elsTBindep
double elsTBindep(double raw_time, int) const
ID = 3, elsTBindep VERSION: (TB independent) correctedValue = par[0] + t * par[1] + par[2]/(t - par[3...
Definition: SVDCoGCalibrationFunction.h:204
Belle2::SVDCoGCalibrationFunction::m_implementations
static std::vector< cogFunction > m_implementations
vector of fuctions for time calibration, we use the m_current
Definition: SVDCoGCalibrationFunction.h:225
Belle2::SVDCoGCalibrationFunction::m_scale
double m_scale[nTriggerBins]
trigger-bin dependent scale
Definition: SVDCoGCalibrationFunction.h:155
Belle2::SVDCoGCalibrationFunction::set_pol5parameters
void set_pol5parameters(double a, double b, double c, double d, double e, double f)
set the pol5 TB independent parameters
Definition: SVDCoGCalibrationFunction.h:122
Belle2::SVDCoGCalibrationFunction::pol1TBdepErr
double pol1TBdepErr(double, double raw_timeErr, int tb) const
implementation of pol1 TB dep error
Definition: SVDCoGCalibrationFunction.h:163
Belle2::SVDCoGCalibrationFunction::pol5TBindepErr
double pol5TBindepErr(double raw_time, double raw_timeErr, int) const
implementation of pol5 TB indep error
Definition: SVDCoGCalibrationFunction.h:193
Belle2::SVDCoGCalibrationFunction::nTriggerBins
static const int nTriggerBins
total number of trigger bins
Definition: SVDCoGCalibrationFunction.h:149
Belle2::SVDCoGCalibrationFunction
class to contain the CoG Time calibrations
Definition: SVDCoGCalibrationFunction.h:33
Belle2::SVDCoGCalibrationFunction::calibratedValue
double calibratedValue(double raw_time, int trigger_bin) const
returns the calibrated value of raw_time, depending on the trigger bin
Definition: SVDCoGCalibrationFunction.h:44