Subversion Repositories f9daq

Rev

Rev 38 | Rev 50 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 38 Rev 40
Line 10... Line 10...
10
#include "TF1.h"
10
#include "TF1.h"
11
#include "TGraph.h"
11
#include "TGraph.h"
12
#include "TSpectrum.h"
12
#include "TSpectrum.h"
13
#include "stdio.h"
13
#include "stdio.h"
14
#include "THStack.h"
14
#include "THStack.h"
-
 
15
#include "TPaveText.h"
15
 
16
 
16
#include "include/RTUtil.h"
17
#include "include/RTUtil.h"
17
 
18
 
18
double getNoise(TH2F*, int, int);
19
double getNoise(TH2F*, int, int);
19
 
20
 
20
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)
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)
21
{
22
{
22
  const int c_nChannels = 64;
23
  const int c_nChannels = 64;
23
  const double c_xOffset = 1; // mm
24
  const double c_xOffset = 0; // mm
24
  const double c_yOffset = 0.7;
25
  const double c_yOffset = 0;
25
 
26
 
26
  int map[8][8]={{32,34,53,55,40,42,61,63},
27
  int map[8][8]={{32,34,53,55,40,42,61,63},
27
                 {48,50,37,39,56,58,45,47},
28
                 {48,50,37,39,56,58,45,47},
28
                 {33,35,52,54,41,43,60,62},
29
                 {33,35,52,54,41,43,60,62},
29
                 {49,51,36,38,57,59,44,46},
30
                 {49,51,36,38,57,59,44,46},
Line 72... Line 73...
72
    //h0->Project3D("yz")->Draw("colz");
73
    //h0->Project3D("yz")->Draw("colz");
73
    //canvas21->cd(3);
74
    //canvas21->cd(3);
74
    TH2D* h_correctedTDC = (TH2D*) h0->Project3D("xz");
75
    TH2D* h_correctedTDC = (TH2D*) h0->Project3D("xz");
75
    //h0->GetZaxis()->SetRangeUser(-5,5);
76
    //h0->GetZaxis()->SetRangeUser(-5,5);
76
    //h0->Project3D("xzo")->Draw("colz");
77
    //h0->Project3D("xzo")->Draw("colz");
77
    h_correctedTDC->SetTitle("; t [ns]; Channel");
78
    //h_correctedTDC->SetTitle("; t [ns]; Channel");
78
    h_correctedTDC->Draw("colz");
79
    h_correctedTDC->Draw("colz");
79
    /*
80
    /*
80
    TH1F* tdc1 = new TH1F("tdc1",";TDC [ns];Events",binsZ, minZ, maxZ);
81
    TH1F* tdc1 = new TH1F("tdc1",";TDC [ns];Events",binsZ, minZ, maxZ);
81
    //for(int j=minY; j<maxY; j++) {
82
    //for(int j=minY; j<maxY; j++) {
82
      for(int k=minZ; k<maxZ; k++) {
83
      for(int k=minZ; k<maxZ; k++) {
Line 87... Line 88...
87
    tdc1->Draw();
88
    tdc1->Draw();
88
    */
89
    */
89
   
90
   
90
    TH2D* h_timeWalk = (TH2D*) h0->Project3D("zy");
91
    TH2D* h_timeWalk = (TH2D*) h0->Project3D("zy");
91
    canvas21->cd(2);
92
    canvas21->cd(2);
92
    h_timeWalk->SetTitle(";Threshold [V]; t [ns]");
93
    //h_timeWalk->SetTitle(";Threshold [V]; t [ns]");
93
    h_timeWalk->Draw("colz");
94
    h_timeWalk->Draw("colz");
94
  }
95
  }
95
 
96
 
96
  if (strstr(plopt, "bias") != NULL) {
97
  if (strstr(plopt, "bias") != NULL) {
97
    TCanvas* canvas01 = new TCanvas("canvas01","",800, 800);
98
    TCanvas* canvas01 = new TCanvas("canvas01","",800, 800);
Line 135... Line 136...
135
  TVirtualPad *main = new TPad("main","main",0,0,1,1,10,1);
136
  TVirtualPad *main = new TPad("main","main",0,0,1,1,10,1);
136
  main->Draw();
137
  main->Draw();
137
  main->cd();
138
  main->cd();
138
  main->Divide(4,4);
139
  main->Divide(4,4);
139
  for(int i=chXstart; i<chXend; i++) {
140
  for(int i=chXstart; i<chXend; i++) {
140
    for(int j=chYstart; j<chYend; j++) {
141
    for(int j=(int)par1; j<(int)par2; j++) {
141
      int channel = map[i][j];
142
      int channel = map[i][j];
142
      TH1D* h_projection = h_threshold->ProjectionY("",channel+1,channel+1);
143
      TH1D* h_projection = h_threshold->ProjectionY("",channel+1,channel+1);
143
      int canvasPosition = i-chXend+4*(chYend-j)+1;
144
      int canvasPosition = i-chXend+4*((int)par2-j)+1;
144
      printf(" %d ", canvasPosition);
145
      printf(" %d ", canvasPosition);
145
      main->cd(canvasPosition);
146
      main->cd(canvasPosition);
146
      gPad->SetMargin(0.08, 0.08, 0.08, 0.08);
147
      gPad->SetMargin(0.08, 0.08, 0.08, 0.08);
147
      char name[128];
148
      char name[128];
148
      sprintf(name,"Channel %d",channel);
149
      sprintf(name,"Channel %d",channel);
Line 179... Line 180...
179
    sprintf(name,"Channel %d",channel);
180
    sprintf(name,"Channel %d",channel);
180
    h_projection->SetTitle(name);
181
    h_projection->SetTitle(name);
181
    h_projection->SetMarkerStyle(kFullDotMedium);
182
    h_projection->SetMarkerStyle(kFullDotMedium);
182
    //h_projection->SetMarkerSize(8);
183
    //h_projection->SetMarkerSize(8);
183
    gPad->SetMargin(0.1,0.1,0.1,0.1);
184
    gPad->SetMargin(0.1,0.1,0.1,0.1);
-
 
185
   
-
 
186
   
-
 
187
    TF1* f_linear = new TF1("f_linear", "[0] + [1]*x", par1, par2);
-
 
188
    f_linear->SetParameter(0, -1);
-
 
189
    f_linear->SetParameter(1, 0.1);
-
 
190
    f_linear->SetParNames("p0", "p1");
-
 
191
    h_projection->Fit(f_linear,"q");
-
 
192
    h_projection->Fit(f_linear,"r");
184
    h_projection->Draw("pe1x0");
193
    h_projection->Draw("pe1x0");
-
 
194
   
-
 
195
    double p0 = f_linear->GetParameter(0);
-
 
196
    double p1 = f_linear->GetParameter(1);
-
 
197
    printf("p0 %f p1 %f V_b = %f [V]\n", p0, p1, -p0/p1);
-
 
198
    TPaveText *text = new TPaveText(0.15,0.5,0.35,0.56);
-
 
199
    text->SetFillColor(0);
-
 
200
    text->SetBorderSize(0.1);
-
 
201
    text->SetTextSize(0.030);
-
 
202
    char string[128];
-
 
203
    sprintf(string, "V_b = %2.2f", -p0/p1);
-
 
204
    text->AddText(string);
-
 
205
    text->Draw("same");
-
 
206
    text->Paint();
185
  }
207
  }
186
 
208
 
187
  if( strstr(plopt, "all") != NULL ) {
209
  if( strstr(plopt, "all") != NULL ) {
188
    TCanvas *canvas2 = new TCanvas("canvas2","Hits x;;",2000,2000);
210
    TCanvas *canvas2 = new TCanvas("canvas2","Hits x;;",2000,2000);
189
    TCanvas *canvas3 = new TCanvas("canvas3","Hits y;;",2000,2000);
211
    TCanvas *canvas3 = new TCanvas("canvas3","Hits y;;",2000,2000);
Line 221... Line 243...
221
    char hname[128];
243
    char hname[128];
222
    sprintf(hname, "hnhitsy%d", chXstart);
244
    sprintf(hname, "hnhitsy%d", chXstart);
223
    h_hitsy = (TH1F*)rootfile->Get(hname);
245
    h_hitsy = (TH1F*)rootfile->Get(hname);
224
    h_hitsy->Draw();
246
    h_hitsy->Draw();
225
  }
247
  }
226
 
-
 
227
  if( strstr(plopt, "share") != NULL ) {
-
 
228
   /*TCanvas *canvas4 = new TCanvas("canvas1","canvas1",1000,1000);
-
 
229
   int nChannels = chYend-chYstart+1;
-
 
230
   int ncols = nChannels/2;
-
 
231
   printf("nch %d nch\\2 %d\n", nChannels, ncols);
-
 
232
   canvas4->Divide(2,ncols);
-
 
233
   TH1F* h_hitsy;
-
 
234
   for(int i=chYstart; i<=chYend; i++){
-
 
235
     canvas4->cd(i-chYstart+1);
-
 
236
     char hname[128];
-
 
237
     int chPosition = map[0][i];
-
 
238
     sprintf(hname, "hnhitsy%d", chPosition);
-
 
239
     h_hitsy = (TH1F*)rootfile->Get(hname);
-
 
240
     h_hitsy->Draw();
-
 
241
   }*/
-
 
242
   
-
 
243
   TCanvas *canvas4 = new TCanvas("canvas4","canvas4",500,500);
-
 
244
   canvas4->cd();
-
 
245
   for(int i=chXstart; i<=chXend; i++) {
-
 
246
     TH1F* h_hitsx;
-
 
247
     char hname[128];
-
 
248
     int chPosition = map[i][chYstart];
-
 
249
     sprintf(hname, "hnhitsx%d", chPosition);
-
 
250
     h_hitsx = (TH1F*)rootfile->Get(hname);
-
 
251
     h_hitsx->SetTitle("Scan X;x [mm]; Entries");
-
 
252
     h_hitsx->GetYaxis()->SetTitleOffset(1.3);
-
 
253
     h_hitsx->SetStats(0);
-
 
254
     if (i == chXstart)
-
 
255
      h_hitsx->Draw();
-
 
256
     else {
-
 
257
      h_hitsx->SetLineColor(i+1);
-
 
258
      h_hitsx->Draw("same");
-
 
259
     }
-
 
260
   }
-
 
261
   //sprintf(fullname, "ps/%s_Yshare.eps", filename);
-
 
262
         //canvas4->SaveAs(fullname);
-
 
263
   
-
 
264
   TCanvas *canvas5 = new TCanvas("canvas5","canvas5",500,500);
-
 
265
   canvas5->cd();
-
 
266
   for(int i=chYstart; i<=chYend; i++) {
-
 
267
     TH1F* h_hitsy;
-
 
268
     char hname[128];
-
 
269
     int chPosition = map[chXstart][i];
-
 
270
     sprintf(hname, "hnhitsy%d", chPosition);
-
 
271
     h_hitsy = (TH1F*)rootfile->Get(hname);
-
 
272
     h_hitsy->SetTitle("Scan Y;y [mm]; Entries");
-
 
273
     h_hitsy->GetYaxis()->SetTitleOffset(1.3);
-
 
274
     h_hitsy->SetStats(0);
-
 
275
     if (i == chYstart)
-
 
276
      h_hitsy->Draw();
-
 
277
     else {
-
 
278
      h_hitsy->SetLineColor(i+1);
-
 
279
      h_hitsy->Draw("same");
-
 
280
     }
-
 
281
   }
-
 
282
   //sprintf(fullname, "ps/%s_Yshare.eps", filename);
-
 
283
         //canvas5->SaveAs(fullname);
-
 
284
  }
-
 
285
 
248
 
286
  /** Draws the signal from 8 channels in x-row
-
 
287
    * for one specific y bin, so the background and cross-talk
-
 
288
    * can be estimated.
-
 
289
    * Draws also a 2d scan of these channels.
-
 
290
    */
-
 
291
  if (strstr(plopt, "line") != NULL) {
-
 
292
    TCanvas* canvas6 = new TCanvas("canvas6","canvas6",500,500);
-
 
293
    canvas6->cd(0);
-
 
294
    gStyle->SetOptStat(0);
-
 
295
   
-
 
296
    TH2F* h0 = (TH2F*) rootfile->Get("h2d0");
-
 
297
          Int_t binsX = h0->GetXaxis()->GetNbins();
-
 
298
    Int_t minX  = h0->GetXaxis()->GetFirst();
-
 
299
    Int_t maxX  = h0->GetXaxis()->GetLast()+1;
-
 
300
    Int_t binsY = h0->GetYaxis()->GetNbins();
-
 
301
    Int_t minY  = h0->GetYaxis()->GetFirst();
-
 
302
    Int_t maxY  = h0->GetYaxis()->GetLast()+1;
-
 
303
    Double_t xLowUser  = h0->GetXaxis()->GetBinLowEdge(minX);
-
 
304
    Double_t xUpUser = h0->GetXaxis()->GetBinUpEdge(maxX);
-
 
305
    Double_t yLowUser  = h0->GetYaxis()->GetBinLowEdge(minY);
-
 
306
    Double_t yUpUser = h0->GetYaxis()->GetBinUpEdge(maxY);
-
 
307
    if (debug) printf("xLow %f xUp %f\n",xLowUser,xUpUser);
-
 
308
   
-
 
309
    //! 1-dimension position in x vs. hits
-
 
310
    TH2F* h[8];
-
 
311
    TH1F* h_line[8];
-
 
312
    for(int j=0; j<8; j++) {
-
 
313
      h_line[j] = new TH1F("h_line", "h_line", binsX, xLowUser, xUpUser);
-
 
314
    }
-
 
315
   
-
 
316
    for(int j=chXstart; j<=chXend; j++) {
-
 
317
      int chPosition = map[j][chYstart];
-
 
318
      char hname[128];
-
 
319
      sprintf(hname, "h2d%d", chPosition);  
-
 
320
      int histogram = j;
-
 
321
      h[histogram] = (TH2F *) rootfile->Get(hname);
-
 
322
      int noise = getNoise(h[histogram], 1, 160);
-
 
323
      for(int k=minX; k<=maxX; k++) {
-
 
324
        int l=chYstart*20+12;
-
 
325
        //for(int l=12; l<=16; l++) {
-
 
326
          double signal = h[histogram]->GetBinContent(k,l);
-
 
327
          //signal -= noise;
-
 
328
          //signal /= 5*10000.0;
-
 
329
          double eta = -log(1 - signal);
-
 
330
          double x = k*(xUpUser-xLowUser)/double(binsX);
-
 
331
          //double y = l*(yUpUser-yLowUser)/double(binsY);
-
 
332
          h_line[j]->Fill(x-c_xOffset, signal);
-
 
333
        //}
-
 
334
      }
-
 
335
      if (j == chXstart) {
-
 
336
        h_line[j]->SetTitle("SiPM#2 w/o noise subtraction;x[mm];Hits");
-
 
337
        //h_line[j]->GetYaxis()->SetRangeUser(-0.05, 0.3);
-
 
338
        //h_line[j]->GetYaxis()->SetRangeUser(-50, 2500);
-
 
339
        h_line[j]->Draw("");
-
 
340
      }
-
 
341
      else {
-
 
342
        h_line[j]->SetLineColor(j+1);
-
 
343
        h_line[j]->Draw("same");
-
 
344
      }
-
 
345
    }
-
 
346
   
-
 
347
   
-
 
348
    //! 2d scan
-
 
349
    TCanvas* canvas61 = new TCanvas("canvas61","canvas61",8*200,300);
-
 
350
    canvas61->cd();
-
 
351
    TH2F* h_corrected = new TH2F("h_corrected","h_corrected",binsX,xLowUser,xUpUser, binsY,yLowUser,yUpUser);
-
 
352
    for(int i=chXstart; i<=chXend; i++) {
-
 
353
      //int canvasPosition = nX*(i-chYstart)+(j-chXstart)+1;
-
 
354
      //int canvasPosition = nX*(chYend-i)+chXstart+1;
-
 
355
      //if (debug) printf("canvas %d\n",canvasPosition);
-
 
356
        int chPosition = map[i][chYstart];
-
 
357
        char hname[128];
-
 
358
              sprintf(hname, "h2d%d", chPosition);  
-
 
359
              int histogram = i;
-
 
360
              h[histogram] = (TH2F *) rootfile->Get(hname);
-
 
361
              int noise = getNoise(h[histogram], 1, 100);
-
 
362
             
-
 
363
              for(int k=minX; k<=maxX; k++) {
-
 
364
          for(int l=minY; l<=maxY; l++) {
-
 
365
            int signal = h[histogram]->GetBinContent(k,l); // detected
-
 
366
            //p /= 10000.;
-
 
367
            //double p0 = 1.0 - p; // events with zero photons
-
 
368
            //double eta = (-log(p0) * p0 ) / (1-p0-0.00001);
-
 
369
            //double eta = -log(p0);
-
 
370
            //printf("p=%f p0=%f log(p0)=%f eta=%f\n",p,p0,log(p0),eta);      
-
 
371
            //double signal = ((p - noise) > 0.1) ? (p-noise) : 0.1;
-
 
372
            double p = signal - noise;
-
 
373
            p /= 10000.0;
-
 
374
            double eta = -log(1 - p);
-
 
375
            double x = k*(xUpUser-xLowUser)/double(binsX);
-
 
376
            double y = l*(yUpUser-yLowUser)/double(binsY);
-
 
377
            h_corrected->Fill(x-c_xOffset, y-c_yOffset, eta);
-
 
378
          }
-
 
379
        }
-
 
380
    }
-
 
381
    h_corrected->SetTitle("SiPM#2 n_pe = - ln(P0);x[mm];y[mm]");
-
 
382
    h_corrected->GetZaxis()->SetRangeUser(-0.05,0.30);
-
 
383
    h_corrected->Draw("colz");
-
 
384
   
-
 
385
  }
-
 
386
 
249
 
387
  /** Draws the sum of the channels
250
  /** Draws the sum of the channels
388
    * Each channel is a 2d plot
251
    * Each channel is a 2d plot
389
    * Intended for the study of 1 channel
252
    * Intended for the study of 1 channel
390
    */
253
    */
391
  if (strstr(plopt, "2d") != NULL) {
254
  if (strstr(plopt, "2d") != NULL) {
392
   
255
   
393
    int nX = chXend - chXstart + 1;
256
    int nX = chXend - chXstart + 1;
394
    int nY = chYend - chYstart + 1;
257
    int nY = (int)par2 - (int)par1 + 1;
395
    TCanvas* canvas7 = new TCanvas("canvas7","canvas7", nX*400,nY*400);
258
    TCanvas* canvas7 = new TCanvas("canvas7","canvas7", nX*400,nY*400);
396
    printf("nx %d ny %d\n",nX,nY);
259
    printf("nx %d ny %d\n",nX,nY);
397
    canvas7->Divide(nX,nY);
260
    canvas7->Divide(nX,nY);
398
    for(int i=chYstart; i<=chYend; i++) {
261
    for(int i=(int)par1; i<=(int)par2; i++) {
399
      for(int j=chXstart; j<=chXend; j++) {
262
      for(int j=chXstart; j<=chXend; j++) {
400
      //int canvasPosition = nX*(i-chYstart)+(j-chXstart)+1;
263
      //int canvasPosition = nX*(i-chYstart)+(j-chXstart)+1;
401
      int canvasPosition = nX*(chYend-i)+(j-chXstart)+1;
264
      int canvasPosition = nX*((int)par2-i)+(j-chXstart)+1;
402
      if (debug) printf("canvas %d\n",canvasPosition);
265
      if (debug) printf("canvas %d\n",canvasPosition);
403
        canvas7->cd(canvasPosition);
266
        canvas7->cd(canvasPosition);
404
        char hname[128];
267
        char hname[128];
405
        int chPosition = map[j][i];
268
        int chPosition = map[j][i];
406
        sprintf(hname, "h2d%d", chPosition);
269
        sprintf(hname, "h2d%d", chPosition);
Line 469... Line 332...
469
  /** Draws the sum of channel signals
332
  /** Draws the sum of channel signals
470
    * Each channel is a 2d ('h2d') histogram
333
    * Each channel is a 2d ('h2d') histogram
471
    * Suitable for 8x8 chs scan
334
    * Suitable for 8x8 chs scan
472
    */
335
    */
473
  if( strstr(plopt, "sum") != NULL ) {
336
  if( strstr(plopt, "sum") != NULL ) {
474
    int nX = chXend - chXstart + 1;
337
    int nX = 7 - 0 + 1;
475
    int nY = chYend - chYstart + 1;
338
    int nY = 7 - 0 + 1;
476
          TCanvas* canvas12 = new TCanvas("canvas12","c2",8*200, 8*200);
339
          TCanvas* canvas12 = new TCanvas("canvas12","c2",8*200, 8*200);
477
          canvas12->cd();
340
          canvas12->cd();
478
          gStyle->SetOptStat(0);
341
          gStyle->SetOptStat(0);
479
 
342
 
480
    // final histogram parameters
343
    // final histogram parameters
Line 492... Line 355...
492
    if (debug) printf("xLow %f xUp %f\n",xLowUser,xUpUser);
355
    if (debug) printf("xLow %f xUp %f\n",xLowUser,xUpUser);
493
    TH2F* h_corrected = new TH2F("h_corrected","h_corrected",binsX,xLowUser,xUpUser, binsY,yLowUser,yUpUser);
356
    TH2F* h_corrected = new TH2F("h_corrected","h_corrected",binsX,xLowUser,xUpUser, binsY,yLowUser,yUpUser);
494
    TH2F* h[9];
357
    TH2F* h[9];
495
   
358
   
496
    // 2d histogram noise subtraction and poisson scaling
359
    // 2d histogram noise subtraction and poisson scaling
497
    for(int i=chYstart; i<=chYend; i++) {
360
    for(int i=0; i<=7; i++) {
498
      for(int j=chXstart; j<=chXend; j++) {
361
      for(int j=chXstart; j<=chXend; j++) {
499
        int chPosition = map[j][i];
362
        int chPosition = map[j][i];
500
        char hname[128];
363
        char hname[128];
501
              sprintf(hname, "h2d%d", chPosition);  
364
              sprintf(hname, "h2d%d", chPosition);  
502
              int histogram = nX*(i-chYstart)+(j-chXstart);
365
              int histogram = nX*(i-0)+(j-chXstart);
503
              h[histogram] = (TH2F *) rootfile->Get(hname);
366
              h[histogram] = (TH2F *) rootfile->Get(hname);
504
              int noise = getNoise(h[histogram], 1, 170);
367
              int noise = getNoise(h[histogram], 1, 170);
505
              if (debug) printf("noise: %d\n",noise);
368
              if (debug) printf("noise: %d\n",noise);
506
              for(int k=minX; k<=maxX; k++) {
369
              for(int k=minX; k<=maxX; k++) {
507
          for(int l=minY; l<=maxY; l++) {
370
          for(int l=minY; l<=maxY; l++) {