-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectrometer.cc
142 lines (125 loc) · 3.68 KB
/
spectrometer.cc
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
#include "spectrometer.h"
#include <fstream>
#include <iostream>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <stdio.h>
double Spectrometer::grasp(double wavelength)
{
double eff, d;
param.principal_incoming.set_wavelength(wavelength);
eff=bench.efficiency(param.principal_incoming);
d = param.source_distance*param.source_distance;
eff*=(param.range_x * param.range_y)/d;
return(eff);
}
void Spectrometer::write_grasp()
{
fstream file;
int i;
double eff,wavelength;
file.open(param.grasp_file,ios::trunc|ios::in|ios::out);
if(!file) cout<<"can't open the file "<<param.grasp_file<<endl;
for(wavelength=param.wavelength_min;wavelength<param.wavelength_max;
wavelength+=0.05*A2cm)
{
eff=grasp(wavelength);
file<<wavelength/A2cm<<" "<<eff<<endl;
}
file.close();
}
void Spectrometer::write_resolving_power() {
fstream file;
int i;
file.open(param.respower_file,ios::trunc|ios::in|ios::out);
if(!file) cout<<"can't open the file "<<param.respower_file<<endl;
double wavelength,res,alpha,bata;
for(wavelength=param.wavelength_min;wavelength<param.wavelength_max;
wavelength+=0.05*A2cm)
{
res=resolving_power(wavelength);
file<<wavelength/A2cm<<" "<<res<<endl;
}
file.close();
}
void Spectrometer::write_calibration() {
fstream file;
int i;
double wavelength;
double x,y;
file.open(param.calib_file,ios::trunc|ios::in|ios::out);
if(!file) cout<<"can't open the file "<<param.calib_file<<endl;
for(wavelength=param.wavelength_min;wavelength<param.wavelength_max;
wavelength+=0.05*A2cm)
{
param.principal_incoming.set_wavelength(wavelength);
bench.incoming=param.principal_incoming;
bench.make_outgoing();
if(!bench.inside) continue;
bench.get_image(x,y);
file<<wavelength/A2cm<<" "<<y<<endl;
}
file.close();
}
void Spectrometer::do_trace()
{
fstream file;
int n,m,i;
double wavelength=0.;
double x,y,x0,y0,x1,y1;
double ux, uz, ur, sig;
Vector v, p0, p1;
char buffer[80];
const gsl_rng_type *T;
gsl_rng *r;
read_input();
optimize();
setup_bench();
write_calibration();
write_grasp();
write_resolving_power();
write_params();
//return;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc(T);
sig = param.source_size/2.35;
while(True){
cout<<"input the wavelength("<<int(param.wavelength_min/A2cm)<<"A-"<<
int(param.wavelength_max/A2cm)<<"A,input 0 to terminate): ";
cin>>wavelength;
sprintf(buffer,"%s.%d",param.image_file,int(wavelength));
wavelength*=A2cm;
if(wavelength==0) break;
if(wavelength>param.wavelength_max||wavelength<param.wavelength_min)
{
cout<<"wavelength out of the band pass."<<endl;
continue;
}
param.principal_incoming.set_wavelength(wavelength);
bench.incoming=param.principal_incoming;
bench.make_outgoing();
bench.get_image(x0,y0);
file.open(buffer,ios::trunc|ios::in|ios::out);
if(!file) cout<<"can't open the file "<<buffer<<endl;
cout<<"the grasp at wavelength "<<wavelength/A2cm
<<"A is "<<grasp(wavelength)<<endl;
for (n = 0; n < MaxN; n++) {
ur = gsl_ran_gaussian(r, sig);
p0.set(ur, param.source_distance, 0.0);
ux = gsl_ran_flat(r, -0.5*param.range_y, 0.5*param.range_y);
uz = gsl_ran_flat(r, -0.5*param.range_x, 0.5*param.range_x);
p1.set(ux, 0.0, uz);
v = p1 - p0;
v.normalize();
bench.incoming.set_passing_point(p0);
bench.incoming.set_direction(v);
bench.make_outgoing();
if (!bench.inside) continue;
bench.get_image(x, y);
file<<(y-y0)/MICRON<<" "<<(x-x0)<<endl;
}
file.close();
}
// cout<<"done"<<endl;
}