Rev 40 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 40 | Rev 47 | ||
---|---|---|---|
1 | #include "TROOT.h" |
1 | #include "TROOT.h" |
2 | #include "TFile.h" |
2 | #include "TFile.h" |
3 | #include "TBenchmark.h" |
3 | #include "TBenchmark.h" |
4 | #include "TH1F.h" |
4 | #include "TH1F.h" |
5 | #include "TH2F.h" |
5 | #include "TH2F.h" |
6 | #include "TH3F.h" |
6 | #include "TH3F.h" |
7 | #include "TCanvas.h" |
7 | #include "TCanvas.h" |
8 | #include "TStyle.h" |
8 | #include "TStyle.h" |
9 | #include "TPad.h" |
9 | #include "TPad.h" |
10 | #include "TF1.h" |
10 | #include "TF1.h" |
11 | #include "TGraph.h" |
11 | #include "TGraph.h" |
12 | #include "TSpectrum.h" |
12 | #include "TSpectrum.h" |
13 | #include "stdio.h" |
13 | #include "stdio.h" |
14 | 14 | ||
15 | //#include "include/RTUtil.h" |
15 | //#include "include/RTUtil.h" |
16 | 16 | ||
17 | int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=-16, double rangeRight=16, bool debug = false) |
17 | int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=-16, double rangeRight=16, bool debug = false) |
18 | { |
18 | { |
19 | //const int c_nChannels = 64; |
19 | //const int c_nChannels = 64; |
20 | //const double c_xOffset = 2.2; // mm |
20 | //const double c_xOffset = 2.2; // mm |
21 | //const double c_yOffset = 2.3; |
21 | //const double c_yOffset = 2.3; |
22 | 22 | ||
23 | int map[8][8]={{32,34,53,55,40,42,61,63}, |
23 | int map[8][8]={{32,34,53,55,40,42,61,63}, |
24 | {48,50,37,39,56,58,45,47}, |
24 | {48,50,37,39,56,58,45,47}, |
25 | {33,35,52,54,41,43,60,62}, |
25 | {33,35,52,54,41,43,60,62}, |
26 | {49,51,36,38,57,59,44,46}, |
26 | {49,51,36,38,57,59,44,46}, |
27 | {17,19,4,6,25,27,12,14}, |
27 | {17,19,4,6,25,27,12,14}, |
28 | {1,3,20,22,9,11,28,30}, |
28 | {1,3,20,22,9,11,28,30}, |
29 | {16,18,5,7,24,26,13,15}, |
29 | {16,18,5,7,24,26,13,15}, |
30 | {0,2,21,23,8,10,29,31} |
30 | {0,2,21,23,8,10,29,31} |
31 | }; |
31 | }; |
32 | 32 | ||
33 | char fnameroot[256]; |
33 | char fnameroot[256]; |
34 | TFile* rootfile; |
34 | TFile* rootfile; |
35 | sprintf(fnameroot, "root/%s.root", filename); |
35 | sprintf(fnameroot, "root/%s.root", filename); |
36 | rootfile = (TFile *) gROOT->FindObject(filename); |
36 | rootfile = (TFile *) gROOT->FindObject(filename); |
37 | if(rootfile==NULL) rootfile = new TFile(fnameroot); |
37 | if(rootfile==NULL) rootfile = new TFile(fnameroot); |
38 | if(rootfile==NULL) { |
38 | if(rootfile==NULL) { |
39 | printf("Cannot open root file %s!!!\n",fnameroot); |
39 | printf("Cannot open root file %s!!!\n",fnameroot); |
40 | return(0); |
40 | return(0); |
41 | } |
41 | } |
42 | 42 | ||
43 | // set draw style |
43 | // set draw style |
44 | gStyle->SetPalette(1, 0); |
44 | gStyle->SetPalette(1, 0); |
45 | 45 | ||
46 | gStyle->SetPaperSize(TStyle::kA4); |
46 | gStyle->SetPaperSize(TStyle::kA4); |
47 | gStyle->SetStatBorderSize(1); |
47 | gStyle->SetStatBorderSize(1); |
48 | gStyle->SetFrameBorderMode(0); |
48 | gStyle->SetFrameBorderMode(0); |
49 | gStyle->SetFrameFillColor(0); |
49 | gStyle->SetFrameFillColor(0); |
50 | gStyle->SetCanvasBorderMode(0); |
50 | gStyle->SetCanvasBorderMode(0); |
51 | gStyle->SetPadBorderMode(0); |
51 | gStyle->SetPadBorderMode(0); |
52 | gStyle->SetPadColor(0); |
52 | gStyle->SetPadColor(0); |
53 | gStyle->SetCanvasColor(0); |
53 | gStyle->SetCanvasColor(0); |
54 | gStyle->SetStatColor(0); |
54 | gStyle->SetStatColor(0); |
55 | gStyle->SetOptFit(11); |
55 | gStyle->SetOptFit(11); |
56 | gStyle->SetOptStat("ne"); |
56 | gStyle->SetOptStat("ne"); |
57 | gStyle->SetPadTopMargin(0.15); |
57 | gStyle->SetPadTopMargin(0.15); |
58 | gStyle->SetPadBottomMargin(0.15); |
58 | gStyle->SetPadBottomMargin(0.15); |
59 | gStyle->SetPadRightMargin(0.15); |
59 | gStyle->SetPadRightMargin(0.15); |
60 | gStyle->SetPadLeftMargin(0.15); |
60 | gStyle->SetPadLeftMargin(0.15); |
61 | //gStyle->SetTitleYOffset(1.4); |
61 | //gStyle->SetTitleYOffset(1.4); |
62 | 62 | ||
63 | TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000); |
63 | TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000); |
64 | TH2F* htdc = (TH2F*) rootfile->Get("htdc"); |
64 | TH2F* htdc = (TH2F*) rootfile->Get("htdc"); |
65 | canvas1->cd(); |
65 | canvas1->cd(); |
66 | htdc->Draw("colz"); |
66 | htdc->Draw("colz"); |
67 | 67 | ||
68 | TH3F |
68 | //TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC"); |
- | 69 | TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC"); |
|
69 | TCanvas* canvas2 = new TCanvas("canvas2","canvas2",800,800); |
70 | TCanvas* canvas2 = new TCanvas("canvas2","canvas2",800,800); |
70 | canvas2->cd(); |
71 | canvas2->cd(); |
71 |
|
72 | h_correctedTDC->Draw("colz"); |
72 | 73 | ||
- | 74 | /* |
|
73 | TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz"); |
75 | TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz"); |
74 | h_correctedTDC->SetTitle("; t [ns]; Channel"); |
76 | h_correctedTDC->SetTitle("; t [ns]; Channel"); |
75 | h_correctedTDC->Draw("colz"); |
77 | h_correctedTDC->Draw("colz"); |
76 | TCanvas* canvas3 = new TCanvas("canvas3","canvas3",800,800); |
78 | TCanvas* canvas3 = new TCanvas("canvas3","canvas3",800,800); |
77 | canvas2->cd(2); |
79 | canvas2->cd(2); |
78 | TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64); |
80 | TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64); |
79 | h_allTDCbins->Draw(); |
81 | h_allTDCbins->Draw(); |
- | 82 | */ |
|
80 | /* |
83 | /* |
81 | int binY = map[chX][chY]; |
84 | int binY = map[chX][chY]; |
82 | TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1); |
85 | TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1); |
83 | channelY->SetStats(0); |
86 | channelY->SetStats(0); |
84 | |
87 | |
85 | char title[256]; |
88 | char title[256]; |
86 | sprintf(title,"Channel %d;t [ns];Events", binY); |
89 | sprintf(title,"Channel %d;t [ns];Events", binY); |
87 | channelY->SetTitle(title); |
90 | channelY->SetTitle(title); |
88 | channelY->GetYaxis()->SetTitleOffset(1.7); |
91 | channelY->GetYaxis()->SetTitleOffset(1.7); |
89 | TAxis* xAxis = h_correctedTDC->GetXaxis(); |
92 | TAxis* xAxis = h_correctedTDC->GetXaxis(); |
90 | int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1); |
93 | int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1); |
91 | channelY->GetXaxis()->SetRangeUser(-range, range); |
94 | channelY->GetXaxis()->SetRangeUser(-range, range); |
92 | channelY->Draw(); |
95 | channelY->Draw(); |
93 | 96 | ||
94 | TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight); |
97 | TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight); |
95 | TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8); |
98 | TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8); |
96 | f_gaus1->SetParNames("Linear","Norm","#mu","#sigma"); |
99 | f_gaus1->SetParNames("Linear","Norm","#mu","#sigma"); |
97 | f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2"); |
100 | f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2"); |
98 | Int_t n = channelY->GetMaximum(); |
101 | Int_t n = channelY->GetMaximum(); |
99 | Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin()); |
102 | Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin()); |
100 | |
103 | |
101 | f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0); |
104 | f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0); |
102 | channelY->Fit(f_gaus1,"0"); |
105 | channelY->Fit(f_gaus1,"0"); |
103 | channelY->Fit(f_gaus1,"r"); |
106 | channelY->Fit(f_gaus1,"r"); |
104 | */ |
107 | */ |
105 | //Fit in range +- 3 sigma |
108 | //Fit in range +- 3 sigma |
106 | //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3), |
109 | //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3), |
107 | // f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3)); |
110 | // f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3)); |
108 | 111 | ||
109 | 112 | ||
110 | //f_gaus2->SetParameters(-1, n, mean-0.1, 0.01, |
113 | //f_gaus2->SetParameters(-1, n, mean-0.1, 0.01, |
111 | // n, mean+0.1, 0.1); |
114 | // n, mean+0.1, 0.1); |
112 | //channelY->Fit(f_gaus2,"0"); |
115 | //channelY->Fit(f_gaus2,"0"); |
113 | //channelY->Fit(f_gaus2,"rl"); |
116 | //channelY->Fit(f_gaus2,"rl"); |
114 | // set range to +- 3 sigma |
117 | // set range to +- 3 sigma |
115 | //channelY->Fit(f_gaus,"lr","",f_gaus->GetParameter(2)-3*f_gaus->GetParameter(3), |
118 | //channelY->Fit(f_gaus,"lr","",f_gaus->GetParameter(2)-3*f_gaus->GetParameter(3), |
116 | // f_gaus->GetParameter(2)+3*f_gaus->GetParameter(3)); |
119 | // f_gaus->GetParameter(2)+3*f_gaus->GetParameter(3)); |
117 | 120 | ||
118 | return (0); |
121 | return (0); |
119 | } |
122 | } |
120 | 123 |