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 |
|
---|
13 | int convertcorsika(int id, int photnum, photon phot[], float inttime_s, int verbose){
|
---|
14 |
|
---|
15 | int i,filenum;
|
---|
16 | float x_cm, y_cm, u, v, lambda_nm, t_ns;
|
---|
17 | char cor_dir[60];
|
---|
18 | char stat_dir[60];
|
---|
19 | char cor_file[15];
|
---|
20 | char stat_file[15];
|
---|
21 |
|
---|
22 | filenum=id;
|
---|
23 |
|
---|
24 | // Event corsika file
|
---|
25 |
|
---|
26 | //File labeling.
|
---|
27 |
|
---|
28 | strcpy (cor_dir, "./");
|
---|
29 |
|
---|
30 | sprintf(cor_file, "cer%06d",filenum);
|
---|
31 |
|
---|
32 | strcat(cor_dir, cor_file);
|
---|
33 |
|
---|
34 |
|
---|
35 | // Fill the header of the corsika-like event.
|
---|
36 | //The fields in evt.fill are: event number, primary identifier, total energy (GeV),
|
---|
37 | // first target identifier, first z interaction(cm) , momentum x, momentum y, momentum z,
|
---|
38 | // zenith angle, azimuth angle, coreposition x (cm), coreposition y(cm)
|
---|
39 |
|
---|
40 | ofstream cerfile;
|
---|
41 |
|
---|
42 | if(!cerfile) {
|
---|
43 | cerr<<"Cannot create cerenkov file.\n";
|
---|
44 | exit(1);
|
---|
45 | }
|
---|
46 |
|
---|
47 | cerfile.open(cor_dir, ios::out);
|
---|
48 |
|
---|
49 | //____________________________________________________________________________________
|
---|
50 |
|
---|
51 | cout<<"Writing binary Cherenkov file"<<" "<<cor_dir<<" "<<"..."<<endl;
|
---|
52 |
|
---|
53 | cerevth.fill (1.0,
|
---|
54 | 99.0, // primary id
|
---|
55 | inttime_s * 1e9, // instead of the total energy: integration time (ns)
|
---|
56 | 1.0,
|
---|
57 | 1.e7,
|
---|
58 | 0.0,
|
---|
59 | 0.0,
|
---|
60 | 0.0,
|
---|
61 | 0.0, // theta is always 0. !
|
---|
62 | 0.0, // phi is always 0. !
|
---|
63 | 0.0,
|
---|
64 | 0.0);
|
---|
65 |
|
---|
66 |
|
---|
67 | cerevth.write(cerfile);
|
---|
68 |
|
---|
69 |
|
---|
70 | // Here we fill the information for each photon as a corsika particle.
|
---|
71 | // The fields in cerphot.fill are: wavelentgh (nm), x core position (cm), y core position (cm),
|
---|
72 | // u cosine director, v cosine director, time since first interaction (ns),
|
---|
73 | // height (cm) of first interaction.
|
---|
74 |
|
---|
75 | for(i=0;i<photnum;i++){
|
---|
76 |
|
---|
77 | lambda_nm = phot[i].lambda_nm;
|
---|
78 | x_cm = phot[i].x_m * 100.0;
|
---|
79 | y_cm = phot[i].y_m * 100.0;
|
---|
80 | u = phot[i].u;
|
---|
81 | v = phot[i].v;
|
---|
82 | t_ns = phot[i].arrtime_sec * 1e9;
|
---|
83 |
|
---|
84 | cerphot.fill(lambda_nm,
|
---|
85 | x_cm,
|
---|
86 | y_cm,
|
---|
87 | u,
|
---|
88 | v,
|
---|
89 | t_ns,
|
---|
90 | 1.e7);
|
---|
91 |
|
---|
92 | cerphot.write(cerfile);
|
---|
93 | }
|
---|
94 |
|
---|
95 | cerphot.fill(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
---|
96 | cerphot.write(cerfile);
|
---|
97 |
|
---|
98 | cerfile.close();
|
---|
99 |
|
---|
100 | cout<<"Done."<<endl;
|
---|
101 |
|
---|
102 | // Statistics corsika file
|
---|
103 |
|
---|
104 | strcpy (stat_dir, "./");
|
---|
105 |
|
---|
106 |
|
---|
107 | //File labeling.
|
---|
108 |
|
---|
109 | sprintf(stat_file, "sta%06d",filenum);
|
---|
110 |
|
---|
111 | strcat(stat_dir, stat_file);
|
---|
112 |
|
---|
113 | cerfile.open (stat_dir);
|
---|
114 |
|
---|
115 | cout<<"Writing binary statistics file "<<" "<<stat_dir<<" "<<"..."<<endl;
|
---|
116 |
|
---|
117 | cerstat.write(cerfile);
|
---|
118 |
|
---|
119 | cerfile.close();
|
---|
120 |
|
---|
121 | cout<<"Done."<<endl;
|
---|
122 |
|
---|
123 | return 0;
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|