source: trunk/MagicSoft/Simulation/Detector/Starfield/convertcorsika.cxx@ 475

Last change on this file since 475 was 431, checked in by harald, 24 years ago
Oscar changed the code just to run it on alpha machines. I just commit the changes due to problems with the repository.
File size: 2.8 KB
Line 
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
9COREventHeader cerevth;
10CORParticle cerphot;
11CORStatfile cerstat;
12
13int convertcorsika(int id, int photnum, photon phot[], float inttime_s, int verbose,char output_name[]){
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[20]="cer";
20 char stat_file[20]="sta";
21
22 filenum=id;
23
24 // Event corsika file
25
26 //File labeling.
27
28 strcpy (cor_dir, "./");
29
30 strcat(cor_file, output_name);
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 //File labeling.
107
108 strcat(stat_file, output_name);
109
110 strcat(stat_dir, stat_file);
111
112 cerfile.open (stat_dir);
113
114 cout<<"Writing binary statistics file "<<" "<<stat_dir<<" "<<"..."<<endl;
115
116 cerstat.write(cerfile);
117
118 cerfile.close();
119
120 cout<<"Done."<<endl;
121
122 return 0;
123
124}
Note: See TracBrowser for help on using the repository browser.