167 {
168
169
171
172
174
177
178 if( nscat == 0 ) return p ;
179
180
181 for( int nv=1 ; nv<(int)p.size()-1 ; ++nv ) {
182 double factor = 1.0 * nv / (p.size()-1) ;
183 p[nv] = (1-factor)*p.front() + factor*p.back() ;
184 }
185
186 int maxnsteps = -1 ;
187
188 if( nscat == 1 ) {
189 double score =
getScore(p,src,trg) ;
190 double dl = 1 ;
191 const double dlmin = 0.0001 ;
195 int istep = 0 ;
196 while( score<0 ) {
197 if( ++istep == maxnsteps ) break ;
198 double initscore = score ;
199
200
201 p[1] = p[1] + dl*dx ;
203
204 p[1] = p[1] - 2*dl*dx ;
205 if(
getScore(p,src,trg) < score ) p[1] = p[1] + dl*dx ;
206 }
207
208
209 p[1] = p[1] + dl*dy ;
211
212 p[1] = p[1] - 2*dl*dy ;
213 if(
getScore(p,src,trg) < score ) p[1] = p[1] + dl*dy ;
214 }
215
216
217 p[1] = p[1] + dl*dz ;
219
220 p[1] = p[1] - 2*dl*dz ;
221 if(
getScore(p,src,trg) < score ) p[1] = p[1] + dl*dz ;
222 }
223
224
226
227 if( score == initscore ) {
228 dl = 0.5 * dl ;
229
230 if( dl<dlmin ) break ;
231 }
232 if( p.getLength() > 10000 ) break ;
233 }
234 }
235
236 if( nscat>1) {
237
238
239
240
241
242 double score =
getScore(p,src,trg) ;
243 double dl = 1 ;
244 const double dlmin = 1e-10 ;
245
246 const int nsm = 6 ;
249
250
251
252
253
254
255
256 int i = 0 ;
257
258 while( score<0 ) {
259 if( ++i>100 ) break ;
260
261 double initscore = score ;
262
263 for( int i=0; i<nsm; ++i ) {
264
265 p[1] = p[1] + dl * single_moves[i] ;
266 double newscore =
getScore(p,src,trg) ;
267 if( newscore < score ) {
268
269 p[1] = p[1] - dl * single_moves[i] ;
270 } else {
271
272
273 score = newscore ;
274 }
275 }
276
277 for( int i=0; i<nsm; ++i ) {
278
279 p[2] = p[2] + dl * single_moves[i] ;
280 double newscore =
getScore(p,src,trg) ;
281 if( newscore < score ) {
282
283 p[2] = p[2] - dl * single_moves[i] ;
284 } else {
285
286
287 score = newscore ;
288 }
289 }
290
291
293
294 if( score == initscore ) {
295
296 dl = 0.5*dl ;
297 if( dl<dlmin ) break ;
298 }
299 if( p.getLength() > 10000 ) {
300
301 break ;
302 }
303 }
304
305
307 p2[0] = p[0] ;
308 p2[1] = p[1] ;
309 p2[2] = p[2] ;
310 p2.back() = p.back() ;
311 for( int nv=3 ; nv<nscat+1 ; ++nv ) {
312 double factor = 1.0 * (nv-2) / (nscat-1) ;
313 p2[nv] = (1-factor)*p2[2] + factor*p2.back() ;
314 }
315 return p2 ;
316 }
317
318 return p ;
319
320 }
double getScore(const JPhotonPath &p, const JDirectedSource *src, const JPMTTarget *trg)
Data structure for position in three dimensions.
Data structure for vector in three dimensions.
const JPosition3D & getPosition() const
const JVersor3D & getDirection() const
const JPosition3D & getPosition() const