| 1,6 → 1,7 |
| #include "TROOT.h" |
| #include "TFile.h" |
| #include "TBenchmark.h" |
| #include "TH1.h" |
| #include "TH1F.h" |
| #include "TH2F.h" |
| #include "TH3F.h" |
| 10,15 → 11,15 |
| #include "TF1.h" |
| #include "TGraph.h" |
| #include "TSpectrum.h" |
| #include "TAttFill.h" |
| #include "stdio.h" |
| |
| #include "include/RTUtil.h" |
| |
| //#include "include/RTUtil.h" |
| |
| int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=-16, double rangeRight=16, bool debug = false) |
| int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=87, double rangeRight=107, bool debug = false) |
| { |
| //const int c_nChannels = 64; |
| //const double c_xOffset = 2.2; // mm |
| //const double c_yOffset = 2.3; |
| |
| int map[8][8]={{32,34,53,55,40,42,61,63}, |
| {48,50,37,39,56,58,45,47}, |
| 41,6 → 42,7 |
| } |
| |
| // set draw style |
| /* |
| gStyle->SetPalette(1, 0); |
| |
| gStyle->SetPaperSize(TStyle::kA4); |
| 52,71 → 54,112 |
| gStyle->SetPadColor(0); |
| gStyle->SetCanvasColor(0); |
| gStyle->SetStatColor(0); |
| gStyle->SetOptFit(11); |
| gStyle->SetOptFit(1111); |
| gStyle->SetOptStat("ne"); |
| gStyle->SetPadTopMargin(0.15); |
| gStyle->SetPadBottomMargin(0.15); |
| gStyle->SetPadRightMargin(0.15); |
| gStyle->SetPadLeftMargin(0.15); |
| //gStyle->SetTitleYOffset(1.4); |
| //gStyle->SetTitleYOffset(1.4);*/ |
| RTSetStyle(gStyle); |
| |
| TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000); |
| TH2F* htdc = (TH2F*) rootfile->Get("htdc"); |
| TH2F* h_tdc = (TH2F*) rootfile->Get("htdc"); |
| canvas1->cd(); |
| htdc->Draw("colz"); |
| h_tdc->Draw("colz"); |
| |
| //TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC"); |
| TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC"); |
| TCanvas* canvas2 = new TCanvas("canvas2","canvas2",800,800); |
| TCanvas* canvas2 = new TCanvas("canvas2","canvas2",1000,1000); |
| canvas2->cd(); |
| h_correctedTDC->Draw("colz"); |
| |
| /* |
| TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz"); |
| h_correctedTDC->SetTitle("; t [ns]; Channel"); |
| h_correctedTDC->Draw("colz"); |
| TCanvas* canvas3 = new TCanvas("canvas3","canvas3",800,800); |
| canvas2->cd(2); |
| TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64); |
| h_allTDCbins->Draw(); |
| */ |
| /* |
| |
| //TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz"); |
| //h_correctedTDC->SetTitle("; t [ns]; Channel"); |
| //h_correctedTDC->Draw("colz"); |
| TCanvas* canvas3 = new TCanvas("canvas3","canvas3",1600,1600); |
| canvas3->cd(); |
| //TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64); |
| //h_allTDCbins->Draw(); |
| |
| |
| int binY = map[chX][chY]; |
| TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1); |
| channelY->SetStats(0); |
| if (debug) printf("%d\n", binY); |
| //TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1); |
| TH1D* channelY = h_tdc->ProjectionX("",binY+1,binY+1); |
| channelY->SetStats(1); |
| |
| char title[256]; |
| sprintf(title,"Channel %d;t [ns];Events", binY); |
| sprintf(title,";Time [ns];Events"); |
| channelY->SetTitle(title); |
| channelY->GetYaxis()->SetTitleOffset(1.7); |
| TAxis* xAxis = h_correctedTDC->GetXaxis(); |
| int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1); |
| channelY->GetXaxis()->SetRangeUser(-range, range); |
| //channelY->GetYaxis()->SetTitleOffset(1.7); |
| //TAxis* xAxis = h_correctedTDC->GetXaxis(); |
| //int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1); |
| //channelY->GetXaxis()->SetRangeUser(-range, range); |
| //gStyle->SetOptStat("nemr"); |
| //gStyle->SetOptFit(111); |
| channelY->GetXaxis()->SetRangeUser(rangeLeft,rangeRight); |
| channelY->Draw(); |
| |
| TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight); |
| TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8); |
| f_gaus1->SetParNames("Linear","Norm","#mu","#sigma"); |
| f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2"); |
| Int_t n = channelY->GetMaximum(); |
| Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin()); |
| |
| f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0); |
| channelY->Fit(f_gaus1,"0"); |
| channelY->Fit(f_gaus1,"r"); |
| */ |
| // Fit function: linear for background c + k*x |
| // Signal: norm*gaussian(mu,sigma) |
| TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)", rangeLeft, rangeRight); |
| //TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)"); |
| f_gaus1->SetParNames("Const","Linear","Norm","#mu","#sigma"); |
| //f_gaus1->SetLineColor(kAzure+1); |
| f_gaus1->SetLineColor(kBlack); |
| f_gaus1->SetLineWidth(4); |
| |
| f_gaus1->SetParameter(0, channelY->GetMinimum()); |
| f_gaus1->SetParameter(1, 0.0); |
| f_gaus1->SetParameter(2, channelY->GetMaximum() - channelY->GetMinimum()); |
| f_gaus1->SetParameter(3, channelY->GetBinCenter(channelY->GetMaximumBin())); |
| f_gaus1->SetParameter(4, 1.0); |
| //channelY->Fit(f_gaus1,"qr"); |
| //channelY->Fit(f_gaus1,"r"); |
| |
| //Fit in range +- 3 sigma |
| //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3), |
| // f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3)); |
| //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(3)-3*f_gaus1->GetParameter(4), |
| channelY->Fit(f_gaus1,"",""); |
| //f_gaus1->GetParameter(3)+3*f_gaus1->GetParameter(4)); |
| |
| double N = channelY->GetEntries(); |
| double Nbkg = (rangeRight - rangeLeft)*f_gaus1->GetParameter(0); |
| double Nsig = N - Nbkg; |
| printf("\nN = %f, Nsig = %f, Nbkg = %f, SN = %f***\n\n", N, Nsig, Nbkg, Nsig/Nbkg); |
| /* |
| //to draw a shaded area above and below an histogram range, we create |
| //a TGraph object (here we shade bins 60 to 80). |
| Int_t i; |
| Int_t n = 2*(80-60); |
| TGraph *gr = new TGraph(2*n); |
| for (i=0;i<20;i++) { |
| Float_t xlow = h1->GetBinLowEdge(60+i); |
| Float_t xup = h1->GetBinLowEdge(60+i+1); |
| Float_t y = h1->GetBinContent(60+i); |
| Float_t yup = 1.1*y; |
| Float_t ydown= 0.9*y; |
| gr->SetPoint(2*i, xlow,yup); |
| gr->SetPoint(2*i+1,xup, yup); |
| gr->SetPoint(2*n-2*i-1,xlow, ydown); |
| gr->SetPoint(2*n-2*i-2,xup, ydown); |
| } |
| gr->SetFillColor(2); |
| gr->Draw("lf");*/ |
| |
| TH1D* timeWindow = (TH1D*) channelY->Clone(); |
| timeWindow->GetXaxis()->SetRangeUser(92,102); |
| //timeWindow->SetFillColor(kAzure-1); |
| timeWindow->SetFillColor(kBlack); |
| timeWindow->SetFillStyle(3004); |
| timeWindow->Draw("same"); |
| |
| |
| //f_gaus2->SetParameters(-1, n, mean-0.1, 0.01, |
| // n, mean+0.1, 0.1); |
| //channelY->Fit(f_gaus2,"0"); |
| //channelY->Fit(f_gaus2,"rl"); |
| // set range to +- 3 sigma |
| //channelY->Fit(f_gaus,"lr","",f_gaus->GetParameter(2)-3*f_gaus->GetParameter(3), |
| // f_gaus->GetParameter(2)+3*f_gaus->GetParameter(3)); |
| |
| |
| char drawing[128]; |
| sprintf(drawing, "ps/%sTDC.pdf", filename); |
| canvas3->SaveAs(drawing); |
| |
| gPad->Update(); |
| return (0); |
| } |