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
213
221 }
223 } else {
224
226 for (i=0; i<2; i++) {
227 distance[i] = kInfinity;
229 isvalid[i] = false;
230 gxx[i].
set(kInfinity, kInfinity, kInfinity);
231 }
232 }
233
237
238
239
240
241
242
243
245
247
248
249 isvalid[0] = false;
251 isvalid[0], 0, validate, &gp, &gv);
252 return 0;
253 }
254
255
256
257
258
259
261 G4double b = fKappa * (v.
x() * p.
z() + v.
z() * p.
x()) - v.
y();
265
268
269
270
271 distance[0] = - c / b;
272 xx[0] = p + distance[0]*v;
274
276 areacode[0] = GetAreaCode(xx[0]);
278 if (distance[0] >= 0) isvalid[0] = true;
279 }
281 areacode[0] = GetAreaCode(xx[0], false);
283 if (distance[0] >= 0) isvalid[0] = true;
284 }
285 } else {
286
287 if (xx[0].x() > 0) {
289 if (distance[0] >= 0) isvalid[0] = true;
290 } else {
291 distance[0] = kInfinity;
293 areacode[0], isvalid[0],
294 0, validate, &gp, &gv);
295 return vout;
296 }
297 }
298
300 isvalid[0], 1, validate, &gp, &gv);
301 vout = 1;
302
303 } else {
304
305
306
307
308
309
310
312 isvalid[0], 0, validate, &gp, &gv);
313 }
314
316
317
318
319 D = std::sqrt(D);
321 G4double tmpdist[2] = {kInfinity, kInfinity};
324 G4bool tmpisvalid[2] = {
false,
false};
326
327 for (i=0; i<2; i++) {
329
330
331
333 if ( b * D < 0 && std::fabs(bminusD / D) < protection ) {
335 tmpdist[i] = - c/b * ( 1 - acovbb * (1 + 2*acovbb));
336 } else {
337 tmpdist[i] = factor * bminusD;
338 }
339
340 D = -D;
341 tmpxx[i] = p + tmpdist[i]*v;
342
344 tmpareacode[i] = GetAreaCode(tmpxx[i]);
346 if (tmpdist[i] >= 0) tmpisvalid[i] = true;
347 continue;
348 }
350 tmpareacode[i] = GetAreaCode(tmpxx[i], false);
352 if (tmpdist[i] >= 0) tmpisvalid[i] = true;
353 continue;
354 }
355 } else {
356
357 if (tmpxx[i].x() > 0) {
359 if (tmpdist[i] >= 0) tmpisvalid[i] = true;
360 continue;
361 } else {
362 tmpdist[i] = kInfinity;
363 continue;
364 }
365 }
366 }
367
368 if (tmpdist[0] <= tmpdist[1]) {
369 distance[0] = tmpdist[0];
370 distance[1] = tmpdist[1];
371 xx[0] = tmpxx[0];
372 xx[1] = tmpxx[1];
375 areacode[0] = tmpareacode[0];
376 areacode[1] = tmpareacode[1];
377 isvalid[0] = tmpisvalid[0];
378 isvalid[1] = tmpisvalid[1];
379 } else {
380 distance[0] = tmpdist[1];
381 distance[1] = tmpdist[0];
382 xx[0] = tmpxx[1];
383 xx[1] = tmpxx[0];
386 areacode[0] = tmpareacode[1];
387 areacode[1] = tmpareacode[0];
388 isvalid[0] = tmpisvalid[1];
389 isvalid[1] = tmpisvalid[0];
390 }
391
393 isvalid[0], 2, validate, &gp, &gv);
395 isvalid[1], 2, validate, &gp, &gv);
396
397
398
399 for (
G4int k=0; k<2; k++) {
400 if (!isvalid[k]) continue;
401
402 G4ThreeVector xxonsurface(xx[k].x(), fKappa * std::fabs(xx[k].x())
403 * xx[k].z() , xx[k].z());
404 G4double deltaY = (xx[k] - xxonsurface).mag();
405
407
411 for (l=0; l<maxcount; l++) {
414 surfacenormal, xx[k]);
415 deltaY = (xx[k] - xxonsurface).mag();
416 if (deltaY > lastdeltaY) {
417
418 }
420
422
423 break;
424 }
425 xxonsurface.set(xx[k].x(),
426 fKappa * std::fabs(xx[k].x()) * xx[k].z(),
427 xx[k].z());
428 }
429 if (l == maxcount) {
430 std::ostringstream message;
431 message <<
"Exceeded maxloop count!" <<
G4endl
432 << " maxloop count " << maxcount;
433 G4Exception(
"G4TwistTubsFlatSide::DistanceToSurface(p,v)",
435 }
436 }
437
438 }
439 vout = 2;
440 } else {
441
442
443
445 isvalid[0], 0, validate, &gp, &gv);
446 }
447
448 return vout;
449}
virtual G4ThreeVector GetNormal(const G4ThreeVector &xx, G4bool isGlobal=false)
G4int GetAreacode(G4int i) const
G4double GetDistance(G4int i) const
void SetCurrentStatus(G4int i, G4ThreeVector &xx, G4double &dist, G4int &areacode, G4bool &isvalid, G4int nxx, EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=0)
G4bool IsValid(G4int i) const
G4ThreeVector GetXX(G4int i) const
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=0)
static const G4int sOutside
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
G4bool IsOutside(G4int areacode) const
static const G4int sInside
CurrentStatus fCurStatWithV
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const