Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 33 | Rev 34 | ||
|---|---|---|---|
| Line 11... | Line 11... | ||
| 11 | # endif |
11 | # endif |
| 12 | # ifdef WIENVME |
12 | # ifdef WIENVME |
| 13 | # include "wienvme_dll.h" |
13 | # include "wienvme_dll.h" |
| 14 | # endif |
14 | # endif |
| 15 | # include "CAENV673A.h" |
15 | # include "CAENV673A.h" |
| 16 | # include "CAENV462.h" |
16 | # include "CAENV462.h" |
| - | 17 | ||
| 17 | #endif |
18 | #endif |
| 18 | 19 | ||
| 19 | #ifdef USE_MIKRO |
20 | #ifdef USE_MIKRO |
| 20 | # include "MIKRO.h" |
21 | # include "MIKRO.h" |
| 21 | #endif |
22 | #endif |
| 22 | 23 | ||
| 23 | #include <userint.h> |
24 | #include <userint.h> |
| 24 | #include <ansi_c.h> |
25 | #include <ansi_c.h> |
| 25 | #include <utility.h> |
26 | #include <utility.h> |
| 26 | #include <analysis.h> |
27 | #include <analysis.h> |
| 27 | 28 | ||
| 28 | #include "c:\HOME\dino\sipmScan\include\sipmBias_ui.h" |
29 | #include "c:\HOME\dino\sipmScan\include\sipmBias_ui.h" |
| 29 | 30 | ||
| 30 | #ifdef USE_DAQ |
31 | #ifdef USE_DAQ |
| 31 | # define USE_CAMAC |
32 | # define USE_CAMAC |
| 32 | # include "camac.h" |
33 | # include "camac.h" |
| - | 34 | # define NDAC 1 // CAEN C221 |
|
| - | 35 | # define ASD8 0 // channels |
|
| - | 36 | # define AMPDISSH 1 |
|
| 33 | # define |
37 | # define SIPM 2 |
| 34 | - | ||
| 35 | # define CAEN_V673A 0x22220000 // IJS |
38 | # define CAEN_V673A 0x22220000 // IJS |
| 36 | //#define CAEN_V673A 0x10110000 // FMF |
39 | //#define CAEN_V673A 0x10110000 // FMF |
| 37 | # define CAEN_V462 0x100300 |
40 | # define CAEN_V462 0x100300 |
| 38 | #endif |
41 | #endif |
| 39 | 42 | ||
| Line 51... | Line 54... | ||
| 51 | #define MAX_THREADS 10 |
54 | #define MAX_THREADS 10 |
| 52 | 55 | ||
| 53 | #define IWAIT 200 |
56 | #define IWAIT 200 |
| 54 | 57 | ||
| 55 | #define NCH 64 |
58 | #define NCH 64 |
| - | 59 | #define POWERSUPPLY 66 // Power supply voltage for SiPM bias |
|
| 56 | 60 | ||
| 57 | static int p1h, pID, rID, tfID; |
61 | static int p1h, pID, rID, tfID; |
| 58 | static int ph_tdc, ph_adc; |
62 | static int ph_tdc, ph_adc; |
| 59 | static int dtdc[NCH][2][MAXCH]; |
63 | static int dtdc[NCH][2][MAXCH]; |
| 60 | static int something[NCH][2][MAXCH]; |
64 | static int something[NCH][2][MAXCH]; |
| Line 136... | Line 140... | ||
| 136 | int ntrig; |
140 | int ntrig; |
| 137 | int chip, len; |
141 | int chip, len; |
| 138 | unsigned long *pdata; |
142 | unsigned long *pdata; |
| 139 | 143 | ||
| 140 | FILE *fp; |
144 | FILE *fp; |
| 141 | #define RUNREC_ID 1 |
145 | #define RUNREC_ID 1 |
| 142 | #define ENDREC_ID 2 |
146 | #define ENDREC_ID 2 |
| 143 | #define POSREC_ID 3 |
147 | #define POSREC_ID 3 |
| 144 | #define EVTREC_ID 4 |
148 | #define EVTREC_ID 4 |
| 145 | #define THRREC_ID 5 |
149 | #define THRREC_ID 5 |
| - | 150 | #define BIASREC_ID 6 |
|
| 146 | 151 | ||
| 147 | typedef struct { |
152 | typedef struct { |
| 148 | unsigned long id,len; |
153 | unsigned long id,len; |
| 149 | unsigned long fver,time; |
154 | unsigned long fver,time; |
| - | 155 | unsigned long thLow, thUp, thStep; |
|
| - | 156 | unsigned long biasLow, biasUp, biasStep; |
|
| 150 | unsigned long nev,nch,ped,xy; |
157 | unsigned long nev,nch,ped,xy; |
| 151 | long nx,x0,dx,ny,y0,dy; |
158 | long nx,x0,dx,ny,y0,dy; |
| 152 | } RUNREC; |
159 | } RUNREC; |
| 153 | RUNREC runrec; |
160 | RUNREC runrec; |
| 154 | 161 | ||
| Line 173... | Line 180... | ||
| 173 | EVTREC evtrec; |
180 | EVTREC evtrec; |
| 174 | 181 | ||
| 175 | typedef struct { |
182 | typedef struct { |
| 176 | unsigned long id; |
183 | unsigned long id; |
| 177 | unsigned long len; |
184 | unsigned long len; |
| 178 | unsigned long thLow, thUp, thStep; |
- | |
| 179 | unsigned long threshold; |
185 | unsigned long threshold; |
| 180 | } THRREC; |
186 | } THRREC; |
| 181 | THRREC thrrec; |
187 | THRREC thrrec; |
| - | 188 | ||
| - | 189 | typedef struct { |
|
| - | 190 | unsigned long id; |
|
| - | 191 | unsigned long len; |
|
| - | 192 | unsigned long bias; |
|
| - | 193 | } BIASREC; |
|
| - | 194 | BIASREC biasrec; |
|
| 182 | 195 | ||
| 183 | double thresholdLow; |
196 | double thresholdLow; |
| 184 | double thresholdUp; |
197 | double thresholdUp; |
| 185 | double thresholdStep; |
198 | double thresholdStep; |
| - | 199 | double biasLow; |
|
| - | 200 | double biasUp; |
|
| - | 201 | double biasStep; |
|
| 186 | 202 | ||
| 187 | #define BSIZE 20000 |
203 | #define BSIZE 20000 |
| 188 | 204 | ||
| 189 | int maxn = BSIZE-4; // 2 words x 2 headers |
205 | int maxn = BSIZE-4; // 2 words x 2 headers |
| 190 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat; |
206 | int tdcdata, edge_type, overflow, tdc_num, channel, ev_dat, last_dat, nval_dat; |
| Line 203... | Line 219... | ||
| 203 | posrec.len = sizeof(posrec); |
219 | posrec.len = sizeof(posrec); |
| 204 | evtrec.id = EVTREC_ID; |
220 | evtrec.id = EVTREC_ID; |
| 205 | evtrec.len = sizeof(evtrec); |
221 | evtrec.len = sizeof(evtrec); |
| 206 | thrrec.id = THRREC_ID; |
222 | thrrec.id = THRREC_ID; |
| 207 | thrrec.len = sizeof(thrrec); |
223 | thrrec.len = sizeof(thrrec); |
| - | 224 | biasrec.id = BIASREC_ID; |
|
| - | 225 | biasrec.len = sizeof(biasrec); |
|
| 208 | 226 | ||
| 209 | 227 | ||
| 210 | cres = 0; |
228 | cres = 0; |
| 211 | 229 | ||
| 212 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
230 | GetCtrlVal (p1h, P1_NEVE, &runrec.nev); |
| Line 239... | Line 257... | ||
| 239 | if (supr0) { |
257 | if (supr0) { |
| 240 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
258 | GetCtrlVal (p1h, P1_TDCMIN, &tdcmin); |
| 241 | GetCtrlVal (p1h, P1_FRAC, &frac); |
259 | GetCtrlVal (p1h, P1_FRAC, &frac); |
| 242 | } |
260 | } |
| 243 | 261 | ||
| 244 | GetCtrlVal (p1h, |
262 | GetCtrlVal (p1h, P1_SASD8THR, &thresholdLow); |
| 245 | runrec.thLow = thresholdLow*1000; // mV |
263 | runrec.thLow = thresholdLow*1000; // mV |
| 246 | GetCtrlVal (p1h, P1_STHRUP, &thresholdUp); |
264 | GetCtrlVal (p1h, P1_STHRUP, &thresholdUp); |
| 247 | runrec.thUp = thresholdUp*1000; // mV |
265 | runrec.thUp = thresholdUp*1000; // mV |
| 248 | GetCtrlVal (p1h, P1_STEP, &thresholdStep); |
266 | GetCtrlVal (p1h, P1_STEP, &thresholdStep); |
| 249 | runrec.thStep = thresholdStep*1000; // mV |
267 | runrec.thStep = thresholdStep*1000; // mV |
| 250 | 268 | ||
| - | 269 | GetCtrlVal (p1h, P1_SBIAS, &biasLow); |
|
| - | 270 | GetCtrlVal (p1h, P1_SBIASUP, &biasUp); |
|
| - | 271 | GetCtrlVal (p1h, P1_SBIASSTEP, &biasStep); |
|
| - | 272 | runrec.biasLow = biasLow*1000; |
|
| - | 273 | runrec.biasUp = biasUp*1000; |
|
| - | 274 | runrec.biasStep = biasStep*1000; |
|
| 251 | 275 | ||
| 252 | #ifdef USE_DAQ |
276 | #ifdef USE_DAQ |
| 253 | V673A_map(0,CAEN_V673A,0); |
277 | V673A_map(0,CAEN_V673A,0); |
| 254 | V673A_init(0); |
278 | V673A_init(0); |
| 255 | 279 | ||
| Line 266... | Line 290... | ||
| 266 | //} |
290 | //} |
| 267 | if (supr0) { |
291 | if (supr0) { |
| 268 | fseed = runrec.time & 0x7fffffff; |
292 | fseed = runrec.time & 0x7fffffff; |
| 269 | Uniform (1, fseed, &fracg); |
293 | Uniform (1, fseed, &fracg); |
| 270 | } |
294 | } |
| 271 | 295 | ||
| - | 296 | // Set SiPM bias voltage |
|
| - | 297 | //SetDac(SIPM, 1.0); |
|
| - | 298 | biasrec.bias = runrec.biasLow; |
|
| - | 299 | while (biasrec.bias <= runrec.biasUp) { |
|
| - | 300 | SetDac(SIPM, biasrec.bias/1000.0 - POWERSUPPLY); |
|
| - | 301 | SetCtrlVal(p1h, P1_SBIAS, biasrec.bias/1000.0); |
|
| - | 302 | status = fwrite(&biasrec, 1, biasrec.len, fp); |
|
| - | 303 | if (print) printf("BIASREC status %d len %d bias %d\n", status, biasrec.len, biasrec.bias); |
|
| - | 304 | ||
| - | 305 | // Set ASD threshold voltage |
|
| 272 | thrrec.threshold = (unsigned long) ceil(thresholdLow*1000); // threshold in mV |
306 | thrrec.threshold = (unsigned long) ceil(thresholdLow*1000); // threshold in mV |
| 273 | while (thrrec.threshold <= thresholdUp*1000) { |
307 | while (thrrec.threshold <= thresholdUp*1000) { |
| 274 | SetDac( |
308 | SetDac(ASD8, thrrec.threshold/1000.0); |
| 275 | SetCtrlVal(p1h, |
309 | SetCtrlVal(p1h, P1_SASD8THR, thrrec.threshold/1000.0); |
| 276 | //wait_loop(100000); |
- | |
| 277 | status = fwrite(&thrrec, 1, thrrec.len, fp); |
310 | status = fwrite(&thrrec, 1, thrrec.len, fp); |
| 278 | if (print) printf("THRREC status %d len %d threshold %d\n", status, thrrec.len, thrrec.threshold); |
311 | if (print) printf("THRREC status %d len %d threshold %d\n", status, thrrec.len, thrrec.threshold); |
| 279 | 312 | ||
| 280 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
313 | for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) { |
| 281 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
314 | posrec.xset = runrec.x0 + posrec.ix*runrec.dx; |
| Line 284... | Line 317... | ||
| 284 | do { |
317 | do { |
| 285 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
318 | MIKRO_MoveTo (MIKRO_X, posrec.xset); |
| 286 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
319 | MIKRO_GetPosition(MIKRO_X, &mikroX); |
| 287 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
320 | } while (abs(posrec.xset - mikroX) > STEP_TOLERANCE); |
| 288 | //printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
321 | //printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset); |
| 289 | #endif |
322 | #endif |
| 290 | //SetCtrlVal (p1h, P1_X, posrec.xset); |
323 | //SetCtrlVal (p1h, P1_X, posrec.xset); |
| 291 | posrec.xset = mikroX; // set the true value |
324 | posrec.xset = mikroX; // set the true value |
| 292 | SetCtrlVal(p1h, P1_X, mikroX); |
325 | SetCtrlVal(p1h, P1_X, mikroX); |
| 293 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
326 | SetCtrlVal (p1h, P1_IX, posrec.ix); |
| 294 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
327 | for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) { |
| 295 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
328 | posrec.yset = runrec.y0 + posrec.iy*runrec.dy; |
| 296 | #ifdef USE_MIKRO_Y |
329 | #ifdef USE_MIKRO_Y |
| 297 | //printf("MIKRO_MoveTo (2, y);%d\n",y); |
330 | //printf("MIKRO_MoveTo (2, y);%d\n",y); |
| 298 | do { |
331 | do { |
| 299 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
332 | MIKRO_MoveTo (MIKRO_Y, posrec.yset); |
| 300 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
333 | MIKRO_GetPosition(MIKRO_Y, &mikroY); |
| 301 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
334 | } while (abs(posrec.yset - mikroY) > STEP_TOLERANCE); |
| 302 | //printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
335 | //printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset); |
| 303 | #endif |
336 | #endif |
| Line 336... | Line 369... | ||
| 336 | count=0; |
369 | count=0; |
| 337 | ntics=0; |
370 | ntics=0; |
| 338 | if (print) printf("Event counter: %d\n", evtrec.nev); |
371 | if (print) printf("Event counter: %d\n", evtrec.nev); |
| 339 | 372 | ||
| 340 | //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t)); |
373 | //if (t!=told ) printf("%d in %2.2f min daq::event() %s\n",i, (double)(t-tstart)/60., ctime(&t)); |
| 341 | 374 | ||
| 342 | #ifdef USE_DAQ |
375 | #ifdef USE_DAQ |
| 343 | #ifdef CAEN_V673A |
376 | #ifdef CAEN_V673A |
| 344 | 377 | ||
| 345 | 378 | ||
| 346 | V462_start0(0); |
379 | V462_start0(0); |
| 347 | //tmlnk (tout); |
380 | //tmlnk (tout); |
| Line 457... | Line 490... | ||
| 457 | if (!daq_on) break; |
490 | if (!daq_on) break; |
| 458 | } // y loop |
491 | } // y loop |
| 459 | if (!daq_on) break; |
492 | if (!daq_on) break; |
| 460 | thrrec.threshold += thresholdStep*1000; |
493 | thrrec.threshold += thresholdStep*1000; |
| 461 | } // threhsold loop |
494 | } // threhsold loop |
| - | 495 | if (!daq_on) break; |
|
| - | 496 | biasrec.bias += runrec.biasStep; |
|
| - | 497 | } // bias loop |
|
| - | 498 | ||
| - | 499 | SetDac(SIPM, 0); // safety |
|
| 462 | 500 | ||
| 463 | //if (dsave) { |
501 | //if (dsave) { |
| 464 | time (&endrec.time); |
502 | time (&endrec.time); |
| 465 | status = fwrite (&endrec, 1, endrec.len, fp); |
503 | status = fwrite (&endrec, 1, endrec.len, fp); |
| 466 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len); |
504 | if (print) printf("ENDREC status %d len %d\n", status, endrec.len); |
| Line 545... | Line 583... | ||
| 545 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
583 | SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2); |
| 546 | 584 | ||
| 547 | QueueUserEvent (1000, p1h, P1_RESET); |
585 | QueueUserEvent (1000, p1h, P1_RESET); |
| 548 | //QueueUserEvent (1000, p1h, P1_ASD8THR); |
586 | //QueueUserEvent (1000, p1h, P1_ASD8THR); |
| 549 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR); |
587 | QueueUserEvent (1000, p1h, P1_AMPDISSHTHR); |
| - | 588 | QueueUserEvent (1000, p1h, P1_BIAS); |
|
| 550 | do { |
589 | do { |
| 551 | GetUserEvent (1, &pID, &rID); |
590 | GetUserEvent (1, &pID, &rID); |
| 552 | switch (rID) { |
591 | switch (rID) { |
| 553 | case P1_TIMER: |
592 | case P1_TIMER: |
| 554 | ntics+=1; |
593 | ntics+=1; |
| Line 572... | Line 611... | ||
| 572 | case P1_ZSET: |
611 | case P1_ZSET: |
| 573 | if (!daq_on) { |
612 | if (!daq_on) { |
| 574 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
613 | GetCtrlVal (p1h, P1_ZSET, &zpos); |
| 575 | #ifdef USE_MIKRO_Z |
614 | #ifdef USE_MIKRO_Z |
| 576 | MIKRO_MoveTo (MIKRO_Z, zpos); |
615 | MIKRO_MoveTo (MIKRO_Z, zpos); |
| 577 | #endif |
616 | #endif |
| 578 | } |
617 | } |
| 579 | break; |
618 | break; |
| 580 | case P1_REREAD: |
619 | case P1_REREAD: |
| 581 | if (!daq_on) { |
620 | if (!daq_on) { |
| 582 | status = FileSelectPopup ("", "*.dat", ".dat", |
621 | status = FileSelectPopup ("", "*.dat", ".dat", |
| 583 | "Choose the previous file", |
622 | "Choose the previous file", |
| 584 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
623 | VAL_LOAD_BUTTON, 0, 0, 1, 0, dfile); |
| Line 594... | Line 633... | ||
| 594 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
633 | SetCtrlVal (p1h, P1_YSTEP, runrec.dy); |
| 595 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
634 | SetCtrlVal (p1h, P1_YMIN, runrec.y0); |
| 596 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
635 | SetCtrlVal (p1h, P1_NEVE, runrec.nev); |
| 597 | } |
636 | } |
| 598 | } |
637 | } |
| 599 | } |
638 | } |
| 600 | break; |
639 | break; |
| 601 | case P1_MGET: |
640 | case P1_MGET: |
| 602 | #ifdef USE_MIKRO |
641 | #ifdef USE_MIKRO |
| 603 | MIKRO_GetPosition(MIKRO_X,&xpos); |
642 | MIKRO_GetPosition(MIKRO_X,&xpos); |
| 604 | Delay(0.01); |
643 | Delay(0.01); |
| Line 648... | Line 687... | ||
| 648 | case P1_ADCLOG: |
687 | case P1_ADCLOG: |
| 649 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
688 | GetCtrlVal (p1h, P1_ADCLOG, &status); |
| 650 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
689 | SetCtrlAttribute (p1h, P1_ADC, ATTR_YMAP_MODE, status); |
| 651 | update_plots(); |
690 | update_plots(); |
| 652 | break; |
691 | break; |
| 653 |
|
692 | case P1_ASD8THR: |
| 654 | { |
693 | { |
| 655 | double value; |
694 | double value; |
| 656 | GetCtrlVal (p1h, P1_SASD8THR, &value); |
695 | GetCtrlVal (p1h, P1_SASD8THR, &value); |
| 657 |
|
696 | SetDac(ASD8, value); |
| 658 | |
697 | |
| 659 | } |
698 | } |
| 660 |
|
699 | break; |
| - | 700 | case P1_BIAS: |
|
| - | 701 | { |
|
| - | 702 | double value; |
|
| - | 703 | GetCtrlVal (p1h, P1_SBIAS, &value); |
|
| - | 704 | value -= POWERSUPPLY; |
|
| - | 705 | SetDac(SIPM, value); |
|
| - | 706 | } |
|
| - | 707 | break; |
|
| 661 | case P1_AMPDISSHTHR: |
708 | case P1_AMPDISSHTHR: |
| 662 | { |
709 | { |
| 663 | double value; |
710 | double value; |
| 664 | GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value); |
711 | GetCtrlVal (p1h, P1_SAMPDISSHTHR, &value); |
| 665 | SetDac( |
712 | SetDac(AMPDISSH, value); |
| 666 | 713 | ||
| 667 | } |
714 | } |
| 668 | break; |
715 | break; |
| 669 | 716 | ||
| 670 | } |
717 | } |