Belle II Software development
CDCDedxInjectTimeAlgorithm.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 <map>
12#include <vector>
13#include <iostream>
14#include <fstream>
15
16#include <TH1D.h>
17#include <TH1I.h>
18#include <TF1.h>
19#include <TCanvas.h>
20#include <TLine.h>
21#include <TLegend.h>
22
23#include <calibration/CalibrationAlgorithm.h>
24#include <framework/database/DBObjPtr.h>
25#include <reconstruction/dbobjects/CDCDedxInjectionTime.h>
26#include <reconstruction/utility/CDCDedxMeanPred.h>
27#include <reconstruction/utility/CDCDedxSigmaPred.h>
28#include <framework/gearbox/Const.h>
29
30// namespace constants
31namespace numdedx {
32 static const int nrings = 2;
33 static const int nvectors = 6;
34}
35
36enum fstatus {fitOK, fitFailed};
37
38namespace Belle2 {
47
48 public:
49
54
59
63 void setMergePayload(bool value = true) {m_isMerge = value;}
64
68 void setMonitoringPlots(bool value = false) {m_ismakePlots = value;}
69
73 void setFitWidth(double value) {m_sigmaR = value;}
74
78 void setMinTracks(int value) {m_thersE = value;}
79
83 void setDedxPars(int value, double min, double max)
84 {
85 m_dedxBins = value;
86 m_dedxMin = min;
87 m_dedxMax = max;
88 }
89
93 void setChiPars(int value, double min, double max)
94 {
95 m_chiBins = value;
96 m_chiMin = min;
97 m_chiMax = max;
98 }
99
103 void fitGaussianWRange(TH1D*& temphist, fstatus& status);
104
108 void getExpRunInfo();
109
113 void defineTimeBins();
114
118 void defineHisto(std::array<std::vector<TH1D*>, numdedx::nrings>& htemp, std::string var);
119
123 void defineTimeHisto(std::array<std::array<TH1D*, 3>, numdedx::nrings>& htemp);
124
128 void checkStatistics(std::array<std::vector<TH1D*>, numdedx::nrings>& hvar);
129
133 void correctBinBias(std::map<int, std::vector<double>>& varcorr, std::map<int, std::vector<double>>& var,
134 std::map<int, std::vector<double>>& time, TH1D*& htimes);
135
139 void createPayload(std::array<double, numdedx::nrings>& scale, std::map<int, std::vector<double>>& vmeans,
140 std::map<int, std::vector<double>>& varscal, std::string svar);
141
145 void getMeanReso(std::array<std::vector<TH1D*>, numdedx::nrings>& hvar,
146 std::map<int, std::vector<double>>& vmeans, std::map<int, std::vector<double>>& vresos);
147
151 void plotEventStats();
152
156 void plotBinLevelDist(std::array<std::vector<TH1D*>, numdedx::nrings>& hvar, std::string var);
157
161 void plotRelConstants(std::map<int, std::vector<double>>& vmeans, std::map<int, std::vector<double>>& vresos,
162 std::map<int, std::vector<double>>& corr, std::string svar);
163
167 void plotTimeStat(std::array<std::vector<TH1D*>, numdedx::nrings>& htime);
168
172 void plotFinalConstants(std::map<int, std::vector<double>>& vmeans, std::map<int, std::vector<double>>& vresos,
173 std::array<double, numdedx::nrings>& scale, std::array<double, numdedx::nrings>& scale_reso);
174
178 void plotInjectionTime(std::array<std::array<TH1D*, 3>, numdedx::nrings>& hvar);
179
183 void setHistStyle(TH1D*& htemp, const int ic, const int is, const double min, const double max)
184 {
185 htemp->SetStats(0);
186 htemp->LabelsDeflate();
187 htemp->SetMarkerColor(ic);
188 htemp->SetMarkerStyle(is);
189 htemp->GetXaxis()->SetLabelOffset(-0.055);
190 htemp->GetYaxis()->SetTitleOffset(0.75);
191 htemp->SetMinimum(min);
192 htemp->SetMaximum(max);
193 }
194
198 std::string getTimeBinLabel(const double& tedges, const int& it)
199 {
200 std::string label = "";
201 if (tedges < 2e4)label = Form("%0.01f-%0.01fK", m_tedges[it] / 1e3, m_tedges[it + 1] / 1e3);
202 else if (tedges < 1e5)label = Form("%0.0f-%0.0fK", m_tedges[it] / 1e3, m_tedges[it + 1] / 1e3);
203 else label = Form("%0.01f-%0.01fM", m_tedges[it] / 1e6, m_tedges[it + 1] / 1e6);
204 return label;
205 }
206
210 void deleteHisto(std::array<std::vector<TH1D*>, numdedx::nrings>& htemp)
211 {
212 for (unsigned int ir = 0; ir < c_rings; ir++) {
213 for (unsigned int it = 0; it < m_tbins; it++) {
214 delete htemp[ir][it];
215 }
216 }
217 }
218
222 void deleteTimeHisto(std::array<std::array<TH1D*, 3>, numdedx::nrings>& htemp)
223 {
224 const int tzoom = 3;
225 for (unsigned int ir = 0; ir < c_rings; ir++) {
226 for (int wt = 0; wt < tzoom; wt++) {
227 delete htemp[ir][wt];
228 }
229 }
230 }
231
235 double getCorrection(unsigned int ring, unsigned int time, std::map<int, std::vector<double>>& vmeans);
236
237
238 protected:
239
243 virtual EResult calibrate() override;
244
245 private:
246
247 static const int c_rings = numdedx::nrings;
248 std::array<std::string, numdedx::nrings> m_sring{"ler", "her"};
250 std::vector<double> m_vtedges;
251 std::vector<double> m_vtlocaledges;
253 double* m_tedges;
254 unsigned int m_tbins;
255 double m_sigmaR;
258 double m_dedxMin;
259 double m_dedxMax;
262 double m_chiMin;
263 double m_chiMax;
272 std::string m_prefix;
273 std::string m_suffix;
275 std::vector<std::vector<double>> m_vinjPayload;
278 };
280} // namespace Belle2
A calibration algorithm for CDC dE/dx injection time (HER/LER)
void setChiPars(int value, double min, double max)
function to set chi hist parameters
void setDedxPars(int value, double min, double max)
function to set dedx hist parameters
bool m_isMerge
merge payload when rel constant
void plotBinLevelDist(std::array< std::vector< TH1D * >, numdedx::nrings > &hvar, std::string var)
function to draw dedx, chi and time dist.
std::vector< double > m_vtlocaledges
internal time vector
double m_sigmaR
fit dedx dist in sigma range
void correctBinBias(std::map< int, std::vector< double > > &varcorr, std::map< int, std::vector< double > > &var, std::map< int, std::vector< double > > &time, TH1D *&htimes)
function to correct dedx mean/reso and return corrected vector map
void defineHisto(std::array< std::vector< TH1D * >, numdedx::nrings > &htemp, std::string var)
function to define histograms for dedx and time dist.
double getCorrection(unsigned int ring, unsigned int time, std::map< int, std::vector< double > > &vmeans)
function to get the correction factor of mean
std::string m_prefix
string prefix for plot names
void getExpRunInfo()
function to get exp/run information (payload object, plotting)
void setHistStyle(TH1D *&htemp, const int ic, const int is, const double min, const double max)
function to set histogram cosmetics
void plotFinalConstants(std::map< int, std::vector< double > > &vmeans, std::map< int, std::vector< double > > &vresos, std::array< double, numdedx::nrings > &scale, std::array< double, numdedx::nrings > &scale_reso)
function to final constant from merging or abs fits
int m_countR
a hack for running functions once
double * m_tedges
internal time array (copy of vtlocaledges)
bool m_ismakePlots
produce plots for monitoring
std::string m_suffix
string suffix for object names
void setMinTracks(int value)
function to set min # of tracks in time bins (0-40ms)
static const int c_rings
injection ring constants
void createPayload(std::array< double, numdedx::nrings > &scale, std::map< int, std::vector< double > > &vmeans, std::map< int, std::vector< double > > &varscal, std::string svar)
function to store payloads after full calibration
void plotInjectionTime(std::array< std::array< TH1D *, 3 >, numdedx::nrings > &hvar)
function to injection time distributions (HER/LER in three bins)
void plotTimeStat(std::array< std::vector< TH1D * >, numdedx::nrings > &htime)
function to draw time stats
void fitGaussianWRange(TH1D *&temphist, fstatus &status)
function to perform gauss fit for input histogram
void defineTimeBins()
function to set/reset time bins
void plotRelConstants(std::map< int, std::vector< double > > &vmeans, std::map< int, std::vector< double > > &vresos, std::map< int, std::vector< double > > &corr, std::string svar)
function to relative constant from dedx fit mean and chi fit reso
void defineTimeHisto(std::array< std::array< TH1D *, 3 >, numdedx::nrings > &htemp)
function to define injection time bins histograms (monitoring only)
void deleteHisto(std::array< std::vector< TH1D * >, numdedx::nrings > &htemp)
function to delete histograms for dedx and time dist.
void setMergePayload(bool value=true)
function to decide merged vs relative calibration
void deleteTimeHisto(std::array< std::array< TH1D *, 3 >, numdedx::nrings > &htemp)
function to define injection time bins histograms (monitoring only)
void plotEventStats()
function to draw event/track statistics plots
virtual EResult calibrate() override
CDC dE/dx Injection time algorithm.
void checkStatistics(std::array< std::vector< TH1D * >, numdedx::nrings > &hvar)
check statistics for obtaining calibration const.
std::vector< double > m_vtedges
external time vector
std::vector< std::vector< double > > m_vinjPayload
vector to store payload values
bool m_isminStat
flag to merge runs for statistics thershold
CDCDedxInjectTimeAlgorithm()
Constructor: Sets the description, the properties and the parameters of the algorithm.
std::array< std::string, numdedx::nrings > m_sring
injection ring name
DBObjPtr< CDCDedxInjectionTime > m_DBInjectTime
Injection time DB object.
void setMonitoringPlots(bool value=false)
function to enable monitoring plots
unsigned int m_tbins
internal time bins
int m_thersE
min tracks to start calibration
void getMeanReso(std::array< std::vector< TH1D * >, numdedx::nrings > &hvar, std::map< int, std::vector< double > > &vmeans, std::map< int, std::vector< double > > &vresos)
function to get mean and reso of histogram
std::string getTimeBinLabel(const double &tedges, const int &it)
function to return time label for histograms labeling
void setFitWidth(double value)
function to set fit range (sigma)
Base class for calibration algorithms.
EResult
The result of calibration.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
Abstract base class for different kinds of events.