Belle II Software  release-05-02-19
TOPLocalCalFitter.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * *
6  * Author: The Belle II Collaboration *
7  * Contributors: Umberto Tamponi *
8  * *
9  * This software is provided "as is" without any warranty. *
10  **************************************************************************/
11 
12 #pragma once
13 #include <top/calibration/TOPLocalCalFitter.h>
14 #include <calibration/CalibrationAlgorithm.h>
15 
16 namespace Belle2 {
21  namespace TOP {
22 
30  class TOPLocalCalFitter : public CalibrationAlgorithm {
31  public:
32 
35 
37  virtual ~TOPLocalCalFitter() {}
38 
40  void setMinEntries(int minEntries)
41  {
42  m_minEntries = minEntries;
43  }
44 
46  void setOutputFileName(const std::string& output)
47  {
48  m_output = output;
49  }
50 
54  void setFitConstraintsFileName(const std::string& fitConstraints)
55  {
56  m_fitConstraints = fitConstraints;
57  }
58 
60  void setTTSFileName(const std::string& TTSData)
61  {
62  m_TTSData = TTSData;
63  }
64 
73  void setFitMode(const std::string& fitterMode)
74  {
75  if (fitterMode == "calibration")
76  B2INFO("Fitter set to calibration mode");
77  else if (fitterMode == "monitoring")
78  B2INFO("Fitter set to monitoring mode");
79  else if (fitterMode == "MC")
80  B2INFO("Fitter set to MC mode");
81  else
82  B2ERROR("Unknown fitter type " << fitterMode << ". The valid options are calibration, monitoring or MC");
83 
84  m_fitterMode = fitterMode;
85  }
86 
88  void fitInAmpliduteBins(bool isFitInAmplitudeBins)
89  {
90  m_isFitInAmplitudeBins = isFitInAmplitudeBins;
91  }
92 
93 
94  protected:
95 
98 
100  void loadMCInfoTrees();
101 
103  void determineFitStatus();
104 
106  void fitChannel(short, short, TH1*);
107 
109  void fitPulser(TH1*, TH1*);
110 
114  void calculateChennelT0();
115 
118  virtual EResult calibrate() override;
119 
120  private:
121 
122  int m_minEntries = 50;
123  std::string m_output = "laserFitResult.root";
124  std::string m_fitConstraints =
125  "/group/belle2/group/detector/TOP/calibration/MCreferences/LaserMCParameters.root";
126  std::string m_TTSData =
127  "/group/belle2/group/detector/TOP/calibration/MCreferences/TTSParametrization.root";
128  std::string m_fitterMode = "calibration";
129  bool m_isFitInAmplitudeBins = false;
130  std::vector<float> m_binEdges = {50, 100, 130, 160, 190, 220, 250, 280, 310, 340, 370, 400, 430, 460, 490, 520, 550, 580, 610, 640, 670, 700, 800, 900, 1000, 1200, 1500, 2000};
131  TFile* m_inputTTS = nullptr;
132  TFile* m_inputConstraints = nullptr;
134  TTree* m_treeTTS = nullptr;
136  nullptr;
137  TFile* m_histFile = nullptr;
138  TTree* m_fitTree = nullptr;
139  TTree* m_timewalkTree =
140  nullptr;
143  // Variables for the TTS parametrization tree
144  float m_mean2 = 0;
145  float m_sigma1 = 0;
146  float m_sigma2 = 0;
147  float m_f1 = 0;
148  float m_f2 = 0;
149  short m_pixelRow = 0;
150  short m_pixelCol = 0;
152  // Variables for the MC truth infos
159  float m_nExtraConstraints = 0.;
160  float m_timeBackgroundConstraints = 0.;
161  float m_sigmaBackgroundConstraints = 0.;
164  // Variables for the output tree
165  float m_binLowerEdge = 0;
166  float m_binUpperEdge = 0;
167  short m_channel = 0;
168  short m_slot = 0;
169  short m_row = 0;
170  short m_col = 0;
171  float m_peakTime = 0;
172  float m_deltaT =
173  0;
174  float m_sigma = 0.;
175  float m_fraction = 0.;
176  float m_yieldLaser = 0.;
177  float m_histoIntegral = 0.;
179  float m_peakTimeErr = 0;
180  float m_deltaTErr = 0;
181  float m_sigmaErr = 0.;
182  float m_fractionErr = 0.;
183  float m_yieldLaserErr = 0.;
185  float m_timeExtra = 0.;
186  float m_sigmaExtra = 0.;
187  float m_yieldLaserExtra = 0.;
188  float m_alphaExtra = 0.;
189  float m_nExtra = 0.;
191  float m_timeBackground = 0.;
192  float m_sigmaBackground = 0.;
193  float m_yieldLaserBackground = 0.;
195  float m_fractionMC = 0.;
196  float m_deltaTMC = 0.;
197  float m_peakTimeMC =
198  0.;
200  float m_chi2 = 0;
201  float m_rms = 0;
203  float m_channelT0 =
204  0.;
205  float m_channelT0Err = 0.;
207  float m_firstPulserTime = 0.;
208  float m_firstPulserSigma = 0.;
211  0.;
212  float m_secondPulserSigma = 0.;
214  short m_fitStatus = 1;
215  };
216  }
218 } // namespace Belle2
219 
220 
Belle2::TOP::TOPLocalCalFitter::calibrate
virtual EResult calibrate() override
Runs the algorithm on events.
Definition: TOPLocalCalFitter.cc:535
Belle2::TOP::TOPLocalCalFitter::m_sigmaBackgroundConstraints
float m_sigmaBackgroundConstraints
Sigma of the gaussian used to describe the background.
Definition: TOPLocalCalFitter.h:170
Belle2::TOP::TOPLocalCalFitter::m_f2
float m_f2
Fraction of the second gaussian on the TTS parametrization.
Definition: TOPLocalCalFitter.h:157
Belle2::TOP::TOPLocalCalFitter::m_fractionConstraints
float m_fractionConstraints
Fraction of the main peak.
Definition: TOPLocalCalFitter.h:164
Belle2::TOP::TOPLocalCalFitter::m_alphaExtraConstraints
float m_alphaExtraConstraints
alpha parameter of the tail of the extra peak.
Definition: TOPLocalCalFitter.h:167
Belle2::TOP::TOPLocalCalFitter::m_secondPulserSigma
float m_secondPulserSigma
Time resolution from the fit of the first electronic pulse, from a Gaussian fit.
Definition: TOPLocalCalFitter.h:221
Belle2::TOP::TOPLocalCalFitter::m_yieldLaser
float m_yieldLaser
Total number of laser hits from the fitting function integral.
Definition: TOPLocalCalFitter.h:185
Belle2::TOP::TOPLocalCalFitter::setupOutputTreeAndFile
void setupOutputTreeAndFile()
prepares the output tree
Definition: TOPLocalCalFitter.cc:153
Belle2::TOP::TOPLocalCalFitter::m_row
short m_row
Pixel row.
Definition: TOPLocalCalFitter.h:178
Belle2::TOP::TOPLocalCalFitter::m_channelT0
float m_channelT0
Raw, channelT0 calibration, defined as peakTime-peakTimeMC.
Definition: TOPLocalCalFitter.h:212
Belle2::TOP::TOPLocalCalFitter::m_yieldLaserBackground
float m_yieldLaserBackground
Integral of the background gaussian.
Definition: TOPLocalCalFitter.h:202
Belle2::TOP::TOPLocalCalFitter::m_nExtra
float m_nExtra
parameter n of the tail of the extra peak
Definition: TOPLocalCalFitter.h:198
Belle2::TOP::TOPLocalCalFitter::m_fitConstraints
std::string m_fitConstraints
File with the TTS parametrization.
Definition: TOPLocalCalFitter.h:133
Belle2::TOP::TOPLocalCalFitter::m_fractionMC
float m_fractionMC
Fraction of events in the secondary peak form the MC simulation.
Definition: TOPLocalCalFitter.h:204
Belle2::TOP::TOPLocalCalFitter::m_inputTTS
TFile * m_inputTTS
File containing m_treeTTS.
Definition: TOPLocalCalFitter.h:140
Belle2::TOP::TOPLocalCalFitter::m_deltaTErr
float m_deltaTErr
Statistical error on deltaT.
Definition: TOPLocalCalFitter.h:189
Belle2::TOP::TOPLocalCalFitter::m_sigmaBackground
float m_sigmaBackground
Sigma of the gaussian used to describe the background.
Definition: TOPLocalCalFitter.h:201
Belle2::TOP::TOPLocalCalFitter::calculateChennelT0
void calculateChennelT0()
Calculates the commonT0 calibration after the fits have been done.
Definition: TOPLocalCalFitter.cc:477
Belle2::TOP::TOPLocalCalFitter::m_peakTime
float m_peakTime
Fitted time of the main (i.e.
Definition: TOPLocalCalFitter.h:180
Belle2::TOP::TOPLocalCalFitter::m_treeTTS
TTree * m_treeTTS
Input to the fitter.
Definition: TOPLocalCalFitter.h:143
Belle2::TOP::TOPLocalCalFitter::setFitMode
void setFitMode(const std::string &fitterMode)
Sets the fitter mode.
Definition: TOPLocalCalFitter.h:82
Belle2::TOP::TOPLocalCalFitter::m_firstPulserTime
float m_firstPulserTime
Average time of the first electronic pulse respect to the reference pulse, from a Gaussian fit.
Definition: TOPLocalCalFitter.h:216
Belle2::TOP::TOPLocalCalFitter::m_sigma2
float m_sigma2
Width of the second gaussian on the TTS parametrization.
Definition: TOPLocalCalFitter.h:155
Belle2::TOP::TOPLocalCalFitter::~TOPLocalCalFitter
virtual ~TOPLocalCalFitter()
Destructor.
Definition: TOPLocalCalFitter.h:46
Belle2::TOP::TOPLocalCalFitter::m_secondPulserTime
float m_secondPulserTime
Average time of the second electronic pulse respect to the reference pulse, from a gaussian fit.
Definition: TOPLocalCalFitter.h:219
Belle2::TOP::TOPLocalCalFitter::m_timeExtra
float m_timeExtra
Position of the extra peak seen in the timing tail, w/ respect to peakTime.
Definition: TOPLocalCalFitter.h:194
Belle2::TOP::TOPLocalCalFitter::m_timewalkTree
TTree * m_timewalkTree
Output of the fitter.
Definition: TOPLocalCalFitter.h:148
Belle2::TOP::TOPLocalCalFitter::m_col
short m_col
Pixel column.
Definition: TOPLocalCalFitter.h:179
Belle2::TOP::TOPLocalCalFitter::TOPLocalCalFitter
TOPLocalCalFitter()
Constructor.
Definition: TOPLocalCalFitter.cc:105
Belle2::TOP::TOPLocalCalFitter::setFitConstraintsFileName
void setFitConstraintsFileName(const std::string &fitConstraints)
Sets the name of the root file containing the laser MC time corrections and the fit constraints.
Definition: TOPLocalCalFitter.h:63
Belle2::TOP::TOPLocalCalFitter::m_firstPulserSigma
float m_firstPulserSigma
Time resolution from the fit of the first electronic pulse, from a Gaussian fit.
Definition: TOPLocalCalFitter.h:217
Belle2::TOP::TOPLocalCalFitter::m_channel
short m_channel
Channel number (0-511)
Definition: TOPLocalCalFitter.h:176
Belle2::TOP::TOPLocalCalFitter::m_histFile
TFile * m_histFile
Output of the fitter.
Definition: TOPLocalCalFitter.h:146
Belle2::TOP::TOPLocalCalFitter::m_minEntries
int m_minEntries
Minimum number of entries to perform the fit.
Definition: TOPLocalCalFitter.h:131
Belle2::TOP::TOPLocalCalFitter::m_histoIntegral
float m_histoIntegral
Integral of the fitted histogram.
Definition: TOPLocalCalFitter.h:186
Belle2::TOP::TOPLocalCalFitter::m_timeBackgroundConstraints
float m_timeBackgroundConstraints
Position of the gaussian used to describe the background, w/ respect to peakTime.
Definition: TOPLocalCalFitter.h:169
Belle2::TOP::TOPLocalCalFitter::m_deltaTConstraints
float m_deltaTConstraints
Distance between the main and the secondary laser peak.
Definition: TOPLocalCalFitter.h:163
Belle2::TOP::TOPLocalCalFitter::m_fitTree
TTree * m_fitTree
Output of the fitter.
Definition: TOPLocalCalFitter.h:147
Belle2::TOP::TOPLocalCalFitter::setTTSFileName
void setTTSFileName(const std::string &TTSData)
Sets the name of the root file containing the TTS parameters.
Definition: TOPLocalCalFitter.h:69
Belle2::TOP::TOPLocalCalFitter::loadMCInfoTrees
void loadMCInfoTrees()
loads the TTS parameters and the MC truth info
Definition: TOPLocalCalFitter.cc:115
Belle2::TOP::TOPLocalCalFitter::fitChannel
void fitChannel(short, short, TH1 *)
Fits the laser light on one channel.
Definition: TOPLocalCalFitter.cc:243
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOP::TOPLocalCalFitter::m_output
std::string m_output
Name of the output file.
Definition: TOPLocalCalFitter.h:132
Belle2::TOP::TOPLocalCalFitter::m_mean2
float m_mean2
Position of the second gaussian of the TTS parametrization with respect to the first one.
Definition: TOPLocalCalFitter.h:153
Belle2::TOP::TOPLocalCalFitter::m_channelT0Err
float m_channelT0Err
Statistical error on channelT0.
Definition: TOPLocalCalFitter.h:214
Belle2::TOP::TOPLocalCalFitter::m_fitterMode
std::string m_fitterMode
Fit mode.
Definition: TOPLocalCalFitter.h:137
Belle2::TOP::TOPLocalCalFitter::m_binEdges
std::vector< float > m_binEdges
Amplitude bins.
Definition: TOPLocalCalFitter.h:139
Belle2::TOP::TOPLocalCalFitter::m_fraction
float m_fraction
Fraction of events in the secondary peak.
Definition: TOPLocalCalFitter.h:184
Belle2::TOP::TOPLocalCalFitter::m_inputConstraints
TFile * m_inputConstraints
File containing m_treeConstraints.
Definition: TOPLocalCalFitter.h:141
Belle2::TOP::TOPLocalCalFitter::m_binLowerEdge
float m_binLowerEdge
Lower edge of the amplitude bin in which this fit is performed.
Definition: TOPLocalCalFitter.h:174
Belle2::TOP::TOPLocalCalFitter::m_peakTimeErr
float m_peakTimeErr
Statistical error on peakTime.
Definition: TOPLocalCalFitter.h:188
Belle2::TOP::TOPLocalCalFitter::m_yieldLaserErr
float m_yieldLaserErr
Statistical error on yield.
Definition: TOPLocalCalFitter.h:192
Belle2::TOP::TOPLocalCalFitter::m_isFitInAmplitudeBins
bool m_isFitInAmplitudeBins
Enables the fit in amplitude bins.
Definition: TOPLocalCalFitter.h:138
Belle2::TOP::TOPLocalCalFitter::m_fitStatus
short m_fitStatus
Fit quality flag, propagated to the constants.
Definition: TOPLocalCalFitter.h:223
Belle2::TOP::TOPLocalCalFitter::fitInAmpliduteBins
void fitInAmpliduteBins(bool isFitInAmplitudeBins)
Enables the fit amplitude bins.
Definition: TOPLocalCalFitter.h:97
Belle2::TOP::TOPLocalCalFitter::determineFitStatus
void determineFitStatus()
determines if the constant obtained by the fit are good or not
Definition: TOPLocalCalFitter.cc:466
Belle2::TOP::TOPLocalCalFitter::m_sigmaExtraConstraints
float m_sigmaExtraConstraints
Width of the guassian used to describe the extra peak on the timing distribution tail.
Definition: TOPLocalCalFitter.h:166
Belle2::TOP::TOPLocalCalFitter::m_timeExtraConstraints
float m_timeExtraConstraints
Position of the guassian used to describe the extra peak on the timing distribution tail.
Definition: TOPLocalCalFitter.h:165
Belle2::CalibrationAlgorithm::EResult
EResult
The result of calibration.
Definition: CalibrationAlgorithm.h:50
Belle2::TOP::TOPLocalCalFitter::m_fractionErr
float m_fractionErr
Statistical error on fraction.
Definition: TOPLocalCalFitter.h:191
Belle2::TOP::TOPLocalCalFitter::m_alphaExtra
float m_alphaExtra
alpha parameter of the tail of the extra peak.
Definition: TOPLocalCalFitter.h:197
Belle2::TOP::TOPLocalCalFitter::m_nExtraConstraints
float m_nExtraConstraints
parameter n of the tail of the extra peak
Definition: TOPLocalCalFitter.h:168
Belle2::TOP::TOPLocalCalFitter::setOutputFileName
void setOutputFileName(const std::string &output)
Sets the name of the output root file.
Definition: TOPLocalCalFitter.h:55
Belle2::TOP::TOPLocalCalFitter::m_yieldLaserExtra
float m_yieldLaserExtra
Integral of the extra peak.
Definition: TOPLocalCalFitter.h:196
Belle2::TOP::TOPLocalCalFitter::m_f1
float m_f1
Fraction of the first gaussian on the TTS parametrization.
Definition: TOPLocalCalFitter.h:156
Belle2::TOP::TOPLocalCalFitter::m_peakTimeMC
float m_peakTimeMC
Time of the main peak in teh MC simulation, i.e.
Definition: TOPLocalCalFitter.h:206
Belle2::TOP::TOPLocalCalFitter::fitPulser
void fitPulser(TH1 *, TH1 *)
Fits the two pulsers.
Definition: TOPLocalCalFitter.cc:428
Belle2::TOP::TOPLocalCalFitter::m_sigma
float m_sigma
Gaussian time resolution, fitted.
Definition: TOPLocalCalFitter.h:183
Belle2::TOP::TOPLocalCalFitter::m_deltaTMC
float m_deltaTMC
Time difference between the main peak and the secondary peak in the MC simulation.
Definition: TOPLocalCalFitter.h:205
Belle2::TOP::TOPLocalCalFitter::m_pixelRow
short m_pixelRow
Pixel row.
Definition: TOPLocalCalFitter.h:158
Belle2::TOP::TOPLocalCalFitter::m_deltaT
float m_deltaT
Time difference between the main peak and the secondary peak.
Definition: TOPLocalCalFitter.h:181
Belle2::TOP::TOPLocalCalFitter::m_rms
float m_rms
RMS of the histogram used for the fit.
Definition: TOPLocalCalFitter.h:210
Belle2::TOP::TOPLocalCalFitter::m_timeBackground
float m_timeBackground
Position of the gaussian used to describe the background, w/ respect to peakTime.
Definition: TOPLocalCalFitter.h:200
Belle2::TOP::TOPLocalCalFitter::m_peakTimeConstraints
float m_peakTimeConstraints
Time of the main laser peak in the MC simulation (aka MC correction)
Definition: TOPLocalCalFitter.h:162
Belle2::TOP::TOPLocalCalFitter::m_chi2
float m_chi2
Reduced chi2 of the fit.
Definition: TOPLocalCalFitter.h:209
Belle2::TOP::TOPLocalCalFitter::m_sigmaExtra
float m_sigmaExtra
Gaussian sigma of the extra peak in the timing tail
Definition: TOPLocalCalFitter.h:195
Belle2::TOP::TOPLocalCalFitter::setMinEntries
void setMinEntries(int minEntries)
Sets the minimum number of entries to perform the calibration in one channel.
Definition: TOPLocalCalFitter.h:49
Belle2::TOP::TOPLocalCalFitter::m_TTSData
std::string m_TTSData
File with the Fit constraints and MC info.
Definition: TOPLocalCalFitter.h:135
Belle2::TOP::TOPLocalCalFitter::m_slot
short m_slot
Slot ID (1-16)
Definition: TOPLocalCalFitter.h:177
Belle2::TOP::TOPLocalCalFitter::m_binUpperEdge
float m_binUpperEdge
Upper edge of the amplitude bin in which this fit is performed.
Definition: TOPLocalCalFitter.h:175
Belle2::TOP::TOPLocalCalFitter::m_sigmaErr
float m_sigmaErr
Statistical error on sigma.
Definition: TOPLocalCalFitter.h:190
Belle2::TOP::TOPLocalCalFitter::m_treeConstraints
TTree * m_treeConstraints
Input to the fitter.
Definition: TOPLocalCalFitter.h:144
Belle2::TOP::TOPLocalCalFitter::m_pixelCol
short m_pixelCol
Pixel column.
Definition: TOPLocalCalFitter.h:159
Belle2::TOP::TOPLocalCalFitter::m_sigma1
float m_sigma1
Width of the first gaussian on the TTS parametrization.
Definition: TOPLocalCalFitter.h:154