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