Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
326 | f9daq | 1 | #include <stdio.h> |
2 | #include <stdlib.h> |
||
3 | #include <TROOT.h> |
||
4 | #include <TF1.h> |
||
5 | #include <TH1F.h> |
||
6 | #include <TH1D.h> |
||
7 | #include <TH2D.h> |
||
8 | #include <TCanvas.h> |
||
9 | #include <TStyle.h> |
||
10 | #include <TSystem.h> |
||
11 | #include <TFile.h> |
||
12 | #include <TDirectory.h> |
||
13 | #include <TPaveText.h> |
||
14 | #include <TStatistic.h> |
||
15 | #include <TNamed.h> |
||
16 | #include <TAxis.h> |
||
17 | #include <TPDF.h> |
||
18 | #include <TFitResult.h> |
||
19 | |||
20 | |||
21 | int febana(int run){ |
||
22 | const int hid=1; |
||
23 | char name[128]; |
||
24 | const char * hname = "h2d_0"; |
||
25 | int brd[4]; |
||
26 | |||
27 | sprintf(name,"%s;%d",hname,hid); //you define histogram h2d_0;1 test pulse, h2d_0;2 offset |
||
28 | TH2D *h = (TH2D *) gDirectory->Get(name); //this tell you directory to your histogram |
||
29 | //serialNumber = h->GetTitle(); |
||
30 | /********radeliti hočem serijsko številko********************/ |
||
31 | char b0[255], b1[255], b2[255], b3[255], b00[255], b01[255], b10[255], b11[255], b20[255], b21[255], b30[255], b31[255]; |
||
32 | |||
33 | //sscanf(serialNumber,"%s%s%s%s",b0,b1,b2,b3); |
||
34 | sscanf(h->GetTitle(),"%s%s%s%s",b0,b1,b2,b3); |
||
35 | sscanf(b0, "%[^=]=%s", b00, b01); //b01 je serijska številka od borda0 |
||
36 | sscanf(b1, "%[^=]=%s", b10, b11); //b11 je serijska številka od borda1 |
||
37 | sscanf(b2, "%[^=]=%s", b20, b21); //b21 je serijska številka od borda2 |
||
38 | sscanf(b3, "%[^=]=%s", b30, b31); //b31 je serijska številka od borda3 |
||
39 | /*****************************************************************************/ |
||
40 | /********radeliti hočem serijsko številko boarda********************/ |
||
41 | for (int k=0;k<4;k++){ |
||
42 | sprintf(name,"vth1_%d_0",k); //you define histogram vth1_0_0;1 |
||
43 | TH2D * h0 = (TH2D *) gDirectory->Get(name); //this tell you directory to your histogram |
||
44 | if (!h0) continue; |
||
45 | sscanf(h0->GetTitle(),"%*s%*s%*s%*s sn=%d",&brd[k]); |
||
46 | printf("sn = %d\n",brd[k]); |
||
47 | } |
||
48 | /*********************Ofset scanning******************************************/ |
||
49 | int nx=0; |
||
50 | int imax=36; |
||
51 | |||
52 | for (int i=2;i<=imax;i++){ |
||
53 | sprintf(name,"h2d_0;%d",i); |
||
54 | TH2D *h2dp=(TH2D *) gDirectory->Get(name); // directory do grafoz z offset scanningom |
||
55 | if (h2dp) nx++; |
||
56 | } |
||
57 | |||
58 | TCanvas *c55= new TCanvas("c55","Offset scanning",1000,800); //definiramo canvase |
||
59 | c55->Divide(8,4); //razdelimo canvase |
||
60 | |||
61 | TCanvas *ccoarse[4]; |
||
62 | TCanvas *cfine[4]; |
||
63 | for (int i=0;i<4;i++){ |
||
64 | sprintf(name,"ccoarse%d",i); |
||
65 | ccoarse[i]= new TCanvas(name,name,1000,800); |
||
66 | ccoarse[i]->Divide(4,4); |
||
67 | sprintf(name,"cfine%d",i); |
||
68 | cfine[i]= new TCanvas(name,name,1000,800); |
||
69 | cfine[i]->Divide(4,4); |
||
70 | } |
||
71 | |||
72 | |||
73 | |||
74 | |||
75 | TH2D *hfeb[4]; |
||
76 | TH2D *hcoarsemean[4]; |
||
77 | TH2D *hfinemean[4]; |
||
78 | TH2D *hmean[4]; |
||
79 | |||
80 | sprintf(name,"h2d_0;2"); |
||
81 | TH2D *h2dz=(TH2D *) gDirectory->Get(name); |
||
82 | if (!h2dz) { |
||
83 | printf("Histogram %s not found.\n"); |
||
84 | return 0; |
||
85 | } |
||
86 | |||
87 | |||
88 | for (int n=0;n<4;n++){ |
||
89 | sprintf(name,"board%d", n); |
||
90 | |||
91 | hfeb[n]= new TH2D(name, name,h2dz->GetNbinsX()/4, -0.5,143.5, h2dz->GetNbinsY() , h2dz->GetYaxis()->GetXmin(), h2dz->GetYaxis()->GetXmax() ); |
||
92 | sprintf(name,"hcoarsemean_%d", n); |
||
93 | hcoarsemean[n]= new TH2D(name,"Mean rough;HAPD ch;decoded offset",144,-0.5,143.5,16,-0.5,15.5); |
||
94 | sprintf(name,"hmean_%d", n); |
||
95 | hmean[n]= new TH2D(name,"Mean;HAPD ch;offset",144,-0.5,144,nx,-0.5,nx-0.5); |
||
96 | hmean[n]->SetMinimum(300); |
||
97 | hmean[n]->SetMaximum(700); |
||
98 | sprintf(name,"hfinemean_%d", n); |
||
99 | hfinemean[n]= new TH2D(name,"Mean fine;HAPD ch;decoded offset",144,-0.5,143.5,16,-0.5,15.5); |
||
100 | } |
||
101 | |||
102 | |||
103 | |||
104 | int i0; |
||
105 | int i01; |
||
106 | for (int i=2;i<nx+2;i++){ |
||
107 | |||
108 | sprintf(name,"h2d_0;%d",i); |
||
109 | printf("%s\n",name); |
||
110 | TH2D *h2d=(TH2D *) gDirectory->Get(name); |
||
111 | for (int x=0;x<h2d->GetNbinsX();x++){ |
||
112 | for (int y=0;y<h2d->GetNbinsY();y++){ |
||
113 | float val = h2d->GetBinContent(x+1,y+1); |
||
114 | hfeb[x/144]->SetBinContent(x%144+1, y+1,val); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | if(i<18){ //popravimo našo skalo za coarse scanning |
||
119 | int j= (i-2)%8; |
||
120 | int k= (i-2)/8; |
||
121 | int j0= -(1-j/1)*1; |
||
122 | int k0= (1-k/1)*8; |
||
123 | i0=j0+k0+1; |
||
124 | } else i0=50; //ker imamo še fine scannig, bo pri njih vrednost x-koordinate enaka 50 (za lažjo obdelovo podatkov) |
||
125 | |||
126 | if(i>17){ //popravimo našo skalo za fine scanning |
||
127 | int j= (i-18)%8; |
||
128 | int k= (i-18)/8; |
||
129 | int j0= -(1-j/1)*1; |
||
130 | int k0= (1-k/1)*8; |
||
131 | i01=j0+k0+1; |
||
132 | } else i01=50; //ker imamo še coarse scannig, bo pri njih vrednost x-koordinate enaka 50 (za lažjo obdelovo podatkov) |
||
133 | |||
134 | if (h2d){ |
||
135 | sprintf(name,"%s %s %s %s graf %d",b01, b11, b21, b31, i-1); |
||
136 | h2d->SetTitle(name); |
||
137 | if (i>1) { |
||
138 | c55->cd(i-1); |
||
139 | h2d->DrawCopy("colz"); //narišemo vse grafe on 4 boardov za Offset scanning |
||
140 | } |
||
141 | } |
||
142 | |||
143 | for (int board=0;board<4;board++){ |
||
144 | if (hfeb[board]){ |
||
145 | if (i>1&&i<18) { |
||
146 | sprintf(name,"Coarse scanning board %d scan %d",brd[board], i-1); |
||
147 | hfeb[board]->SetTitle(name); |
||
148 | ccoarse[board]->cd(i-1); |
||
149 | hfeb[board]->DrawCopy("colz"); //coarse offset scanning board0 |
||
150 | }else{ |
||
151 | sprintf(name,"Fine scanning board %d scan %d",brd[board], i-17); |
||
152 | hfeb[board]->SetTitle(name); |
||
153 | cfine[board]->cd(i-17); |
||
154 | hfeb[board]->DrawCopy("colz"); //fine offset scanning board0 |
||
155 | } |
||
156 | |||
157 | TF1 *f = new TF1("fit","gaus", 0 , 1000); //definiraš gaussovski fit |
||
158 | |||
159 | for (int ch=0;ch<hfeb[board]->GetNbinsX();ch++){ |
||
160 | |||
161 | TH1D *hy0 = hfeb[board]->ProjectionY("_py",ch+1,ch+1); //narediš projekcije za vsak kanal |
||
162 | hy0->Fit(f,"QWWN"); //narediš fit čez projekcije |
||
163 | |||
164 | double mean = hy0->GetMean(); //prebereš mean |
||
165 | hcoarsemean[board]->Fill(ch,i0,mean); //napolniš grafe |
||
166 | hmean[board]->Fill(ch,i-2,mean); |
||
167 | hfinemean[board]->Fill(ch,i01,mean); |
||
168 | |||
169 | } |
||
170 | } |
||
171 | } |
||
172 | |||
173 | |||
174 | |||
175 | |||
176 | } |
||
177 | |||
178 | for (int board=0;board<4;board++){ |
||
179 | sprintf(name,"board %d.pdf", brd[board]); |
||
180 | printf("board pri pdf %s\n",name); |
||
181 | ccoarse[board]->Print(name,"pdf"); |
||
182 | cfine[board]->Print(name,"pdf"); |
||
183 | } |
||
184 | |||
185 | |||
186 | /****************mean and slope together****************************/ |
||
187 | |||
188 | TF1 *f0 = new TF1("mlin","pol1", 0 , 127); //linearni fit definiran za vse grafe |
||
189 | TCanvas * cfit[4]; |
||
190 | TH1F *hpoolfine[4]; |
||
191 | TH1F *hfitcoarse[4]; |
||
192 | TH1F *hfitfine [4]; |
||
193 | TH1F *hpoolcoarse[4]; |
||
194 | for (int board=0;board<4;board++){ |
||
195 | |||
196 | hcoarsemean[board]->FitSlicesY(f0); |
||
197 | sprintf(name,"%s_1",hcoarsemean[board]->GetName()); |
||
198 | printf("%s\n",name); |
||
199 | hfitcoarse[board] = ((TH1F * ) gDirectory->Get(name)); |
||
200 | |||
201 | hfinemean[board]->FitSlicesY(f0); |
||
202 | sprintf(name,"%s_1",hfinemean[board]->GetName()); |
||
203 | printf("%s\n",name); |
||
204 | hfitfine[board] = ((TH1F * ) gDirectory->Get(name)); |
||
205 | |||
206 | sprintf(name,"cfit%d",board); |
||
207 | printf("%s\n",name); |
||
208 | cfit[board]= new TCanvas(name,name,1000,800); |
||
209 | cfit[board]->Divide(1,3); |
||
210 | cfit[board]->cd(1); |
||
211 | hmean[board]->ProjectionY("hprojection1_1",1,1)->Draw(); |
||
212 | hmean[board]->ProjectionY("hprojection1_3",3,3)->Draw("same"); |
||
213 | hmean[board]->ProjectionY("hprojection1_10",10,10)->Draw("same"); |
||
214 | hmean[board]->ProjectionY("hprojection1_15",15,15)->Draw("same"); |
||
215 | |||
216 | cfit[board]->cd(3); |
||
217 | gStyle->SetOptStat(1); |
||
218 | |||
219 | sprintf(name,"hpoolfine_%d",board); |
||
220 | printf("%s\n",name); |
||
221 | hpoolfine[board] = new TH1F(name,"Fine slope together",10,-1.5,-0.7); |
||
222 | for (int ch=0;ch<hfitfine[board]->GetNbinsX();ch++){ |
||
223 | hpoolfine[board]->Fill(hfitfine[board]->GetBinContent(ch+1)); |
||
224 | } |
||
225 | hpoolfine[board]->Draw(); |
||
226 | |||
227 | cfit[board]->cd(2); |
||
228 | gStyle->SetOptStat(1); |
||
229 | |||
230 | sprintf(name,"hpoolcoarse_%d",board); |
||
231 | printf("%s\n",name); |
||
232 | hpoolcoarse[board] = new TH1F(name,"Coarse slope together",10,-17,-10); |
||
233 | for (int ch=0;ch<hfitcoarse[board]->GetNbinsX();ch++){ |
||
234 | hpoolcoarse[board]->Fill(hfitcoarse[board]->GetBinContent(ch+1)); |
||
235 | } |
||
236 | hpoolcoarse[board]->Draw(); |
||
237 | sprintf(name,"board %d.pdf", brd[board]); |
||
238 | printf("%s\n",name); |
||
239 | //c20->Print(name,"pdf"); |
||
240 | |||
241 | } |
||
242 | |||
243 | //return; |
||
244 | /****************************OffsetVariation board0**********************************************/ |
||
245 | TCanvas *c0coarse[4]; |
||
246 | TCanvas *c0fine[4]; |
||
247 | |||
248 | for (int board=0;board<4;board++){ |
||
249 | |||
250 | |||
251 | sprintf(name,"hcoarsemean_%d",board); |
||
252 | TH2D *h0coarse=(TH2D *) gDirectory->Get(name); |
||
253 | sprintf(name,"hfinemean_%d",board); |
||
254 | TH2D *h0fine=(TH2D *) gDirectory->Get(name); |
||
255 | char nv[20]; |
||
256 | char opt[20]; |
||
257 | int first =0; |
||
258 | sprintf(name,"c0coarse%d",board); |
||
259 | c0coarse[board]= new TCanvas(name,name,1000,800); |
||
260 | c0coarse[board]->Divide(4,2); |
||
261 | sprintf(name,"c0fine%d",board); |
||
262 | c0fine[board]= new TCanvas(name,name,1000,800); |
||
263 | c0fine[board]->Divide(4,2); |
||
264 | //return; |
||
265 | for (int chip=0;chip<4; chip++){ |
||
266 | c0coarse[board]->cd(chip+1); |
||
267 | first=0; |
||
268 | for (int ch=0+chip*36;ch<(36+chip*36);ch++) { |
||
269 | sprintf(nv,"hxc_%d",ch); |
||
270 | TH1D* h0coarsep= h0coarse->ProjectionY(nv,ch+1,ch+1); |
||
271 | //TFitResultPtr r0 = h0coarsep>Fit(f0,"SQN"); |
||
272 | //double chi0= r0->Chi2(); |
||
273 | if (first) sprintf(opt,"same"); else { |
||
274 | h0coarsep->GetXaxis()->SetRangeUser(300,1000); |
||
275 | sprintf(opt,""); |
||
276 | } |
||
277 | sprintf(name,"Coarse mean chip %d",chip); |
||
278 | h0coarsep->SetTitle(name); |
||
279 | h0coarsep->SetMinimum(350); |
||
280 | h0coarsep->SetMaximum(750); |
||
281 | h0coarsep->Draw(opt); |
||
282 | first=1; |
||
283 | } |
||
284 | } |
||
285 | gStyle->SetOptStat(1); |
||
286 | for (int chip=0;chip<4;chip++){ |
||
287 | c0coarse[board]->cd(chip+5); |
||
288 | sprintf(name,"hslopecoarse%dchip%d",board,chip); |
||
289 | TH1F *hpool = new TH1F(name,name,10,-17,-10); |
||
290 | for (int ch=0+chip*36;ch<(36+chip*36);ch++){ |
||
291 | hpool->Fill(hfitcoarse[board]->GetBinContent(ch+1)); |
||
292 | } |
||
293 | hpool->Draw(); |
||
294 | } |
||
295 | |||
296 | |||
297 | for (int chip=0;chip<4; chip++){ |
||
298 | c0fine[board]->cd(chip+1); |
||
299 | first=0; |
||
300 | for (int ch=0+chip*36;ch<(36+chip*36);ch++) { |
||
301 | sprintf(nv,"hxf_%d",ch); |
||
302 | TH1D* h0finep= h0fine->ProjectionY(nv,ch+1,ch+1); |
||
303 | TFitResultPtr r0 = h0finep->Fit(f0,"SQN"); |
||
304 | double chi0= r0->Chi2(); |
||
305 | if (first) sprintf(opt,"same"); else { |
||
306 | h0finep->GetXaxis()->SetRangeUser(300,1000); |
||
307 | sprintf(opt,""); |
||
308 | } |
||
309 | sprintf(name,"Fine mean chip %d",chip); |
||
310 | h0finep->SetTitle(name); |
||
311 | h0finep->SetMinimum(400); |
||
312 | h0finep->SetMaximum(600); |
||
313 | h0finep->Draw(opt); |
||
314 | first=1; |
||
315 | } |
||
316 | } |
||
317 | |||
318 | |||
319 | for (int chip=0;chip<4;chip++){ |
||
320 | c0fine[board]->cd(chip+5); |
||
321 | sprintf(name,"hslopefine%dchip%d",board,chip); |
||
322 | TH1F *hpool = new TH1F(name,name,10,-1.5,-0.7); |
||
323 | for (int ch=0+chip*36;ch<(36+chip*36);ch++){ |
||
324 | hpool->Fill(hfitfine[board]->GetBinContent(ch+1)); |
||
325 | } |
||
326 | hpool->Draw(); |
||
327 | } |
||
328 | |||
329 | |||
330 | |||
331 | c0coarse[board]->Update(); |
||
332 | c0fine[board]->Update(); |
||
333 | /* sprintf(pngname,"C:\\home\\anze\\print\\scan\\Offset Variation\\%s %s.png",Offset0,b01); |
||
334 | c0v->SaveAs(pngname, "png");*/ |
||
335 | sprintf(name,"board %d.pdf", brd[board]); |
||
336 | c0coarse[board]->Print(name,"pdf"); |
||
337 | sprintf(name,"board %d.pdf)", brd[board]); |
||
338 | c0fine[board]->Print(name,"pdf"); |
||
339 | } |
||
340 | |||
341 | /************************Slope**************************************************/ |
||
342 | /*FILE *fp1 = fopen("Slope vsi.txt","at"); |
||
343 | if (fp1!=NULL) { |
||
344 | fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b01,hpool0->GetMean(),hpool01->GetMean(), hpool0100->GetMean(), hpool0101->GetMean(), hpool0102->GetMean(), hpool0103->GetMean(), hpool0104->GetMean(), hpool0105->GetMean(), hpool0106->GetMean(), hpool0107->GetMean()); |
||
345 | fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b11,hpool1->GetMean(),hpool11->GetMean(), hpool1110->GetMean(), hpool1111->GetMean(), hpool1112->GetMean(), hpool1113->GetMean(), hpool1114->GetMean(), hpool1115->GetMean(), hpool1116->GetMean(), hpool1117->GetMean()); |
||
346 | fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b21,hpool2->GetMean(),hpool21->GetMean(), hpool2120->GetMean(), hpool2121->GetMean(), hpool2122->GetMean(), hpool2123->GetMean(), hpool2124->GetMean(), hpool2125->GetMean(), hpool2126->GetMean(), hpool2127->GetMean()); |
||
347 | fprintf(fp1,"%s , %f , %f , %f , %f , %f , %f , %f , %f , %f , %f\n",b31,hpool3->GetMean(),hpool31->GetMean(), hpool3130->GetMean(), hpool3131->GetMean(), hpool3132->GetMean(), hpool3133->GetMean(), hpool3134->GetMean(), hpool3135->GetMean(), hpool3136->GetMean(), hpool3137->GetMean()); |
||
348 | } |
||
349 | fclose(fp1); |
||
350 | /***********************************vsi nakloni iz vseh kanalov*************************************************/ |
||
351 | /*for(int ch=0;ch<144;ch++){ |
||
352 | FILE *fp2 = fopen("proba tocke.txt","at"); |
||
353 | if (fp2!=NULL) { |
||
354 | //fprintf(fp2,"%s , %f , %f\n",b01,hfito10->GetBinContent(ch+1),hfito101->GetBinContent(ch+1)); |
||
355 | //fprintf(fp2,"%s , %f , %f\n",b11,hfito11->GetBinContent(ch+1),hfito111->GetBinContent(ch+1)); |
||
356 | //fprintf(fp2,"%s , %f , %f\n",b21,hfito12->GetBinContent(ch+1),hfito121->GetBinContent(ch+1)); |
||
357 | fprintf(fp2,"%s , %f , %f\n",b31,hfito13->GetBinContent(ch+1),hfito131->GetBinContent(ch+1))); |
||
358 | } |
||
359 | } |
||
360 | /****************************************************************************************************/ |
||
361 | return 0; |
||
362 | } |