Belle II Software development
TOPTimeBaseCalibratorModule.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/core/Module.h>
12#include <framework/datastore/StoreArray.h>
13#include <top/dataobjects/TOPDigit.h>
14
15#include <string>
16#include <vector>
17#include <TMatrixDSym.h>
18#include <TH1F.h>
19#include <TH2F.h>
20
21namespace Belle2 {
30 struct Hit {
31 double time = 0;
32 double timeErr = 0;
33 int pulseHeight = 0;
34 double pulseWidth = 0;
39 Hit(double t, double et, int height, double width)
40 {
41 time = t;
42 timeErr = et;
43 pulseHeight = height;
44 pulseWidth = width;
45 }
46 };
47
51 struct TwoTimes {
52 float t1 = 0;
53 float t2 = 0;
54 float sigma = 0;
55 bool good = false;
60 TwoTimes(double time1, double time2, double sig)
61 {
62 if (time1 < time2) {
63 t1 = time1;
64 t2 = time2;
65 } else {
66 t1 = time2;
67 t2 = time1;
68 }
69 sigma = sig;
70 good = true;
71 }
72 };
73
78
79 public:
80
85
90
95 virtual void initialize() override;
96
101 virtual void beginRun() override;
102
106 virtual void event() override;
107
112 virtual void endRun() override;
113
118 virtual void terminate() override;
119
120 private:
121
125 enum {c_NumChannels = 512,
127 c_NumScrodChannels = c_NumChannels / c_NumBoardstacks,
130 };
131
142 bool calibrateChannel(std::vector<TwoTimes>& ntuple,
143 unsigned scrodID, unsigned scrodChannel,
144 TH1F& Hchi2, TH1F& Hndf, TH1F& HDeltaT);
145
157 bool matrixInversion(const std::vector<TwoTimes>& ntuple,
158 unsigned scrodID, unsigned scrodChannel,
159 double meanTimeDifference,
160 TH1F& Hchi2, TH1F& Hndf, TH1F& HDeltaT);
161
174 bool iterativeTBC(const std::vector<TwoTimes>& ntuple,
175 unsigned scrodID, unsigned scrodChannel,
176 double meanTimeDifference,
177 TH1F& Hchi2, TH1F& Hndf, TH1F& HDeltaT);
178
185 void Iteration(const std::vector<TwoTimes>& ntuple, std::vector<double>& xval);
186
192 double Chisq(const std::vector<TwoTimes>& ntuple, const std::vector<double>& xxval);
193
202 void saveAsHistogram(const std::vector<double>& vec,
203 const std::string& name,
204 const std::string& title,
205 const std::string& xTitle = "",
206 const std::string& yTitle = "") const;
207
217 void saveAsHistogram(const std::vector<double>& vec,
218 const std::vector<double>& err,
219 const std::string& name,
220 const std::string& title,
221 const std::string& xTitle = "",
222 const std::string& yTitle = "") const;
223
230 void saveAsHistogram(const TMatrixDSym& M,
231 const std::string& name,
232 const std::string& title) const;
233
234
235 int m_moduleID = 0;
236 double m_minTimeDiff = 0;
237 double m_maxTimeDiff = 0;
238 unsigned m_minHits = 0;
239 unsigned m_numIterations = 100;
240 std::string m_directoryName;
241 unsigned m_method = 0;
242 bool m_useFallingEdge = false;
243 bool m_saveMatrix = false;
245 std::vector<TwoTimes> m_ntuples[c_NumChannels];
246 double m_syncTimeBase = 0;
252 // parameters for iTBC
253 int m_good = 0;
254 double m_dt_min = 20.0;
255 double m_dt_max = 24.0;
256 double m_dev_step = 0.001;
257 double m_xstep = 0.020;
258 double m_dchi2dxv = 0.0;
259 double m_change_xstep = 0.015;
260 double m_new_xstep = 2.0 * m_xstep;
261 double m_min_binwidth = 0.05;
262 double m_max_binwidth = 2.0;
263 double m_dchi2_min = 0.2;
264 unsigned m_conv_iter = 100;
265 double m_deltamin = 0.01 * 0.01;
266 double m_DtSigma = 0.0424;
269 };
270
272} // Belle2 namespace
273
Base class for Modules.
Definition: Module.h:72
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
double m_deltamin
minumum chisq change in an iteration.
double m_xstep
unit for an interation of delta(X_s)
TH2F m_calPulseSecond
pulse height versus width of the second calibration pulse
double m_sigm2_exp
(sigma_0(dT))**2 for nomarlization of chisq = sum{dT^2/sigma^2}
std::vector< TwoTimes > m_ntuples[c_NumChannels]
channel wise data
double m_min_binwidth
minimum time interval of one sample
TH2F m_goodHits
pulse height versus width of all good hits
double m_syncTimeBase
synchronization time (two ASIC windows)
double m_new_xstep
m_xstep = m_new_xstep if m_dchi2dxv < m_change_step
double m_dt_min
minimum Delta T of raw calpulse
bool m_saveMatrix
if true, save also matrix and its inverse in a root file
double m_dt_max
maximum Delta T of raw calpulse
double m_dev_step
a step size to calculate the value of d(chisq)/dxval
double m_DtSigma
a reference resolution of sigma_0(dT)=42.4 ps from Run3524
unsigned m_conv_iter
Number of iteration with chisq changes less than deltamin.
@ c_NumBoardstacks
number of boardstacks per module
@ c_NumChannels
number of channels per module
@ c_TimeAxisSize
number of samples to calibrate
double m_dchi2dxv
rms of 255 dchi2/dxval values
double m_max_binwidth
maximum time interval of one sample
unsigned m_minHits
minimal required hits per channel
double m_minTimeDiff
lower bound for time difference [samples]
double m_change_xstep
update m_xstep if m_dchi2dxv < m_change_step
StoreArray< TOPDigit > m_digits
collection of digits
unsigned m_numIterations
Number of Iterations of iTBC.
std::string m_directoryName
directory name for the output root files
int m_good
good events used for chisq cal.
TH2F m_calPulseFirst
pulse height versus width of the first calibration pulse
double m_dchi2_min
quit if chisq increase in iteratons is larger than this value.
bool m_useFallingEdge
if true, use falling edge instead of rising
double m_maxTimeDiff
upper bound for time difference [samples]
bool matrixInversion(const std::vector< TwoTimes > &ntuple, unsigned scrodID, unsigned scrodChannel, double meanTimeDifference, TH1F &Hchi2, TH1F &Hndf, TH1F &HDeltaT)
Method by matrix inversion.
bool calibrateChannel(std::vector< TwoTimes > &ntuple, unsigned scrodID, unsigned scrodChannel, TH1F &Hchi2, TH1F &Hndf, TH1F &HDeltaT)
calibrate single channel
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
void Iteration(const std::vector< TwoTimes > &ntuple, std::vector< double > &xval)
Iteration function called by iterativeTBC()
double Chisq(const std::vector< TwoTimes > &ntuple, const std::vector< double > &xxval)
Return the chisqure of one set of TBC constants (xval) in iTBC calculaton.
void saveAsHistogram(const std::vector< double > &vec, const std::string &name, const std::string &title, const std::string &xTitle="", const std::string &yTitle="") const
Save vector to histogram and write it out.
bool iterativeTBC(const std::vector< TwoTimes > &ntuple, unsigned scrodID, unsigned scrodChannel, double meanTimeDifference, TH1F &Hchi2, TH1F &Hndf, TH1F &HDeltaT)
Method by iteration of chi2 minimization.
Abstract base class for different kinds of events.
Structure to hold some of the calpulse data.
double pulseWidth
pulse width [ns]
int pulseHeight
pulse height [ADC counts]
Hit(double t, double et, int height, double width)
Full constructor.
double timeErr
raw time uncertainty [samples]
double time
raw time [samples]
Structure to hold calpulse raw times expressed in samples since sample 0 of window 0.
float t2
time of the second pulse [samples]
float t1
time of the first pulse [samples]
float sigma
uncertainty of time difference (r.m.s.)
TwoTimes(double time1, double time2, double sig)
Full constructor.