Belle II Software  release-08-01-10
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 <TObject.h>
12 
13 #include <cmath>
14 #include <vector>
15 
16 namespace Belle2 {
23  class SVDCoGCalibrationFunction : public TObject {
24 
25  public:
26 
28  typedef double (SVDCoGCalibrationFunction::*cogFunction)(double, int) const;
29 
31  typedef double (SVDCoGCalibrationFunction::*cogFunctionErr)(double, double, int) const;
32 
34  double calibratedValue(double raw_time, int trigger_bin) const
35  {
37  return (this->*f)(raw_time, trigger_bin) ;
38  }
40  double calibratedValueError(double raw_time, double raw_timeErr, int trigger_bin) const
41  {
43  return (this->*fErr)(raw_time, raw_timeErr, trigger_bin) ;
44  }
45 
48  {
49  // The m_implementations vector is static.
50  // We have to initialize it just once.
51  if (m_implementations.size() == 0) {
56  //m_implementations.push_back(
57  // &SVDCoGCalibrationFunction::betterVersion);
58  }
59 
60  // The m_implementationsErr vector is static.
61  // We have to initialize it just once.
62  if (m_implementationsErr.size() == 0) {
67  //m_implementationsErr.push_back(
68  // &SVDCoGCalibrationFunction::betterVersion);
69  }
70 
71  m_current = m_implementations.size() - 1;
72 
73  };
74 
76  void set_current(int current)
77  {
78  m_current = current;
79  }
80 
81  //SETTERS FOR function ID = 0 (pol1TBdep)
83  void set_bias(double tb0, double tb1, double tb2, double tb3)
84  {
85  m_bias[0] = tb0;
86  m_bias[1] = tb1;
87  m_bias[2] = tb2;
88  m_bias[3] = tb3;
89  }
91  void set_scale(double tb0, double tb1, double tb2, double tb3)
92  {
93  m_scale[0] = tb0;
94  m_scale[1] = tb1;
95  m_scale[2] = tb2;
96  m_scale[3] = tb3;
97  }
98 
99 
100  //SETTERS FOR function ID = 1 (pol3TBindep)
102  void set_pol3parameters(double a, double b, double c, double d)
103  {
104  m_par[ 0 ] = a;
105  m_par[ 1 ] = b;
106  m_par[ 2 ] = c;
107  m_par[ 3 ] = d;
108  }
109 
110  //SETTERS FOR function ID = 2 (pol5TBindep)
112  void set_pol5parameters(double a, double b, double c, double d, double e, double f)
113  {
114  m_par[ 0 ] = a;
115  m_par[ 1 ] = b;
116  m_par[ 2 ] = c;
117  m_par[ 3 ] = d;
118  m_par[ 4 ] = e;
119  m_par[ 5 ] = f;
120  }
121 
122  //SETTERS FOR function ID = 3 (elsTBindep)
124  void set_elsparameters(double a, double b, double c, double d)
125  {
126  m_par[ 0 ] = a;
127  m_par[ 1 ] = b;
128  m_par[ 2 ] = c;
129  m_par[ 3 ] = d;
130  }
131 
134 
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 useful 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 
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 }
class to contain the CoG Time calibrations
static const int nTriggerBins
total number of trigger bins
static std::vector< cogFunction > m_implementations
vector of fuctions 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
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.