Rev 175 | Rev 182 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 175 | Rev 180 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | #include "TStyle.h" |
5 | #include "TStyle.h" |
6 | #include "TLegend.h" |
6 | #include "TLegend.h" |
7 | //#include "TROOT.h" |
7 | //#include "TROOT.h" |
8 | 8 | ||
9 | #include <stdio.h> |
9 | #include <stdio.h> |
- | 10 | #include <time.h> |
|
10 | 11 | ||
11 | #define DATA_PATH "./data/" |
12 | #define DATA_PATH "./data/" |
12 | #define CFRAC 0.4 |
13 | #define CFRAC 0.4 |
13 | #define DWIDTH 1024 |
14 | #define DWIDTH 1024 |
- | 15 | #define NCH 4 |
|
- | 16 | #include "drs.h" |
|
- | 17 | ||
- | 18 | ClassImp (drs) |
|
- | 19 | ||
14 |
|
20 | drs::drs( const char *FileName, int nch, DrsChannel* d, int trgch, int nev, int updfrq) |
15 | { |
21 | { |
- | 22 | int debug=0; |
|
16 | int i,ich,iev; |
23 | int i,ich,iev; |
17 | int stat; |
24 | int stat; |
18 | char histname[128]; |
25 | char histname[128]; |
19 | // char FileName[300]="./data/n2.dat"; |
26 | // char FileName[300]="./data/n2.dat"; |
20 | FILE *fin; |
27 | FILE *fin; |
21 | 28 | ||
22 | char recid[5]="SAMO"; |
29 | char recid[5]="SAMO"; |
23 | unsigned short *srecid = (unsigned short *) &recid[0]; |
30 | unsigned short *srecid = (unsigned short *) &recid[0]; |
24 | 31 | ||
25 | struct evrec { |
32 | struct evrec { |
26 | unsigned long evn; |
33 | unsigned long evn; |
27 | unsigned short tYear,tMonth,tDay,tHour,tMin,tSec,tmSec,rc; |
34 | unsigned short tYear,tMonth,tDay,tHour,tMin,tSec,tmSec,rc; |
28 | } evrec; |
35 | } evrec; |
29 | 36 | ||
30 | float dtdata[ |
37 | float dtdata[NCH][DWIDTH]; |
31 | float tcdata[ |
38 | float tcdata[NCH][DWIDTH]; |
32 | float tccalib[ |
39 | float tccalib[NCH]; |
33 | float scaler[ |
40 | float scaler[NCH]; |
34 | float *t; |
41 | float *t; |
35 | float *y; |
42 | float *y; |
36 | float *ay; |
43 | float *ay; |
37 | 44 | ||
38 | short lwfm[ |
45 | short lwfm[NCH]; |
39 | int nwfm[ |
46 | int nwfm[NCH]; |
40 | int board; |
47 | int board; |
41 | int version; |
48 | int version; |
42 | 49 | ||
43 | 50 | ||
44 | unsigned |
51 | unsigned short ichdat[NCH][DWIDTH]; |
45 | float chdat[ |
52 | float chdat[NCH][DWIDTH]; |
46 | float achdat[ |
53 | float achdat[NCH][DWIDTH]; |
47 | float chmax[ |
54 | float chmax[NCH][2]; |
48 | float chmin[ |
55 | float chmin[NCH][2]; |
49 | float letime |
56 | float letime[NCH],cftime[NCH],qdc[NCH]; |
50 | // float threshold[4][2]={{0.,-0.02},{0.,0.},{0.,0.},{0.,-0.25}}; |
- | |
51 | // float twin[4][2]={{120.,130.},{100.,150.},{100.,150.},{70.,90.}}; |
- | |
52 | // float adcgate[4][2]={{124.,136.},{120.,140.},{120.,140.},{70.,90.}}; |
- | |
53 | // float threshold[4][2]={{0.,-0.05},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
- | |
54 | // float twin[4][2]={{80.,100.},{80.,100.},{90.,110.},{50.,70.}}; |
- | |
55 | // float adcgate[4][2]={{80.,110.},{80.,110.},{90.,110.},{50.,70.}}; |
- | |
56 | float threshold[4][2]={{0.,-0.1 },{0.,-0.05 },{0.,-0.25 },{0.,-0.25}}; |
- | |
57 | float twin[4][2] ={{100.,120.},{100.,120.},{40.,130. },{60.,80. }}; |
- | |
58 | float adcgate[4][2] ={{105.,125.},{105.,125.},{110.,130.},{60.,80. }}; |
- | |
59 | float vcut[4][2] ={{-1,1 },{-1,1 },{-1,1 },{-1,1 }}; |
- | |
- | 57 | ||
60 | 58 | ||
61 | // gROOT->Reset(); |
59 | // gROOT->Reset(); |
62 | 60 | ||
63 | gStyle->SetOptStat(1111111); |
61 | gStyle->SetOptStat(1111111); |
64 | // gStyle->SetPalette(52); |
62 | // gStyle->SetPalette(52); |
65 | 63 | ||
66 | TH1F *h1_chmax[ |
64 | TH1F *h1_chmax[NCH]; |
67 | TH1F *h1_chmaxt[ |
65 | TH1F *h1_chmaxt[NCH]; |
68 | TH1F *h1_chmin[ |
66 | TH1F *h1_chmin[NCH]; |
69 | TH1F *h1_chmint[ |
67 | TH1F *h1_chmint[NCH]; |
70 | TH1F *h1_letime[ |
68 | TH1F *h1_letime[NCH]; |
71 | TH1F *h1_cftime[ |
69 | TH1F *h1_cftime[NCH]; |
72 | TH1F *h1_cftdif[ |
70 | TH1F *h1_cftdif[NCH]; |
73 | TH1F *h1_qdc[ |
71 | TH1F *h1_qdc[NCH]; |
74 | TH2F *h2_dpo[ |
72 | TH2F *h2_dpo[NCH]; |
75 | TH2F *h2_tdcadc[ |
73 | TH2F *h2_tdcadc[NCH]; |
76 | TH2F *h2_ctdcadc[ |
74 | TH2F *h2_ctdcadc[NCH]; |
77 | TH2F *h2_ctalk; |
75 | TH2F *h2_ctalk; |
78 | TGraph *gr_wfm[ |
76 | TGraph *gr_wfm[NCH]; |
79 | TCanvas *c_wfm= new TCanvas("c_wfm","WFM",50,50,700,700); |
77 | TCanvas *c_wfm= new TCanvas("c_wfm","WFM",50,50,700,700); |
80 | TLegend *leg = new TLegend(0.8, 0.8, 1, 1); |
78 | TLegend *leg = new TLegend(0.8, 0.8, 1, 1); |
81 | c_wfm->Divide(1,1); |
79 | c_wfm->Divide(1,1); |
82 | c_wfm->cd(1); |
80 | c_wfm->cd(1); |
83 | 81 | ||
84 | for |
82 | for (i=0; i<nch; i++) { |
85 | sprintf(histname,"chmax_%02d",i); |
83 | sprintf(histname,"chmax_%02d",i); |
86 | h1_chmax[i]=new TH1F(histname,histname,1100,-0.55,0.55); |
84 | h1_chmax[i]=new TH1F(histname,histname,1100,-0.55,0.55); |
87 | sprintf(histname,"chmaxt_%02d",i); |
85 | sprintf(histname,"chmaxt_%02d",i); |
88 | h1_chmaxt[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7); |
86 | h1_chmaxt[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7); |
89 | sprintf(histname,"chmin_%02d",i); |
87 | sprintf(histname,"chmin_%02d",i); |
90 | h1_chmin[i]=new TH1F(histname,histname,1100,-0.55,0.55); |
88 | h1_chmin[i]=new TH1F(histname,histname,1100,-0.55,0.55); |
91 | sprintf(histname,"chmint_%02d",i); |
89 | sprintf(histname,"chmint_%02d",i); |
92 | h1_chmint[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7); |
90 | h1_chmint[i]=new TH1F(histname,histname,DWIDTH,-0.1,204.7); |
93 | sprintf(histname," |
91 | sprintf(histname,"letime_%02d",i); |
94 | h1_letime |
92 | h1_letime[i]=new TH1F(histname,histname,500,d[i].twin[0],d[i].twin[1]); |
95 | sprintf(histname," |
93 | sprintf(histname,"cftime_%02d",i); |
96 |
|
94 | h1_cftime[i]=new TH1F(histname,histname,500,d[i].twin[0],d[i].twin[1]); |
97 | sprintf(histname," |
95 | sprintf(histname,"cftdif_%02d",i); |
98 |
|
96 | h1_cftdif[i]=new TH1F(histname,histname,2000,d[i].twin[0],d[i].twin[1]); |
99 | sprintf(histname," |
97 | sprintf(histname,"qdc_%02d",i); |
100 |
|
98 | h1_qdc[i]=new TH1F(histname,histname,500,-0.1,4.9); |
101 | sprintf(histname," |
99 | sprintf(histname,"dpo_%02d",i); |
102 |
|
100 | h2_dpo[i]=new TH2F(histname,histname,DWIDTH,-0.1,204.7,1100,-0.55,0.55); |
103 | sprintf(histname," |
101 | sprintf(histname,"tdcadc_%02d",i); |
104 |
|
102 | h2_tdcadc[i]=new TH2F(histname,histname,250,0.,0.5,400,d[i].twin[0],d[i].twin[1]); |
105 | sprintf(histname," |
103 | sprintf(histname,"ctdcadc_%02d",i); |
106 |
|
104 | h2_ctdcadc[i]=new TH2F(histname,histname,250,0.,0.5,400,d[i].twin[0],d[i].twin[1]); |
107 |
|
105 | gr_wfm[i]=new TGraph(DWIDTH); |
108 |
|
106 | gr_wfm[i]->SetMinimum(-0.55); |
109 |
|
107 | gr_wfm[i]->SetMaximum(0.55); |
110 |
|
108 | gr_wfm[i]->SetLineColor(i+1); |
111 | gr_wfm |
109 | gr_wfm[i]->SetMarkerColor(i+1); |
112 |
|
110 | sprintf(histname,"ch %d",i); |
113 |
|
111 | leg->AddEntry(gr_wfm[i], histname, "l"); |
114 | gr_wfm[i]-> |
112 | if (i) gr_wfm[i]->Draw("LP"); else gr_wfm[i]->Draw("ALP"); |
115 | gr_wfm[i]-> |
113 | gr_wfm[i]->GetHistogram()->SetTitle("WaveForms"); |
116 |
|
114 | } |
117 | leg->AddEntry(gr_wfm[i], histname, "l"); |
115 | |
118 |
|
116 | leg->Draw(); |
119 | 117 | h2_ctalk=new TH2F("ctalk","ctalk",250,0.,0.5,250,0.,0.5); |
|
120 | } |
118 | |
121 |
|
119 | fin=fopen(FileName,"rb"); |
122 |
|
120 | if (fin==NULL) { |
123 | 121 | printf("Error opening file %s\n",FileName); |
|
124 |
|
122 | return; |
125 |
|
123 | } |
126 |
|
124 | printf("%s, %lu\n",recid,sizeof(evrec)); |
127 | return; |
125 | |
128 | } |
126 | |
129 |
|
127 | for (ich=0; ich<nch; ich++) { |
130 | 128 | nwfm[ich]=0; |
|
131 | 129 | for (i=0; i<DWIDTH; i++) { |
|
132 |
|
130 | achdat[ich][i]=0; |
133 |
|
131 | } |
134 |
|
132 | } |
135 |
|
133 | unsigned int trgcell = 0; |
136 |
|
134 | int event = -1; |
137 | } |
135 | |
138 |
|
136 | iev=0; |
139 |
|
137 | time_t t0,told; |
140 | 138 | time(&t0); |
|
141 |
|
139 | told=t0-1; |
142 | while(!feof(fin)){ |
140 | while(!feof(fin)) { |
143 | if (iev>=nev) break; |
141 | if (iev>=nev) break; |
144 | stat=fread(recid,1,4,fin); |
142 | stat=fread(recid,1,4,fin); |
145 | if |
143 | if (debug) { |
146 | if (recid[1]=='#') printf("%c%c%u\n",recid[0],recid[1],srecid[1]); |
144 | if (recid[1]=='#') printf("%c%c%u\n",recid[0],recid[1],srecid[1]); |
147 | else |
145 | else printf("%s\n",recid ); |
148 | } |
146 | } |
149 | switch |
147 | switch (recid[0]) { |
150 | case 'D': // DRS |
148 | case 'D': // DRS |
151 | version = atoi(&recid[3]); |
149 | version = atoi(&recid[3]); |
152 | break; |
150 | break; |
153 | case 'T': // TIME |
151 | case 'T': // TIME |
154 | switch |
152 | switch (recid[1]) { |
155 | case 'I': |
153 | case 'I': |
156 | event=0; |
154 | event=0; |
157 | if |
155 | if (version ==0) version++; |
158 | break; |
156 | break; |
159 | case '#': trgcell = srecid[1]; break; |
157 | case '#': trgcell = srecid[1]; break; |
160 | } |
158 | } |
161 | break; |
159 | break; |
162 | case 'B': |
160 | case 'B': |
163 | board = srecid[1]; |
161 | board = srecid[1]; |
164 | break; |
162 | break; |
165 | case 'C': |
163 | case 'C': |
166 | sscanf(recid,"C%d",&ich); |
164 | sscanf(recid,"C%d",&ich); |
167 | ich=ich-1; |
165 | ich=ich-1; |
168 | if (event) { |
166 | if (event) { |
169 | if (version>1) stat=fread(&scaler[ich],1,sizeof(float),fin); |
167 | if (version>1) stat=fread(&scaler[ich],1,sizeof(float),fin); |
170 | stat=fread(ichdat[ich],1,sizeof(ichdat[ich]),fin); |
168 | stat=fread(ichdat[ich],1,sizeof(ichdat[ich]),fin); |
171 | } else { |
169 | } else { |
172 | 170 | ||
173 | stat=fread(dtdata[ich],1,sizeof(float)*DWIDTH,fin); |
171 | stat=fread(dtdata[ich],1,sizeof(float)*DWIDTH,fin); |
174 | 172 | ||
175 | } |
173 | } |
176 | break; |
174 | break; |
177 | case 'E': |
175 | case 'E': |
178 | stat=fread(&evrec.evn,1,sizeof(evrec),fin); |
176 | stat=fread(&evrec.evn,1,sizeof(evrec),fin); |
179 | iev++; |
177 | iev++; |
180 | if (!version) { |
178 | if (!version) { |
181 | stat=fread(dtdata[0],1,sizeof(float)*DWIDTH,fin); |
179 | stat=fread(dtdata[0],1,sizeof(float)*DWIDTH,fin); |
182 | } |
180 | } |
183 | event=1; |
181 | event=1; |
184 | break; |
182 | break; |
185 | default: |
183 | default: |
186 | printf("Unknown header! %s\n", recid); |
184 | printf("Unknown header! %s\n", recid); |
187 | break; |
185 | break; |
188 | } |
186 | } |
189 | 187 | ||
190 | 188 | ||
191 | if |
189 | if (recid[0] == 'E') { |
192 | for |
190 | for ( i=0; i<nch; i++) { |
193 | if (!lwfm[i]) continue; |
191 | if (!lwfm[i]) continue; |
194 | if |
192 | if ((chmin[i][0]>d[i].vcut[0])&&(chmin[i][0]<d[i].vcut[1])) { |
195 | h1_cftdif[i]->Fill(cftime[i |
193 | h1_cftdif[i]->Fill(cftime[i]-cftime[trgch]+110.); |
196 | } |
194 | } |
197 | // h2_tdcadc[i]->Fill(-chmin[i][0],letime[i][1]-cftime[trgch][1]+72); |
195 | // h2_tdcadc[i]->Fill(-chmin[i][0],letime[i][1]-cftime[trgch][1]+72); |
198 | // h2_ctdcadc[i]->Fill(-chmin[i][0],cftime[i][1]-cftime[trgch][1]+72); |
196 | // h2_ctdcadc[i]->Fill(-chmin[i][0],cftime[i][1]-cftime[trgch][1]+72); |
199 | h2_tdcadc[i]->Fill(-chmin[0][0],letime[i |
197 | h2_tdcadc[i]->Fill(-chmin[0][0],letime[i]-cftime[trgch]+72); |
200 | h2_ctdcadc[i]->Fill(-chmin[0][0],cftime[i |
198 | h2_ctdcadc[i]->Fill(-chmin[0][0],cftime[i]-cftime[trgch]+72); |
201 | } |
199 | } |
202 | h2_ctalk->Fill(-chmin[0][0],-chmin[1][0]); |
200 | h2_ctalk->Fill(-chmin[0][0],-chmin[1][0]); |
203 | } |
201 | } |
204 | if (event<1) continue; |
202 | if (event<1) continue; |
205 | if (recid[0]!='C') continue; |
203 | if (recid[0]!='C') continue; |
- | 204 | if (ich>=nch) continue; |
|
206 | 205 | ||
207 | - | ||
208 | lwfm[ich]=0; |
206 | lwfm[ich]=0; |
209 | qdc[ich]=0; |
207 | qdc[ich]=0; |
210 | chmax[ich][0]=-1; chmax[ich][1]=-1; |
208 | chmax[ich][0]=-1; chmax[ich][1]=-1; |
211 | chmin[ich][0]=1; chmin[ich][1]=-1; |
209 | chmin[ich][0]=1; chmin[ich][1]=-1; |
212 |
|
210 | letime[ich]=-1.; letime[ich]=-1.; |
213 |
|
211 | cftime[ich]=-1.; cftime[ich]=-1.; |
214 | - | ||
215 | 212 | ||
216 | lwfm[ich]=1; |
- | |
217 | nwfm[ich]+=1; |
- | |
218 | 213 | ||
- | 214 | lwfm[ich]=1; |
|
- | 215 | nwfm[ich]+=1; |
|
- | 216 | ||
- | 217 | ||
- | 218 | ||
- | 219 | t = &tcdata[ich][0]; |
|
- | 220 | y = &chdat[ich][0]; |
|
- | 221 | ay = &achdat[ich][0]; |
|
- | 222 | ||
- | 223 | float sum=0; |
|
- | 224 | for (i=0; i<DWIDTH; i++) { |
|
- | 225 | sum+= dtdata[ich][(i+trgcell)%DWIDTH]; |
|
- | 226 | if (version) t[i]=sum; |
|
- | 227 | else t[i]=dtdata[0][i]; // old format |
|
- | 228 | } |
|
- | 229 | tccalib[ich]=t[(DWIDTH-trgcell)%DWIDTH]; |
|
- | 230 | ||
- | 231 | for (i=0; i<DWIDTH; i++) { |
|
- | 232 | if (version) t[i]-=(tccalib[ich]-tccalib[0]); // assume ich 0 is connected and always first in the data |
|
- | 233 | y[i]=-0.5+(float)ichdat[ich][i]/0xFFFF; |
|
- | 234 | if (version) y[i]+=evrec.rc; |
|
- | 235 | h2_dpo[ich]->Fill(t[i],y[i]); |
|
- | 236 | gr_wfm[ich]->SetPoint(i,t[i],y[i]+0.05*(ich-1)); |
|
- | 237 | } |
|
- | 238 | ||
- | 239 | ||
- | 240 | for (i=0; i<DWIDTH; i++) { |
|
- | 241 | // accumulated waveforms |
|
- | 242 | ay[i]+=y[i]; |
|
- | 243 | ||
- | 244 | // signal minumum |
|
- | 245 | if (y[i]>chmax[ich][0]) { |
|
- | 246 | chmax[ich][0]=y[i]; |
|
- | 247 | chmax[ich][1]=t[i]; |
|
- | 248 | } |
|
- | 249 | ||
- | 250 | // signal maximum |
|
- | 251 | if (y[i]<chmin[ich][0]) { |
|
- | 252 | chmin[ich][0]=y[i]; |
|
- | 253 | chmin[ich][1]=t[i]; |
|
- | 254 | } |
|
- | 255 | float t0 = t[i]; |
|
- | 256 | float t0p = t[i+1]; |
|
- | 257 | float t0n = t[i-1]; |
|
- | 258 | // charge in the range |
|
- | 259 | if ((t0>d[ich].adcgate[0])&&(t0<d[ich].adcgate[1])) { |
|
- | 260 | qdc[ich]+=-y[i]*(t0p-t0n)/2; |
|
- | 261 | } |
|
- | 262 | } |
|
- | 263 | ||
- | 264 | for (i=1; i<DWIDTH-1; i++) { |
|
- | 265 | float t0 = t[i]; |
|
- | 266 | float t0p = t[i+1]; |
|
- | 267 | float t0n = t[i-1]; |
|
- | 268 | // leading edge in the range |
|
- | 269 | if ((t0>d[ich].twin[0])&&(t0<d[ich].twin[1])) { |
|
- | 270 | if ( ((!d[ich].edge)&&(y[i]<d[ich].threshold) || |
|
- | 271 | ( d[ich].edge)&&(y[i]>d[ich].threshold ) ) |
|
- | 272 | &&(letime[ich]<0.)) { |
|
- | 273 | letime[ich]=t0n+(t0-t0n)*(d[ich].threshold-y[i-1])/(y[i]-y[i-1]); |
|
- | 274 | } |
|
- | 275 | // constant fraction time in the range |
|
- | 276 | if ( ( ((!d[ich].edge) && (chmin[ich][0]<d[ich].threshold)&&(y[i]<chmin[ich][0]*d[ich].cfrac)) || |
|
- | 277 | (( d[ich].edge) && (chmax[ich][0]>d[ich].threshold)&&(y[i]>chmax[ich][0]*d[ich].cfrac)) ) |
|
- | 278 | &&(cftime[ich]<0.) |
|
- | 279 | ||
- | 280 | ) { |
|
- | 281 | cftime[ich]=t0n+(t0-t0n)*(chmin[ich][0]*d[ich].cfrac-y[i-1])/(y[i]-y[i-1]); |
|
- | 282 | } |
|
- | 283 | } |
|
- | 284 | } |
|
- | 285 | ||
- | 286 | if ((chmax[ich][1]>d[ich].twin[0])&&(chmax[ich][1]<d[ich].twin[1])) { |
|
- | 287 | h1_chmax[ich]->Fill(chmax[ich][0]); |
|
- | 288 | if (chmax[ich][0]>d[ich].threshold) h1_chmaxt[ich]->Fill(chmax[ich][1]); |
|
- | 289 | } |
|
- | 290 | if ((chmin[ich][1]>d[ich].twin[0])&&(chmin[ich][1]<d[ich].twin[1])) { |
|
- | 291 | h1_chmin[ich]->Fill(chmin[ich][0]); |
|
- | 292 | if (chmin[ich][0]<d[ich].threshold) h1_chmint[ich]->Fill(chmin[ich][1]); |
|
- | 293 | } |
|
- | 294 | h1_qdc[ich]->Fill(qdc[ich]); |
|
- | 295 | h1_letime[ich]->Fill(letime[ich]); |
|
- | 296 | h1_cftime[ich]->Fill(cftime[ich]); |
|
- | 297 | time(&t0); |
|
- | 298 | ||
- | 299 | if ((t0!=told) || ((updfrq>0)&&(!(iev%updfrq) ) ) ) { |
|
- | 300 | c_wfm->Update(); |
|
- | 301 | for (i=0; i<DWIDTH; i++) { |
|
- | 302 | ay[i]/=nwfm[ich]; |
|
- | 303 | gr_wfm[ich]->SetPoint(i,t[i],ay[i]+0.00*(ich-1)); |
|
- | 304 | } |
|
- | 305 | printf("processing event %d\n",iev); |
|
- | 306 | told=t0; |
|
- | 307 | } |
|
219 | 308 | } |
|
- | 309 | ||
- | 310 | printf("number of events: %d\n",iev); |
|
- | 311 | fclose(fin); |
|
- | 312 | ||
- | 313 | TCanvas* c_dpo= new TCanvas("c_dpo","DPO",750,50,700,700); |
|
- | 314 | c_dpo->Divide(2,2); |
|
- | 315 | for (i=0; i<nch; i++) {c_dpo->cd(i+1); h2_dpo[i]->Draw("colz");} |
|
- | 316 | ||
- | 317 | TCanvas* c_cftdif= new TCanvas("c_cftdif","DPO",750,50,700,700); |
|
- | 318 | c_cftdif->Divide(2,2); |
|
- | 319 | for (i=0; i<nch; i++) {c_cftdif->cd(i+1); h1_cftdif[i]->Draw();} |
|
- | 320 | return; |
|
220 | 321 | } |
|
- | 322 | ||
- | 323 | ||
- | 324 | void drsana(int nev=1000, int updfrq=20, char *FileName="./data/x1.dat", int trgch=0){ |
|
- | 325 | ||
- | 326 | // float threshold[nch][2]={{0.,-0.02},{0.,0.},{0.,0.},{0.,-0.25}}; |
|
- | 327 | // float twin[nch][2]={{120.,130.},{100.,150.},{100.,150.},{70.,90.}}; |
|
- | 328 | // float adcgate[nch][2]={{12nch.,136.},{120.,140.},{120.,140.},{70.,90.}}; |
|
- | 329 | // float threshold[4][2]={{0.,-0.05},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
|
- | 330 | // float twin[4][2]={{80.,100.},{80.,100.},{90.,110.},{50.,70.}}; |
|
- | 331 | // float adcgate[4][2]={{80.,110.},{80.,110.},{90.,110.},{50.,70.}}; |
|
- | 332 | float threshold[4][2]={{0.,-0.05},{0.,-0.05},{0.,-0.25},{0.,-0.25}}; |
|
- | 333 | float twin[4][2]={{100.,120.},{100.,120.},{110.,130.},{60.,80.}}; |
|
- | 334 | float adcgate[4][2]={{105.,125.},{105.,125.},{110.,130.},{60.,80.}}; |
|
- | 335 | float vcut[4][2]={{-0.49,-0.07},{-1,1},{-1,1},{-1,1}}; |
|
- | 336 | int edge[4]={1,1,1,1};// 0 -- rising, 1 -- falling |
|
- | 337 | ||
221 |
|
338 | DrsChannel c[2]; |
- | 339 | ||
- | 340 | c[0].cfrac = CFRAC; |
|
- | 341 | c[0].threshold = threshold[0][0]; |
|
- | 342 | c[0].twin[0] = twin[0][0]; |
|
- | 343 | c[0].twin[1] = twin[0][1]; |
|
- | 344 | ||
- | 345 | c[0].adcgate[0] = adcgate[0][0]; |
|
- | 346 | c[0].adcgate[1] = adcgate[0][1]; |
|
- | 347 | ||
222 |
|
348 | c[0].vcut[0] = vcut[0][0]; |
- | 349 | c[0].vcut[1] = vcut[0][1]; |
|
- | 350 | ||
223 |
|
351 | c[0].edge = edge[0]; |
224 | 352 | ||
225 | float sum=0; |
- | |
226 | for (i=0;i<DWIDTH;i++) { |
- | |
227 | sum+= dtdata[ich][(i+trgcell)%DWIDTH]; |
- | |
228 | if (version) t[i]=sum; |
- | |
229 | else t[i]=dtdata[0][i]; // old format |
- | |
230 | } |
- | |
231 | tccalib[ich]=t[(DWIDTH-trgcell)%DWIDTH]; |
- | |
232 | - | ||
233 | for (i=0;i<DWIDTH;i++) { |
- | |
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 | } |
- | |
240 | - | ||
241 | - | ||
242 | for (i=0;i<DWIDTH;i++) { |
- | |
243 | // accumulated waveforms |
- | |
244 | ay[i]+=y[i]; |
- | |
245 | - | ||
246 | // signal minumum |
- | |
247 | if (y[i]>chmax[ich][0]) { |
- | |
248 | chmax[ich][0]=y[i]; |
- | |
249 | chmax[ich][1]=t[i]; |
- | |
250 | } |
- | |
251 | - | ||
252 | // signal maximum |
- | |
253 | if (y[i]<chmin[ich][0]) { |
- | |
254 | chmin[ich][0]=y[i]; |
- | |
255 | chmin[ich][1]=t[i]; |
- | |
256 | } |
- | |
257 | float t0 = t[i]; |
- | |
258 | float t0p = t[i+1]; |
- | |
259 | float t0n = t[i-1]; |
- | |
260 | // charge in the range |
- | |
261 | if ((t0>adcgate[ich][0])&&(t0<adcgate[ich][1])) { |
- | |
262 | qdc[ich]+=-y[i]*(t0p-t0n)/2; |
- | |
263 | } |
- | |
264 | } |
- | |
265 | - | ||
266 | for (i=1;i<DWIDTH-1;i++) { |
- | |
267 | float t0 = t[i]; |
- | |
268 | float t0p = t[i+1]; |
- | |
269 | float t0n = t[i-1]; |
- | |
270 | // leading edge in the range |
- | |
271 | if ((t0>twin[ich][0])&&(t0<twin[ich][1])) { |
- | |
272 | if ((y[i]<threshold[ich][1])&&(letime[ich][1]<0.)) { |
- | |
273 | letime[ich][1]=t0n+(t0-t0n)*(threshold[ich][1]-y[i-1])/(y[i]-y[i-1]); |
- | |
274 | } |
- | |
275 | // constant fraction time in the range |
- | |
276 | if ((chmin[ich][0]<threshold[ich][1])&&(y[i]<chmin[ich][0]*CFRAC)&&(cftime[ich][1]<0.)) { |
- | |
277 | cftime[ich][1]=t0n+(t0-t0n)*(chmin[ich][0]*CFRAC-y[i-1])/(y[i]-y[i-1]); |
- | |
278 | } |
- | |
279 | } |
- | |
280 | } |
- | |
281 | - | ||
282 | if ((chmax[ich][1]>twin[ich][0])&&(chmax[ich][1]<twin[ich][1])) { |
- | |
283 | h1_chmax[ich]->Fill(chmax[ich][0]); |
- | |
284 | if (chmax[ich][0]>threshold[ich][0]) h1_chmaxt[ich]->Fill(chmax[ich][1]); |
- | |
285 | } |
- | |
286 | if ((chmin[ich][1]>twin[ich][0])&&(chmin[ich][1]<twin[ich][1])) { |
- | |
287 | h1_chmin[ich]->Fill(chmin[ich][0]); |
- | |
288 | if (chmin[ich][0]<threshold[ich][1]) h1_chmint[ich]->Fill(chmin[ich][1]); |
- | |
289 | } |
- | |
290 | h1_qdc[ich]->Fill(qdc[ich]); |
- | |
291 | h1_letime[ich][1]->Fill(letime[ich][1]); |
- | |
292 | h1_cftime[ich][1]->Fill(cftime[ich][1]); |
- | |
293 | 353 | ||
294 | if (!(iev%updfrq)) { |
- | |
295 |
|
354 | c[1].cfrac = CFRAC; |
296 |
|
355 | c[1].threshold = threshold[1][0]; |
297 |
|
356 | c[1].twin[0] = twin[1][0]; |
298 | gr_wfm[ich]->SetPoint(i,t[i],ay[i]+0.05*(ich-1)); |
- | |
299 | } |
- | |
300 |
|
357 | c[1].twin[1] = twin[1][1]; |
301 | } |
- | |
302 | } |
- | |
303 | 358 | ||
304 |
|
359 | c[1].adcgate[0] = adcgate[1][0]; |
305 |
|
360 | c[1].adcgate[1] = adcgate[1][1]; |
306 | 361 | ||
307 | TCanvas* c_dpo= new TCanvas("c_dpo","DPO",750,50,700,700); |
- | |
308 |
|
362 | c[1].vcut[0] = vcut[1][0]; |
309 |
|
363 | c[1].vcut[1] = vcut[1][1]; |
310 | 364 | ||
311 | TCanvas* c_cftdif= new TCanvas("c_cftdif","DPO",750,50,700,700); |
- | |
312 |
|
365 | c[1].edge = edge[1]; |
313 |
|
366 | drs * d = new drs(FileName, 2, c, trgch, nev, updfrq ); |
314 | return; |
- | |
315 | } |
367 | } |