1 #include <cdc/calibration/T0CalibrationAlgorithm.h>
2 #include <calibration/CalibrationAlgorithm.h>
3 #include <cdc/dbobjects/CDCTimeZeros.h>
4 #include <cdc/dataobjects/WireID.h>
5 #include <cdc/geometry/CDCGeometryPar.h>
9 #include <TGraphErrors.h>
14 #include <framework/database/DBObjPtr.h>
15 #include <framework/database/IntervalOfValidity.h>
16 #include <framework/logging/Logger.h>
26 " -------------------------- T0 Calibration Algorithm -------------------------\n"
33 B2INFO(
"Creating histograms");
42 auto tree = getObjectPtr<TTree>(
"tree");
43 tree->SetBranchAddress(
"lay", &lay);
44 tree->SetBranchAddress(
"IWire", &IWire);
45 tree->SetBranchAddress(
"x_u", &x);
46 tree->SetBranchAddress(
"t", &t_mea);
47 tree->SetBranchAddress(
"t_fit", &t_fit);
48 tree->SetBranchAddress(
"ndf", &ndf);
49 tree->SetBranchAddress(
"Pval", &Pval);
53 std::vector<TString> list_vars = {
"lay",
"IWire",
"x_u",
"t",
"t_fit",
"Pval",
"ndf"};
54 tree->SetBranchStatus(
"*", 0);
56 for (TString brname : list_vars) {
57 tree->SetBranchStatus(brname, 1);
65 for (
int i = 0; i < 56; ++i) {
68 halfCSize[i] = M_PI * R / nW;
71 m_hTotal =
new TH1F(
"hTotal",
"hTotal", 30, -15, 15);
74 for (
int il = 0; il < 56; il++) {
76 for (
int ic = 0; ic < nW; ++ic) {
77 m_h1[il][ic] =
new TH1F(Form(
"hdT_L%d_W%d", il, ic), Form(
"L%d_cell%d", il, ic), 30, -15, 15);
82 for (
int ib = 0; ib < 300; ++ib) {
83 m_hT0b[ib] =
new TH1F(Form(
"hdT_b%d", ib), Form(
"boardID_%d", ib), 100, -20, 20);
87 const Long64_t nEntries = tree->GetEntries();
88 B2INFO(
"Number of entries: " << nEntries);
89 for (Long64_t i = 0; i < nEntries; ++i) {
91 double xmax = halfCSize[lay] - 0.1;
92 if ((fabs(x) <
m_xmin) || (fabs(x) > xmax)
97 m_h1[lay][IWire]->Fill(t_mea - t_fit);
100 m_hT0b[boardID]->Fill(t_mea - t_fit);
103 B2INFO(
"Finish making histogram for all channels");
108 B2INFO(
"Start calibration");
111 gErrorIgnoreLevel = 3001;
119 B2INFO(
"ExpRun used for DB Geometry : " << exprun.first <<
" " << exprun.second);
130 B2INFO(
"Creating CDCGeometryPar object");
133 auto hEvtT0 = getObjectPtr<TH1F>(
"hEventT0");
134 double dEventT0 = hEvtT0->GetMean();
136 TH1F* hm_All =
new TH1F(
"hm_All",
"mean of #DeltaT distribution for all chanels", 500, -10, 10);
137 TH1F* hs_All =
new TH1F(
"hs_All",
"#sigma of #DeltaT distribution for all chanels", 100, 0, 10);
140 TF1* g1 =
new TF1(
"g1",
"gaus", -100, 100);
141 g1->SetParLimits(1, -20, 20);
142 vector<double> b, db, Sb, dSb;
143 vector<double> c[56];
144 vector<double> dc[56];
145 vector<double> s[56];
146 vector<double> ds[56];
148 B2INFO(
"Gaus fitting for whole channel");
152 m_hTotal->Fit(
"g1",
"Q",
"", mean - 15, mean + 15);
153 g1->GetParameters(par);
155 B2INFO(
"Gaus fitting for each board");
156 for (
int ib = 1; ib < 300; ++ib) {
162 if (
m_hT0b[ib]->Integral(1,
m_hT0b[ib]->GetNbinsX()) < 50) {
166 mean =
m_hT0b[ib]->GetMean();
167 m_hT0b[ib]->SetDirectory(0);
168 m_hT0b[ib]->Fit(
"g1",
"Q",
"", mean - 15, mean + 15);
169 g1->GetParameters(par);
172 Sb.push_back(par[1]);
173 dSb.push_back(g1->GetParError(1));
174 dtb[ib] = par[1] + dEventT0;
175 err_dtb[ib] = g1->GetParError(1);
177 B2INFO(
"Gaus fitting for each cell");
178 for (
int ilay = 0; ilay < 56; ++ilay) {
180 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
182 const int n =
m_h1[ilay][iwire]->Integral(1,
m_h1[ilay][iwire]->GetNbinsX()) ;
183 B2DEBUG(21,
"layer " << ilay <<
" wire " << iwire <<
" entries " << n);
191 err_dt[ilay][iwire] = 50;
continue;
194 mean =
m_h1[ilay][iwire]->GetMean();
195 m_h1[ilay][iwire]->SetDirectory(0);
196 m_h1[ilay][iwire]->Fit(
"g1",
"Q",
"", mean - 15, mean + 15);
197 g1->GetParameters(par);
198 c[ilay].push_back(iwire);
199 dc[ilay].push_back(0.0);
200 s[ilay].push_back(par[1]);
201 ds[ilay].push_back(g1->GetParError(1));
203 dt[ilay][iwire] = par[1] + dEventT0;
204 err_dt[ilay][iwire] = g1->GetParError(1);
205 hm_All->Fill(par[1]);
206 hs_All->Fill(par[2]);
211 B2INFO(
"Storing histograms");
212 auto hNDF = getObjectPtr<TH1F>(
"hNDF");
213 auto hPval = getObjectPtr<TH1F>(
"hPval");
214 TFile* fout =
new TFile(
m_histName.c_str(),
"RECREATE");
216 TGraphErrors* gr[56];
217 TDirectory* top = gDirectory;
220 if (hNDF && hPval && hEvtT0) {
228 TDirectory* subDir[56];
229 for (
int ilay = 0; ilay < 56; ++ilay) {
230 subDir[ilay] = top ->mkdir(Form(
"lay_%d", ilay));
233 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
234 m_h1[ilay][iwire]->Write();
239 TDirectory* corrT0 = top->mkdir(
"DeltaT0");
243 TGraphErrors* grb =
new TGraphErrors(b.size(), &b.at(0), &Sb.at(0), &db.at(0), &dSb.at(0));
244 grb->SetMarkerColor(2);
245 grb->SetMarkerSize(1.0);
246 grb->SetTitle(
"#DeltaT0;BoardID;#DeltaT0[ns]");
248 grb->SetMinimum(-10);
249 grb->SetName(
"Board");
252 for (
int sl = 0; sl < 56; ++sl) {
253 if (c[sl].size() < 2)
continue;
254 gr[sl] =
new TGraphErrors(c[sl].size(), &c[sl].at(0), &s[sl].at(0), &dc[sl].at(0), &ds[sl].at(0));
255 gr[sl]->SetMarkerColor(2);
256 gr[sl]->SetMarkerSize(1.0);
257 gr[sl]->SetTitle(Form(
"Layer_%d;IWire;#LT t_{mea}-t_{fit} #GT [ns]", sl));
258 gr[sl]->SetMaximum(10);
259 gr[sl]->SetMinimum(-10);
260 gr[sl]->SetName(Form(
"lay%d", sl));
265 B2INFO(
"Writing constants");
270 B2INFO(
"mean " << fabs(hm_All->GetMean()) <<
" " <<
m_maxMeanDt);
271 B2INFO(
"sigma " << fabs(hm_All->GetRMS()) <<
" " <<
m_maxRMSDt);
274 B2INFO(
"mean " << fabs(hm_All->GetMean()) <<
" " <<
m_maxMeanDt);
275 B2INFO(
"sigma " << fabs(hm_All->GetRMS()) <<
" " <<
m_maxRMSDt);
286 for (
int ib = 0; ib < 300; ++ib) {
287 hT0B[ib] =
new TH1F(Form(
"hT0B%d", ib), Form(
"boardID_%d", ib), 9000, 0, 9000);
290 TH1F* hT0_all =
new TH1F(
"hT0_all",
"T0 distribution", 9000, 0, 9000);
293 for (
int ilay = 0; ilay < 56; ++ilay) {
295 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
296 WireID wireid(ilay, iwire);
297 T0 = cdcgeo.
getT0(wireid);
305 if (fabs(T0_average -
m_commonT0) > 50) {B2WARNING(
"Large difference between common T0 (" <<
m_commonT0 <<
") and aveage value" << T0_average);}
308 for (
int i = 0; i < 300; ++i) {T0B[i] =
m_commonT0;}
311 for (
int ib = 1; ib < 300; ++ib) {
313 if (fabs(T0B[ib] - T0_average) > 25) {
314 B2WARNING(
"T0 of Board " << ib <<
" (= " << T0B[ib] <<
") is too different with common T0: " << T0_average <<
315 "\n It will be replaced by common T0");
316 T0B[ib] = T0_average;
320 if (abs(
err_dtb[ib]) < 2 && abs(
dtb[ib]) < 20) {
327 for (
int ilay = 0; ilay < 56; ++ilay) {
329 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
330 WireID wireid(ilay, iwire);
334 T0 = cdcgeo.
getT0(wireid);
335 if (fabs(T0 - T0B[bID]) > 25 || fabs(T0 - T0_average) > 25) {
336 B2WARNING(
"T0 of wireID L-W: " << ilay <<
"--" << iwire <<
" (= " << T0
337 <<
") is too different with common T0 of board: " << bID <<
" = " << T0B[bID] <<
338 "\n It will be replaced by common T0 of the Board");
344 if (abs(
err_dt[ilay][iwire]) < 2 && abs(
dt[ilay][iwire]) < 20) {
345 dT =
dt[ilay][iwire];
349 tz->
setT0(wireid, T0 - dT);
360 double mean1 = h1->GetMean();
361 h1->GetXaxis()->SetRangeUser(mean1 - 50, 8000);
362 double mean2 = h1->GetMean();
363 while (fabs(mean1 - mean2) > 0.5) {
365 h1->GetXaxis()->SetRangeUser(mean1 - 50, 8000);
366 mean2 = h1->GetMean();