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 <TH2D.h>
7
#include <TCanvas.h>
8
#include <TStyle.h>
9
#include <TSystem.h>
10
#include <TFile.h>
11
#include <TColor.h>
12
#include <TDirectory.h>
13
#include <TPaveText.h>
14
 
15
#include <iostream>
16
#include <string>
17
 
18
#include "base.h"
19
#include "treshold.h"
20
#include "savetoroot.h"
21
 
22
int treshold(int runNumber, int save){
23
 
24
  int HAPDnumber; //Number of HAPD: 0, 1, 2 or 3!
25
 
26
  char name[128];
27
  char pdfname[128];
28
  char buf[256];
29
 
30
  const char * hname = "h2d_0";
31
 
32
  sprintf(buf,"../modules/%04d/%04d_1_Treshold_Waveform.root",runNumber,runNumber);
33
  TFile * data = new TFile(buf);
34
 
35
  const char * serialNumber = getSN(runNumber);
36
  printf("base.c return: %s\n", serialNumber);
37
  /******* PREVERI ČE JE NALOŽEN FILE *******/
38
  if (!strcmp(serialNumber, "NoFILE")){
39
    printf("Ni naloženege datoteke\n");
40
    return -1;
41
  }
42
  std::string serialNumberTemp = serialNumber;
43
  std::cout << serialNumberTemp << std::endl;
44
  std::string HAPDserialNumber,FEBserialNumber;
45
 
46
  GRID m = mapping();
47
  int vrstaPisave = 82;
48
 
49
  TCanvas * c, * c4;
50
  TH2D * h;
51
  TH1D * p = NULL;
52
  TH2D * h2 = NULL;
53
  TPad * pad1, * pad2, * pad3;
54
  TPaveText * sn, * gainTitle;
55
 
56
  /*
57
  TFile * out;
58
  //----------- CREATE OUTPUT FILE
59
  sprintf(buf,"../modules/%04d/%04d.root",runNumber,runNumber);
60
  if (file_exists(buf)){
61
    //out = new TFile(path,"UPDATE");
62
    printf("File %s already exists. To create new, delete old.\n",buf);
63
    return 1;
64
  } else {
65
    out = new TFile(buf,"RECREATE");
66
    printf("Creating file %s\n",buf);
67
  }
68
  */
69
 
70
 
71
  /********** GLOBALNE **********/
72
  gStyle->SetOptStat(0);
73
  //gStyle->SetOptTitle(1);
74
  gStyle->SetTextFont(vrstaPisave);
75
  gStyle->SetTitleFont(vrstaPisave);
76
  gStyle->SetTitleFontSize(0.1);
77
  gStyle->SetNumberContours(100);
78
 
79
  gStyle->SetPalette(55);
80
 
81
  //gROOT->SetBatch(kTRUE); //Does not show canvases
82
 
83
 
84
  /******* PREVERI ČE JE NALOŽEN FILE *******/
85
  if (!strcmp(serialNumber, "NoFILE")){
86
    printf("Ni naloženege datoteke\n");
87
    return 0;
88
  }
89
 
90
  /******* ZRIHTA GRAFE *******/
91
  for(HAPDnumber=0;HAPDnumber<4;HAPDnumber++){
92
 
93
        if(save==2) {  
94
            SaveToRootInit();
95
        }
96
 
97
    //std::cout << serialNumberTemp << std::endl;
98
    FEBserialNumber = serialNumberTemp.substr(0,serialNumberTemp.find(","));
99
    serialNumberTemp.erase(0,FEBserialNumber.length()+1);
100
    if(!FEBserialNumber.compare("noserial")) continue;
101
    HAPDserialNumber = FEBserialNumber.substr(0,FEBserialNumber.find("/"));
102
    FEBserialNumber.erase(0,FEBserialNumber.find("/")+1);
103
 
104
    printf("%s \t %s \t %s \n",FEBserialNumber.c_str(),HAPDserialNumber.c_str(),hname);
105
 
106
    sprintf(name,"%04d_%s_Treshold_c4",runNumber,HAPDserialNumber.c_str());
107
    c4 = new TCanvas(name,name,0,0,1200,1200);
108
    c4->Divide(2,2);
109
 
110
    for (int chip=0;chip<4; chip++){
111
      sprintf(name,"%04d_%s_Treshold_c%d",runNumber,HAPDserialNumber.c_str(),chip);
112
      c = new TCanvas(name,name,0,0,1200,1200);
113
      c->cd();
114
      pad1 = new TPad("pad11","SN",0,0.975,1,1,0,0);
115
        pad1->SetFillStyle(4000);
116
        pad1->Draw();
117
        pad1->cd();
118
        sn = new TPaveText(0.2,0,0.8,1,"ndc");
119
          sn->SetBorderSize(0);
120
          sn->SetFillColor(4000);
121
          sn->SetTextSize(.8);
122
          sn->SetTextAlign(22);
123
          sprintf(buf,"%s (treshold scan)",HAPDserialNumber.c_str());
124
          sn->AddText(buf);
125
          //sn->Draw();
126
 
127
      /******* DRUGI PAD *******/
128
      c->cd();
129
      pad2 = new TPad("pad2","Date",0.05,0.95,0.95,0.99,0,0);
130
        pad2->SetFillStyle(4000);
131
        pad2->Draw();
132
        pad2->cd();
133
        gainTitle = new TPaveText(0,0,1,1,"ndc");
134
          gainTitle->SetBorderSize(0);
135
          gainTitle->SetFillColor(kSpring+1);
136
          gainTitle->SetTextSize(.6);
137
          gainTitle->SetTextAlign(22);
138
          sprintf(buf,"Treshold scan over center of channels:");
139
          switch(chip){
140
            case 0: sprintf(buf,"%s Chip A",buf);break;
141
            case 1: sprintf(buf,"%s Chip B",buf);break;
142
            case 2: sprintf(buf,"%s Chip D",buf);break;
143
            case 3: sprintf(buf,"%s Chip C",buf);break;
144
          }
145
          gainTitle->AddText(buf);
146
          gainTitle->Draw();
147
 
148
      //----------- PAD 2 (FIGURES)
149
      c->cd();
150
      pad3 = new TPad("pad2","Figures",0,0,1,0.96,0,0);
151
        pad3->SetFillStyle(4000);
152
        pad3->Draw();
153
        pad3->cd();
154
        pad3->Divide(6,6,0,0,0);
155
      for (int i=0;i<36;i++) {      
156
        int idx = i+chip*36;
157
        sprintf(name,"%s;%d",hname,m.pozicijaPixla[idx]+1);
158
        h = (TH2D *) data->Get(name);
159
 
160
        TVirtualPad * pad = pad3->cd(m.pozicijaPixlaNaCipu[idx]+1);
161
        pad->SetBorderSize(0);
162
        pad->SetBorderMode(0);
163
 
164
        if (h){
165
          sprintf(name,"HAPD%d ASIC %d ch %d",HAPDnumber,chip,idx);
166
          p = h->ProjectionY(name,idx+HAPDnumber*144+1,idx+HAPDnumber*144+1);
167
          p->SetTitle(name);
168
          p->SetStats(kFALSE);
169
          p->SetFillColor(kBlue);
170
          p->SetMinimum(-0.1);
171
          p->DrawCopy("AH");
172
 
173
 
174
            if(save==2) {  
175
                sprintf(text_for_STR, "Threshold_1D_%s_ASIC_%d_CH_%d", HAPDserialNumber.c_str(),chip,idx);
176
                SaveToRootAddTH1DCopy(p, text_for_STR);
177
            }
178
 
179
          if (idx==0 && h->InheritsFrom("TH2D")) {
180
            sprintf(name,"%s_2d",p->GetName());
181
            TAxis * axis = p->GetXaxis();
182
            h2 = new TH2D(name,p->GetTitle(),144,-0.5,143.5,axis->GetNbins(),
183
                                                            axis->GetXmin(),
184
                                                            axis->GetXmax() );
185
            h2->SetTitle("HAPD Treshold scan");
186
            h2->GetXaxis()->SetTitle("HAPD 2d channels");
187
            h2->GetYaxis()->SetTitle("Treshold");
188
            h2->GetYaxis()->SetTitleOffset(1.4);
189
          }
190
          if (h2){
191
            for (int k=0;k<p->GetNbinsX();k++){
192
              if ((int)p->GetBinContent(k+1)==0) h2->SetBinContent(idx+1,k+1,1);
193
              else h2->SetBinContent(idx+1,k+1,p->GetBinContent(k+1));
194
            }
195
          }
196
        } else printf("TH2D %s does not exist !!!!\n",name);  
197
      }
198
      c->Modified();
199
      c->Update();
200
      if(chip%2==0) c4->cd(chip+2);
201
      else c4->cd(chip);
202
      c->DrawClonePad();
203
      //c->Write();
204
      if (save==1){
205
        switch (chip) {
206
          case 0: sprintf(pdfname,"../modules/%04d/%04d_%s_1_Treshold.pdf(",runNumber,runNumber,HAPDserialNumber.c_str());break;
207
          default: sprintf(pdfname,"../modules/%04d/%04d_%s_1_Treshold.pdf",runNumber,runNumber,HAPDserialNumber.c_str());break;
208
        }
209
        c->SaveAs(pdfname,"pdf");
210
      } else if (save==3){
211
        sprintf(pdfname,"../modules/%04d/%04d_%s.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
212
        c->SaveAs(pdfname,"pdf");
213
      } else if (save==4){
214
        if(chip==3) sprintf(pdfname,"../modules/%04d/%04d_%s.pdf)",runNumber,runNumber,HAPDserialNumber.c_str());
215
        else sprintf(pdfname,"../modules/%04d/%04d_%s.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
216
        c->SaveAs(pdfname,"pdf");
217
      }
218
    }
219
    if (h2) {
220
      sprintf(name,"%04d_%s_Treshold_c%d",runNumber,HAPDserialNumber.c_str(),5);
221
      c = new TCanvas(name,name,600,500);
222
      c->SetRightMargin(0.15);
223
      c->SetLeftMargin(0.15);
224
      c->SetLogz();
225
 
226
      sprintf(buf,"Treshold scan over the center of channels");
227
 
228
      h2->SetTitle(buf);
229
      gStyle->SetTitleFontSize(0.05);
230
      h2->SetTitleFont(vrstaPisave);
231
 
232
      h2->GetZaxis()->SetRangeUser(1,10000);
233
      h2->GetZaxis()->SetTickLength(.02);
234
      h2->GetZaxis()->SetLabelFont(vrstaPisave);
235
      h2->GetZaxis()->SetLabelSize(0.03);
236
 
237
      h2->GetYaxis()->SetRangeUser(500,700);
238
      h2->GetYaxis()->SetTitleFont(vrstaPisave);
239
      h2->GetYaxis()->SetLabelFont(vrstaPisave);
240
      //h2->GetYaxis()->SetLabelSize(0.04);
241
      h2->GetYaxis()->SetLabelColor(kBlack);
242
      //h2->GetYaxis()->SetNdivisions(12);
243
      h2->GetYaxis()->CenterTitle();
244
      h2->GetYaxis()->SetTitle("Treshold");
245
      //h2->GetYaxis()->SetTitleSize(0.05);
246
      h2->GetYaxis()->SetTitleOffset(1.5);
247
      h2->GetYaxis()->SetTitleColor(kBlack);
248
 
249
      //h2->GetXaxis()->SetTickLength(0.05);
250
      h2->GetXaxis()->SetTitleFont(vrstaPisave);
251
      h2->GetXaxis()->SetLabelFont(vrstaPisave);
252
      //h2->GetXaxis()->SetLabelSize(0.04);
253
      h2->GetXaxis()->SetLabelColor(kBlack);
254
      //h2->GetXaxis()->SetLabelOffset(.05);
255
      //h2->GetXaxis()->SetNdivisions(0);
256
      //h2->GetXaxis()->CenterTitle();
257
      h2->GetXaxis()->SetTitle("Channel");
258
      //h2->GetXaxis()->SetTitleSize(0.05);
259
      h2->GetXaxis()->SetTitleColor(kBlack); //zato ker ga ne moreš pozicionirat
260
      h2->GetXaxis()->SetTitleOffset(1.2);
261
 
262
 
263
      h2->SetStats(kFALSE);
264
      h2->DrawCopy("COLZ");
265
 
266
      if(save==2) {    
267
            sprintf(text_for_STR, "Threshold_2D_%s", HAPDserialNumber.c_str());
268
            SaveToRootAddTH2DCopy(h2, text_for_STR);
269
        }
270
 
271
      c->Modified();
272
      c->Update();
273
      //c->Write();
274
      if (save==1){
275
        sprintf(pdfname,"../modules/%04d/%04d_%s_1_Treshold.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
276
        c4->SaveAs(pdfname,"pdf");
277
        sprintf(pdfname,"../modules/%04d/%04d_%s_1_Treshold.pdf)",runNumber,runNumber,HAPDserialNumber.c_str());
278
        c->SaveAs(pdfname,"pdf");
279
      } else if (save==2){
280
        sprintf(pdfname,"../modules/%04d/%04d_%s.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
281
        c4->SaveAs(pdfname,"pdf");
282
        c->SaveAs(pdfname,"pdf");
283
      } else if (save==3){
284
        sprintf(pdfname,"../modules/%04d/%04d_%s.pdf",runNumber,runNumber,HAPDserialNumber.c_str());
285
        c4->SaveAs(pdfname,"pdf");
286
        sprintf(pdfname,"../modules/%04d/%04d_%s.pdf)",runNumber,runNumber,HAPDserialNumber.c_str());
287
        c->SaveAs(pdfname,"pdf");
288
      }
289
 
290
        if(save==2) {  
291
            sprintf(text_for_STR,"../modules/%04d/%04d_%s_out.root",runNumber,runNumber,HAPDserialNumber.c_str());
292
            SaveToRootWrite(text_for_STR, HAPDserialNumber.c_str());
293
        }
294
    }
295
  }
296
  delete data;
297
  //out->Close();
298
  return 0;
299
}