Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
289 | f9daq | 1 | |
2 | #include <stdlib.h> |
||
3 | #include <stdio.h> |
||
4 | #include "TH1F.h" |
||
5 | #include "TH2F.h" |
||
6 | #include "TH1.h" |
||
7 | #include "TStyle.h" |
||
8 | #include "TString.h" |
||
9 | #include "TGraph2D.h" |
||
10 | #include "TGraph.h" |
||
11 | #include "TCanvas.h" |
||
12 | #include "TROOT.h" |
||
13 | #include "TFile.h" |
||
14 | #include "TCanvas.h" |
||
15 | |||
16 | int qeplot(char *fname="2010_05_19_mcp9000596_d.dat",int nx=9, int ny=9,int wl=4000, const char *snc="9000596" ){ |
||
17 | /* |
||
18 | hdr[0]=1;//recid |
||
19 | hdr[1]=(nref*5+5)*sizeof(int); |
||
20 | hdr[2]=j; |
||
21 | hdr[3]=xpos; |
||
22 | hdr[4]=ypos; |
||
23 | |||
24 | hdr[5]=xpos;//recid |
||
25 | hdr[6]=ypos; |
||
26 | fhdr[7]=bgrtokref; |
||
27 | fhdr[8]=bgrtok; |
||
28 | hdr[9]=time(NULL); |
||
29 | |||
30 | |||
31 | sdata[0]=wl[0][i]; |
||
32 | sdata[1]=tok[0][i]; |
||
33 | sdata[2]=tok[j][i]; |
||
34 | sdata[3]=qe[0][i]; |
||
35 | sdata[4]=qe[j][i]; |
||
36 | */ |
||
37 | gROOT->Reset(); |
||
38 | char rname[256]; |
||
39 | sprintf(rname,"%s",fname); |
||
40 | sprintf(&rname[strlen(rname)-3],"root"); |
||
41 | FILE *fp=fopen(fname,"r"); |
||
42 | if (!fp) return -1; |
||
43 | TFile *f=new TFile(rname,"RECREATE"); |
||
44 | int hdr[5]; |
||
45 | int hdrp[5]; |
||
46 | float sdata[5]; |
||
47 | float *fhdr=(float *) hdrp; |
||
48 | TGraph2D * gr2d=0; |
||
49 | TGraph * noised=0; |
||
50 | TH2F * h2d=0; |
||
51 | TH1F * h1d=0; |
||
52 | TGraph *noise= new TGraph(); |
||
53 | |||
54 | const float fac=0.3595e-3; |
||
55 | |||
56 | TString sn(snc); |
||
57 | int nwl=46; |
||
58 | float minwl=200; |
||
59 | float maxwl=660; |
||
60 | TString swl; |
||
61 | swl.Form(" %d nm",int(wl/10.)); |
||
62 | |||
63 | if (nx==1) { |
||
64 | noised=new TGraph(); |
||
65 | h1d=new TH1F("h1d",(sn+swl+TString(";y [steps]")).Data(),ny,-0.5,ny-0.5); |
||
66 | h2d=new TH2F("h2d",(sn+swl+TString(";y [steps];wavelength [nm]")).Data(),ny,-0.5,ny-0.5,nwl,minwl-1,maxwl-1); |
||
67 | } |
||
68 | if (ny==1) { |
||
69 | noised=new TGraph(); |
||
70 | h1d=new TH1F("h1d",(sn+swl+TString(";y [steps]")).Data(),nx,-0.5,nx-0.5); |
||
71 | h2d=new TH2F("h2d",(sn+swl+TString(";y [steps];wavelength [nm]")).Data(),nx,-0.5,nx-0.5,nwl,minwl-1,maxwl-1); |
||
72 | } |
||
73 | if (ny>1 && nx>1) { |
||
74 | gr2d=new TGraph2D(ny*nx); |
||
75 | |||
76 | h2d=new TH2F("h2d",(sn+swl+TString(";x [steps];y [steps]")).Data(),nx,-0.5,nx-0.5,ny,-0.5,ny-0.5); |
||
77 | } |
||
78 | int posk0=0; |
||
79 | |||
80 | int icount=0; |
||
81 | while (!feof(fp)){ |
||
82 | int nb=fread(hdr,sizeof(int),5,fp); |
||
83 | // printf("[%d] %d %d %d %d %d\n",nb, hdr[0], hdr[1], hdr[2], hdr[3],hdr[4]); |
||
84 | if (nb!=5) break; |
||
85 | switch (hdr[0]){ |
||
86 | case 3:{ |
||
87 | int nb=fread(hdrp,sizeof(int),5,fp); |
||
88 | printf("x=%u y=%u | i0=%g i1=%g t=%u\t",hdrp[0],hdrp[1],fhdr[2],fhdr[3],hdrp[4]); |
||
89 | hdr[3]=hdrp[0]; |
||
90 | hdr[4]=hdrp[1]; |
||
91 | noise->SetPoint(icount++,hdrp[4],-fhdr[3]); |
||
92 | } |
||
93 | case 2: |
||
94 | case 1:{ |
||
95 | int nref=hdr[1]/sizeof(int)/5-1; |
||
96 | if (hdr[0]==3) nref--; |
||
97 | printf("%d [%d] x=%d y=%d\n",hdr[2],nref, hdr[3],hdr[4]); |
||
98 | int posk=hdr[2]-1; |
||
99 | for (int i=0;i<nref;i++) { |
||
100 | nb=fread(sdata,sizeof(float),5,fp); |
||
101 | |||
102 | if (ny>1 && nx>1) { |
||
103 | if (sdata[0]==wl){ |
||
104 | // printf("%d x=%d y=%d z=%f\n",posk, hdr[3],hdr[4],sdata[4]); |
||
105 | if (hdr[3]==93933) hdr[3]=225001; |
||
106 | if (hdr[3]==154024) hdr[3]=285000; |
||
107 | if (hdr[3]==15350) hdr[3]=277501; |
||
108 | if (hdr[3]==282289) hdr[3]=270001; |
||
109 | |||
110 | h2d->Fill(float(posk/ny),float(posk%ny),sdata[4]); |
||
111 | gr2d->SetPoint(posk0,hdr[3]*fac,hdr[4]*fac,sdata[4]); |
||
112 | posk0++; |
||
113 | |||
114 | } |
||
115 | } else { |
||
116 | if (sdata[0]==wl) { |
||
117 | if (hdr[4]==81679) hdr[4]= 126000; |
||
118 | h1d->Fill(hdr[2],sdata[4]); |
||
119 | if (nx==1) noised->SetPoint(posk0,hdr[4]*fac,sdata[4]); |
||
120 | if (ny==1) noised->SetPoint(posk0,hdr[3]*fac,sdata[4]); |
||
121 | posk0++; |
||
122 | } |
||
123 | h2d->Fill(hdr[2],sdata[0]/10.,sdata[4]); |
||
124 | |||
125 | //printf("%5.0f %g %g %g %g\n",sdata[0],sdata[1],sdata[2],sdata[3],sdata[4]); |
||
126 | } |
||
127 | |||
128 | |||
129 | } |
||
130 | break; |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | |||
135 | |||
136 | gStyle->SetStatColor(0); |
||
137 | //gStyle->SetTitleColor(0); |
||
138 | gStyle->SetCanvasColor(0); |
||
139 | gStyle->SetPadColor(0); |
||
140 | gStyle->SetPadBorderMode(0); |
||
141 | gStyle->SetCanvasBorderMode(0); |
||
142 | gStyle->SetFrameBorderMode(0); |
||
143 | |||
144 | gStyle->SetPalette(1); |
||
145 | gStyle->SetOptStat(0); |
||
146 | |||
147 | |||
148 | if (h2d) h2d->Draw("colz"); |
||
149 | if (h1d) h1d->Draw(); |
||
150 | if (noise) { |
||
151 | TCanvas *c0 = new TCanvas("c0","dark noise vs time"); |
||
152 | |||
153 | noise->SetNameTitle("noise",sn+TString(";time(s);dark current(A)")); |
||
154 | noise->Draw("AWL"); |
||
155 | noise->GetXaxis()->SetTimeDisplay(kTRUE); |
||
156 | |||
157 | noise->SetLineWidth(1); |
||
158 | noise->SetLineColor(kBlue); |
||
159 | noise->SetMarkerStyle(21); |
||
160 | noise->GetXaxis()->SetTimeDisplay(1); // The X axis is a time axis |
||
161 | noise->GetYaxis()->SetLabelSize(0.02); |
||
162 | |||
163 | noise->GetXaxis()->SetLabelSize(0.02); |
||
164 | noise->GetXaxis()->SetTimeFormat("%d.%m.%H:%M"); |
||
165 | noise->GetXaxis()->SetTitle("Time"); |
||
166 | |||
167 | noise->Draw("AWL"); |
||
168 | TString str; |
||
169 | str.Form("_darknoise"); |
||
170 | if (nx==1) str+=TString("_y"); |
||
171 | if (ny==1) str+=TString("_x"); |
||
172 | if (ny>1 && nx>1) str+=TString("_xy"); |
||
173 | c0->SaveAs((sn+str+TString(".png")).Data()); |
||
174 | c0->SaveAs((sn+str+TString(".pdf")).Data()); |
||
175 | |||
176 | } |
||
177 | if (noised && ( nx==1 || ny==1)) { |
||
178 | TCanvas *c = new TCanvas("c","QE1d"); |
||
179 | noised->Draw("AWL"); |
||
180 | |||
181 | |||
182 | TString str; |
||
183 | str.Form("_%d_nm",int(wl/10.)); |
||
184 | |||
185 | |||
186 | if (nx==1) { |
||
187 | str+=TString("_y"); |
||
188 | noised->SetNameTitle("noised",sn+swl+TString(";y [mm]")); |
||
189 | } else { |
||
190 | str+=TString("_x"); |
||
191 | noised->SetNameTitle("noised",sn+swl+TString(";x [mm]")); |
||
192 | } |
||
193 | c->SaveAs((sn+str+TString(".pdf")).Data()); |
||
194 | c->SaveAs((sn+str+TString(".png")).Data()); |
||
195 | } |
||
196 | |||
197 | if (gr2d && nx>1 && ny>1) { |
||
198 | TCanvas *c = new TCanvas("c","QE2d",0,0,600,600); |
||
199 | gr2d->Draw("colz"); |
||
200 | gr2d->SetNameTitle("gr2d",sn+swl+TString(";x [mm];y [mm]")); |
||
201 | ; |
||
202 | TString str; |
||
203 | str.Form("_%d_nm",int(wl/10.)); |
||
204 | c->SaveAs((sn+str+TString("_xy.pdf")).Data()); |
||
205 | c->SaveAs((sn+str+TString("_xy.png")).Data()); |
||
206 | } |
||
207 | f->Write(); |
||
208 | //f->Close(); |
||
209 | //delete f; |
||
210 | return 0; |
||
211 | } |
||
212 | |||
213 | TH2F *wlnormalize(TH2F *h,int n){ |
||
214 | |||
215 | TH2F *hn=(TH2F *)h->Clone(); |
||
216 | int nx=h->GetNbinsX(); |
||
217 | int ny=h->GetNbinsY(); |
||
218 | float max=0; |
||
219 | int nymax=1; |
||
220 | for (int i=1;i<ny+1;i++){ |
||
221 | int nxy=h->GetBin(n,i); |
||
222 | float val=h->GetBinContent(nxy); |
||
223 | if (val>max){ |
||
224 | nymax=i; |
||
225 | max=val; |
||
226 | } |
||
227 | } |
||
228 | printf("Maximum at %d %f\n", nymax,max); |
||
229 | for (int j=1;j<nx+1;j++){ |
||
230 | int nxy0=h->GetBin(j,nymax); |
||
231 | float norm=h->GetBinContent(nxy0); |
||
232 | |||
233 | for (int i=1;i<ny+1;i++){ |
||
234 | int nxy=h->GetBin(j,i); |
||
235 | float val=hn->GetBinContent(nxy); |
||
236 | if (norm) hn->SetBinContent(nxy,val/norm); |
||
237 | else hn->SetBinContent(nxy,val/norm); |
||
238 | } |
||
239 | } |
||
240 | return hn; |
||
241 | } |