Belle II Software development
TOPLocalCalFitter.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#include <array>
11#include <string>
12#include <top/dataobjects/TOPDigit.h>
13#include <calibration/CalibrationAlgorithm.h>
14
15class TH1;
16
17namespace Belle2 {
22 namespace TOP {
23
32 public:
33
36
38 ~TOPLocalCalFitter() override;
39
42
45
47 void setMinEntries(int minEntries)
48 {
49 m_minEntries = minEntries;
50 }
51
53 void setOutputFileName(const std::string& output)
54 {
55 m_output = output;
56 }
57
61 void setFitConstraintsFileName(const std::string& fitConstraints)
62 {
63 m_fitConstraints = fitConstraints;
64 }
65
67 void setTTSFileName(const std::string& TTSData)
68 {
69 m_TTSData = TTSData;
70 }
71
80 void setFitMode(const std::string& fitterMode)
81 {
82 if (fitterMode == "calibration")
83 B2INFO("Fitter set to calibration mode");
84 else if (fitterMode == "monitoring")
85 B2INFO("Fitter set to monitoring mode");
86 else if (fitterMode == "MC")
87 B2INFO("Fitter set to MC mode");
88 else
89 B2ERROR("Unknown fitter type " << fitterMode << ". The valid options are calibration, monitoring or MC");
90
91 m_fitterMode = fitterMode;
92 }
93
95 void fitInAmpliduteBins(bool isFitInAmplitudeBins)
96 {
97 m_isFitInAmplitudeBins = isFitInAmplitudeBins;
98 }
99
100 protected:
101
104
106 void loadMCInfoTrees();
107
109 void determineFitStatus();
110
112 void fitChannel(short slot, short channel, TH1* h);
113
121 void fitChannel(short slot, short channel, TH1* h, bool inBins, double frac);
122
124 void fitPulser(TH1*, TH1*);
125
129 void calculateChannelT0();
130
133 EResult calibrate() override;
134
135 private:
136
137 int m_minEntries = 50;
138 std::string m_output = "laserFitResult.root";
139 std::string m_fitConstraints =
140 "/group/belle2/group/detector/TOP/calibration/MCreferences/LaserMCParameters.root";
141 std::string m_TTSData =
142 "/group/belle2/group/detector/TOP/calibration/MCreferences/TTSParametrization.root";
143 std::string m_fitterMode = "calibration";
145 std::vector<float> m_binEdges = {50, 100, 150, 200, 250, 300, 350, 400, 500, 600, 800, 1000, 1500, 2000};
146 TFile* m_inputTTS = nullptr;
147 TFile* m_inputConstraints = nullptr;
148 TTree* m_treeTTS = nullptr;
150 nullptr;
151 TFile* m_histFile = nullptr;
152 TTree* m_fitTree = nullptr;
154 nullptr;
156
157 bool m_detectCrosstalk = false;
158
159 TTree* m_crosstalkTree = nullptr;
160 TTree* m_fitTree_noXtalk = nullptr;
161
162 // Per-candidate (crosstalk) variables
163 short m_sl0 = -1;
164 short m_sl1 = -1;
165 short m_ch0 = -1;
166 short m_ch1 = -1;
167 float m_ht0 = NAN;
168 float m_ht1 = NAN;
169 float m_a0 = NAN;
170 float m_a1 = NAN;
171 float m_w0 = NAN;
172 float m_w1 = NAN;
173 float m_q0 = NAN;
174 float m_q1 = NAN;
175 float m_f_q0 = NAN;
176
177 // Variables for the TTS parametrization tree
178 float m_mean2 = 0;
179 float m_sigma1 = 0;
180 float m_sigma2 = 0;
181 float m_f1 = 0;
182 float m_f2 = 0;
183 short m_pixelRow = 0;
184 short m_pixelCol = 0;
185
186 // Variables for the MC truth infos
196
197
198 // Variables for the output tree
199 float m_binLowerEdge = 0;
200 float m_binUpperEdge = 0;
201 short m_channel = 0;
202 short m_slot = 0;
203 short m_row = 0;
204 short m_col = 0;
205 short m_asic = 0;
206 short m_asicChannel = 0;
207 short m_boardstack = 0;
208 float m_peakTime = 0;
209 float m_deltaT =
210 0;
211 float m_sigma = 0.;
212 float m_fraction = 0.;
213 float m_yieldLaser = 0.;
214 float m_histoIntegral = 0.;
215
216 float m_peakTimeErr = 0;
217 float m_deltaTErr = 0;
218 float m_sigmaErr = 0.;
219 float m_fractionErr = 0.;
220 float m_yieldLaserErr = 0.;
221
222 float m_timeExtra = 0.;
223 float m_sigmaExtra = 0.;
224 float m_yieldLaserExtra = 0.;
225 float m_alphaExtra = 0.;
226 float m_nExtra = 0.;
227
228 float m_timeBackground = 0.;
229 float m_sigmaBackground = 0.;
231
232 float m_fractionMC = 0.;
233 float m_deltaTMC = 0.;
235 0.;
237
238 float m_chi2 = 0;
239 float m_rms = 0;
240
242 0.;
246 float m_channelT0Err = 0.;
247
248 float m_firstPulserTime = 0.;
250
252 0.;
254
255 short m_fitStatus = 1;
256
257 double m_width = 0;
258 double m_amplitude = 0;
259
260 // Row/Col per (slot, channel). Slots are 0..15, channels 0..511 (0-based inside code).
261 std::array<std::array<short, 512>, 16> m_rowOf{};
262 std::array<std::array<short, 512>, 16> m_colOf{};
263 bool m_hasChannelMaps{false};
264
266 inline short rowOf(short slot, short ch) const noexcept
267 {
268 return (slot >= 0 && slot < 16 && ch >= 0 && ch < 512) ? m_rowOf[slot][ch] : short(-1);
269 }
270
271 inline short colOf(short slot, short ch) const noexcept
272 {
273 return (slot >= 0 && slot < 16 && ch >= 0 && ch < 512) ? m_colOf[slot][ch] : short(-1);
274 }
275
284 void setHardwareIdentifiers(short channel)
285 {
286 TOPDigit digit;
287 digit.setChannel(channel);
288
289 m_asic = static_cast<short>(digit.getASICNumber());
290 m_asicChannel = static_cast<short>(digit.getASICChannel());
291 m_boardstack = static_cast<short>(digit.getBoardstackNumber());
292 }
293
298 inline bool areNeighbors(short slot, short a, short b, int drMax = 1, int dcMax = 1) const noexcept
299 {
300 const int dr = std::abs(rowOf(slot, a) - rowOf(slot, b));
301 const int dc = std::abs(colOf(slot, a) - colOf(slot, b));
302 return (dr + dc > 0) && (dr <= drMax) && (dc <= dcMax);
303 }
304
306 void buildChannelMaps();
307
308 };
309 } // namespace TOP
311} // namespace Belle2
EResult
The result of calibration.
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
Class to store TOP digitized hits (output of TOPDigitizer or raw data unpacker) relations to TOPSimHi...
Definition TOPDigit.h:24
unsigned int getASICNumber() const
Returns ASIC number.
Definition TOPDigit.h:342
unsigned int getASICChannel() const
Returns ASIC channel number.
Definition TOPDigit.h:336
unsigned int getBoardstackNumber() const
Returns boardstack number.
Definition TOPDigit.h:354
void setChannel(unsigned int channel)
Sets hardware channel number (0-based)
Definition TOPDigit.h:111
short m_fitStatus
Fit quality flag, propagated to the constants.
short colOf(short slot, short ch) const noexcept
Column index for (slot,channel), or -1 if out of bounds.
short m_asicChannel
ASIC channel number (0-7)
TTree * m_crosstalkTree
Output tree for crosstalk candidates.
float m_yieldLaserErr
Statistical error on yield.
float m_binLowerEdge
Lower edge of the amplitude bin in which this fit is performed.
float m_nExtraConstraints
parameter n of the tail of the extra peak
float m_chi2
Reduced chi2 of the fit.
float m_timeExtraConstraints
Position of the gaussian used to describe the extra peak on the timing distribution tail.
void fitChannel(short slot, short channel, TH1 *h)
Fits the laser light on one channel.
int m_minEntries
Minimum number of entries to perform the fit.
float m_f1
Fraction of the first gaussian on the TTS parametrization.
float m_fraction
Fraction of events in the secondary peak.
float m_sigmaExtra
Gaussian sigma of the extra peak in the timing tail.
float m_secondPulserSigma
Time resolution from the fit of the first electronic pulse, from a Gaussian fit.
float m_yieldLaserBackground
Integral of the background gaussian.
float m_sigma
Gaussian time resolution, fitted.
void setMinEntries(int minEntries)
Sets the minimum number of entries to perform the calibration in one channel.
float m_peakTimeMC
Time of the main peak in the MC simulation, i.e.
std::string m_output
Name of the output file.
float m_q0
Integrated charge for channel 0 in pair.
float m_timeBackground
Position of the gaussian used to describe the background, w/ respect to peakTime.
void loadMCInfoTrees()
loads the TTS parameters and the MC truth info
float m_deltaTMC
Time difference between the main peak and the secondary peak in the MC simulation.
float m_peakTimeErr
Statistical error on peakTime.
short m_channel
Channel number (0-511)
float m_channelT0Err
Statistical error on channelT0.
bool m_detectCrosstalk
Enables the crosstalk detection algorithm.
std::string m_TTSData
File with the TTS parametrization.
std::vector< float > m_binEdges
Amplitude bins.
float m_sigmaBackground
Sigma of the gaussian used to describe the background.
float m_peakTime
Fitted time of the main (i.e.
float m_fractionErr
Statistical error on fraction.
bool m_isFitInAmplitudeBins
Enables the fit in amplitude bins.
TOPLocalCalFitter & operator=(const TOPLocalCalFitter &)=delete
Assignment operator (disabled)
void setHardwareIdentifiers(short channel)
Set the hardware identifiers corresponding to a TOP channel.
TOPLocalCalFitter(const TOPLocalCalFitter &)=delete
Copy constructor (disabled)
float m_alphaExtra
alpha parameter of the tail of the extra peak.
float m_a0
Amplitude for channel 0 in pair.
float m_rms
RMS of the histogram used for the fit.
float m_mean2
Position of the second gaussian of the TTS parametrization with respect to the first one.
std::string m_fitConstraints
File with the Fit constraints.
bool m_hasChannelMaps
Flag indicating if channel->(row,col) maps have been built.
TTree * m_timewalkTree
Output of the fitter.
void setFitConstraintsFileName(const std::string &fitConstraints)
Sets the name of the root file containing the laser MC time corrections and the fit constraints.
float m_w0
Width for channel 0 in pair.
float m_yieldLaser
Total number of laser hits from the fitting function integral.
bool areNeighbors(short slot, short a, short b, int drMax=1, int dcMax=1) const noexcept
Return true if channels a and b are neighbors on the same slot in row/col space.
TFile * m_inputTTS
File containing m_treeTTS.
float m_nExtra
parameter n of the tail of the extra peak
float m_ht1
Hit time for channel 1 in pair.
void fitInAmpliduteBins(bool isFitInAmplitudeBins)
Enables the fit amplitude bins.
float m_alphaExtraConstraints
alpha parameter of the tail of the extra peak.
float m_channelT0
Raw, channelT0 calibration, defined as peakTime-peakTimeMC.
short m_ch1
Channel number (0-511)
float m_sigmaErr
Statistical error on sigma.
float m_binUpperEdge
Upper edge of the amplitude bin in which this fit is performed.
float m_f_q0
Fraction of charge on channel 0 in pair.
TFile * m_histFile
Output of the fitter.
TTree * m_treeConstraints
Input to the fitter.
float m_sigmaExtraConstraints
Width of the gaussian used to describe the extra peak on the timing distribution tail.
float m_w1
Width for channel 1 in pair.
float m_firstPulserSigma
Time resolution from the fit of the first electronic pulse, from a Gaussian fit.
float m_ht0
Hit time for channel 0 in pair.
std::array< std::array< short, 512 >, 16 > m_colOf
Column index for (slot,channel), or -1 if out of bounds.
short rowOf(short slot, short ch) const noexcept
Row index for (slot,channel), or -1 if out of bounds.
float m_q1
Integrated charge for channel 1 in pair.
float m_deltaT
Time difference between the main peak and the secondary peak.
TTree * m_fitTree
Output of the fitter.
float m_f2
Fraction of the second gaussian on the TTS parametrization.
void setOutputFileName(const std::string &output)
Sets the name of the output root file.
void determineFitStatus()
determines if the constant obtained by the fit are good or not
void buildChannelMaps()
Build (row,col) lookup tables from the TTS tree; call after opening m_treeTTS.
void setFitMode(const std::string &fitterMode)
Sets the fitter mode.
float m_secondPulserTime
Average time of the second electronic pulse respect to the reference pulse, from a gaussian fit.
short m_boardstack
Boardstack number (0-3)
float m_peakTimeConstraints
Time of the main laser peak in the MC simulation (aka MC correction)
float m_sigma1
Width of the first gaussian on the TTS parametrization.
float m_fractionMC
Fraction of events in the secondary peak form the MC simulation.
float m_sigmaBackgroundConstraints
Sigma of the gaussian used to describe the background.
TTree * m_treeTTS
Input to the fitter.
void setupOutputTreeAndFile()
prepares the output tree
~TOPLocalCalFitter() override
Destructor.
TTree * m_fitTree_noXtalk
Output tree for non-crosstalk candidates.
float m_timeBackgroundConstraints
Position of the gaussian used to describe the background, w/ respect to peakTime.
short m_ch0
Channel number (0-511)
TFile * m_inputConstraints
File containing m_treeConstraints.
float m_deltaTErr
Statistical error on deltaT.
void calculateChannelT0()
Calculates the commonT0 calibration after the fits have been done.
std::array< std::array< short, 512 >, 16 > m_rowOf
Row index for (slot,channel), or -1 if out of bounds.
float m_firstPulserTime
Average time of the first electronic pulse respect to the reference pulse, from a Gaussian fit.
float m_histoIntegral
Integral of the fitted histogram.
float m_yieldLaserExtra
Integral of the extra peak.
float m_sigma2
Width of the second gaussian on the TTS parametrization.
float m_a1
Amplitude for channel 1 in pair.
void fitPulser(TH1 *, TH1 *)
Fits the two pulsers.
EResult calibrate() override
Runs the algorithm on events.
float m_timeExtra
Position of the extra peak seen in the timing tail, w/ respect to peakTime.
float m_fractionConstraints
Fraction of the main peak.
float m_deltaTConstraints
Distance between the main and the secondary laser peak.
void setTTSFileName(const std::string &TTSData)
Sets the name of the root file containing the TTS parameters.
Abstract base class for different kinds of events.