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