Rev 216 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 216 | Rev 218 | ||
|---|---|---|---|
| 1 | #include <stdlib.h> |
1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
2 | #include <stdio.h> |
| 3 | #include <TFile.h> |
3 | #include <TFile.h> |
| 4 | #include <TH1F.h> |
4 | #include <TH1F.h> |
| 5 | #include <TH1D.h> |
5 | #include <TH1D.h> |
| 6 | #include <TH2F.h> |
6 | #include <TH2F.h> |
| 7 | #include <TStyle.h> |
7 | #include <TStyle.h> |
| 8 | #include <TCanvas.h> |
8 | #include <TCanvas.h> |
| 9 | #include <TLegend.h> |
9 | #include <TLegend.h> |
| 10 | // Program za analizo podatkov zajetih z AITSiPMDAQ |
10 | // Program za analizo podatkov zajetih z AITSiPMDAQ |
| 11 | 11 | ||
| 12 | int aitana( const char *fname="a1.dat", int range=10, float cut=500, int *offset = NULL) |
12 | int aitana( const char *fname="a1.dat", int range=10, float cut=500, int *offset = NULL) |
| 13 | { |
13 | { |
| 14 | int debug=0; |
14 | int debug=0; |
| 15 | //int off[4]={507,521,497,459}; |
15 | //int off[4]={507,521,497,459}; |
| 16 | int off[4]={87,125,95,80}; |
16 | int off[4]={87,125,95,80}; |
| 17 | if (offset) for (int i=0;i<4;i++){off[i]=offset[i];}; |
17 | if (offset) for (int i=0;i<4;i++){off[i]=offset[i];}; |
| 18 | 18 | ||
| 19 | gStyle->SetOptStat(0); |
19 | gStyle->SetOptStat(0); |
| 20 | 20 | ||
| 21 | char rootname[0xFF]; |
21 | char rootname[0xFF]; |
| 22 | sprintf(rootname, "%s.root", fname); |
22 | sprintf(rootname, "%s.root", fname); |
| 23 | TFile *froot = new TFile(rootname,"RECREATE"); |
23 | TFile *froot = new TFile(rootname,"RECREATE"); |
| 24 | char histname[128]; |
24 | char histname[128]; |
| 25 | TLegend * leg = new TLegend(0.8, 0.8, 1, 1); |
25 | TLegend * leg = new TLegend(0.8, 0.8, 1, 1); |
| 26 | TH1F *hadc[4]; |
26 | TH1F *hadc[4]; |
| 27 | TH1F *hadcsum; |
27 | TH1F *hadcsum; |
| 28 | TH1F *hadcsumx; |
28 | TH1F *hadcsumx; |
| 29 | TH1F *hadcsumy; |
29 | TH1F *hadcsumy; |
| 30 | TH2F *hxy; |
30 | TH2F *hxy; |
| 31 | TH2F *h2d=NULL; |
31 | TH2F *h2d=NULL; |
| 32 | TH2F *h2dx=NULL; |
32 | TH2F *h2dx=NULL; |
| 33 | TH2F *h2dy=NULL; |
33 | TH2F *h2dy=NULL; |
| 34 | TH2F *hxcorr=NULL; |
34 | TH2F *hxcorr=NULL; |
| 35 | TH2F *hycorr=NULL; |
35 | TH2F *hycorr=NULL; |
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | for (int i=0; i<4; i++) { |
38 | for (int i=0; i<4; i++) { |
| 39 | sprintf(histname,"adc%d",i); |
39 | sprintf(histname,"adc%d",i); |
| 40 | hadc[i]=new TH1F(histname,histname,200,0.5,200*range+0.5); |
40 | hadc[i]=new TH1F(histname,histname,200,0.5,200*range+0.5); |
| 41 | } |
41 | } |
| 42 | hadcsum=new TH1F("adcsum","adcsum",200,0.5,8*200*range+0.5); |
42 | hadcsum=new TH1F("adcsum","adcsum",200,0.5,8*200*range+0.5); |
| 43 | hadcsumx=new TH1F("adcsumx","adcsumx",200,0.5,200*range+0.5); |
43 | hadcsumx=new TH1F("adcsumx","adcsumx",200,0.5,200*range+0.5); |
| 44 | hadcsumy=new TH1F("adcsumy","adcsumy",200,0.5,200*range+0.5); |
44 | hadcsumy=new TH1F("adcsumy","adcsumy",200,0.5,200*range+0.5); |
| 45 | hxy=new TH2F("hxy","Center of gravity;ycog(a.u.);xcog(a.u.)",200,0,1,200,0,1); |
45 | hxy=new TH2F("hxy","Center of gravity;ycog(a.u.);xcog(a.u.)",200,0,1,200,0,1); |
| 46 | 46 | ||
| 47 | FILE *fin=fopen(fname,"rb"); |
47 | FILE *fin=fopen(fname,"rb"); |
| 48 | if (fin==NULL) { |
48 | if (fin==NULL) { |
| 49 | printf("Error opening file %s\n",fname); |
49 | printf("Error opening file %s\n",fname); |
| 50 | return 0; |
50 | return 0; |
| 51 | } |
51 | } |
| 52 | 52 | ||
| 53 | unsigned short hdr[2]; |
53 | unsigned short hdr[2]; |
| 54 | int pos[7]={0,0,0,0,0,0,0}; |
54 | int pos[7]={0,0,0,0,0,0,0}; |
| 55 | int poshdr[9]={0,0,0,0,0,0,0,0,0}; |
55 | int poshdr[9]={0,0,0,0,0,0,0,0,0}; |
| 56 | float b[4], sum=0; |
56 | float b[4], sum=0; |
| 57 | unsigned short a[4]; |
57 | unsigned short a[4]; |
| 58 | unsigned short buf[10000]; |
58 | unsigned short buf[10000]; |
| 59 | float posx=0, posy=0; |
59 | float posx=0, posy=0; |
| 60 | while(!feof(fin)) { |
60 | while(!feof(fin)) { |
| 61 | 61 | ||
| 62 | int stat=fread(hdr,1,4,fin); |
62 | int stat=fread(hdr,1,4,fin); |
| 63 | 63 | ||
| 64 | //if (hdr[0]!= 1 ) printf("#%d %d\n",hdr[0], hdr[1] ); |
64 | //if (hdr[0]!= 1 ) printf("#%d %d\n",hdr[0], hdr[1] ); |
| 65 | 65 | ||
| 66 | stat=fread(buf,1,hdr[1],fin); |
66 | stat=fread(buf,1,hdr[1],fin); |
| 67 | if (stat!=hdr[1]){ |
67 | if (stat!=hdr[1]){ |
| 68 | 68 | ||
| 69 | printf("READ ERROR!\n"); |
69 | printf("READ ERROR!\n"); |
| 70 | break; |
70 | break; |
| 71 | 71 | ||
| 72 | } |
72 | } |
| 73 | switch (hdr[0]) { |
73 | switch (hdr[0]) { |
| 74 | 74 | ||
| 75 | case 0x1: |
75 | case 0x1: |
| 76 | 76 | ||
| 77 | for (int i=0;i<hdr[1]/4/sizeof(unsigned short);i++){ |
77 | for (int i=0;i<hdr[1]/4/sizeof(unsigned short);i++){ |
| 78 | unsigned short *adc=&buf[i*4]; |
78 | unsigned short *adc=&buf[i*4]; |
| 79 | sum=0; |
79 | sum=0; |
| 80 | for (int j=0;j<4;j++){ |
80 | for (int j=0;j<4;j++){ |
| 81 | a[j]=adc[j]&0xFFF; |
81 | a[j]=adc[j]&0xFFF; |
| 82 | sum |
82 | //sum+=a[j]; |
| 83 | hadc[j]->Fill(a[j]); |
83 | hadc[j]->Fill(a[j]); |
| 84 | b[j]=a[j]-off[j]+10; |
84 | b[j]=a[j]-off[j]+10; |
| 85 | sum+=b[j]; |
85 | sum+=b[j]; |
| 86 | } |
86 | } |
| 87 | hadcsum->Fill(sum); |
87 | hadcsum->Fill(sum); |
| 88 | hadcsumx->Fill(a[0]+a[1]); |
88 | hadcsumx->Fill(a[0]+a[1]); |
| 89 | hadcsumy->Fill(a[2]+a[3]); |
89 | hadcsumy->Fill(a[2]+a[3]); |
| 90 | float y = (b[0]+b[1])? b[0]/(b[0]+b[1]) : 0; |
90 | float y = (b[0]+b[1])? b[0]/(b[0]+b[1]) : 0; |
| 91 | float x = (b[2]+b[3])? b[2]/(b[2]+b[3]) : 0; |
91 | float x = (b[2]+b[3])? b[2]/(b[2]+b[3]) : 0; |
| 92 | if (h2d) h2d->Fill(posx,posy,sum); |
92 | if (h2d) h2d->Fill(posx,posy,sum); |
| 93 | if (h2dx) h2dx->Fill(posx,posy,b[0]+b[1]); |
93 | if (h2dx) h2dx->Fill(posx,posy,b[0]+b[1]); |
| 94 | if (h2dy) h2dy->Fill(posx,posy,b[2]+b[3]); |
94 | if (h2dy) h2dy->Fill(posx,posy,b[2]+b[3]); |
| 95 | 95 | ||
| 96 | if (sum>cut) { |
96 | if (sum>cut) { |
| 97 | hxy->Fill(y,x); |
97 | hxy->Fill(y,x); |
| 98 | if (hxcorr) hxcorr->Fill(pos[0],y); |
98 | if (hxcorr) hxcorr->Fill(pos[0],y); |
| 99 | if (hycorr) hycorr->Fill(pos[1],x); |
99 | if (hycorr) hycorr->Fill(pos[1],x); |
| 100 | } |
100 | } |
| 101 | 101 | ||
| 102 | } |
102 | } |
| 103 | break; |
103 | break; |
| 104 | case 0x2:{ |
104 | case 0x2:{ |
| 105 | int *p= (int *) &buf[0]; |
105 | int *p= (int *) &buf[0]; |
| 106 | for (int k=0;k<7;k++) pos[k]=p[k]; |
106 | for (int k=0;k<7;k++) pos[k]=p[k]; |
| 107 | printf("Position: %d %d\n",pos[3], pos[4] ); |
107 | printf("Position: %d %d\n",pos[3], pos[4] ); |
| 108 | posx = poshdr[0]+pos[3]* poshdr[3]; |
108 | posx = poshdr[0]+pos[3]* poshdr[3]; |
| 109 | posy = poshdr[1]+pos[4]* poshdr[4]; |
109 | posy = poshdr[1]+pos[4]* poshdr[4]; |
| 110 | } |
110 | } |
| 111 | break; |
111 | break; |
| 112 | case 0x3:{ |
112 | case 0x3:{ |
| 113 | int *p= (int *) &buf[0]; |
113 | int *p= (int *) &buf[0]; |
| 114 | for (int k=0;k<9;k++) poshdr[k]=p[k]; |
114 | for (int k=0;k<9;k++) poshdr[k]=p[k]; |
| 115 | 115 | ||
| 116 | h2d=new TH2F("h2d","Position dependency of sum;x(step);y(step)", |
116 | h2d=new TH2F("h2d","Position dependency of sum;x(step);y(step)", |
| 117 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), |
117 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), |
| 118 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5) ); |
118 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5) ); |
| 119 | 119 | ||
| 120 | h2dx=new TH2F("h2dx","Position dependency of xsum;x(step);y(step)", |
120 | h2dx=new TH2F("h2dx","Position dependency of xsum;x(step);y(step)", |
| 121 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), |
121 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), |
| 122 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5) ); |
122 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5) ); |
| 123 | 123 | ||
| 124 | h2dy=new TH2F("h2dy","Position dependency of ysum;x(step);y(step)", |
124 | h2dy=new TH2F("h2dy","Position dependency of ysum;x(step);y(step)", |
| 125 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), |
125 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), |
| 126 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5) ); |
126 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5) ); |
| 127 | 127 | ||
| 128 | 128 | ||
| 129 | hxcorr=new TH2F("hxcorr","Correlation stage position vs cog;x(step);xcog(a.u.)", |
129 | hxcorr=new TH2F("hxcorr","Correlation stage position vs cog;x(step);xcog(a.u.)", |
| 130 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), 100 , 0, 1); |
130 | poshdr[6],poshdr[0]-poshdr[3]*0.5 ,poshdr[0]+poshdr[6]*(poshdr[3]-0.5), 100 , 0, 1); |
| 131 | 131 | ||
| 132 | hycorr=new TH2F("hycorr","Correlation stage position vs cog;y(step);ycog(a.u.)", |
132 | hycorr=new TH2F("hycorr","Correlation stage position vs cog;y(step);ycog(a.u.)", |
| 133 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5), 100 , 0, 1); |
133 | poshdr[7],poshdr[1]-poshdr[4]*0.5 ,poshdr[1]+poshdr[7]*(poshdr[4]-0.5), 100 , 0, 1); |
| 134 | } |
134 | } |
| 135 | break; |
135 | break; |
| 136 | default: break; |
136 | default: break; |
| 137 | } |
137 | } |
| 138 | } |
138 | } |
| 139 | 139 | ||
| 140 | TCanvas* c= new TCanvas("c","ADC",750,50,700,700); |
140 | TCanvas* c= new TCanvas("c","ADC",750,50,700,700); |
| 141 | sprintf(rootname, "%s.pdf", fname); |
141 | sprintf(rootname, "%s.pdf", fname); |
| 142 | c->Print(TString(rootname) + "[","pdf"); |
142 | c->Print(TString(rootname) + "[","pdf"); |
| 143 | 143 | ||
| 144 | c->Divide(2,3); |
144 | c->Divide(2,3); |
| 145 | for (int i=0; i<4; i++) { |
145 | for (int i=0; i<4; i++) { |
| 146 | c->cd(i+1)->SetLogy(); |
146 | c->cd(i+1)->SetLogy(); |
| 147 | hadc[i]->DrawCopy(); |
147 | hadc[i]->DrawCopy(); |
| 148 | } |
148 | } |
| 149 | c->cd(5)->SetLogy();hadcsumx->DrawCopy(); |
149 | c->cd(5)->SetLogy();hadcsumx->DrawCopy(); |
| 150 | c->cd(6)->SetLogy();hadcsumy->DrawCopy(); |
150 | c->cd(6)->SetLogy();hadcsumy->DrawCopy(); |
| 151 | 151 | ||
| 152 | /* |
152 | /* |
| 153 | c->cd(7);hadcsumx->DrawCopy(); |
153 | c->cd(7);hadcsumx->DrawCopy(); |
| 154 | hadc[0]->DrawCopy("same"); |
154 | hadc[0]->DrawCopy("same"); |
| 155 | hadc[1]->DrawCopy("same"); |
155 | hadc[1]->DrawCopy("same"); |
| 156 | c->cd(8);hadcsumy->DrawCopy(); |
156 | c->cd(8);hadcsumy->DrawCopy(); |
| 157 | hadc[2]->DrawCopy("same"); |
157 | hadc[2]->DrawCopy("same"); |
| 158 | hadc[3]->DrawCopy("same"); |
158 | hadc[3]->DrawCopy("same"); |
| 159 | */ |
159 | */ |
| 160 | c->Print(rootname,"pdf"); |
160 | c->Print(rootname,"pdf"); |
| 161 | 161 | ||
| 162 | 162 | ||
| 163 | c= new TCanvas("c1","ait reconstruction",750,50,700,700); |
163 | c= new TCanvas("c1","ait reconstruction",750,50,700,700); |
| 164 | c->Divide(2,3); |
164 | c->Divide(2,3); |
| 165 | if (!h2d){ |
165 | if (!h2d){ |
| 166 | c->Clear(); |
166 | c->Clear(); |
| 167 | c->Divide(1,4); |
167 | c->Divide(1,4); |
| 168 | } |
168 | } |
| 169 | 169 | ||
| 170 | 170 | ||
| 171 | hxy->SetMinimum(-1); |
171 | hxy->SetMinimum(-1); |
| 172 | hxy->SetMaximum(1000); |
172 | hxy->SetMaximum(1000); |
| 173 | c->cd(1)->SetLogz(); hxy->DrawCopy("colz"); |
173 | c->cd(1)->SetLogz(); hxy->DrawCopy("colz"); |
| 174 | c->cd(4)->SetLogy(); hadcsum->DrawCopy(); |
174 | c->cd(4)->SetLogy(); hadcsum->DrawCopy(); |
| 175 | 175 | ||
| 176 | if (h2d){ |
176 | if (h2d){ |
| 177 | hxcorr->SetMinimum(-1); |
177 | hxcorr->SetMinimum(-1); |
| 178 | hycorr->SetMinimum(-1); |
178 | hycorr->SetMinimum(-1); |
| 179 | c->cd(5); hxcorr->DrawCopy("colz"); |
179 | c->cd(5); hxcorr->DrawCopy("colz"); |
| 180 | c->cd(6); hycorr->DrawCopy("colz"); |
180 | c->cd(6); hycorr->DrawCopy("colz"); |
| 181 | } |
181 | } |
| 182 | TH1D *px = hxy->ProjectionX("_px",0,-1); |
182 | TH1D *px = hxy->ProjectionX("_px",0,-1); |
| 183 | c->cd(2); px->DrawCopy(); |
183 | c->cd(2); px->DrawCopy(); |
| 184 | 184 | ||
| 185 | TH1D *py = hxy->ProjectionY("_py",0,-1); |
185 | TH1D *py = hxy->ProjectionY("_py",0,-1); |
| 186 | c->cd(3); py->DrawCopy(); |
186 | c->cd(3); py->DrawCopy(); |
| 187 | 187 | ||
| 188 | c->Modified(); |
188 | c->Modified(); |
| 189 | c->Update(); |
189 | c->Update(); |
| 190 | c->Print(rootname,"pdf"); |
190 | c->Print(rootname,"pdf"); |
| 191 | 191 | ||
| 192 | 192 | ||
| 193 | if (h2d){ |
193 | if (h2d){ |
| 194 | c= new TCanvas("c2","position dependence sum, xsum, ysum",750,50,700,700); |
194 | c= new TCanvas("c2","position dependence sum, xsum, ysum",750,50,700,700); |
| 195 | c->Divide(1,3); |
195 | c->Divide(1,3); |
| 196 | c->cd(1); h2d->DrawCopy("colz"); |
196 | c->cd(1); h2d->DrawCopy("colz"); |
| 197 | c->cd(2); h2dx->DrawCopy("colz"); |
197 | c->cd(2); h2dx->DrawCopy("colz"); |
| 198 | c->cd(3); h2dy->DrawCopy("colz"); |
198 | c->cd(3); h2dy->DrawCopy("colz"); |
| 199 | c->Modified(); |
199 | c->Modified(); |
| 200 | c->Update(); |
200 | c->Update(); |
| 201 | c->Print(rootname,"pdf"); |
201 | c->Print(rootname,"pdf"); |
| 202 | } |
202 | } |
| 203 | 203 | ||
| 204 | c->Print(TString(rootname) + "]","pdf"); |
204 | c->Print(TString(rootname) + "]","pdf"); |
| 205 | froot->Write(); |
205 | froot->Write(); |
| 206 | froot->Close(); |
206 | froot->Close(); |
| 207 | if (fin) fclose(fin); |
207 | if (fin) fclose(fin); |
| 208 | 208 | ||
| 209 | return 0; |
209 | return 0; |
| 210 | } |
210 | } |
| 211 | 211 | ||