void time_res(void) { gROOT->Reset(); // Timewalk corrections. These were obtained by running the // timewalk.C macro and copying the last few lines that // printed to stdout. // old walkcorrections // char *tn7 = "(tn7-(3.331473*exp(-0.006549*n7)+0.773828+(-0.000631*n7)))"; // char *tn8 = "(tn8-(2.421650*exp(-0.005287*n8)+0.410419+(-0.000499*n8)))"; // char *ts7 = "(ts7-(3.248674*exp(-0.006659*s7)+0.563583+(-0.000647*s7)))"; // char *ts8 = "(ts8-(2.566994*exp(-0.005763*s8)+0.494722+(-0.000601*s8)))"; // char *tn9 = "(tn9-(2.848297*exp(-0.010014*n9)+0.762059+(-0.001716*n9)))"; // char *ts9 = "(ts9-(2.648966*exp(-0.005678*s9)+0.286492+(-0.000976*s9)))"; // newest WC char *tn7 = "(tn7-(3.318633*exp(-0.007758*n7)+-2.285192+(-0.000754*n7)))"; char *ts7 = "(ts7-(2.209792*exp(-0.006442*s7)+-2.561431+(-0.000607*s7)))"; char *tn8 = "(tn8-(2.512104*exp(-0.004475*n8)+-2.579980+(-0.000414*n8)))"; char *ts8 = "(ts8-(2.396487*exp(-0.005468*s8)+-2.408689+(-0.000530*s8)))"; char *tn9 = "(tn9-(3.379855*exp(-0.008501*n9)+-2.716681+(-0.001110*n9)))"; char *ts9 = "(ts9-(3.284677*exp(-0.006599*s9)+-2.976956+(-0.000848*s9)))"; // Create canvas with 2 pads, top for no timewalk correction, bottom corrected TCanvas *c1 = new TCanvas("c1","",600,800); c1->Divide(1,4); for(int i=1; i<=3; i++){ c1->GetPad(i)->SetTickx(); c1->GetPad(i)->SetTicky(); } // Get pointer to bcal TTree TTree *bcal = (TTree*)gROOT->FindObject("bcal"); // Make histograms to hold time diff vs. photon energy plot TH2F *tdiff_vs_Ephoton = new TH2F("tdiff_vs_Ephoton", "#Deltat vs. Ephoton", 100, 150.0, 650.0, 100, -10.0, 10.0); TH2F *tdiff_vs_Ephoton_corr = new TH2F("tdiff_vs_Ephoton_corr", "#Deltat vs. Ephoton timewalk corrected", 100, 150.0, 650.0, 100, -10.0, 10.0); // Set labels and turn off stats for pretty plotting tdiff_vs_Ephoton->SetStats(0); tdiff_vs_Ephoton->SetYTitle("Difference in mean times between cell 8 and tagger (ns)"); tdiff_vs_Ephoton->SetXTitle("E_{#gamma} from tagger (MeV)"); tdiff_vs_Ephoton_corr->SetStats(0); tdiff_vs_Ephoton_corr->SetYTitle("Difference in mean times between cell 8 and tagger (ns)"); tdiff_vs_Ephoton_corr->SetXTitle("E_{#gamma} from tagger (MeV)"); // Draw time difference between mean time of cell 7 and tagger // vs. photon energy without timewalk correction. c1->cd(1); bcal->Project("tdiff_vs_Ephoton", "(tn9+ts9)/2.0 + tphoton-531 :Ephoton", "Nphotons==1&&n9>200&&s9>200"); tdiff_vs_Ephoton->Draw(); // Draw time difference between mean time of cell 7 and tagger // vs. photon energy WITH timewalk corrections. c1->cd(2); char expr[512]; sprintf(expr, "(%s+%s)/2.0 +tphoton-531:Ephoton", tn9, ts9); bcal->Project("tdiff_vs_Ephoton_corr", expr, "Nphotons==1&&n9>200&&s9>200"); tdiff_vs_Ephoton_corr->SetMarkerColor(kRed); tdiff_vs_Ephoton_corr->Draw(); // Fit slices of both the corrected and uncorrected histograms // and plot the sigmas vs. photon energy to see the improvement. tdiff_vs_Ephoton->FitSlicesY(); tdiff_vs_Ephoton_corr->FitSlicesY(); TH1D* tdiff_vs_Ephoton_2 = (TH1D*)gROOT->FindObject("tdiff_vs_Ephoton_2"); TH1D* tdiff_vs_Ephoton_corr_2 = (TH1D*)gROOT->FindObject("tdiff_vs_Ephoton_corr_2"); c1->cd(3); TH2F *axes = new TH2F("axes","#sigma_{#Deltat} vs. E_{#gamma}", 100, 150, 650, 100, 0.0, 1.0); axes->SetStats(0); axes->SetYTitle("#sigma of difference in mean times between cell 9 and tagger (ns)"); axes->SetXTitle("E_{#gamma} from tagger (MeV)"); axes->Draw(); tdiff_vs_Ephoton_2->Draw("same"); tdiff_vs_Ephoton_corr_2->SetMarkerColor(kRed); tdiff_vs_Ephoton_corr_2->SetLineColor(kRed); tdiff_vs_Ephoton_corr_2->Draw("same"); c1->Update(); c1->cd(4); // TH2F *axes2 = new TH2F("axes2","#sigma_{#Deltat} vs. E_{#gamma}", 100, 150, 650, 100, 0.0, 1.0); // axes2->SetStats(0); // axes2->SetYTitle("#sigma of difference in mean times between cell 7 and tagger (ns)"); // axes2->SetXTitle("E_{#gamma} from tagger (MeV)"); // axes2->Draw(); TH1D* tdiff_vs_Ephoton_corr_3 = (TH1D*)gROOT->FindObject("tdiff_vs_Ephoton_corr_2"); tdiff_vs_Ephoton_corr_3->Draw(""); TF1 *f1 = new TF1("f1","sqrt(([0]*1/sqrt(x/1000))^2 + ([1])^2) ",150,650); f1->SetParameters(0.2,0.2); //initialize fit parameters tdiff_vs_Ephoton_corr_3->Fit("f1"); tdiff_vs_Ephoton_corr_3->SetStats(1); //add resulting fit equation to plot double p0 = f1->GetParameter(0); double e0 = f1->GetParError(0); double p1 = f1->GetParameter(1); double e1 = f1->GetParError(1); double chi2 = f1->GetChisquare(); double ndf = f1->GetNDF(); char pictext[100]; sprintf(pictext,"#frac{ %.3f #pm %.3f }{#sqrt{E}} #oplus ( %.3f #pm %.3f ) ",p0,e0,p1,e1); TLatex *l = new TLatex(200,0.3,pictext); l->SetTextSize(0.055); l->Draw(); c1->Update(); // Save to file c1->SaveAs("bcal_time_res_vs_Ephoton_9.gif"); }