Rev 101 | Rev 180 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 101 | Rev 175 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | #include <stdio.h> |
9 | #include <stdio.h> |
10 | 10 | ||
11 | #define DATA_PATH "./data/" |
11 | #define DATA_PATH "./data/" |
12 | #define CFRAC 0.4 |
12 | #define CFRAC 0.4 |
13 | #define DWIDTH 1024 |
13 | #define DWIDTH 1024 |
14 | void drs(int nev=1000, int updfrq=20, const char *FileName=" |
14 | void drs(int nev=1000, int updfrq=20, const char *FileName="drs000.dat", int trgch=0, int debug=0) |
15 | { |
15 | { |
16 | int i |
16 | int i,ich,iev; |
17 | int stat; |
17 | int stat; |
18 | char histname[128]; |
18 | char histname[128]; |
19 | // char FileName[300]="./data/n2.dat"; |
19 | // char FileName[300]="./data/n2.dat"; |
20 | FILE *fin; |
20 | FILE *fin; |
21 | 21 | ||
22 | char recid[5]="SAMO"; |
22 | char recid[5]="SAMO"; |
23 | unsigned short *srecid = (unsigned short *) &recid[0]; |
23 | unsigned short *srecid = (unsigned short *) &recid[0]; |
24 | unsigned int * irecid; |
- | |
- | 24 | ||
25 | struct evrec { |
25 | struct evrec { |
26 | unsigned long evn; |
26 | unsigned long evn; |
27 | unsigned short tYear,tMonth,tDay,tHour,tMin,tSec,tmSec, |
27 | unsigned short tYear,tMonth,tDay,tHour,tMin,tSec,tmSec,rc; |
28 | } evrec; |
28 | } evrec; |
29 | 29 | ||
30 | float dtdata[4][DWIDTH]; |
30 | float dtdata[4][DWIDTH]; |
31 | float tcdata[4][DWIDTH]; |
31 | float tcdata[4][DWIDTH]; |
32 | float tccalib[4]; |
32 | float tccalib[4]; |
- | 33 | float scaler[4]; |
|
- | 34 | float *t; |
|
- | 35 | float *y; |
|
- | 36 | float *ay; |
|
33 | 37 | ||
34 | short lwfm[4]; |
38 | short lwfm[4]; |
35 | int nwfm[4]; |
39 | int nwfm[4]; |
36 | int board; |
40 | int board; |
- | 41 | int version; |
|
37 | 42 | ||
38 | // int imin[4]={250,250,250,250}; |
- | |
39 | // int imax[4]={750,750,750,750}; |
- | |
- | 43 | ||
40 | unsigned short ichdat[4][DWIDTH]; |
44 | unsigned short ichdat[4][DWIDTH]; |
- | 45 | float chdat[4][DWIDTH]; |
|
41 | float |
46 | float achdat[4][DWIDTH]; |
- | 47 | float chmax[4][2]; |
|
- | 48 | float chmin[4][2]; |
|
42 | float letime[4][2],cftime[4][2],qdc[4]; |
49 | float letime[4][2],cftime[4][2],qdc[4]; |
43 | // float threshold[4][2]={{0.,-0.02},{0.,0.},{0.,0.},{0.,-0.25}}; |
50 | // float threshold[4][2]={{0.,-0.02},{0.,0.},{0.,0.},{0.,-0.25}}; |
44 | // float twin[4][2]={{120.,130.},{100.,150.},{100.,150.},{70.,90.}}; |
51 | // float twin[4][2]={{120.,130.},{100.,150.},{100.,150.},{70.,90.}}; |
45 | // float adcgate[4][2]={{124.,136.},{120.,140.},{120.,140.},{70.,90.}}; |
52 | // float adcgate[4][2]={{124.,136.},{120.,140.},{120.,140.},{70.,90.}}; |
46 | // float threshold[4][2]={{0.,-0.05},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
53 | // float threshold[4][2]={{0.,-0.05},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
47 | // float twin[4][2]={{80.,100.},{80.,100.},{90.,110.},{50.,70.}}; |
54 | // float twin[4][2]={{80.,100.},{80.,100.},{90.,110.},{50.,70.}}; |
48 | // float adcgate[4][2]={{80.,110.},{80.,110.},{90.,110.},{50.,70.}}; |
55 | // float adcgate[4][2]={{80.,110.},{80.,110.},{90.,110.},{50.,70.}}; |
49 | float threshold[4][2]={{0.,-0.1},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
56 | float threshold[4][2]={{0.,-0.1 },{0.,-0.05 },{0.,-0.25 },{0.,-0.25}}; |
50 | float twin[4][2]={{100.,120.},{100.,120.},{40.,130.},{60.,80.}}; |
57 | float twin[4][2] ={{100.,120.},{100.,120.},{40.,130. },{60.,80. }}; |
51 | float adcgate[4][2]={{105.,125.},{105.,125.},{110.,130.},{60.,80.}}; |
58 | float adcgate[4][2] ={{105.,125.},{105.,125.},{110.,130.},{60.,80. }}; |
52 | float vcut[4][2]={{-1,1},{-1,1},{-1,1},{-1,1}}; |
59 | float vcut[4][2] ={{-1,1 },{-1,1 },{-1,1 },{-1,1 }}; |
53 | 60 | ||
54 | // gROOT->Reset(); |
61 | // gROOT->Reset(); |
55 | 62 | ||
56 | gStyle->SetOptStat(1111111); |
63 | gStyle->SetOptStat(1111111); |
57 | // gStyle->SetPalette(52); |
64 | // gStyle->SetPalette(52); |
Line 113... | Line 120... | ||
113 | } |
120 | } |
114 | leg->Draw(); |
121 | leg->Draw(); |
115 | h2_ctalk=new TH2F("ctalk","ctalk",250,0.,0.5,250,0.,0.5); |
122 | h2_ctalk=new TH2F("ctalk","ctalk",250,0.,0.5,250,0.,0.5); |
116 | 123 | ||
117 | fin=fopen(FileName,"rb"); |
124 | fin=fopen(FileName,"rb"); |
- | 125 | if (fin==NULL) { |
|
- | 126 | printf("Error opening file %s\n",FileName); |
|
- | 127 | return; |
|
118 | 128 | } |
|
119 | printf("%s, %lu\n",recid,sizeof(evrec)); |
129 | printf("%s, %lu\n",recid,sizeof(evrec)); |
120 | 130 | ||
121 | 131 | ||
122 | for ( |
132 | for (ich=0;ich<4;ich++){ |
123 | nwfm[ |
133 | nwfm[ich]=0; |
124 | for ( |
134 | for (i=0;i<DWIDTH;i++){ |
125 | achdat[ |
135 | achdat[ich][i]=0; |
126 | } |
136 | } |
127 | } |
137 | } |
128 | unsigned int trgcell = 0; |
138 | unsigned int trgcell = 0; |
129 | int event = -1; |
139 | int event = -1; |
130 | 140 | ||
Line 135... | Line 145... | ||
135 | if (debug){ |
145 | if (debug){ |
136 | if (recid[1]=='#') printf("%c%c%u\n",recid[0],recid[1],srecid[1]); |
146 | if (recid[1]=='#') printf("%c%c%u\n",recid[0],recid[1],srecid[1]); |
137 | else printf("%s\n",recid ); |
147 | else printf("%s\n",recid ); |
138 | } |
148 | } |
139 | switch (recid[0]){ |
149 | switch (recid[0]){ |
- | 150 | case 'D': // DRS |
|
- | 151 | version = atoi(&recid[3]); |
|
- | 152 | break; |
|
140 | case 'T': |
153 | case 'T': // TIME |
141 | switch (recid[1]){ |
154 | switch (recid[1]){ |
142 | case 'I': |
155 | case 'I': |
- | 156 | event=0; |
|
- | 157 | if (version ==0) version++; |
|
- | 158 | break; |
|
143 | case '#': trgcell = srecid[1]; break; |
159 | case '#': trgcell = srecid[1]; break; |
144 | } |
160 | } |
145 | break; |
161 | break; |
146 | case 'B': |
162 | case 'B': |
147 | board = srecid[1]; |
163 | board = srecid[1]; |
148 | break; |
164 | break; |
149 | case 'C': |
165 | case 'C': |
150 | sscanf(recid,"C%d",&ich); |
166 | sscanf(recid,"C%d",&ich); |
151 | ich=ich-1; |
167 | ich=ich-1; |
152 | if (event) { |
168 | if (event) { |
- | 169 | if (version>1) stat=fread(&scaler[ich],1,sizeof(float),fin); |
|
153 | stat=fread(ichdat[ich],1,sizeof(ichdat[ich]),fin); |
170 | stat=fread(ichdat[ich],1,sizeof(ichdat[ich]),fin); |
154 | } else { |
171 | } else { |
- | 172 | ||
155 | stat=fread(dtdata[ich],1,sizeof(float)*DWIDTH,fin); |
173 | stat=fread(dtdata[ich],1,sizeof(float)*DWIDTH,fin); |
156 | 174 | ||
157 | } |
175 | } |
158 | break; |
176 | break; |
159 | case 'E': |
177 | case 'E': |
160 | stat=fread(&evrec.evn,1,sizeof(evrec),fin); |
178 | stat=fread(&evrec.evn,1,sizeof(evrec),fin); |
161 | iev++; |
179 | iev++; |
- | 180 | if (!version) { |
|
- | 181 | stat=fread(dtdata[0],1,sizeof(float)*DWIDTH,fin); |
|
- | 182 | } |
|
162 | event=1; |
183 | event=1; |
163 | break; |
184 | break; |
164 | default: |
185 | default: |
165 | printf("Unknown header!\n"); |
186 | printf("Unknown header! %s\n", recid); |
166 | break; |
187 | break; |
167 | } |
188 | } |
168 | 189 | ||
169 | 190 | ||
170 | if (recid[0] == 'E'){ |
191 | if (recid[0] == 'E'){ |
Line 181... | Line 202... | ||
181 | h2_ctalk->Fill(-chmin[0][0],-chmin[1][0]); |
202 | h2_ctalk->Fill(-chmin[0][0],-chmin[1][0]); |
182 | } |
203 | } |
183 | if (event<1) continue; |
204 | if (event<1) continue; |
184 | if (recid[0]!='C') continue; |
205 | if (recid[0]!='C') continue; |
185 | 206 | ||
186 | - | ||
187 | 207 | ||
188 | lwfm[ich]=0; |
208 | lwfm[ich]=0; |
189 | qdc[ich]=0; |
209 | qdc[ich]=0; |
190 | chmax[ich][0]=-1; chmax[ich][1]=-1; |
210 | chmax[ich][0]=-1; chmax[ich][1]=-1; |
191 | chmin[ich][0]=1; chmin[ich][1]=-1; |
211 | chmin[ich][0]=1; chmin[ich][1]=-1; |
192 | letime[ich][0]=-1.; letime[ich][1]=-1.; |
212 | letime[ich][0]=-1.; letime[ich][1]=-1.; |
193 | cftime[ich][0]=-1.; cftime[ich][1]=-1.; |
213 | cftime[ich][0]=-1.; cftime[ich][1]=-1.; |
194 | 214 | ||
195 | 215 | ||
196 |
|
216 | lwfm[ich]=1; |
197 |
|
217 | nwfm[ich]+=1; |
- | 218 | ||
- | 219 | ||
- | 220 | ||
- | 221 | t = &tcdata[ich][0]; |
|
- | 222 | y = &chdat[ich][0]; |
|
- | 223 | ay = &achdat[ich][0]; |
|
198 | 224 | ||
199 | float sum=0; |
225 | float sum=0; |
200 |
|
226 | for (i=0;i<DWIDTH;i++) { |
201 |
|
227 | sum+= dtdata[ich][(i+trgcell)%DWIDTH]; |
202 |
|
228 | if (version) t[i]=sum; |
- | 229 | else t[i]=dtdata[0][i]; // old format |
|
203 |
|
230 | } |
204 |
|
231 | tccalib[ich]=t[(DWIDTH-trgcell)%DWIDTH]; |
205 | 232 | ||
206 |
|
233 | for (i=0;i<DWIDTH;i++) { |
207 |
|
234 | if (version) t[i]-=(tccalib[ich]-tccalib[0]); // assume ich 0 is connected and always first in the data |
- | 235 | y[i]=-0.5+(float)ichdat[ich][i]/0xFFFF; |
|
- | 236 | if (version) y[i]+=evrec.rc; |
|
- | 237 | h2_dpo[ich]->Fill(t[i],y[i]); |
|
- | 238 | gr_wfm[ich]->SetPoint(i,t[i],y[i]+0.05*(ich-1)); |
|
- | 239 | } |
|
208 |
|
240 | |
209 | 241 | ||
210 | for |
242 | for (i=0;i<DWIDTH;i++) { |
211 |
|
243 | // accumulated waveforms |
212 |
|
244 | ay[i]+=y[i]; |
- | 245 | ||
213 |
|
246 | // signal minumum |
214 |
|
247 | if (y[i]>chmax[ich][0]) { |
215 |
|
248 | chmax[ich][0]=y[i]; |
216 |
|
249 | chmax[ich][1]=t[i]; |
217 |
|
250 | } |
- | 251 | ||
- | 252 | // signal maximum |
|
218 |
|
253 | if (y[i]<chmin[ich][0]) { |
219 |
|
254 | chmin[ich][0]=y[i]; |
220 |
|
255 | chmin[ich][1]=t[i]; |
221 |
|
256 | } |
222 |
|
257 | float t0 = t[i]; |
223 |
|
258 | float t0p = t[i+1]; |
224 |
|
259 | float t0n = t[i-1]; |
225 | - | ||
226 | if ((tdata>adcgate[ich][0])&&(tdata<adcgate[ich][1])) { |
- | |
227 | qdc[ich]+=-chdat[ich][i]*(tdatap-tdatan)/2; |
- | |
228 |
|
260 | // charge in the range |
229 |
|
261 | if ((t0>adcgate[ich][0])&&(t0<adcgate[ich][1])) { |
230 | if ((chdat[ich][i]<threshold[ich][1])&&(letime[ich][1]<0.)) { |
- | |
231 |
|
262 | qdc[ich]+=-y[i]*(t0p-t0n)/2; |
232 | (threshold[ich][1]-chdat[ich][i-1])/(chdat[ich][i]-chdat[ich][i-1]); |
- | |
233 | // preveri za 0!! |
- | |
234 | } |
- | |
235 | } |
- | |
236 | } |
263 | } |
237 | 264 | } |
|
238 | 265 | ||
239 | i=ich; |
- | |
240 | - | ||
241 | - | ||
242 | for |
266 | for (i=1;i<DWIDTH-1;i++) { |
243 |
|
267 | float t0 = t[i]; |
244 |
|
268 | float t0p = t[i+1]; |
245 |
|
269 | float t0n = t[i-1]; |
246 |
|
270 | // leading edge in the range |
247 |
|
271 | if ((t0>twin[ich][0])&&(t0<twin[ich][1])) { |
248 | if (( |
272 | if ((y[i]<threshold[ich][1])&&(letime[ich][1]<0.)) { |
249 |
|
273 | letime[ich][1]=t0n+(t0-t0n)*(threshold[ich][1]-y[i-1])/(y[i]-y[i-1]); |
- | 274 | } |
|
250 |
|
275 | // constant fraction time in the range |
251 |
|
276 | if ((chmin[ich][0]<threshold[ich][1])&&(y[i]<chmin[ich][0]*CFRAC)&&(cftime[ich][1]<0.)) { |
252 |
|
277 | cftime[ich][1]=t0n+(t0-t0n)*(chmin[ich][0]*CFRAC-y[i-1])/(y[i]-y[i-1]); |
253 | } |
- | |
254 | } |
278 | } |
255 | } |
279 | } |
256 | 280 | } |
|
257 | 281 | ||
258 |
|
282 | if ((chmax[ich][1]>twin[ich][0])&&(chmax[ich][1]<twin[ich][1])) { |
259 |
|
283 | h1_chmax[ich]->Fill(chmax[ich][0]); |
260 |
|
284 | if (chmax[ich][0]>threshold[ich][0]) h1_chmaxt[ich]->Fill(chmax[ich][1]); |
261 |
|
285 | } |
262 |
|
286 | if ((chmin[ich][1]>twin[ich][0])&&(chmin[ich][1]<twin[ich][1])) { |
263 |
|
287 | h1_chmin[ich]->Fill(chmin[ich][0]); |
264 |
|
288 | if (chmin[ich][0]<threshold[ich][1]) h1_chmint[ich]->Fill(chmin[ich][1]); |
265 |
|
289 | } |
266 |
|
290 | h1_qdc[ich]->Fill(qdc[ich]); |
267 |
|
291 | h1_letime[ich][1]->Fill(letime[ich][1]); |
268 |
|
292 | h1_cftime[ich][1]->Fill(cftime[ich][1]); |
269 | //84,56 |
- | |
270 | - | ||
271 | - | ||
272 | - | ||
273 | 293 | ||
274 | if (!(iev%updfrq)) { |
294 | if (!(iev%updfrq)) { |
275 | c_wfm->Update(); |
295 | c_wfm->Update(); |
276 | for ( |
296 | for (i=0;i<DWIDTH;i++) { |
277 |
|
297 | ay[i]/=nwfm[ich]; |
278 | gr_wfm[ |
298 | gr_wfm[ich]->SetPoint(i,t[i],ay[i]+0.05*(ich-1)); |
279 | } |
299 | } |
280 | printf("processing event %d\n",iev); |
300 | printf("processing event %d\n",iev); |
281 | } |
301 | } |
282 | - | ||
283 | - | ||
284 | - | ||
285 | - | ||
286 | } |
302 | } |
287 | - | ||
288 | 303 | ||
289 | printf("number of events: %d\n",iev); |
304 | printf("number of events: %d\n",iev); |
290 | fclose(fin); |
305 | fclose(fin); |
291 | 306 | ||
292 | TCanvas* c_dpo= new TCanvas("c_dpo","DPO",750,50,700,700); |
307 | TCanvas* c_dpo= new TCanvas("c_dpo","DPO",750,50,700,700); |
Line 294... | Line 309... | ||
294 | for (i=0;i<4;i++) {c_dpo->cd(i+1);h2_dpo[i]->Draw("colz");} |
309 | for (i=0;i<4;i++) {c_dpo->cd(i+1);h2_dpo[i]->Draw("colz");} |
295 | 310 | ||
296 | TCanvas* c_cftdif= new TCanvas("c_cftdif","DPO",750,50,700,700); |
311 | TCanvas* c_cftdif= new TCanvas("c_cftdif","DPO",750,50,700,700); |
297 | c_cftdif->Divide(2,2); |
312 | c_cftdif->Divide(2,2); |
298 | for (i=0;i<4;i++) {c_cftdif->cd(i+1);h1_cftdif[i]->Draw();} |
313 | for (i=0;i<4;i++) {c_cftdif->cd(i+1);h1_cftdif[i]->Draw();} |
299 | - | ||
300 | return; |
314 | return; |
301 | } |
315 | } |