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 NCH 1 |
||
16 | #define TDC_BIN (25./1000.) //1 TDC bin in ns |
||
17 | #define MIKRO_BIN 0.3595/1000. //1 mikro step in mm |
||
18 | |||
19 | #define HFILL_COLOR 18 |
||
20 | |||
21 | void plots(char *fname, char *plopt="atc", double fitw=1.0, char *fitf="g") |
||
22 | { |
||
23 | char fullname[256]; |
||
24 | |||
25 | //get ROOT file with histograms |
||
26 | char fnameroot[1024]; |
||
27 | TFile * rootfile; |
||
28 | TDirectory *dir; |
||
29 | |||
30 | sprintf(fnameroot, "root/%s.root", fname); |
||
31 | rootfile = (TFile *) gROOT->FindObject(fname); |
||
32 | if(rootfile==NULL) rootfile = new TFile(fnameroot); |
||
33 | if(rootfile==NULL) { |
||
34 | printf("Cannot open root file %s!!!\n",fnameroot); |
||
35 | return; |
||
36 | } |
||
37 | dir = (TDirectory*) rootfile; |
||
38 | |||
39 | |||
40 | // set draw style |
||
41 | gStyle->SetOptStat("ne"); |
||
42 | gStyle->SetPalette(1, 0); |
||
43 | |||
44 | gStyle->SetPaperSize(TStyle::kA4); |
||
45 | gStyle->SetStatBorderSize(1); |
||
46 | gStyle->SetFrameBorderMode(0); |
||
47 | gStyle->SetFrameFillColor(0); |
||
48 | gStyle->SetCanvasBorderMode(0); |
||
49 | gStyle->SetPadBorderMode(0); |
||
50 | gStyle->SetPadColor(0); |
||
51 | gStyle->SetCanvasColor(0); |
||
52 | gStyle->SetStatColor(0); |
||
53 | gStyle->SetOptFit(11); |
||
54 | gStyle->SetPadRightMargin(0.1); |
||
55 | |||
56 | RTCanvas *c[16]; |
||
57 | int cc=-1; |
||
58 | char hname[256]; |
||
59 | TH1F *hp1d; TH2F *hp2d; |
||
60 | |||
61 | // ADCs ----------------------------------------------------------------------------------------------- |
||
62 | |||
63 | if( strchr(plopt, 'a') != NULL ) { |
||
64 | c[++cc] = new RTCanvas("QDC", fname, 50*(cc+1), 0, 600, 850); |
||
65 | //c[cc]->Divide(2,4); |
||
66 | c[cc]->Divide(NCH); |
||
67 | |||
68 | for(int i=0;i<NCH;i++) { |
||
69 | c[cc]->cd(i+1); gPad->SetLogy(); |
||
70 | sprintf(hname, "hadcpos%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
71 | |||
72 | hp1d->SetTitle("QDC; QDC; N"); |
||
73 | //(hp1d->GetXaxis())->SetRangeUser(0.,2500.); |
||
74 | hp1d->DrawCopy(); |
||
75 | } |
||
76 | sprintf(fullname, "ps/%s_QDC.eps", fname); |
||
77 | c[cc]->SaveAs(fullname); |
||
78 | } |
||
79 | |||
80 | // Correlation 2d plots ------------------------------------------------------------------------------- |
||
81 | |||
82 | if( strchr(plopt, 'c') != NULL ) { |
||
83 | c[++cc] = new RTCanvas("TDCvsQDC", fname, 50*(cc+1), 0, 600, 850); |
||
84 | //c[cc]->Divide(3,3); |
||
85 | c[cc]->Divide(NCH); |
||
86 | |||
87 | for(int i=0;i<NCH;i++) { |
||
88 | c[cc]->cd(i+1); gPad->SetLogz(); |
||
89 | sprintf(hname, "hcorpos%d",i); hp2d = (TH2F *) dir->Get(hname); |
||
90 | |||
91 | hp2d->SetTitle("TDCvsQDC; QDC; TDC [ns]"); |
||
92 | (hp2d->GetXaxis())->SetRangeUser(0.,500.); |
||
93 | //hp2d->GetYaxis()->SetRangeUser(-1.5,5.0); |
||
94 | hp2d->DrawCopy("COLZ"); |
||
95 | } |
||
96 | sprintf(fullname, "ps/%s_cor.eps", fname); |
||
97 | c[cc]->SaveAs(fullname); |
||
98 | } |
||
99 | |||
100 | |||
101 | // Fits of corrected TDCs ----------------------------------------------------------------------------- |
||
102 | |||
103 | TF1 *fg = new TF1("fg", "gaus"); |
||
104 | TF1 *fgg = new TF1("fgg", "gaus(0)+gaus(3)"); |
||
105 | fgg->SetParNames("Constant","Mean","Sigma","Constant2","Mean2","Sigma2"); |
||
106 | if( strchr(plopt, 'f') != NULL ) { |
||
107 | c[++cc] = new RTCanvas("Corrected TDCs", fname, 50*(cc+1), 0, 600, 850); |
||
108 | //c[cc]->Divide(2,4); |
||
109 | c[cc]->Divide(NCH); |
||
110 | |||
111 | for(int i=0;i<NCH;i++) { |
||
112 | c[cc]->cd(i+1); gPad->SetLogy(); |
||
113 | sprintf(hname, "hctdc%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
114 | hp1d->SetTitle("cTDC; TDC [ns]; N"); |
||
115 | (hp1d->GetXaxis())->SetRangeUser(-40*TDC_BIN,160*TDC_BIN); |
||
116 | if( hp1d->GetMaximum() < 50 ) continue; |
||
117 | //(hp1d->GetXaxis())->SetRangeUser(-0.25,0.75); |
||
118 | |||
119 | if( strcmp(fitf, "g")==0 ) { |
||
120 | fg->SetParameters(hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin()), 0.05); |
||
121 | hp1d->Fit(fg, "0ql", "", fg->GetParameter(1)-0.1*fitw, fg->GetParameter(1)+0.05*fitw); |
||
122 | hp1d->Fit(fg, "ql", "", fg->GetParameter(1)-0.1*fitw, fg->GetParameter(1)+0.05*fitw); |
||
123 | |||
124 | printf("Ch[%d] Sigma =%6.1lfps\n",i,fg->GetParameter(2)*1000.); |
||
125 | } |
||
126 | else if( strcmp(fitf, "gg")==0 ) { |
||
127 | //fgg->SetParameters(2600.,0*TDC_BIN,2*TDC_BIN, 100.,0*TDC_BIN,10*TDC_BIN); |
||
128 | fgg->SetParameters(hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin()), 0.03, |
||
129 | hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin())/10., 0.1); |
||
130 | hp1d->Fit(fgg, "0ql", "", -50*TDC_BIN, 50*TDC_BIN); |
||
131 | hp1d->Fit(fgg, "ql", "", fgg->GetParameter(1)-2.5*fitw*fgg->GetParameter(2), |
||
132 | fgg->GetParameter(1)+3.5*fitw*fgg->GetParameter(2)); |
||
133 | |||
134 | printf("Ch[%d] Sigma =%6.1lfps\n",i,fgg->GetParameter(2)*1000.); |
||
135 | /* |
||
136 | fg->SetRange(-50., 200.); |
||
137 | fg->SetParameters(fgg->GetParameter(0), fgg->GetParameter(1), fgg->GetParameter(2)); |
||
138 | fg->SetLineColor(2); |
||
139 | fg->DrawCopy("LSAME"); |
||
140 | fg->SetParameters(fgg->GetParameter(3), fgg->GetParameter(4), fgg->GetParameter(5)); |
||
141 | fg->SetLineColor(3); |
||
142 | fg->DrawCopy("LSAME"); |
||
143 | */ |
||
144 | } else {printf("Wrong fit function (parameter 4)!!!\n"); return;} |
||
145 | } |
||
146 | sprintf(fullname, "ps/%s_cTDC.eps", fname); |
||
147 | c[cc]->SaveAs(fullname); |
||
148 | } |
||
149 | |||
150 | // TDCs ----------------------------------------------------------------------------------------------- |
||
151 | |||
152 | if( strchr(plopt, 't') != NULL ) { |
||
153 | c[++cc] = new RTCanvas("Raw TDC", fname, 50*(cc+1), 0, 600, 850); |
||
154 | //c[cc]->Divide(2,4); |
||
155 | c[cc]->Divide(NCH); |
||
156 | |||
157 | for(int i=0;i<NCH;i++) { |
||
158 | c[cc]->cd(i+1); gPad->SetLogy(); |
||
159 | sprintf(hname, "htdcpos%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
160 | hp1d->SetTitle("TDC; TDC [ns]; N"); |
||
161 | (hp1d->GetXaxis())->SetRangeUser(-2,5); |
||
162 | hp1d->DrawCopy(); |
||
163 | if( hp1d->GetMaximum() < 50 ) continue; |
||
164 | |||
165 | fg->SetParameters(hp1d->GetMaximum(), hp1d->GetBinCenter(hp1d->GetMaximumBin()), 0.25); |
||
166 | hp1d->Fit(fg,"0QL", "", fg->GetParameter(1)-0.5, fg->GetParameter(1)+0.25); |
||
167 | hp1d->Fit(fg,"QL", "", fg->GetParameter(1)-0.5, fg->GetParameter(1)+0.25); |
||
168 | |||
169 | printf("Ch[%d] RAW Sigma =%6.1lfps\n",i,fg->GetParameter(2)*1000.); |
||
170 | } |
||
171 | sprintf(fullname, "ps/%s_TDC.eps", fname); |
||
172 | c[cc]->SaveAs(fullname); |
||
173 | } |
||
174 | |||
175 | // Y scans ----------------------------------------------------------------------------------------------- |
||
176 | |||
177 | if( strchr(plopt, 'y') != NULL ) { |
||
178 | c[++cc] = new RTCanvas("Yscans", fname, 50*(cc+1), 0, 600, 850); |
||
179 | //c[cc]->Divide(2,4); |
||
180 | c[cc]->Divide(NCH); |
||
181 | |||
182 | for(int i=0;i<NCH;i++) { |
||
183 | c[cc]->cd(i+1); //gPad->SetLogy(); |
||
184 | sprintf(hname, "hnhitsy%d",i); |
||
185 | hp1d = (TH1F *) dir->Get(hname); |
||
186 | hp1d->SetTitle("YScan; x; N"); |
||
187 | //(hp1d->GetXaxis())->SetRangeUser(-80*TDC_BIN,200*TDC_BIN); |
||
188 | //if(i==0) |
||
189 | hp1d->DrawCopy(); |
||
190 | //else hp1d->DrawCopy("SAME"); |
||
191 | } |
||
192 | sprintf(fullname, "ps/%s_Ys.eps", fname); |
||
193 | c[cc]->SaveAs(fullname); |
||
194 | } |
||
195 | |||
196 | // X scans ----------------------------------------------------------------------------------------------- |
||
197 | TF1 *ferf = new TF1("ferf","[0]+[1]*(1+TMath::Erf((x-[2])/[3]))"); |
||
198 | //int cmap[NCH]={40,1,2,8,4,5,6,41}; |
||
199 | int cmap[NCH]={1}; |
||
200 | if( strchr(plopt, 'x') != NULL ) { |
||
201 | c[++cc] = new RTCanvas("Xscans", fname, 50*(cc+1), 0, 600, 430); |
||
202 | //c[cc]->Divide(2,4); |
||
203 | //c[cc]->Divide(NCH); |
||
204 | /* |
||
205 | sprintf(hname, "hnhitsx%d",4); hp1d = (TH1F *) dir->Get(hname); |
||
206 | hp1d->SetTitle("XScan; x; N"); |
||
207 | |||
208 | ferf->SetParameters(130,1600,43.4,1.0); |
||
209 | ferf->SetParNames("Offset","Constant","Mean","Sigma"); |
||
210 | hp1d->Fit(ferf,"QL"); |
||
211 | */ |
||
212 | |||
213 | for(int i=0;i<1;i++) { |
||
214 | |||
215 | sprintf(hname, "hnhitsx%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
216 | hp1d->SetTitle("XScan; x; N"); |
||
217 | hp1d->SetLineColor(cmap[i]); |
||
218 | (hp1d->GetYaxis())->SetRangeUser(0,hp1d->GetMaximum()*1.2); |
||
219 | if(i==0) hp1d->DrawCopy(); |
||
220 | else hp1d->DrawCopy("SAME"); |
||
221 | |||
222 | // c[cc]->cd(i+1); //gPad->SetLogy(); |
||
223 | // sprintf(hname, "hnhitsx%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
224 | // hp1d->SetTitle("XScan; x; N"); |
||
225 | //(hp1d->GetXaxis())->SetRangeUser(-80*TDC_BIN,200*TDC_BIN); |
||
226 | // hp1d->DrawCopy(); |
||
227 | } |
||
228 | |||
229 | sprintf(fullname, "ps/%s_Xs.eps", fname); |
||
230 | c[cc]->SaveAs(fullname); |
||
231 | } |
||
232 | |||
233 | // tdc vs. MCP OUT tdc ----------------------------------------------------------------------------------- |
||
234 | |||
235 | if( strchr(plopt, 'm') != NULL ) { |
||
236 | c[++cc] = new RTCanvas("TDCvsMCPOUT", fname, 50*(cc+1), 0, 400, 850); |
||
237 | //c[cc]->Divide(2,4); |
||
238 | c[cc]->Divide(NCH); |
||
239 | |||
240 | for(int i=0;i<NCH;i++) { |
||
241 | c[cc]->cd(i+1); gPad->SetLogz(); |
||
242 | sprintf(hname, "hmcpoutcor%d",i); hp2d = (TH2F *) dir->Get(hname); |
||
243 | hp2d->SetTitle("TDCvsMCPOUT; MCP OUT TDC [ns]; TDC [ns]"); |
||
244 | //(hp1d->GetXaxis())->SetRangeUser(-80*TDC_BIN,200*TDC_BIN); |
||
245 | hp2d->DrawCopy("COLZ"); |
||
246 | } |
||
247 | sprintf(fullname, "ps/%s_TDCvsMCPOUT.eps", fname); |
||
248 | c[cc]->SaveAs(fullname); |
||
249 | } |
||
250 | |||
251 | // Charge sharing ----------------------------------------------------------------------------------- |
||
252 | |||
253 | if( strchr(plopt, 's') != NULL ) { |
||
254 | c[++cc] = new RTCanvas("ChargeSharing", fname, 50*(cc+1), 0, 600, 850); |
||
255 | c[cc]->Divide(1,2); |
||
256 | c[cc]->cd(1); gPad->SetLogz(); |
||
257 | sprintf(hname, "hshare"); hp2d = (TH2F *) dir->Get(hname); |
||
258 | hp2d->SetTitle("ChargeSharing; x [mm]; ADC1/(ADC1+ADC2)"); |
||
259 | hp2d->DrawCopy("COLZ"); |
||
260 | |||
261 | c[cc]->cd(2); //gPad->SetLogy(); |
||
262 | TH1F *hprojx = (TH1F*)hp2d->ProjectionX("ProjectionX", 59, 61); |
||
263 | hprojx->Fit("gaus","QL","", hprojx->GetMean()-hprojx->GetRMS(), hprojx->GetMean()+hprojx->GetRMS()); |
||
264 | sprintf(fullname, "ps/%s_share.eps", fname); |
||
265 | c[cc]->SaveAs(fullname); |
||
266 | } |
||
267 | |||
268 | //rootfile->Close(); |
||
269 | } |