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

Last change on this file was 5110, checked in by moralejo, 20 years ago
Commited to CVS all changes to adapt headers to current C++ syntaxis
File size: 3.3 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;
12float outbuf[273];
13
14int 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|ios::binary);
51
52 /*if((cerfilec=fopen(cor_dir,"wb"))==NULL){
53 printf("C-style::Cannot create cerenkov file.\n");
54 exit(1);
55 }*/
56
57 //____________________________________________________________________________________
58
59 cout<<"Writing binary Cherenkov file"<<" "<<cor_dir<<" "<<"..."<<endl;
60
61 cerevth.fill (1.0,
62 99.0, // primary id
63 inttime_s * 1e9, // instead of the total energy: integration time (ns)
64 1.0,
65 1.e7,
66 0.0,
67 0.0,
68 0.0,
69 0.0, // theta is always 0. !
70 0.0, // phi is always 0. !
71 0.0,
72 0.0);
73 strcpy(cerevth.EVTH, "RUNH");
74
75 cerevth.write(cerfile);
76
77 strcpy(cerevth.EVTH, "EVTH");
78 cerevth.write(cerfile);
79
80 // Here we fill the information for each photon as a corsika particle.
81 // The fields in cerphot.fill are: wavelentgh (nm), x core position (cm), y core position (cm),
82 // u cosine director, v cosine director, time since first interaction (ns),
83 // height (cm) of first interaction.
84 //photnum=0;
85 for(i=0;i<photnum;i++){
86
87 lambda_nm = phot[i].lambda_nm;
88 x_cm = phot[i].x_m * 100.0;
89 y_cm = phot[i].y_m * 100.0;
90
91 u = phot[i].u;
92 v = phot[i].v;
93 t_ns = phot[i].arrtime_sec * 1e9;
94
95 cerphot.fill(lambda_nm,
96 x_cm,
97 y_cm,
98 u,
99 v,
100 t_ns,
101 1.e7);
102
103
104 cerphot.write(cerfile);
105 }
106 lastblock=39-photnum%39;
107
108 for(i=0;i<lastblock;i++){
109 cerphot.fill(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
110 cerphot.write(cerfile);
111 }
112 strcpy(cerevth.EVTH, "EVTE");
113 cerevth.write(cerfile);
114 strcpy(cerevth.EVTH, "RUNE");
115 cerevth.write(cerfile);
116
117 cerfile.close();
118
119 cout<<"Done."<<endl;
120
121 // Statistics corsika file
122
123 strcpy (stat_dir, "./");
124
125 //File labeling.
126
127 strcat(stat_file, output_name);
128
129 strcat(stat_dir, stat_file);
130
131 cerfile.open (stat_dir, ios::out|ios::binary);
132
133 cout<<"Writing binary statistics file "<<" "<<stat_dir<<" "<<"..."<<endl;
134
135 cerstat.write(cerfile);
136
137 cerfile.close();
138
139 cout<<"Done."<<endl;
140
141 return 0;
142
143}
Note: See TracBrowser for help on using the repository browser.