Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
326 | f9daq | 1 | #include <stdio.h> |
2 | #include <time.h> |
||
3 | #include <stdlib.h> |
||
4 | |||
5 | #include <TROOT.h> |
||
6 | #include <TLatex.h> |
||
7 | #include <TH1F.h> |
||
8 | #include <TH2D.h> |
||
9 | #include <TH3D.h> |
||
10 | #include <TGraph.h> |
||
11 | #include <TCanvas.h> |
||
12 | #include <TLegend.h> |
||
13 | #include <TStyle.h> |
||
14 | #include <TSystem.h> |
||
15 | #include <TFile.h> |
||
16 | #include <TTree.h> |
||
17 | #include <TDirectory.h> |
||
18 | #include <TPaveText.h> |
||
19 | |||
20 | #include "base.h" |
||
21 | #include "info.h" |
||
22 | #include "savetoroot.h" |
||
23 | |||
24 | int info(int runNumber, int save) { |
||
25 | |||
26 | int HAPDnumber; //Number of HAPD: 0, 1, 2 or 3! |
||
27 | |||
28 | char text[256]; |
||
29 | char pdfname[256]; |
||
30 | char buf[256]; |
||
31 | char path[128]; |
||
32 | int vrstaPisave = 82; |
||
33 | |||
34 | const char * serialNumber; |
||
35 | std::string serialNumberTemp; |
||
36 | std::string HAPDserialNumber,FEBserialNumber; |
||
37 | |||
38 | unsigned int id, len, cas; |
||
39 | int vmon[24], vset[24]; |
||
40 | int imon[24]; |
||
41 | //int status[6]; |
||
42 | //int min_imon[6], max_imon[6], min_vmon[6], max_vmon[6], min_status[6], max_status[6]; |
||
43 | int min_chipBias = 0, max_chipBias = 0; |
||
44 | int sizeOfTree; |
||
45 | time_t itime; |
||
46 | TDatime dh(1995,01,01,00,00,00); // to je za SetTimeOffset |
||
47 | |||
48 | char * viri[6] = {"Guard", "Chip A", "Chip B", "Chip C", "Chip D", "HV"}; |
||
49 | |||
50 | TFile * data[3]; |
||
51 | TCanvas * c; |
||
52 | TPad * pad1, * pad2, * pad3, * pad4, * pad5; |
||
53 | TPaveText * sn, * timeStamp, * imeMeritve, * zacetekMeritve; |
||
54 | TGraph * gr[10]; |
||
55 | TLegend * leg[2]; |
||
56 | TTree * tree; |
||
57 | |||
58 | /********** GLOBALNE **********/ |
||
59 | gStyle->SetOptStat(0); |
||
60 | //gStyle->SetOptTitle(1); |
||
61 | gStyle->SetTextFont(vrstaPisave); |
||
62 | gStyle->SetTitleFont(vrstaPisave); |
||
63 | gStyle->SetTitleFontSize(0.08); |
||
64 | |||
65 | gStyle->SetPalette(55); |
||
66 | |||
67 | //gROOT->SetBatch(kTRUE); //Does not show canvases |
||
68 | |||
69 | sprintf(path,"../modules/%04d/%04d_1_Treshold_Waveform.root",runNumber,runNumber); |
||
70 | data[0] = new TFile(path); |
||
71 | if (!file_exists(path)){ |
||
72 | printf("File '%s' does not exist.\n",path); |
||
73 | return -1; |
||
74 | } |
||
75 | serialNumber = getSN(runNumber); |
||
76 | printf("base.c return: %s\n", serialNumber); |
||
77 | serialNumberTemp = serialNumber; |
||
78 | |||
79 | sprintf(path,"../modules/%04d/%04d_2_2DX.root",runNumber,runNumber); |
||
80 | data[1] = new TFile(path); |
||
81 | if (!file_exists(path)){ |
||
82 | printf("File '%s' does not exist.\n",path); |
||
83 | return -1; |
||
84 | } |
||
85 | sprintf(path,"../modules/%04d/%04d_3_2DY.root",runNumber,runNumber); |
||
86 | data[2] = new TFile(path); |
||
87 | if (!file_exists(path)){ |
||
88 | printf("File '%s' does not exist.\n",path); |
||
89 | return -1; |
||
90 | } |
||
91 | |||
92 | for(HAPDnumber=0;HAPDnumber<4;HAPDnumber++){ |
||
93 | |||
94 | SaveToRootInit(); |
||
95 | |||
96 | //std::cout << serialNumberTemp << std::endl; |
||
97 | FEBserialNumber = serialNumberTemp.substr(0,serialNumberTemp.find(",")); |
||
98 | serialNumberTemp.erase(0,FEBserialNumber.length()+1); |
||
99 | if(!FEBserialNumber.compare("noserial")) continue; |
||
100 | HAPDserialNumber = FEBserialNumber.substr(0,FEBserialNumber.find("/")); |
||
101 | FEBserialNumber.erase(0,FEBserialNumber.find("/")+1); |
||
102 | |||
103 | printf("%s \t %s \n",FEBserialNumber.c_str(),HAPDserialNumber.c_str()); |
||
104 | |||
105 | sprintf(buf,"%04d_%s_Monitor",runNumber,HAPDserialNumber.c_str()); |
||
106 | c = new TCanvas(buf,buf,0,0,1500,1200); |
||
107 | /******* PRVI PAD *******/ |
||
108 | sprintf(buf,"%04d_%s_Monitor_pad1",runNumber,HAPDserialNumber.c_str()); |
||
109 | pad1 = new TPad(buf,"SN",0,0.95,1,1,0,0); |
||
110 | pad1->SetFillStyle(4000); |
||
111 | pad1->Draw(); |
||
112 | sn = new TPaveText(0.2,0,0.8,1,"ndc"); |
||
113 | sn->SetBorderSize(0); |
||
114 | sn->SetFillColor(4000); |
||
115 | sn->SetTextSize(.8); |
||
116 | sn->SetTextAlign(22); |
||
117 | sn->SetTextFont(vrstaPisave); |
||
118 | |||
119 | /******* DRUGI PAD *******/ |
||
120 | sprintf(buf,"%04d_%s_Monitor_pad2",runNumber,HAPDserialNumber.c_str()); |
||
121 | pad2 = new TPad(buf,"Date",0.05,0.9,0.95,0.95,0,0); |
||
122 | pad2->SetFillStyle(4000); |
||
123 | pad2->Draw(); |
||
124 | timeStamp = new TPaveText(0.2,0,0.8,1,"ndc"); |
||
125 | timeStamp->SetBorderSize(0); |
||
126 | timeStamp->SetFillColor(4000); |
||
127 | timeStamp->SetTextSize(.4); |
||
128 | timeStamp->SetTextAlign(22); |
||
129 | timeStamp->SetTextFont(vrstaPisave); |
||
130 | |||
131 | /******* TRETJI PAD *******/ |
||
132 | sprintf(buf,"%04d_%s_Monitor_pad3",runNumber,HAPDserialNumber.c_str()); |
||
133 | pad3 = new TPad(buf,"Napetosti",0,0,1,0.9,0,0); |
||
134 | pad3->SetFillStyle(4000); |
||
135 | pad3->Draw(); |
||
136 | pad3->cd(); |
||
137 | pad3->Divide(0,3); |
||
138 | |||
139 | for (int k=0;k<3;k++){ |
||
140 | pad3->cd(k+1); |
||
141 | |||
142 | sprintf(buf,"%04d_%s_Monitor_pad4",runNumber,HAPDserialNumber.c_str()); |
||
143 | pad4 = new TPad(buf,"Naslov",0.05,0.9,0.95,1,0,0); |
||
144 | pad4->SetFillStyle(4000); |
||
145 | pad4->Draw(); |
||
146 | imeMeritve = new TPaveText(0,0,1,1,"ndc"); |
||
147 | imeMeritve->SetBorderSize(0); |
||
148 | imeMeritve->SetFillColor(kSpring+1); |
||
149 | imeMeritve->SetTextSize(.6); |
||
150 | imeMeritve->SetTextAlign(22); |
||
151 | imeMeritve->SetTextFont(vrstaPisave); |
||
152 | |||
153 | zacetekMeritve = new TPaveText(0.8,0,1,1,"ndc"); |
||
154 | zacetekMeritve->SetBorderSize(0); |
||
155 | zacetekMeritve->SetFillColor(kSpring+1); |
||
156 | zacetekMeritve->SetTextSize(.4); |
||
157 | zacetekMeritve->SetTextAlign(22); |
||
158 | zacetekMeritve->SetTextFont(vrstaPisave); |
||
159 | |||
160 | switch (k){ |
||
161 | case 0: sprintf(text, "Treshold and Waveform");break; |
||
162 | case 1: sprintf(text, "2D in X");break; |
||
163 | case 2: sprintf(text, "2D in Y");break; |
||
164 | } |
||
165 | |||
166 | pad4->cd(); |
||
167 | imeMeritve->AddText(text); |
||
168 | imeMeritve->Draw(); |
||
169 | |||
170 | pad3->cd(k+1); |
||
171 | |||
172 | sprintf(buf,"%04d_%s_Monitor_pad5",runNumber,HAPDserialNumber.c_str()); |
||
173 | pad5 = new TPad(buf,"Grafi",0,0,1,.9,0,0); |
||
174 | pad5->SetFillStyle(4000); |
||
175 | pad5->Draw(); |
||
176 | pad5->cd(); |
||
177 | pad5->Divide(4,0); |
||
178 | |||
179 | tree = (TTree*) data[k]->Get("Monitor"); |
||
180 | tree->SetBranchAddress("id",&id); |
||
181 | tree->SetBranchAddress("len",&len); |
||
182 | tree->SetBranchAddress("time",&cas); |
||
183 | tree->SetBranchAddress("imon",&imon); |
||
184 | tree->SetBranchAddress("vmon",&vmon); |
||
185 | tree->SetBranchAddress("vset",&vset); |
||
186 | //tree->SetBranchAddress("status",&status); |
||
187 | |||
188 | sizeOfTree = tree->GetEntries(); |
||
189 | |||
190 | gr[0] = new TGraph(sizeOfTree); |
||
191 | gr[1] = new TGraph(sizeOfTree); |
||
192 | gr[2] = new TGraph(sizeOfTree); |
||
193 | gr[3] = new TGraph(sizeOfTree); |
||
194 | gr[4] = new TGraph(sizeOfTree); |
||
195 | gr[5] = new TGraph(sizeOfTree); |
||
196 | gr[6] = new TGraph(sizeOfTree); |
||
197 | gr[7] = new TGraph(sizeOfTree); |
||
198 | gr[8] = new TGraph(sizeOfTree); |
||
199 | gr[9] = new TGraph(sizeOfTree); |
||
200 | |||
201 | for (int i=0;i<sizeOfTree;i++){ |
||
202 | tree->GetEntry(i); |
||
203 | |||
204 | cas = cas-2208988800; //(2208988800)CVI zapiše čas v sekundah od 00:00:00 1.1.1900 naprej, UNIX čas je od 00:00:00 1.1.1970 |
||
205 | // cas-u morš še nekaj odštet, kr kasneje ko delaš TimeOffset, le ta vodi čas od 00:00:00 1.1.1995 naprej. |
||
206 | gr[0]->SetPoint(i,cas-788918400,vmon[HAPDnumber*6+0]); |
||
207 | gr[1]->SetPoint(i,cas-788918400,vmon[HAPDnumber*6+1]-vset[HAPDnumber*6+1]); |
||
208 | gr[2]->SetPoint(i,cas-788918400,vmon[HAPDnumber*6+2]-vset[HAPDnumber*6+2]); |
||
209 | gr[3]->SetPoint(i,cas-788918400,vmon[HAPDnumber*6+3]-vset[HAPDnumber*6+3]); |
||
210 | gr[4]->SetPoint(i,cas-788918400,vmon[HAPDnumber*6+4]-vset[HAPDnumber*6+4]); |
||
211 | gr[5]->SetPoint(i,cas-788918400,vmon[HAPDnumber*6+5]); |
||
212 | gr[6]->SetPoint(i,cas-788918400,imon[HAPDnumber*6+1]/1000.); |
||
213 | gr[7]->SetPoint(i,cas-788918400,imon[HAPDnumber*6+2]/1000.); |
||
214 | gr[8]->SetPoint(i,cas-788918400,imon[HAPDnumber*6+3]/1000.); |
||
215 | gr[9]->SetPoint(i,cas-788918400,imon[HAPDnumber*6+4]/1000.); |
||
216 | if (!i){ |
||
217 | itime = cas; |
||
218 | zacetekMeritve->AddText(ctime(&itime)); |
||
219 | } else if (k==2 && i==sizeOfTree-1){ |
||
220 | itime = cas; |
||
221 | sprintf(buf,"End of measuring: %s",ctime(&itime)); |
||
222 | timeStamp->AddText(buf); |
||
223 | } |
||
224 | |||
225 | for (int j=1;j<5;j++){ |
||
226 | if (!i && j==1) { |
||
227 | min_chipBias = max_chipBias = vmon[HAPDnumber*6+j]-vset[HAPDnumber*6+j]; |
||
228 | } else { |
||
229 | if (min_chipBias > vmon[HAPDnumber*6+j]-vset[HAPDnumber*6+j]) min_chipBias = vmon[HAPDnumber*6+j]-vset[HAPDnumber*6+j]; |
||
230 | else if (max_chipBias < vmon[HAPDnumber*6+j]-vset[HAPDnumber*6+j]) max_chipBias = vmon[HAPDnumber*6+j]-vset[HAPDnumber*6+j]; |
||
231 | } |
||
232 | } |
||
233 | } |
||
234 | |||
235 | leg[0] = new TLegend(0.55,0.1,.9,0.35); |
||
236 | leg[1] = new TLegend(0.70,0.70,.9,0.9); |
||
237 | leg[0]->SetFillColor(0); |
||
238 | leg[1]->SetFillColor(0); |
||
239 | for (int i=0;i<10;i++){ |
||
240 | gr[i]->GetYaxis()->CenterTitle(); |
||
241 | gr[i]->GetYaxis()->SetTitleFont(vrstaPisave); |
||
242 | gr[i]->GetYaxis()->SetLabelFont(vrstaPisave); |
||
243 | gr[i]->GetYaxis()->SetTitleOffset(1.6); |
||
244 | |||
245 | |||
246 | gr[i]->GetXaxis()->SetTitleFont(vrstaPisave); |
||
247 | gr[i]->GetXaxis()->SetLabelFont(vrstaPisave); |
||
248 | //gr[i]->GetXaxis()->CenterTitle(); |
||
249 | gr[i]->GetXaxis()->SetTimeDisplay(1); |
||
250 | gr[i]->GetXaxis()->SetTimeOffset(dh.Convert()); |
||
251 | gr[i]->GetXaxis()->SetTimeFormat("#splitline{%H:%M}{%d-%m}"); |
||
252 | gr[i]->GetXaxis()->SetLabelOffset(0.02); |
||
253 | gr[i]->GetXaxis()->SetTitleOffset(1.5); |
||
254 | |||
255 | |||
256 | if(!i){ |
||
257 | pad5->cd(1); |
||
258 | |||
259 | sprintf(text, "Guard bias (RMS = %.0f mV);Time;Bias [mV]", gr[i]->GetRMS(2)); |
||
260 | gr[i]->SetTitle(text); |
||
261 | gr[i]->GetYaxis()->SetRangeUser(170000,180000); |
||
262 | |||
263 | gr[i]->Draw("AL"); |
||
264 | |||
265 | sprintf(text, "Guard_%s_T_%d", HAPDserialNumber.c_str(), k); |
||
266 | SaveToRootAddGraph(gr[i], text); |
||
267 | } else if (i<5 && i!=0){ |
||
268 | pad5->cd(2); |
||
269 | sprintf(text, "%s (RMS = %.0f mV)", viri[i], gr[i]->GetRMS(2)); |
||
270 | leg[0]->AddEntry(gr[i],text,"L"); |
||
271 | |||
272 | |||
273 | //gr[i]->GetYaxis()->SetRangeUser(min_chipBias-50,max_chipBias+50); |
||
274 | gr[i]->GetYaxis()->SetRangeUser(-1000,1000); |
||
275 | |||
276 | gr[i]->SetTitle("Chip (vmon - vset) difference;Time;Bias difference [mV]"); |
||
277 | if (i==1) gr[i]->Draw("AL"); |
||
278 | |||
279 | gr[i]->SetLineColor(i); |
||
280 | gr[i]->SetLineWidth(1); |
||
281 | |||
282 | gr[i]->Draw("LSAME"); |
||
283 | |||
284 | sprintf(text, "BiasDifference_%s_CHIP_%d_T_%d", HAPDserialNumber.c_str(), i-1, k); |
||
285 | SaveToRootAddGraph(gr[i], text); |
||
286 | } else if (i>5){ |
||
287 | pad5->cd(3); |
||
288 | sprintf(text, "%s", viri[i-5]); |
||
289 | leg[1]->AddEntry(gr[i],text,"L"); |
||
290 | |||
291 | gr[i]->GetYaxis()->SetRangeUser(-1,11); |
||
292 | |||
293 | gr[i]->SetTitle("Chip leakage current;Time;Leakage current [mA]"); |
||
294 | if (i==6) gr[i]->Draw("AL"); |
||
295 | |||
296 | gr[i]->SetLineColor(i); |
||
297 | gr[i]->SetLineWidth(1); |
||
298 | |||
299 | gr[i]->Draw("LSAME"); |
||
300 | |||
301 | sprintf(text, "LeakageCurrent_%s_CHIP_%d_T_%d", HAPDserialNumber.c_str(), i-6, k); |
||
302 | SaveToRootAddGraph(gr[i], text); |
||
303 | } else if (i==5){ |
||
304 | pad5->cd(4); |
||
305 | sprintf(text, "HV (RMS = %.0f mV);Time;Bias [mV]", gr[i]->GetRMS(2)); |
||
306 | gr[i]->GetYaxis()->SetRangeUser(6900000,7100000); |
||
307 | |||
308 | gr[i]->SetTitle(text); |
||
309 | |||
310 | gr[i]->Draw("AL"); |
||
311 | |||
312 | sprintf(text, "HV_%s_T_%d", HAPDserialNumber.c_str(), k); |
||
313 | SaveToRootAddGraph(gr[i], text); |
||
314 | } |
||
315 | } |
||
316 | |||
317 | pad5->cd(2); |
||
318 | leg[0]->Draw(); |
||
319 | pad5->cd(3); |
||
320 | leg[1]->Draw(); |
||
321 | |||
322 | pad4->cd(); |
||
323 | zacetekMeritve->Draw(); |
||
324 | } |
||
325 | |||
326 | pad1->cd(); |
||
327 | sprintf(buf,"RUN#: %04d (pos %d) FEB#: %s HAPD#: %s",runNumber, HAPDnumber, FEBserialNumber.c_str(),HAPDserialNumber.c_str()); |
||
328 | sn->AddText(buf); |
||
329 | sn->Draw(); |
||
330 | |||
331 | pad2->cd(); |
||
332 | timeStamp->Draw(); |
||
333 | |||
334 | c->Modified(); |
||
335 | c->Update(); |
||
336 | |||
337 | if (save) { |
||
338 | switch (save) { |
||
339 | case 1: sprintf(pdfname,"../modules/%04d/%04d_%s_0_Info.pdf",runNumber,runNumber,HAPDserialNumber.c_str());break; |
||
340 | case 2: sprintf(pdfname,"../modules/%04d/%04d_%s.pdf(",runNumber,runNumber,HAPDserialNumber.c_str());break; |
||
341 | |||
342 | } |
||
343 | c->SaveAs(pdfname,"pdf"); |
||
344 | } |
||
345 | sprintf(pdfname,"../modules/%04d/%04d_%s_out.root",runNumber,runNumber,HAPDserialNumber.c_str()); |
||
346 | SaveToRootWrite(pdfname, HAPDserialNumber.c_str()); |
||
347 | } |
||
348 | for(int k=0;k<3;k++) delete data[k]; |
||
349 | |||
350 | return 0; |
||
351 | } |