-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxray_bi_ccd.c
2057 lines (1909 loc) · 61.1 KB
/
xray_bi_ccd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <argz.h>
#include "henke.h"
#include "ray.h"
#include "numrec/include/nr.h"
#include "numrec/include/nrutil.h"
#include "bi_ccd.h"
#include "xray_bi_ccd.h"
void rebin_map (float *map,int rbn,int *xs,int *ys);
void output_evlist (float *map,int xside,int yside,
FILE *of,int *nout,int xoff,int yoff);
void mk_alphas(int nalpha,float alpha[],float bs,float L,float R);
void mk_bs_cumdist(int nrads,float rads[],float maxrad,float cdist[],
float z,float bs,float R,float L,int nalpha,float alpha[]);
void dump_local_map(int xs,int ys,float *map);
void get_optical_depths(float *xpos,float t[],float ts[],float imfps[],
float imfpsks[],float p_si[],float epel[]);
void setup_bsprofs(int nrads,float rads[],float maxrad,int ndists,
float *cdists[],float z[],float bs,float R,float L,
int nalpha,float alpha[]);
void acis_pix_dist_func(int argz_len,char *argz[],ccd_runpars *ccd_rp);
void acis_pix_dist_complain(void);
void setup_mfps(float energy,float cofda[][4]);
void makeODmaps (int dim);
void xray_bi_ccd (char *xray_arglist,ccd_runpars *ccd_rp) {
char *argz;
size_t argz_len;
int argc;
char **argv;
char *entry;
int i;
// at the point of this invocation ccd_rp is already
fprintf(stderr,"holy smokes: %s\n",xray_arglist);
if (argz_create_sep(xray_arglist,' ',&argz,&argz_len)) {
fprintf(stderr,"argz_create failure!\n");
exit(1);
}
argc=argz_count(argz,argz_len);
argv=(char**)malloc(argc*sizeof(char*));
entry=NULL;
for (i=0;i<argc;i++) {
entry=argz_next(argz,argz_len,entry);
argv[i]=entry;
}
acis_pix_dist_func(argc,argv,ccd_rp);
return;
}
/* cpix_dist -- ASCA X-Ray CCD event/response simulator by A. Rasmussen */
#define MIN(a,b) (((a)<(b))?(a):(b))
#define PI 3.14159265359
#define PIXEL 13.5 /* pixel size */
/* backside event distribution stuff */
#define NDISTS 15 /* number of sample depths */
#define NRADS 300 /* radii */
#define MAXRAD 300 /* microns */
#define DIFFLEN 400 /* microns */
#define NALPHA 200 /* number of eigenvalues */
#define MINRAD 0.5 /* microns */
#define MINZ 0.000001/* microns */
/* Si characteristics */
#define FANO 0.12 /* fano factor for Si */
#define SiYield 0.043 /* fluorescent yield for Si */
#define ESiK 1.739 /* Si K energy */
#define ESiKEdge 1.840 /* Si K shell energy */
#define EOKEdge 0.5317 /* O K shell energy */
#define ENKEdge 0.4016 /* O K shell energy */
/* CCD structure -- updated from ACIS memos 74 & ?? */
#define NA 2.7E12 /* acceptor density */
#define WCS (4.53*10/24.0) /* width of channel stop covers */
#define TG1 0.312 /* gate thicknesses */
#define TG2 0.266
#define TG3 0.203
#define TGO1 0.315 /* gate oxide thicknesses */
#define TGO2 0.256
#define TGO3 0.161
#define G1 (7.800*PIXEL/24.0) /* gate lengths */
#define G2 (7.800*PIXEL/24.0)
#define G3 (7.800*PIXEL/24.0)
#define V31 (0.152*PIXEL/24.0) /* overlaps */
#define V12 (0.150*PIXEL/24.0)
#define V23 (0.125*PIXEL/24.0)
#define S31 (0.20*PIXEL/24.0) /* gaps between gates */
#define S12 (0.20*PIXEL/24.0)
#define S23 (0.20*PIXEL/24.0)
#define TIO 0.06 /* gate insulator oxide thickness */
#define TIN 0.04 /* gate insulator nitride thickness */
#define TD 45.0 /* depletion depth */
#define TCSP 0.75 /* thickness of channel stop (p++ Si?? ) */
#define TCSO 0.48 /* thickness of channel stop cover (SiO2) */
/* CCD individual characteristics */
/*#define GAIN 3.365*/ /* eV per ADU */
/*#define RON 5.5 */ /* read-out noise (electrons) */
/* old gain values -- originally based on IC443 measurements on all 8 chips. */
/*
float gains[]={
3.565436,3.574005,3.2887644,3.468571,3.1875235,3.2696250,3.517825,3.24945};
*/
/* new gains for s0c1,s0c2, s1c0, s1c3 -- based on W49B (FUJIMOTO). */
/* new gains for other 4 chips are pending W49B data. */
float gains[]={
3.565436,
3.57782, /* Fujimoto - W49B */
3.30033, /* Fujimoto - W49B */
3.468571,
3.19183, /* Fujimoto - W49B */
3.2696250,
3.517825,
3.25098 /* Fujimoto - W49B */
};
/* old noise values -- based on MWB analysis of frame mode data. */
/* float noises[]={5.9,5.5,6.1,6.0,4.4,4.2,5.8,5.0}; */
/* New noise values --- based on GBC measurement of PERSEUS & COMA data */
float noises[]={5.30,5.19,5.41,6.02,4.03,4.12,6.29,4.94};
/* miscellaneous */
#define MAXMAP 3000
#define EVENT_THRESH 30
int nyREG=15;
float yBND[] = {
V31, G1-V12, G1,
G1+S12, G1+S12+TG2, G1+S12+TG2+TGO2,
G1+S12+G2-V23, G1+S12+G2, G1+S12+G2+S23,
G1+S12+G2+S23+TG3, G1+S12+G2+S23+TG3+TGO3, G1+S12+G2+S23+G3-TG3-TGO3,
G1+S12+G2+S23+G3-TG3, G1+S12+G2+S23+G3, G1+S12+G2+S23+G3+S31};
float SI1[]={
TG1, TG1, TG1, 0.0, TG1+TGO1+TG2,
TG2, TG2, TG2, 0.0, TG2+TGO2+TG3,
TG3, TG3, TG3, TG3+TG1+TGO1, 0.0};
float SO1[]={
TGO1, TGO1, TGO1, TG1+TGO1, TGO2,
TG1+TGO1+TGO2, TGO2, TGO1, TG2+TGO2, TGO3,
TG2+TGO2+TGO3, TGO3, TG1+TGO1+TGO3, TGO3, TG1+TGO1};
float SI2[]={
TG3, 0.0, TG2, TG2, 0.0,
0.0, 0.0, TG3, TG3, 0.0,
0.0, 0.0, 0.0, 0.0, TG3};
float SO2[]={
TGO3, 0.0, TGO2, TGO2, 0.0,
0.0, 0.0, TGO3, TGO3, 0.0,
0.0, 0.0, 0.0, 0.0, TGO3};
int ncof=12;
float cofda[][4]={
/* si */ {0.1038, 3.0688, 1.7359, -1.2153},
/* sio2 */ {0.16533, 3.1152, 1.7406, -1.1601},
/* si3n4 */ {0.1226, 3.12336, 1.79513, -1.1022},
/* etc. */ {0.2358, 1.22176, 10.3584, 1.6264},
/* below si edge */ {0.91088, 3.02935, 0.4724, -1.215895},
{0.3380, 3.5212, 2.3309, -1.1949},
/* etc. */ {0.2358, 1.22176, 10.3584, 1.6264},
/* below ok edge */ {0.698319, 2.24294, 4.541946, 2.5228e-5},
{0.3380, 3.5212, 2.3309, -1.1949},
/* etc. */ {0.2358, 1.22176, 10.3584, 1.6264},
/* below nk edge */ {0.698319, 2.24294, 4.541946, 2.5228e-5},
{3.5621, 2.30224, -0.1332, -4.9e-5}};
struct data_str
{
char mode;
int framenum;
short chipnum,x,y,data[9];
} event;
float threshold;
short size = sizeof(struct data_str);
float imfp_si,imfp_sio2,imfp_si3n4; /* imfps for Si, SiO2, Si3N4 */
float imfpsk_si,imfpsk_sio2,imfpsk_si3n4; /* same but for Si K fluorescence */
float si1,si2,so1,so2;
FILE *fp,*outf;
/* modes */
enum MODES {PUTOUT_MAPS,PUTOUT_RV,PUTOUT_OPTICALDEPTHS};
void acis_pix_dist_func (int argc,char *argv[],ccd_runpars *ccd_rp)
{
float *bigmap=NULL; int NX=2048; int NY=512;
int ACCUMULATE_N_FLUSH=0;
float N_resonance_collisions=0.0;
float x[2],y[2],z[2],nE[2],nrg[2],evpel[2],nelectrons[3];
/*simulated photon positions wrt pixel center*/
float dfe,eMobility,lamda,zeta,sigma,init_sigma,drift_sigma,depletiondepth;
float odval,odval2,odstep,si_yield,minDelta,max_drift_sigma;
float tau[7],tausk[7],likelihood_Si[7],en_elec[7];
// float siktau;
float cswalldepth[4],ckwalldepth[4],fraction[4],ft[5],fraction_moment[4];
float imfps[7],imfpsks[7],distance,R;
float x0,y0,primaryenergy,gain,ron,echo,eloss,elost,tx,ty,typ;
// float tz;
float xc,yc,zc,phi,map[MAXMAP],fracx[128],fracy[128],atten_coeff();
// float ta,tb,chi,chi0,ftemp1,ftemp2,ftemp3,ftemp4;
int temp1,temp2;
float this,last,usex,usey;
float temperature,t_bs_Si,ckdeff,deflection(),wallthicknss();
float P,fdff[2],zm,nkt_kt,diffLen,z_twiddle;
static float csdefault[][4]={{29.0,3.5,9.0,17.0},{29.0,3.5,9.0,19.0}};
static float ckdefault[][4]={{20.0,5.0,9.5,18.0},{21.25,4.5,8.25,20.0}};
int i,j,k,part,m,n,N,numphot,xside,yside,startx,starty;
int idumi,nout,escape,fluoresce;
int sensor,chip,dimension;
long iduml,ntries,nattempt,nreal,nescape,nfluor;
char BSI,cswallspec,ckwallspec,exclude_SiK,exclude_Cont;
char fullydepleted;
enum MODES operation=PUTOUT_RV;
float zlim[2],min_delta_scale,drift_sigma_scale;
float *cdists[NDISTS],alpha[NALPHA],rads[NRADS],zlist[NDISTS];
int rbn=1;
int finished_reading=0;
int do_rays=0;
ray aray;
if (argc<3) acis_pix_dist_complain();
/* defaults */
sensor=1; chip=3;
gain=gains[4*sensor+chip];
gain=3.65;
ron =noises[4*sensor+chip];
ron=2.50;
sensor=-1; chip=-1;
depletiondepth=TD;
dfe=0.0;
temperature=223.0;
t_bs_Si=120.0;
si_yield=SiYield;
BSI=cswallspec=ckwallspec=fullydepleted=0;
zlim[0]=zlim[1]=0.0;
/* these wall depths (and widths) were found to minimize chisquared
when comparing branching ratios at sp=40ADU, 4.2 electrons readout noise
for sensor 1 chip 1 -- ISAS data. AR, 27-Jul-93 */
cswalldepth[0]=0.0;
cswalldepth[1]=0.0;
cswalldepth[2]=0.0;
cswalldepth[3]=0.0;
ckwalldepth[0]=0.0;
ckwalldepth[1]=0.0;
ckwalldepth[2]=0.0;
ckwalldepth[3]=0.0;
fdff[0]=0.0;
fdff[1]=0.0;
exclude_SiK=0;
exclude_Cont=0;
ckdeff=1.0;
eloss=0.0;
dimension=128;
primaryenergy=0.0;
threshold=(float)(EVENT_THRESH);
diffLen=DIFFLEN;
min_delta_scale=1.0;
drift_sigma_scale=1.0;
echo=0.0;
n=0L;
N=0L;
P=6.5; /* channel potential, needed for fully depleted backside devices */
nkt_kt=1.0; /* number of kT to use as the schottky barrier `fieldfree' zone*/
R=0.00001;
outf=stdout;
// here transfer parameters from ccd_runpars to old commandline switch values:
temperature =ccd_rp->ccdpars.T;
depletiondepth = ccd_rp->ccdpars.t_si * 1e4; // because t_si is in cm
int nsigma=ccd_rp->ccdpars.n_sigma;
float *lateral_sigma=ccd_rp->ccdpars.lateral_sigma;
while (argc) {
if ((argv[0][0]=='-') &&
(((strchr("BiCFRx",argv[0][1])!=NULL) && (argc>=1)) ||
((strchr("z",argv[0][1])!=NULL) && (argc>=3)) ||
((strchr("w",argv[0][1])!=NULL) && (argc>=5)) ||
((strchr("ADLMNPRSYbcefgklmnorst",argv[0][1])!=NULL) && (argc>=2)))) {
switch (argv[0][1]){
/* attempt to specify diagnostic output. */
case 'i':
argc--;argv++;
do_rays = 1;
break; /* expect rays on stdin */
case 'B':
argc--;argv++;
BSI = 1;
break; /* backside illuminated*/
case 'C':
argc--;argv++;
exclude_Cont=1;
break; /* no partial events */
case 'D':
argc--;argv++;
dfe =atof(argv[1]);
break;
case 'F':
argc--;argv++;
fullydepleted=1;
break;/*device is fully dep'd*/
case 'A':
argc--;argv++;
ACCUMULATE_N_FLUSH=atoi(argv[0]);
argc--;argv++;
break; /* accumulate x-rays onto the frame. */
case 'L':
argc--;argv++;
diffLen=atof(argv[0]);
argc--;argv++;
break;
case 'M':
argc--;argv++;
min_delta_scale=atof(argv[0]);
argc--;argv++;break;
case 'N':
argc--;argv++;
N=atol(argv[0]);
argc--;argv++;
break;
case 'P':
argc--;argv++;
P=atof(argv[0]);
argc--;argv++;
break;/* weighted channel potential, volts */
case 'R':
argc--;argv++;
N_resonance_collisions=atof(argv[0]);
argc--;argv++;
break;
// case 'T':
// argc--;argv++;
// temperature=atof(argv[0]);
// argc--;argv++;
// break;
case 'S':
argc--;argv++;
drift_sigma_scale=atof(argv[0]);
argc--;argv++;
break;
case 'Y':
argc--;argv++;
si_yield =atof(argv[0]);
argc--;argv++;
break;
case 'b':
switch (argv[0][2]) {
case 'r':
/* backside reflection coefficient */
argc--;argv++;
R=atof(argv[0]);
argc--;argv++;
if (R<=0.0 || R>=1.0) {
fprintf(stderr,"reflection coefficient must be 0<R<1.\n");
acis_pix_dist_complain();
}
break;
case 'n':
// specify rebinning
argc--;argv++;
rbn=atoi(argv[0]);
argc--;argv++;
break;
default:
argc--;argv++;
t_bs_Si =atof(argv[0]);
argc--;argv++;
if (t_bs_Si<=0.0) {
fullydepleted=1;
t_bs_Si=0.0;
}
break;
}
break; /* backside undepleted */
case 'c':
argc--;argv++;
chip=atoi(argv[0]);
argc--;argv++;
break;
// case 'd':
// argc--;argv++;
// depletiondepth=atof(argv[0]);
// argc--;argv++;
// break;
case 'e':
argc--;argv++;
primaryenergy=atof(argv[0]);
argc--;argv++;
break;
case 'f':
argc--;argv++;
ckdeff =atof(argv[0]);
argc--;argv++;
break;
/* attempt to specify gain, eV per ADU */
case 'g':
argc--;argv++;
gain =atof(argv[0]);
argc--;argv++;
break;
case 'k':
switch (argv[0][2]) {
case 'T':
argc--;argv++;
nkt_kt=atof(argv[0]);
argc--;argv++;
break;
default:
argc--;argv++;
echo =atof(argv[0]);
argc--;argv++;
break;
}
break;
case 'l':
argc--;argv++;
eloss =atof(argv[0]);
argc--;argv++;
break;
case 'm':
argc--;argv++;
{
switch (argv[0][0]){
case 'o':
if (argc>=2) {
operation=PUTOUT_OPTICALDEPTHS;
argc--;argv++;
if (argv[0][0]!='-') {
dimension=atoi(argv[0]);
}
} else {
fprintf(stderr,"wrong number or args??");
acis_pix_dist_complain();
}
break;
case 'e':
operation=PUTOUT_MAPS;
break;
case 'r':
operation=PUTOUT_RV;
break;
default:
acis_pix_dist_complain();
break;
}
argc--;argv++;
}
break;
case 'n':
if (argv[0][2]=='e') {
argc--;argv++;
ron=atof(argv[0]);
argc--;argv++;
} else {
argc--;argv++;
n=atol(argv[0]);
argc--;argv++;
}
break;
case 'o':
argc--;argv++;
if ((outf=fopen(argv[0],"w")) == NULL)
acis_pix_dist_complain();
argc--;argv++;
break;
case 'r':
argc--;argv++;
ron=atof(argv[0]);
argc--;argv++;
break;
case 's':
argc--;argv++;
sensor=atoi(argv[0]);
argc--;argv++;
break;
case 't':
argc--;argv++;
threshold=atof(argv[0]);
argc--;argv++;
break;
/* attempt to specify wall depths */
case 'w':
switch (argv[0][2]) {
case 'c':
argc--;argv++;
cswalldepth[0]=atof(argv[0]);
argc--;argv++;
cswalldepth[1]=atof(argv[0]);
argc--;argv++;
cswalldepth[2]=atof(argv[0]);
argc--;argv++;
cswalldepth[3]=atof(argv[0]);
argc--;argv++;
cswallspec=1;
break;
case 'k':
argc--;argv++;
ckwalldepth[0]=atof(argv[0]);
argc--;argv++;
ckwalldepth[1]=atof(argv[0]);
argc--;argv++;
ckwalldepth[2]=atof(argv[0]);
argc--;argv++;
ckwalldepth[3]=atof(argv[0]);
argc--;argv++;
ckwallspec=1;
break;
default:
argc--;argv++;
fprintf(stderr,"Unknown: %s\n",argv[0]);
acis_pix_dist_complain();
break;
}
break;
case 'x':
exclude_SiK=1;
argc++;argv--;
break; /* no fluor & escape */
case 'z':
argc++;argv--;
zlim[0]=atof(argv[0]);
argc++;argv--;
zlim[1]=atof(argv[0]);
argc--;argv++;
break;
default :
acis_pix_dist_complain();
break;
}
} else {
acis_pix_dist_complain();
}
}
eMobility=1450.0*pow(temperature/300.0,-2.42);
minDelta=min_delta_scale*sqrt(5.58*temperature*2e12/(200.0*NA));
// max_drift_sigma=3.34117*drift_sigma_scale*
// sqrt(-log(1.-(minDelta/depletiondepth))*(temperature/200.0)*(2e12/NA));
max_drift_sigma=lateral_sigma[0];
switch (sensor) {
case 0:
case 1:
for (j=0;j<4;j++) {
if (! ckwallspec ) ckwalldepth[j]=ckdefault[sensor][j];
if (! cswallspec ) cswalldepth[j]=csdefault[sensor][j];
}
break;
default:
break;
}
if (fullydepleted && !BSI) {
acis_pix_dist_complain();
}
if (fullydepleted && (P==0.0)) {
fprintf(stderr,"specify channel potential for fullydepleted devices.\n");
acis_pix_dist_complain();
}
if (fullydepleted) {
t_bs_Si=0.0;
}
if (zlim[0]==0.0 && zlim[1]==0.0) {
if (BSI) {
if (fullydepleted) {
float k,q,e0,esi,efermi,Ebs,xm,A,zeta1,zeta2;
/* here calculate the schottky barrier parameters,
together with temperature, to formulate a field-free
region as well as a `dead' layer (where charge is not collected) */
/* use: PtSi -- p-type Si schottky barrier of 0.2 volts */
/* xm=sqrt(q/(16*Pi*e0*esi*E(bs))) */
q=1.6e-19;
k=1.38e-16;
e0=8.86e-14;
esi=11.7;
efermi=0.20;
Ebs=(P+efermi+0.5*(q*NA)/(esi*e0)*pow(1e-4*depletiondepth,2.0))/
(1e-4*depletiondepth); /*volts/cm*/
/* z_twiddle is the projected location (measured from the back surface)
where the electric field should drop to zero. (effective depletion
depth for charge diffusion purposes */
z_twiddle=1e4*((P+efermi)*(esi*e0)/(1e-4*depletiondepth*q*NA)
-0.5*1e-4*depletiondepth); /*microns*/
xm=sqrt(q/(16*PI*e0*esi*Ebs)); /* cm */
A = (nkt_kt*k*temperature*1.0e-7)/(2*q*Ebs*xm);
zeta1=1+A-sqrt(pow(1+A,2.0)-1);
zeta2=1+A+sqrt(pow(1+A,2.0)-1);
/* thickness of the `dead' layer */
fdff[0] = zeta1*xm*1.0e4; /* microns */
/* boundary of the `fieldfree' region (typ. 0.1 microns) */
fdff[1] = zeta2*xm*1.0e4; /* microns */
zlim[0]=0.0;
zlim[1]=depletiondepth;
zm=xm*1.0e4;
} else { /* not fully depleted */
zlim[0]=-t_bs_Si;
zlim[1]=depletiondepth;
z_twiddle=0.0;
}
} else {
zlim[0]=-5.0;
zlim[1]=depletiondepth+t_bs_Si;
z_twiddle=0.0;
}
} else if (zlim[0]<-5.0||zlim[0]>zlim[1]||zlim[1]>depletiondepth+t_bs_Si){
fprintf(stderr,"zlim must be ordered and within depletion region.");
acis_pix_dist_complain();
}
if (!do_rays && (primaryenergy==0.0)) acis_pix_dist_complain();
if (operation == PUTOUT_OPTICALDEPTHS) {
setup_mfps(primaryenergy,cofda);
makeODmaps(dimension);exit(0);
}
if (!do_rays && (primaryenergy==0.0)) acis_pix_dist_complain();
if (!do_rays && ((n==0L && N==0L) || ((n & N) != 0L)))
acis_pix_dist_complain();
if ((sensor==-1) ^ (chip==-1)) acis_pix_dist_complain();
if (sensor!=-1) {
gain=gains [4*sensor+chip];
ron =noises[4*sensor+chip];
}
/* energy = primaryenergy; */
ntries = nreal = nattempt = nescape = nfluor = 0L;
/* regurgitate input parameters */
fprintf(stderr,"gain = %f\n",gain);
fprintf(stderr,"energy= %f\n",primaryenergy);
fprintf(stderr,"number=%d\n",n);
fprintf(stderr,"sensor=%d\n",sensor);
fprintf(stderr,"chip=%d\n",chip);
fprintf(stderr,"noise=%f\n",ron);
fprintf(stderr,"electron loss=%f\n",eloss);
fprintf(stderr,"depletiondepth=%f\n",depletiondepth);
fprintf(stderr,"event threshold=%f\n",threshold);
fprintf(stderr,"echo=%f\n",echo);
fprintf(stderr,"CS wall width=%f d1=%f d2=%f d3=%f\n",
cswalldepth[0],cswalldepth[1],cswalldepth[2],cswalldepth[3]);
fprintf(stderr,"CLK wall width=%f d1=%f d2=%f d3=%f\n",
ckwalldepth[0],ckwalldepth[1],ckwalldepth[2],ckwalldepth[3]);
fprintf(stderr,"zlims=%f,%f\n",zlim[0],zlim[1]);
fprintf(stderr,"temperature = %f\n",temperature);
fprintf(stderr,"dark frame error = %f electrons.\n",dfe);
fprintf(stderr,"backside undepleted region = %f microns.\n",t_bs_Si);
fprintf(stderr,"backside reflection coefficient = %f\n",R);
fprintf(stderr,"backside diffusion length = %f\n",diffLen);
fprintf(stderr,"backside illuminated? %d.\n",BSI);
fprintf(stderr,"exclude_siK? %d\n",exclude_SiK);
fprintf(stderr,"exclude_continuum? %d\n",exclude_Cont);
fprintf(stderr,"minimum delta: %f\n",minDelta);
fprintf(stderr,"Si_Yield=%f\n",si_yield);
if (BSI) {
fprintf(stderr,"fully depleted? %d\n",fullydepleted);
fprintf(stderr,"energy threshold: %f * kT.\n",nkt_kt);
fprintf(stderr,"effective `dead' layer: 0.0 - %f microns.\n",fdff[0]);
fprintf(stderr,"`field-free' region : %f - %f microns.\n",fdff[0],fdff[1]);
fprintf(stderr,"weighted channel potential=%f\n",P);
fprintf(stderr,"z_twiddle=%f\n",z_twiddle);
}
setup_mfps(primaryenergy,cofda);
for(i=0;i<NDISTS;i++)
if ((cdists[i]=(float*)malloc(NRADS*sizeof(float)))==NULL)
exit(1);
if (fullydepleted) {
setup_bsprofs((int)(NRADS),rads,(float)(MAXRAD),(int)(NDISTS),
cdists,zlist,fdff[1]-fdff[0],(BSI)?R:0.00001,diffLen,
(int)(NALPHA),alpha);
} else {
setup_bsprofs((int)(NRADS),rads,(float)(MAXRAD),(int)(NDISTS),
cdists,zlist,t_bs_Si,(BSI)?R:0.00001,diffLen,
(int)(NALPHA),alpha);
}
/* initialize random sequence */
time(&iduml);
ran2(&iduml);
idumi=-1;
expdev(&idumi);
gasdev(&idumi);
/* do the optical depth calculation for BSI only once. */
if (BSI) {
tau[0]=t_bs_Si*imfp_si;tausk[0]=t_bs_Si*imfpsk_si;
/* fudge optical depths calculation because of backside illumination */
for(k=1;k<7;k++){tau[k]=0.0;tausk[k]=0.0;}
}
i=0;
finished_reading=0;
fprintf(stderr,"do_rays is %d\n",do_rays);
while ( (!do_rays && (i < n || ntries < N)) || do_rays ) {
if (!do_rays) {
ntries++;
/* reset energy value */
nrg[0] = primaryenergy;
nrg[1] = 0.0;
numphot=1;escape=0;fluoresce=0;
/* sample the spatial distribution.. */
x[0]= PIXEL * (-0.5 + ran2(&iduml));
y[0]= PIXEL * (-0.5 + ran2(&iduml));
/* a more convenient representation for LE QE stuff. */
y0 = PIXEL/2. + y[0];
x0 = PIXEL - fabs((double)(2.*x[0]));
y0 -= PIXEL*floor(y0/PIXEL);
x0 -= PIXEL*floor(x0/PIXEL);
} else {
// do_rays. read in from stdin.
if (fread(&aray,sizeof(ray),1,stdin)) {
// collapse the ray on the surface and proceed to
// determine its interaction position
float kev=1.2398*modulus(&aray.k)/(0.1*2*M_PI);
primaryenergy=kev;
nrg[0] = kev;
nrg[1] = 0.0;
numphot=1;escape=0;fluoresce=0;
x[0]=aray.p.x/1e-3; // in microns
y[0]=aray.p.y/1e-3; // in microns
y0 = PIXEL/2. + y[0];
x0 = PIXEL - fabs((double)(2.*x[0]));
y0 -= PIXEL*floor(y0/PIXEL);
x0 -= PIXEL*floor(x0/PIXEL);
setup_mfps(nrg[0],cofda);
} else {
finished_reading=1;
// going straight to finished_rdng (e.g., EOF) causes a core dump
goto finished_rdng;
}
}
/* locate the y value of the event */
j=0;
while ( j<nyREG && y0 > yBND[j] ) j++;
si1=SI1[j];
so1=SO1[j];
si2=SI2[j];
so2=SO2[j];
/* optical depth calculation */
if (! BSI) {
get_optical_depths(&x0,tau,tausk,imfps,imfpsks,likelihood_Si,en_elec);
j=6;
} else {
// imfps[0]=imfp_si;
// en_elec[0]=0.00365;
// no window material or anything. backside illuminated
j=-1;
}
odval=expdev(&idumi);
float cosine;
if (do_rays) {
vec tmp,norm;
norm.x=norm.y=0.0;
norm.z=1;
memcpy(&tmp,&aray.k,sizeof(vec));
cosine=fabs(dot_prod(&tmp,&norm)/modulus(&tmp));
fprintf(stderr,"REM cosine %g\n",cosine);
} else {
cosine=1.0;
}
// fprintf(stderr,"r[0] %f cosine %f\n",sqrt(pow(x[0],2)+pow(y[0],2)),cosine);
/* see if photon made it through the gate structure. If not, there is
a possibility for the fluorescence to be detected.. */
while (j>=0 && odval>tau[j]/cosine) {
// this is computed in the case of FSI
odval = odval-tau[j]/cosine;j--;
// neglect the change in position as photon traverses
// through gate structure
}
if (j<0) {
/* photon gets into depleted region */
z[0]= odval/imfp_si * cosine;
fprintf(stderr,"REM depth is z[0]=%g\n",z[0]);
if (do_rays) {
x[0] += odval/imfp_si * (aray.k.x)/modulus(&aray.k);
y[0] += odval/imfp_si * (aray.k.y)/modulus(&aray.k);
}
fprintf(stderr,"REM %f %f\n",sqrt(pow(x[0],2)+pow(y[0],2)),z[0]);
/* z[m] is measured from the depletion region boundary on the side */
/* on which the photon entered. */
if (z[0]>0.0 && z[0]<depletiondepth)
i++; /* increment # `interacting' photons */
fprintf(stderr,"REM compare z[0] to zlim[1]=%g and zlim[0]=%g\n",zlim[1],zlim[0]);
if ( (z[0] > zlim[1]) || (z[0] <= zlim[0])) continue;
/* the photon interacted in depleted region !! continue.. */
evpel[0]=0.00365;
/* consider escape possibility. */
if ((primaryenergy > ESiKEdge) &&
(!exclude_SiK) &&
(ran2(&iduml) < si_yield)) {
numphot=2;
escape=1;
nrg[0] = primaryenergy - ESiK;
nrg[1] = ESiK;
zc = 1. - 2. * ran2(&iduml);
odval2=expdev(&idumi);
z[1] = z[0] + zc*odval2/imfpsk_si;
phi=6.28319*ran2(&iduml);
xc = sqrt(1. - zc*zc) * cos(phi);
yc = xc * tan(phi);
x[1] = x[0] + odval2/imfpsk_si * xc;
y[1] = y[0] + odval2/imfpsk_si * yc;
evpel[1]=0.00365;
/* this above wasn't treated completely. We are neglecting
material properties of the gate structure, where fluorescent
photons may end up. i.e. assuming that the MFP is that appropriate
for silicon, and the energy per electron produced is the straight
0.00365 keV. */
}
} else {
/* the photon didn't get through. */
/* how far from the boundary did it land? */
distance=(tau[j]-odval)/imfps[j];
for (k=j;k>=0;k--) {
if (k==j) continue;
distance+=tau[k]/imfps[k];
}
z[0] = -distance; /* this far from the boundary. */
if ( z[0] > zlim[1] || z[0] <= zlim[0]) continue;
evpel[0]=en_elec[j];
/* chances SILICON fluorescent photon */
if ((primaryenergy > ESiKEdge) &&
(ran2(&iduml) < likelihood_Si[j]*si_yield )) {
if (exclude_SiK) continue;
numphot=2;
nrg[0] = primaryenergy - ESiK;
nrg[1] = ESiK;
x[1]=x[0];y[1]=y[0];z[1]=z[0]; /* initial values */
/* see if the fluorescent photon makes it into depletion region. */
zc = 1. - 2*ran2(&iduml); /* photon may be going either direction */
phi=6.28319*ran2(&iduml);
xc = sqrt(1. - zc*zc) * cos(phi);
yc = xc * tan(phi);
/* new optical depth calculation */
odval2=expdev(&idumi);
if (zc<0.0) odstep=MIN((tau[j]-odval)*tausk[j]/tau[j],odval2);
else odstep=MIN(odval*tausk[j]/tau[j],odval2);
z[1] += zc*odstep/imfpsks[j];
x[1] += xc*odstep/imfpsks[j];
y[1] += yc*odstep/imfpsks[j];
odval2-=odstep;
evpel[1]=en_elec[j];
for (k=j; !BSI && k<7 && k>=0 && odval2>0.0 ;k += (zc<0.0)?1:-1) {
if (k==j) continue;
odstep=MIN(tausk[k],odval2);
z[1] += zc*odstep/imfpsks[j];
x[1] += xc*odstep/imfpsks[j];
y[1] += yc*odstep/imfpsks[j];
odval2-=odstep;
evpel[1]=en_elec[k];
}
/* if photon has enough mmpf it may end up in the depletion region */
if (odval2>0.0) {
z[1]+=zc*odval2/imfpsk_si;
x[1]+=xc*odval2/imfpsk_si;
y[1]+=yc*odval2/imfpsk_si;
evpel[1]=0.00365;
/* check on interaction positions later */
}
/* now have the interaction position of fluorescence photon */
}
}
//diagnostic output
//printf("numphot=%d ",numphot);
// for (m=0;m<numphot;m++)
// printf("%f %f %f %f ",x[m],y[m],z[m],nrg[m]);
// printf("\n");
//continue;
/* final primary energy.. calculate # of electrons produced. */
for(m=0;m<numphot;m++) {
/* use nominal notation */
if (BSI) z[m]=depletiondepth-z[m];
/* electron number calculation */
nE[m]=(int)((nrg[m] / 0.00365) +
sqrt(FANO * nrg[m] / evpel[m]) * gasdev(&idumi) + 0.5);
}
/* time to re-group. how many events will be detected? */
/* first calculate the number of pixels spanned between event locations */
switch (numphot) {
case 1:
temp1 = (int)(x[0]/PIXEL+0.5);
temp2 = (int)(y[0]/PIXEL+0.5);
startx = temp1 - 2*rbn;
starty = temp2 - 2*rbn;
// startx=(floor(temp1/rbn)-2)*rbn;
// starty=(floor(temp2/rbn)-2)*rbn;
xside=yside=5*rbn;
break;
case 2:
temp1 = (int)(x[0]/PIXEL+0.5);
temp2 = (int)(x[1]/PIXEL+0.5);
startx= ((temp1<temp2)?temp1:temp2)-2*rbn;
xside = abs(temp1-temp2)+5;
xside *=rbn;
temp1 = (int)(y[0]/PIXEL+0.5);
temp2 = (int)(y[1]/PIXEL+0.5);
starty= ((temp1<temp2)?temp1:temp2)-2*rbn;
yside = abs(temp1-temp2)+5;
yside *=rbn;
if (xside*yside>=MAXMAP) {
startx=starty=-2;
xside=yside=5;
startx=starty=-2*rbn;
xside=yside=5*rbn;
}
break;
}
/* initialize charge maps */
fprintf(stderr,"REM MAXMAP=%d vs. xside*yside=%d\n",MAXMAP,xside*yside);
for (j=0;j<xside*yside;j++) map[j]=0.0;
/* first collect the true number of electrons using the map. */
for (m=0;m<numphot;m++) {
/* fudge for now, since field free region drift is not understood */
/*if ((z[m]>zlim[1]) || (z[m]<=zlim[0])) continue;*/
if (z[m]>depletiondepth+t_bs_Si) continue; /* this prevents crashing */
usex=x[m];usey=y[m];
/* idea here is to shift charge cloud around rather than use different
sigma X and sigma Y expressions. */
/* include initial charge cloud. */
/* ready to go on.. */
/* assume for now that the charge cloud size may be calculated from
the amount of energy deposited (e.g. from escape) */
init_sigma=(1.03*1.7e-2*pow(nE[m]*0.00365,1.75))/2.0; /* hopkinson 2,3 */
/* modification inspired by scholtz&ulm */
init_sigma=sqrt(N_resonance_collisions*0.1*0.1+init_sigma*init_sigma);
/* What is the fraction of charge contained in the depletion region? */
/* want to make this so that all charge at bottom is collected ?? */
if (fullydepleted && BSI) {
fprintf(stderr,"REM fullydepleted && BSI.\n");
/* note : t_bs_Si is out of the picture here */
fraction[1]=erf(z[m]/(sqrt(2.0)*init_sigma));
fraction[2]=erf((z[m]-(depletiondepth-fdff[1]))/
(sqrt(2.0)*init_sigma));