28 #include <TDirectory.h>
35 #include <TFitResult.h>
36 #include <TFitResultPtr.h>
96 Double_t
fitf(Double_t *
x, Double_t *par) {
98 Double_t
f = par[0] + par[1]*pow((xx/
THRESHOLD),par[2]);
105 TF1 *ftw =
new TF1(
"ftw",
fitf,100.,1000.,3);
107 std::cout <<
"Defined time-walk fit function" << std::endl;
110 ftw->SetParameter(0,-1.9);
111 ftw->SetParameter(1,4.8);
112 ftw->SetParameter(2,-0.4);
113 ftw->SetParName(0,
"c0");
114 ftw->SetParName(1,
"c1");
115 ftw->SetParName(2,
"c2");
117 h_tw->Fit(
"ftw",
"RWq");
119 std::cout <<
"Fit histogram" << std::endl;
122 c0[arm][module] = ftw->GetParameter(
"c0");
123 c1[arm][module] = ftw->GetParameter(
"c1");
124 c2[arm][module] = ftw->GetParameter(
"c2");
126 std::cout <<
"c0: " <<
c0[arm][module] << std::endl;
127 std::cout <<
"c1: " <<
c1[arm][module] << std::endl;
128 std::cout <<
"c2: " <<
c2[arm][module] << std::endl;
136 infile =
new TFile(inputFile);
137 outfile =
new TFile(
"results.root",
"RECREATE");
141 std::cout <<
"Creating output file directories" << std::endl;
144 outfile->mkdir(
"dt_vs_pp/dt_vs_pp_L");
145 outfile->mkdir(
"dt_vs_pp/dt_vs_pp_R");
146 outfile->mkdir(
"dt_vs_pp_corr");
147 outfile->mkdir(
"dt_vs_pp_corr/dt_vs_pp_corr_L");
148 outfile->mkdir(
"dt_vs_pp_corr/dt_vs_pp_corr_R");
149 outfile->mkdir(
"dt_vs_pp_profile");
150 outfile->mkdir(
"dt_vs_pp_profile/dt_vs_pp_profile_L");
151 outfile->mkdir(
"dt_vs_pp_profile/dt_vs_pp_profile_R");
154 TCanvas *
c = (TCanvas*)gROOT->FindObject(
"c");
156 c =
new TCanvas(
"c",
"c",0,20,600,500);
161 std::cout <<
"Naming histograms" << std::endl;
164 for (Int_t i = 0; i <
NMODULES; ++i) {
166 h_dt_l[i] =
new TH1D(Form(
"dt_l_%i",i+1),
167 Form(
"Time difference;PSC_L_%i - RF_L (ns)",i+1),
169 h_pp_l[i] =
new TH1D(Form(
"pp_l_%i",i+1),
170 Form(
"Pulse peak;PSC_L_%i pulse peak (adc counts)",i+1),
174 Form(
"Time difference vs pulse peak for PSC_L_%i",i+1),
176 g_dt_vs_pp_l[i] =
new TProfile(Form(
"g_dt_vs_pp_L_%i",i+1),
177 Form(
"Time difference vs pulse peak for PSC_L_%i",i+1),
183 h_dt_r[i] =
new TH1D(Form(
"dt_r_%i",i+1),
184 Form(
"Time difference;PSC_R_%i - RF_R (ns)",i+1),
186 h_pp_r[i] =
new TH1D(Form(
"pp_r_%i",i+1),
187 Form(
"Pulse peak;PSC_R_%i pulse peak (adc counts)",i+1),
191 Form(
"Time difference vs pulse peak for PSC_R_%i",i+1),
193 g_dt_vs_pp_r[i] =
new TProfile(Form(
"g_dt_vs_pp_R_%i",i+1),
194 Form(
"Time difference vs pulse peak for PSC_R_%i",i+1),
200 "Mean time difference for each PSC counter before corrections;\
201 Counter (1-8 left, 9-16 right);\
202 #Deltat (PSC - RF) [ns]",
203 2*NMODULES,1.0,2*NMODULES+1.0);
206 h_means_b->GetYaxis()->SetTitleOffset(1.2);
208 "Sigmas for time difference for each PSC counter before corrections;\
209 Counter (1-8 left, 9-16);\
211 2*NMODULES,1.0,2*NMODULES+1.0);
216 "Mean time difference for each PSC counter after corrections;\
217 Counter (1-8 left, 9-16 right);\
218 #Deltat (PSC - RF) [ns]",
219 2*NMODULES,1.0,2*NMODULES+1.0);
222 h_means_a->GetYaxis()->SetTitleOffset(1.2);
224 "Sigmas for time difference for each PSC counter after corrections;\
225 Counter (1-8 left, 9-16);\
227 2*NMODULES,1.0,2*NMODULES+1.0);
233 std::cout <<
"Fitting initial timing distributions" << std::endl;
235 for (Int_t i = 0; i <
NMODULES; ++i) {
238 TFitResultPtr resultpL0 =
h_dt_l[i]->Fit(
"gaus",
"sq");
239 double meanL = resultpL0->Parameter(1);
240 double sigmaL = resultpL0->Parameter(2);
243 TFitResultPtr resultpL =
h_dt_l[i]->Fit(
"gaus",
"sq",
"",meanL-2*sigmaL,meanL+2*sigmaL);
244 dtMeanL[i] = resultpL->Parameter(1);
246 h_means_b->SetBinError(i+1,resultpL->ParError(1));
248 h_sigmas_b->SetBinError(i+1,resultpL->ParError(2));
250 std::cout <<
"Sigma for left module " << i+1 <<
" is " << 1000*resultpL->Parameter(2) << std::endl;
257 TFitResultPtr resultpR0 =
h_dt_r[i]->Fit(
"gaus",
"sq");
258 double meanR = resultpR0->Parameter(1);
259 double sigmaR = resultpR0->Parameter(2);
262 TFitResultPtr resultpR =
h_dt_r[i]->Fit(
"gaus",
"sq",
"",meanR-2*sigmaR,meanR+2*sigmaR);
263 dtMeanR[i] = resultpR->Parameter(1);
265 h_means_b->SetBinError(i+NMODULES+1,resultpR->ParError(1));
266 h_sigmas_b->Fill(i+NMODULES+1,resultpR->Parameter(2));
267 h_sigmas_b->SetBinError(i+NMODULES+1,resultpR->ParError(2));
269 std::cout <<
"Sigma for right module " << i+1 <<
" is " << 1000*resultpR->Parameter(2) << std::endl;
279 std::cout <<
"Making TProfile" << std::endl;
281 for (Int_t m = 0; m <
NMODULES; ++m) {
282 for (Int_t i = 1; i <= 1000; ++i) {
283 for (Int_t j = 1; j <= 100; ++j) {
285 Double_t content_l =
h_dt_vs_pp_l[m]->GetBinContent(i,j);
286 double t_shift_l = -5 + 0.1*j -
dtMeanL[m];
287 if (content_l > 0 && t_shift_l < -2)
289 else if (content_l > 0 && t_shift_l > 2)
295 Double_t content_r =
h_dt_vs_pp_r[m]->GetBinContent(i,j);
296 double t_shift_r = -5 + 0.1*j -
dtMeanR[m];
297 if (content_r > 0 && t_shift_r < -2)
299 else if (content_r > 0 && t_shift_r > 2)
308 std::cout <<
"Getting most probable value" << std::endl;
311 for (Int_t i = 0; i <
NMODULES; ++i) {
314 TFitResultPtr ptrL1 =
h_pp_l[i]->Fit(
"landau",
"sq");
315 double mpv_L = ptrL1->Parameter(1);
316 double sigma_pp_L = ptrL1->Parameter(2);
317 TFitResultPtr ptrL2 =
h_pp_l[i]->Fit(
"landau",
"sq",
"",mpv_L-1.5*sigma_pp_L,mpv_L+1.5*sigma_pp_L);
318 mpv[0][i] = ptrL2->Parameter(1);
322 TFitResultPtr ptrR1 =
h_pp_r[i]->Fit(
"landau",
"sq");
323 double mpv_R = ptrR1->Parameter(1);
324 double sigma_pp_R = ptrR1->Parameter(2);
325 TFitResultPtr ptrR2 =
h_pp_r[i]->Fit(
"landau",
"sq",
"",mpv_R-1.5*sigma_pp_R,mpv_R+1.5*sigma_pp_R);
326 mpv[1][i] = ptrR2->Parameter(1);
330 std::cout <<
"Writing to file ..." << std::endl;
332 for (Int_t i = 0; i <
NMODULES; ++i) {
334 outfile->cd(
"dt_vs_pp/dt_vs_pp_L");
337 outfile->cd(
"dt_vs_pp_profile/dt_vs_pp_profile_L");
341 outfile->cd(
"dt_vs_pp/dt_vs_pp_R");
344 outfile->cd(
"dt_vs_pp_profile/dt_vs_pp_profile_L");
350 for (
int j = 0; j <
NMODULES; ++j) {
352 std::cout <<
"Calling tw_fit() for modules " << j << std::endl;
364 std::cout <<
"Input file: " << inputFile << std::endl;
369 std::cout <<
"Writing psc_tw_parms.out" << std::endl;
372 std::ofstream
flog(
"psc_tw_parms.out");
373 for (Int_t i = 0; i < 2; ++i) {
374 for (Int_t j = 0; j <
NMODULES; ++j) {
375 flog << i << std::setw(15)
376 << j+1 << std::setw(15)
377 <<
c0[i][j] << std::setw(15)
378 <<
c1[i][j] << std::setw(15)
379 <<
c2[i][j] << std::setw(15)
381 <<
mpv[i][j] << std::endl;
386 std::cout <<
"About to fill corrected histograms" << std::endl;
388 for (Int_t i = 0; i <
NMODULES; ++i) {
389 for (Int_t j = 0; j < 1000; ++j) {
390 for (Int_t k = 0; k < 100; ++k) {
393 double t_shift_l = -5 + 0.1*k -
dtMeanL[i];
394 if (content_l > 0 && t_shift_l > 2)
396 else if (content_l > 0 && t_shift_l < -2)
403 double t_shift_r = -5 + 0.1*k -
dtMeanR[i];
404 if (content_r > 0 && t_shift_r > 2)
406 else if (content_r > 0 && t_shift_r < -2)
414 for (Int_t i = 0; i <
NMODULES; ++i) {
416 outfile->cd(
"dt_vs_pp_corr/dt_vs_pp_corr_L");
420 outfile->cd(
"dt_vs_pp_corr/dt_vs_pp_corr_R");
429 std::ofstream flogsig(
"sigmas.out");
430 flogsig <<
"Arm\t" <<
"Module\t" <<
"Sigma (ps)" << std::endl;
432 for (Int_t i = 0; i <
NMODULES; ++i) {
435 TFitResultPtr ptrL =
h_dt_l_corr[i]->Fit(
"gaus",
"sq");
436 double mean = ptrL->Parameter(1);
437 double sigma = ptrL->Parameter(2);
438 ptrL =
h_dt_l_corr[i]->Fit(
"gaus",
"sq",
"",mean-2*sigma,mean+2*sigma);
439 mean = ptrL->Parameter(1);
440 sigma = ptrL->Parameter(2);
442 h_means_a->SetBinError(i+1,ptrL->ParError(1));
444 h_sigmas_a->SetBinError(i+1,ptrL->ParError(2));
446 std::cout <<
"Sigma for left module " << i+1 <<
": " << sigma*1000 << std::endl;
450 flogsig <<
"0\t" << i+1 <<
"\t" << sigma*1000 << std::endl;
454 TFitResultPtr ptrR =
h_dt_r_corr[i]->Fit(
"gaus",
"sq");
455 mean = ptrR->Parameter(1);
456 sigma = ptrR->Parameter(2);
457 ptrR =
h_dt_r_corr[i]->Fit(
"gaus",
"sq",
"",mean-2*sigma,mean+2*sigma);
458 mean = ptrR->Parameter(1);
459 sigma = ptrR->Parameter(2);
461 h_means_a->SetBinError(i+NMODULES+1,ptrR->ParError(1));
463 h_sigmas_a->SetBinError(i+NMODULES+1,ptrR->ParError(2));
465 std::cout <<
"Sigma for right module " << i+1 <<
": " << sigma*1000 << std::endl;
469 flogsig <<
"1\t" << i+1 <<
"\t" << sigma*1000 << std::endl;
477 if (TVirtualPad::Pad() == NULL)
478 c =
new TCanvas(
"PSC_TW",
"PSC_TW",1200,600);
480 c = gPad->GetCanvas();
484 gStyle->SetOptStat(0);
487 TPad*
pad = (TPad*)c->GetPad(1);
488 pad->SetLeftMargin(0.15);
493 pad = (TPad*)c->GetPad(2);
494 pad->SetLeftMargin(0.15);
499 pad = (TPad*)c->GetPad(3);
500 pad->SetLeftMargin(0.15);
505 pad = (TPad*)c->GetPad(4);
506 pad->SetLeftMargin(0.15);
510 c->Print(
"CalibCheck.pdf",
"pdf");
517 std::cout <<
"avgL: " << avgL << std::endl;
518 std::cout <<
"avgR: " << avgR << std::endl;
519 std::cout <<
"avg: " << avg << std::endl;
std::ofstream flog("tagm_tw_parms_defaults.out")
TH2F * h_dt_vs_pp_r[NMODULES]
void tw_corr(char const *inputFile)
TH1D * h_dt_r_corr[NMODULES]
TH2F * h_dt_vs_pp_l[NMODULES]
TH1D * h_dt_l_corr[NMODULES]
Double_t fitf(Double_t *x, Double_t *par)
void tw_plot(char const *inputFile)
TProfile * g_dt_vs_pp_r[NMODULES]
Double_t dtMeanL[NMODULES]
Double_t dtMeanR[NMODULES]
Double_t sigma[NCHANNELS]
TProfile * g_dt_vs_pp_l[NMODULES]
void tw_fit(TProfile *h_tw, int arm, int module)
TH2F * h_dt_vs_pp_l_corr[NMODULES]
Double_t mpv[2][NMODULES]
TH2F * h_dt_vs_pp_r_corr[NMODULES]