1 | //////////////////////////////////////////////////////////////////////////////////////
|
---|
2 | // Write photon data in binary corsika-like format.
|
---|
3 | // Output will be used as an input for the reflector as if it was a shower event.
|
---|
4 | //
|
---|
5 | //////////////////////////////////////////////////////////////////////////////////////
|
---|
6 |
|
---|
7 | #include "convertcorsika.h"
|
---|
8 |
|
---|
9 | COREventHeader cerevth;
|
---|
10 | CORParticle cerphot;
|
---|
11 | CORStatfile cerstat;
|
---|
12 | float outbuf[273];
|
---|
13 |
|
---|
14 | int convertcorsika(int id, int photnum, photon phot[], float inttime_s, int verbose,char output_name[]){
|
---|
15 |
|
---|
16 | int i,filenum;
|
---|
17 | int lastblock;
|
---|
18 | float x_cm, y_cm, u, v, lambda_nm, t_ns;
|
---|
19 | char cor_dir[60];
|
---|
20 | char stat_dir[60];
|
---|
21 | char cor_file[20]="cer";
|
---|
22 | char stat_file[20]="sta";
|
---|
23 |
|
---|
24 | filenum=id;
|
---|
25 |
|
---|
26 | // Event corsika file
|
---|
27 |
|
---|
28 | //File labeling.
|
---|
29 |
|
---|
30 | strcpy (cor_dir, "./");
|
---|
31 |
|
---|
32 | strcat(cor_file, output_name);
|
---|
33 |
|
---|
34 | strcat(cor_dir, cor_file);
|
---|
35 |
|
---|
36 |
|
---|
37 | // Fill the header of the corsika-like event.
|
---|
38 | //The fields in evt.fill are: event number, primary identifier, total energy (GeV),
|
---|
39 | // first target identifier, first z interaction(cm) , momentum x, momentum y, momentum z,
|
---|
40 | // zenith angle, azimuth angle, coreposition x (cm), coreposition y(cm)
|
---|
41 |
|
---|
42 | ofstream cerfile;
|
---|
43 | //FILE cerfilec;
|
---|
44 |
|
---|
45 | if(!cerfile) {
|
---|
46 | cerr<<"Cannot create cerenkov file.\n";
|
---|
47 | exit(1);
|
---|
48 | }
|
---|
49 |
|
---|
50 | cerfile.open(cor_dir, ios::out);
|
---|
51 | /*if((cerfilec=fopen(cor_dir,"wb"))==NULL){
|
---|
52 | printf("C-style::Cannot create cerenkov file.\n");
|
---|
53 | exit(1);
|
---|
54 | }*/
|
---|
55 |
|
---|
56 | //____________________________________________________________________________________
|
---|
57 |
|
---|
58 | cout<<"Writing binary Cherenkov file"<<" "<<cor_dir<<" "<<"..."<<endl;
|
---|
59 |
|
---|
60 | cerevth.fill (1.0,
|
---|
61 | 99.0, // primary id
|
---|
62 | inttime_s * 1e9, // instead of the total energy: integration time (ns)
|
---|
63 | 1.0,
|
---|
64 | 1.e7,
|
---|
65 | 0.0,
|
---|
66 | 0.0,
|
---|
67 | 0.0,
|
---|
68 | 0.0, // theta is always 0. !
|
---|
69 | 0.0, // phi is always 0. !
|
---|
70 | 0.0,
|
---|
71 | 0.0);
|
---|
72 | strcpy(cerevth.EVTH, "RUNH");
|
---|
73 |
|
---|
74 | cerevth.write(cerfile);
|
---|
75 |
|
---|
76 | strcpy(cerevth.EVTH, "EVTH");
|
---|
77 | cerevth.write(cerfile);
|
---|
78 |
|
---|
79 | // Here we fill the information for each photon as a corsika particle.
|
---|
80 | // The fields in cerphot.fill are: wavelentgh (nm), x core position (cm), y core position (cm),
|
---|
81 | // u cosine director, v cosine director, time since first interaction (ns),
|
---|
82 | // height (cm) of first interaction.
|
---|
83 | //photnum=0;
|
---|
84 | for(i=0;i<photnum;i++){
|
---|
85 |
|
---|
86 | lambda_nm = phot[i].lambda_nm;
|
---|
87 | x_cm = phot[i].x_m * 100.0;
|
---|
88 | y_cm = phot[i].y_m * 100.0;
|
---|
89 |
|
---|
90 | u = phot[i].u;
|
---|
91 | v = phot[i].v;
|
---|
92 | t_ns = phot[i].arrtime_sec * 1e9;
|
---|
93 |
|
---|
94 | cerphot.fill(lambda_nm,
|
---|
95 | x_cm,
|
---|
96 | y_cm,
|
---|
97 | u,
|
---|
98 | v,
|
---|
99 | t_ns,
|
---|
100 | 1.e7);
|
---|
101 |
|
---|
102 |
|
---|
103 | cerphot.write(cerfile);
|
---|
104 | }
|
---|
105 | lastblock=39-photnum%39;
|
---|
106 |
|
---|
107 | for(i=0;i<lastblock;i++){
|
---|
108 | cerphot.fill(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
---|
109 | cerphot.write(cerfile);
|
---|
110 | }
|
---|
111 | strcpy(cerevth.EVTH, "EVTE");
|
---|
112 | cerevth.write(cerfile);
|
---|
113 | strcpy(cerevth.EVTH, "RUNE");
|
---|
114 | cerevth.write(cerfile);
|
---|
115 |
|
---|
116 | cerfile.close();
|
---|
117 |
|
---|
118 | cout<<"Done."<<endl;
|
---|
119 |
|
---|
120 | // Statistics corsika file
|
---|
121 |
|
---|
122 | strcpy (stat_dir, "./");
|
---|
123 |
|
---|
124 | //File labeling.
|
---|
125 |
|
---|
126 | strcat(stat_file, output_name);
|
---|
127 |
|
---|
128 | strcat(stat_dir, stat_file);
|
---|
129 |
|
---|
130 | cerfile.open (stat_dir);
|
---|
131 |
|
---|
132 | cout<<"Writing binary statistics file "<<" "<<stat_dir<<" "<<"..."<<endl;
|
---|
133 |
|
---|
134 | cerstat.write(cerfile);
|
---|
135 |
|
---|
136 | cerfile.close();
|
---|
137 |
|
---|
138 | cout<<"Done."<<endl;
|
---|
139 |
|
---|
140 | return 0;
|
---|
141 |
|
---|
142 | }
|
---|