#include #include #include #include #include #include #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; //------------------------------------ //----------------- // E_calibrate //----------------- void E_calibrate(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); TH2D *h = new TH2D("h", "", 200, 0.0, 13000.0, 200, 0.0, 2.0); TH2D *y = new TH2D("y", "", 200, 0.0, 2.0, 200, 0.0, 13000.0); // Loop over all events and fill histogram. We do this // rather than TTree::Project since we need to call the // BCAL_tdiff_res for each entry int Nentries = branch->GetEntries(); double E_thrown = 0.0; double E_tot = 0.0; int last_event=1; for(int i=1; i<=Nentries; i++){ tree->GetEntry(i); // Fill histogram on event boundaries and reset for next event if(hit.event!=last_event){ h->Fill(E_tot, E_thrown); y->Fill(E_thrown, E_tot); E_thrown = 0.0; E_tot = 0.0; last_event = hit.event; } if(hit.layer<1 || hit.layer>MaxSummedLayers())continue; // if(hit.tup_corrected<-100)continue; if(hit.tdn_corrected<-100)continue; // Accumulate info for this event double geomn = hit.geometric_mean; double E = geomn; E_tot += E; E_thrown = hit.E_thrown; } TGraphErrors *gres; TGraphErrors *gmean; GetPoints(h, gres, gmean); TCanvas *c1 = new TCanvas("c1"); c1->SetTicks(); c1->SetGrid(); //c1->SetLogx(); TF1 *fun = new TF1("fun", "[0]+x*([1]+x*([2]+x*([3])))"); fun->FixParameter(0, 0.0); fun->SetParameter(1, 2.0/11000.0); fun->SetParameter(2, 0.0); fun->SetParameter(3, 0.0); gmean->Fit(fun); TH2D *axes = new TH2D("axes","", 100, 0.0, 13000.0, 100, 0.0, 2.0); axes->SetStats(0); axes->SetXTitle("#Sigma Geometric mean (fADC counts)"); axes->SetYTitle("Energy generated (GeV)"); axes->Draw(); h->Draw("same"); gmean->Draw("Psame"); gres->Draw("Psame"); StandardLabels(axes, Scheme(), "", AngleStr("#theta_{#gamma}=")); c1->SaveAs("E_calibrate.pdf"); c1->SaveAs("E_calibrate.png"); // For the "calibration" file we want two functions. One // that converts fADC values to GeV and the one that does // the inverse. For the inverse function we just do a fit // to the "y" histogram (x-y axes exchanged relative to "h") TGraphErrors *ygres; TGraphErrors *ygmean; GetPoints(y, ygres, ygmean); TF1 *fun2 = new TF1("fun2", "[0]+x*([1]+x*([2]+x*([3])))"); fun2->FixParameter(0, 0.0); fun2->SetParameter(1, 11000.0/2.0); fun2->SetParameter(2, 0.0); fun2->SetParameter(3, 0.0); ygmean->Fit(fun2); // Write parameters out in form of C++ file const char *cppfname = "E_calibrate.cc"; ofstream pout(cppfname); pout<"<GetParameter(j); } pout<<" };"<GetParameter(j); } pout<<" };"<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 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 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.010; // GeV 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); gmean = new TGraphErrors(Npoints, &x[0], &y_mean[0], 0, &y_mean_err[0]); gmean->SetMarkerColor(kRed); gmean->SetMarkerStyle(22); gmean->SetLineColor(kRed); }