Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
326 f9daq 1
#include <stdio.h>
2
#include <stdlib.h>
3
 
4
#include <TROOT.h>
5
#include <TH1D.h>
6
#include <TH1F.h>
7
#include <TH2D.h>
8
#include <TH2F.h>
9
#include <TH2I.h>
10
#include <TNtuple.h>
11
#include <TTree.h>
12
#include <TGraph.h>
13
#include <TGraphErrors.h>
14
#include <TCanvas.h>
15
#include <TStyle.h>
16
#include <TSystem.h>
17
#include <TFile.h>
18
#include <TDirectory.h>
19
#include <TPaveText.h>
20
#include <TSpectrum.h>
21
#include <TF1.h>
22
#include <TColor.h>
23
#include <algorithm>
24
using namespace std;
25
 
26
#include <iostream>
27
#include <string>
28
 
29
#include "base.h"
30
#include "gain.h"
31
#include "savetoroot.h"
32
 
33
int charge(int runNumber, int save){
34
 
35
  int HAPDnumber; //Number of HAPD: 0, 1, 2 or 3!
36
 
37
  double xmin = -50;
38
  double xmax = 300;
39
  char name[64];
40
  char pdfname[128];
41
  char buf[256];
42
  char hname[0xF];
43
 
44
  sprintf(buf,"../modules/%04d/%04d_1_Treshold_Waveform.root",runNumber,runNumber);
45
  TFile * data = new TFile(buf);
46
 
47
  const char * serialNumber = getSN(runNumber);
48
  printf("base.c return: %s\n", serialNumber);
49
  /******* PREVERI ČE JE NALOŽEN FILE *******/
50
  if (!strcmp(serialNumber, "NoFILE")){
51
    printf("Ni naloženege datoteke\n");
52
    return -1;
53
  }
54
  std::string serialNumberTemp = serialNumber;
55
  std::cout << serialNumberTemp << std::endl;
56
  std::string HAPDserialNumber,FEBserialNumber;
57
 
58
  GRID m = mapping();
59
  int vrstaPisave = 82;
60
 
61
  TCanvas * c, * c4;
62
  TH1D * h;
63
  TH2D * h2 = NULL;
64
  TPad * pad1, * pad2, * pad3;
65
  TPaveText * sn, * gainTitle;
66
 
67
  /********** GLOBALNE **********/
68
  gStyle->SetOptStat(0);
69
  //gStyle->SetOptTitle(1);
70
  gStyle->SetTextFont(vrstaPisave);
71
  gStyle->SetTitleFont(vrstaPisave);
72
  gStyle->SetTitleFontSize(0.1);
73
  gStyle->SetNumberContours(100);
74
 
75
  gStyle->SetPalette(55);
76
 
77
  //gROOT->SetBatch(kTRUE); //Does not show canvases
78
 
79
 
80
 
81
  /******* ZRIHTA GRAFE *******/
82
  for(HAPDnumber=0;HAPDnumber<4;HAPDnumber++){
83
 
84
        if(save==2) {  
85
            SaveToRootInit();
86
        }
87
 
88
    //std::cout << serialNumberTemp << std::endl;
89
    FEBserialNumber = serialNumberTemp.substr(0,serialNumberTemp.find(","));
90
    serialNumberTemp.erase(0,FEBserialNumber.length()+1);
91
    if(!FEBserialNumber.compare("noserial")) continue;
92
    HAPDserialNumber = FEBserialNumber.substr(0,FEBserialNumber.find("/"));
93
    FEBserialNumber.erase(0,FEBserialNumber.find("/")+1);
94
 
95
    sprintf(hname,"hcharge%d_0",HAPDnumber);
96
    printf("%s \t %s \t %s \n",FEBserialNumber.c_str(),HAPDserialNumber.c_str(),hname);
97
 
98
    sprintf(name,"%04d_%s_Charge_c4",runNumber,HAPDserialNumber.c_str());
99
    c4 = new TCanvas(name,name,0,0,1200,1200);
100
    c4->Divide(2,2);
101
 
102
    for (int chip=0;chip<4; chip++){
103
      sprintf(name,"%04d_%s_c%d",runNumber,HAPDserialNumber.c_str(),chip);
104
      c = new TCanvas(name,name,0,0,1200,1200);
105
      c->cd();
106
      pad1 = new TPad("pad11","SN",0,0.975,1,1,0,0);
107
        pad1->SetFillStyle(4000);
108
        pad1->Draw();
109
        pad1->cd();
110
        sn = new TPaveText(0.2,0,0.8,1,"ndc");
111
          sn->SetBorderSize(0);
112
          sn->SetFillColor(4000);
113
          sn->SetTextSize(.8);
114
          sn->SetTextAlign(22);
115
          sprintf(buf,"Charge %s",HAPDserialNumber.c_str());
116
          sn->AddText(buf);
117
          //sn->Draw();
118
 
119
      /******* DRUGI PAD *******/
120
      c->cd();
121
      pad2 = new TPad("pad2","Date",0.05,0.95,0.95,.99,0,0);
122
        pad2->SetFillStyle(4000);
123
        pad2->Draw();
124
        pad2->cd();
125
        gainTitle = new TPaveText(0,0,1,1,"ndc");
126
          gainTitle->SetBorderSize(0);
127
          gainTitle->SetFillColor(kSpring+1);
128
          gainTitle->SetTextSize(.8);
129
          gainTitle->SetTextAlign(22);
130
          sprintf(buf,"Charge scan over center of channels:");
131
          switch(chip){
132
            case 0: sprintf(buf,"%s Chip A",buf);break;
133
            case 1: sprintf(buf,"%s Chip B",buf);break;
134
            case 2: sprintf(buf,"%s Chip D",buf);break;
135
            case 3: sprintf(buf,"%s Chip C",buf);break;
136
          }
137
          gainTitle->AddText(buf);
138
          gainTitle->Draw();
139
 
140
      //----------- PAD 2 (FIGURES)
141
      c->cd();
142
      pad3 = new TPad("pad3","Figures",0,0,1,0.96,0,0);
143
        pad3->SetFillStyle(4000);
144
        pad3->Draw();
145
        pad3->cd();
146
        pad3->Divide(6,6,0,0,0);
147
      for (int i=0;i<36;i++) {      
148
        int idx = i+chip*36;
149
        sprintf(name,"%s;%d",hname,m.pozicijaPixla[idx]+1);
150
        h = ((TH1D * ) data->Get(name));
151
 
152
        TVirtualPad *pad = pad3->cd(m.pozicijaPixlaNaCipu[idx]+1);
153
        pad->SetBorderSize(0);
154
        pad->SetBorderMode(0);
155
 
156
        if (idx==0 && h->InheritsFrom("TH1D") ) {
157
          sprintf(name,"%s_2d",h->GetName());
158
          TAxis *axis = h->GetXaxis();
159
          h2 = new TH2D(name,h->GetTitle(),144,-0.5,143.5,axis->GetNbins(),
160
                                                          axis->GetXmin(),
161
                                                          axis->GetXmax());
162
          h2->GetXaxis()->SetTitle("HAPD 2d channels");
163
          h2->GetYaxis()->SetTitle(axis->GetTitle());
164
          h2->GetYaxis()->SetTitleOffset(1.4);
165
        }
166
 
167
        if (h) {
168
          //printf("TH2D %s\n",name);
169
          sprintf(name,"ASIC %d ch %d",chip,idx);
170
          h->SetTitle(name);
171
          h->GetXaxis()->SetRangeUser(xmin,xmax);
172
          h->SetMinimum(-0.1);
173
          h->SetStats(kFALSE);
174
          h->SetFillColor(kBlue);
175
          h->DrawCopy("AH");
176
 
177
            if(save==2) {  
178
                sprintf(text_for_STR, "Charge_1D_%s_ASIC_%d_CH_%d", HAPDserialNumber.c_str(),chip,idx);
179
                SaveToRootAddTH1DCopy(h, text_for_STR);
180
            }
181
 
182
          if (h2){
183
            for(int k=xmin;k<h->GetNbinsX(); k++){
184
              //if (idx==133) printf("x = %d \t y = %d \t value = %d\n", idx+1, k,(int)h->GetBinContent(k+1));
185
              if ((int)h->GetBinContent(k+1)==0) h2->SetBinContent(idx+1,k+1,1);
186
              else h2->SetBinContent(idx+1,k+1,h->GetBinContent(k+1));
187
            }
188
          }
189
        } else printf("TH2D %s does not exist !!!!\n",name);  
190
      }
191
      c->Modified();
192
      c->Update();
193
      if(chip%2==0) c4->cd(chip+2);
194
      else c4->cd(chip);
195
      c->DrawClonePad();
196
      if (save==1){
197
        switch (chip) {
198
          case 0: sprintf(pdfname,"../modules/%04d/%04d_%s_1_Charge.pdf(",runNumber,runNumber,HAPDserialNumber.c_str());break;
199
          default: sprintf(pdfname,"../modules/%04d/%04d_%s_1_Charge.pdf",runNumber,runNumber,HAPDserialNumber.c_str());break;
200
        }
201
        c->SaveAs(pdfname,"pdf");
202
      } else if (save==4){
203
        sprintf(pdfname,"../modules/%04d/%04d_%s.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
204
        c->SaveAs(pdfname,"pdf");
205
      }
206
    }
207
    if (h2) {
208
      sprintf(name,"%04d_%s_c%d",runNumber,HAPDserialNumber.c_str(),5);
209
      c = new TCanvas(name,name,600,500);
210
      c->SetLeftMargin(0.15);
211
      c->SetRightMargin(0.15);
212
      c->SetLogz(1);
213
 
214
      sprintf(buf,"Charge scan over the center of channels");
215
 
216
      h2->SetTitle(buf);
217
      gStyle->SetTitleFontSize(0.05);
218
      h2->SetTitleFont(vrstaPisave);
219
      h2->SetTitleOffset(0);
220
 
221
      h2->GetZaxis()->SetRangeUser(1,10000);
222
      h2->GetZaxis()->SetTickLength(.02);
223
      h2->GetZaxis()->SetLabelFont(vrstaPisave);
224
      h2->GetZaxis()->SetLabelSize(0.03);
225
 
226
      h2->GetYaxis()->SetRangeUser(xmin,xmax);
227
      h2->GetYaxis()->SetTitleFont(vrstaPisave);
228
      h2->GetYaxis()->SetLabelFont(vrstaPisave);
229
      //h2->GetYaxis()->SetLabelSize(0.04);
230
      h2->GetYaxis()->SetLabelColor(kBlack);
231
      //h2->GetYaxis()->SetNdivisions(12);
232
      h2->GetYaxis()->CenterTitle();
233
      h2->GetYaxis()->SetTitle("ADC channel (a.u.)");
234
      //h2->GetYaxis()->SetTitleSize(0.05);
235
      h2->GetYaxis()->SetTitleOffset(1.5);
236
      h2->GetYaxis()->SetTitleColor(kBlack);
237
 
238
      //h2->GetXaxis()->SetTickLength(0.05);
239
      h2->GetXaxis()->SetTitleFont(vrstaPisave);
240
      h2->GetXaxis()->SetLabelFont(vrstaPisave);
241
      //h2->GetXaxis()->SetLabelSize(0.04);
242
      h2->GetXaxis()->SetLabelColor(kBlack);
243
      //h2->GetXaxis()->SetLabelOffset(.05);
244
      //h2->GetXaxis()->SetNdivisions(0);
245
      //h2->GetXaxis()->CenterTitle();
246
      h2->GetXaxis()->SetTitle("Channel");
247
      //h2->GetXaxis()->SetTitleSize(0.05);
248
      h2->GetXaxis()->SetTitleColor(kBlack); //zato ker ga ne moreš pozicionirat
249
      h2->GetXaxis()->SetTitleOffset(1.2);
250
 
251
 
252
      h2->DrawCopy("COLZ");
253
        if(save==2) {    
254
            sprintf(text_for_STR, "Charge_2D_%s", HAPDserialNumber.c_str());
255
            SaveToRootAddTH2DCopy(h2, text_for_STR);
256
        }
257
 
258
      c->Modified();
259
      c->Update();
260
      if (save==1){
261
        sprintf(pdfname,"../modules/%04d/%04d_%s_1_Charge.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
262
        c4->SaveAs(pdfname,"pdf");
263
        sprintf(pdfname,"../modules/%04d/%04d_%s_1_Charge.pdf)",runNumber,runNumber,HAPDserialNumber.c_str());
264
        c->SaveAs(pdfname,"pdf");
265
      } else if (save==2){
266
        sprintf(pdfname,"../modules/%04d/%04d_%s.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
267
        c4->SaveAs(pdfname,"pdf");
268
        c->SaveAs(pdfname,"pdf");
269
      }
270
 
271
        if(save==2) {  
272
            sprintf(text_for_STR,"../modules/%04d/%04d_%s_out.root",runNumber,runNumber,HAPDserialNumber.c_str());
273
            SaveToRootWrite(text_for_STR, HAPDserialNumber.c_str());
274
        }
275
    }
276
  }
277
  delete data;
278
  return 0;
279
}
280
 
281
float getGain(TH1D * h, int deadChannelSigma) {
282
  TF1 * g0,  * g1, * g2,  * g3;
283
  float gain;
284
  float mean1, sigma1, mean2;
285
  //Double_t * xpeaks;
286
  Float_t * xpeaks;
287
 
288
  TSpectrum * s = new TSpectrum(3);
289
  int nfound = s->Search(h); //TALE FUNKICJA LAHKO POVZROČA TEŽAVE, KER NI NUJNO DA VRNE VRHOVE V PRAVEM ZAPOREDJU
290
  //printf("Found %d candidate peaks to fit\n",nfound);
291
  xpeaks = s->GetPositionX();
292
 
293
  Float_t * first(&xpeaks[0]);
294
  Float_t * last(first + nfound);
295
  std::sort(first, last);
296
 
297
 
298
 
299
  float xp;
300
  for (int p=0;p<nfound;p++) {
301
    xp = xpeaks[p];
302
    //printf("Vrh številka %d je na poziciji %f\n",p,xp);
303
    if(p==0) {
304
      g0 = new TF1("0ph","gaus",xp-14,xp+14);
305
      h->Fit(g0,"QR");
306
    } else if(p==1) {
307
      g1 = new TF1("1ph","gaus",xp-14,xp+14);
308
      h->Fit(g1,"QR+");
309
     } else if(p==2) {
310
      g2 = new TF1("2ph","gaus",xp-14,xp+14);
311
      h->Fit(g2,"QR+");
312
    } else {
313
      g3 = new TF1("3ph","gaus",xp-14,xp+14);
314
      h->Fit(g3,"QR+");
315
    }
316
  }
317
 
318
  if(nfound >= 1){
319
    mean1 = g0->GetParameter(1);
320
    sigma1 = g0->GetParameter(2);
321
    if (sigma1<deadChannelSigma) gain = 0;
322
    else gain = 30;
323
  } else {
324
    gain = 0;
325
  }
326
  if(nfound > 1){
327
    mean2 = g1->GetParameter(1);
328
    printf("%f \t %f\n", mean1, mean2);
329
    if (mean1<mean2) gain = mean2 - mean1;
330
    else gain = mean1 - mean2;
331
    //printf("nfound: %d \t gain: %.1f \t mean1: %.1f \t sigma1: %.1f \t mean2: %.1f\n", nfound, gain, mean1, sigma1, mean2);
332
  }
333
  delete s;
334
  return gain;
335
}
336
 
337
int gain(int runNumber, int save){
338
 
339
  int HAPDnumber = 0; //Number of HAPD: 0, 1, 2 or 3!
340
 
341
  char name[128];
342
  char pdfname[128];
343
  char buf[0xFF];
344
  float ojacanje;
345
 
346
  char hname[0xF];
347
 
348
  sprintf(buf,"../modules/%04d/%04d_1_Treshold_Waveform.root",runNumber,runNumber);
349
  TFile * data = new TFile(buf);
350
 
351
  const char * serialNumber = getSN(runNumber);
352
  printf("base.c return: %s\n", serialNumber);
353
  /******* PREVERI ČE JE NALOŽEN FILE *******/
354
  if (!strcmp(serialNumber, "NoFILE")){
355
    printf("Ni naloženege datoteke\n");
356
    return -1;
357
  }
358
  std::string serialNumberTemp = serialNumber;
359
  std::cout << serialNumberTemp << std::endl;
360
  std::string HAPDserialNumber,FEBserialNumber;
361
 
362
  GRID m = mapping();
363
  int vrstaPisave = 82;
364
 
365
  int blackWhite = 40;
366
  int max = 140;
367
 
368
  TCanvas * c1, * c2, * c3;
369
  TPad * pad1, * pad2;
370
  TPaveText * title;
371
  TH1D * h;
372
  TH1F * Gain1D;
373
  TH2F * Gain2D;
374
  TH2I * Gain2D_black, * Gain2D_white;
375
 
376
  gStyle->SetOptStat(0);
377
  gStyle->SetPalette(52);
378
  gStyle->SetNumberContours(100);
379
 
380
 
381
  for(HAPDnumber=0;HAPDnumber<4;HAPDnumber++){
382
 
383
          SaveToRootInit();
384
 
385
    //std::cout << serialNumberTemp << std::endl;
386
    FEBserialNumber = serialNumberTemp.substr(0,serialNumberTemp.find(","));
387
    serialNumberTemp.erase(0,FEBserialNumber.length()+1);
388
    if(!FEBserialNumber.compare("noserial")) continue;
389
    HAPDserialNumber = FEBserialNumber.substr(0,FEBserialNumber.find("/"));
390
    FEBserialNumber.erase(0,FEBserialNumber.find("/")+1);
391
 
392
    sprintf(hname,"hcharge%d_0",HAPDnumber);
393
    printf("%s \t %s \t %s \n",FEBserialNumber.c_str(),HAPDserialNumber.c_str(),hname);  
394
 
395
    /******* 1D *******/
396
    sprintf(buf,"%04d_%s_Gain1D",runNumber,HAPDserialNumber.c_str());
397
    c1 = new TCanvas(buf,buf,0,0,600,300);
398
 
399
    sprintf(name,"1D Gain of HAPD %s (%04d);Channel number;Gain",HAPDserialNumber.c_str(),runNumber);
400
    Gain1D = new TH1F("Gain1D",name,144,0,144);
401
 
402
    /******* 2D *******/
403
    sprintf(buf,"%04d_%s_Gain2D",runNumber,HAPDserialNumber.c_str());
404
    c2 = new TCanvas(buf,buf,0,0,600,600);
405
      c2->SetRightMargin(0.15);
406
 
407
    sprintf(name,"Backside view: Gain of HAPD %s (%04d)",HAPDserialNumber.c_str(),runNumber);
408
    Gain2D = new TH2F("Gain2D",name,12,-0.5,11.5,12,-0.5,11.5);
409
    Gain2D_black = new TH2I("Gain2D_black","Gain2D_black",12,-0.5,11.5,12,-0.5,11.5);
410
    Gain2D_white = new TH2I("Gain2D_white","Gain2D_white",12,-0.5,11.5,12,-0.5,11.5);
411
    Gain2D->SetMinimum(-0.1);
412
    Gain2D->SetMaximum(max);
413
    Gain2D_black->SetMinimum(blackWhite);
414
 
415
    /******* NAREDI HISTOGRAME *******/
416
    for (int i=0;i<12;i++) {
417
      for (int j=0;j<12;j++) {
418
        sprintf(name,"%s;%d",hname,m.pozicijaPixla[m.koordinatniSistem[i][j]]+1);
419
        //printf("%s\n",name);
420
        h = (TH1D *) data->Get(name);
421
        h->GetXaxis()->SetRangeUser(-50,300);
422
 
423
        ojacanje = getGain(h);
424
        //printf("channel %d \t gain %f\n", m.koordinatniSistem[i][j], ojacanje);
425
 
426
        Gain1D->Fill(m.koordinatniSistem[i][j],ojacanje);
427
 
428
        Gain2D->Fill(i,j,ojacanje);
429
        if(ojacanje<=blackWhite) Gain2D_white->Fill(i,j,ojacanje);
430
        Gain2D_black->Fill(i,j,ojacanje);
431
      }
432
    }
433
 
434
 
435
    c1->cd();
436
      c1->SetGrid(1);
437
 
438
      Gain1D->SetTitle("");
439
      //Gain1D->SetLineWidth(2);
440
      Gain1D->SetFillColor(kRed-10);
441
 
442
      Gain1D->GetYaxis()->SetRangeUser(0,140);
443
      Gain1D->GetYaxis()->SetTickLength(0.01);
444
      Gain1D->GetYaxis()->SetTitleFont(vrstaPisave);
445
      Gain1D->GetYaxis()->SetLabelFont(vrstaPisave);
446
      Gain1D->GetYaxis()->SetLabelSize(0.04);
447
      Gain1D->GetYaxis()->SetLabelColor(kBlack);
448
      //Gain1D->GetYaxis()->SetNdivisions(0);
449
      Gain1D->GetYaxis()->CenterTitle();
450
      Gain1D->GetYaxis()->SetTitle("Gain");
451
      Gain1D->GetYaxis()->SetTitleSize(0.05);
452
      //Gain1D->GetYaxis()->SetTitleOffset(.5);
453
      Gain1D->GetYaxis()->SetTitleColor(kBlack);
454
 
455
      //Gain1D->GetXaxis()->SetRangeUser(0,80);
456
      //Gain1D->GetXaxis()->SetTickLength(0.05);
457
      Gain1D->GetXaxis()->SetTitleFont(vrstaPisave);
458
      Gain1D->GetXaxis()->SetLabelFont(vrstaPisave);
459
      Gain1D->GetXaxis()->SetLabelSize(0.04);
460
      Gain1D->GetXaxis()->SetLabelColor(kBlack);
461
      //Gain1D->GetXaxis()->SetLabelOffset(.05);
462
      //Gain1D->GetXaxis()->SetNdivisions(0);
463
      //Gain1D->GetXaxis()->CenterTitle();
464
      Gain1D->GetXaxis()->SetTitle("Channel");
465
      Gain1D->GetXaxis()->SetTitleSize(0.05);
466
      Gain1D->GetXaxis()->SetTitleColor(kBlack); //zato ker ga ne moreš pozicionirat
467
      Gain1D->GetXaxis()->SetTitleOffset(1);
468
 
469
      Gain1D->DrawCopy();
470
 
471
 
472
    c2->cd();
473
 
474
      Gain2D->SetTitle("");
475
 
476
      Gain2D->GetZaxis()->SetTickLength(.02);
477
      Gain2D->GetZaxis()->SetTitleFont(vrstaPisave);
478
      Gain2D->GetZaxis()->SetLabelFont(vrstaPisave);
479
      Gain2D->GetZaxis()->SetLabelSize(0.03);
480
      Gain2D->GetZaxis()->SetTitle("G_{a}");
481
      Gain2D->GetZaxis()->CenterTitle();
482
 
483
 
484
      //Gain2D->GetYaxis()->SetTickLength(0.03);
485
      Gain2D->GetYaxis()->SetTitleFont(vrstaPisave);
486
      Gain2D->GetYaxis()->SetLabelFont(vrstaPisave);
487
      Gain2D->GetYaxis()->SetLabelSize(0.03);
488
      Gain2D->GetYaxis()->SetLabelColor(kBlack);
489
      Gain2D->GetYaxis()->SetLabelOffset(.01);
490
      //Gain2D->GetYaxis()->SetNdivisions(12);
491
      Gain2D->GetYaxis()->CenterTitle();
492
      Gain2D->GetYaxis()->SetTitle("Rows");
493
      Gain2D->GetYaxis()->SetTitleSize(0.035);
494
      Gain2D->GetYaxis()->SetTitleOffset(1.2);
495
      Gain2D->GetYaxis()->SetTitleColor(kBlack);
496
 
497
      //Gain2D->GetXaxis()->SetTickLength(0.03);
498
      Gain2D->GetXaxis()->SetTitleFont(vrstaPisave);
499
      Gain2D->GetXaxis()->SetLabelFont(vrstaPisave);
500
      Gain2D->GetXaxis()->SetLabelSize(0.03);
501
      Gain2D->GetXaxis()->SetLabelColor(kBlack);
502
      //Gain2D->GetXaxis()->SetLabelOffset(.05);
503
      //Gain2D->GetXaxis()->SetNdivisions(0);
504
      //Gain2D->GetXaxis()->CenterTitle();
505
      Gain2D->GetXaxis()->SetTitle("Columns");
506
      Gain2D->GetXaxis()->SetTitleSize(0.03);
507
      Gain2D->GetXaxis()->SetTitleColor(kBlack); //zato ker ga ne moreš pozicionirat
508
      Gain2D->GetXaxis()->SetTitleOffset(1.2);
509
 
510
      Gain2D->DrawCopy("COLZ");
511
 
512
      Gain2D_black->DrawCopy("TEXT,SAME");
513
      Gain2D_white->SetMarkerColor(kWhite);
514
      Gain2D_white->DrawCopy("TEXT,SAME");
515
 
516
 
517
    c1->Modified();
518
    c1->Update();
519
    c2->Modified();
520
    c2->Update();
521
 
522
    sprintf(buf,"%04d_%s_Gain",runNumber,HAPDserialNumber.c_str());
523
    c3 = new TCanvas(buf,buf,0,0,1000,1000);
524
    c3->cd();
525
    /******* 1D *******/
526
    sprintf(buf,"%04d_%s_gain1d_pad1",runNumber,HAPDserialNumber.c_str());
527
    pad1 = new TPad(buf,"SN",.15,0.7,.85,1,0,0);
528
      pad1->SetFillStyle(4000);
529
      pad1->Draw();
530
      //pad1->SetRightMargin(0.15);
531
 
532
    /******* 2D *******/
533
    sprintf(buf,"%04d_%s_gain2d_pad2",runNumber,HAPDserialNumber.c_str());
534
    pad2 = new TPad(buf,"Date",.15,0,.85,0.7,0,0);
535
      pad2->SetFillStyle(4000);
536
      pad2->Draw();
537
      pad2->SetRightMargin(0.15);
538
 
539
    pad1->cd();
540
      pad1->SetGrid(1);
541
      Gain1D->DrawCopy();
542
 
543
          sprintf(text_for_STR, "Gain_1D_%s", HAPDserialNumber.c_str());
544
          SaveToRootAddTH1F(Gain1D, text_for_STR);
545
 
546
      title = new TPaveText(0.2,.93,0.8,.94,"ndc");
547
        title->SetBorderSize(0);
548
        title->SetFillColor(4000);
549
        title->SetTextSize(.06);
550
        title->SetTextAlign(22);
551
        title->SetTextFont(vrstaPisave);
552
      title->AddText("Gain");
553
      title->Draw();
554
 
555
 
556
    pad2->cd();
557
      Gain2D->DrawCopy("COLZ");
558
 
559
      Gain2D_black->DrawCopy("TEXT,SAME");
560
      Gain2D_white->SetMarkerColor(kWhite);
561
      Gain2D_white->DrawCopy("TEXT,SAME");
562
 
563
          sprintf(text_for_STR, "Gain_2D_%s", HAPDserialNumber.c_str());
564
          SaveToRootAddTH2F(Gain2D, text_for_STR);
565
 
566
      title = new TPaveText(0.2,.91,0.8,.93,"ndc");
567
        title->SetBorderSize(0);
568
        title->SetFillColor(4000);
569
        title->SetTextSize(.035);
570
        title->SetTextAlign(22);
571
        title->SetTextFont(vrstaPisave);
572
      title->AddText("Backside view gain");
573
      title->Draw();
574
 
575
      delete c1;
576
      delete c2;
577
 
578
    if (save==1) {
579
      sprintf(pdfname,"../modules/%04d/%04d_%s_Gain.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
580
      c3->SaveAs(pdfname,"pdf");
581
    } else if (save==2){
582
      sprintf(pdfname,"../modules/%04d/%04d_%s.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
583
      c3->SaveAs(pdfname,"pdf");
584
    } else if (save==3){
585
      sprintf(pdfname,"../modules/%04d/%04d_%s.pdf(",runNumber,runNumber,HAPDserialNumber.c_str());
586
      c3->SaveAs(pdfname,"pdf");
587
    } else if (save==5){
588
      sprintf(pdfname,"../modules/%04d/%04d_%s.root",runNumber,runNumber,HAPDserialNumber.c_str());
589
      c3->SaveAs(pdfname,"root");
590
    }
591
 
592
 
593
    sprintf(text_for_STR,"../modules/%04d/%04d_%s_out.root",runNumber,runNumber,HAPDserialNumber.c_str());
594
    SaveToRootWrite(text_for_STR, HAPDserialNumber.c_str());
595
 
596
    delete Gain1D;
597
    delete Gain2D;
598
    delete Gain2D_white;
599
    delete Gain2D_black;
600
 
601
  }
602
  delete data;
603
  return 0;
604
}