#include #include #include #include #include #include #include #include #include using namespace std; #include "StandardLabels.C" #include "Angle.h" #include "Geom.h" void GetPoints(TH2D *h, TGraphErrors* &gres, TGraphErrors* &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_calibrate //----------------- void tdiff_calibrate(void) { TFile *f = new TFile("hd_root.root"); f->cd(); TTree *tree = (TTree*)gROOT->FindObject("tree"); TCanvas *c1 = new TCanvas("c1"); c1->SetTicks(); c1->SetGrid(); c1->SetLogx(); TF1 *fun = new TF1("fun", "[0]+log(x)*([1]+log(x)*([2]+log(x)*([3]+log(x)*([4]+log(x)*([5]+log(x)*[6])))))", 0.0, 3500.0); double parms[10+1][7]; // Open PDF file for plots c1->Print("tdiff.ps["); // Loop over layers int Nlayers=0; for(int ilayer=1; ilayer<=MaxSummedLayers() ; ilayer++, Nlayers++){ //for(int ilayer=1; ilayer<=1 ; ilayer++, Nlayers++){ // First, project onto a 2D histo and then project slices // of that onto a temporary histo. This speeds things up // considerably compared to projecting each slice individually TH2D *hmax_2D = new TH2D("hmax_2D","", 800, 0.0, 8000.0, 600, -15.0, 15.0); char cut[256]; sprintf(cut, "layer==%d && tup_corrected>-100 && tdn_corrected>-100", ilayer); tree->Project("hmax_2D", "(tup_corrected - tdn_corrected)/2.0:geometric_mean", cut); TGraphErrors *gres; TGraphErrors *gmean; GetPoints(hmax_2D, gres, gmean); // Find appropriate minimum/maximum for x-axis TH1D *htmp = hmax_2D->ProjectionX(); 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; TH2D *axes = new TH2D("axes","", 100, xmin, xmax, 100, -2.0, 2.0); axes->SetStats(0); axes->SetXTitle("fADC"); axes->SetYTitle("#Deltat/2 (ns)"); char title[256]; sprintf(title, "#Deltat/2 for layer %d", ilayer); axes->SetTitle(title); fun->SetLineColor(kRed); fun->SetParameter(0, 0.0); fun->SetParameter(1, 0.0); fun->SetParameter(2, 0.0); fun->SetParameter(3, 0.0); fun->SetParameter(4, 0.0); fun->SetParameter(5, 0.0); fun->SetParameter(6, 0.0); // Limit number of free parameters based on numberof data points int Nfree_parms = (int)gres->GetN(); for(int ipar=Nfree_parms+1; ipar<=6; ipar++)fun->FixParameter(ipar, 0.0); gmean->Fit("fun","","",30.0, xmax); gmean->SetLineColor(kMagenta); axes->Draw(); tree->Draw("(tup_corrected - tdn_corrected)/2.0:geometric_mean", cut, "same"); gmean->Draw("Psame"); for(int ipar=0; ipar<=6; ipar++)parms[ilayer][ipar] = fun->GetParameter(ipar); cout<<"Number of points:"<GetN()<SaveAs(fname); } // Close PDF file c1->Print("tdiff.ps]"); // Write parameters out in form of C++ file const char *cppfname = "tdiff.cc"; ofstream pout(cppfname); pout<"<NLAYERS_BCAL ? NLAYERS_BCAL:layer;"<ProjectionX("_px", 1); // Loop over (uneven) bins int Npoints = 0; vector x; vector y; vector y_mean; vector yerr; vector y_mean_err; 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 int status = h_py->Fit("gaus","0Q"); if(status!=0){ start_bin++; continue; } //c1->Update(); // Get fit results double mean = h_py->GetFunction("gaus")->GetParameter(1); double sigma = h_py->GetFunction("gaus")->GetParameter(2); double mean_err = h_py->GetFunction("gaus")->GetParError(1); 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 mean_err = sqrt(mean_err*mean_err + epsilon*epsilon); 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); y_mean_err.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 TGraphErrors(Npoints, &x[0], &y_mean[0], 0, &y_mean_err[0]); gmean->SetMarkerColor(kRed); gmean->SetMarkerStyle(22); gmean->SetLineColor(kRed); }