25 #include "TPaveText.h"
60 double fitMax,
int lwb,
int upb,
unsigned int chi2Pars,
63 TH1D*
h =
new TH1D(
name,
"#chi^{2} distribution",
nBins, 0,
max);
64 unsigned int nDofEff = 0, nDofLast = 0;
71 shapeErrorGetter->
add(*kFactorGetter);
74 if ((
i+1) % 10000 == 0) cout <<
"Processing entry # " <<
i+1 << endl;
76 if (!history)
continue;
78 for (
unsigned int j = 0; j < history->
nData(); j++) {
79 h->Fill(history->
chi2(j, lwb, upb, chi2Pars, shapeErrorType, &nDofEff));
80 if (nDofLast > 0 && nDofLast != nDofEff) cout <<
"WARNING @ hash = " <<
i <<
", index = " << j <<
" : nDof varied from " << nDofLast <<
" to " << nDofEff << endl;
85 if (nDof > 0 && nDof != nDofEff) cout <<
"WARNING : fixing nDof = " << nDof <<
", but computer nDofEff = " << nDofEff << endl;
87 if (fitMax < 0)
return h;
88 TF1* fChi2 =
fitChi2(*
h,
"chi2", 0,
max, nDof, 0, fitMax);
90 TPaveText*
p =
new TPaveText(0.6, 0.85, 0.85, 0.65,
"NDC");
91 p->AddText(Form(
"k = %.1f%%",
kFactor*100));
92 p->AddText(Form(
"Fit #chi^{2} = %.1f", fChi2->GetChisquare()));
93 p->AddText(Form(
"Fit nDOF = %.1f", fChi2->GetParameter(1)));
96 if (shapeErrorGetter) {
98 delete shapeErrorGetter;
106 TF1* fChi2 =
new TF1(
name,
"[0]*TMath::Power(x/2, [1]/2)/x*TMath::Exp(-x/2)/TMath::Gamma([1]/2)", xMin, xMax);
107 fChi2->SetParameter(0, 100);
108 fChi2->SetParameter(1, 3);
109 fChi2->SetParLimits(1, 1, 7);
115 double nDof,
double fitMin,
double fitMax)
121 fChi2->SetParameter(0, 4*
h.GetMaximum());
122 if (nDof > 0) fChi2->FixParameter(1, nDof);
124 h.Fit(fChi2,
"",
"", fitMin, fitMax);
125 fChi2->SetRange(xMin, xMax);
131 double refErrMin,
double refErrMax,
unsigned int refErrNBins,
132 int lwb,
int upb,
unsigned int chi2Pars,
unsigned int nDof)
const
135 if (nDof > 0) fChi2->FixParameter(1, nDof);
137 double delta = (refErrMax - refErrMin)/refErrNBins;
138 TH1D* fitResults =
new TH1D(
"fitResults",
"", refErrNBins, refErrMin - delta/2, refErrMax - delta/2);
140 for (
unsigned int k = 0;
k < refErrNBins;
k++) {
141 double refErr = refErrMin + delta*
k;
142 TH1D*
h =
new TH1D(
name,
"#chi^{2} distribution",
nBins, 0,
max);
146 shapeErrorGetter.
add(kFactorGetter);
149 if (!history)
continue;
151 for (
unsigned int j = 0; j < history->
nData(); j++) {
152 h->Fill(history->
chi2(j, lwb, upb, chi2Pars));
156 fitResults->SetBinContent(
k+1, fChi2->GetChisquare());
160 TF1* fPol2 =
new TF1(
"fPol2",
"[0]*(x - [1])*(x - [1]) + [2]", refErrMin, refErrMax);
162 double center = fitResults->GetBinCenter(fitResults->GetMinimumBin());
163 fPol2->SetParameter(0, (fitResults->GetMaximum() - fitResults->GetMinimum())/center/center);
164 fPol2->SetParameter(1, center);
165 fPol2->SetParameter(2, fitResults->GetMinimum());
168 fitResults->Fit(fPol2);
170 TPaveText*
p =
new TPaveText(0.6, 0.85, 0.85, 0.65,
"NDC");
171 p->AddText(Form(
"Fit k_{best} = %.1f%%", fPol2->GetParameter(1)*100));
172 p->AddText(Form(
"Fit #delta k_{best} = %.2f%%", 1/TMath::Sqrt(fPol2->GetParameter(0))*100));
173 p->AddText(Form(
"Fit #chi^{2}_{min} = %.2f", fPol2->GetParameter(2)));
183 TH1D*
h =
new TH1D(
name,
"gain distribution", 3, -0.5, 2.5);
184 h->GetXaxis()->SetBinLabel(1,
"Low");
185 h->GetXaxis()->SetBinLabel(2,
"Medium");
186 h->GetXaxis()->SetBinLabel(3,
"High");
189 if (!history)
continue;
190 for (
unsigned int j = 0; j < history->
nData(); j++)
h->Fill(history->
data(j)->
gain());
198 TH1D*
h =
new TH1D(
name,
"layer distribution", 4, -0.5, 3.5);
199 h->GetXaxis()->SetBinLabel(1,
"PS");
200 h->GetXaxis()->SetBinLabel(2,
"Strips");
201 h->GetXaxis()->SetBinLabel(3,
"Middle");
202 h->GetXaxis()->SetBinLabel(4,
"Back");
205 if (!history)
continue;
214 TH1D*
h =
new TH1D(
name,
"Residual distribution",
nBins, rMin, rMax);
215 h->GetXaxis()->SetTitle(
norm ?
"Residual/ADCMax (%)" :
"Residual (ADC counts)");
219 if (!history)
continue;
220 for (
unsigned int j = 0; j < history->
nData(); j++)
228 double lo,
double hi,
const TString&
fileName)
232 TString globalTitle = TString(xip ?
"Derivative" :
"Offset") +
" correction";
233 for (
unsigned short k = 0;
k < 5;
k++) {
234 TString
title = globalTitle +
" for sampling " + Form(
"%d",
k);
235 h1[
k] =
new TH1D(Form(
"h%d",
k),
title, 100, lo, hi);
236 h1[
k]->GetXaxis()->SetTitle(
"correction");
238 hEtaPhi[
k]->SetMinimum(lo);
239 hEtaPhi[
k]->SetMaximum(hi);
244 TH2D* hAll =
new TH2D(
"hAll", globalTitle +
" vs. sampling", 5, 0, 5, 100, lo, hi);
245 hAll->GetXaxis()->SetTitle(
"sampling");
246 hAll->GetYaxis()->SetTitle(
"correction");
248 if ((
i+1) % 10000 == 0) cout <<
"Cell # " <<
i+1 <<
"/" <<
nChannels() << endl;
250 if (!history || history->
nData() == 0)
continue;
251 for (
unsigned short k = 0;
k < 5;
k++) {
260 for (
unsigned int i = 1;
i <= 100;
i++)
261 for (
unsigned short k = 0;
k < 5;
k++)
262 hAll->SetBinContent(
k+1,
i,
h1[
k]->GetBinContent(
i));
263 TFile*
ff = TFile::Open(
fileName +
".root",
"RECREATE");
264 for (
unsigned short k = 0;
k < 5;
k++) {
270 TCanvas*
c1 =
new TCanvas(
"c1",
Id::str(calo) +
" layer " + Form(
"%d",
layer), 1600, 2000);
272 for (
unsigned short k = 0;
k < 5;
k++) {
274 hEtaPhi[
k]->Draw(
"COLZ");
285 double lo,
double hi,
const TString&
fileName)
287 unsigned int nBins = 100;
289 TString globalTitle = TString(xip ?
"Derivative" :
"Offset") +
" correction";
290 for (
unsigned short l = 0;
l < 5;
l++)
291 for (
unsigned short k = 0;
k < 5;
k++)
292 h[
l][
k] =
new TH1D(Form(
"h%d%d",
l,
k),
"",
nBins,
l < 2 ? -15 : lo,
l < 2 ? 15 : hi);
297 hAll[0] =
new TH2D(
"h0All",
"#xi_{cell}/#delta#xi vs. sampling", 5, 0, 5,
nBins, -15, 15);
298 hAll[1] =
new TH2D(
"hDAll",
"(#xi_{cell} - #xi_{ring})/#delta#xi vs. sampling", 5, 0, 5,
nBins, -15, 15);
299 hAll[2] =
new TH2D(
"hEAll", globalTitle +
" per-cell value vs. sampling", 5, 0, 5,
nBins, 0, hi);
300 hAll[3] =
new TH2D(
"hRAll", globalTitle +
" per-ring value vs. sampling", 5, 0, 5,
nBins, lo, hi);
301 hAll[4] =
new TH2D(
"hCAll", globalTitle +
" per-cell error vs. sampling", 5, 0, 5,
nBins, lo, hi);
302 TH2D* hCor =
new TH2D(
"hCor", globalTitle +
" per-ring vs. per-cell values",
nBins, lo, hi,
nBins, lo, hi);
303 hCor->GetXaxis()->SetTitle(
"#xi_{cell}");
304 hCor->GetYaxis()->SetTitle(
"#xi_{ring}");
305 for (
unsigned short l = 0;
l < 4;
l++) {
306 hAll[
l]->GetXaxis()->SetTitle(
"sampling");
307 hAll[
l]->GetYaxis()->SetTitle(
"significance");
310 if ((
i+1) % 10000 == 0) cout <<
"Cell # " <<
i+1 <<
"/" <<
nChannels() << endl;
312 if (!history || history->
nData() == 0)
continue;
313 for (
unsigned short k = 0;
k < 5;
k++) {
316 if (!cellSED || !ringSED) {
317 if (cellSED)
delete cellSED;
318 if (ringSED)
delete ringSED;
321 double cellVal = (xip ? cellSED->
xi()(
k) : cellSED->
xip()(
k));
322 double ringVal = (xip ? ringSED->
xi()(
k) : ringSED->
xip()(
k));
323 double cellErr = TMath::Sqrt(xip ? cellSED->
xiErr()(
k,
k) : cellSED->
xipErr()(
k,
k));
326 h[0][
k]->Fill(cellVal/cellErr);
327 h[1][
k]->Fill((cellVal - ringVal)/cellErr);
328 h[2][
k]->Fill(cellVal);
329 h[3][
k]->Fill(ringVal);
330 h[4][
k]->Fill(cellErr);
331 hCor->Fill(cellVal, ringVal);
334 for (
unsigned int i = 1;
i <=
nBins;
i++)
335 for (
unsigned short l = 0;
l < 5;
l++)
336 for (
unsigned short k = 0;
k < 5;
k++)
337 hAll[
l]->SetBinContent(
k+1,
i,
h[
l][
k]->GetBinContent(
i));
338 TFile*
ff = TFile::Open(
fileName +
".root",
"RECREATE");
339 for (
unsigned short l = 0;
l < 5;
l++) {
340 for (
unsigned short k = 0;
k < 5;
k++)
345 TCanvas*
c1 =
new TCanvas(
"c1",
Id::str(calo) +
" layer " + Form(
"%d",
layer), 1600, 500);
347 c1->cd(1); hCor->Draw();
348 TLatex
l;
l.SetNDC();
349 TString corrStr = Form(
"Correlation : %.1f%%", 100*hCor->GetCorrelationFactor());
350 l.DrawLatex(0.2, 0.8, corrStr);
351 c1->cd(2); hAll[0]->Draw(
"COL");
352 c1->cd(3); hAll[1]->Draw(
"COL");
360 double lo,
double hi,
const TString&
fileName)
362 unsigned int nBins = 100;
364 TString globalTitle = TString(xip ?
"Derivative" :
"Offset") +
" correction";
365 for (
unsigned short l = 0;
l < 5;
l++)
366 for (
unsigned short k = 0;
k < 5;
k++)
367 h[
l][
k] =
new TH1D(Form(
"h%d%d",
l,
k),
"",
nBins,
l < 2 ? -15 : lo,
l < 2 ? 15 : hi);
372 hAll[0] =
new TH2D(
"h0All",
"#xi_{high}/#delta#xi vs. sampling", 5, 0, 5,
nBins, -15, 15);
373 hAll[1] =
new TH2D(
"hDAll",
"(#xi_{high} - #xi_{low})/#delta#xi vs. sampling", 5, 0, 5,
nBins, -15, 15);
374 hAll[2] =
new TH2D(
"hEAll", globalTitle +
" higher-gain value vs. sampling", 5, 0, 5,
nBins, 0, hi);
375 hAll[3] =
new TH2D(
"hRAll", globalTitle +
" lower-gain value vs. sampling", 5, 0, 5,
nBins, lo, hi);
376 hAll[4] =
new TH2D(
"hCAll", globalTitle +
" higher-gain error vs. sampling", 5, 0, 5,
nBins, lo, hi);
377 TH2D* hCor =
new TH2D(
"hCor", globalTitle +
" lower-gain vs. higher-gain values",
nBins, lo, hi,
nBins, lo, hi);
378 hCor->GetXaxis()->SetTitle(
"#xi_{high}");
379 hCor->GetYaxis()->SetTitle(
"#xi_{low}");
380 for (
unsigned short l = 0;
l < 4;
l++) {
381 hAll[
l]->GetXaxis()->SetTitle(
"sampling");
382 hAll[
l]->GetYaxis()->SetTitle(
"significance");
389 if ((
i+1) % 10000 == 0) cout <<
"Cell # " <<
i+1 <<
"/" <<
nChannels() << endl;
391 if (!history || history->
nData() == 0)
continue;
392 for (
unsigned short k = 0;
k < 5;
k++) {
395 if (!hgSED || !lgSED) {
396 if (hgSED)
delete hgSED;
397 if (lgSED)
delete lgSED;
400 double hgVal = (xip ? hgSED->
xi()(
k) : hgSED->
xip()(
k));
401 double lgVal = (xip ? lgSED->
xi()(
k) : lgSED->
xip()(
k));
402 double hgErr = TMath::Sqrt(xip ? hgSED->
xiErr()(
k,
k) : hgSED->
xipErr()(
k,
k));
406 h[0][
k]->Fill(hgVal/hgErr);
407 h[1][
k]->Fill((hgVal - lgVal)/
error);
408 h[2][
k]->Fill(hgVal);
409 h[3][
k]->Fill(lgVal);
410 h[4][
k]->Fill(hgErr);
411 hCor->Fill(hgVal, lgVal);
414 for (
unsigned int i = 1;
i <=
nBins;
i++)
415 for (
unsigned short l = 0;
l < 5;
l++)
416 for (
unsigned short k = 0;
k < 5;
k++)
417 hAll[
l]->SetBinContent(
k+1,
i,
h[
l][
k]->GetBinContent(
i));
418 TFile*
ff = TFile::Open(
fileName +
".root",
"RECREATE");
419 for (
unsigned short l = 0;
l < 5;
l++) {
420 for (
unsigned short k = 0;
k < 5;
k++)
425 TCanvas*
c1 =
new TCanvas(
"c1",
Id::str(calo) +
" layer " + Form(
"%d",
layer), 1600, 500);
427 c1->cd(1); hCor->Draw();
428 TLatex
l;
l.SetNDC();
429 TString corrStr = Form(
"Correlation : %.1f%%", 100*hCor->GetCorrelationFactor());
430 l.DrawLatex(0.2, 0.8, corrStr);
431 c1->cd(2); hAll[0]->Draw(
"COL");
432 c1->cd(3); hAll[1]->Draw(
"COL");
441 TH1D*
h =
new TH1D(
name,
"Shape error",
nBins, rMin, rMax);
442 h->GetXaxis()->SetTitle(
"#epsilon^{2}");
446 if (!history)
continue;
447 for (
unsigned int j = 0; j < history->
nData(); j++) {
451 h->Fill((delta*delta -
ofc->Gamma()(
k,
k))/(adcMax*adcMax));
454 cout << sqrt(
h->GetMean())*100 <<
" +/- " << sqrt(
h->GetMeanError())*100 << endl;
466 if (!history)
continue;
467 for (
unsigned int j = 0; j < history->
nData(); j++) {
468 double residual1 = history->
data(j)->
delta(k1);
469 double residual2 = history->
data(j)->
delta(k2);
470 sum += residual1*residual2;
481 CovMatrix sum2N(lwb, upb), sumCN(lwb, upb);
482 TVectorD
sum(lwb, upb), sumN(lwb, upb);
483 double sumA = 0,
n = 0;
486 if (!history)
continue;
487 for (
unsigned int j = 0; j < history->
nData(); j++) {
490 if (!
ofc ||
ofc->hasSameRange(lwb, upb)) { cout <<
"Invalid index bounds!" << endl;
return false; }
491 for (
int i1 = lwb; i1 <= upb; i1++) {
493 sumN(i1) = sumN(i1) + history->
data(j)->
delta(i1)/TMath::Power(history->
data(j)->
adcMax(), 2);
494 for (
int i2 = lwb; i2 <= upb; i2++) {
495 sumCN(i1, i2) = sumCN(i1, i2) +
ofc->Gamma()(i1, i2)/TMath::Power(history->
data(j)->
adcMax(), 2);
499 sumA += 1/TMath::Power(history->
data(j)->
adcMax(), 2);
505 k.ResizeTo(lwb, upb);
506 means.ResizeTo(lwb, upb);
508 for (
int i1 = lwb; i1 <= upb; i1++) {
510 sumN(i1) = sumN(i1)/
n;
514 for (
int i1 = lwb; i1 <= upb; i1++) {
515 for (
int i2 = lwb; i2 <= upb; i2++) {
516 sumCN(i1, i2) = sumCN(i1, i2)/
n;
517 sum2N(i1, i2) = sum2N(i1, i2)/
n;
518 k(i1, i2) = sum2N(i1, i2) - sumN(i1)*
sum(i2) -
sum(i1)*sumN(i2)
519 +
sum(i1)*
sum(i2)*sumA - sumCN(i1,i2);
520 k(i1, i2) = (
k(i1, i2) >= 0 ? sqrt(
k(i1, i2)) : -sqrt(-
k(i1, i2)));
532 shape =
ref =
nullptr;
537 if ((
i+1) % 50000 == 0) cout <<
"Cell # " <<
i+1 <<
"/" <<
nChannels() << endl;
539 if (!history)
continue;
540 for (
unsigned int j = 0; j < history->
nData(); j++) {
541 if (!
f.passEvent(*history->
data(j)))
continue;
543 cout <<
"Adding pulse (" <<
n+1 <<
") at hash " <<
i <<
", index " << j <<
", max = " << maxSum/(
n+1) << endl;
566 if (!history)
return nullptr;
569 if (
adjust)
delete history;
575 unsigned int minSize,
bool weigh,
bool adjust,
bool zeroTime)
const
578 std::vector< std::vector<ResidualCalculator> > ringCalcs;
582 cout <<
"Processing cells" << endl;
585 if ((
i+1) % 10000 == 0) cout <<
"Processing hash = " << (
i+1) << endl;
588 if (residuals && (resTrunc > 0 || timeTrunc > 0)) {
591 residuals = truncated;
594 if (residuals && residuals->
size() < minSize) {
618 cout <<
"Processing phi-symmetric data" << endl;
622 if (ringCalcs[
g][
i].
size() > 0)
623 cout <<
"Saving data for gain " <<
g <<
", phi ring " <<
i <<
", n = " << ringCalcs[
g][
i].
size() <<
", range = " << ringCalcs[
g][
i].rangeStr() << endl;
628 cout <<
"Done!" << endl;