Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
30 | f9daq | 1 | #include "TROOT.h" |
2 | #include "TFile.h" |
||
3 | #include "TBenchmark.h" |
||
4 | #include "TH1F.h" |
||
5 | #include "TH2F.h" |
||
6 | #include "TCanvas.h" |
||
7 | #include "TStyle.h" |
||
8 | #include "TPad.h" |
||
9 | #include "TF1.h" |
||
10 | #include "TGraph.h" |
||
11 | #include "TSpectrum.h" |
||
12 | |||
13 | #include "RTUtil.h" |
||
14 | |||
15 | #define TDC_BIN (25./1000.) //1 TDC bin in ns |
||
16 | #define MIKRO_BIN 0.49609/1000. //1 mikro step in mm |
||
17 | |||
18 | #define HFILL_COLOR 18 |
||
19 | |||
20 | void mppc(char *fname, char *plopt="t", int nChannels = 1, double fitw=1.0, char *fitf="g") |
||
21 | { |
||
22 | char fullname[256]; |
||
23 | |||
24 | //get ROOT file with histograms |
||
25 | char fnameroot[1024]; |
||
26 | TFile * rootfile; |
||
27 | TDirectory *dir; |
||
28 | |||
29 | sprintf(fnameroot, "root/%s.root", fname); |
||
30 | rootfile = (TFile *) gROOT->FindObject(fname); |
||
31 | if(rootfile==NULL) rootfile = new TFile(fnameroot); |
||
32 | if(rootfile==NULL) { |
||
33 | printf("Cannot open root file %s!!!\n",fnameroot); |
||
34 | return; |
||
35 | } |
||
36 | dir = (TDirectory*) rootfile; |
||
37 | |||
38 | |||
39 | // set draw style |
||
40 | gStyle->SetOptStat("ne"); |
||
41 | gStyle->SetPalette(1, 0); |
||
42 | |||
43 | gStyle->SetPaperSize(TStyle::kA4); |
||
44 | gStyle->SetStatBorderSize(1); |
||
45 | gStyle->SetFrameBorderMode(0); |
||
46 | gStyle->SetFrameFillColor(0); |
||
47 | gStyle->SetCanvasBorderMode(0); |
||
48 | gStyle->SetPadBorderMode(0); |
||
49 | gStyle->SetPadColor(0); |
||
50 | gStyle->SetCanvasColor(0); |
||
51 | gStyle->SetStatColor(0); |
||
52 | gStyle->SetOptFit(11); |
||
53 | gStyle->SetOptStat(); |
||
54 | gStyle->SetPadRightMargin(0.15); |
||
55 | gStyle->SetPadLeftMargin(0.12); |
||
56 | //gStyle->SetTitleYOffset(1.4); |
||
57 | |||
58 | TCanvas *c[16]; |
||
59 | int cc=-1; |
||
60 | char hname[256]; |
||
61 | TH1F *hp1d; TH2F *hp2d; |
||
62 | |||
63 | |||
64 | // 2d Scan -------------------------------------------------------------------------------------------- |
||
65 | |||
66 | if( strchr(plopt, '2') != NULL ) { |
||
67 | c[++cc] = new TCanvas("2D Scan", fname, 650, 400, 600, 600); |
||
68 | |||
69 | int i=0; |
||
70 | gPad->SetLogz(); |
||
71 | sprintf(hname, "h2d%d",i); hp2d = (TH2F *) dir->Get(hname); |
||
72 | |||
73 | (hp2d->GetYaxis())->SetLabelOffset(0.01); |
||
74 | hp2d->SetTitle("; X [mm]; Y[mm]"); |
||
75 | hp2d->DrawCopy("COLZ"); |
||
76 | |||
77 | sprintf(fullname, "ps/%s_2d.eps", fname); |
||
78 | c[cc]->SaveAs(fullname); |
||
79 | } |
||
80 | |||
81 | // 1d Scan Y ------------------------------------------------------------------------------------------ |
||
82 | |||
83 | if( strchr(plopt, 'y') != NULL ) { |
||
84 | c[++cc] = new TCanvas("Y Scan", fname, 250, 200, 600, 600); |
||
85 | |||
86 | int i=0; |
||
87 | //gPad->SetLogy(); |
||
88 | sprintf(hname, "hnhitsy%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
89 | |||
90 | hp1d->SetTitle("Y Scan; Y; Count"); |
||
91 | hp1d->DrawCopy(); |
||
92 | |||
93 | sprintf(fullname, "ps/%s_y.eps", fname); |
||
94 | c[cc]->SaveAs(fullname); |
||
95 | } |
||
96 | |||
97 | // 1d Scan X ------------------------------------------------------------------------------------------ |
||
98 | |||
99 | if( strchr(plopt, 'x') != NULL ) { |
||
100 | c[++cc] = new TCanvas("X Scan", fname, 250, 200, 600, 600); |
||
101 | |||
102 | int i=0; |
||
103 | //gPad->SetLogy(); |
||
104 | sprintf(hname, "hnhitsx%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
105 | |||
106 | hp1d->SetTitle("X Scan; X; Count"); |
||
107 | hp1d->DrawCopy(); |
||
108 | |||
109 | sprintf(fullname, "ps/%s_x.eps", fname); |
||
110 | c[cc]->SaveAs(fullname); |
||
111 | } |
||
112 | |||
113 | // Fits of corrected TDCs ----------------------------------------------------------------------------- |
||
114 | |||
115 | TF1 *fg = new TF1("fg", "gaus"); |
||
116 | TF1 *fgg = new TF1("fgg", "gaus(0)+gaus(3)"); |
||
117 | fgg->SetParNames("Constant","Mean","Sigma","Constant2","Mean2","Sigma2"); |
||
118 | if( strchr(plopt, 'f') != NULL ) { |
||
119 | c[++cc] = new TCanvas("Corrected TDCs", fname, 50*(cc+1), 0, 600, 850); |
||
120 | //c[cc]->Divide(2,4); |
||
121 | c[cc]->Divide(nChannels); |
||
122 | |||
123 | for(int i=0;i<nChannels;i++) { |
||
124 | c[cc]->cd(i+1); gPad->SetLogy(); |
||
125 | sprintf(hname, "hctdc%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
126 | hp1d->SetTitle("cTDC; TDC [ns]; N"); |
||
127 | (hp1d->GetXaxis())->SetRangeUser(-40*TDC_BIN,160*TDC_BIN); |
||
128 | if( hp1d->GetMaximum() < 50 ) continue; |
||
129 | //(hp1d->GetXaxis())->SetRangeUser(-0.25,0.75); |
||
130 | |||
131 | if( strcmp(fitf, "g")==0 ) { |
||
132 | fg->SetParameters(hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin()), 0.05); |
||
133 | hp1d->Fit(fg, "0ql", "", fg->GetParameter(1)-0.1*fitw, fg->GetParameter(1)+0.05*fitw); |
||
134 | hp1d->Fit(fg, "ql", "", fg->GetParameter(1)-0.1*fitw, fg->GetParameter(1)+0.05*fitw); |
||
135 | |||
136 | printf("Ch[%d] Sigma =%6.1lfps\n",i,fg->GetParameter(2)*1000.); |
||
137 | } |
||
138 | else if( strcmp(fitf, "gg")==0 ) { |
||
139 | //fgg->SetParameters(2600.,0*TDC_BIN,2*TDC_BIN, 100.,0*TDC_BIN,10*TDC_BIN); |
||
140 | fgg->SetParameters(hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin()), 0.03, |
||
141 | hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin())/10., 0.1); |
||
142 | hp1d->Fit(fgg, "0ql", "", -50*TDC_BIN, 50*TDC_BIN); |
||
143 | hp1d->Fit(fgg, "ql", "", fgg->GetParameter(1)-2.5*fitw*fgg->GetParameter(2), |
||
144 | fgg->GetParameter(1)+3.5*fitw*fgg->GetParameter(2)); |
||
145 | |||
146 | printf("Ch[%d] Sigma =%6.1lfps\n",i,fgg->GetParameter(2)*1000.); |
||
147 | /* |
||
148 | fg->SetRange(-50., 200.); |
||
149 | fg->SetParameters(fgg->GetParameter(0), fgg->GetParameter(1), fgg->GetParameter(2)); |
||
150 | fg->SetLineColor(2); |
||
151 | fg->DrawCopy("LSAME"); |
||
152 | fg->SetParameters(fgg->GetParameter(3), fgg->GetParameter(4), fgg->GetParameter(5)); |
||
153 | fg->SetLineColor(3); |
||
154 | fg->DrawCopy("LSAME"); |
||
155 | */ |
||
156 | } else {printf("Wrong fit function (parameter 4)!!!\n"); return;} |
||
157 | } |
||
158 | sprintf(fullname, "ps/%s_cTDC.eps", fname); |
||
159 | c[cc]->SaveAs(fullname); |
||
160 | } |
||
161 | |||
162 | // TDCs ----------------------------------------------------------------------------------------------- |
||
163 | |||
164 | if( strchr(plopt, 't') != NULL ) { |
||
165 | c[++cc] = new TCanvas("Raw TDC", fname, 0, 500, 600, 430); |
||
166 | |||
167 | int i=0; |
||
168 | gPad->SetLogy(); |
||
169 | sprintf(hname, "htdc%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
170 | hp1d->SetTitle("TDC; TDC [ns]; N"); |
||
171 | (hp1d->GetXaxis())->SetRangeUser(-10,20); |
||
172 | hp1d->DrawCopy(); |
||
173 | //if( hp1d->GetMaximum() < 10 ) continue; |
||
174 | |||
175 | fg->SetParameters(hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin()), 0.25); |
||
176 | fg->SetLineColor(kRed); |
||
177 | hp1d->Fit(fg,"0QL", "", fg->GetParameter(1)-0.5, fg->GetParameter(1)+0.5); |
||
178 | hp1d->Fit(fg,"QL", "", fg->GetParameter(1)-0.8, fg->GetParameter(1)+0.8); |
||
179 | |||
180 | printf("Ch[%d] RAW Sigma =%6.1lfps\n",i,fg->GetParameter(2)*1000.); |
||
181 | |||
182 | sprintf(fullname, "ps/%s_TDC.eps", fname); |
||
183 | c[cc]->SaveAs(fullname); |
||
184 | } |
||
185 | |||
186 | |||
187 | //rootfile->Close(); |
||
188 | } |