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