-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp_func.C
More file actions
228 lines (195 loc) · 5.61 KB
/
Copy pathhelp_func.C
File metadata and controls
228 lines (195 loc) · 5.61 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// These functions are needed for the 1st round of reconstruction to
// get an estimate on vertex posision.
//#include <map>
#include <iterator>
#include <algorithm>
//map<int, double> INDEX;
int TowerIPhi(double phi)
{
double two_pi = 2.0*3.1415926535;
if(phi<0.0) phi = two_pi+phi;
return int(phi*NPHI/two_pi);
}
int TowerITheta(double theta)
{
return int((1+TMath::Cos(theta))*NTHETA/2.);
}
// Divides sphere in NPHIxNTHETA segments and takes 1st photon from each segment
int MarkEarlyPhotons(int N, float* x, float* y, float* z, float* t, int* process, int* pe, bool* ph_vec)
{
//Fill in iphi-itheta towers with photon number (only photons passing QE&P cuts)
////QE&P = quantum efficiency and creation process
std::vector<int> map[NPHI][NTHETA];
for(int i=0;i!=N;++i)
{
// if(process) continue;
if(pe[i]==0) continue;
TVector3 vec(x[i],y[i],z[i]);
int iphi=TowerIPhi(vec.Phi());
int itheta=TowerITheta(vec.Theta());
map[iphi][itheta].push_back(i);
}
// at this point map is created from photons passing QE&P cuts
// let's mark earliest in each sphere segment
for(int ip=0;ip!=NPHI;++ip)
for(int it=0;it!=NTHETA;++it)
{
if(map[ip][it].size()==0) continue;
int n1st=map[ip][it][0];
for(int i=1;i<map[ip][it].size();++i)
{
if(t[map[ip][it][i]]<t[n1st])
n1st=map[ip][it][i];
}
ph_vec[n1st]=1;
}
return 0;
}
int MarkEarlyPhotons_(int N, float* x, float* y, float* z, float* t, int* process, int* pe, int* ph_vec, int num=1)
{
//Fill in iphi-itheta towers with photon number (only photons passing QE&P cuts)
////QE&P = quantum efficiency and creation process
std::vector<int> map[NPHI][NTHETA];
for(int i=0;i!=N;++i)
{
// if(process) continue;
if(pe[i]==0) continue;
TVector3 vec(x[i],y[i],z[i]);
int iphi=TowerIPhi(vec.Phi());
int itheta=TowerITheta(vec.Theta());
map[iphi][itheta].push_back(i);
}
// at this point map is created from photons passing QE&P cuts
// let's mark earliest in each sphere segment
for(int ip=0;ip!=NPHI;++ip)
for(int it=0;it!=NTHETA;++it)
{
if(map[ip][it].size()==0) continue;
//------------ make a loop to select first num photons
for(int n=1;n<=num;++n)
{
if(map[ip][it].size()==0) break; // this may happen if num > initial size of map[ip][it]
int I=0;
int n1st=map[ip][it][I];
for(int i=1;i<map[ip][it].size();++i)
{
if(t[map[ip][it][i]]<t[n1st])
{
n1st=map[ip][it][i];
I=i;
}
}
ph_vec[n1st]=n;
map[ip][it].erase(map[ip][it].begin()+I);// current earlies is marked. remove it from futher consideartion
}
//================
}
return 0;
}
int FillIndex(char* fName)
{
int wl;
double n_ref;
ifstream infile(fName);
while(infile>>wl>>n_ref)
{
cout<<"nref = "<<n_ref<<endl;
INDEX[wl] = n_ref;
}
//now caculate ref. index for group velocity
double dn=0;
double dl=0;
double n=0;
double l=0;
map<int, double>::iterator last = INDEX.end();
last--;
for(map<int, double>::iterator m=INDEX.begin(); m!=INDEX.end(); ++m)
{
cout<<m->first<<" "<<m->second<<endl;
n = m->second;
l = m->first;
map<int, double>::iterator next = m;
map<int, double>::iterator prev = m;
next++;
prev--;
if(m==INDEX.begin())
{
dn = next->second - m->second;
dl = next->first - m->first;
} else
if(m==last)
{
dn = m->second - prev->second;
dl = m->first - prev->first;
} else
{
dn = next->second - prev->second;
dl = next->first - prev->first;
}
INDEX_GR[l] = n - l*(dn/dl); // group velocity will be C_VAC/INDEX_GR[]
}
//some output for testing:
cout<<"INDEX_GR[400] = "<<INDEX_GR[400]<<endl;
for(int i=400;i!=450;++i)
{
cout<<i<<" "<<INDEX_GR[i]<<" "<<INDEX[i]<<endl;
}
return 0;
}
double Velocity(double lambda)
{
double v=0.;
return v;
}
//The followinf is copied from M.Wetstein's WChSanBox package
double _c=C_VAC; //this line added for compatibility
Double_t CalcMaxAlpha(Double_t dD, Double_t dT, Double_t ni)
{
cout<<"dD = "<<dD<<" dT = "<<dT<<" ni = "<<ni<<endl;
cout<<"dD/dT = "<<dD/dT<<" c/n = "<<_c/ni<<" dv = "<<dD/dT-_c/ni<<endl;
double qA=4*(ni*ni*ni*ni)*dD*dD;
double qB=-8*(ni*ni)*(_c*dT)*dD;
double qC= (4*dT*dT*_c*_c) - (4*((ni*ni) - 1)*( (ni*ni*dD*dD) - (dT*dT*_c*_c) ));
// cout<<"qA = "<<qA<<" qBi"
double maxa=-555555;
if( (qB*qB) > (4*qA*qC) ){
double cosa = (-qB + sqrt(qB*qB - 4*qA*qC))/(2*qA);
maxa = acos(cosa);
double cosalphap = cos(maxa + 0.01);
double qA1=((ni*ni)-1);
double qB1=2*((_c*dT)-(ni*ni*dD*cosalphap));
double qC1=(ni*ni*dD*dD)-(_c*_c*dT*dT);
double cosalpham = cos(maxa - 0.01);
qA1=((ni*ni)-1);
qB1=2*((_c*dT)-(ni*ni*dD*cosalpham));
qC1=(ni*ni*dD*dD)-(_c*_c*dT*dT);
} else{
}
return maxa;
}
Double_t CalcS1(Double_t alpha, Double_t dD, Double_t dT, Double_t ni)
{
double theS1=-55555.;
if(alpha>=0){
double cosalpha = cos(alpha);
double qA=((ni*ni)-1);
double qB=2*((_c*dT)-(ni*ni*dD*cosalpha));
double qC=(ni*ni*dD*dD)-(_c*_c*dT*dT);
double sqrtterm=qB*qB - 4*qA*qC;
if( fabs(sqrtterm)<0.0001 ) sqrtterm=0;
if( sqrtterm>=0 ){
theS1 = (-qB + sqrt(sqrtterm))/(2*qA);
}
else{
}
}
return theS1;
}
Double_t CalcS2(Double_t alpha, Double_t dD, Double_t dT, Double_t ni)
{
double mins1 = CalcS1(alpha,dD,dT,ni);
double ds2x = dD - mins1*cos(alpha);
double ds2y = mins1*sin(alpha);
double theS2 = sqrt( ds2x*ds2x + ds2y*ds2y );
return theS2;
}