// apply all timing offsets to TDC time and overall timing correction for ADC time // then calculate time difference between adc and tdc time and deterine offsets // T_tdc - T_adc = offset_t_adc // the sign of the parameters will be flipped to be in accordance with the analysis code #include "TTree.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include "TF1.h" #include "TROOT.h" #include "TStyle.h" #include "TGraphErrors.h" #include "TMath.h" #include "TCanvas.h" #include #include #include #include using namespace std; int DEBUG = 0; TH2F *TDiff; int FIRST = 0; void saverootfile(int R){ char fnam[128]; sprintf(fnam,"calibration%d/adc_time_offsets_run%d.root",R,R); TFile *RF = new TFile(fnam,"RECREATE"); RF->cd(); TDiff->Write(); RF->Close(); } void doadctimeoffsets(int RunNumber){ float LOLIM = -10.; float HILIM = 10.; if (!FIRST){ TDiff = new TH2F("TDiff","TDC_T - ADC_T",176, 0,176, 200, LOLIM, HILIM); } else { TDiff->Reset(); } FIRST++; char fnam[128]; char ROOTFILE[128]; if (RunNumber == 99999){ sprintf(ROOTFILE,"localdir/big%d.root",RunNumber); } else { sprintf(ROOTFILE,"localdir/tofdata_run%d.root",RunNumber); } // get TDC timing offsets sprintf(fnam,"calibration%d/tofpmt_tdc_offsets_all_FULL_run%d.DB",RunNumber,RunNumber); cout<<"offsetfile: "<>PMTOffsets[k]; //cout< %s", RunNumber, fnam); system(cmd); INF.open(fnam); char dummy[128]; INF.getline(dummy,120); float ADC_T_OFFSET, TDC_T_OFFSET; INF>>ADC_T_OFFSET>>TDC_T_OFFSET; INF.close(); // get walk correction parameters double WalkPar[176][3]; double dum; sprintf(fnam,"calibration%d/tof_walk_parameters_run%d.DB",RunNumber,RunNumber); INF.open(fnam); for (int k=0;k<176;k++){ INF>>dum>>WalkPar[k][0]>>WalkPar[k][1]>>WalkPar[k][2]; } INF.close(); TFile *f = new TFile(ROOTFILE,"READ"); //f->ls(); TTree *t3 = (TTree*)f->Get("TOFcalib/t3"); int Event; int Nhits; float TShift; int Plane[100]; int Paddle[100]; float MeanTime[100]; float TimeDiff[100]; int NhitsA; int PlaneA[100]; int PaddleA[100]; float MeanTimeA[100]; float TimeDiffA[100]; float ADCL[100]; float ADCR[100]; int OFL[100]; int OFR[100]; int NsinglesA; int PlaneSA[100]; int PaddleSA[100]; int LRA[100]; float ADCS[100]; float TADCS[100]; int OF[100]; int NsinglesT; int PlaneST[100]; int PaddleST[100]; int LRT[100]; float TDCST[100]; t3->SetBranchAddress("Event",&Event); t3->SetBranchAddress("Nhits",&Nhits); t3->SetBranchAddress("TShift",&TShift); t3->SetBranchAddress("Plane",Plane); t3->SetBranchAddress("Paddle",Paddle); t3->SetBranchAddress("MeanTime",MeanTime); t3->SetBranchAddress("TimeDiff",TimeDiff); t3->SetBranchAddress("NhitsA",&NhitsA); t3->SetBranchAddress("PlaneA",PlaneA); t3->SetBranchAddress("PaddleA",PaddleA); t3->SetBranchAddress("MeanTimeA",MeanTimeA); t3->SetBranchAddress("TimeDiffA",TimeDiffA); t3->SetBranchAddress("ADCL",ADCL); t3->SetBranchAddress("ADCR",ADCR); t3->SetBranchAddress("OFL",OFL); t3->SetBranchAddress("OFR",OFR); t3->SetBranchAddress("NsinglesA",&NsinglesA); t3->SetBranchAddress("PlaneSA",PlaneSA); t3->SetBranchAddress("PaddleSA",PaddleSA); t3->SetBranchAddress("LRA",LRA); t3->SetBranchAddress("ADCS",ADCS); t3->SetBranchAddress("TADCS",TADCS); t3->SetBranchAddress("OF",OF); t3->SetBranchAddress("NsinglesT",&NsinglesT); t3->SetBranchAddress("PlaneST",PlaneST); t3->SetBranchAddress("PaddleST",PaddleST); t3->SetBranchAddress("LRT",LRT); t3->SetBranchAddress("TDCST",TDCST); unsigned int nentries = (unsigned int) t3->GetEntries(); cout<<"Start reading root file with "<GetEntry(kk); //cout<Fill(hid1, tL - tLADC + THESHIFT); TDiff->Fill(hid2, tR - tRADC + THESHIFT); } } } for (int i=0; iFill(idx, T - tADC + THESHIFT); } } } } if (DEBUG){ TDiff->Draw("colz"); gPad->Update(); getchar(); } float ADC_T_offsets[176]; for (int k=0;k<176;k++) { ADC_T_offsets[k] = 0.; //cout<<"bin "<ProjectionY("h",k+1,k+1); if (h->GetEntries()>100){ double pos = 0; double sig = 0; int maxbin = h->GetMaximumBin(); float maxloc = h->GetBinCenter(maxbin); float lowlim = maxloc - 1.; float higlim = maxloc + 1.; if (lowlim < LOLIM){ lowlim = LOLIM; } if (higlim > HILIM) { higlim = HILIM; } h->Fit("gaus","Q","R", lowlim, higlim); TF1 *func = h->GetFunction("gaus"); pos = func->GetParameter(1); sig = func->GetParameter(2); lowlim = pos - 2.*sig; higlim = pos + 2.*sig; if (lowlim < LOLIM){ lowlim = LOLIM; } if (higlim > HILIM) { higlim = HILIM; } h->Fit("gaus","Q","R", lowlim, higlim); func = h->GetFunction("gaus"); pos = func->GetParameter(1); sig = func->GetParameter(2); ADC_T_offsets[k] = -pos; //change sign if (DEBUG){ h->Draw(); gPad->Update(); getchar(); } } } sprintf(fnam,"calibration%d/tdc_adc_time_offsets_run%d.DB",RunNumber,RunNumber); ofstream OUTF; OUTF.open(fnam); for (int k=0;k<176;k++) { OUTF << ADC_T_offsets[k]<cd(); TDiff->Write(); RootF->Close(); }