40 B2INFO(
"Creating histograms");
50 tree->SetBranchAddress(
"lay", &lay);
51 tree->SetBranchAddress(
"IWire", &IWire);
52 tree->SetBranchAddress(
"x_u", &x);
53 tree->SetBranchAddress(
"t", &t_mea);
54 tree->SetBranchAddress(
"t_fit", &t_fit);
55 tree->SetBranchAddress(
"ndf", &ndf);
56 tree->SetBranchAddress(
"Pval", &Pval);
60 std::vector<TString> list_vars = {
"lay",
"IWire",
"x_u",
"t",
"t_fit",
"Pval",
"ndf"};
61 tree->SetBranchStatus(
"*", 0);
63 for (TString brname : list_vars) {
64 tree->SetBranchStatus(brname, 1);
72 for (
int i = 0; i < 56; ++i) {
75 halfCSize[i] = M_PI *
R / nW;
78 m_hTotal =
new TH1F(
"hTotal",
"hTotal", 30, -15, 15);
81 for (
int il = 0; il < 56; il++) {
83 for (
int ic = 0; ic < nW; ++ic) {
84 m_h1[il][ic] =
new TH1F(Form(
"hdT_L%d_W%d", il, ic), Form(
"L%d_cell%d", il, ic), 30, -15, 15);
89 for (
int ib = 0; ib < 300; ++ib) {
90 m_hT0b[ib] =
new TH1F(Form(
"hdT_b%d", ib), Form(
"boardID_%d", ib), 100, -20, 20);
94 const Long64_t nEntries = tree->GetEntries();
95 B2INFO(
"Number of entries: " << nEntries);
98 for (Long64_t i = 0; i < nEntries; ++i) {
100 double xmax = halfCSize[lay] - 0.1;
101 if ((fabs(x) <
m_xmin) || (fabs(x) > xmax)
106 m_h1[lay][IWire]->Fill(t_mea - t_fit);
109 m_hT0b[boardID]->Fill(t_mea - t_fit);
112 B2INFO(
"Finish making histogram for all channels");
113 B2INFO(
"Time to fill histograms: " << timer.RealTime() <<
"s");
119 B2INFO(
"Start calibration");
122 gErrorIgnoreLevel = 3001;
130 B2INFO(
"ExpRun used for DB Geometry : " << exprun.first <<
" " << exprun.second);
141 B2INFO(
"Creating CDCGeometryPar object");
145 double dEventT0 = hEvtT0->GetMean();
147 TH1F* hm_All =
new TH1F(
"hm_All",
"mean of #DeltaT distribution for all channels", 500, -10, 10);
148 TH1F* hs_All =
new TH1F(
"hs_All",
"#sigma of #DeltaT distribution for all channels", 100, 0, 10);
151 TF1* g1 =
new TF1(
"g1",
"gaus", -100, 100);
152 g1->SetParLimits(1, -20, 20);
153 vector<double> b, db, Sb, dSb;
154 vector<double> c[56];
155 vector<double> dc[56];
156 vector<double> s[56];
157 vector<double> ds[56];
159 B2INFO(
"Gaus fitting for whole channel");
163 m_hTotal->Fit(
"g1",
"Q",
"", mean - 15, mean + 15);
164 g1->GetParameters(par);
166 B2INFO(
"Gaus fitting for each board");
167 for (
int ib = 1; ib < 300; ++ib) {
173 if (
m_hT0b[ib]->Integral(1,
m_hT0b[ib]->GetNbinsX()) < 50) {
177 mean =
m_hT0b[ib]->GetMean();
178 m_hT0b[ib]->SetDirectory(0);
179 m_hT0b[ib]->Fit(
"g1",
"Q",
"", mean - 15, mean + 15);
180 g1->GetParameters(par);
183 Sb.push_back(par[1]);
184 dSb.push_back(g1->GetParError(1));
185 dtb[ib] = par[1] + dEventT0;
186 err_dtb[ib] = g1->GetParError(1);
188 B2INFO(
"Gaus fitting for each cell");
189 for (
int ilay = 0; ilay < 56; ++ilay) {
191 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
193 const int n =
m_h1[ilay][iwire]->Integral(1,
m_h1[ilay][iwire]->GetNbinsX()) ;
194 B2DEBUG(21,
"layer " << ilay <<
" wire " << iwire <<
" entries " << n);
202 err_dt[ilay][iwire] = 50;
continue;
205 mean =
m_h1[ilay][iwire]->GetMean();
206 m_h1[ilay][iwire]->SetDirectory(0);
207 m_h1[ilay][iwire]->Fit(
"g1",
"Q",
"", mean - 15, mean + 15);
208 g1->GetParameters(par);
209 c[ilay].push_back(iwire);
210 dc[ilay].push_back(0.0);
211 s[ilay].push_back(par[1]);
212 ds[ilay].push_back(g1->GetParError(1));
214 dt[ilay][iwire] = par[1] + dEventT0;
215 err_dt[ilay][iwire] = g1->GetParError(1);
216 hm_All->Fill(par[1]);
217 hs_All->Fill(par[2]);
222 B2INFO(
"Storing histograms");
225 TFile* fout =
new TFile(
m_histName.c_str(),
"RECREATE");
227 TGraphErrors* gr[56];
228 TDirectory* top = gDirectory;
231 if (hNDF && hPval && hEvtT0) {
239 TDirectory* subDir[56];
240 for (
int ilay = 0; ilay < 56; ++ilay) {
241 subDir[ilay] = top ->mkdir(Form(
"lay_%d", ilay));
244 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
245 m_h1[ilay][iwire]->Write();
250 TDirectory* corrT0 = top->mkdir(
"DeltaT0");
254 TGraphErrors* grb =
new TGraphErrors(b.size(), &b.at(0), &Sb.at(0), &db.at(0), &dSb.at(0));
255 grb->SetMarkerColor(2);
256 grb->SetMarkerSize(1.0);
257 grb->SetTitle(
"#DeltaT0;BoardID;#DeltaT0[ns]");
259 grb->SetMinimum(-10);
260 grb->SetName(
"Board");
263 for (
int sl = 0; sl < 56; ++sl) {
264 if (c[sl].size() < 2)
continue;
265 gr[sl] =
new TGraphErrors(c[sl].size(), &c[sl].at(0), &s[sl].at(0), &dc[sl].at(0), &ds[sl].at(0));
266 gr[sl]->SetMarkerColor(2);
267 gr[sl]->SetMarkerSize(1.0);
268 gr[sl]->SetTitle(Form(
"Layer_%d;IWire;#LT t_{mea}-t_{fit} #GT [ns]", sl));
269 gr[sl]->SetMaximum(10);
270 gr[sl]->SetMinimum(-10);
271 gr[sl]->SetName(Form(
"lay%d", sl));
276 B2INFO(
"Writing constants...");
277 int Ngood_T0 =
write();
278 B2INFO(
"Checking conversion conditions...");
279 double rms_dT = hm_All->GetRMS();
280 double n_below = hm_All->Integral(0, hm_All->GetXaxis()->FindBin(
m_offsetMeanDt - 5 * rms_dT));
281 double n_upper = hm_All->Integral(hm_All->GetXaxis()->FindBin(
m_offsetMeanDt + 5 * rms_dT), hm_All->GetXaxis()->GetNbins() - 1);
282 int N_remaining = n_below + n_upper - (14112 - Ngood_T0);
283 if (N_remaining < 0) N_remaining = 0;
284 B2INFO(
"+ Number of channel which are properly calibrated : " << Ngood_T0);
285 B2INFO(
"+ Number of channel which still need to be calibrated are: " << N_remaining <<
"(requirement <" <<
m_maxBadChannel <<
")");
286 B2INFO(
"+ Median of Delta_T - offset:" << hm_All->GetMean() -
m_offsetMeanDt <<
"(requirement: <" <<
m_maxMeanDt <<
")");
287 B2INFO(
"+ RMS of Delta_T dist. :" << rms_dT <<
" (Requirement: <" <<
m_maxRMSDt <<
")");
292 B2INFO(
"T0 Calibration Finished:");
295 B2INFO(
"Need more iteration ...");
306 for (
int ib = 0; ib < 300; ++ib) {
307 hT0B[ib] =
new TH1F(Form(
"hT0B%d", ib), Form(
"boardID_%d", ib), 9000, 0, 9000);
310 TH1F* hT0_all =
new TH1F(
"hT0_all",
"T0 distribution", 9000, 0, 9000);
313 for (
int ilay = 0; ilay < 56; ++ilay) {
315 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
316 WireID wireid(ilay, iwire);
317 T0 = cdcgeo.
getT0(wireid);
325 if (fabs(T0_average -
m_commonT0) > 50) {B2WARNING(
"Large difference between common T0 (" <<
m_commonT0 <<
") and aveage value" << T0_average);}
328 for (
int i = 0; i < 300; ++i) {T0B[i] =
m_commonT0;}
331 for (
int ib = 1; ib < 300; ++ib) {
333 if (fabs(T0B[ib] - T0_average) > 25) {
334 B2WARNING(
"T0 of Board " << ib <<
" (= " << T0B[ib] <<
") is too different with common T0: " << T0_average <<
335 "\n It will be replaced by common T0");
336 T0B[ib] = T0_average;
340 if (abs(
err_dtb[ib]) < 2 && abs(
dtb[ib]) < 20) {
348 for (
int ilay = 0; ilay < 56; ++ilay) {
350 for (
unsigned int iwire = 0; iwire < nW; ++iwire) {
351 WireID wireid(ilay, iwire);
355 T0 = cdcgeo.
getT0(wireid);
356 if (fabs(T0 - T0B[bID]) > 25 || fabs(T0 - T0_average) > 25) {
357 B2WARNING(
"T0 of wireID L-W: " << ilay <<
"--" << iwire <<
" (= " << T0
358 <<
") is too different with common T0 of board: " << bID <<
" = " << T0B[bID] <<
359 "\n It will be replaced by common T0 of the Board");
365 if (abs(
err_dt[ilay][iwire]) < 2 && abs(
dt[ilay][iwire]) < 20) {
366 dT =
dt[ilay][iwire];
371 tz->
setT0(wireid, T0 - dT);