#include #include #include #include #include #include #include #include #include using namespace std; #include "tdiff.cc" #include "E_calibrate.cc" #include "Angle.h" #include "Geom.h" #include "StandardLabels.C" void GetPoints(TH2D *h, TGraphErrors* &gres, TGraph* &gmean); //------------------------------------ // Copied from JEventProcessor_bcal_timing.cc typedef struct{ int event; int layer; int sector; int fADC_up; int fADC_dn; float Etot; float geometric_mean; float tup; float tdn; float tup_corrected; float tdn_corrected; float theta_thrown; float E_thrown; }HIT_t; //------------------------------------ //----------------- // tdiff_check //----------------- void tdiff_check(void) { TFile *f = new TFile("hd_root.root"); f->cd(); TTree *tree = (TTree*)gROOT->FindObject("tree"); HIT_t hit; HIT_t *hitptr = &hit; TBranch *branch = tree->GetBranch("T"); branch->SetAddress(hitptr); // Make histograms to hold tdiff vs. geometric mean // for each layer. TH2D *tdiff_vs_geomn[10+1]; for(int ilayer=1; ilayer<=MaxSummedLayers() ; ilayer++){ char hname[256]; sprintf(hname, "tdiff_vs_geomn_lay%02d",ilayer); tdiff_vs_geomn[ilayer] = new TH2D(hname, "", 4000, 0.0, 8000.0, 100, -5.0, 5.0); } vector tdiff_correcteds[10+1]; vector geomns[10+1]; int Nentries = branch->GetEntries(); for(int i=1; i<=Nentries; i++){ tree->GetEntry(i); if(hit.layer<1 || hit.layer>MaxSummedLayers())continue; // bulletproof if(hit.tup_corrected<-100)continue; if(hit.tdn_corrected<-100)continue; float tdiff = (hit.tup_corrected - hit.tdn_corrected)/2.0; float geomn = hit.geometric_mean; float tdiff_corrected = tdiff - BCAL_tdiff(geomn, hit.layer); geomns[hit.layer].push_back(geomn); tdiff_correcteds[hit.layer].push_back(tdiff_corrected); tdiff_vs_geomn[hit.layer]->Fill(geomn, tdiff_corrected); } TCanvas *c1 = new TCanvas("c1"); c1->SetTicks(); c1->SetGrid(); c1->SetLogx(); // Open PDF file for plots c1->Print("tdiff_check.ps["); // Loop over layers int Nlayers=0; TF1 *sigma_vs_geomn[10+1]; for(int ilayer=1; ilayer<=MaxSummedLayers() ; ilayer++, Nlayers++){ //for(int ilayer=1; ilayer<=1 ; ilayer++, Nlayers++){ // Find appropriate minimum/maximum for x-axis float *v = &geomns[ilayer][0]; TH1D *htmp = new TH1D("htmp", "", 800, 0.0, 8000.0); for(unsigned int i=0; iFill(v[i]); for(int ibin=2; ibin<=htmp->GetNbinsX(); ibin++)htmp->SetBinContent(ibin, htmp->GetBinContent(ibin)+htmp->GetBinContent(ibin-1)); double hnorm = htmp->GetBinContent(htmp->GetNbinsX()); if(hnorm<=0.0)hnorm = 1.0; htmp->Scale(1.0/hnorm); double xmin = 0.0; for(int ibin=2; ibin<=htmp->GetNbinsX(); ibin++){ if(htmp->GetBinContent(ibin)>0.02)break; xmin = htmp->GetXaxis()->GetBinCenter(ibin); } double xmax = 0.0; for(int ibin=2; ibin<=htmp->GetNbinsX(); ibin++){ if(htmp->GetBinContent(ibin)>0.95)break; xmax = htmp->GetXaxis()->GetBinCenter(ibin); } xmax*=2.0; cout<<"xmax="<SetStats(0); axes->SetXTitle("fADC"); axes->SetYTitle("#Deltat/2 (ns)"); TGraph *g = new TGraph(geomns[ilayer].size(), &geomns[ilayer][0], &tdiff_correcteds[ilayer][0]); char title[256]; sprintf(title, "#Deltat/2 for layer %d", ilayer); axes->SetTitle(title); TGraphErrors *gres; TGraph *gmean; GetPoints(tdiff_vs_geomn[ilayer], gres, gmean); axes->Draw(); g->Draw("Psame"); gres->Draw("same"); gmean->Draw("Psame"); cout<<"Number of points:"<GetN()<GetFunction("fun"); if(fun){ char funname[256]; sprintf(funname, "sigma_vs_geomn_lay%02d", ilayer); sigma_vs_geomn[ilayer] = (TF1*)fun->Clone(funname); }else{ sigma_vs_geomn[ilayer] = NULL; } // Function label if(sigma_vs_geomn[ilayer]){ TF1 *fun = sigma_vs_geomn[ilayer]; char flab[256]; if(fun->GetNpar()==4){ double conv_to_gev = pow(BCAL_E2fADC(1.0), fun->GetParameter(2)); // factor to convert par1 and par 3 so function can be expressed as E in GeV double p0 = fun->GetParameter(0)*1000.0; double p1 = fun->GetParameter(1)/conv_to_gev*1000.0; double p2 = fun->GetParameter(2); double p3 = fun->GetParameter(3)/conv_to_gev; sprintf(flab,"#sigma_{#Deltat} = %dps + #frac{%gps}{E^{%4.2f}%+g}", (int)p0, p1, p2, p3); }else{ sprintf(flab,"#sigma_{#Deltat} = %dps", (int)(fun->GetParameter(0)*1000.0)); } TLatex *lab = new TLatex(xmax/2.0, 1.5, flab); lab->SetTextSize(0.03); lab->SetTextAlign(22); lab->Draw(); } StandardLabels(axes, Scheme(), "", AngleStr("#theta_{#gamma}=")); c1->Update(); c1->Print("tdiff_check.ps"); char fname[256]; sprintf(fname, "tdiff_check_layer%02d.png", ilayer); c1->SaveAs(fname); } // Close PDF file c1->Print("tdiff_check.ps]"); cout<<"Plots written to \"tdiff_check.ps\". Convert to PDF with:"<GetExpFormula("p")).Data(); while(true){ size_t pos=expr.find("(x^"); if(pos!=string::npos){ expr.replace(pos, 3, "pow(x,"); }else{ break; } } // Set resolution to 100ns for outer detectors, // effictively disabling them if(IsOuter(ilayer))expr = "100.0"; pout<<"\t\t\t"<<"return "<ProjectionX("_px", 1); // Loop over (uneven) bins int Npoints = 0; vector x; vector y; vector y_mean; vector yerr; int Nbins = h->GetNbinsX(); for(int start_bin=1; start_bin<=Nbins; ){ // Find limits to give us min_entries entries int end_bin = start_bin; while(h_px->Integral(start_bin, end_bin)Integral(end_bin, Nbins)Integral()>=20){ // Fit to Gaussian h_py->Fit("gaus","0Q"); //c1->Update(); // Get fit results double mean = h_py->GetFunction("gaus")->GetParameter(1); double sigma = h_py->GetFunction("gaus")->GetParameter(2); double sigma_err = h_py->GetFunction("gaus")->GetParError(2); // Find average fADC value for hits in this bin range double fADC = 0.0; double norm = 0.0; for(int bin=start_bin; bin<=end_bin; bin++){ double weight = h_px->GetBinContent(bin); fADC += h_px->GetBinCenter(bin)*weight; norm += weight; } fADC /= norm; // Add floor term to error obtained from Gaussian fit double epsilon = 0.050; // ns sigma_err = sqrt(sigma_err*sigma_err + epsilon*epsilon); x.push_back(fADC); y.push_back(sigma); y_mean.push_back(mean); yerr.push_back(sigma_err); Npoints++; } // Increment for next iteration start_bin=end_bin+1; } gres = new TGraphErrors(Npoints, &x[0], &y[0], 0, &yerr[0]); gres->SetMarkerColor(kMagenta); gres->SetLineColor(kMagenta); gres->SetLineWidth(2.0); gmean = new TGraph(Npoints, &x[0], &y_mean[0]); gmean->SetMarkerColor(kRed); gmean->SetMarkerStyle(22); gmean->SetLineColor(kRed); // Fit the graph. If there are less than 8 points, just fit to // a flat line. TF1 *fun; if(Npoints<4){ fun = new TF1("fun", "[0]"); }else{ fun = new TF1("fun", "[0] + [1]/(pow(x,[2])+[3])"); fun->SetParameter(0, 0.037); fun->SetParameter(1, 1000.0); fun->SetParameter(2, 1.0); fun->SetParameter(3, -3.0); fun->SetParLimits(2, 0.0, 10.0); } fun->SetLineColor(kBlue); gres->Fit(fun); }