Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
291 | f9daq | 1 | #include "stdio.h" |
2 | #include "TROOT.h" |
||
3 | #include "TSystem.h" |
||
4 | #include "TFile.h" |
||
5 | #include "TH1F.h" |
||
6 | #include "TH2F.h" |
||
7 | #include "TF1.h" |
||
8 | #include "TMath.h" |
||
9 | #include "TStyle.h" |
||
10 | #include "TCanvas.h" |
||
11 | #include "TLine.h" |
||
12 | |||
13 | //kobayashi |
||
14 | #include "TTree.h" |
||
15 | |||
16 | //~ #define USE_ZLIB |
||
17 | #ifdef USE_ZLIB |
||
18 | # include "zlib.h" |
||
19 | #endif |
||
20 | // ------------------------------------------------------------------------------ |
||
21 | |||
22 | #define POSMARG 1000 |
||
23 | |||
24 | #define READBUFFERLENGTH 500000 |
||
25 | |||
26 | // data format |
||
27 | #define MAXDATA 64 |
||
28 | #define NCH 32 |
||
29 | #define ANALYSE_CH 32 |
||
30 | #define MPPC_1_CH 0 |
||
31 | #define MPPC_2_CH 1 |
||
32 | #define TRIGGER_CH 31 |
||
33 | //~ #define ANALYSE_CH 8 |
||
34 | //~ #define MPPC_1_CH 2 |
||
35 | //~ #define MPPC_2_CH 5 |
||
36 | #define REF_CH 0 |
||
37 | #define TDC_BIN (25./1000.) //1 TDC bin in ns |
||
38 | #define MIKRO_BIN 0.3595/1000. //1 mikro step in mm |
||
39 | |||
40 | #define RUNREC_ID 1 |
||
41 | #define ENDREC_ID 2 |
||
42 | #define POSREC_ID 3 |
||
43 | #define EVTREC_ID 4 |
||
44 | |||
45 | //define testpulse |
||
46 | typedef struct { |
||
47 | unsigned long id,len; |
||
48 | unsigned long fver,time; |
||
49 | unsigned long nev,nch,ped,xy; |
||
50 | long nx,x0,dx,ny,y0,dy; |
||
51 | } RUNREC; |
||
52 | RUNREC *runrec; |
||
53 | RUNREC run; |
||
54 | |||
55 | typedef struct { |
||
56 | unsigned long id,len; |
||
57 | unsigned long time; |
||
58 | } ENDREC; |
||
59 | ENDREC *endrec; |
||
60 | |||
61 | typedef struct { |
||
62 | unsigned long id,len; |
||
63 | unsigned long time; |
||
64 | long ix,x,xset,iy,y,yset; |
||
65 | } POSREC; |
||
66 | POSREC *posrec; |
||
67 | POSREC pos; |
||
68 | |||
69 | typedef struct { |
||
70 | unsigned long id,len; |
||
71 | unsigned long nev; |
||
72 | unsigned short data[MAXDATA]; |
||
73 | } EVTREC; |
||
74 | EVTREC *evtrec; |
||
75 | |||
76 | // ------------------------------------------------------------------------------ |
||
77 | |||
78 | int d2r(char* dfile0="test", double qdcmi=0, double qdcma=4096, double tdcmi=-1.5, double tdcma=3, double adc_cor_min=200.0, double deltaT_ctdcdiff=0) |
||
79 | { |
||
80 | int dbg=0; |
||
81 | printf(" dat 2 root conversion program\nUsage:\nd2r(input file -.dat, TDC min [ps], TDC max [ps], QDC min, QDC max)\n\n"); |
||
82 | |||
83 | char fullname[256], sbuff[256]; |
||
84 | FILE *fp; |
||
85 | |||
86 | //Chanel information |
||
87 | //~ int chmapx[NCH]={7,6,5,4,3,2,1,0}; |
||
88 | //~ int chmapx[NCH]={ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19}; |
||
89 | int chmapx[NCH]; for(int i=0; i<NCH; i++) {chmapx[i]=i;}; |
||
90 | |||
91 | //~ double padcenter[NCH][2]={ {201000, 210000}, |
||
92 | //~ {183000, 210000}, |
||
93 | //~ {165000, 210000}, |
||
94 | //~ {147000, 210000}, |
||
95 | //~ {129000, 210000}, |
||
96 | //~ {111000, 210000}, |
||
97 | //~ { 93000, 210000}, |
||
98 | //~ { 75000, 210000} }; |
||
99 | //~ // double tdcoffset[NCH]={57.78, 57.28, 57.86, 57.64, 56.06, 56.46, 57.5, 57.41}; |
||
100 | //~ double tdcoffset[NCH]={2311*TDC_BIN, 2291*TDC_BIN, 2314*TDC_BIN, 2306*TDC_BIN, |
||
101 | //~ 2242*TDC_BIN, 2258*TDC_BIN, 2300*TDC_BIN, 2296*TDC_BIN}; |
||
102 | double padcenter[NCH][2]; for(int i=0; i<NCH; i++) {padcenter[i][0]=0; padcenter[i][1]=0;}; |
||
103 | double tdcoffset[NCH]; for(int i=0; i<NCH; i++) {tdcoffset[i]=0;}; |
||
104 | sprintf(fullname, "d2r.ini"); |
||
105 | if( (fp=fopen(fullname, "rt")) == NULL ) |
||
106 | printf("Cannot open pad centers file %s !!!\n", fullname); |
||
107 | else { |
||
108 | printf("Opened pad centers file %s\n", fullname); |
||
109 | fgets(sbuff,256, fp);printf("%s", sbuff); |
||
110 | for(int i=0; i<NCH; i++) |
||
111 | fscanf(fp, "%lf %lf %lf\n", &padcenter[i][0], &padcenter[i][1], &tdcoffset[i]); |
||
112 | fclose(fp); |
||
113 | } |
||
114 | for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", padcenter[i][0], padcenter[i][1], tdcoffset[i]); |
||
115 | |||
116 | //TDC correction parameters |
||
117 | //~ double corpar[NCH][3]={ {-0.8, 25, 0}, |
||
118 | //~ {-0.8, 25, 0}, |
||
119 | //~ {-0.8, 25, 0}, |
||
120 | //~ {-0.8, 25, 0}, |
||
121 | //~ {-0.8, 25, 0}, |
||
122 | //~ {-0.8, 25, 0}, |
||
123 | //~ {-0.8, 25, 0}, |
||
124 | //~ {-0.8, 25, 0} }; |
||
125 | double corpar[NCH][3]; for(int i=0; i<NCH; i++) {corpar[i][0]=0.0; corpar[i][1]=0.005; corpar[i][2]=0.0;}; |
||
126 | sprintf(fullname, "data/%s_cor.txt", dfile0); |
||
127 | if( (fp=fopen(fullname, "rt")) == NULL ) |
||
128 | printf("Cannot open parameter file %s !!!\n", fullname); |
||
129 | else { |
||
130 | printf("Opened parameter file %s\n", fullname); |
||
131 | for(int i=0; i<NCH; i++) { |
||
132 | fscanf(fp, "%lf %lf %lf\n", &corpar[i][0], &corpar[i][1], &corpar[i][2]); |
||
133 | /*// check if parameters make sense |
||
134 | if( (corpar[i][0] < (tdcmi-0.2*tdcmi)) || ((tdcma+0.2*tdcma) < corpar[i][0]) || |
||
135 | (corpar[i][1] < 0) || (1e4*TDC_BIN < corpar[i][1]) || |
||
136 | (1e4 < TMath::Abs(corpar[i][2])) ) { |
||
137 | printf("Warning: parameters for ch%d out of limits -> using default!\n", i); |
||
138 | corpar[i][0]=2200*TDC_BIN; corpar[i][1]=1000*TDC_BIN; corpar[i][2]=-100*TDC_BIN; |
||
139 | }*/ |
||
140 | } |
||
141 | fclose(fp); |
||
142 | } |
||
143 | for(int i=0; i<NCH; i++) printf("%.2lf %.2lf %.2lf\n", corpar[i][0], corpar[i][1], corpar[i][2]); |
||
144 | |||
145 | |||
146 | //histograms |
||
147 | char hname[256], htitle[256]; |
||
148 | double adc,tdc; |
||
149 | TH1F *hadc[NCH], *hadc_cut[NCH], *hadc_cut_2[NCH]; |
||
150 | TH1F *htdc[NCH], *htdc_cut[NCH], *htdc_cut_2[NCH], *hctdc[NCH]; |
||
151 | TH2F *h2d[NCH], *hcor[NCH]; |
||
152 | TH2F *hdiffcor[NCH][NCH]; |
||
153 | TH2F *hdiffcor_low[NCH][NCH]; |
||
154 | TH2F *hdiffcor_hi[NCH][NCH]; |
||
155 | TH2F *hadccor; |
||
156 | TH2F *htdccor; |
||
157 | TH2F *hcoradctdc0, *hcoradctdc1, hcoradctdc01, hcoradctdc11; |
||
158 | TH1F *htesttdc1, *htesttdc2; |
||
159 | TTree *ftt; |
||
160 | |||
161 | TH1F *htdcdiff, *htdcdiff_cut, *htdcdiff_cut_2; |
||
162 | |||
163 | double ref_cut_1_lo = qdcmi; |
||
164 | double ref_cut_1_hi = qdcma; |
||
165 | double ref_cut_2_lo = tdcmi; |
||
166 | double ref_cut_2_hi = tdcma; |
||
167 | |||
168 | //kobayashi |
||
169 | double t_adc0, t_tdc0, t_adc1, t_tdc1, t_ctdc; |
||
170 | |||
171 | //data buffer |
||
172 | char readbuf[READBUFFERLENGTH]; |
||
173 | runrec = (RUNREC *) readbuf; |
||
174 | endrec = (ENDREC *) readbuf; |
||
175 | posrec = (POSREC *) readbuf; |
||
176 | evtrec = (EVTREC *) readbuf; |
||
177 | |||
178 | //data file |
||
179 | #ifdef USE_ZLIB |
||
180 | gzFile dfp; |
||
181 | #else |
||
182 | FILE *dfp; |
||
183 | #endif |
||
184 | char dfile[256]; |
||
185 | int ftype=0, fcount=1; |
||
186 | do { |
||
187 | switch(ftype++) { |
||
188 | case 0: |
||
189 | sprintf(dfile, "data/%s_file%02d.dat", dfile0, fcount); |
||
190 | break; |
||
191 | case 1: |
||
192 | sprintf(dfile, "data/%s_file%02d.dat.gz", dfile0, fcount); |
||
193 | break; |
||
194 | case 2: |
||
195 | sprintf(dfile, "data/%s_file%02d.gz", dfile0, fcount); |
||
196 | break; |
||
197 | default: |
||
198 | printf(" Cannot find data file for %s !!!\n", dfile0); |
||
199 | return -1; |
||
200 | } |
||
201 | #ifdef USE_ZLIB |
||
202 | dfp=gzopen(dfile,"rb"); |
||
203 | #else |
||
204 | dfp=fopen(dfile,"rb"); |
||
205 | #endif |
||
206 | |||
207 | } while(!dfp); |
||
208 | printf("Opened data file %s\n", dfile); |
||
209 | |||
210 | //opens ROOT file |
||
211 | TFile *rootfile; char fnameroot[256]; |
||
212 | sprintf(fnameroot, "root/%s.root", dfile0); |
||
213 | //rootfile = (TFile *) gROOT->FindObjectAny(dfile0); |
||
214 | //if (rootfile!=NULL) {printf("!!!\n");rootfile->Close();} |
||
215 | //rootfile = new TFile(fnameroot); |
||
216 | //if(rootfile) rootfile->Close(); |
||
217 | rootfile = new TFile(fnameroot,"RECREATE",dfile0); |
||
218 | |||
219 | // ----------------------------------------------- |
||
220 | // loop trough records |
||
221 | UInt_t rec_id, rec_len; |
||
222 | unsigned ulsize = 4; |
||
223 | int ceve=0; |
||
224 | int end_of_file = 0; |
||
225 | |||
226 | while(1) { |
||
227 | #ifdef USE_ZLIB |
||
228 | if(gzeof(dfp)) end_of_file = 1; |
||
229 | #else |
||
230 | if(feof(dfp)) end_of_file = 1; |
||
231 | #endif |
||
232 | |||
233 | #ifdef USE_ZLIB |
||
234 | gzread(dfp, (voidp)&readbuf, 2*ulsize); |
||
235 | #else |
||
236 | fread( (void*)&readbuf, 2*ulsize, 1, dfp); |
||
237 | |||
238 | #endif |
||
239 | rec_id=readbuf[0]; |
||
240 | rec_len=readbuf[ulsize]; |
||
241 | //kobayashi |
||
242 | if(rec_id == 4) rec_len = 140; |
||
243 | |||
244 | //~ if(dbg) printf("-----------------------------------------------\n"); |
||
245 | //~ if(dbg) printf("[%d] rec_id = %d | rec_len = %d\n", ceve, rec_id, rec_len); |
||
246 | |||
247 | //printf("[%d] rec_id = %d | rec_len = %u\n", ceve, readbuf[0], readbuf[ulsize]); |
||
248 | switch(rec_id) |
||
249 | { |
||
250 | |||
251 | case RUNREC_ID: |
||
252 | #ifdef USE_ZLIB |
||
253 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
254 | #else |
||
255 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
256 | #endif |
||
257 | run=*runrec; |
||
258 | |||
259 | if(dbg) { |
||
260 | printf("RUNREC_ID\n"); |
||
261 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
||
262 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
||
263 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
||
264 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
||
265 | |||
266 | //~ break; |
||
267 | } |
||
268 | |||
269 | //create histograms |
||
270 | |||
271 | sprintf(hname, "htdcdiff"); |
||
272 | htdcdiff = (TH1F*)gROOT->FindObject(hname); |
||
273 | if(htdcdiff) delete htdcdiff; |
||
274 | htdcdiff = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
275 | //~ htdcdiff = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN); |
||
276 | |||
277 | sprintf(hname, "htdcdiff_cut"); |
||
278 | htdcdiff_cut = (TH1F*)gROOT->FindObject(hname); |
||
279 | if(htdcdiff_cut) delete htdcdiff_cut; |
||
280 | //~ htdcdiff_cut = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
281 | htdcdiff_cut = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
282 | //kobayashi |
||
283 | //~ htdcdiff_cut = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN); |
||
284 | |||
285 | sprintf(hname, "htdcdiff_cut_2"); |
||
286 | htdcdiff_cut_2 = (TH1F*)gROOT->FindObject(hname); |
||
287 | if(htdcdiff_cut_2) delete htdcdiff_cut_2; |
||
288 | htdcdiff_cut_2 = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
289 | //~ htdcdiff_cut_2 = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN); |
||
290 | |||
291 | sprintf(hname, "hadccor"); |
||
292 | hadccor = (TH2F*)gROOT->FindObject(hname); |
||
293 | if(hadccor) delete hadccor; |
||
294 | //~ hadccor = new TH2F(hname, hname, 256, 0, 4096, 256, 0, 4096); |
||
295 | hadccor = new TH2F(hname, hname, 256, 0, 4096, 256, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
296 | |||
297 | sprintf(hname, "htdccor"); |
||
298 | htdccor = (TH2F*)gROOT->FindObject(hname); |
||
299 | if(htdccor) delete hadccor; |
||
300 | //~ htdccor = new TH2F(hname, hname, 512, 0, 1024*TDC_BIN, 512, 0, 1024*TDC_BIN); |
||
301 | htdccor = new TH2F(hname, hname, 512, 1024*TDC_BIN, 2048*TDC_BIN, 512, 1024*TDC_BIN, 2048*TDC_BIN); |
||
302 | //~ htdccor = new TH2F(hname, hname, 512, 0, 2048*TDC_BIN, 512, 0, 2048*TDC_BIN); |
||
303 | //~ htdccor = new TH2F(hname, hname, 11*20+1, 15.985, 27.035, 3*40+1, 15.990,19.015); |
||
304 | //~ htdccor = new TH2F(hname, hname, 512, 0, 2047.5*TDC_BIN, 3*40+1, 15.990,19.015); |
||
305 | |||
306 | //kobayashi |
||
307 | sprintf(hname, "hcoradctdc0"); |
||
308 | hcoradctdc0 = (TH2F*)gROOT->FindObject(hname); |
||
309 | hcoradctdc0 = new TH2F(hname,hname,2000,0,2000,800,-10,10); |
||
310 | sprintf(hname, "hcoradctdc1"); |
||
311 | hcoradctdc1 = (TH2F*)gROOT->FindObject(hname); |
||
312 | hcoradctdc1 = new TH2F(hname,hname,2000,0,2000,800,-10,10); |
||
313 | ftt = (TTree*)gROOT->FindObject("ftt"); |
||
314 | if(ftt) delete ftt; |
||
315 | ftt = new TTree("ftt","ftt"); |
||
316 | ftt->Branch("t_adc0",&t_adc0,"t_adc0/D"); |
||
317 | ftt->Branch("t_adc1",&t_adc1,"t_adc1/D"); |
||
318 | ftt->Branch("t_tdc0",&t_tdc0,"t_tdc0/D"); |
||
319 | ftt->Branch("t_tdc1",&t_tdc1,"t_tdc1/D"); |
||
320 | ftt->Branch("t_ctdc",&t_ctdc,"t_ctdc/D"); |
||
321 | #ifdef testpulse |
||
322 | sprintf(hname, "htesttdc1"); |
||
323 | htesttdc1 = (TH1F*)gROOT->FindObject(hname); |
||
324 | if(htesttdc1) delete htesttdc1; |
||
325 | htesttdc1 = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); |
||
326 | sprintf(hname, "htesttdc2"); |
||
327 | htesttdc2 = (TH1F*)gROOT->FindObject(hname); |
||
328 | if(htesttdc2) delete htesttdc2; |
||
329 | htesttdc2 = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); |
||
330 | #endif |
||
331 | |||
332 | for(int i=0; i<ANALYSE_CH; i++) { |
||
333 | sprintf(hname, "hadc%d", i); |
||
334 | hadc[i] = (TH1F*)gROOT->FindObject(hname); |
||
335 | if(hadc[i]) delete hadc[i]; |
||
336 | hadc[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5); |
||
337 | |||
338 | sprintf(hname, "hadc_cut%d", i); |
||
339 | hadc_cut[i] = (TH1F*)gROOT->FindObject(hname); |
||
340 | if(hadc_cut[i]) delete hadc_cut[i]; |
||
341 | hadc_cut[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5); |
||
342 | |||
343 | sprintf(hname, "hadc_cut_2%d", i); |
||
344 | hadc_cut_2[i] = (TH1F*)gROOT->FindObject(hname); |
||
345 | if(hadc_cut_2[i]) delete hadc_cut_2[i]; |
||
346 | hadc_cut_2[i] = new TH1F(hname, hname, 4096, -0.5, 4095.5); |
||
347 | |||
348 | sprintf(hname, "htdc%d", i); |
||
349 | htdc[i] = (TH1F*)gROOT->FindObject(hname); |
||
350 | if(htdc[i]) delete htdc[i]; |
||
351 | //~ htdc[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
352 | //~ htdc[i] = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN); //original |
||
353 | //~ htdc[i] = new TH1F(hname, hname, 65536/2, -0.5*TDC_BIN, 65535.5*TDC_BIN); //koba |
||
354 | //~ htdc[i] = new TH1F(hname, hname, 65536/2, -32768.5*TDC_BIN, 32767.5*TDC_BIN); //koba |
||
355 | htdc[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
356 | //~ htdc[i] = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); |
||
357 | |||
358 | sprintf(hname, "htdc_cut%d", i); |
||
359 | htdc_cut[i] = (TH1F*)gROOT->FindObject(hname); |
||
360 | if(htdc_cut[i]) delete htdc_cut[i]; |
||
361 | //~ htdc_cut[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
362 | //~ htdc_cut[i] = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN);//original |
||
363 | //~ htdc_cut[i] = new TH1F(hname, hname, 65536/2, -0.5*TDC_BIN, 65535.5*TDC_BIN); //koba |
||
364 | htdc_cut[i] = new TH1F(hname, hname, 65536/2, -32768.5*TDC_BIN, 32767.5*TDC_BIN); //koba |
||
365 | //~ htdc_cut[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
366 | |||
367 | sprintf(hname, "htdc_cut_2%d", i); |
||
368 | htdc_cut_2[i] = (TH1F*)gROOT->FindObject(hname); |
||
369 | if(htdc_cut_2[i]) delete htdc_cut_2[i]; |
||
370 | //~ htdc_cut_2[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
371 | //~ htdc_cut_2[i] = new TH1F(hname, hname, 4096, -0.5*TDC_BIN, 4095.5*TDC_BIN);//original |
||
372 | htdc_cut_2[i] = new TH1F(hname, hname, 65536, -0.5*TDC_BIN, 65535.5*TDC_BIN); //koba |
||
373 | |||
374 | sprintf(hname, "hctdc%d", i); |
||
375 | hctdc[i] = (TH1F*)gROOT->FindObject(hname); |
||
376 | if(hctdc[i]) delete hctdc[i]; |
||
377 | //~ hctdc[i] = new TH1F(hname, hname, 4096, -2048.5*TDC_BIN, 2047.5*TDC_BIN); |
||
378 | //~ hctdc[i] = new TH1F(hname, hname, 65536/2, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
379 | hctdc[i] = new TH1F(hname, hname, 65536, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
380 | |||
381 | sprintf(hname, "h2d%d", i); |
||
382 | h2d[i] = (TH2F*)gROOT->FindObject(hname); |
||
383 | if(h2d[i]) delete h2d[i]; |
||
384 | h2d[i] = new TH2F(hname, hname, run.nx, (run.x0-0.5*run.dx)*MIKRO_BIN, (run.x0+(run.nx-0.5)*run.dx)*MIKRO_BIN, |
||
385 | run.ny, (run.y0-0.5*run.dy)*MIKRO_BIN, (run.y0+(run.ny-0.5)*run.dy)*MIKRO_BIN); |
||
386 | |||
387 | sprintf(hname, "hcor%d", i); |
||
388 | hcor[i] = (TH2F*)gROOT->FindObject(hname); |
||
389 | if(hcor[i]) delete hcor[i]; |
||
390 | //~ hcor[i] = new TH2F(hname, hname, 256, 0-0.5, 1024-0.5, 200, 10-(TDC_BIN/2), 20-(TDC_BIN/2)); |
||
391 | //~ hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 1024-0.5, 4096, -32768.5*TDC_BIN, 32767.5*TDC_BIN); |
||
392 | //~ hcor[i] = new TH2F(hname, hname, 256, 0-0.5, 512-0.5, 160, -2-(TDC_BIN/2), 2-(TDC_BIN/2)); |
||
393 | hcor[i] = new TH2F(hname, hname, 512, 0-0.5, 1024-0.5, 160, -1.5-(TDC_BIN/2), 2.5-(TDC_BIN/2)); |
||
394 | |||
395 | |||
396 | for(int j=0; j<ANALYSE_CH; j++) { |
||
397 | sprintf(hname, "hdiffcor_%d_%d",i,j); |
||
398 | sprintf(htitle, "ch.%d - ch.%d",i,j); |
||
399 | hdiffcor[i][j] = (TH2F*)gROOT->FindObject(hname); |
||
400 | if(hdiffcor[i][j]) delete hdiffcor[i][j]; |
||
401 | hdiffcor[i][j] = new TH2F(hname, htitle, 256, 0-0.5, 1024-0.5, 128, -6.4-(TDC_BIN/2), 6.4-(TDC_BIN/2)); |
||
402 | |||
403 | sprintf(hname, "hdiffcor_low_%d_%d",i,j); |
||
404 | sprintf(htitle, "ch.%d - ch.%d",i,j); |
||
405 | hdiffcor_low[i][j] = (TH2F*)gROOT->FindObject(hname); |
||
406 | if(hdiffcor_low[i][j]) delete hdiffcor_low[i][j]; |
||
407 | hdiffcor_low[i][j] = new TH2F(hname, htitle, 256, 0-0.5, 512-0.5, 128, -6.4-(TDC_BIN/2), 6.4-(TDC_BIN/2)); |
||
408 | |||
409 | sprintf(hname, "hdiffcor_hi_%d_%d",i,j); |
||
410 | sprintf(htitle, "ch.%d - ch.%d",i,j); |
||
411 | hdiffcor_hi[i][j] = (TH2F*)gROOT->FindObject(hname); |
||
412 | if(hdiffcor_hi[i][j]) delete hdiffcor_hi[i][j]; |
||
413 | hdiffcor_hi[i][j] = new TH2F(hname, htitle, 256, 0-0.5, 2048-0.5, 128, -6.4-(TDC_BIN/2), 6.4-(TDC_BIN/2)); |
||
414 | } |
||
415 | } |
||
416 | |||
417 | break; |
||
418 | |||
419 | case POSREC_ID: |
||
420 | #ifdef USE_ZLIB |
||
421 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
422 | #else |
||
423 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
424 | #endif |
||
425 | |||
426 | pos=*posrec; |
||
427 | |||
428 | if(dbg) { |
||
429 | printf("POSREC_ID\n"); |
||
430 | printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time); |
||
431 | printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset); |
||
432 | printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset); |
||
433 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
||
434 | |||
435 | break; |
||
436 | |||
437 | case EVTREC_ID: |
||
438 | #ifdef USE_ZLIB |
||
439 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
440 | #else |
||
441 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
442 | #endif |
||
443 | |||
444 | |||
445 | if(dbg) { |
||
446 | //~ printf("EVTREC_ID\n"); |
||
447 | //~ printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
||
448 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
||
449 | //printf("\n"); |
||
450 | //for(int datai = NCH; datai < NCH+NCH; datai++) printf("%u ", evtrec->data[datai]); |
||
451 | //printf("\n"); |
||
452 | //break; |
||
453 | } |
||
454 | // events ------------------------------------------------------------------------------------------ |
||
455 | // fill histograms |
||
456 | |||
457 | double tdc_noise_cut; |
||
458 | //~ double adc_cor_min; |
||
459 | double tdca[ANALYSE_CH]; |
||
460 | double ctdca[ANALYSE_CH]; |
||
461 | double adca[ANALYSE_CH]; |
||
462 | double ctdcdiff, tdcdiff; |
||
463 | |||
464 | |||
465 | tdc_noise_cut = 5.0; |
||
466 | //~ adc_cor_min = 200.0; |
||
467 | |||
468 | for(int i=0; i<ANALYSE_CH; i++) { |
||
469 | tdc=((double)evtrec->data[i])*TDC_BIN + tdcoffset[i]; |
||
470 | //~ tdc=((double)evtrec->data[i])*TDC_BIN; |
||
471 | |||
472 | adc=(double)evtrec->data[i+NCH]; |
||
473 | //~ if(i==15) printf("aaaaaaaaaaa15 norma %f\n",tdc); |
||
474 | tdca[i]=tdc; |
||
475 | adca[i]=adc; |
||
476 | |||
477 | //~ if(ceve < 100) { |
||
478 | //~ printf("[%3d] tdc[%2d] = %lf | adc[%2d] = %lf\n", ceve, i, tdc, i, adc); |
||
479 | //~ } |
||
480 | } |
||
481 | for(int i=0; i<ANALYSE_CH; i++) { |
||
482 | if(0 < adca[i]) hadc[i]->Fill(adca[i]); |
||
483 | //~ if( (qdcmi < adca[i]) && (adca[i] < qdcma) ) |
||
484 | if(0 < tdca[i]) htdc[i]->Fill(tdca[i]-tdca[TRIGGER_CH]); |
||
485 | //~ if(0 < tdca[i]) htdc[i]->Fill(tdca[i]); |
||
486 | hcor[i]->Fill(adca[i],tdca[i]-tdca[TRIGGER_CH]); |
||
487 | |||
488 | if(adca[i] > corpar[i][2]) { |
||
489 | ctdca[i] = tdca[i]-tdca[TRIGGER_CH] - (corpar[i][0] + corpar[i][1]/TMath::Sqrt(adca[i] - corpar[i][2])); |
||
490 | } else { |
||
491 | ctdca[i] = -999.9*(i+1); |
||
492 | } |
||
493 | //~ if(tdc_noise_cut < tdca[i]) |
||
494 | double adc_max_cut = 1000; |
||
495 | if(adca[i] < adc_max_cut) |
||
496 | hctdc[i]->Fill( ctdca[i] ); |
||
497 | |||
498 | //~ if(dbg && (i<4) && (1 < tdca[0] && (1 < tdca[1]))) printf("tdca[%d] = %lf | tdca[TRG] = %lf | ctdca[i] = %lf | adca[i] = %lf\n", i, tdca[i],tdca[TRIGGER_CH],ctdca[i],adca[i]); |
||
499 | if(dbg && (i<4) ) printf("[%4d] tdca[%d] = %lf | tdca[TRG] = %lf | ctdca[i] = %lf | adca[i] = %lf\n", ceve, i, tdca[i],tdca[TRIGGER_CH],ctdca[i],adca[i]); |
||
500 | |||
501 | if( (qdcmi < adca[i]) && (adca[i] < qdcma) && (tdcmi < tdca[i]) && (tdca[i] < tdcma)) { |
||
502 | h2d[i]->Fill(pos.xset*MIKRO_BIN, pos.yset*MIKRO_BIN); |
||
503 | } |
||
504 | } |
||
505 | |||
506 | //~ printf("aaaaaaaaaaa15 %f\n",((double)evtrec->data[15])); printf("aaaaaaaaaaa15 %f\n",((double)evtrec->data[15])*TDC_BIN); |
||
507 | //~ printf("aaaaaaaaaaa30 %d\n",evtrec->data[30]); |
||
508 | //~ printf("aaaaaaaaaaa31 %d\n",evtrec->data[31]); |
||
509 | //~ printf("aaaaaaaaaaa15 %f\n",tdca[15]); |
||
510 | //~ printf("aaaaaaaaaaa30 %d\n",tdca[30]); |
||
511 | //~ printf("aaaaaaaaaaa31 %d\n",tdca[31]); |
||
512 | //~ |
||
513 | //kobayashi |
||
514 | ctdcdiff = ctdca[MPPC_2_CH] - ctdca[MPPC_1_CH] +deltaT_ctdcdiff; |
||
515 | tdcdiff = tdca[MPPC_2_CH] - tdca[MPPC_1_CH]; |
||
516 | t_ctdc = ctdcdiff; |
||
517 | t_tdc0=tdca[0]; |
||
518 | t_tdc1=tdca[1]; |
||
519 | t_adc0=adca[15]; |
||
520 | t_adc1=adca[1]; |
||
521 | |||
522 | hcoradctdc0->Fill(adca[0],ctdcdiff); |
||
523 | hcoradctdc1->Fill(adca[1],ctdcdiff); |
||
524 | ftt->Fill(); |
||
525 | #ifdef testpulse |
||
526 | htesttdc1->Fill(tdca[16]-tdca[14]); |
||
527 | htesttdc2->Fill(tdca[14]-tdca[15]); |
||
528 | #endif |
||
529 | |||
530 | //cut za timing: |
||
531 | #define CUT_1_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) && (tdcmi < adca[MPPC_2_CH]) && (adca[MPPC_2_CH] < tdcma) ) |
||
532 | //~ // cut za meritev efficiency: |
||
533 | //~ #define CUT_1_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) ) |
||
534 | |||
535 | //~ #define CUT_1_CONDITION ( (tdcmi < ctdcdiff) && (ctdcdiff < tdcma) ) |
||
536 | //~ #define CUT_1_CONDITION ( (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) ) |
||
537 | //~ #define CUT_1_CONDITION ( (qdcmi < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < qdcma) ) |
||
538 | //~ #define CUT_1_CONDITION ( (ref_cut_1_lo < adca[REF_CH]) && (adca[REF_CH] < ref_cut_1_hi) && (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) ) |
||
539 | |||
540 | |||
541 | // cut za meritev efficiency: |
||
542 | #define CUT_2_CONDITION ( (tdcmi < adca[REF_CH]) && (adca[REF_CH] < tdcma) ) |
||
543 | //~ #define CUT_2_CONDITION ( (qdcmi < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < qdcma) && (tdcmi < adca[REF_CH]) && (adca[REF_CH] < tdcma) ) |
||
544 | //~ #define CUT_2_CONDITION ( (ref_cut_1_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_1_hi) ) |
||
545 | //~ #define CUT_2_CONDITION ( (qdcmi < adca[REF_CH]) && (adca[REF_CH] < qdcma) && (tdcmi < tdca[REF_CH]) && (tdca[REF_CH] < tdcma) ) |
||
546 | //~ #define CUT_2_CONDITION ( (ref_cut_1_lo < adca[MPPC_1_CH]) && (adca[MPPC_1_CH] < ref_cut_1_hi) && (ref_cut_2_lo < adca[MPPC_2_CH]) && (adca[MPPC_2_CH] < ref_cut_2_hi) ) |
||
547 | //~ #define CUT_2_CONDITION ( (ref_cut_2_lo < adca[REF_CH]) && (adca[REF_CH] < ref_cut_2_hi) ) |
||
548 | //~ #define CUT_2_CONDITION ( (ref_cut_1_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_1_hi) && (ref_cut_2_lo < tdca[MPPC_2_CH]) && (tdca[MPPC_2_CH] < ref_cut_2_hi) ) |
||
549 | //~ #define CUT_2_CONDITION ( (ref_cut_2_lo < tdca[REF_CH]) && (tdca[REF_CH] < ref_cut_2_hi) && (ref_cut_2_lo < tdca[MPPC_1_CH]) && (tdca[MPPC_1_CH] < ref_cut_2_hi) ) |
||
550 | |||
551 | |||
552 | if( (tdc_noise_cut < tdca[MPPC_1_CH]) && (tdc_noise_cut < tdca[MPPC_2_CH])) { |
||
553 | //~ if( (qdcmi < adca[MPPC_1_CH]) && (tdcmi < adca[MPPC_2_CH]) ) |
||
554 | htdcdiff->Fill(ctdcdiff); |
||
555 | |||
556 | if( CUT_1_CONDITION ) { |
||
557 | htdcdiff_cut->Fill(ctdcdiff); |
||
558 | //~ htdcdiff_cut->Fill(tdcdiff); |
||
559 | } |
||
560 | if( CUT_2_CONDITION ) { |
||
561 | htdcdiff_cut_2->Fill(ctdcdiff); |
||
562 | } |
||
563 | } |
||
564 | |||
565 | for(int i=0; i<ANALYSE_CH; i++) { |
||
566 | |||
567 | //~ if( CUT_1_CONDITION ) { |
||
568 | //~ if( ( (qdcmi < adca[REF_CH]) && (adca[REF_CH] < qdcma) ) ) { |
||
569 | //~ if( ( (-2 < ctdca[0]) && (ctdca[0] < 2) ) ) { |
||
570 | //~ htdc_cut[i]->Fill(tdca[i]-tdca[31]); |
||
571 | //~ htdc_cut[i]->Fill(ctdca[i]); |
||
572 | //~ hadc_cut[i]->Fill(adca[i]); |
||
573 | //~ } |
||
574 | if( (qdcmi < adca[i]) && (adca[i] < qdcma) && (adca[i] > corpar[i][2]) ) |
||
575 | htdc_cut[i]->Fill(ctdca[i]); |
||
576 | if( (tdcmi < ctdca[i]) && (ctdca[i] < tdcma) ) |
||
577 | hadc_cut[i]->Fill(adca[i]); |
||
578 | |||
579 | if( CUT_2_CONDITION ) { |
||
580 | htdc_cut_2[i]->Fill(tdca[i]); |
||
581 | hadc_cut_2[i]->Fill(adca[i]); |
||
582 | hadc_cut_2[i]->Fill(adca[i]); |
||
583 | } |
||
584 | } |
||
585 | |||
586 | //~ hadccor->Fill(adca[REF_CH], adca[MPPC_1_CH]); |
||
587 | hadccor->Fill(adca[REF_CH], tdca[8]-tdca[31]); |
||
588 | |||
589 | htdccor->Fill(tdca[MPPC_1_CH], tdca[MPPC_2_CH]); |
||
590 | |||
591 | |||
592 | // --------------- corelation plots for time-walk correction --------------- |
||
593 | |||
594 | if( (tdc_noise_cut<tdca[MPPC_1_CH]) && (tdc_noise_cut<tdca[MPPC_2_CH]) && (adc_cor_min<adca[MPPC_2_CH]) ) { |
||
595 | hdiffcor[MPPC_1_CH][MPPC_2_CH]->Fill(adca[MPPC_1_CH],tdca[MPPC_1_CH]-ctdca[MPPC_2_CH]); |
||
596 | |||
597 | hdiffcor_low[MPPC_1_CH][MPPC_2_CH]->Fill(adca[MPPC_1_CH],tdca[MPPC_1_CH]-ctdca[MPPC_2_CH]); |
||
598 | hdiffcor_hi[MPPC_1_CH][MPPC_2_CH]->Fill(adca[MPPC_1_CH],tdca[MPPC_1_CH]-ctdca[MPPC_2_CH]); |
||
599 | } |
||
600 | |||
601 | if( (tdc_noise_cut<tdca[MPPC_2_CH]) && (tdc_noise_cut<tdca[MPPC_1_CH]) && (adc_cor_min<adca[MPPC_1_CH]) ) { |
||
602 | hdiffcor[MPPC_2_CH][MPPC_1_CH]->Fill(adca[MPPC_2_CH],tdca[MPPC_2_CH]-ctdca[MPPC_1_CH]); |
||
603 | |||
604 | hdiffcor_low[MPPC_2_CH][MPPC_1_CH]->Fill(adca[MPPC_2_CH],tdca[MPPC_2_CH]-ctdca[MPPC_1_CH]); |
||
605 | hdiffcor_hi[MPPC_2_CH][MPPC_1_CH]->Fill(adca[MPPC_2_CH],tdca[MPPC_2_CH]-ctdca[MPPC_1_CH]); |
||
606 | } |
||
607 | |||
608 | // events ------------------------------------------------------------------------------------------ |
||
609 | |||
610 | break; |
||
611 | |||
612 | case ENDREC_ID: |
||
613 | #ifdef USE_ZLIB |
||
614 | gzread(dfp, (voidp)&readbuf[2*ulsize], (rec_len-2*ulsize)); |
||
615 | #else |
||
616 | fread( (void*)&readbuf[2*ulsize], (rec_len-2*ulsize), 1, dfp); |
||
617 | #endif |
||
618 | |||
619 | if(dbg) { |
||
620 | printf("ENDREC_ID\n"); |
||
621 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
||
622 | } else printf(" ENDREC\n"); |
||
623 | |||
624 | fcount++; |
||
625 | switch(ftype-1) { |
||
626 | case 0: |
||
627 | sprintf(dfile, "data/%s_file%02d.dat", dfile0, fcount); |
||
628 | break; |
||
629 | case 1: |
||
630 | sprintf(dfile, "data/%s_file%02d.dat.gz", dfile0, fcount); |
||
631 | break; |
||
632 | case 2: |
||
633 | sprintf(dfile, "data/%s_file%02d.gz", dfile0, fcount); |
||
634 | break; |
||
635 | } |
||
636 | |||
637 | #ifdef USE_ZLIB |
||
638 | if(dfp) gzclose(dfp); |
||
639 | dfp=gzopen(dfile,"rb"); |
||
640 | #else |
||
641 | if(dfp) fclose(dfp); |
||
642 | dfp=fopen(dfile,"rb"); |
||
643 | #endif |
||
644 | |||
645 | if(!dfp) { |
||
646 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
||
647 | end_of_file = 1; |
||
648 | } else { |
||
649 | printf(" Opened data file: %s\n", dfile); |
||
650 | end_of_file = 0; |
||
651 | } |
||
652 | |||
653 | break; |
||
654 | |||
655 | default: |
||
656 | printf("switch(rec_id): default !!!\n"); |
||
657 | end_of_file = 1; |
||
658 | break; |
||
659 | } |
||
660 | |||
661 | ceve++; |
||
662 | if( (ceve%50000) == 0) printf(" Current event = %d\n", ceve); |
||
663 | if(dbg) if( ceve>dbg ) break; |
||
664 | if(end_of_file) break; |
||
665 | } |
||
666 | |||
667 | |||
668 | #ifdef USE_ZLIB |
||
669 | if(dfp) gzclose(dfp); |
||
670 | #else |
||
671 | if(dfp) fclose(dfp); |
||
672 | #endif |
||
673 | |||
674 | if(dbg) return 1; |
||
675 | if(rootfile) { |
||
676 | #ifdef testpulse |
||
677 | printf("<<< EASIROC Disc : %f [ps]\n", htesttdc1->GetRMS()*1000); |
||
678 | printf("<<< TEST Disc : %f [ps]\n", htesttdc2->GetRMS()*1000); |
||
679 | #endif |
||
680 | ftt->Write(); |
||
681 | rootfile->Write(); |
||
682 | //cout<<"maximum x value = " << htdcdiff->GetXaxis()->GetBinCenter( htdcdiff->GetMaximumBin()) <<endl; |
||
683 | printf("Saved to %s\n", fnameroot); |
||
684 | rootfile->Close(); |
||
685 | } |
||
686 | |||
687 | gSystem->Exit(1); |
||
688 | |||
689 | return 1; |
||
690 | } |