#include #include #include #include #include #include #include #include #include using namespace std; #include "StandardLabels.C" //------------------------------------ // 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; }HIT_t; //------------------------------------ //----------------- // tdiff_calibrate_tgraph //----------------- void tdiff_calibrate_tgraph(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); vector tdiffs[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>10)continue; // bulletproof if(hit.tup_corrected<-100)continue; if(hit.tdn_corrected<-100)continue; float tdiff = hit.tup_corrected - hit.tdn_corrected; float geomn = hit.geometric_mean; if(fabs(tdiff)>15.0)continue; tdiffs[hit.layer].push_back(tdiff); geomns[hit.layer].push_back(geomn); } TCanvas *c1 = new TCanvas("c1"); c1->SetTicks(); c1->SetGrid(); 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_tgraph.ps["); // Loop over layers int Nlayers=0; for(int ilayer=1; ilayer<=10 ; ilayer++, Nlayers++){ // Find appropriate minimum/maximum for x-axis float *v = &geomns[ilayer][0]; TH1D *htmp = new TH1D("htmp", "", 350, 0.0, 3500.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); } TH2D *axes = new TH2D("axes","", 100, xmin, xmax, 100, -2.0, 2.0); axes->SetStats(0); axes->SetXTitle("fADC"); axes->SetYTitle("t (ns)"); TGraph *g = new TGraph(tdiffs[ilayer].size(), &geomns[ilayer][0], &tdiffs[ilayer][0]); char title[256]; sprintf(title, "#Deltat 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); g->Fit("fun","","",30.0, 3500.0); axes->Draw(); g->Draw("Psame"); for(int ipar=0; ipar<=6; ipar++)parms[ilayer][ipar] = fun->GetParameter(ipar); cout<<"Number of points:"<GetN()<Update(); c1->Print("tdiff_tgraph.ps"); char fname[256]; sprintf(fname, "tdiff_tgraph_layer%02d.png", ilayer); c1->SaveAs(fname); } // Close PDF file c1->Print("tdiff_tgraph.ps]"); // Write parameters out in form of C++ file const char *cppfname = "tdiff_tgraph.cc"; ofstream pout(cppfname); pout<"<NLAYERS_BCAL ? NLAYERS_BCAL:layer;"<