Problem 56 - In src/G4LineSection.cc divide by 0 and sqrt() from negative value are possible
Summary: In src/G4LineSection.cc divide by 0 and sqrt() from negative value are possible
Status: RESOLVED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: geometry (show other problems)
Version: 1.0
Hardware: PC Other
: P2 normal
Assignee: Vladimir.Grichine
URL:
Depends on:
Blocks:
 
Reported: 2000-02-08 23:40 CET by isupov
Modified: 2000-03-27 12:52 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this problem.
Description isupov 2000-02-08 23:40:55 CET
1) If PntA so close to PntB, that VecAtoB.mag2() returns 0, we obtains
divide by zero in calculation inverse_square_distAB. If inverse_square_distAB
used only in G4LineSection::Dist() for unit_projection calc., , I think, we can
put it 0 without a problems:


  G4double sq_VecAB = VecAtoB.mag2();
  if (sq_VecAB == 0.0)
    inverse_square_distAB = 0.0;
  else
    inverse_square_distAB=1.0 / sq_VecAB;

-----------instead of -----------------------------

    inverse_square_distAB=1.0 / VecAtoB.mag2();

2) Because of we calculate subtract:

     dist_sq= sq_VecAZ -  unit_projection * inner_prod;

, we can obtain negative value in real calculations, where loss of precision
is possible. That leads to sqrt from negative value. I think, we need following
change:

     dist_sq= sq_VecAZ -  unit_projection * inner_prod;
     if (dist_sq < 0.0)
        dist_sq = 0.0;

--------------------instead of simple: --------------------

     dist_sq= sq_VecAZ -  unit_projection * inner_prod;


(Sorry fo non-diff "patches", but you web problem report form not so comfortable
for insertion from files :-(
Comment 1 Vladimir.Grichine 2000-03-24 08:44:59 CET
G4Exceptions were added in conditions resulting in
the problem mentioned.