Rev 47 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 47 | Rev 50 | ||
|---|---|---|---|
| 1 | ////////////////////////////////////////// |
1 | ////////////////////////////////////////// |
| 2 | // Data to root conversion root script |
2 | // Data to root conversion root script |
| 3 | // |
3 | // |
| 4 | // Contributors: Rok Pestotnik, Rok Dolenec, Dino Tahirovic |
4 | // Contributors: Rok Pestotnik, Rok Dolenec, Dino Tahirovic |
| 5 | // |
5 | // |
| 6 | // 3/1/2014 TDC cut relative to tdc offset |
6 | // 3/1/2014 TDC cut relative to tdc offset |
| 7 | // 5/3/2014 TH3F h_correctedTDC; commented 'delete' commands |
7 | // 5/3/2014 TH3F h_correctedTDC; commented 'delete' commands |
| 8 | // 12/3/2014 declarations of all histos before while{} |
8 | // 12/3/2014 declarations of all histos before while{} |
| 9 | 9 | ||
| 10 | #include "stdio.h" |
10 | #include "stdio.h" |
| 11 | #include "TROOT.h" |
11 | #include "TROOT.h" |
| 12 | #include "TFile.h" |
12 | #include "TFile.h" |
| 13 | #include "TNtuple.h" |
13 | #include "TNtuple.h" |
| 14 | #include "TH1F.h" |
14 | #include "TH1F.h" |
| 15 | #include "TH2F.h" |
15 | #include "TH2F.h" |
| 16 | #include "TH3F.h" |
16 | #include "TH3F.h" |
| 17 | #include "TF1.h" |
17 | #include "TF1.h" |
| 18 | #include "TMath.h" |
18 | #include "TMath.h" |
| 19 | #include "TStyle.h" |
19 | #include "TStyle.h" |
| 20 | #include "TCanvas.h" |
20 | #include "TCanvas.h" |
| 21 | #include "TLine.h" |
21 | #include "TLine.h" |
| 22 | #include "zlib.h" |
22 | #include "zlib.h" |
| 23 | 23 | ||
| 24 | // ------------------------------------------------------------------------------ |
24 | // ------------------------------------------------------------------------------ |
| 25 | 25 | ||
| 26 | #define POSMARG 1000 |
26 | #define POSMARG 1000 |
| 27 | 27 | ||
| 28 | #define READBUFFERLENGTH 10000 |
28 | #define READBUFFERLENGTH 10000 |
| 29 | 29 | ||
| 30 | // data format |
30 | // data format |
| 31 | #define MAXDATA 16 |
31 | #define MAXDATA 16 |
| 32 | #define NCH 64 |
32 | #define NCH 64 |
| 33 | #define TDC_BIN 1.0416 // 1 TDC bin in ns |
33 | #define TDC_BIN 1.0416 // 1 TDC bin in ns |
| 34 | #define MIKRO_BIN 0.49609/1000. //1 mikro step in mm; stage MM3MF |
34 | #define MIKRO_BIN 0.49609/1000. //1 mikro step in mm; stage MM3MF |
| 35 | #define OFFSETX 4800 // Right edge of SiPM+Lightguide |
35 | #define OFFSETX 4800 // Right edge of SiPM+Lightguide |
| 36 | #define OFFSETY 3400 // Lower edge of SiPM+Lightguide |
36 | #define OFFSETY 3400 // Lower edge of SiPM+Lightguide |
| 37 | 37 | ||
| 38 | #define RUNREC_ID 1 |
38 | #define RUNREC_ID 1 |
| 39 | #define ENDREC_ID 2 |
39 | #define ENDREC_ID 2 |
| 40 | #define POSREC_ID 3 |
40 | #define POSREC_ID 3 |
| 41 | #define EVTREC_ID 4 |
41 | #define EVTREC_ID 4 |
| 42 | #define THRREC_ID 5 |
42 | #define THRREC_ID 5 |
| 43 | #define BIASREC_ID 6 |
43 | #define BIASREC_ID 6 |
| 44 | 44 | ||
| 45 | typedef struct { |
45 | typedef struct { |
| 46 | unsigned int id,len; |
46 | unsigned int id,len; |
| 47 | unsigned int fver,time; |
47 | unsigned int fver,time; |
| 48 | unsigned int thLow, thUp, thStep; |
48 | unsigned int thLow, thUp, thStep; |
| 49 | unsigned int biasLow, biasUp, biasStep; |
49 | unsigned int biasLow, biasUp, biasStep; |
| 50 | unsigned int nev,nch,ped,xy; |
50 | unsigned int nev,nch,ped,xy; |
| 51 | int nx,x0,dx,ny,y0,dy; |
51 | int nx,x0,dx,ny,y0,dy; |
| 52 | } RUNREC; |
52 | } RUNREC; |
| 53 | RUNREC *runrec; |
53 | RUNREC *runrec; |
| 54 | RUNREC run; |
54 | RUNREC run; |
| 55 | 55 | ||
| 56 | typedef struct { |
56 | typedef struct { |
| 57 | unsigned int id,len; |
57 | unsigned int id,len; |
| 58 | unsigned int time; |
58 | unsigned int time; |
| 59 | } ENDREC; |
59 | } ENDREC; |
| 60 | ENDREC *endrec; |
60 | ENDREC *endrec; |
| 61 | 61 | ||
| 62 | typedef struct { |
62 | typedef struct { |
| 63 | unsigned int id,len; |
63 | unsigned int id,len; |
| 64 | unsigned int time; |
64 | unsigned int time; |
| 65 | int ix; |
65 | int ix; |
| 66 | int x; |
66 | int x; |
| 67 | int xset; |
67 | int xset; |
| 68 | int iy; |
68 | int iy; |
| 69 | int y; |
69 | int y; |
| 70 | int yset; |
70 | int yset; |
| 71 | } POSREC; |
71 | } POSREC; |
| 72 | POSREC *posrec; |
72 | POSREC *posrec; |
| 73 | POSREC pos; |
73 | POSREC pos; |
| 74 | 74 | ||
| 75 | typedef struct { |
75 | typedef struct { |
| 76 | unsigned int id; |
76 | unsigned int id; |
| 77 | unsigned int len; |
77 | unsigned int len; |
| 78 | unsigned int nev; |
78 | unsigned int nev; |
| 79 | } EVTREC; |
79 | } EVTREC; |
| 80 | EVTREC *evtrec; |
80 | EVTREC *evtrec; |
| 81 | 81 | ||
| 82 | typedef struct { |
82 | typedef struct { |
| 83 | unsigned int id; |
83 | unsigned int id; |
| 84 | unsigned int len; |
84 | unsigned int len; |
| 85 | unsigned int threshold; |
85 | unsigned int threshold; |
| 86 | } THRREC; |
86 | } THRREC; |
| 87 | THRREC *thrrec; |
87 | THRREC *thrrec; |
| 88 | THRREC thr; |
88 | THRREC thr; |
| 89 | 89 | ||
| 90 | typedef struct { |
90 | typedef struct { |
| 91 | unsigned int id; |
91 | unsigned int id; |
| 92 | unsigned int len; |
92 | unsigned int len; |
| 93 | unsigned int bias; |
93 | unsigned int bias; |
| 94 | } BIASREC; |
94 | } BIASREC; |
| 95 | BIASREC *biasrec; |
95 | BIASREC *biasrec; |
| 96 | BIASREC bias; |
96 | BIASREC bias; |
| 97 | 97 | ||
| 98 | double padCenter[NCH][2]; |
98 | double padCenter[NCH][2]; |
| 99 | 99 | ||
| 100 | int position(int, int, int); |
100 | int position(int, int, int); |
| 101 | 101 | ||
| 102 | // ------------------------------------------------------------------------------ |
102 | // ------------------------------------------------------------------------------ |
| 103 | 103 | ||
| 104 | int analysisBias(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
104 | int analysisBias(char* dfile0="test", int dbg=0, double tdcCut=5.0) |
| 105 | { |
105 | { |
| 106 | const double c_tdcOffset = |
106 | const double c_tdcOffset = 97*TDC_BIN; // ns, SiPM4 |
| 107 | 107 | ||
| 108 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
108 | printf(" Data to root conversion program\nUsage:\nd2r(input file name <without.dat>, debug on/off, TDC cut +-[ns])\n\n"); |
| 109 | 109 | ||
| 110 | char fullname[256]; |
110 | char fullname[256]; |
| 111 | char sbuff[256]; |
111 | char sbuff[256]; |
| 112 | FILE *fp; |
112 | FILE *fp; |
| 113 | 113 | ||
| 114 | //Chanel information |
114 | //Chanel information |
| 115 | 115 | ||
| 116 | double tdcOffset[NCH]; |
116 | double tdcOffset[NCH]; |
| 117 | sprintf(fullname, "d2r.ini"); |
117 | sprintf(fullname, "d2r.ini"); |
| 118 | if( (fp=fopen(fullname, "rt")) == NULL ) |
118 | if( (fp=fopen(fullname, "rt")) == NULL ) |
| 119 | printf("Cannot open pad centers file %s !!!\n", fullname); |
119 | printf("Cannot open pad centers file %s !!!\n", fullname); |
| 120 | else { |
120 | else { |
| 121 | printf("Opened pad centers file %s\n", fullname); |
121 | printf("Opened pad centers file %s\n", fullname); |
| 122 | char* result = fgets(sbuff,256, fp); |
122 | char* result = fgets(sbuff,256, fp); |
| 123 | if (dbg) printf("Read buffer %s\n", result); |
123 | if (dbg) printf("Read buffer %s\n", result); |
| 124 | printf("%s", sbuff); |
124 | printf("%s", sbuff); |
| 125 | for(int i=0; i<NCH; i++) { |
125 | for(int i=0; i<NCH; i++) { |
| 126 | int channel; |
126 | int channel; |
| 127 | int message = fscanf(fp, "%d %lf %lf %lf\n", &channel, &padCenter[i][0], &padCenter[i][1], &tdcOffset[i]); |
127 | int message = fscanf(fp, "%d %lf %lf %lf\n", &channel, &padCenter[i][0], &padCenter[i][1], &tdcOffset[i]); |
| 128 | if (dbg) printf("Read d2r.ini returned %d\n", message); |
128 | if (dbg) printf("Read d2r.ini returned %d\n", message); |
| 129 | } |
129 | } |
| 130 | fclose(fp); |
130 | fclose(fp); |
| 131 | } |
131 | } |
| 132 | for(int i=0; i<NCH; i++) { |
132 | for(int i=0; i<NCH; i++) { |
| 133 | tdcOffset[i] += c_tdcOffset; |
133 | tdcOffset[i] += c_tdcOffset; |
| 134 | printf("%.2lf %.2lf %.2lf\n", padCenter[i][0], padCenter[i][1], tdcOffset[i]); |
134 | printf("%.2lf %.2lf %.2lf\n", padCenter[i][0], padCenter[i][1], tdcOffset[i]); |
| 135 | } |
135 | } |
| 136 | 136 | ||
| 137 | //data buffer |
137 | //data buffer |
| 138 | unsigned int readbuf[READBUFFERLENGTH]; |
138 | unsigned int readbuf[READBUFFERLENGTH]; |
| 139 | unsigned int buf[READBUFFERLENGTH]; |
139 | unsigned int buf[READBUFFERLENGTH]; |
| 140 | 140 | ||
| 141 | //data file |
141 | //data file |
| 142 | gzFile dfp; |
142 | gzFile dfp; |
| 143 | char dfile[256]; |
143 | char dfile[256]; |
| 144 | int ftype=0; |
144 | int ftype=0; |
| 145 | int fcount=1; |
145 | int fcount=1; |
| 146 | do { |
146 | do { |
| 147 | switch(ftype++) { |
147 | switch(ftype++) { |
| 148 | case 0: |
148 | case 0: |
| 149 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
149 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
| 150 | break; |
150 | break; |
| 151 | case 1: |
151 | case 1: |
| 152 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
152 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
| 153 | break; |
153 | break; |
| 154 | case 2: |
154 | case 2: |
| 155 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
155 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
| 156 | break; |
156 | break; |
| 157 | default: |
157 | default: |
| 158 | printf(" Cannot find data file for %s !!!\n", dfile0); |
158 | printf(" Cannot find data file for %s !!!\n", dfile0); |
| 159 | return -1; |
159 | return -1; |
| 160 | } |
160 | } |
| 161 | dfp=gzopen(dfile,"rb"); |
161 | dfp=gzopen(dfile,"rb"); |
| 162 | } while(!dfp); |
162 | } while(!dfp); |
| 163 | printf("Opened data file %s\n", dfile); |
163 | printf("Opened data file %s\n", dfile); |
| 164 | 164 | ||
| 165 | //opens ROOT file |
165 | //opens ROOT file |
| 166 | char fnameroot[256]; |
166 | char fnameroot[256]; |
| 167 | sprintf(fnameroot, "root/%s.root", dfile0); |
167 | sprintf(fnameroot, "root/%s.root", dfile0); |
| 168 | TFile rootfile(fnameroot,"RECREATE",dfile0); |
168 | TFile rootfile(fnameroot,"RECREATE",dfile0); |
| 169 | if (rootfile.IsZombie()) { |
169 | if (rootfile.IsZombie()) { |
| 170 | std::cout << "Error opening file" << std::endl; |
170 | std::cout << "Error opening file" << std::endl; |
| 171 | exit(-1); |
171 | exit(-1); |
| 172 | } |
172 | } |
| 173 | if (rootfile.IsOpen()) std::cout << "ROOT file opened for writing." << std::endl; |
173 | if (rootfile.IsOpen()) std::cout << "ROOT file opened for writing." << std::endl; |
| 174 | 174 | ||
| 175 | // ----------------------------------------------- |
175 | // ----------------------------------------------- |
| 176 | // loop trough records |
176 | // loop trough records |
| 177 | unsigned int rec_id, rec_len; |
177 | unsigned int rec_id, rec_len; |
| 178 | unsigned int ulsize = sizeof(unsigned int); |
178 | unsigned int ulsize = sizeof(unsigned int); |
| 179 | //unsigned int ulsize = 4; |
179 | //unsigned int ulsize = 4; |
| 180 | if (dbg) printf("Size of unsigned int: %lu\n", sizeof(unsigned int)); |
180 | if (dbg) printf("Size of unsigned int: %lu\n", sizeof(unsigned int)); |
| 181 | int ceve=0; |
181 | int ceve=0; |
| 182 | int end_of_file = 0; |
182 | int end_of_file = 0; |
| 183 | 183 | ||
| 184 | int ii; |
184 | int ii; |
| 185 | int nint; |
185 | int nint; |
| 186 | int nb; |
186 | int nb; |
| 187 | int status; |
187 | int status; |
| 188 | char hname[256]; |
188 | char hname[256]; |
| - | 189 | // Full range TDC data for every channel |
|
| 189 | TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
190 | TH2F* htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,-0.5,511.5,NCH,-0.5,NCH-0.5); |
| - | 191 | // TDC data in specific time window |
|
| 190 | TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
192 | TH3F* h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
| 191 | NCH, -0.5, NCH-0.5, |
193 | NCH, -0.5, NCH-0.5, |
| 192 | 101, 1.0, 2.0, |
194 | 101, 1.0, 2.0, |
| 193 | 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
195 | 33, -16.5*TDC_BIN, 16.5*TDC_BIN); |
| - | 196 | // Hits distribution in every channel per stage position |
|
| 194 | TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
197 | TH1F* hnhitsx[NCH]; // move to 2d with (channel, position) |
| 195 | TH1F* hnhitsy[NCH]; //-||- |
198 | TH1F* hnhitsy[NCH]; //-||- |
| - | 199 | // 2d hits distribution |
|
| 196 | TH2F* h2d[NCH]; //-||- |
200 | TH2F* h2d[NCH]; //-||- |
| - | 201 | int nBiasSteps = 20; |
|
| - | 202 | double biasLow = 71.0; |
|
| - | 203 | double biasUp = 73.0; |
|
| 197 | TH2F* h_bias = new TH2F("h_bias", "", 64, 0, 63, |
204 | TH2F* h_bias = new TH2F("h_bias", "", 64, 0, 63, nBiasSteps, biasLow, biasUp); |
| - | 205 | int nSteps = 51; |
|
| - | 206 | double thrLow = 1.0; |
|
| - | 207 | double thrUp = 2.0; |
|
| 198 | TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
208 | TH2F* h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]", |
| 199 | 64,-0.5,63.5, |
209 | 64,-0.5,63.5, |
| 200 |
|
210 | nSteps, thrLow, thrUp); |
| - | 211 | // Bias vs. ASD threshold per channel to estimate working point |
|
| - | 212 | TH3F* h_biasThreshold = new TH3F("h_biasThreshold","", 64,-0.5, 63.5, |
|
| - | 213 | 31, 71.0, 74.0, 51, 1.0, 2.0); |
|
| 201 | TH2F* h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
214 | TH2F* h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
| 202 | TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
215 | TNtuple* nt = new TNtuple("nt", "nt", "ch:x:y:tdc"); |
| 203 | 216 | ||
| 204 | while(1) { |
217 | while(1) { |
| 205 | if(gzeof(dfp)) end_of_file = 1; |
218 | if(gzeof(dfp)) end_of_file = 1; |
| 206 | 219 | ||
| 207 | gzread(dfp, (voidp)&readbuf, 2*ulsize); |
220 | gzread(dfp, (voidp)&readbuf, 2*ulsize); |
| 208 | rec_id=readbuf[0]; |
221 | rec_id=readbuf[0]; |
| 209 | rec_len=readbuf[1]; |
222 | rec_len=readbuf[1]; |
| 210 | 223 | ||
| 211 | 224 | ||
| 212 | if(dbg) printf("-----------------------------------------------\n"); |
225 | if(dbg) printf("-----------------------------------------------\n"); |
| 213 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
226 | if(dbg) printf("[%d] rec_id = %d | rec_len = %u\n", ceve, rec_id, rec_len); |
| 214 | 227 | ||
| 215 | int nSteps = 0; |
- | |
| 216 | int nBiasSteps = 0; |
- | |
| - | 228 | ||
| - | 229 | ||
| 217 | 230 | ||
| 218 | switch(rec_id) |
231 | switch(rec_id) |
| 219 | { |
232 | { |
| 220 | case RUNREC_ID: |
233 | case RUNREC_ID: |
| 221 | if (dbg) printf("RUNREC\n"); |
234 | if (dbg) printf("RUNREC\n"); |
| 222 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
235 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| 223 | runrec = (RUNREC *) readbuf; |
236 | runrec = (RUNREC *) readbuf; |
| 224 | run=*runrec; |
237 | run=*runrec; |
| 225 | 238 | ||
| 226 | if(dbg) { |
239 | if(dbg) { |
| 227 | printf("RUNREC_ID\n"); |
240 | printf("RUNREC_ID\n"); |
| 228 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
241 | printf("id = %d, len = %d, time = %d\n", run.id, run.len, run.time); |
| 229 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
242 | printf("nev = %d, nch = %d\n", run.nev, run.nch); |
| 230 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
243 | printf("nx = %d, x0 = %d, dx = %d\n", run.nx, run.x0, run.dx); |
| 231 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
244 | printf("ny = %d, y0 = %d, dy = %d\n", run.ny, run.y0, run.dy); |
| 232 | printf("thLow = %d, thUp = %d, thStep = %d\n", run.thLow, run.thUp, run.thStep); |
245 | printf("thLow = %d, thUp = %d, thStep = %d\n", run.thLow, run.thUp, run.thStep); |
| 233 | } |
246 | } |
| 234 | 247 | ||
| 235 | //create histograms |
248 | //create histograms |
| 236 | //nt = (TNtuple*) gROOT->FindObject("nt"); |
249 | //nt = (TNtuple*) gROOT->FindObject("nt"); |
| 237 | //if (nt) delete nt; |
250 | //if (nt) delete nt; |
| 238 | 251 | ||
| 239 | //sprintf(hname, "htdc"); |
252 | //sprintf(hname, "htdc"); |
| 240 | //htdc = (TH2F*) gROOT->FindObject(hname); |
253 | //htdc = (TH2F*) gROOT->FindObject(hname); |
| 241 | //if (htdc) delete htdc; |
254 | //if (htdc) delete htdc; |
| 242 | //htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
255 | //htdc = new TH2F("htdc",";TDC channel;SiPM channel",512,0,512,NCH,0,NCH); |
| 243 | 256 | ||
| 244 | //TH1F* gsumV673A[NCH/16] = new TH1F(hn,hname,256,-0.5,255.5); |
257 | //TH1F* gsumV673A[NCH/16] = new TH1F(hn,hname,256,-0.5,255.5); |
| 245 | for(int i=0; i<NCH; i++) { |
258 | for(int i=0; i<NCH; i++) { |
| 246 | /* |
259 | /* |
| 247 | sprintf(hname, "htdcpos%d", i); |
260 | sprintf(hname, "htdcpos%d", i); |
| 248 | htdcpos[i] = (TH1F*)gROOT->FindObject(hname); |
261 | htdcpos[i] = (TH1F*)gROOT->FindObject(hname); |
| 249 | if(htdcpos[i]) delete htdcpos[i]; |
262 | if(htdcpos[i]) delete htdcpos[i]; |
| 250 | htdcpos[i] = new TH1F(hname, hname, 512, 0, 512*TDC_BIN); |
263 | htdcpos[i] = new TH1F(hname, hname, 512, 0, 512*TDC_BIN); |
| 251 | |
264 | |
| 252 | sprintf(hname, "htdc%d", i); |
265 | sprintf(hname, "htdc%d", i); |
| 253 | htdc[i] = (TH1F*)gROOT->FindObject(hname); |
266 | htdc[i] = (TH1F*)gROOT->FindObject(hname); |
| 254 | if(htdc[i]) delete htdc[i]; |
267 | if(htdc[i]) delete htdc[i]; |
| 255 | htdc[i] = new TH1F(hname, hname, 512, 0*TDC_BIN, 512*TDC_BIN); |
268 | htdc[i] = new TH1F(hname, hname, 512, 0*TDC_BIN, 512*TDC_BIN); |
| 256 | */ |
269 | */ |
| 257 | 270 | ||
| 258 | sprintf(hname, "hnhitsx%d", i); |
271 | sprintf(hname, "hnhitsx%d", i); |
| 259 | hnhitsx[i] = (TH1F*)gROOT->FindObject(hname); |
272 | hnhitsx[i] = (TH1F*)gROOT->FindObject(hname); |
| 260 | if(hnhitsx[i]) delete hnhitsx[i]; |
273 | if(hnhitsx[i]) delete hnhitsx[i]; |
| 261 | hnhitsx[i] = new TH1F(hname, hname, run.nx, |
274 | hnhitsx[i] = new TH1F(hname, hname, run.nx, |
| 262 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
275 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
| 263 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN); |
276 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN); |
| 264 | 277 | ||
| 265 | sprintf(hname, "hnhitsy%d", i); |
278 | sprintf(hname, "hnhitsy%d", i); |
| 266 | hnhitsy[i] = (TH1F*)gROOT->FindObject(hname); |
279 | hnhitsy[i] = (TH1F*)gROOT->FindObject(hname); |
| 267 | if(hnhitsy[i]) delete hnhitsy[i]; |
280 | if(hnhitsy[i]) delete hnhitsy[i]; |
| 268 | //hnhitsy[i] = new TH1F(hname, hname, run.ny, (run.y0-0.5*run.dy)*MIKRO_BIN, (run.y0+(run.ny-0.5)*run.dy)*MIKRO_BIN); |
281 | //hnhitsy[i] = new TH1F(hname, hname, run.ny, (run.y0-0.5*run.dy)*MIKRO_BIN, (run.y0+(run.ny-0.5)*run.dy)*MIKRO_BIN); |
| 269 | hnhitsy[i] = new TH1F(hname, hname, run.ny, |
282 | hnhitsy[i] = new TH1F(hname, hname, run.ny, |
| 270 | (run.y0 - 0.5*run.dy - OFFSETY)*MIKRO_BIN, |
283 | (run.y0 - 0.5*run.dy - OFFSETY)*MIKRO_BIN, |
| 271 | (run.y0 + (run.ny-0.5)*run.dy - OFFSETY)*MIKRO_BIN); |
284 | (run.y0 + (run.ny-0.5)*run.dy - OFFSETY)*MIKRO_BIN); |
| 272 | //hnhitsy[i] = new TH1F(hname, hname, 100, 0,100); |
285 | //hnhitsy[i] = new TH1F(hname, hname, 100, 0,100); |
| 273 | 286 | ||
| 274 | sprintf(hname, "h2d%d", i); |
287 | sprintf(hname, "h2d%d", i); |
| 275 | h2d[i] = (TH2F*)gROOT->FindObject(hname); |
288 | h2d[i] = (TH2F*)gROOT->FindObject(hname); |
| 276 | if(h2d[i]) delete h2d[i]; |
289 | if(h2d[i]) delete h2d[i]; |
| 277 | h2d[i] = new TH2F(hname, hname, run.nx, |
290 | h2d[i] = new TH2F(hname, hname, run.nx, |
| 278 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
291 | (run.x0 - OFFSETX - 0.5*run.dx)*MIKRO_BIN, |
| 279 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN, |
292 | (run.x0 - OFFSETX + (run.nx-0.5)*run.dx)*MIKRO_BIN, |
| 280 | run.ny, |
293 | run.ny, |
| 281 | (run.y0 - OFFSETY - 0.5*run.dy)*MIKRO_BIN, |
294 | (run.y0 - OFFSETY - 0.5*run.dy)*MIKRO_BIN, |
| 282 | (run.y0 - OFFSETY + (run.ny-0.5)*run.dy)*MIKRO_BIN); |
295 | (run.y0 - OFFSETY + (run.ny-0.5)*run.dy)*MIKRO_BIN); |
| 283 | } |
296 | } |
| 284 | - | ||
| 285 | nBiasSteps = (run.biasUp - run.biasLow)/double(run.biasStep) + 1; |
- | |
| 286 | 297 | ||
| - | 298 | nBiasSteps = (run.biasUp - run.biasLow)/double(run.biasStep) + 1; |
|
| 287 | h_correctedTDC = (TH3F*) gROOT->FindObject("h_correctedTDC"); |
299 | h_correctedTDC = (TH3F*) gROOT->FindObject("h_correctedTDC"); |
| 288 | if (h_correctedTDC) delete h_correctedTDC; |
300 | if (h_correctedTDC) delete h_correctedTDC; |
| 289 | nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
301 | nSteps = (run.thUp - run.thLow)/double(run.thStep) + 1; |
| 290 | if (dbg) printf("nSteps %d\n", nSteps); |
302 | if (dbg) printf("nSteps %d\n", nSteps); |
| - | 303 | biasLow = (run.biasLow - 0.5*run.biasStep)/1000.0; |
|
| - | 304 | biasUp = (run.biasUp + 0.5*run.biasStep)/1000.0; |
|
| 291 | h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
305 | h_correctedTDC = new TH3F("h_correctedTDC",";SiPM channel; ASD threshold [V]; t [ns]", |
| 292 | NCH, |
- | |
| 293 | -0.5, |
- | |
| 294 | NCH-0.5, |
306 | NCH, -0.5, NCH-0.5, |
| 295 | nBiasSteps, |
307 | nBiasSteps, biasLow, biasUp, |
| 296 | (run.biasLow - 0.5*run.biasStep)/1000.0, |
- | |
| 297 | (run.biasUp + 0.5*run.biasStep)/1000.0, |
- | |
| 298 | 2*tdcCut+1, |
308 | 2*tdcCut+1, |
| 299 | -tdcCut*TDC_BIN - 0.5*TDC_BIN, |
309 | -tdcCut*TDC_BIN - 0.5*TDC_BIN, |
| 300 | tdcCut*TDC_BIN + 0.5*TDC_BIN); |
310 | tdcCut*TDC_BIN + 0.5*TDC_BIN); |
| 301 | 311 | ||
| 302 | h_bias = (TH2F*) gROOT->FindObject("h_bias"); |
312 | h_bias = (TH2F*) gROOT->FindObject("h_bias"); |
| 303 | if (h_bias) delete h_bias; |
313 | if (h_bias) delete h_bias; |
| 304 | h_bias = new TH2F("h_bias",";Channel; Bias [V]", 64, -0.5, 63.5, |
314 | h_bias = new TH2F("h_bias",";Channel; Bias [V]", 64, -0.5, 63.5, |
| 305 | nBiasSteps, |
315 | nBiasSteps, biasLow, biasUp); |
| 306 | (run.biasLow - 0.5*run.biasStep)/1000.0, |
- | |
| 307 | (run.biasUp + 0.5*run.biasStep)/1000.0); |
- | |
| 308 | - | ||
| 309 | 316 | ||
| 310 | if (h_threshold) delete h_threshold; |
317 | if (h_threshold) delete h_threshold; |
| - | 318 | thrLow = (run.thLow - 0.5*run.thStep)/1000.0; |
|
| - | 319 | thrUp = (run.thUp + 0.5*run.thStep)/1000.0; |
|
| 311 | h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]",64,-0.5,63.5, |
320 | h_threshold = new TH2F("h_threshold",";SiPM ch;Threshold[V]",64,-0.5,63.5, |
| 312 | nSteps, |
321 | nSteps, thrLow, thrUp); |
| 313 | (run.thLow - 0.5*run.thStep)/1000.0, |
- | |
| 314 | (run.thUp + 0.5*run.thStep)/1000.0); |
- | |
| 315 | 322 | ||
| 316 | //h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
323 | //h_threshold = new TH2F("h_threshold","Threshold scan;SiPM ch;Threshold[mV]",64,-0.5,63.5, |
| 317 | // 101,995,2005); |
324 | // 101,995,2005); |
| 318 | 325 | ||
| 319 | if (h_ch33) delete h_ch33; |
326 | if (h_ch33) delete h_ch33; |
| 320 | h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
327 | h_ch33 = new TH2F("h_ch33","ch. 33;x;y",100,20000,30000,100,0,10000); |
| - | 328 | ||
| - | 329 | h_biasThreshold = (TH3F*) gROOT->FindObject("h_biasThreshold"); |
|
| - | 330 | if (h_biasThreshold) delete h_biasThreshold; |
|
| - | 331 | h_biasThreshold = new TH3F("h_biasThreshold", ";Channel;Bias[V];Threshold[V]", |
|
| - | 332 | 64, -0.5, 63.5, |
|
| - | 333 | nBiasSteps, biasLow, biasUp, |
|
| - | 334 | nSteps, thrLow, thrUp); |
|
| 321 | 335 | ||
| 322 | if (dbg) printf("RUNREC: all histos created.\n"); |
336 | if (dbg) printf("RUNREC: all histos created.\n"); |
| 323 | break; |
337 | break; |
| 324 | 338 | ||
| 325 | case POSREC_ID: |
339 | case POSREC_ID: |
| 326 | if (dbg) printf("POSREC\n"); |
340 | if (dbg) printf("POSREC\n"); |
| 327 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
341 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| 328 | posrec = (POSREC *) readbuf; |
342 | posrec = (POSREC *) readbuf; |
| 329 | pos=*posrec; |
343 | pos=*posrec; |
| 330 | 344 | ||
| 331 | if(dbg) { |
345 | if(dbg) { |
| 332 | printf("POSREC_ID\n"); |
346 | printf("POSREC_ID\n"); |
| 333 | printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time); |
347 | printf("id = %d, len = %d, time = %d\n", posrec->id, posrec->len, posrec->time); |
| 334 | printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset); |
348 | printf("ix = %d, x = %d, xset = %d\n", posrec->ix, posrec->x, posrec->xset); |
| 335 | printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset); |
349 | printf("iy = %d, y = %d, yset = %d\n", posrec->iy, posrec->y, posrec->yset); |
| 336 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
350 | } else printf(" [%d,%d] %d, %d\n", pos.ix, pos.iy, pos.xset, pos.yset); |
| 337 | 351 | ||
| 338 | break; |
352 | break; |
| 339 | 353 | ||
| 340 | case EVTREC_ID: |
354 | case EVTREC_ID: |
| 341 | gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record |
355 | gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record |
| 342 | evtrec = (EVTREC *) readbuf; |
356 | evtrec = (EVTREC *) readbuf; |
| 343 | //evtrec->nev = buf[0]; |
357 | //evtrec->nev = buf[0]; |
| 344 | //if (rec_len < 0 || rec_len > 10000) { |
358 | //if (rec_len < 0 || rec_len > 10000) { |
| 345 | if (rec_len > READBUFFERLENGTH) { |
359 | if (rec_len > READBUFFERLENGTH) { |
| 346 | printf("Len %u\n", rec_len); |
360 | printf("Len %u\n", rec_len); |
| 347 | return(1); |
361 | return(1); |
| 348 | } |
362 | } |
| 349 | nb = rec_len - 3*ulsize; // no. of bytes to read |
363 | nb = rec_len - 3*ulsize; // no. of bytes to read |
| 350 | gzread(dfp, (voidp)&buf, nb); |
364 | gzread(dfp, (voidp)&buf, nb); |
| 351 | 365 | ||
| 352 | if(dbg) { |
366 | if(dbg) { |
| 353 | printf("EVTREC_ID\n"); |
367 | printf("EVTREC_ID\n"); |
| 354 | printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
368 | printf("id = %d, len = %d, nev = %d\n", evtrec->id, evtrec->len, evtrec->nev); |
| 355 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
369 | //for(int datai = 0; datai < NCH; datai++) printf("%u ", evtrec->data[datai]); |
| 356 | //printf("\n"); |
370 | //printf("\n"); |
| 357 | //for(int datai = NCH; datai < NCH+NCH; datai++) printf("%u ", evtrec->data[datai]); |
371 | //for(int datai = NCH; datai < NCH+NCH; datai++) printf("%u ", evtrec->data[datai]); |
| 358 | //printf("\n"); |
372 | //printf("\n"); |
| 359 | break; |
373 | break; |
| 360 | } |
374 | } |
| 361 | 375 | ||
| 362 | nint = nb / ulsize; // no. of subrecords |
376 | nint = nb / ulsize; // no. of subrecords |
| 363 | if (dbg) printf("No. of subrecords %d \n", nint); |
377 | if (dbg) printf("No. of subrecords %d \n", nint); |
| 364 | ii=0; |
378 | ii=0; |
| 365 | while (ii<nint){ |
- | |
| 366 | int recid = buf[ii++]; |
- | |
| 367 | int len = buf[ii++]; |
- | |
| 368 | if (dbg) printf("Buffer pointer %d\n", ii); |
- | |
| 369 | unsigned int *dbuf = (unsigned int *)&buf[ii]; |
- | |
| 370 | //if (n%1000==0) |
- | |
| 371 | if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
- | |
| 372 | //unsigned short edge; |
- | |
| 373 | //int nhits; |
- | |
| 374 | if (recid==0x140 || recid==0x141) { |
- | |
| 375 | for (int i=0; i<len; i++) { |
- | |
| 376 | int data = dbuf[i] & 0xFFFF ; |
- | |
| 377 | int edge_type = (dbuf[i]>>16)&0x1 ; |
- | |
| 378 | int overflow = (dbuf[i]>>17)&0x1 ; |
- | |
| 379 | int tdc_num = (dbuf[i]>>25)&0x1 ; |
- | |
| 380 | int channel = ((dbuf[i]>>18)&0x1F) | tdc_num<<5 ; |
- | |
| 381 | int ev_dat = (dbuf[i]>>23)&0x1 ; |
- | |
| 382 | int last_dat = (dbuf[i]>>30)&0x1 ; |
- | |
| 383 | int nval_dat = (dbuf[i]>>31)&0x1 ; |
- | |
| 384 | if (dbg){ |
- | |
| 385 | if (ev_dat) printf("Event %d\n",data); |
- | |
| 386 | else printf("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n", |
- | |
| 387 | channel, edge_type,ev_dat,data,last_dat,nval_dat); |
- | |
| 388 | } |
- | |
| 389 | if (!ev_dat){ |
- | |
| 390 | if (!edge_type && !overflow) { |
- | |
| 391 | htdc->Fill(data, channel); |
- | |
| 392 | if (dbg) printf("ch: %d tdc: %d\n", channel, data); |
- | |
| 393 | if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
- | |
| 394 | double tdcmin = tdcOffset[channel] - tdcCut; |
- | |
| 395 | double tdcmax = tdcOffset[channel] + tdcCut; |
- | |
| 396 | double time = data*TDC_BIN - tdcOffset[channel]; |
- | |
| 397 | if(time >= -tdcCut and time <= tdcCut) { |
- | |
| 398 | h_correctedTDC->Fill(channel, bias.bias/1000.0, time); |
- | |
| 399 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
- | |
| 400 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
- | |
| 401 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
- | |
| 402 | 379 | ||
| - | 380 | while (ii<nint){ |
|
| - | 381 | int recid = buf[ii++]; |
|
| - | 382 | int len = buf[ii++]; |
|
| - | 383 | if (dbg) printf("Buffer pointer %d\n", ii); |
|
| - | 384 | unsigned int *dbuf = (unsigned int *)&buf[ii]; |
|
| - | 385 | //if (n%1000==0) |
|
| - | 386 | if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len); |
|
| - | 387 | //unsigned short edge; |
|
| - | 388 | //int nhits; |
|
| - | 389 | if (recid==0x140 || recid==0x141) { |
|
| - | 390 | for (int i=0; i<len; i++) { |
|
| - | 391 | int data = dbuf[i] & 0xFFFF ; |
|
| - | 392 | int edge_type = (dbuf[i]>>16)&0x1 ; |
|
| - | 393 | int overflow = (dbuf[i]>>17)&0x1 ; |
|
| - | 394 | int tdc_num = (dbuf[i]>>25)&0x1 ; |
|
| - | 395 | int channel = ((dbuf[i]>>18)&0x1F) | tdc_num<<5 ; |
|
| - | 396 | int ev_dat = (dbuf[i]>>23)&0x1 ; |
|
| - | 397 | int last_dat = (dbuf[i]>>30)&0x1 ; |
|
| - | 398 | int nval_dat = (dbuf[i]>>31)&0x1 ; |
|
| - | 399 | if (dbg){ |
|
| - | 400 | if (ev_dat) printf("Event %d\n",data); |
|
| - | 401 | else printf("ch=%d edge=%d ev=%d data=%d last=%d nval=%d\n", |
|
| - | 402 | channel, edge_type,ev_dat,data,last_dat,nval_dat); |
|
| - | 403 | } |
|
| - | 404 | if (!ev_dat){ |
|
| - | 405 | if (!edge_type && !overflow) { |
|
| - | 406 | htdc->Fill(data, channel); |
|
| - | 407 | if (dbg) printf("ch: %d tdc: %d\n", channel, data); |
|
| - | 408 | if (dbg) nt->Fill(channel, pos.ix, pos.iy, data); |
|
| - | 409 | //double tdcmin = tdcOffset[channel] - tdcCut; |
|
| - | 410 | //double tdcmax = tdcOffset[channel] + tdcCut; |
|
| - | 411 | double time = data*TDC_BIN - tdcOffset[channel]; |
|
| - | 412 | h_biasThreshold->Fill(channel, bias.bias/1000.0, thr.threshold/1000.0); |
|
| - | 413 | ||
| - | 414 | if(time >= -tdcCut and time <= tdcCut) { |
|
| - | 415 | h_correctedTDC->Fill(channel, bias.bias/1000.0, time); |
|
| - | 416 | hnhitsx[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN); |
|
| - | 417 | hnhitsy[channel]->Fill((pos.yset - OFFSETY) * MIKRO_BIN); |
|
| - | 418 | h2d[channel]->Fill((pos.xset - OFFSETX) * MIKRO_BIN, (pos.yset - OFFSETY) * MIKRO_BIN); |
|
| - | 419 | ||
| 403 | if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
420 | if (position(pos.xset-OFFSETX, pos.yset-OFFSETY, channel)) { |
| 404 | h_ch33 |
421 | //h_ch33->Fill(pos.xset-OFFSETX, pos.yset-OFFSETY); |
| 405 | h_threshold->Fill(channel, thr.threshold/1000.0); |
422 | h_threshold->Fill(channel, thr.threshold/1000.0); |
| 406 | h_bias->Fill(channel, bias.bias/1000.0); |
423 | h_bias->Fill(channel, bias.bias/1000.0); |
| 407 | } |
424 | } |
| - | 425 | ||
| 408 | } |
426 | } |
| 409 | //gV673A->Fill(data,channel); |
427 | //gV673A->Fill(data,channel); |
| 410 | //gsumV673A[channel/16]->Fill(data); |
428 | //gsumV673A[channel/16]->Fill(data); |
| 411 | } |
429 | } |
| 412 | } |
430 | } |
| 413 | if (last_dat) break; |
431 | if (last_dat) break; |
| 414 |
|
432 | } |
| 415 | } // if (recid== 0x140 || recid== 0x141) |
433 | } // if (recid== 0x140 || recid== 0x141) |
| 416 | ii += len; |
434 | ii += len; |
| 417 | } //while |
435 | } //while |
| 418 | 436 | ||
| 419 | break; |
437 | break; |
| 420 | 438 | ||
| 421 | case THRREC_ID: |
439 | case THRREC_ID: |
| 422 | status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
440 | status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| 423 | thrrec = (THRREC*) readbuf; |
441 | thrrec = (THRREC*) readbuf; |
| 424 | thr = *thrrec; |
442 | thr = *thrrec; |
| 425 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
443 | if (dbg) printf("THRREC id = %d len = %d threshold %d\n", |
| 426 | thrrec->id, thrrec->len, thrrec->threshold); |
444 | thrrec->id, thrrec->len, thrrec->threshold); |
| 427 | break; |
445 | break; |
| 428 | 446 | ||
| 429 | case ENDREC_ID: |
447 | case ENDREC_ID: |
| 430 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
448 | gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| 431 | endrec = (ENDREC *) readbuf; |
449 | endrec = (ENDREC *) readbuf; |
| 432 | 450 | ||
| 433 | case BIASREC_ID: |
451 | case BIASREC_ID: |
| 434 | status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
452 | status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize)); |
| 435 | biasrec = (BIASREC*) readbuf; |
453 | biasrec = (BIASREC*) readbuf; |
| 436 | bias = *biasrec; |
454 | bias = *biasrec; |
| 437 | if (dbg) printf("BIASREC id = %d len = %d bias %d\n", |
455 | if (dbg) printf("BIASREC id = %d len = %d bias %d\n", |
| 438 | bias.id, bias.len, bias.bias); |
456 | bias.id, bias.len, bias.bias); |
| 439 | break; |
457 | break; |
| 440 | 458 | ||
| 441 | if(dbg) { |
459 | if(dbg) { |
| 442 | printf("ENDREC_ID\n"); |
460 | printf("ENDREC_ID\n"); |
| 443 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
461 | printf("id = %d, len = %d, time = %d\n", endrec->id, endrec->len, endrec->time); |
| 444 | } else printf(" ENDREC\n"); |
462 | } else printf(" ENDREC\n"); |
| 445 | 463 | ||
| 446 | fcount++; |
464 | fcount++; |
| 447 | switch(ftype-1) { |
465 | switch(ftype-1) { |
| 448 | case 0: |
466 | case 0: |
| 449 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
467 | sprintf(dfile, "./data/%s_file%02d.dat", dfile0, fcount); |
| 450 | break; |
468 | break; |
| 451 | case 1: |
469 | case 1: |
| 452 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
470 | sprintf(dfile, "./data/%s_file%02d.dat.gz", dfile0, fcount); |
| 453 | break; |
471 | break; |
| 454 | case 2: |
472 | case 2: |
| 455 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
473 | sprintf(dfile, "./data/%s_file%02d.gz", dfile0, fcount); |
| 456 | break; |
474 | break; |
| 457 | } |
475 | } |
| 458 | 476 | ||
| 459 | if(dfp) gzclose(dfp); |
477 | if(dfp) gzclose(dfp); |
| 460 | 478 | ||
| 461 | dfp=gzopen(dfile,"rb"); |
479 | dfp=gzopen(dfile,"rb"); |
| 462 | if(!dfp) { |
480 | if(!dfp) { |
| 463 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
481 | printf(" Cannot open data file: %s ---> Exiting\n", dfile); |
| 464 | end_of_file = 1; |
482 | end_of_file = 1; |
| 465 | } else { |
483 | } else { |
| 466 | printf(" Opened data file: %s\n", dfile); |
484 | printf(" Opened data file: %s\n", dfile); |
| 467 | end_of_file = 0; |
485 | end_of_file = 0; |
| 468 | } |
486 | } |
| 469 | 487 | ||
| 470 | break; |
488 | break; |
| 471 | 489 | ||
| 472 | default: |
490 | default: |
| 473 | printf("switch(rec_id): default !!!\n"); |
491 | printf("switch(rec_id): default !!!\n"); |
| 474 | end_of_file = 1; |
492 | end_of_file = 1; |
| 475 | break; |
493 | break; |
| 476 | } |
494 | } |
| 477 | 495 | ||
| 478 | ceve++; |
496 | ceve++; |
| 479 | if ( (ceve%50000) == 0) printf(" Current event = %d\n", ceve); |
497 | if ( (ceve%50000) == 0) printf(" Current event = %d\n", ceve); |
| 480 | //if(dbg) if( ceve>dbg ) break; |
498 | //if(dbg) if( ceve>dbg ) break; |
| 481 | if (end_of_file) break; |
499 | if (end_of_file) break; |
| 482 | } |
500 | } |
| 483 | 501 | ||
| 484 | if(dfp) { |
502 | if(dfp) { |
| 485 | gzclose(dfp); |
503 | gzclose(dfp); |
| 486 | //delete dfp; |
504 | //delete dfp; |
| 487 | } |
505 | } |
| 488 | //if(dbg) return 0; |
506 | //if(dbg) return 0; |
| 489 | if(rootfile.IsOpen()) { |
507 | if(rootfile.IsOpen()) { |
| 490 | nt->Write(); |
508 | nt->Write(); |
| 491 | rootfile.Write(); |
509 | rootfile.Write(); |
| 492 | printf("Saved to %s\n", fnameroot); |
510 | printf("Saved to %s\n", fnameroot); |
| 493 | rootfile.Close(); |
511 | rootfile.Close(); |
| 494 | //delete rootfile; |
512 | //delete rootfile; |
| 495 | } |
513 | } |
| 496 | 514 | ||
| 497 | return 0; |
515 | return 0; |
| 498 | } |
516 | } |
| 499 | 517 | ||
| 500 | int position(int x, int y, int channel) |
518 | int position(int x, int y, int channel) |
| 501 | { |
519 | { |
| 502 | int flag = 0; |
520 | int flag = 0; |
| 503 | if ( (x > (padCenter[channel][0] - 5040)) and (x < (padCenter[channel][0] + 5040)) and |
521 | if ( (x > (padCenter[channel][0] - 5040)) and (x < (padCenter[channel][0] + 5040)) and |
| 504 | (y > (padCenter[channel][1] - 5040)) and (y < (padCenter[channel][1] + 5040)) ) flag = 1; |
522 | (y > (padCenter[channel][1] - 5040)) and (y < (padCenter[channel][1] + 5040)) ) flag = 1; |
| 505 | return flag; |
523 | return flag; |
| 506 | } |
524 | } |
| 507 | 525 | ||