Subversion Repositories f9daq

Rev

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