Rev 40 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
35 | f9daq | 1 | #include "TROOT.h" |
2 | #include "TFile.h" |
||
3 | #include "TBenchmark.h" |
||
4 | #include "TH1F.h" |
||
5 | #include "TH2F.h" |
||
6 | #include "TH3F.h" |
||
7 | #include "TCanvas.h" |
||
8 | #include "TStyle.h" |
||
9 | #include "TPad.h" |
||
10 | #include "TF1.h" |
||
11 | #include "TGraph.h" |
||
12 | #include "TSpectrum.h" |
||
13 | #include "stdio.h" |
||
38 | f9daq | 14 | #include "THStack.h" |
40 | f9daq | 15 | #include "TPaveText.h" |
35 | f9daq | 16 | |
17 | #include "include/RTUtil.h" |
||
18 | |||
19 | double getNoise(TH2F*, int, int); |
||
20 | |||
40 | f9daq | 21 | int biasScan(char filename[256] = "test", char plopt[256]="th", int chXstart=0, int chXend=7, double par1=0.0, double par2=0.0, bool debug = false) |
35 | f9daq | 22 | { |
23 | const int c_nChannels = 64; |
||
40 | f9daq | 24 | const double c_xOffset = 0; // mm |
25 | const double c_yOffset = 0; |
||
35 | f9daq | 26 | |
27 | int map[8][8]={{32,34,53,55,40,42,61,63}, |
||
28 | {48,50,37,39,56,58,45,47}, |
||
29 | {33,35,52,54,41,43,60,62}, |
||
30 | {49,51,36,38,57,59,44,46}, |
||
31 | {17,19,4,6,25,27,12,14}, |
||
32 | {1,3,20,22,9,11,28,30}, |
||
33 | {16,18,5,7,24,26,13,15}, |
||
34 | {0,2,21,23,8,10,29,31} |
||
35 | }; |
||
36 | |||
38 | f9daq | 37 | // Set draw style |
35 | f9daq | 38 | RTSetStyle(gStyle); |
39 | |||
40 | // open the file with histograms |
||
41 | char fnameroot[256]; |
||
42 | TFile* rootfile; |
||
43 | sprintf(fnameroot, "root/%s.root", filename); |
||
44 | rootfile = (TFile *) gROOT->FindObject(filename); |
||
45 | if(rootfile==NULL) rootfile = new TFile(fnameroot); |
||
46 | if(rootfile==NULL) { |
||
47 | printf("Cannot open root file %s!!!\n",fnameroot); |
||
48 | return(0); |
||
49 | } |
||
50 | |||
51 | if(strstr(plopt, "tdc") != NULL) { |
||
52 | TCanvas *canvas21 = new TCanvas("canvas21","canvas21",1600,800); |
||
53 | TH3F* h0 = (TH3F*) rootfile->Get("h_correctedTDC"); |
||
54 | Int_t binsX = h0->GetXaxis()->GetNbins(); |
||
55 | Int_t minX = h0->GetXaxis()->GetFirst(); |
||
56 | Int_t maxX = h0->GetXaxis()->GetLast()+1; |
||
57 | Int_t binsY = h0->GetYaxis()->GetNbins(); |
||
58 | Int_t minY = h0->GetYaxis()->GetFirst(); |
||
59 | Int_t maxY = h0->GetYaxis()->GetLast()+1; |
||
60 | Int_t binsZ = h0->GetZaxis()->GetNbins(); |
||
61 | Int_t minZ = h0->GetZaxis()->GetFirst(); |
||
62 | Int_t maxZ = h0->GetZaxis()->GetLast()+1; |
||
63 | Double_t xLowUser = h0->GetXaxis()->GetBinLowEdge(minX); |
||
64 | Double_t xUpUser = h0->GetXaxis()->GetBinUpEdge(maxX); |
||
65 | Double_t yLowUser = h0->GetYaxis()->GetBinLowEdge(minY); |
||
66 | Double_t yUpUser = h0->GetYaxis()->GetBinUpEdge(maxY); |
||
67 | |||
68 | canvas21->Divide(2); |
||
69 | //h0->Draw(); |
||
70 | canvas21->cd(1); |
||
71 | //h0->Project3D("xy")->Draw("colz"); |
||
72 | //canvas21->cd(2); |
||
73 | //h0->Project3D("yz")->Draw("colz"); |
||
74 | //canvas21->cd(3); |
||
75 | TH2D* h_correctedTDC = (TH2D*) h0->Project3D("xz"); |
||
76 | //h0->GetZaxis()->SetRangeUser(-5,5); |
||
77 | //h0->Project3D("xzo")->Draw("colz"); |
||
40 | f9daq | 78 | //h_correctedTDC->SetTitle("; t [ns]; Channel"); |
35 | f9daq | 79 | h_correctedTDC->Draw("colz"); |
80 | /* |
||
81 | TH1F* tdc1 = new TH1F("tdc1",";TDC [ns];Events",binsZ, minZ, maxZ); |
||
82 | //for(int j=minY; j<maxY; j++) { |
||
83 | for(int k=minZ; k<maxZ; k++) { |
||
84 | double signal = h0->GetBinContent(1,1,k); |
||
85 | tdc1->Fill(k,signal); |
||
86 | //} |
||
87 | } |
||
88 | tdc1->Draw(); |
||
89 | */ |
||
90 | |||
91 | TH2D* h_timeWalk = (TH2D*) h0->Project3D("zy"); |
||
92 | canvas21->cd(2); |
||
40 | f9daq | 93 | //h_timeWalk->SetTitle(";Threshold [V]; t [ns]"); |
35 | f9daq | 94 | h_timeWalk->Draw("colz"); |
95 | } |
||
96 | |||
36 | f9daq | 97 | if (strstr(plopt, "bias") != NULL) { |
98 | TCanvas* canvas01 = new TCanvas("canvas01","",800, 800); |
||
99 | canvas01->cd(); |
||
100 | TH2F* h_bias = (TH2F*) rootfile->Get("h_bias"); |
||
101 | h_bias->Draw("colz"); |
||
50 | f9daq | 102 | |
103 | TCanvas* canvas02 = new TCanvas("canvas02","",800, 800); |
||
104 | //canvas02->Divide(2,2); |
||
105 | canvas02->cd(); |
||
106 | TH3F* h_biasThreshold = (TH3F*) rootfile->Get("h_biasThreshold"); |
||
107 | //h_biasThreshold->Draw(); |
||
108 | //canvas02->cd(2); |
||
109 | //h_biasThreshold->GetXaxis()->SetRange(1,5); |
||
110 | h_biasThreshold->Project3D("zy"); |
||
111 | h_biasThreshold_zy->DrawCopy("colz"); |
||
112 | |||
113 | TCanvas* canvas03 = new TCanvas("canvas03","",1200, 1200); |
||
114 | canvas03->Divide(4,4); |
||
115 | int x1=0; |
||
116 | int x2=3; |
||
117 | int y1=0; |
||
118 | int y2=3; |
||
119 | for(int j=x1; j<=x2; j++){ |
||
120 | for(int k=y1; k<=y2; k++){ |
||
121 | int channel = map[j][k]; |
||
122 | int canvasPosition = 4*(4-k-1) + 4 - j; |
||
123 | canvas03->cd(canvasPosition); |
||
124 | h_biasThreshold->GetXaxis()->SetRange(channel+1,channel+1); |
||
125 | char histoName[128]; |
||
126 | sprintf(histoName, "Ch %d", channel); |
||
127 | h_biasThreshold->Project3D("zy"); |
||
128 | //sprintf(option, "h_biasThresholsd_zy%f", channel); |
||
129 | h_biasThreshold_zy->SetTitle(histoName); |
||
130 | h_biasThreshold_zy->DrawCopy("colz"); |
||
131 | |||
132 | } |
||
133 | } |
||
134 | TCanvas* canvas04 = new TCanvas("canvas04","",1200, 1200); |
||
135 | canvas04->Divide(4,4); |
||
136 | int x1=0; |
||
137 | int x2=3; |
||
138 | int y1=4; |
||
139 | int y2=7; |
||
140 | for(int j=x1; j<=x2; j++){ |
||
141 | for(int k=y1; k<=y2; k++){ |
||
142 | int channel = map[j][k]; |
||
143 | int canvasPosition = 4*(8-k-1) + 4 - j; |
||
144 | canvas04->cd(canvasPosition); |
||
145 | h_biasThreshold->GetXaxis()->SetRange(channel+1,channel+1); |
||
146 | char histoName[128]; |
||
147 | sprintf(histoName, "Ch %d", channel); |
||
148 | h_biasThreshold->Project3D("zy"); |
||
149 | //sprintf(option, "h_biasThresholsd_zy%f", channel); |
||
150 | h_biasThreshold_zy->SetTitle(histoName); |
||
151 | h_biasThreshold_zy->DrawCopy("colz"); |
||
152 | |||
153 | } |
||
154 | } |
||
155 | TCanvas* canvas05 = new TCanvas("canvas05","",1200, 1200); |
||
156 | canvas05->Divide(4,4); |
||
157 | int x1=4; |
||
158 | int x2=7; |
||
159 | int y1=0; |
||
160 | int y2=3; |
||
161 | for(int j=x1; j<=x2; j++){ |
||
162 | for(int k=y1; k<=y2; k++){ |
||
163 | int channel = map[j][k]; |
||
164 | int canvasPosition = 4*(4-k-1) + 8 - j; |
||
165 | canvas05->cd(canvasPosition); |
||
166 | h_biasThreshold->GetXaxis()->SetRange(channel+1,channel+1); |
||
167 | char histoName[128]; |
||
168 | sprintf(histoName, "Ch %d", channel); |
||
169 | h_biasThreshold->Project3D("zy"); |
||
170 | //sprintf(option, "h_biasThresholsd_zy%f", channel); |
||
171 | h_biasThreshold_zy->SetTitle(histoName); |
||
172 | h_biasThreshold_zy->DrawCopy("colz"); |
||
173 | |||
174 | } |
||
175 | } |
||
176 | |||
177 | TCanvas* canvas06 = new TCanvas("canvas06","",1200, 1200); |
||
178 | canvas06->Divide(4,4); |
||
179 | int x1=4; |
||
180 | int x2=7; |
||
181 | int y1=4; |
||
182 | int y2=7; |
||
183 | for(int j=x1; j<=x2; j++){ |
||
184 | for(int k=y1; k<=y2; k++){ |
||
185 | int channel = map[j][k]; |
||
186 | int canvasPosition = 4*(8-k-1) + 8 - j; |
||
187 | canvas06->cd(canvasPosition); |
||
188 | h_biasThreshold->GetXaxis()->SetRange(channel+1,channel+1); |
||
189 | char histoName[128]; |
||
190 | sprintf(histoName, "Ch %d", channel); |
||
191 | h_biasThreshold->Project3D("zy"); |
||
192 | //sprintf(option, "h_biasThresholsd_zy%f", channel); |
||
193 | h_biasThreshold_zy->SetTitle(histoName); |
||
194 | h_biasThreshold_zy->DrawCopy("colz"); |
||
195 | |||
196 | } |
||
197 | } |
||
198 | |||
36 | f9daq | 199 | } |
200 | |||
201 | if (strstr(plopt, "th") != NULL) { |
||
202 | TCanvas* canvas1 = new TCanvas("canvas1","",800,800); |
||
203 | canvas1->cd(); |
||
204 | //gPad->SetLogz(); |
||
205 | //canvas1->SetLogz(); |
||
206 | TH2F* h_threshold = (TH2F*) rootfile->Get("h_threshold"); |
||
207 | h_threshold->SetTitleOffset(1.5,"y"); |
||
208 | //h_threshold->GetZaxis()->SetRangeUser(0,1000); |
||
209 | h_threshold->SetContour(20); |
||
210 | |||
211 | h_threshold->Draw("colz"); |
||
212 | |||
213 | TCanvas* canvas2 = new TCanvas("canvas2","",1600,800); |
||
214 | canvas2->Divide(2); |
||
215 | TH1D* h_projection1 = h_threshold->ProjectionY("Ch 37",38,38); |
||
216 | canvas2->cd(1); |
||
217 | //h_projection1->GetYaxis()->SetRangeUser(0,1000); |
||
218 | //gPad->SetLogy(); |
||
219 | h_projection1->Draw(); |
||
220 | |||
221 | TH1D* h_projection2 = h_threshold->ProjectionY("Ch 38",39,39); |
||
222 | canvas2->cd(2); |
||
223 | //gPad->SetLogy(); |
||
224 | h_projection2->Draw(); |
||
225 | } |
||
226 | |||
35 | f9daq | 227 | if(strstr(plopt,"16") != NULL) |
228 | { |
||
36 | f9daq | 229 | TH2F* h_threshold = (TH2F*) rootfile->Get("h_bias"); |
35 | f9daq | 230 | TCanvas* canvas = new TCanvas("canvas","",1600,1600); |
38 | f9daq | 231 | TCanvas* canvas11 = new TCanvas("canvas11","",800,800); |
35 | f9daq | 232 | canvas->cd(); |
233 | TVirtualPad *main = new TPad("main","main",0,0,1,1,10,1); |
||
234 | main->Draw(); |
||
38 | f9daq | 235 | main->cd(); |
35 | f9daq | 236 | main->Divide(4,4); |
237 | for(int i=chXstart; i<chXend; i++) { |
||
40 | f9daq | 238 | for(int j=(int)par1; j<(int)par2; j++) { |
35 | f9daq | 239 | int channel = map[i][j]; |
240 | TH1D* h_projection = h_threshold->ProjectionY("",channel+1,channel+1); |
||
40 | f9daq | 241 | int canvasPosition = i-chXend+4*((int)par2-j)+1; |
35 | f9daq | 242 | printf(" %d ", canvasPosition); |
243 | main->cd(canvasPosition); |
||
38 | f9daq | 244 | gPad->SetMargin(0.08, 0.08, 0.08, 0.08); |
35 | f9daq | 245 | char name[128]; |
246 | sprintf(name,"Channel %d",channel); |
||
247 | h_projection->SetTitle(name); |
||
38 | f9daq | 248 | h_projection->GetYaxis()->SetRangeUser(0,10000); |
249 | h_projection->DrawCopy("pe1x0"); |
||
250 | canvas11->cd(); |
||
251 | if (canvasPosition == 1) { |
||
252 | h_projection->SetMarkerStyle(kFullDotMedium); |
||
253 | h_projection->GetYaxis()->SetRangeUser(0,10000); |
||
254 | h_projection->DrawCopy("Pl"); |
||
255 | } |
||
256 | else { |
||
257 | h_projection->SetMarkerStyle(kFullDotMedium); |
||
258 | h_projection->SetLineColor(canvasPosition); |
||
259 | h_projection->SetMarkerColor(canvasPosition); |
||
260 | h_projection->SetTitle(""); |
||
261 | h_projection->DrawCopy("plsame"); |
||
262 | } |
||
35 | f9daq | 263 | } |
38 | f9daq | 264 | |
35 | f9daq | 265 | } |
266 | printf("\n"); |
||
267 | } |
||
268 | |||
36 | f9daq | 269 | if(strstr(plopt, "1ch") != NULL) |
270 | { |
||
271 | TH2F* h_bias = (TH2F*) rootfile->Get("h_bias"); |
||
38 | f9daq | 272 | TCanvas* canvas = new TCanvas("canvas","",800,800); |
36 | f9daq | 273 | canvas->cd(); |
274 | int channel = map[chXstart][chXend]; |
||
275 | TH1D* h_projection = h_bias->ProjectionY("",channel+1,channel+1); |
||
276 | char name[128]; |
||
277 | sprintf(name,"Channel %d",channel); |
||
278 | h_projection->SetTitle(name); |
||
38 | f9daq | 279 | h_projection->SetMarkerStyle(kFullDotMedium); |
280 | //h_projection->SetMarkerSize(8); |
||
281 | gPad->SetMargin(0.1,0.1,0.1,0.1); |
||
40 | f9daq | 282 | |
283 | |||
284 | TF1* f_linear = new TF1("f_linear", "[0] + [1]*x", par1, par2); |
||
285 | f_linear->SetParameter(0, -1); |
||
286 | f_linear->SetParameter(1, 0.1); |
||
287 | f_linear->SetParNames("p0", "p1"); |
||
288 | h_projection->Fit(f_linear,"q"); |
||
289 | h_projection->Fit(f_linear,"r"); |
||
38 | f9daq | 290 | h_projection->Draw("pe1x0"); |
40 | f9daq | 291 | |
292 | double p0 = f_linear->GetParameter(0); |
||
293 | double p1 = f_linear->GetParameter(1); |
||
294 | printf("p0 %f p1 %f V_b = %f [V]\n", p0, p1, -p0/p1); |
||
295 | TPaveText *text = new TPaveText(0.15,0.5,0.35,0.56); |
||
296 | text->SetFillColor(0); |
||
297 | text->SetBorderSize(0.1); |
||
298 | text->SetTextSize(0.030); |
||
299 | char string[128]; |
||
300 | sprintf(string, "V_b = %2.2f", -p0/p1); |
||
301 | text->AddText(string); |
||
302 | text->Draw("same"); |
||
303 | text->Paint(); |
||
36 | f9daq | 304 | } |
305 | |||
35 | f9daq | 306 | if( strstr(plopt, "all") != NULL ) { |
307 | TCanvas *canvas2 = new TCanvas("canvas2","Hits x;;",2000,2000); |
||
308 | TCanvas *canvas3 = new TCanvas("canvas3","Hits y;;",2000,2000); |
||
309 | canvas2->Divide(8,8); |
||
310 | canvas3->Divide(8,8); |
||
311 | TH1F* h_hitsx; |
||
312 | TH1F* h_hitsy; |
||
313 | for(int i=0; i<c_nChannels; i++) { |
||
314 | canvas2->cd(i+1); |
||
315 | char hname[128]; |
||
316 | sprintf(hname, "hnhitsx%d", i); |
||
317 | h_hitsx = (TH1F*)rootfile->Get(hname); |
||
318 | h_hitsx->Draw(); |
||
319 | canvas3->cd(i+1); |
||
320 | sprintf(hname, "hnhitsy%d", i); |
||
321 | h_hitsy = (TH1F*)rootfile->Get(hname); |
||
322 | h_hitsy->Draw(); |
||
323 | } |
||
324 | } |
||
325 | |||
326 | if( strstr(plopt, "x") != NULL ) { |
||
327 | TCanvas *canvas10 = new TCanvas("canvas10","Ch x;;",500,500); |
||
328 | TH1F* h_hitsx; |
||
329 | canvas10->cd(); |
||
330 | char hname[128]; |
||
331 | sprintf(hname, "hnhitsx%d", chXstart); |
||
332 | h_hitsx = (TH1F*)rootfile->Get(hname); |
||
333 | h_hitsx->Draw("colz"); |
||
334 | } |
||
335 | |||
336 | if( strstr(plopt, "y") != NULL ) { |
||
337 | TCanvas *canvas11 = new TCanvas("canvas11","Ch x;;",500,500); |
||
338 | TH1F* h_hitsy; |
||
339 | canvas11->cd(); |
||
340 | char hname[128]; |
||
341 | sprintf(hname, "hnhitsy%d", chXstart); |
||
342 | h_hitsy = (TH1F*)rootfile->Get(hname); |
||
343 | h_hitsy->Draw(); |
||
344 | } |
||
40 | f9daq | 345 | |
35 | f9daq | 346 | |
347 | /** Draws the sum of the channels |
||
348 | * Each channel is a 2d plot |
||
349 | * Intended for the study of 1 channel |
||
350 | */ |
||
351 | if (strstr(plopt, "2d") != NULL) { |
||
352 | |||
353 | int nX = chXend - chXstart + 1; |
||
40 | f9daq | 354 | int nY = (int)par2 - (int)par1 + 1; |
35 | f9daq | 355 | TCanvas* canvas7 = new TCanvas("canvas7","canvas7", nX*400,nY*400); |
356 | printf("nx %d ny %d\n",nX,nY); |
||
357 | canvas7->Divide(nX,nY); |
||
40 | f9daq | 358 | for(int i=(int)par1; i<=(int)par2; i++) { |
35 | f9daq | 359 | for(int j=chXstart; j<=chXend; j++) { |
360 | //int canvasPosition = nX*(i-chYstart)+(j-chXstart)+1; |
||
40 | f9daq | 361 | int canvasPosition = nX*((int)par2-i)+(j-chXstart)+1; |
35 | f9daq | 362 | if (debug) printf("canvas %d\n",canvasPosition); |
363 | canvas7->cd(canvasPosition); |
||
364 | char hname[128]; |
||
365 | int chPosition = map[j][i]; |
||
366 | sprintf(hname, "h2d%d", chPosition); |
||
367 | TH2F* h_2d = (TH2F*)rootfile->Get(hname); |
||
368 | h_2d->Draw("colz"); |
||
369 | } //x |
||
370 | } |
||
371 | |||
372 | // Number of photoelectrons - Poissonian correction |
||
373 | TCanvas* canvas8 = new TCanvas("canvas8","canvas8", 1000,1000); |
||
374 | canvas8->cd(); |
||
375 | gStyle->SetOptStat(0); |
||
376 | char hname[128]; |
||
377 | int chPosition = map[1][2]; |
||
378 | sprintf(hname, "h2d%d", chPosition); |
||
379 | TH2F* h_2d = (TH2F*)rootfile->Get(hname); |
||
380 | |||
381 | Int_t binsX = h_2d->GetXaxis()->GetNbins(); |
||
382 | Int_t minX = h_2d->GetXaxis()->GetFirst(); |
||
383 | Int_t maxX = h_2d->GetXaxis()->GetLast()+1; |
||
384 | Int_t binsY = h_2d->GetYaxis()->GetNbins(); |
||
385 | Int_t minY = h_2d->GetYaxis()->GetFirst(); |
||
386 | Int_t maxY = h_2d->GetYaxis()->GetLast()+1; |
||
387 | Double_t xLowUser = h_2d->GetXaxis()->GetBinLowEdge(minX); |
||
388 | Double_t xUpUser = h_2d->GetXaxis()->GetBinUpEdge(maxX); |
||
389 | Double_t yLowUser = h_2d->GetYaxis()->GetBinLowEdge(minY); |
||
390 | Double_t yUpUser = h_2d->GetYaxis()->GetBinUpEdge(maxY); |
||
391 | if (debug) printf("xLow %f xUp %f\n",xLowUser,xUpUser); |
||
392 | TH2F* h_corrected = new TH2F("h_corrected","h_corrected",binsX, xLowUser, xUpUser, binsY, yLowUser, yUpUser); |
||
393 | |||
394 | double noise = getNoise(h_2d, 1, 89); |
||
395 | if(debug) printf("Noise = %f\n", noise); |
||
396 | for(int k=minX; k<=maxX; k++) { |
||
397 | for(int j=minY; j<=maxY; j++) { |
||
398 | double signal = h_2d->GetBinContent(k,j); // detected |
||
399 | //double p = ((signal - noise) > 1) ? (signal-noise) : 1; |
||
400 | double p = signal - noise; |
||
401 | p /= 10000.; |
||
402 | double p0 = 1.0 - p; // events with zero photons |
||
403 | //double eta = (-log(p0) * p0 ) / (1-p0-0.00001); |
||
404 | double eta = -log(p0); // constant of the poissonian statistics |
||
405 | if (debug) printf("p=%f p0=%f log(p0)=%f eta=%f\n",p,p0,log(p0),eta); |
||
406 | double x = k*(xUpUser-xLowUser)/double(binsX); |
||
407 | double y = j*(yUpUser-yLowUser)/double(binsY); |
||
408 | h_corrected->Fill(x+3,y+8, eta); |
||
409 | } |
||
410 | } |
||
411 | h_corrected->SetTitle("n_pe = - ln P(0);x[mm];y[mm]"); |
||
412 | h_corrected->GetZaxis()->SetRangeUser(-0.05,0.3); |
||
413 | h_corrected->Draw("colz"); |
||
414 | |||
415 | // collection efficiency |
||
416 | int nPoints =0; |
||
417 | double efficiency=0; |
||
418 | for (int i=18; i<=58; i++) { |
||
419 | for (int j=19; j<=59; j++) { |
||
420 | double signal = h_corrected->GetBinContent(i,j); |
||
421 | if(debug) printf("signal %f\n",signal); |
||
422 | efficiency += signal; |
||
423 | nPoints++; |
||
424 | } |
||
425 | } |
||
426 | printf("Signal sum = %f\n # of points = %d\n",efficiency,nPoints); |
||
427 | } |
||
428 | |||
429 | /** Draws the sum of channel signals |
||
430 | * Each channel is a 2d ('h2d') histogram |
||
431 | * Suitable for 8x8 chs scan |
||
432 | */ |
||
433 | if( strstr(plopt, "sum") != NULL ) { |
||
40 | f9daq | 434 | int nX = 7 - 0 + 1; |
435 | int nY = 7 - 0 + 1; |
||
35 | f9daq | 436 | TCanvas* canvas12 = new TCanvas("canvas12","c2",8*200, 8*200); |
437 | canvas12->cd(); |
||
438 | gStyle->SetOptStat(0); |
||
439 | |||
440 | // final histogram parameters |
||
441 | TH2F* h0 = (TH2F*) rootfile->Get("h2d0"); |
||
442 | Int_t binsX = h0->GetXaxis()->GetNbins(); |
||
443 | Int_t minX = h0->GetXaxis()->GetFirst(); |
||
444 | Int_t maxX = h0->GetXaxis()->GetLast()+1; |
||
445 | Int_t binsY = h0->GetYaxis()->GetNbins(); |
||
446 | Int_t minY = h0->GetYaxis()->GetFirst(); |
||
447 | Int_t maxY = h0->GetYaxis()->GetLast()+1; |
||
448 | Double_t xLowUser = h0->GetXaxis()->GetBinLowEdge(minX); |
||
449 | Double_t xUpUser = h0->GetXaxis()->GetBinUpEdge(maxX); |
||
450 | Double_t yLowUser = h0->GetYaxis()->GetBinLowEdge(minY); |
||
451 | Double_t yUpUser = h0->GetYaxis()->GetBinUpEdge(maxY); |
||
452 | if (debug) printf("xLow %f xUp %f\n",xLowUser,xUpUser); |
||
453 | TH2F* h_corrected = new TH2F("h_corrected","h_corrected",binsX,xLowUser,xUpUser, binsY,yLowUser,yUpUser); |
||
454 | TH2F* h[9]; |
||
455 | |||
456 | // 2d histogram noise subtraction and poisson scaling |
||
40 | f9daq | 457 | for(int i=0; i<=7; i++) { |
35 | f9daq | 458 | for(int j=chXstart; j<=chXend; j++) { |
459 | int chPosition = map[j][i]; |
||
460 | char hname[128]; |
||
461 | sprintf(hname, "h2d%d", chPosition); |
||
40 | f9daq | 462 | int histogram = nX*(i-0)+(j-chXstart); |
35 | f9daq | 463 | h[histogram] = (TH2F *) rootfile->Get(hname); |
464 | int noise = getNoise(h[histogram], 1, 170); |
||
465 | if (debug) printf("noise: %d\n",noise); |
||
466 | for(int k=minX; k<=maxX; k++) { |
||
467 | for(int l=minY; l<=maxY; l++) { |
||
468 | int signal = h[histogram]->GetBinContent(k,l); // detected |
||
469 | //double p = ((signal - noise) > 0.1) ? (signal-noise) : 0.1; |
||
470 | double p = signal - noise; |
||
471 | p /= 10000.; |
||
472 | double p0 = 1.0 - p; // events with zero photons |
||
473 | //double eta = (-log(p0) * p0 ) / (1-p0-0.00001); |
||
474 | double eta = -log(p0); |
||
475 | //printf("p=%f p0=%f log(p0)=%f eta=%f\n",p,p0,log(p0),eta); |
||
476 | double x = k*(xUpUser-xLowUser)/double(binsX); |
||
477 | double y = l*(yUpUser-yLowUser)/double(binsY); |
||
478 | h_corrected->Fill(x-c_xOffset, y-c_yOffset, signal); |
||
479 | } |
||
480 | } |
||
481 | |||
482 | } |
||
483 | } |
||
484 | |||
485 | h_corrected->SetTitle("SiPM#2 n_p.e.;x[mm];y[mm]"); |
||
486 | //h_corrected->GetZaxis()->SetRangeUser(-0.05,.30); |
||
487 | h_corrected->Draw("colz"); |
||
488 | |||
489 | TCanvas* canvas13 = new TCanvas("canvas13","canvas13",600,300); |
||
490 | canvas13->Divide(2); |
||
491 | canvas13->cd(1); |
||
492 | //h[16]->Draw("colz"); |
||
493 | canvas13->cd(2); |
||
494 | //h[8]->Draw("colz"); |
||
495 | } |
||
496 | |||
497 | return(0); |
||
498 | } |
||
499 | |||
500 | /** Function calculates the noise from one channel |
||
501 | * it runs through the bins along x and returns the average value |
||
502 | */ |
||
503 | double getNoise(TH2F* histogram, int yStart, int yEnd) |
||
504 | { |
||
505 | double noise=0; |
||
506 | int count=0; |
||
507 | for(int j=yStart; j<yEnd; j++) { |
||
508 | double value = histogram->GetBinContent(j,2); |
||
509 | //if (noise < value) noise = value; |
||
510 | noise += value; |
||
511 | count++; |
||
512 | } |
||
513 | return (noise/double(count)); |
||
514 | } |
||
515 |