Import Geant4 9.2.0 source tree
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4AuxiliaryNavServices.cc,v 1.3 2006/06/29 18:36:32 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -0,0 +1,736 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4BrentLocator.cc,v 1.5 2008/12/11 10:13:41 tnikitin Exp $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// Class G4BrentLocator implementation
|
||||
//
|
||||
// 27.10.08 - Tatiana Nikitina.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "G4BrentLocator.hh"
|
||||
#include "G4ios.hh"
|
||||
#include <iomanip>
|
||||
|
||||
G4BrentLocator::G4BrentLocator(G4Navigator *theNavigator)
|
||||
: G4VIntersectionLocator(theNavigator)
|
||||
{
|
||||
// In case of too slow progress in finding Intersection Point
|
||||
// intermediates Points on the Track must be stored.
|
||||
// Initialise the array of Pointers [max_depth+1] to do this
|
||||
|
||||
G4ThreeVector zeroV(0.0,0.0,0.0);
|
||||
for (G4int idepth=0; idepth<max_depth+1; idepth++ )
|
||||
{
|
||||
ptrInterMedFT[ idepth ] = new G4FieldTrack( zeroV, zeroV, 0., 0., 0., 0.);
|
||||
}
|
||||
|
||||
// Counters for Locator
|
||||
|
||||
// Counter for Maximum Number Of Trial before Intersection Found
|
||||
//
|
||||
maxNumberOfStepsForIntersection=0;
|
||||
|
||||
// Counter for Number Of Calls to ReIntegrationEndPoint Method
|
||||
//
|
||||
maxNumberOfCallsToReIntegration=0;
|
||||
maxNumberOfCallsToReIntegration_depth=0;
|
||||
}
|
||||
|
||||
G4BrentLocator::~G4BrentLocator()
|
||||
{
|
||||
for ( G4int idepth=0; idepth<max_depth+1; idepth++)
|
||||
{
|
||||
delete ptrInterMedFT[idepth];
|
||||
}
|
||||
#ifdef G4DEBUG_FIELD
|
||||
if(fVerboseLevel>0)
|
||||
{
|
||||
G4cout << "G4BrentLocator::Location with Max Number of Steps="
|
||||
<< maxNumberOfStepsForIntersection<<G4endl;
|
||||
G4cout << "G4BrentLocator::ReIntegrateEndPoint was called "
|
||||
<< maxNumberOfCallsToReIntegration
|
||||
<< " times and for depth algorithm "
|
||||
<< maxNumberOfCallsToReIntegration_depth << " times." << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// G4bool G4PropagatorInField::LocateIntersectionPoint(
|
||||
// const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
// const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
// const G4ThreeVector& TrialPoint, // E
|
||||
// G4FieldTrack& IntersectedOrRecalculated // Output
|
||||
// G4bool& recalculated) // Out
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Function that returns the intersection of the true path with the surface
|
||||
// of the current volume (either the external one or the inner one with one
|
||||
// of the daughters:
|
||||
//
|
||||
// A = Initial point
|
||||
// B = another point
|
||||
//
|
||||
// Both A and B are assumed to be on the true path:
|
||||
//
|
||||
// E is the first point of intersection of the chord AB with
|
||||
// a volume other than A (on the surface of A or of a daughter)
|
||||
//
|
||||
// Convention of Use :
|
||||
// i) If it returns "true", then IntersectionPointVelocity is set
|
||||
// to the approximate intersection point.
|
||||
// ii) If it returns "false", no intersection was found.
|
||||
// The validity of IntersectedOrRecalculated depends on 'recalculated'
|
||||
// a) if latter is false, then IntersectedOrRecalculated is invalid.
|
||||
// b) if latter is true, then IntersectedOrRecalculated is
|
||||
// the new endpoint, due to a re-integration.
|
||||
// --------------------------------------------------------------------------
|
||||
// NOTE: implementation taken from G4PropagatorInField
|
||||
// New second order locator is added
|
||||
//
|
||||
G4bool G4BrentLocator::EstimateIntersectionPoint(
|
||||
const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
const G4ThreeVector& TrialPoint, // E
|
||||
G4FieldTrack& IntersectedOrRecalculatedFT, // Output
|
||||
G4bool& recalculatedEndPoint, // Out
|
||||
G4double& fPreviousSafety, // In/Out
|
||||
G4ThreeVector& fPreviousSftOrigin) // In/Out
|
||||
|
||||
{
|
||||
// Find Intersection Point ( A, B, E ) of true path AB - start at E.
|
||||
|
||||
G4bool found_approximate_intersection = false;
|
||||
G4bool there_is_no_intersection = false;
|
||||
|
||||
G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
|
||||
G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
G4ThreeVector CurrentE_Point = TrialPoint;
|
||||
G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity); // FT-Def-Construct
|
||||
G4double NewSafety = 0.0;
|
||||
G4bool last_AF_intersection = false;
|
||||
|
||||
// G4bool final_section= true; // Shows whether current section is last
|
||||
// (i.e. B=full end)
|
||||
G4bool first_section = true;
|
||||
recalculatedEndPoint = false;
|
||||
|
||||
G4bool restoredFullEndpoint = false;
|
||||
|
||||
G4int substep_no = 0;
|
||||
|
||||
// Limits for substep number
|
||||
//
|
||||
const G4int max_substeps= 10000; // Test 120 (old value 100 )
|
||||
const G4int warn_substeps= 1000; // 100
|
||||
|
||||
// Statistics for substeps
|
||||
//
|
||||
static G4int max_no_seen= -1;
|
||||
static G4int trigger_substepno_print= warn_substeps - 20 ;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Algorithm for the case if progress in founding intersection is too slow.
|
||||
// Process is defined too slow if after N=param_substeps advances on the
|
||||
// path, it will be only 'fraction_done' of the total length.
|
||||
// In this case the remaining length is divided in two half and
|
||||
// the loop is restarted for each half.
|
||||
// If progress is still too slow, the division in two halfs continue
|
||||
// until 'max_depth'.
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
const G4int param_substeps=100; // Test value for the maximum number
|
||||
// of substeps
|
||||
const G4double fraction_done=0.3;
|
||||
|
||||
G4bool Second_half = false; // First half or second half of divided step
|
||||
|
||||
// We need to know this for the 'final_section':
|
||||
// real 'final_section' or first half 'final_section'
|
||||
// In algorithm it is considered that the 'Second_half' is true
|
||||
// and it becomes false only if we are in the first-half of level
|
||||
// depthness or if we are in the first section
|
||||
|
||||
G4int depth=0; // Depth counts how many subdivisions of initial step made
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
static G4double tolerance= 1.0e-8;
|
||||
G4ThreeVector StartPosition= CurveStartPointVelocity.GetPosition();
|
||||
if( (TrialPoint - StartPosition).mag() < tolerance * mm )
|
||||
{
|
||||
G4cerr << "WARNING - G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is on top of starting point A."
|
||||
<< G4endl;
|
||||
G4Exception("G4BrentLocator::EstimateIntersectionPoint()",
|
||||
"IntersectionPointIsAtStart", JustWarning,
|
||||
"Intersection point F is exactly at start point A." );
|
||||
}
|
||||
#endif
|
||||
|
||||
// Intermediates Points on the Track = Subdivided Points must be stored.
|
||||
// Give the initial values to 'InterMedFt'
|
||||
// Important is 'ptrInterMedFT[0]', it saves the 'EndCurvePoint'
|
||||
//
|
||||
*ptrInterMedFT[0] = CurveEndPointVelocity;
|
||||
for (G4int idepth=1; idepth<max_depth+1; idepth++ )
|
||||
{
|
||||
*ptrInterMedFT[idepth]=CurveStartPointVelocity;
|
||||
}
|
||||
|
||||
//Final_section boolean store
|
||||
G4bool fin_section_depth[max_depth];
|
||||
for (G4int idepth=0; idepth<max_depth; idepth++ )
|
||||
{
|
||||
fin_section_depth[idepth]=true;
|
||||
}
|
||||
|
||||
// 'SubStartPoint' is needed to calculate the length of the divided step
|
||||
//
|
||||
G4FieldTrack SubStart_PointVelocity = CurveStartPointVelocity;
|
||||
|
||||
do
|
||||
{
|
||||
G4int substep_no_p = 0;
|
||||
G4bool sub_final_section = false; // the same as final_section,
|
||||
// but for 'sub_section'
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
do // REPEAT param
|
||||
{
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector Point_B = CurrentB_PointVelocity.GetPosition();
|
||||
|
||||
// F = a point on true AB path close to point E
|
||||
// (the closest if possible)
|
||||
//
|
||||
if(substep_no_p==0)
|
||||
{
|
||||
ApproxIntersecPointV = GetChordFinderFor()
|
||||
->ApproxCurvePointV( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
CurrentE_Point,
|
||||
GetEpsilonStepFor());
|
||||
// The above method is the key & most intuitive part ...
|
||||
}
|
||||
#ifdef G4DEBUG_FIELD
|
||||
if( ApproxIntersecPointV.GetCurveLength() >
|
||||
CurrentB_PointVelocity.GetCurveLength() * (1.0 + tolerance) )
|
||||
{
|
||||
G4cerr << "ERROR - G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is more advanced than"
|
||||
<< " endpoint B." << G4endl;
|
||||
G4Exception("G4BrentLocator::EstimateIntersectionPoint()",
|
||||
"IntermediatePointConfusion", FatalException,
|
||||
"Intermediate F point is past end B point" );
|
||||
}
|
||||
#endif
|
||||
|
||||
G4ThreeVector CurrentF_Point= ApproxIntersecPointV.GetPosition();
|
||||
|
||||
// First check whether EF is small - then F is a good approx. point
|
||||
// Calculate the length and direction of the chord AF
|
||||
//
|
||||
G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
|
||||
|
||||
if ( ChordEF_Vector.mag2() <= sqr(GetDeltaIntersectionFor()) )
|
||||
{
|
||||
found_approximate_intersection = true;
|
||||
|
||||
// Create the "point" return value
|
||||
//
|
||||
IntersectedOrRecalculatedFT = ApproxIntersecPointV;
|
||||
IntersectedOrRecalculatedFT.SetPosition( CurrentE_Point );
|
||||
|
||||
if ( GetAdjustementOfFoundIntersection() )
|
||||
{
|
||||
// Try to Get Correction of IntersectionPoint using SurfaceNormal()
|
||||
//
|
||||
G4ThreeVector IP;
|
||||
G4ThreeVector MomentumDir=ApproxIntersecPointV.GetMomentumDirection();
|
||||
G4bool goodCorrection = AdjustmentOfFoundIntersection( Point_A,
|
||||
CurrentE_Point, CurrentF_Point, MomentumDir,
|
||||
last_AF_intersection, IP, NewSafety,
|
||||
fPreviousSafety, fPreviousSftOrigin );
|
||||
if ( goodCorrection )
|
||||
{
|
||||
IntersectedOrRecalculatedFT = ApproxIntersecPointV;
|
||||
IntersectedOrRecalculatedFT.SetPosition(IP);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: in order to return a point on the boundary,
|
||||
// we must return E. But it is F on the curve.
|
||||
// So we must "cheat": we are using the position at point E
|
||||
// and the velocity at point F !!!
|
||||
//
|
||||
// This must limit the length we can allow for displacement!
|
||||
}
|
||||
else // E is NOT close enough to the curve (ie point F)
|
||||
{
|
||||
// Check whether any volumes are encountered by the chord AF
|
||||
// ---------------------------------------------------------
|
||||
// First relocate to restore any Voxel etc information
|
||||
// in the Navigator before calling ComputeStep()
|
||||
//
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume( Point_A );
|
||||
|
||||
G4ThreeVector PointG; // Candidate intersection point
|
||||
G4double stepLengthAF;
|
||||
G4bool Intersects_AF = IntersectChord( Point_A, CurrentF_Point,
|
||||
NewSafety,fPreviousSafety,
|
||||
fPreviousSftOrigin,
|
||||
stepLengthAF,
|
||||
PointG );
|
||||
last_AF_intersection = Intersects_AF;
|
||||
if( Intersects_AF )
|
||||
{
|
||||
// G is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
// B <- F
|
||||
// E <- G
|
||||
//
|
||||
G4FieldTrack EndPoint = ApproxIntersecPointV;
|
||||
ApproxIntersecPointV = GetChordFinderFor()->ApproxCurvePointS(
|
||||
CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
EndPoint,CurrentE_Point, CurrentF_Point,PointG,
|
||||
true, GetEpsilonStepFor() );
|
||||
CurrentB_PointVelocity = EndPoint;
|
||||
CurrentE_Point = PointG;
|
||||
|
||||
// By moving point B, must take care if current
|
||||
// AF has no intersection to try current FB!!
|
||||
//
|
||||
fin_section_depth[depth] = false;
|
||||
#ifdef G4VERBOSE
|
||||
if( fVerboseLevel > 3 )
|
||||
{
|
||||
G4cout << "G4PiF::LI> Investigating intermediate point"
|
||||
<< " at s=" << ApproxIntersecPointV.GetCurveLength()
|
||||
<< " on way to full s="
|
||||
<< CurveEndPointVelocity.GetCurveLength() << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else // not Intersects_AF
|
||||
{
|
||||
// In this case:
|
||||
// There is NO intersection of AF with a volume boundary.
|
||||
// We must continue the search in the segment FB!
|
||||
//
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume( CurrentF_Point );
|
||||
|
||||
G4double stepLengthFB;
|
||||
G4ThreeVector PointH;
|
||||
|
||||
// Check whether any volumes are encountered by the chord FB
|
||||
// ---------------------------------------------------------
|
||||
|
||||
G4bool Intersects_FB = IntersectChord( CurrentF_Point, Point_B,
|
||||
NewSafety,fPreviousSafety,
|
||||
fPreviousSftOrigin,
|
||||
stepLengthFB,
|
||||
PointH );
|
||||
if( Intersects_FB )
|
||||
{
|
||||
// There is an intersection of FB with a volume boundary
|
||||
// H <- First Intersection of Chord FB
|
||||
|
||||
// H is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
|
||||
// Note that F must be in volume volA (the same as A)
|
||||
// (otherwise AF would meet a volume boundary!)
|
||||
// A <- F
|
||||
// E <- H
|
||||
//
|
||||
CurrentA_PointVelocity = ApproxIntersecPointV;
|
||||
ApproxIntersecPointV = GetChordFinderFor()->ApproxCurvePointS(
|
||||
CurrentA_PointVelocity,CurrentB_PointVelocity,
|
||||
CurrentA_PointVelocity,CurrentE_Point,Point_A,PointH,
|
||||
false,GetEpsilonStepFor());
|
||||
CurrentE_Point = PointH;
|
||||
}
|
||||
else // not Intersects_FB
|
||||
{
|
||||
// There is NO intersection of FB with a volume boundary
|
||||
|
||||
if( fin_section_depth[depth] )
|
||||
{
|
||||
// If B is the original endpoint, this means that whatever
|
||||
// volume(s) intersected the original chord, none touch the
|
||||
// smaller chords we have used.
|
||||
// The value of 'IntersectedOrRecalculatedFT' returned is
|
||||
// likely not valid
|
||||
|
||||
// Check on real final_section or SubEndSection
|
||||
//
|
||||
if( ((Second_half)&&(depth==0)) || (first_section) )
|
||||
{
|
||||
there_is_no_intersection = true; // real final_section
|
||||
}
|
||||
else
|
||||
{
|
||||
// end of subsection, not real final section
|
||||
// exit from the and go to the depth-1 level
|
||||
|
||||
substep_no_p = param_substeps+2; // exit from the loop
|
||||
|
||||
// but 'Second_half' is still true because we need to find
|
||||
// the 'CurrentE_point' for the next loop
|
||||
//
|
||||
Second_half = true;
|
||||
sub_final_section = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(depth==0)
|
||||
{
|
||||
// We must restore the original endpoint
|
||||
//
|
||||
CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B
|
||||
CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
restoredFullEndpoint = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We must restore the depth endpoint
|
||||
//
|
||||
CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth];
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
restoredFullEndpoint = true;
|
||||
}
|
||||
}
|
||||
} // Endif (Intersects_FB)
|
||||
} // Endif (Intersects_AF)
|
||||
|
||||
// Ensure that the new endpoints are not further apart in space
|
||||
// than on the curve due to different errors in the integration
|
||||
//
|
||||
G4double linDistSq, curveDist;
|
||||
linDistSq = ( CurrentB_PointVelocity.GetPosition()
|
||||
- CurrentA_PointVelocity.GetPosition() ).mag2();
|
||||
curveDist = CurrentB_PointVelocity.GetCurveLength()
|
||||
- CurrentA_PointVelocity.GetCurveLength();
|
||||
|
||||
// Change this condition for very strict parameters of propagation
|
||||
//
|
||||
if( curveDist*curveDist*(1+2* GetEpsilonStepFor()) < linDistSq )
|
||||
{
|
||||
// Re-integrate to obtain a new B
|
||||
//
|
||||
G4FieldTrack newEndPointFT=
|
||||
ReEstimateEndpoint( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
linDistSq, // to avoid recalculation
|
||||
curveDist );
|
||||
G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
|
||||
CurrentB_PointVelocity = newEndPointFT;
|
||||
|
||||
if ( (fin_section_depth[depth]) // real final section
|
||||
&&( first_section || ((Second_half)&&(depth==0)) ) )
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
IntersectedOrRecalculatedFT = newEndPointFT;
|
||||
// So that we can return it, if it is the endpoint!
|
||||
}
|
||||
}
|
||||
if( curveDist < 0.0 )
|
||||
{
|
||||
G4cerr << "ERROR - G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Error in advancing propagation." << G4endl;
|
||||
fVerboseLevel = 5; // Print out a maximum of information
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no );
|
||||
G4cerr << " Point A (start) is " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (end) is " << CurrentB_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Curve distance is " << curveDist << G4endl;
|
||||
G4cerr << G4endl
|
||||
<< "The final curve point is not further along"
|
||||
<< " than the original!" << G4endl;
|
||||
|
||||
if( recalculatedEndPoint )
|
||||
{
|
||||
G4cerr << "Recalculation of EndPoint was called with fEpsStep= "
|
||||
<< GetEpsilonStepFor() << G4endl;
|
||||
}
|
||||
G4cerr.precision(20);
|
||||
G4cerr << " Point A (Curve start) is " << CurveStartPointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (Curve end) is " << CurveEndPointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point A (Current start) is " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (Current end) is " << CurrentB_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point S (Sub start) is " << SubStart_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point E (Trial Point) is " << CurrentE_Point
|
||||
<< G4endl;
|
||||
G4cerr << " Point F (Intersection) is " << ApproxIntersecPointV
|
||||
<< G4endl;
|
||||
G4cerr << " LocateIntersection parameters are : Substep no= "
|
||||
<< substep_no << G4endl;
|
||||
G4cerr << " Substep depth no= "<< substep_no_p << " Depth= "
|
||||
<< depth << G4endl;
|
||||
|
||||
G4Exception("G4BrentLocator::EstimateIntersectionPoint()",
|
||||
"FatalError", FatalException,
|
||||
"Error in advancing propagation.");
|
||||
}
|
||||
|
||||
if(restoredFullEndpoint)
|
||||
{
|
||||
fin_section_depth[depth] = restoredFullEndpoint;
|
||||
restoredFullEndpoint = false;
|
||||
}
|
||||
} // EndIf ( E is close enough to the curve, ie point F. )
|
||||
// tests ChordAF_Vector.mag() <= maximum_lateral_displacement
|
||||
|
||||
#ifdef G4DEBUG_LOCATE_INTERSECTION
|
||||
if( substep_no >= trigger_substepno_print )
|
||||
{
|
||||
G4cout << "Difficulty in converging in "
|
||||
<< "G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Substep no = " << substep_no << G4endl;
|
||||
if( substep_no == trigger_substepno_print )
|
||||
{
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0);
|
||||
}
|
||||
G4cout << " State of point A: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1, 0);
|
||||
G4cout << " State of point B: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no);
|
||||
}
|
||||
#endif
|
||||
substep_no++;
|
||||
substep_no_p++;
|
||||
|
||||
} while ( ( ! found_approximate_intersection )
|
||||
&& ( ! there_is_no_intersection )
|
||||
&& ( substep_no_p <= param_substeps) ); // UNTIL found or
|
||||
// failed param substep
|
||||
first_section = false;
|
||||
|
||||
if( (!found_approximate_intersection) && (!there_is_no_intersection) )
|
||||
{
|
||||
G4double did_len = std::abs( CurrentA_PointVelocity.GetCurveLength()
|
||||
- SubStart_PointVelocity.GetCurveLength());
|
||||
G4double all_len = std::abs( CurrentB_PointVelocity.GetCurveLength()
|
||||
- SubStart_PointVelocity.GetCurveLength());
|
||||
|
||||
G4double stepLengthAB;
|
||||
G4ThreeVector PointGe;
|
||||
|
||||
// Check if progress is too slow and if it possible to go deeper,
|
||||
// then halve the step if so
|
||||
//
|
||||
if ( ( did_len < fraction_done*all_len )
|
||||
&& (depth<max_depth) && (!sub_final_section) )
|
||||
{
|
||||
Second_half=false;
|
||||
depth++;
|
||||
|
||||
G4double Sub_len = (all_len-did_len)/(2.);
|
||||
G4FieldTrack start = CurrentA_PointVelocity;
|
||||
G4MagInt_Driver* integrDriver =
|
||||
GetChordFinderFor()->GetIntegrationDriver();
|
||||
integrDriver->AccurateAdvance(start, Sub_len, GetEpsilonStepFor());
|
||||
*ptrInterMedFT[depth] = start;
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth];
|
||||
|
||||
// Adjust 'SubStartPoint' to calculate the 'did_length' in next loop
|
||||
//
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
|
||||
// Find new trial intersection point needed at start of the loop
|
||||
//
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();
|
||||
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume(Point_A);
|
||||
G4bool Intersects_AB = IntersectChord(Point_A, SubE_point,
|
||||
NewSafety, fPreviousSafety,
|
||||
fPreviousSftOrigin,stepLengthAB,
|
||||
PointGe);
|
||||
if( Intersects_AB )
|
||||
{
|
||||
last_AF_intersection = Intersects_AB;
|
||||
CurrentE_Point = PointGe;
|
||||
fin_section_depth[depth]=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No intersection found for first part of curve
|
||||
// (CurrentA,InterMedPoint[depth]). Go to the second part
|
||||
//
|
||||
Second_half = true;
|
||||
}
|
||||
} // if did_len
|
||||
|
||||
if( (Second_half)&&(depth!=0) )
|
||||
{
|
||||
// Second part of curve (InterMed[depth],Intermed[depth-1]) )
|
||||
// On the depth-1 level normally we are on the 'second_half'
|
||||
|
||||
Second_half = true;
|
||||
|
||||
// Find new trial intersection point needed at start of the loop
|
||||
//
|
||||
SubStart_PointVelocity = *ptrInterMedFT[depth];
|
||||
CurrentA_PointVelocity = *ptrInterMedFT[depth];
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth-1];
|
||||
// Ensure that the new endpoints are not further apart in space
|
||||
// than on the curve due to different errors in the integration
|
||||
//
|
||||
G4double linDistSq, curveDist;
|
||||
linDistSq = ( CurrentB_PointVelocity.GetPosition()
|
||||
- CurrentA_PointVelocity.GetPosition() ).mag2();
|
||||
curveDist = CurrentB_PointVelocity.GetCurveLength()
|
||||
- CurrentA_PointVelocity.GetCurveLength();
|
||||
if( curveDist*curveDist*(1+2*GetEpsilonStepFor() ) < linDistSq )
|
||||
{
|
||||
// Re-integrate to obtain a new B
|
||||
//
|
||||
G4FieldTrack newEndPointFT=
|
||||
ReEstimateEndpoint( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
linDistSq, // to avoid recalculation
|
||||
curveDist );
|
||||
G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
|
||||
CurrentB_PointVelocity = newEndPointFT;
|
||||
if (depth==1)
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
IntersectedOrRecalculatedFT = newEndPointFT;
|
||||
// So that we can return it, if it is the endpoint!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume(Point_A);
|
||||
G4bool Intersects_AB = IntersectChord(Point_A, SubE_point, NewSafety,
|
||||
fPreviousSafety,
|
||||
fPreviousSftOrigin,stepLengthAB, PointGe);
|
||||
if( Intersects_AB )
|
||||
{
|
||||
last_AF_intersection = Intersects_AB;
|
||||
CurrentE_Point = PointGe;
|
||||
}
|
||||
|
||||
depth--;
|
||||
fin_section_depth[depth]=true;
|
||||
}
|
||||
} // if(!found_aproximate_intersection)
|
||||
|
||||
} while ( ( ! found_approximate_intersection )
|
||||
&& ( ! there_is_no_intersection )
|
||||
&& ( substep_no <= max_substeps) ); // UNTIL found or failed
|
||||
|
||||
if( substep_no > max_no_seen )
|
||||
{
|
||||
max_no_seen = substep_no;
|
||||
if( max_no_seen > warn_substeps )
|
||||
{
|
||||
trigger_substepno_print = max_no_seen-20; // Want to see last 20 steps
|
||||
}
|
||||
}
|
||||
|
||||
if( ( substep_no >= max_substeps)
|
||||
&& !there_is_no_intersection
|
||||
&& !found_approximate_intersection )
|
||||
{
|
||||
G4cerr << "WARNING - G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cerr << " Abandoning effort to intersect. " << G4endl;
|
||||
G4cerr << " Information on start & current step follows in cout."
|
||||
<< G4endl;
|
||||
G4cout << "WARNING - G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cout << " Found intersection = "
|
||||
<< found_approximate_intersection << G4endl
|
||||
<< " Intersection exists = "
|
||||
<< !there_is_no_intersection << G4endl;
|
||||
G4cout << " Start and Endpoint of Requested Step:" << G4endl;
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0);
|
||||
G4cout << G4endl;
|
||||
G4cout << " 'Bracketing' starting and endpoint of current Sub-Step"
|
||||
<< G4endl;
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1);
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no);
|
||||
G4cout << G4endl;
|
||||
G4cout.precision( 10 );
|
||||
G4double done_len = CurrentA_PointVelocity.GetCurveLength();
|
||||
G4double full_len = CurveEndPointVelocity.GetCurveLength();
|
||||
G4cout << "ERROR - G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken only length: " << done_len
|
||||
<< " out of " << full_len << " required." << G4endl;
|
||||
G4cout << " Remaining length = " << full_len - done_len << G4endl;
|
||||
|
||||
G4Exception("G4BrentLocator::EstimateIntersectionPoint()",
|
||||
"UnableToLocateIntersection", FatalException,
|
||||
"Too many substeps while trying to locate intersection.");
|
||||
}
|
||||
else if( substep_no >= warn_substeps )
|
||||
{
|
||||
G4int oldprc= G4cout.precision( 10 );
|
||||
G4cout << "WARNING - G4BrentLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken length: "
|
||||
<< CurrentB_PointVelocity.GetCurveLength();
|
||||
G4cout << " - Needed: " << substep_no << " substeps." << G4endl
|
||||
<< " Warning level = " << warn_substeps
|
||||
<< " and maximum substeps = " << max_substeps << G4endl;
|
||||
G4Exception("G4BrentLocator::EstimateIntersectionPoint()",
|
||||
"DifficultyToLocateIntersection", JustWarning,
|
||||
"Many substeps while trying to locate intersection.");
|
||||
G4cout.precision( oldprc );
|
||||
}
|
||||
return !there_is_no_intersection; // Success or failure
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4DrawVoxels.cc,v 1.4 2006/06/29 18:36:34 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
//
|
||||
// class G4DrawVoxels
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4ErrorPropagationNavigator.cc,v 1.1 2007/05/16 12:49:18 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// $Id: G4ErrorPropagationNavigator.cc,v 1.2 2008/10/24 14:00:03 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
@@ -125,9 +125,11 @@ ComputeStep ( const G4ThreeVector &pGlobalPoint,
|
||||
|
||||
G4double G4ErrorPropagationNavigator::
|
||||
ComputeSafety( const G4ThreeVector &pGlobalpoint,
|
||||
const G4double pMaxLength )
|
||||
const G4double pMaxLength,
|
||||
const G4bool keepState )
|
||||
{
|
||||
G4double newSafety = G4Navigator::ComputeSafety(pGlobalpoint, pMaxLength);
|
||||
G4double newSafety = G4Navigator::ComputeSafety(pGlobalpoint,
|
||||
pMaxLength, keepState);
|
||||
|
||||
G4ErrorPropagatorData *g4edata
|
||||
= G4ErrorPropagatorData::GetErrorPropagatorData();
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestErrorList.cc,v 1.3 2006/06/29 18:36:36 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestOverlapList.cc,v 1.3 2006/06/29 18:36:39 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestOvershootList.cc,v 1.3 2006/06/29 18:36:41 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestPoint.cc,v 1.3 2006/06/29 18:36:44 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestSegment.cc,v 1.11 2007/11/16 09:39:14 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestStreamLogger.cc,v 1.3 2006/06/29 18:36:49 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestVolPoint.cc,v 1.3 2006/06/29 18:36:52 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeomTestVolume.cc,v 1.6 2007/11/16 09:39:14 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4GeometryMessenger.cc,v 1.5 2006/06/29 18:36:57 gunter Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
// GEANT 4 class source file
|
||||
|
||||
@@ -0,0 +1,722 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4MultiLevelLocator.cc,v 1.5 2008/12/11 10:01:02 tnikitin Exp $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// Class G4MultiLevelLocator implementation
|
||||
//
|
||||
// 27.10.08 - Tatiana Nikitina.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include "G4MultiLevelLocator.hh"
|
||||
|
||||
G4MultiLevelLocator::G4MultiLevelLocator(G4Navigator *theNavigator)
|
||||
: G4VIntersectionLocator(theNavigator)
|
||||
{
|
||||
// In case of too slow progress in finding Intersection Point
|
||||
// intermediates Points on the Track must be stored.
|
||||
// Initialise the array of Pointers [max_depth+1] to do this
|
||||
|
||||
G4ThreeVector zeroV(0.0,0.0,0.0);
|
||||
for (G4int idepth=0; idepth<max_depth+1; idepth++ )
|
||||
{
|
||||
ptrInterMedFT[ idepth ] = new G4FieldTrack( zeroV, zeroV, 0., 0., 0., 0.);
|
||||
}
|
||||
}
|
||||
|
||||
G4MultiLevelLocator::~G4MultiLevelLocator()
|
||||
{
|
||||
for ( G4int idepth=0; idepth<max_depth+1; idepth++)
|
||||
{
|
||||
delete ptrInterMedFT[idepth];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// G4bool G4PropagatorInField::LocateIntersectionPoint(
|
||||
// const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
// const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
// const G4ThreeVector& TrialPoint, // E
|
||||
// G4FieldTrack& IntersectedOrRecalculated // Output
|
||||
// G4bool& recalculated ) // Out
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Function that returns the intersection of the true path with the surface
|
||||
// of the current volume (either the external one or the inner one with one
|
||||
// of the daughters:
|
||||
//
|
||||
// A = Initial point
|
||||
// B = another point
|
||||
//
|
||||
// Both A and B are assumed to be on the true path:
|
||||
//
|
||||
// E is the first point of intersection of the chord AB with
|
||||
// a volume other than A (on the surface of A or of a daughter)
|
||||
//
|
||||
// Convention of Use :
|
||||
// i) If it returns "true", then IntersectionPointVelocity is set
|
||||
// to the approximate intersection point.
|
||||
// ii) If it returns "false", no intersection was found.
|
||||
// The validity of IntersectedOrRecalculated depends on 'recalculated'
|
||||
// a) if latter is false, then IntersectedOrRecalculated is invalid.
|
||||
// b) if latter is true, then IntersectedOrRecalculated is
|
||||
// the new endpoint, due to a re-integration.
|
||||
// --------------------------------------------------------------------------
|
||||
// NOTE: implementation taken from G4PropagatorInField
|
||||
//
|
||||
G4bool G4MultiLevelLocator::EstimateIntersectionPoint(
|
||||
const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
const G4ThreeVector& TrialPoint, // E
|
||||
G4FieldTrack& IntersectedOrRecalculatedFT, // Output
|
||||
G4bool& recalculatedEndPoint, // Out
|
||||
G4double &fPreviousSafety, // In/Out
|
||||
G4ThreeVector &fPreviousSftOrigin) // In/Out
|
||||
{
|
||||
// Find Intersection Point ( A, B, E ) of true path AB - start at E.
|
||||
|
||||
G4bool found_approximate_intersection = false;
|
||||
G4bool there_is_no_intersection = false;
|
||||
|
||||
G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
|
||||
G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
G4ThreeVector CurrentE_Point = TrialPoint;
|
||||
G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity); // FT-Def-Construct
|
||||
G4double NewSafety = 0.0;
|
||||
G4bool last_AF_intersection = false;
|
||||
|
||||
// G4bool final_section= true; // Shows whether current section is last
|
||||
// (i.e. B=full end)
|
||||
G4bool first_section = true;
|
||||
recalculatedEndPoint = false;
|
||||
|
||||
G4bool restoredFullEndpoint = false;
|
||||
|
||||
G4int substep_no = 0;
|
||||
|
||||
// Limits for substep number
|
||||
//
|
||||
const G4int max_substeps= 10000; // Test 120 (old value 100 )
|
||||
const G4int warn_substeps= 1000; // 100
|
||||
|
||||
// Statistics for substeps
|
||||
//
|
||||
static G4int max_no_seen= -1;
|
||||
static G4int trigger_substepno_print= warn_substeps - 20 ;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Algorithm for the case if progress in founding intersection is too slow.
|
||||
// Process is defined too slow if after N=param_substeps advances on the
|
||||
// path, it will be only 'fraction_done' of the total length.
|
||||
// In this case the remaining length is divided in two half and
|
||||
// the loop is restarted for each half.
|
||||
// If progress is still too slow, the division in two halfs continue
|
||||
// until 'max_depth'.
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
const G4int param_substeps=10; // Test value for the maximum number
|
||||
// of substeps
|
||||
const G4double fraction_done=0.3;
|
||||
|
||||
G4bool Second_half = false; // First half or second half of divided step
|
||||
|
||||
// We need to know this for the 'final_section':
|
||||
// real 'final_section' or first half 'final_section'
|
||||
// In algorithm it is considered that the 'Second_half' is true
|
||||
// and it becomes false only if we are in the first-half of level
|
||||
// depthness or if we are in the first section
|
||||
|
||||
G4int depth=0; // Depth counts how many subdivisions of initial step made
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
static G4double tolerance= 1.0e-8;
|
||||
G4ThreeVector StartPosition= CurveStartPointVelocity.GetPosition();
|
||||
if( (TrialPoint - StartPosition).mag() < tolerance * mm )
|
||||
{
|
||||
G4cerr << "WARNING - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is on top of starting point A."
|
||||
<< G4endl;
|
||||
G4Exception("G4MultiLevelLocator::EstimateIntersectionPoint()",
|
||||
"IntersectionPointIsAtStart", JustWarning,
|
||||
"Intersection point F is exactly at start point A." );
|
||||
}
|
||||
#endif
|
||||
|
||||
// Intermediates Points on the Track = Subdivided Points must be stored.
|
||||
// Give the initial values to 'InterMedFt'
|
||||
// Important is 'ptrInterMedFT[0]', it saves the 'EndCurvePoint'
|
||||
//
|
||||
*ptrInterMedFT[0] = CurveEndPointVelocity;
|
||||
for (G4int idepth=1; idepth<max_depth+1; idepth++ )
|
||||
{
|
||||
*ptrInterMedFT[idepth]=CurveStartPointVelocity;
|
||||
}
|
||||
|
||||
// Final_section boolean store
|
||||
//
|
||||
G4bool fin_section_depth[max_depth];
|
||||
for (G4int idepth=0; idepth<max_depth; idepth++ )
|
||||
{
|
||||
fin_section_depth[idepth]=true;
|
||||
}
|
||||
// 'SubStartPoint' is needed to calculate the length of the divided step
|
||||
//
|
||||
G4FieldTrack SubStart_PointVelocity = CurveStartPointVelocity;
|
||||
|
||||
do
|
||||
{
|
||||
G4int substep_no_p = 0;
|
||||
G4bool sub_final_section = false; // the same as final_section,
|
||||
// but for 'sub_section'
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
do // REPEAT param
|
||||
{
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector Point_B = CurrentB_PointVelocity.GetPosition();
|
||||
|
||||
// F = a point on true AB path close to point E
|
||||
// (the closest if possible)
|
||||
//
|
||||
ApproxIntersecPointV = GetChordFinderFor()
|
||||
->ApproxCurvePointV( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
CurrentE_Point,
|
||||
GetEpsilonStepFor());
|
||||
// The above method is the key & most intuitive part ...
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
if( ApproxIntersecPointV.GetCurveLength() >
|
||||
CurrentB_PointVelocity.GetCurveLength() * (1.0 + tolerance) )
|
||||
{
|
||||
G4cerr << "ERROR - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is more advanced than"
|
||||
<< " endpoint B." << G4endl;
|
||||
G4Exception("G4multiLevelLocator::EstimateIntersectionPoint()",
|
||||
"IntermediatePointConfusion", FatalException,
|
||||
"Intermediate F point is past end B point" );
|
||||
}
|
||||
#endif
|
||||
|
||||
G4ThreeVector CurrentF_Point= ApproxIntersecPointV.GetPosition();
|
||||
|
||||
// First check whether EF is small - then F is a good approx. point
|
||||
// Calculate the length and direction of the chord AF
|
||||
//
|
||||
G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
|
||||
|
||||
if ( ChordEF_Vector.mag2() <= sqr(GetDeltaIntersectionFor()) )
|
||||
{
|
||||
found_approximate_intersection = true;
|
||||
|
||||
// Create the "point" return value
|
||||
//
|
||||
IntersectedOrRecalculatedFT = ApproxIntersecPointV;
|
||||
IntersectedOrRecalculatedFT.SetPosition( CurrentE_Point );
|
||||
|
||||
if ( GetAdjustementOfFoundIntersection() )
|
||||
{
|
||||
// Try to Get Correction of IntersectionPoint using SurfaceNormal()
|
||||
//
|
||||
G4ThreeVector IP;
|
||||
G4ThreeVector MomentumDir=ApproxIntersecPointV.GetMomentumDirection();
|
||||
G4bool goodCorrection = AdjustmentOfFoundIntersection(Point_A,
|
||||
CurrentE_Point, CurrentF_Point, MomentumDir,
|
||||
last_AF_intersection, IP, NewSafety,
|
||||
fPreviousSafety, fPreviousSftOrigin );
|
||||
if ( goodCorrection )
|
||||
{
|
||||
IntersectedOrRecalculatedFT = ApproxIntersecPointV;
|
||||
IntersectedOrRecalculatedFT.SetPosition(IP);
|
||||
}
|
||||
}
|
||||
// Note: in order to return a point on the boundary,
|
||||
// we must return E. But it is F on the curve.
|
||||
// So we must "cheat": we are using the position at point E
|
||||
// and the velocity at point F !!!
|
||||
//
|
||||
// This must limit the length we can allow for displacement!
|
||||
}
|
||||
else // E is NOT close enough to the curve (ie point F)
|
||||
{
|
||||
// Check whether any volumes are encountered by the chord AF
|
||||
// ---------------------------------------------------------
|
||||
// First relocate to restore any Voxel etc information
|
||||
// in the Navigator before calling ComputeStep()
|
||||
//
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume( Point_A );
|
||||
|
||||
G4ThreeVector PointG; // Candidate intersection point
|
||||
G4double stepLengthAF;
|
||||
G4bool Intersects_AF = IntersectChord( Point_A, CurrentF_Point,
|
||||
NewSafety,fPreviousSafety,
|
||||
fPreviousSftOrigin,
|
||||
stepLengthAF,
|
||||
PointG );
|
||||
last_AF_intersection = Intersects_AF;
|
||||
if( Intersects_AF )
|
||||
{
|
||||
// G is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
// B <- F
|
||||
// E <- G
|
||||
//
|
||||
CurrentB_PointVelocity = ApproxIntersecPointV;
|
||||
CurrentE_Point = PointG;
|
||||
|
||||
// By moving point B, must take care if current
|
||||
// AF has no intersection to try current FB!!
|
||||
//
|
||||
fin_section_depth[depth]=false;
|
||||
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if( fVerboseLevel > 3 )
|
||||
{
|
||||
G4cout << "G4PiF::LI> Investigating intermediate point"
|
||||
<< " at s=" << ApproxIntersecPointV.GetCurveLength()
|
||||
<< " on way to full s="
|
||||
<< CurveEndPointVelocity.GetCurveLength() << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else // not Intersects_AF
|
||||
{
|
||||
// In this case:
|
||||
// There is NO intersection of AF with a volume boundary.
|
||||
// We must continue the search in the segment FB!
|
||||
//
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume( CurrentF_Point );
|
||||
|
||||
G4double stepLengthFB;
|
||||
G4ThreeVector PointH;
|
||||
|
||||
// Check whether any volumes are encountered by the chord FB
|
||||
// ---------------------------------------------------------
|
||||
|
||||
G4bool Intersects_FB = IntersectChord( CurrentF_Point, Point_B,
|
||||
NewSafety,fPreviousSafety,
|
||||
fPreviousSftOrigin,
|
||||
stepLengthFB,
|
||||
PointH );
|
||||
if( Intersects_FB )
|
||||
{
|
||||
// There is an intersection of FB with a volume boundary
|
||||
// H <- First Intersection of Chord FB
|
||||
|
||||
// H is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
|
||||
// Note that F must be in volume volA (the same as A)
|
||||
// (otherwise AF would meet a volume boundary!)
|
||||
// A <- F
|
||||
// E <- H
|
||||
//
|
||||
CurrentA_PointVelocity = ApproxIntersecPointV;
|
||||
CurrentE_Point = PointH;
|
||||
}
|
||||
else // not Intersects_FB
|
||||
{
|
||||
// There is NO intersection of FB with a volume boundary
|
||||
|
||||
if(fin_section_depth[depth])
|
||||
{
|
||||
// If B is the original endpoint, this means that whatever
|
||||
// volume(s) intersected the original chord, none touch the
|
||||
// smaller chords we have used.
|
||||
// The value of 'IntersectedOrRecalculatedFT' returned is
|
||||
// likely not valid
|
||||
|
||||
// Check on real final_section or SubEndSection
|
||||
//
|
||||
if( ((Second_half)&&(depth==0)) || (first_section) )
|
||||
{
|
||||
there_is_no_intersection = true; // real final_section
|
||||
}
|
||||
else
|
||||
{
|
||||
// end of subsection, not real final section
|
||||
// exit from the and go to the depth-1 level
|
||||
|
||||
substep_no_p = param_substeps+2; // exit from the loop
|
||||
|
||||
// but 'Second_half' is still true because we need to find
|
||||
// the 'CurrentE_point' for the next loop
|
||||
//
|
||||
Second_half = true;
|
||||
sub_final_section = true;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(depth==0)
|
||||
{
|
||||
// We must restore the original endpoint
|
||||
//
|
||||
CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B
|
||||
CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
restoredFullEndpoint = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We must restore the depth endpoint
|
||||
//
|
||||
CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth];
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
restoredFullEndpoint = true;
|
||||
}
|
||||
}
|
||||
} // Endif (Intersects_FB)
|
||||
} // Endif (Intersects_AF)
|
||||
|
||||
// Ensure that the new endpoints are not further apart in space
|
||||
// than on the curve due to different errors in the integration
|
||||
//
|
||||
G4double linDistSq, curveDist;
|
||||
linDistSq = ( CurrentB_PointVelocity.GetPosition()
|
||||
- CurrentA_PointVelocity.GetPosition() ).mag2();
|
||||
curveDist = CurrentB_PointVelocity.GetCurveLength()
|
||||
- CurrentA_PointVelocity.GetCurveLength();
|
||||
|
||||
// Change this condition for very strict parameters of propagation
|
||||
//
|
||||
if( curveDist*curveDist*(1+2* GetEpsilonStepFor()) < linDistSq )
|
||||
{
|
||||
// Re-integrate to obtain a new B
|
||||
//
|
||||
G4FieldTrack newEndPointFT=
|
||||
ReEstimateEndpoint( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
linDistSq, // to avoid recalculation
|
||||
curveDist );
|
||||
G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
|
||||
CurrentB_PointVelocity = newEndPointFT;
|
||||
|
||||
if ( (fin_section_depth[depth]) // real final section
|
||||
&&( first_section || ((Second_half)&&(depth==0)) ) )
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
IntersectedOrRecalculatedFT = newEndPointFT;
|
||||
// So that we can return it, if it is the endpoint!
|
||||
}
|
||||
}
|
||||
if( curveDist < 0.0 )
|
||||
{
|
||||
G4cerr << "ERROR - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Error in advancing propagation." << G4endl;
|
||||
fVerboseLevel = 5; // Print out a maximum of information
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no );
|
||||
G4cerr << " Point A (start) is " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (end) is " << CurrentB_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Curve distance is " << curveDist << G4endl;
|
||||
G4cerr << G4endl
|
||||
<< "The final curve point is not further along"
|
||||
<< " than the original!" << G4endl;
|
||||
|
||||
if( recalculatedEndPoint )
|
||||
{
|
||||
G4cerr << "Recalculation of EndPoint was called with fEpsStep= "
|
||||
<< GetEpsilonStepFor() << G4endl;
|
||||
}
|
||||
G4cerr.precision(20);
|
||||
G4cerr << " Point A (Curve start) is " << CurveStartPointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (Curve end) is " << CurveEndPointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point A (Current start) is " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (Current end) is " << CurrentB_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point S (Sub start) is " << SubStart_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point E (Trial Point) is " << CurrentE_Point
|
||||
<< G4endl;
|
||||
G4cerr << " Point F (Intersection) is " << ApproxIntersecPointV
|
||||
<< G4endl;
|
||||
G4cerr << " LocateIntersection parameters are : Substep no= "
|
||||
<< substep_no << G4endl;
|
||||
G4cerr << " Substep depth no= "<< substep_no_p << " Depth= "
|
||||
<< depth << G4endl;
|
||||
|
||||
G4Exception("G4MultiLevelLocator::EstimateIntersectionPoint()",
|
||||
"FatalError", FatalException,
|
||||
"Error in advancing propagation.");
|
||||
}
|
||||
if(restoredFullEndpoint)
|
||||
{
|
||||
fin_section_depth[depth] = restoredFullEndpoint;
|
||||
restoredFullEndpoint = false;
|
||||
}
|
||||
} // EndIf ( E is close enough to the curve, ie point F. )
|
||||
// tests ChordAF_Vector.mag() <= maximum_lateral_displacement
|
||||
|
||||
#ifdef G4DEBUG_LOCATE_INTERSECTION
|
||||
if( substep_no >= trigger_substepno_print )
|
||||
{
|
||||
G4cout << "Difficulty in converging in "
|
||||
<< "G4MultiLevelLocator::EstimateIntersectionPoint():"
|
||||
<< G4endl
|
||||
<< " Substep no = " << substep_no << G4endl;
|
||||
if( substep_no == trigger_substepno_print )
|
||||
{
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0);
|
||||
}
|
||||
G4cout << " State of point A: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1, 0);
|
||||
G4cout << " State of point B: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no);
|
||||
}
|
||||
#endif
|
||||
substep_no++;
|
||||
substep_no_p++;
|
||||
|
||||
} while ( ( ! found_approximate_intersection )
|
||||
&& ( ! there_is_no_intersection )
|
||||
&& ( substep_no_p <= param_substeps) ); // UNTIL found or
|
||||
// failed param substep
|
||||
first_section = false;
|
||||
|
||||
if( (!found_approximate_intersection) && (!there_is_no_intersection) )
|
||||
{
|
||||
G4double did_len = std::abs( CurrentA_PointVelocity.GetCurveLength()
|
||||
- SubStart_PointVelocity.GetCurveLength());
|
||||
G4double all_len = std::abs( CurrentB_PointVelocity.GetCurveLength()
|
||||
- SubStart_PointVelocity.GetCurveLength());
|
||||
|
||||
G4double stepLengthAB;
|
||||
G4ThreeVector PointGe;
|
||||
// Check if progress is too slow and if it possible to go deeper,
|
||||
// then halve the step if so
|
||||
//
|
||||
if( ( ( did_len )<fraction_done*all_len)
|
||||
&& (depth<max_depth) && (!sub_final_section) )
|
||||
{
|
||||
Second_half=false;
|
||||
depth++;
|
||||
|
||||
G4double Sub_len = (all_len-did_len)/(2.);
|
||||
G4FieldTrack start = CurrentA_PointVelocity;
|
||||
G4MagInt_Driver* integrDriver
|
||||
= GetChordFinderFor()->GetIntegrationDriver();
|
||||
integrDriver->AccurateAdvance(start, Sub_len, GetEpsilonStepFor());
|
||||
*ptrInterMedFT[depth] = start;
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth];
|
||||
|
||||
// Adjust 'SubStartPoint' to calculate the 'did_length' in next loop
|
||||
//
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
|
||||
// Find new trial intersection point needed at start of the loop
|
||||
//
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();
|
||||
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume(Point_A);
|
||||
G4bool Intersects_AB = IntersectChord(Point_A, SubE_point,
|
||||
NewSafety, fPreviousSafety,
|
||||
fPreviousSftOrigin,stepLengthAB,
|
||||
PointGe);
|
||||
if( Intersects_AB )
|
||||
{
|
||||
last_AF_intersection = Intersects_AB;
|
||||
CurrentE_Point = PointGe;
|
||||
fin_section_depth[depth]=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No intersection found for first part of curve
|
||||
// (CurrentA,InterMedPoint[depth]). Go to the second part
|
||||
//
|
||||
Second_half = true;
|
||||
}
|
||||
} // if did_len
|
||||
|
||||
if( (Second_half)&&(depth!=0) )
|
||||
{
|
||||
// Second part of curve (InterMed[depth],Intermed[depth-1]) )
|
||||
// On the depth-1 level normally we are on the 'second_half'
|
||||
|
||||
Second_half = true;
|
||||
// Find new trial intersection point needed at start of the loop
|
||||
//
|
||||
SubStart_PointVelocity = *ptrInterMedFT[depth];
|
||||
CurrentA_PointVelocity = *ptrInterMedFT[depth];
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth-1];
|
||||
// Ensure that the new endpoints are not further apart in space
|
||||
// than on the curve due to different errors in the integration
|
||||
//
|
||||
G4double linDistSq, curveDist;
|
||||
linDistSq = ( CurrentB_PointVelocity.GetPosition()
|
||||
- CurrentA_PointVelocity.GetPosition() ).mag2();
|
||||
curveDist = CurrentB_PointVelocity.GetCurveLength()
|
||||
- CurrentA_PointVelocity.GetCurveLength();
|
||||
if( curveDist*curveDist*(1+2*GetEpsilonStepFor() ) < linDistSq )
|
||||
{
|
||||
// Re-integrate to obtain a new B
|
||||
//
|
||||
G4FieldTrack newEndPointFT=
|
||||
ReEstimateEndpoint( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
linDistSq, // to avoid recalculation
|
||||
curveDist );
|
||||
G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
|
||||
CurrentB_PointVelocity = newEndPointFT;
|
||||
if (depth==1)
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
IntersectedOrRecalculatedFT = newEndPointFT;
|
||||
// So that we can return it, if it is the endpoint!
|
||||
}
|
||||
}
|
||||
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume(Point_A);
|
||||
G4bool Intersects_AB = IntersectChord(Point_A, SubE_point, NewSafety,
|
||||
fPreviousSafety,
|
||||
fPreviousSftOrigin,stepLengthAB,
|
||||
PointGe);
|
||||
if( Intersects_AB )
|
||||
{
|
||||
last_AF_intersection = Intersects_AB;
|
||||
CurrentE_Point = PointGe;
|
||||
}
|
||||
depth--;
|
||||
fin_section_depth[depth]=true;
|
||||
}
|
||||
} // if(!found_aproximate_intersection)
|
||||
|
||||
} while ( ( ! found_approximate_intersection )
|
||||
&& ( ! there_is_no_intersection )
|
||||
&& ( substep_no <= max_substeps) ); // UNTIL found or failed
|
||||
|
||||
if( substep_no > max_no_seen )
|
||||
{
|
||||
max_no_seen = substep_no;
|
||||
if( max_no_seen > warn_substeps )
|
||||
{
|
||||
trigger_substepno_print = max_no_seen-20; // Want to see last 20 steps
|
||||
}
|
||||
}
|
||||
|
||||
if( ( substep_no >= max_substeps)
|
||||
&& !there_is_no_intersection
|
||||
&& !found_approximate_intersection )
|
||||
{
|
||||
G4cerr << "WARNING - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cerr << " Abandoning effort to intersect. " << G4endl;
|
||||
G4cerr << " Information on start & current step follows in cout."
|
||||
<< G4endl;
|
||||
G4cout << "WARNING - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cout << " Found intersection = "
|
||||
<< found_approximate_intersection << G4endl
|
||||
<< " Intersection exists = "
|
||||
<< !there_is_no_intersection << G4endl;
|
||||
G4cout << " Start and Endpoint of Requested Step:" << G4endl;
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0);
|
||||
G4cout << G4endl;
|
||||
G4cout << " 'Bracketing' starting and endpoint of current Sub-Step"
|
||||
<< G4endl;
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1);
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no);
|
||||
G4cout << G4endl;
|
||||
|
||||
#ifdef FUTURE_CORRECTION
|
||||
// Attempt to correct the results of the method // FIX - TODO
|
||||
|
||||
if ( ! found_approximate_intersection )
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
// Return the further valid intersection point -- potentially A ??
|
||||
// JA/19 Jan 2006
|
||||
IntersectedOrRecalculatedFT = CurrentA_PointVelocity;
|
||||
|
||||
G4cout << "WARNING - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Did not convergence after " << substep_no
|
||||
<< " substeps." << G4endl;
|
||||
G4cout << " The endpoint was adjused to pointA resulting"
|
||||
<< G4endl
|
||||
<< " from the last substep: " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
G4cout.precision( 10 );
|
||||
G4double done_len = CurrentA_PointVelocity.GetCurveLength();
|
||||
G4double full_len = CurveEndPointVelocity.GetCurveLength();
|
||||
G4cout << "ERROR - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken only length: " << done_len
|
||||
<< " out of " << full_len << " required." << G4endl;
|
||||
G4cout << " Remaining length = " << full_len - done_len << G4endl;
|
||||
|
||||
G4Exception("G4MultiLevelLocator::EstimateIntersectionPoint()",
|
||||
"UnableToLocateIntersection", FatalException,
|
||||
"Too many substeps while trying to locate intersection.");
|
||||
}
|
||||
else if( substep_no >= warn_substeps )
|
||||
{
|
||||
G4int oldprc= G4cout.precision( 10 );
|
||||
G4cout << "WARNING - G4MultiLevelLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken length: "
|
||||
<< CurrentB_PointVelocity.GetCurveLength();
|
||||
G4cout << " - Needed: " << substep_no << " substeps." << G4endl
|
||||
<< " Warning level = " << warn_substeps
|
||||
<< " and maximum substeps = " << max_substeps << G4endl;
|
||||
G4Exception("G4MultiLevelLocator::EstimateIntersectionPoint()",
|
||||
"DifficultyToLocateIntersection", JustWarning,
|
||||
"Many substeps while trying to locate intersection.");
|
||||
G4cout.precision( oldprc );
|
||||
}
|
||||
return !there_is_no_intersection; // Success or failure
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4MultiNavigator.cc,v 1.7 2007/11/02 13:48:43 japost Exp $
|
||||
// $Id: G4MultiNavigator.cc,v 1.8 2008/10/24 14:00:03 gcosmo Exp $
|
||||
// GEANT4 tag $ Name: $
|
||||
//
|
||||
// class G4PathFinder Implementation
|
||||
@@ -422,7 +422,8 @@ G4MultiNavigator::LocateGlobalPointWithinVolume(const G4ThreeVector& position)
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
G4double G4MultiNavigator::ComputeSafety( const G4ThreeVector& position,
|
||||
G4double maxDistance)
|
||||
const G4double maxDistance,
|
||||
const G4bool state)
|
||||
{
|
||||
// Recompute safety for the relevant point
|
||||
|
||||
@@ -433,7 +434,7 @@ G4double G4MultiNavigator::ComputeSafety( const G4ThreeVector& position,
|
||||
|
||||
for( register int num=0; num< fNoActiveNavigators; ++pNavigatorIter,++num )
|
||||
{
|
||||
safety = (*pNavigatorIter)->ComputeSafety( position, maxDistance );
|
||||
safety = (*pNavigatorIter)->ComputeSafety( position, maxDistance, state);
|
||||
if( safety < minSafety ) { minSafety = safety; }
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4Navigator.cc,v 1.37 2007/10/18 14:18:36 gcosmo Exp $
|
||||
// $Id: G4Navigator.cc,v 1.38 2008/10/24 14:00:03 gcosmo Exp $
|
||||
// GEANT4 tag $ Name: $
|
||||
//
|
||||
// class G4Navigator Implementation
|
||||
@@ -1213,7 +1213,8 @@ G4ThreeVector G4Navigator::GetLocalExitNormal( G4bool* valid )
|
||||
// ********************************************************************
|
||||
//
|
||||
G4double G4Navigator::ComputeSafety( const G4ThreeVector &pGlobalpoint,
|
||||
const G4double pMaxLength)
|
||||
const G4double pMaxLength,
|
||||
const G4bool keepState)
|
||||
{
|
||||
G4double newSafety = 0.0;
|
||||
|
||||
@@ -1235,6 +1236,8 @@ G4double G4Navigator::ComputeSafety( const G4ThreeVector &pGlobalpoint,
|
||||
}
|
||||
#endif
|
||||
|
||||
if (keepState) { SetSavedState(); }
|
||||
|
||||
G4double distEndpointSq = (pGlobalpoint-fStepEndPoint).mag2();
|
||||
G4bool stayedOnEndpoint = distEndpointSq < kCarTolerance*kCarTolerance;
|
||||
G4bool endpointOnSurface = fEnteredDaughter || fExitedMother;
|
||||
@@ -1321,6 +1324,8 @@ G4double G4Navigator::ComputeSafety( const G4ThreeVector &pGlobalpoint,
|
||||
fPreviousSftOrigin = pGlobalpoint;
|
||||
fPreviousSafety = newSafety;
|
||||
|
||||
if (keepState) { RestoreSavedState(); }
|
||||
|
||||
#ifdef G4DEBUG_NAVIGATION
|
||||
if( fVerbose > 1 )
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4NormalNavigation.cc,v 1.9 2007/05/11 13:43:59 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
//
|
||||
// class G4NormalNavigation Implementation
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4ParameterisedNavigation.cc,v 1.12 2007/11/09 16:06:02 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
//
|
||||
// class G4ParameterisedNavigation Implementation
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4PathFinder.cc,v 1.58 2007/11/14 10:04:21 gcosmo Exp $
|
||||
// $Id: G4PathFinder.cc,v 1.61 2008/11/13 12:59:26 gcosmo Exp $
|
||||
// GEANT4 tag $ Name: $
|
||||
//
|
||||
// class G4PathFinder Implementation
|
||||
@@ -254,6 +254,7 @@ G4PathFinder::ComputeStep( const G4FieldTrack &InitialFieldTrack,
|
||||
"Number of geometries limiting the step not set.");
|
||||
}
|
||||
}
|
||||
#ifdef G4DEBUG_PATHFINDER
|
||||
else
|
||||
{
|
||||
if( proposedStepLength < fTrueMinStep ) // For 2nd+ geometry
|
||||
@@ -306,16 +307,16 @@ G4PathFinder::ComputeStep( const G4FieldTrack &InitialFieldTrack,
|
||||
// client accessing information for the current track, step
|
||||
// We will simply retrieve the results of the synchronous
|
||||
// stepping for this Navigator Id below.
|
||||
#ifdef G4DEBUG_PATHFINDER
|
||||
//
|
||||
if( fVerboseLevel > 1 )
|
||||
{
|
||||
G4cout << " G4P::CS -> Not calling DoNextLinearStep: "
|
||||
<< " stepNo= " << stepNo << " last= " << fLastStepNo
|
||||
<< " new= " << fNewTrack << " Step already done" << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
fNewTrack= false;
|
||||
|
||||
@@ -579,19 +580,10 @@ void G4PathFinder::ReLocate( const G4ThreeVector& position )
|
||||
|
||||
if( (!fNewTrack) && ( longMoveEnd && longMoveSaf ) )
|
||||
{
|
||||
G4ThreeVector LastSafetyLocation;
|
||||
// Copy to keep last value - and restore
|
||||
|
||||
LastSafetyLocation= fSafetyLocation;
|
||||
|
||||
// Recompute ComputeSafety for end position
|
||||
//
|
||||
revisedSafety= ComputeSafety(lastEndPosition);
|
||||
|
||||
// Reset the state of last call to ComputeSafety
|
||||
//
|
||||
ComputeSafety( LastSafetyLocation );
|
||||
|
||||
#ifdef G4DEBUG_PATHFINDER
|
||||
|
||||
const G4double kRadTolerance =
|
||||
@@ -755,11 +747,11 @@ G4double G4PathFinder::ComputeSafety( const G4ThreeVector& position )
|
||||
G4double minSafety= kInfinity;
|
||||
|
||||
std::vector<G4Navigator*>::iterator pNavigatorIter;
|
||||
pNavigatorIter= fpTransportManager-> GetActiveNavigatorsIterator();
|
||||
pNavigatorIter= fpTransportManager->GetActiveNavigatorsIterator();
|
||||
|
||||
for( register G4int num=0; num<fNoActiveNavigators; ++pNavigatorIter,++num )
|
||||
{
|
||||
G4double safety = (*pNavigatorIter)->ComputeSafety( position );
|
||||
G4double safety = (*pNavigatorIter)->ComputeSafety( position,true );
|
||||
if( safety < minSafety ) { minSafety = safety; }
|
||||
fNewSafetyComputed[num]= safety;
|
||||
}
|
||||
@@ -1181,7 +1173,7 @@ G4PathFinder::DoNextCurvedStep( const G4FieldTrack &initialState,
|
||||
G4double minSafety= kInfinity, safety;
|
||||
for( numNav=0; numNav < fNoActiveNavigators; ++numNav )
|
||||
{
|
||||
safety= fpNavigator[numNav]->ComputeSafety( startPoint );
|
||||
safety= fpNavigator[numNav]->ComputeSafety( startPoint, false );
|
||||
fPreSafetyValues[numNav]= safety;
|
||||
fCurrentPreStepSafety[numNav]= safety;
|
||||
minSafety = std::min( safety, minSafety );
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4PhantomParameterisation.cc,v 1.2 2007/12/10 16:29:59 gunter Exp $
|
||||
// $Id: G4PhantomParameterisation.cc,v 1.4 2008/01/22 15:02:36 gcosmo Exp $
|
||||
// GEANT4 tag $ Name:$
|
||||
//
|
||||
// class G4PhantomParameterisation implementation
|
||||
//
|
||||
// Author: Pedro Arce, May 2007
|
||||
// May 2007 Pedro Arce, first version
|
||||
//
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
@@ -251,19 +251,19 @@ GetReplicaNo( const G4ThreeVector& localPoint, const G4ThreeVector& localDir )
|
||||
// Add +kCarTolerance so that they are first placed on voxel N, and then
|
||||
// if the direction is negative substract 1
|
||||
|
||||
G4double fx = (localPoint.x()+fContainerWallX+kCarTolerance)/fVoxelHalfX/2.;
|
||||
G4double fx = (localPoint.x()+fContainerWallX+kCarTolerance)/(fVoxelHalfX*2.);
|
||||
G4int nx = G4int(fx);
|
||||
|
||||
G4double fy = (localPoint.y()+fContainerWallY+kCarTolerance)/fVoxelHalfY/2.;
|
||||
G4double fy = (localPoint.y()+fContainerWallY+kCarTolerance)/(fVoxelHalfY*2.);
|
||||
G4int ny = G4int(fy);
|
||||
|
||||
G4double fz = (localPoint.z()+fContainerWallZ+kCarTolerance)/fVoxelHalfZ/2.;
|
||||
G4double fz = (localPoint.z()+fContainerWallZ+kCarTolerance)/(fVoxelHalfZ*2.);
|
||||
G4int nz = G4int(fz);
|
||||
|
||||
// If it is on the surface side, check the direction: if direction is
|
||||
// negative place it on the previous voxel (if direction is positive it is
|
||||
// already in the next voxel...).
|
||||
// NOTE: Sometimes this algorithm gives nx = -1, it is always traced to be
|
||||
// Correct also cases where n = -1 or n = fNoVoxel. It is always traced to be
|
||||
// due to multiple scattering: track is entering a voxel but multiple
|
||||
// scattering changes the angle towards outside
|
||||
//
|
||||
@@ -275,8 +275,12 @@ GetReplicaNo( const G4ThreeVector& localPoint, const G4ThreeVector& localDir )
|
||||
{
|
||||
nx -= 1;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if( nx == G4int(fNoVoxelX) )
|
||||
{
|
||||
nx -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,8 +292,12 @@ GetReplicaNo( const G4ThreeVector& localPoint, const G4ThreeVector& localDir )
|
||||
{
|
||||
ny -= 1;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ny == G4int(fNoVoxelY) )
|
||||
{
|
||||
ny -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,63 +309,69 @@ GetReplicaNo( const G4ThreeVector& localPoint, const G4ThreeVector& localDir )
|
||||
{
|
||||
nz -= 1;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if( nz == G4int(fNoVoxelZ) )
|
||||
{
|
||||
nz -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
G4int copyNo = nx + fNoVoxelX*ny + fNoVoxelXY*nz;
|
||||
|
||||
// Correct precision problems
|
||||
// Check if there are still errors
|
||||
//
|
||||
if( copyNo < 0 || copyNo >= G4int(fNoVoxel) )
|
||||
G4bool isOK = true;
|
||||
if( nx < 0 )
|
||||
{
|
||||
G4bool isOK = true;
|
||||
if( nx < 0 )
|
||||
{
|
||||
nx = 0;
|
||||
isOK = false;
|
||||
}
|
||||
else if( nx >= G4int(fNoVoxelX) )
|
||||
{
|
||||
nx = fNoVoxelX-1;
|
||||
isOK = false;
|
||||
}
|
||||
if( ny < 0 )
|
||||
{
|
||||
ny = 0;
|
||||
isOK = false;
|
||||
}
|
||||
else if( ny >= G4int(fNoVoxelY) )
|
||||
{
|
||||
ny = fNoVoxelY-1;
|
||||
isOK = false;
|
||||
}
|
||||
if( nz < 0 )
|
||||
{
|
||||
nz = 0;
|
||||
isOK = false;
|
||||
}
|
||||
else if( nz >= G4int(fNoVoxelZ) )
|
||||
{
|
||||
nz = fNoVoxelZ-1;
|
||||
isOK = false;
|
||||
}
|
||||
if( !isOK )
|
||||
{
|
||||
G4cerr << "WARNING - G4PhantomParameterisation::GetReplicaNo()" << G4endl
|
||||
<< " LocalPoint: " << localPoint << G4endl
|
||||
<< " Voxel container size: " << fContainerWallX
|
||||
<< " " << fContainerWallY << " " << fContainerWallZ << G4endl;
|
||||
G4Exception("G4PhantomParameterisation::GetReplicaNo()",
|
||||
"Wrong-copy-number", JustWarning,
|
||||
"Corrected the copy numbe! It was negative or too big");
|
||||
copyNo = nx + fNoVoxelX*ny + fNoVoxelXY*nz;
|
||||
}
|
||||
nx = 0;
|
||||
isOK = false;
|
||||
}
|
||||
else if( nx >= G4int(fNoVoxelX) )
|
||||
{
|
||||
nx = fNoVoxelX-1;
|
||||
isOK = false;
|
||||
}
|
||||
if( ny < 0 )
|
||||
{
|
||||
ny = 0;
|
||||
isOK = false;
|
||||
}
|
||||
else if( ny >= G4int(fNoVoxelY) )
|
||||
{
|
||||
ny = fNoVoxelY-1;
|
||||
isOK = false;
|
||||
}
|
||||
if( nz < 0 )
|
||||
{
|
||||
nz = 0;
|
||||
isOK = false;
|
||||
}
|
||||
else if( nz >= G4int(fNoVoxelZ) )
|
||||
{
|
||||
nz = fNoVoxelZ-1;
|
||||
isOK = false;
|
||||
}
|
||||
if( !isOK )
|
||||
{
|
||||
G4cerr << "WARNING - G4PhantomParameterisation::GetReplicaNo()" << G4endl
|
||||
<< " LocalPoint: " << localPoint << G4endl
|
||||
<< " LocalDir: " << localDir << G4endl
|
||||
<< " Voxel container size: " << fContainerWallX
|
||||
<< " " << fContainerWallY << " " << fContainerWallZ << G4endl
|
||||
<< " LocalPoint - wall: "
|
||||
<< localPoint.x()-fContainerWallX << " "
|
||||
<< localPoint.y()-fContainerWallY << " "
|
||||
<< localPoint.z()-fContainerWallZ << G4endl;
|
||||
G4Exception("G4PhantomParameterisation::GetReplicaNo()",
|
||||
"Wrong-copy-number", JustWarning,
|
||||
"Corrected the copy number! It was negative or too big");
|
||||
copyNo = nx + fNoVoxelX*ny + fNoVoxelXY*nz;
|
||||
}
|
||||
|
||||
CheckCopyNo( copyNo ); // not needed, just for debugging code
|
||||
// CheckCopyNo( copyNo ); // not needed, just for debugging code
|
||||
|
||||
return copyNo;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4PropagatorInField.cc,v 1.40 2007/11/16 09:39:14 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
//
|
||||
//
|
||||
// This class implements an algorithm to track a particle in a
|
||||
@@ -49,13 +47,15 @@
|
||||
#include "G4GeometryTolerance.hh"
|
||||
#include "G4VCurvedTrajectoryFilter.hh"
|
||||
#include "G4ChordFinder.hh"
|
||||
#include "G4MultiLevelLocator.hh"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constructors and destructor
|
||||
|
||||
G4PropagatorInField::G4PropagatorInField( G4Navigator *theNavigator,
|
||||
G4FieldManager *detectorFieldMgr )
|
||||
G4FieldManager *detectorFieldMgr,
|
||||
G4VIntersectionLocator *vLocator )
|
||||
: fDetectorFieldMgr(detectorFieldMgr),
|
||||
fCurrentFieldMgr(detectorFieldMgr),
|
||||
fNavigator(theNavigator),
|
||||
@@ -83,23 +83,23 @@ G4PropagatorInField::G4PropagatorInField( G4Navigator *theNavigator,
|
||||
fPreviousSafety= 0.0;
|
||||
kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
||||
|
||||
// In case of too slow progress in finding Intersection Point
|
||||
// intermediates Points on the Track must be stored.
|
||||
// Initialise the array of Pointers [max_depth+1] to do this
|
||||
|
||||
G4ThreeVector zeroV(0.0,0.0,0.0);
|
||||
for (G4int idepth=0; idepth<max_depth+1; idepth++ )
|
||||
{
|
||||
ptrInterMedFT[ idepth ] = new G4FieldTrack( zeroV, zeroV, 0., 0., 0., 0.);
|
||||
// Definding Intersection Locator and his parameters
|
||||
if(vLocator==0){
|
||||
fIntersectionLocator= new G4MultiLevelLocator(theNavigator);
|
||||
fAllocatedLocator=true;
|
||||
}else{
|
||||
fIntersectionLocator=vLocator;
|
||||
fAllocatedLocator=false;
|
||||
}
|
||||
fIntersectionLocator->SetEpsilonStepFor(fEpsilonStep);
|
||||
fIntersectionLocator->SetDeltaIntersectionFor(GetDeltaIntersection());
|
||||
fIntersectionLocator->SetChordFinderFor(GetChordFinder());
|
||||
fIntersectionLocator->SetSafetyParametersFor( fUseSafetyForOptimisation);
|
||||
}
|
||||
|
||||
G4PropagatorInField::~G4PropagatorInField()
|
||||
{
|
||||
for ( G4int idepth=0; idepth<max_depth+1; idepth++)
|
||||
{
|
||||
delete ptrInterMedFT[idepth];
|
||||
}
|
||||
if(fAllocatedLocator)delete fIntersectionLocator;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@@ -113,6 +113,7 @@ G4PropagatorInField::ComputeStep(
|
||||
G4double& currentSafety, // IN/OUT
|
||||
G4VPhysicalVolume* pPhysVol)
|
||||
{
|
||||
|
||||
// If CurrentProposedStepLength is too small for finding Chords
|
||||
// then return with no action (for now - TODO: some action)
|
||||
//
|
||||
@@ -148,7 +149,14 @@ G4PropagatorInField::ComputeStep(
|
||||
// For the next call, the field manager must again be set
|
||||
fSetFieldMgr= false;
|
||||
|
||||
GetChordFinder()->SetChargeMomentumMass(fCharge, fInitialMomentumModulus, fMass);
|
||||
GetChordFinder()->SetChargeMomentumMass(fCharge, fInitialMomentumModulus, fMass);
|
||||
|
||||
// Values for Intersection Locator has to be updated on each call
|
||||
// because the CurrentFieldManager changes
|
||||
fIntersectionLocator->SetChordFinderFor(GetChordFinder());
|
||||
fIntersectionLocator->SetSafetyParametersFor( fUseSafetyForOptimisation);
|
||||
fIntersectionLocator->SetEpsilonStepFor(fEpsilonStep);
|
||||
fIntersectionLocator->SetDeltaIntersectionFor(GetDeltaIntersection());
|
||||
|
||||
G4FieldTrack CurrentState(pFieldTrack);
|
||||
G4FieldTrack OriginalState = CurrentState;
|
||||
@@ -286,11 +294,11 @@ G4PropagatorInField::ComputeStep(
|
||||
// Find the intersection point of AB true path with the surface
|
||||
// of vol(A), if it exists. Start with point E as first "estimate".
|
||||
G4bool recalculatedEndPt= false;
|
||||
G4bool found_intersection =
|
||||
LocateIntersectionPoint( SubStepStartState, CurrentState,
|
||||
|
||||
G4bool found_intersection = fIntersectionLocator->
|
||||
EstimateIntersectionPoint( SubStepStartState, CurrentState,
|
||||
InterSectionPointE, IntersectPointVelct_G,
|
||||
recalculatedEndPt);
|
||||
//G4cout<<"In Locate"<<recalculatedEndPt<<" and V"<<IntersectPointVelct_G.GetPosition()<<G4endl;
|
||||
recalculatedEndPt,fPreviousSafety,fPreviousSftOrigin);
|
||||
intersects = intersects && found_intersection;
|
||||
if( found_intersection ) {
|
||||
End_PointAndTangent= IntersectPointVelct_G; // G is our EndPoint ...
|
||||
@@ -404,576 +412,22 @@ G4PropagatorInField::ComputeStep(
|
||||
G4cout << " WARNING - G4PropagatorInField::ComputeStep():" << G4endl
|
||||
<< " Zero progress for " << fNoZeroStep << " attempted steps."
|
||||
<< G4endl;
|
||||
G4cout << "Proposed Step is "<<CurrentProposedStepLength <<" but Step Taken is "<< fFull_CurveLen_of_LastAttempt <<G4endl;
|
||||
G4cout << "For Particle with Charge ="<<fCharge
|
||||
<< " Momentum="<< fInitialMomentumModulus<<" Mass="<< fMass<<G4endl;
|
||||
if( pPhysVol )
|
||||
G4cout << " in the volume " << pPhysVol->GetName() ;
|
||||
else
|
||||
G4cout << " in unknown or null volume. " ;
|
||||
G4cout << G4endl;
|
||||
if ( fVerboseLevel > 2 )
|
||||
G4cout << " Particle that is stuck will be killed." << G4endl;
|
||||
fNoZeroStep = 0;
|
||||
}
|
||||
// G4cout << "G4PropagatorInField returns " << TruePathLength << G4endl;
|
||||
|
||||
return TruePathLength;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// G4bool
|
||||
// G4PropagatorInField::LocateIntersectionPoint(
|
||||
// const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
// const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
// const G4ThreeVector& TrialPoint, // E
|
||||
// G4FieldTrack& IntersectedOrRecalculated // Output
|
||||
// G4bool& recalculated) // Out
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Function that returns the intersection of the true path with the surface
|
||||
// of the current volume (either the external one or the inner one with one
|
||||
// of the daughters
|
||||
//
|
||||
// A = Initial point
|
||||
// B = another point
|
||||
//
|
||||
// Both A and B are assumed to be on the true path.
|
||||
//
|
||||
// E is the first point of intersection of the chord AB with
|
||||
// a volume other than A (on the surface of A or of a daughter)
|
||||
//
|
||||
// Convention of Use :
|
||||
// i) If it returns "true", then IntersectionPointVelocity is set
|
||||
// to the approximate intersection point.
|
||||
// ii) If it returns "false", no intersection was found.
|
||||
// The validity of IntersectedOrRecalculated depends on 'recalculated'
|
||||
// a) if latter is false, then IntersectedOrRecalculated is invalid.
|
||||
// b) if latter is true, then IntersectedOrRecalculated is
|
||||
// the new endpoint, due to a re-integration.
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
G4bool
|
||||
G4PropagatorInField::LocateIntersectionPoint(
|
||||
const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
const G4ThreeVector& TrialPoint, // E
|
||||
G4FieldTrack& IntersectedOrRecalculatedFT, // Out: point found
|
||||
G4bool& recalculatedEndPoint) // Out:
|
||||
{
|
||||
// Find Intersection Point ( A, B, E ) of true path AB - start at E.
|
||||
|
||||
G4bool found_approximate_intersection = false;
|
||||
G4bool there_is_no_intersection = false;
|
||||
|
||||
G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
|
||||
G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
G4ThreeVector CurrentE_Point = TrialPoint;
|
||||
G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity); // FT-Def-Construct
|
||||
G4double NewSafety= -0.0;
|
||||
|
||||
G4bool final_section= true; // Shows whether current section is last
|
||||
// (i.e. B=full end)
|
||||
G4bool first_section=true;
|
||||
recalculatedEndPoint= false;
|
||||
|
||||
G4bool restoredFullEndpoint= false;
|
||||
|
||||
G4int substep_no = 0;
|
||||
|
||||
// Limits for substep number
|
||||
//
|
||||
const G4int max_substeps= 10000; // Test 120 (old value 100 )
|
||||
const G4int warn_substeps= 1000; // 100
|
||||
|
||||
// Statistics for substeps
|
||||
//
|
||||
static G4int max_no_seen= -1;
|
||||
static G4int trigger_substepno_print= warn_substeps - 20 ;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Algoritm for the case if progress in founding intersection is too slow.
|
||||
// Process is defined too slow if after N=param_substeps advances on the
|
||||
// path, it will be only 'fraction_done' of the total length.
|
||||
// In this case the remaining length is divided in two half and
|
||||
// the loop is restarted for each half.
|
||||
// If progress is still too slow, the division in two halfs continue
|
||||
// until 'max_depth'.
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
const G4int param_substeps=10; // Test value for the maximum number
|
||||
// of substeps
|
||||
const G4double fraction_done=0.3;
|
||||
|
||||
G4bool Second_half=false; // First half or second half of divided step
|
||||
|
||||
// We need to know this for the 'final_section':
|
||||
// real 'final_section' or first half 'final_section'
|
||||
// In algorithm it is considered that the 'Second_half' is true
|
||||
// and it becomes false only if we are in the first-half of level
|
||||
// depthness or if we are in the first section
|
||||
|
||||
G4int depth=0; // Depth counts how many subdivisions of initial step made
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
static G4double tolerance= 1.0e-8;
|
||||
G4ThreeVector StartPosition= CurveStartPointVelocity.GetPosition();
|
||||
if( (TrialPoint - StartPosition).mag() < tolerance * mm )
|
||||
{
|
||||
G4cerr << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is on top of starting point A."
|
||||
<< G4endl;
|
||||
G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
|
||||
"IntersectionPointIsAtStart", JustWarning,
|
||||
"Intersection point F is exactly at start point A." );
|
||||
}
|
||||
#endif
|
||||
|
||||
// Intermediates Points on the Track = Subdivided Points must be stored.
|
||||
// Give the initial values to 'InterMedFt'
|
||||
// Important is 'ptrInterMedFT[0]', it saves the 'EndCurvePoint'
|
||||
//
|
||||
*ptrInterMedFT[0] = CurveEndPointVelocity;
|
||||
for (G4int idepth=1; idepth<max_depth+1; idepth++ )
|
||||
{
|
||||
*ptrInterMedFT[idepth]=CurveStartPointVelocity;
|
||||
}
|
||||
|
||||
// 'SubStartPoint' is needed to calculate the length of the divided step
|
||||
//
|
||||
G4FieldTrack SubStart_PointVelocity = CurveStartPointVelocity;
|
||||
|
||||
do
|
||||
{
|
||||
G4int substep_no_p = 0;
|
||||
G4bool sub_final_section = false; // the same as final_section,
|
||||
// but for 'sub_section'
|
||||
do // REPEAT param
|
||||
{
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector Point_B = CurrentB_PointVelocity.GetPosition();
|
||||
|
||||
// F = a point on true AB path close to point E
|
||||
// (the closest if possible)
|
||||
//
|
||||
ApproxIntersecPointV = GetChordFinder()
|
||||
->ApproxCurvePointV( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
CurrentE_Point,
|
||||
fEpsilonStep );
|
||||
// The above method is the key & most intuitive part ...
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
if( ApproxIntersecPointV.GetCurveLength() >
|
||||
CurrentB_PointVelocity.GetCurveLength() * (1.0 + tolerance) )
|
||||
{
|
||||
G4cerr << "ERROR - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is more advanced than"
|
||||
<< " endpoint B." << G4endl;
|
||||
G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
|
||||
"IntermediatePointConfusion", FatalException,
|
||||
"Intermediate F point is past end B point" );
|
||||
}
|
||||
#endif
|
||||
|
||||
G4ThreeVector CurrentF_Point= ApproxIntersecPointV.GetPosition();
|
||||
|
||||
// First check whether EF is small - then F is a good approx. point
|
||||
// Calculate the length and direction of the chord AF
|
||||
//
|
||||
G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
|
||||
|
||||
if ( ChordEF_Vector.mag2() <= sqr(GetDeltaIntersection()) )
|
||||
{
|
||||
found_approximate_intersection = true;
|
||||
|
||||
// Create the "point" return value
|
||||
//
|
||||
IntersectedOrRecalculatedFT = ApproxIntersecPointV;
|
||||
IntersectedOrRecalculatedFT.SetPosition( CurrentE_Point );
|
||||
|
||||
// Note: in order to return a point on the boundary,
|
||||
// we must return E. But it is F on the curve.
|
||||
// So we must "cheat": we are using the position at point E
|
||||
// and the velocity at point F !!!
|
||||
//
|
||||
// This must limit the length we can allow for displacement!
|
||||
}
|
||||
else // E is NOT close enough to the curve (ie point F)
|
||||
{
|
||||
// Check whether any volumes are encountered by the chord AF
|
||||
// ---------------------------------------------------------
|
||||
// First relocate to restore any Voxel etc information
|
||||
// in the Navigator before calling ComputeStep()
|
||||
//
|
||||
fNavigator->LocateGlobalPointWithinVolume( Point_A );
|
||||
|
||||
G4ThreeVector PointG; // Candidate intersection point
|
||||
G4double stepLengthAF;
|
||||
G4bool Intersects_AF = IntersectChord( Point_A, CurrentF_Point,
|
||||
NewSafety, stepLengthAF,
|
||||
PointG );
|
||||
if( Intersects_AF )
|
||||
{
|
||||
// G is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
// B <- F
|
||||
// E <- G
|
||||
|
||||
CurrentB_PointVelocity = ApproxIntersecPointV;
|
||||
CurrentE_Point = PointG;
|
||||
|
||||
// By moving point B, must take care if current
|
||||
// AF has no intersection to try current FB!!
|
||||
//
|
||||
final_section= false;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if( fVerboseLevel > 3 )
|
||||
{
|
||||
G4cout << "G4PiF::LI> Investigating intermediate point"
|
||||
<< " at s=" << ApproxIntersecPointV.GetCurveLength()
|
||||
<< " on way to full s="
|
||||
<< CurveEndPointVelocity.GetCurveLength() << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else // not Intersects_AF
|
||||
{
|
||||
// In this case:
|
||||
// There is NO intersection of AF with a volume boundary.
|
||||
// We must continue the search in the segment FB!
|
||||
//
|
||||
fNavigator->LocateGlobalPointWithinVolume( CurrentF_Point );
|
||||
|
||||
G4double stepLengthFB;
|
||||
G4ThreeVector PointH;
|
||||
|
||||
// Check whether any volumes are encountered by the chord FB
|
||||
// ---------------------------------------------------------
|
||||
|
||||
G4bool Intersects_FB = IntersectChord( CurrentF_Point, Point_B,
|
||||
NewSafety, stepLengthFB,
|
||||
PointH );
|
||||
if( Intersects_FB )
|
||||
{
|
||||
// There is an intersection of FB with a volume boundary
|
||||
// H <- First Intersection of Chord FB
|
||||
|
||||
// H is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
|
||||
// Note that F must be in volume volA (the same as A)
|
||||
// (otherwise AF would meet a volume boundary!)
|
||||
// A <- F
|
||||
// E <- H
|
||||
|
||||
CurrentA_PointVelocity = ApproxIntersecPointV;
|
||||
CurrentE_Point = PointH;
|
||||
}
|
||||
else // not Intersects_FB
|
||||
{
|
||||
// There is NO intersection of FB with a volume boundary
|
||||
|
||||
if( final_section )
|
||||
{
|
||||
// If B is the original endpoint, this means that whatever
|
||||
// volume(s) intersected the original chord, none touch the
|
||||
// smaller chords we have used.
|
||||
// The value of 'IntersectedOrRecalculatedFT' returned is
|
||||
// likely not valid
|
||||
|
||||
// Check on real final_section or SubEndSection
|
||||
//
|
||||
if( ((Second_half)&&(depth==0)) || (first_section) )
|
||||
{
|
||||
there_is_no_intersection = true; // real final_section
|
||||
}
|
||||
else
|
||||
{
|
||||
// end of subsection, not real final section
|
||||
// exit from the and go to the depth-1 level
|
||||
|
||||
substep_no_p = param_substeps+2; // exit from the loop
|
||||
|
||||
// but 'Second_half' is still true because we need to find
|
||||
// the 'CurrentE_point' for the next loop
|
||||
//
|
||||
Second_half = true;
|
||||
sub_final_section = true;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// We must restore the original endpoint
|
||||
|
||||
CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B
|
||||
CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
restoredFullEndpoint = true;
|
||||
}
|
||||
} // Endif (Intersects_FB)
|
||||
} // Endif (Intersects_AF)
|
||||
|
||||
// Ensure that the new endpoints are not further apart in space
|
||||
// than on the curve due to different errors in the integration
|
||||
//
|
||||
G4double linDistSq, curveDist;
|
||||
linDistSq = ( CurrentB_PointVelocity.GetPosition()
|
||||
- CurrentA_PointVelocity.GetPosition() ).mag2();
|
||||
curveDist = CurrentB_PointVelocity.GetCurveLength()
|
||||
- CurrentA_PointVelocity.GetCurveLength();
|
||||
if( curveDist*(curveDist+2*perMillion ) < linDistSq )
|
||||
{
|
||||
// Re-integrate to obtain a new B
|
||||
//
|
||||
G4FieldTrack newEndPointFT=
|
||||
ReEstimateEndpoint( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
linDistSq, // to avoid recalculation
|
||||
curveDist );
|
||||
G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
|
||||
CurrentB_PointVelocity = newEndPointFT;
|
||||
|
||||
if( (final_section)&&(Second_half)&&(depth==0) ) // real final section
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
IntersectedOrRecalculatedFT = newEndPointFT;
|
||||
// So that we can return it, if it is the endpoint!
|
||||
}
|
||||
}
|
||||
if( curveDist < 0.0 )
|
||||
{
|
||||
G4cerr << "ERROR - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Error in advancing propagation." << G4endl;
|
||||
fVerboseLevel = 5; // Print out a maximum of information
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no, 0 );
|
||||
G4cerr << " Point A (start) is " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (end) is " << CurrentB_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Curve distance is " << curveDist << G4endl;
|
||||
G4cerr << G4endl
|
||||
<< "The final curve point is not further along"
|
||||
<< " than the original!" << G4endl;
|
||||
G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
|
||||
"FatalError", FatalException,
|
||||
"Error in advancing propagation.");
|
||||
}
|
||||
|
||||
if(restoredFullEndpoint)
|
||||
{
|
||||
final_section = restoredFullEndpoint;
|
||||
restoredFullEndpoint = false;
|
||||
}
|
||||
} // EndIf ( E is close enough to the curve, ie point F. )
|
||||
// tests ChordAF_Vector.mag() <= maximum_lateral_displacement
|
||||
|
||||
#ifdef G4DEBUG_LOCATE_INTERSECTION
|
||||
if( substep_no >= trigger_substepno_print )
|
||||
{
|
||||
G4cout << "Difficulty in converging in "
|
||||
<< "G4PropagatorInField::LocateIntersectionPoint():"
|
||||
<< G4endl
|
||||
<< " Substep no = " << substep_no << G4endl;
|
||||
if( substep_no == trigger_substepno_print )
|
||||
{
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0, 0);
|
||||
}
|
||||
G4cout << " State of point A: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1, 0);
|
||||
G4cout << " State of point B: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
substep_no++;
|
||||
substep_no_p++;
|
||||
|
||||
} while ( ( ! found_approximate_intersection )
|
||||
&& ( ! there_is_no_intersection )
|
||||
&& ( substep_no_p <= param_substeps) ); // UNTIL found or
|
||||
// failed param substep
|
||||
first_section = false;
|
||||
|
||||
if( (!found_approximate_intersection) && (!there_is_no_intersection) )
|
||||
{
|
||||
G4double did_len = std::abs( CurrentA_PointVelocity.GetCurveLength()
|
||||
- SubStart_PointVelocity.GetCurveLength());
|
||||
G4double all_len = std::abs( CurrentB_PointVelocity.GetCurveLength()
|
||||
- SubStart_PointVelocity.GetCurveLength());
|
||||
|
||||
G4double stepLengthAB;
|
||||
G4ThreeVector PointGe;
|
||||
|
||||
// Check if progress is too slow and if it possible to go deeper,
|
||||
// then halve the step if so
|
||||
//
|
||||
if( ( ( did_len )<fraction_done*all_len)
|
||||
&& (depth<max_depth) && (!sub_final_section) )
|
||||
{
|
||||
|
||||
Second_half=false;
|
||||
depth++;
|
||||
|
||||
G4double Sub_len = (all_len-did_len)/(2.);
|
||||
G4FieldTrack start = CurrentA_PointVelocity;
|
||||
G4MagInt_Driver* integrDriver=GetChordFinder()->GetIntegrationDriver();
|
||||
integrDriver->AccurateAdvance(start, Sub_len, fEpsilonStep);
|
||||
*ptrInterMedFT[depth] = start;
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth];
|
||||
|
||||
// Adjust 'SubStartPoint' to calculate the 'did_length' in next loop
|
||||
//
|
||||
SubStart_PointVelocity = CurrentA_PointVelocity;
|
||||
|
||||
// Find new trial intersection point needed at start of the loop
|
||||
//
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();
|
||||
|
||||
fNavigator->LocateGlobalPointWithinVolume(Point_A);
|
||||
G4bool Intersects_AB = IntersectChord(Point_A, SubE_point,
|
||||
NewSafety, stepLengthAB, PointGe);
|
||||
if(Intersects_AB)
|
||||
{
|
||||
CurrentE_Point = PointGe;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No intersection found for first part of curve
|
||||
// (CurrentA,InterMedPoint[depth]). Go to the second part
|
||||
//
|
||||
Second_half = true;
|
||||
}
|
||||
} // if did_len
|
||||
|
||||
if( (Second_half)&&(depth!=0) )
|
||||
{
|
||||
// Second part of curve (InterMed[depth],Intermed[depth-1]) )
|
||||
// On the depth-1 level normally we are on the 'second_half'
|
||||
|
||||
Second_half = true;
|
||||
|
||||
// Find new trial intersection point needed at start of the loop
|
||||
//
|
||||
SubStart_PointVelocity = *ptrInterMedFT[depth];
|
||||
CurrentA_PointVelocity = *ptrInterMedFT[depth];
|
||||
CurrentB_PointVelocity = *ptrInterMedFT[depth-1];
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector SubE_point = CurrentB_PointVelocity.GetPosition();
|
||||
fNavigator->LocateGlobalPointWithinVolume(Point_A);
|
||||
G4bool Intersects_AB = IntersectChord(Point_A, SubE_point, NewSafety,
|
||||
stepLengthAB, PointGe);
|
||||
if(Intersects_AB)
|
||||
{
|
||||
CurrentE_Point = PointGe;
|
||||
}
|
||||
else
|
||||
{
|
||||
final_section = true;
|
||||
}
|
||||
depth--;
|
||||
}
|
||||
} // if(!found_aproximate_intersection)
|
||||
|
||||
} while ( ( ! found_approximate_intersection )
|
||||
&& ( ! there_is_no_intersection )
|
||||
&& ( substep_no <= max_substeps) ); // UNTIL found or failed
|
||||
|
||||
if( substep_no > max_no_seen )
|
||||
{
|
||||
max_no_seen = substep_no;
|
||||
if( max_no_seen > warn_substeps )
|
||||
{
|
||||
trigger_substepno_print = max_no_seen-20; // Want to see last 20 steps
|
||||
}
|
||||
}
|
||||
|
||||
if( ( substep_no >= max_substeps)
|
||||
&& !there_is_no_intersection
|
||||
&& !found_approximate_intersection )
|
||||
{
|
||||
G4cerr << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cerr << " Abandoning effort to intersect. " << G4endl;
|
||||
G4cerr << " Information on start & current step follows in cout."
|
||||
<< G4endl;
|
||||
G4cout << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cout << " Found intersection = "
|
||||
<< found_approximate_intersection << G4endl
|
||||
<< " Intersection exists = "
|
||||
<< !there_is_no_intersection << G4endl;
|
||||
G4cout << " Start and Endpoint of Requested Step:" << G4endl;
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0, 0);
|
||||
G4cout << G4endl;
|
||||
G4cout << " 'Bracketing' starting and endpoint of current Sub-Step"
|
||||
<< G4endl;
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1, 0);
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no, 0);
|
||||
G4cout << G4endl;
|
||||
|
||||
#ifdef FUTURE_CORRECTION
|
||||
// Attempt to correct the results of the method // FIX - TODO
|
||||
|
||||
if ( ! found_approximate_intersection )
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
// Return the further valid intersection point -- potentially A ??
|
||||
// JA/19 Jan 2006
|
||||
IntersectedOrRecalculatedFT = CurrentA_PointVelocity;
|
||||
|
||||
G4cout << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Did not convergence after " << substep_no
|
||||
<< " substeps." << G4endl;
|
||||
G4cout << " The endpoint was adjused to pointA resulting"
|
||||
<< G4endl
|
||||
<< " from the last substep: " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
G4cout.precision( 10 );
|
||||
G4double done_len = CurrentA_PointVelocity.GetCurveLength();
|
||||
G4double full_len = CurveEndPointVelocity.GetCurveLength();
|
||||
G4cout << "ERROR - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken only length: " << done_len
|
||||
<< " out of " << full_len << " required." << G4endl;
|
||||
G4cout << " Remaining length = " << full_len - done_len << G4endl;
|
||||
|
||||
G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
|
||||
"UnableToLocateIntersection", FatalException,
|
||||
"Too many substeps while trying to locate intersection.");
|
||||
}
|
||||
else if( substep_no >= warn_substeps )
|
||||
{
|
||||
int oldprc= G4cout.precision( 10 );
|
||||
G4cout << "WARNING - G4PropagatorInField::LocateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken length: "
|
||||
<< CurrentB_PointVelocity.GetCurveLength();
|
||||
G4cout << " - Needed: " << substep_no << " substeps." << G4endl
|
||||
<< " Warning level = " << warn_substeps
|
||||
<< " and maximum substeps = " << max_substeps << G4endl;
|
||||
G4Exception("G4PropagatorInField::LocateIntersectionPoint()",
|
||||
"DifficultyToLocateIntersection", JustWarning,
|
||||
"Many substeps while trying to locate intersection.");
|
||||
G4cout.precision( oldprc );
|
||||
}
|
||||
|
||||
return !there_is_no_intersection; // Success or failure
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dumps status of propagator.
|
||||
@@ -1106,216 +560,6 @@ G4PropagatorInField::PrintStepLengthDiagnostic(
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
G4bool
|
||||
G4PropagatorInField::IntersectChord( G4ThreeVector StartPointA,
|
||||
G4ThreeVector EndPointB,
|
||||
G4double &NewSafety,
|
||||
G4double &LinearStepLength,
|
||||
G4ThreeVector &IntersectionPoint
|
||||
)
|
||||
{
|
||||
// Calculate the direction and length of the chord AB
|
||||
G4ThreeVector ChordAB_Vector = EndPointB - StartPointA;
|
||||
G4double ChordAB_Length = ChordAB_Vector.mag(); // Magnitude (norm)
|
||||
G4ThreeVector ChordAB_Dir = ChordAB_Vector.unit();
|
||||
G4bool intersects;
|
||||
|
||||
G4ThreeVector OriginShift = StartPointA - fPreviousSftOrigin ;
|
||||
G4double MagSqShift = OriginShift.mag2() ;
|
||||
G4double currentSafety;
|
||||
G4bool doCallNav= false;
|
||||
|
||||
if( MagSqShift >= sqr(fPreviousSafety) )
|
||||
{
|
||||
currentSafety = 0.0 ;
|
||||
}else{
|
||||
currentSafety = fPreviousSafety - std::sqrt(MagSqShift) ;
|
||||
}
|
||||
|
||||
if( fUseSafetyForOptimisation && (ChordAB_Length <= currentSafety) )
|
||||
{
|
||||
// The Step is guaranteed to be taken
|
||||
|
||||
LinearStepLength = ChordAB_Length;
|
||||
intersects = false;
|
||||
|
||||
NewSafety= currentSafety;
|
||||
|
||||
#if 0
|
||||
G4cout << " G4PropagatorInField does not call Navigator::ComputeStep " << G4endl ;
|
||||
G4cout << " step= " << LinearStepLength << " safety= " << NewSafety << G4endl;
|
||||
G4cout << " safety: Origin = " << fPreviousSftOrigin << " val= " << fPreviousSafety << G4endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
doCallNav= true;
|
||||
// Check whether any volumes are encountered by the chord AB
|
||||
|
||||
// G4cout << " G4PropagatorInField calling Navigator::ComputeStep " << G4endl ;
|
||||
|
||||
LinearStepLength =
|
||||
fNavigator->ComputeStep( StartPointA, ChordAB_Dir,
|
||||
ChordAB_Length, NewSafety );
|
||||
intersects = (LinearStepLength <= ChordAB_Length);
|
||||
// G4Navigator contracts to return k_infinity if len==asked
|
||||
// and it did not find a surface boundary at that length
|
||||
LinearStepLength = std::min( LinearStepLength, ChordAB_Length);
|
||||
|
||||
// G4cout << " G4PiF got step= " << LinearStepLength << " safety= " << NewSafety << G4endl;
|
||||
|
||||
// Save the last calculated safety!
|
||||
fPreviousSftOrigin = StartPointA;
|
||||
fPreviousSafety= NewSafety;
|
||||
|
||||
if( intersects ){
|
||||
// Intersection Point of chord AB and either volume A's surface
|
||||
// or a daughter volume's surface ..
|
||||
IntersectionPoint = StartPointA + LinearStepLength * ChordAB_Dir;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_INTERSECTS_CHORD
|
||||
// printIntersection(
|
||||
// StartPointA, EndPointB, LinearStepLength, IntersectionPoint, NewSafety
|
||||
|
||||
G4cout << " G4PropagatorInField::IntersectChord reports " << G4endl;
|
||||
G4cout << " PiF-IC> "
|
||||
<< "Start=" << std::setw(12) << StartPointA << " "
|
||||
<< "End= " << std::setw(8) << EndPointB << " "
|
||||
<< "StepIn=" << std::setw(8) << LinearStepLength << " "
|
||||
<< "NewSft=" << std::setw(8) << NewSafety << " "
|
||||
<< "CallNav=" << doCallNav << " "
|
||||
<< "Intersects " << intersects << " ";
|
||||
if( intersects )
|
||||
G4cout << "IntrPt=" << std::setw(8) << IntersectionPoint << " " ;
|
||||
G4cout << G4endl;
|
||||
#endif
|
||||
|
||||
return intersects;
|
||||
}
|
||||
|
||||
// --------------------- oooo000000000000oooo ----------------------------
|
||||
|
||||
G4FieldTrack G4PropagatorInField::
|
||||
ReEstimateEndpoint( const G4FieldTrack &CurrentStateA,
|
||||
const G4FieldTrack &EstimatedEndStateB,
|
||||
G4double linearDistSq,
|
||||
G4double curveDist
|
||||
)
|
||||
{
|
||||
// G4double checkCurveDist= EstimatedEndStateB.GetCurveLength()
|
||||
// - CurrentStateA.GetCurveLength();
|
||||
// G4double checkLinDistSq= (EstimatedEndStateB.GetPosition()
|
||||
// - CurrentStateA.GetPosition() ).mag2();
|
||||
|
||||
G4FieldTrack newEndPoint( CurrentStateA );
|
||||
G4MagInt_Driver* integrDriver= GetChordFinder()->GetIntegrationDriver();
|
||||
|
||||
G4FieldTrack retEndPoint( CurrentStateA );
|
||||
G4bool goodAdvance;
|
||||
G4int itrial=0;
|
||||
const G4int no_trials= 20;
|
||||
|
||||
G4double endCurveLen= EstimatedEndStateB.GetCurveLength();
|
||||
do
|
||||
{
|
||||
G4double currentCurveLen= newEndPoint.GetCurveLength();
|
||||
G4double advanceLength= endCurveLen - currentCurveLen ;
|
||||
if (std::abs(advanceLength)<kCarTolerance)
|
||||
{
|
||||
advanceLength=(EstimatedEndStateB.GetPosition()
|
||||
-newEndPoint.GetPosition()).mag();
|
||||
}
|
||||
goodAdvance=
|
||||
integrDriver->AccurateAdvance(newEndPoint, advanceLength, fEpsilonStep);
|
||||
// ***************
|
||||
}
|
||||
while( !goodAdvance && (++itrial < no_trials) );
|
||||
|
||||
if( goodAdvance )
|
||||
{
|
||||
retEndPoint= newEndPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
retEndPoint= EstimatedEndStateB; // Could not improve without major work !!
|
||||
}
|
||||
|
||||
// All the work is done
|
||||
// below are some diagnostics only -- before the return!
|
||||
//
|
||||
static const G4String MethodName("G4PropagatorInField::ReEstimateEndpoint");
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
G4int latest_good_trials=0;
|
||||
if( itrial > 1)
|
||||
{
|
||||
if( fVerboseLevel > 0 )
|
||||
{
|
||||
G4cout << MethodName << " called - goodAdv= " << goodAdvance
|
||||
<< " trials = " << itrial
|
||||
<< " previous good= " << latest_good_trials
|
||||
<< G4endl;
|
||||
}
|
||||
latest_good_trials=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
latest_good_trials++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
G4double lengthDone = newEndPoint.GetCurveLength()
|
||||
- CurrentStateA.GetCurveLength();
|
||||
if( !goodAdvance )
|
||||
{
|
||||
if( fVerboseLevel >= 3 )
|
||||
{
|
||||
G4cout << MethodName << "> AccurateAdvance failed " ;
|
||||
G4cout << " in " << itrial << " integration trials/steps. " << G4endl;
|
||||
G4cout << " It went only " << lengthDone << " instead of " << curveDist
|
||||
<< " -- a difference of " << curveDist - lengthDone << G4endl;
|
||||
G4cout << " ReEstimateEndpoint> Reset endPoint to original value!"
|
||||
<< G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
static G4int noInaccuracyWarnings = 0;
|
||||
G4int maxNoWarnings = 10;
|
||||
if ( (noInaccuracyWarnings < maxNoWarnings )
|
||||
|| (fVerboseLevel > 1) )
|
||||
{
|
||||
G4cerr << "G4PropagatorInField::LocateIntersectionPoint():"
|
||||
<< G4endl
|
||||
<< " Warning: Integration inaccuracy requires"
|
||||
<< " an adjustment in the step's endpoint." << G4endl
|
||||
<< " Two mid-points are further apart than their"
|
||||
<< " curve length difference" << G4endl
|
||||
<< " Dist = " << std::sqrt(linearDistSq)
|
||||
<< " curve length = " << curveDist << G4endl;
|
||||
G4cerr << " Correction applied is "
|
||||
<< (newEndPoint.GetPosition()-EstimatedEndStateB.GetPosition()).mag()
|
||||
<< G4endl;
|
||||
}
|
||||
#else
|
||||
// Statistics on the RMS value of the corrections
|
||||
|
||||
static G4int noCorrections=0;
|
||||
static G4double sumCorrectionsSq = 0;
|
||||
noCorrections++;
|
||||
if( goodAdvance )
|
||||
{
|
||||
sumCorrectionsSq += (EstimatedEndStateB.GetPosition() -
|
||||
newEndPoint.GetPosition()).mag2();
|
||||
}
|
||||
linearDistSq -= curveDist; // To use linearDistSq ... !
|
||||
#endif
|
||||
|
||||
return retEndPoint;
|
||||
}
|
||||
|
||||
// Access the points which have passed through the filter. The
|
||||
// points are stored as ThreeVectors for the initial impelmentation
|
||||
// only (jacek 30/10/2002)
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4ReplicaNavigation.cc,v 1.17 2007/11/16 09:39:14 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// $Id: G4ReplicaNavigation.cc,v 1.19 2008/04/28 15:39:55 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
//
|
||||
// class G4ReplicaNavigation Implementation
|
||||
@@ -1043,7 +1043,7 @@ G4ReplicaNavigation::BackLocate(G4NavigationHistory &history,
|
||||
motherSolid = pNRMother->GetLogicalVolume()->GetSolid();
|
||||
goodPoint = history.GetTransform(mdepth).TransformPoint(globalPoint);
|
||||
insideCode = motherSolid->Inside(goodPoint);
|
||||
if ( (insideCode==kOutside)||(insideCode==kSurface)&&exiting )
|
||||
if ( (insideCode==kOutside)||((insideCode==kSurface)&&exiting) )
|
||||
{
|
||||
// Outside mother -> back up to mother level
|
||||
// Locate.. in Navigator will back up one more level
|
||||
@@ -1065,7 +1065,7 @@ G4ReplicaNavigation::BackLocate(G4NavigationHistory &history,
|
||||
insideCode = Inside(history.GetVolume(depth),
|
||||
history.GetReplicaNo(depth),
|
||||
repPoint);
|
||||
if ( (insideCode==kOutside)||(insideCode==kSurface)&&exiting )
|
||||
if ( (insideCode==kOutside)||((insideCode==kSurface)&&exiting) )
|
||||
{
|
||||
localPoint = goodPoint;
|
||||
history.BackLevel(cdepth-depth);
|
||||
@@ -1084,7 +1084,7 @@ G4ReplicaNavigation::BackLocate(G4NavigationHistory &history,
|
||||
// of *previous* level - location code in navigator will back up one
|
||||
// level [And also manage blocking]
|
||||
//
|
||||
if ( (insideCode==kOutside)||(insideCode==kSurface)&&exiting )
|
||||
if ( (insideCode==kOutside)||((insideCode==kSurface)&&exiting) )
|
||||
{
|
||||
localPoint = goodPoint;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4SafetyHelper.cc,v 1.15 2007/11/14 10:04:21 gcosmo Exp $
|
||||
// $Id: G4SafetyHelper.cc,v 1.16 2008/10/24 14:00:03 gcosmo Exp $
|
||||
// GEANT4 tag $ Name: $
|
||||
//
|
||||
// class G4SafetyHelper Implementation
|
||||
@@ -127,12 +127,12 @@ G4double G4SafetyHelper::ComputeSafety( const G4ThreeVector& position )
|
||||
if( !fUseParallelGeometries )
|
||||
{
|
||||
// Safety for mass geometry
|
||||
fLastSafety = fpMassNavigator->ComputeSafety(position);
|
||||
fLastSafety = fpMassNavigator->ComputeSafety(position,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Safety for all geometries
|
||||
fLastSafety = fpPathFinder->ComputeSafety( position );
|
||||
fLastSafety = fpPathFinder->ComputeSafety(position);
|
||||
}
|
||||
newSafety = fLastSafety;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,483 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4SimpleLocator.cc,v 1.5 2008/12/11 10:27:58 tnikitin Exp $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// Class G4SimpleLocator implementation
|
||||
//
|
||||
// 27.10.08 - Tatiana Nikitina.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "G4ios.hh"
|
||||
#include "G4SimpleLocator.hh"
|
||||
|
||||
G4SimpleLocator::G4SimpleLocator(G4Navigator *theNavigator)
|
||||
: G4VIntersectionLocator(theNavigator)
|
||||
{
|
||||
}
|
||||
|
||||
G4SimpleLocator::~G4SimpleLocator()
|
||||
{
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// G4bool G4PropagatorInField::LocateIntersectionPoint(
|
||||
// const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
// const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
// const G4ThreeVector& TrialPoint, // E
|
||||
// G4FieldTrack& IntersectedOrRecalculated // Output
|
||||
// G4bool& recalculated ) // Out
|
||||
// --------------------------------------------------------------------------
|
||||
//
|
||||
// Function that returns the intersection of the true path with the surface
|
||||
// of the current volume (either the external one or the inner one with one
|
||||
// of the daughters:
|
||||
//
|
||||
// A = Initial point
|
||||
// B = another point
|
||||
//
|
||||
// Both A and B are assumed to be on the true path:
|
||||
//
|
||||
// E is the first point of intersection of the chord AB with
|
||||
// a volume other than A (on the surface of A or of a daughter)
|
||||
//
|
||||
// Convention of Use :
|
||||
// i) If it returns "true", then IntersectionPointVelocity is set
|
||||
// to the approximate intersection point.
|
||||
// ii) If it returns "false", no intersection was found.
|
||||
// The validity of IntersectedOrRecalculated depends on 'recalculated'
|
||||
// a) if latter is false, then IntersectedOrRecalculated is invalid.
|
||||
// b) if latter is true, then IntersectedOrRecalculated is
|
||||
// the new endpoint, due to a re-integration.
|
||||
// --------------------------------------------------------------------------
|
||||
// NOTE: implementation taken from G4PropagatorInField
|
||||
//
|
||||
G4bool G4SimpleLocator::EstimateIntersectionPoint(
|
||||
const G4FieldTrack& CurveStartPointVelocity, // A
|
||||
const G4FieldTrack& CurveEndPointVelocity, // B
|
||||
const G4ThreeVector& TrialPoint, // E
|
||||
G4FieldTrack& IntersectedOrRecalculatedFT, // Output
|
||||
G4bool& recalculatedEndPoint, // Out
|
||||
G4double &fPreviousSafety, //In/Out
|
||||
G4ThreeVector &fPreviousSftOrigin) //In/Out
|
||||
{
|
||||
// Find Intersection Point ( A, B, E ) of true path AB - start at E.
|
||||
|
||||
G4bool found_approximate_intersection = false;
|
||||
G4bool there_is_no_intersection = false;
|
||||
|
||||
G4FieldTrack CurrentA_PointVelocity = CurveStartPointVelocity;
|
||||
G4FieldTrack CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
G4ThreeVector CurrentE_Point = TrialPoint;
|
||||
G4FieldTrack ApproxIntersecPointV(CurveEndPointVelocity); // FT-Def-Construct
|
||||
G4double NewSafety = 0.0;
|
||||
G4bool last_AF_intersection = false;
|
||||
G4bool final_section = true; // Shows whether current section is last
|
||||
// (i.e. B=full end)
|
||||
recalculatedEndPoint = false;
|
||||
|
||||
G4bool restoredFullEndpoint = false;
|
||||
|
||||
G4int substep_no = 0;
|
||||
|
||||
// Limits for substep number
|
||||
//
|
||||
const G4int max_substeps = 100000000; // Test 120 (old value 100 )
|
||||
const G4int warn_substeps = 1000; // 100
|
||||
|
||||
// Statistics for substeps
|
||||
//
|
||||
static G4int max_no_seen= -1;
|
||||
static G4int trigger_substepno_print= warn_substeps - 20;
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
static G4double tolerance= 1.0e-8;
|
||||
G4ThreeVector StartPosition= CurveStartPointVelocity.GetPosition();
|
||||
if( (TrialPoint - StartPosition).mag() < tolerance * mm )
|
||||
{
|
||||
G4cerr << "WARNING - G4SimpleLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is on top of starting point A."
|
||||
<< G4endl;
|
||||
G4Exception("G4SimpleLocator::EstimateIntersectionPoint()",
|
||||
"IntersectionPointIsAtStart", JustWarning,
|
||||
"Intersection point F is exactly at start point A." );
|
||||
}
|
||||
#endif
|
||||
|
||||
do
|
||||
{
|
||||
G4ThreeVector Point_A = CurrentA_PointVelocity.GetPosition();
|
||||
G4ThreeVector Point_B = CurrentB_PointVelocity.GetPosition();
|
||||
|
||||
// F = a point on true AB path close to point E
|
||||
// (the closest if possible)
|
||||
//
|
||||
ApproxIntersecPointV = GetChordFinderFor()
|
||||
->ApproxCurvePointV( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
CurrentE_Point,
|
||||
GetEpsilonStepFor());
|
||||
// The above method is the key & most intuitive part ...
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
if( ApproxIntersecPointV.GetCurveLength() >
|
||||
CurrentB_PointVelocity.GetCurveLength() * (1.0 + tolerance) )
|
||||
{
|
||||
G4cerr << "ERROR - G4SimpleLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Intermediate F point is more advanced than"
|
||||
<< " endpoint B." << G4endl;
|
||||
G4Exception("G4SimpleLocator::EstimateIntersectionPoint()",
|
||||
"IntermediatePointConfusion", FatalException,
|
||||
"Intermediate F point is past end B point" );
|
||||
}
|
||||
#endif
|
||||
|
||||
G4ThreeVector CurrentF_Point= ApproxIntersecPointV.GetPosition();
|
||||
|
||||
// First check whether EF is small - then F is a good approx. point
|
||||
// Calculate the length and direction of the chord AF
|
||||
//
|
||||
G4ThreeVector ChordEF_Vector = CurrentF_Point - CurrentE_Point;
|
||||
|
||||
if ( ChordEF_Vector.mag2() <= sqr(GetDeltaIntersectionFor()) )
|
||||
{
|
||||
found_approximate_intersection = true;
|
||||
|
||||
// Create the "point" return value
|
||||
//
|
||||
|
||||
IntersectedOrRecalculatedFT = ApproxIntersecPointV;
|
||||
IntersectedOrRecalculatedFT.SetPosition( CurrentE_Point );
|
||||
|
||||
if ( GetAdjustementOfFoundIntersection() )
|
||||
{
|
||||
// Try to Get Correction of IntersectionPoint using SurfaceNormal()
|
||||
//
|
||||
G4ThreeVector IP;
|
||||
G4ThreeVector MomentumDir= ApproxIntersecPointV.GetMomentumDirection();
|
||||
G4bool goodCorrection = AdjustmentOfFoundIntersection( Point_A,
|
||||
CurrentE_Point, CurrentF_Point, MomentumDir,
|
||||
last_AF_intersection, IP, NewSafety,
|
||||
fPreviousSafety, fPreviousSftOrigin );
|
||||
|
||||
if(goodCorrection)
|
||||
{
|
||||
IntersectedOrRecalculatedFT = ApproxIntersecPointV;
|
||||
IntersectedOrRecalculatedFT.SetPosition(IP);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: in order to return a point on the boundary,
|
||||
// we must return E. But it is F on the curve.
|
||||
// So we must "cheat": we are using the position at point E
|
||||
// and the velocity at point F !!!
|
||||
//
|
||||
// This must limit the length we can allow for displacement!
|
||||
}
|
||||
else // E is NOT close enough to the curve (ie point F)
|
||||
{
|
||||
// Check whether any volumes are encountered by the chord AF
|
||||
// ---------------------------------------------------------
|
||||
// First relocate to restore any Voxel etc information
|
||||
// in the Navigator before calling ComputeStep()
|
||||
//
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume( Point_A );
|
||||
|
||||
G4ThreeVector PointG; // Candidate intersection point
|
||||
G4double stepLengthAF;
|
||||
G4bool Intersects_AF = IntersectChord( Point_A, CurrentF_Point,
|
||||
NewSafety,fPreviousSafety,
|
||||
fPreviousSftOrigin,
|
||||
stepLengthAF,
|
||||
PointG );
|
||||
last_AF_intersection = Intersects_AF;
|
||||
if( Intersects_AF )
|
||||
{
|
||||
// G is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
// B <- F
|
||||
// E <- G
|
||||
|
||||
CurrentB_PointVelocity = ApproxIntersecPointV;
|
||||
CurrentE_Point = PointG;
|
||||
|
||||
// By moving point B, must take care if current
|
||||
// AF has no intersection to try current FB!!
|
||||
//
|
||||
final_section= false;
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
if( fVerboseLevel > 3 )
|
||||
{
|
||||
G4cout << "G4PiF::LI> Investigating intermediate point"
|
||||
<< " at s=" << ApproxIntersecPointV.GetCurveLength()
|
||||
<< " on way to full s="
|
||||
<< CurveEndPointVelocity.GetCurveLength() << G4endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else // not Intersects_AF
|
||||
{
|
||||
// In this case:
|
||||
// There is NO intersection of AF with a volume boundary.
|
||||
// We must continue the search in the segment FB!
|
||||
//
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume( CurrentF_Point );
|
||||
|
||||
G4double stepLengthFB;
|
||||
G4ThreeVector PointH;
|
||||
|
||||
// Check whether any volumes are encountered by the chord FB
|
||||
// ---------------------------------------------------------
|
||||
|
||||
G4bool Intersects_FB = IntersectChord( CurrentF_Point, Point_B,
|
||||
NewSafety,fPreviousSafety,
|
||||
fPreviousSftOrigin,
|
||||
stepLengthFB,
|
||||
PointH );
|
||||
if( Intersects_FB )
|
||||
{
|
||||
// There is an intersection of FB with a volume boundary
|
||||
// H <- First Intersection of Chord FB
|
||||
|
||||
// H is our new Candidate for the intersection point.
|
||||
// It replaces "E" and we will repeat the test to see if
|
||||
// it is a good enough approximate point for us.
|
||||
|
||||
// Note that F must be in volume volA (the same as A)
|
||||
// (otherwise AF would meet a volume boundary!)
|
||||
// A <- F
|
||||
// E <- H
|
||||
//
|
||||
CurrentA_PointVelocity = ApproxIntersecPointV;
|
||||
CurrentE_Point = PointH;
|
||||
}
|
||||
else // not Intersects_FB
|
||||
{
|
||||
// There is NO intersection of FB with a volume boundary
|
||||
|
||||
if( final_section )
|
||||
{
|
||||
// If B is the original endpoint, this means that whatever
|
||||
// volume(s) intersected the original chord, none touch the
|
||||
// smaller chords we have used.
|
||||
// The value of 'IntersectedOrRecalculatedFT' returned is
|
||||
// likely not valid
|
||||
|
||||
there_is_no_intersection = true; // real final_section
|
||||
}
|
||||
else
|
||||
{
|
||||
// We must restore the original endpoint
|
||||
|
||||
CurrentA_PointVelocity = CurrentB_PointVelocity; // Got to B
|
||||
CurrentB_PointVelocity = CurveEndPointVelocity;
|
||||
restoredFullEndpoint = true;
|
||||
}
|
||||
} // Endif (Intersects_FB)
|
||||
} // Endif (Intersects_AF)
|
||||
|
||||
// Ensure that the new endpoints are not further apart in space
|
||||
// than on the curve due to different errors in the integration
|
||||
//
|
||||
G4double linDistSq, curveDist;
|
||||
linDistSq = ( CurrentB_PointVelocity.GetPosition()
|
||||
- CurrentA_PointVelocity.GetPosition() ).mag2();
|
||||
curveDist = CurrentB_PointVelocity.GetCurveLength()
|
||||
- CurrentA_PointVelocity.GetCurveLength();
|
||||
|
||||
// Change this condition for very strict parameters of propagation
|
||||
//
|
||||
if( curveDist*curveDist*(1+2* GetEpsilonStepFor()) < linDistSq )
|
||||
{
|
||||
// Re-integrate to obtain a new B
|
||||
//
|
||||
G4FieldTrack newEndPointFT =
|
||||
ReEstimateEndpoint( CurrentA_PointVelocity,
|
||||
CurrentB_PointVelocity,
|
||||
linDistSq, // to avoid recalculation
|
||||
curveDist );
|
||||
G4FieldTrack oldPointVelB = CurrentB_PointVelocity;
|
||||
CurrentB_PointVelocity = newEndPointFT;
|
||||
|
||||
if( (final_section)) // real final section
|
||||
{
|
||||
recalculatedEndPoint = true;
|
||||
IntersectedOrRecalculatedFT = newEndPointFT;
|
||||
// So that we can return it, if it is the endpoint!
|
||||
}
|
||||
}
|
||||
if( curveDist < 0.0 )
|
||||
{
|
||||
G4cerr << "ERROR - G4SimpleLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Error in advancing propagation." << G4endl;
|
||||
fVerboseLevel = 5; // Print out a maximum of information
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no );
|
||||
G4cerr << " Point A (start) is " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (end) is " << CurrentB_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Curve distance is " << curveDist << G4endl;
|
||||
G4cerr << G4endl
|
||||
<< "The final curve point is not further along"
|
||||
<< " than the original!" << G4endl;
|
||||
|
||||
if( recalculatedEndPoint )
|
||||
{
|
||||
G4cerr << "Recalculation of EndPoint was called with fEpsStep= "
|
||||
<< GetEpsilonStepFor() << G4endl;
|
||||
}
|
||||
G4cerr.precision(20);
|
||||
G4cerr << " Point A (Curve start) is " << CurveStartPointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (Curve end) is " << CurveEndPointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point A (Current start) is " << CurrentA_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point B (Current end) is " << CurrentB_PointVelocity
|
||||
<< G4endl;
|
||||
G4cerr << " Point E (Trial Point) is " << CurrentE_Point
|
||||
<< G4endl;
|
||||
G4cerr << " Point F (Intersection) is " << ApproxIntersecPointV
|
||||
<< G4endl;
|
||||
G4cerr << " LocateIntersection parameters are : Substep no= "
|
||||
<< substep_no << G4endl;
|
||||
|
||||
G4Exception("G4SimpleLocator::EstimateIntersectionPoint()",
|
||||
"FatalError", FatalException,
|
||||
"Error in advancing propagation.");
|
||||
}
|
||||
|
||||
if(restoredFullEndpoint)
|
||||
{
|
||||
final_section = restoredFullEndpoint;
|
||||
restoredFullEndpoint = false;
|
||||
}
|
||||
} // EndIf ( E is close enough to the curve, ie point F. )
|
||||
// tests ChordAF_Vector.mag() <= maximum_lateral_displacement
|
||||
|
||||
#ifdef G4DEBUG_LOCATE_INTERSECTION
|
||||
if( substep_no >= trigger_substepno_print )
|
||||
{
|
||||
G4cout << "Difficulty in converging in "
|
||||
<< "G4SimpleLocator::EstimateIntersectionPoint():"
|
||||
<< G4endl
|
||||
<< " Substep no = " << substep_no << G4endl;
|
||||
if( substep_no == trigger_substepno_print )
|
||||
{
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0);
|
||||
}
|
||||
G4cout << " State of point A: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1, 0);
|
||||
G4cout << " State of point B: ";
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no);
|
||||
}
|
||||
#endif
|
||||
substep_no++;
|
||||
|
||||
} while ( ( ! found_approximate_intersection )
|
||||
&& ( ! there_is_no_intersection )
|
||||
&& ( substep_no <= max_substeps) ); // UNTIL found or failed
|
||||
|
||||
if( substep_no > max_no_seen )
|
||||
{
|
||||
max_no_seen = substep_no;
|
||||
if( max_no_seen > warn_substeps )
|
||||
{
|
||||
trigger_substepno_print = max_no_seen-20; // Want to see last 20 steps
|
||||
}
|
||||
}
|
||||
|
||||
if( ( substep_no >= max_substeps)
|
||||
&& !there_is_no_intersection
|
||||
&& !found_approximate_intersection )
|
||||
{
|
||||
G4cerr << "WARNING - G4SimpleLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cerr << " Abandoning effort to intersect. " << G4endl;
|
||||
G4cerr << " Information on start & current step follows in cout."
|
||||
<< G4endl;
|
||||
G4cout << "WARNING - G4SimpleLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Convergence is requiring too many substeps: "
|
||||
<< substep_no << G4endl;
|
||||
G4cout << " Found intersection = "
|
||||
<< found_approximate_intersection << G4endl
|
||||
<< " Intersection exists = "
|
||||
<< !there_is_no_intersection << G4endl;
|
||||
G4cout << " Start and Endpoint of Requested Step:" << G4endl;
|
||||
printStatus( CurveStartPointVelocity, CurveEndPointVelocity,
|
||||
-1.0, NewSafety, 0);
|
||||
G4cout << G4endl;
|
||||
G4cout << " 'Bracketing' starting and endpoint of current Sub-Step"
|
||||
<< G4endl;
|
||||
printStatus( CurrentA_PointVelocity, CurrentA_PointVelocity,
|
||||
-1.0, NewSafety, substep_no-1);
|
||||
printStatus( CurrentA_PointVelocity, CurrentB_PointVelocity,
|
||||
-1.0, NewSafety, substep_no);
|
||||
G4cout << G4endl;
|
||||
G4cout.precision( 10 );
|
||||
G4double done_len = CurrentA_PointVelocity.GetCurveLength();
|
||||
G4double full_len = CurveEndPointVelocity.GetCurveLength();
|
||||
G4cout << "ERROR - G4SimpleLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken only length: " << done_len
|
||||
<< " out of " << full_len << " required." << G4endl;
|
||||
G4cout << " Remaining length = " << full_len - done_len << G4endl;
|
||||
|
||||
G4Exception("G4SimpleLocator::EstimateIntersectionPoint()",
|
||||
"UnableToLocateIntersection", FatalException,
|
||||
"Too many substeps while trying to locate intersection.");
|
||||
}
|
||||
else if( substep_no >= warn_substeps )
|
||||
{
|
||||
G4int oldprc= G4cout.precision( 10 );
|
||||
G4cout << "WARNING - G4SimpleLocator::EstimateIntersectionPoint()"
|
||||
<< G4endl
|
||||
<< " Undertaken length: "
|
||||
<< CurrentB_PointVelocity.GetCurveLength();
|
||||
G4cout << " - Needed: " << substep_no << " substeps." << G4endl
|
||||
<< " Warning level = " << warn_substeps
|
||||
<< " and maximum substeps = " << max_substeps << G4endl;
|
||||
G4Exception("G4SimpleLocator::EstimateIntersectionPoint()",
|
||||
"DifficultyToLocateIntersection", JustWarning,
|
||||
"Many substeps while trying to locate intersection.");
|
||||
G4cout.precision( oldprc );
|
||||
}
|
||||
return !there_is_no_intersection; // Success or failure
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
//
|
||||
//
|
||||
// $Id: G4TransportationManager.cc,v 1.15 2007/04/12 11:51:48 vnivanch Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
//
|
||||
// G4TransportationManager
|
||||
|
||||
@@ -0,0 +1,394 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: G4VIntersectionLocator.cc,v 1.4 2008/11/14 18:26:35 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
// Class G4VIntersectionLocator implementation
|
||||
//
|
||||
// 27.10.08 - John Apostolakis, Tatiana Nikitina.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "G4VIntersectionLocator.hh"
|
||||
#include "G4GeometryTolerance.hh"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
G4VIntersectionLocator:: G4VIntersectionLocator(G4Navigator *theNavigator)
|
||||
{
|
||||
kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
|
||||
fiNavigator = theNavigator;
|
||||
fVerboseLevel = 0;
|
||||
fUseNormalCorrection = false;
|
||||
fHelpingNavigator = new G4Navigator();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Destructor.
|
||||
//
|
||||
G4VIntersectionLocator::~G4VIntersectionLocator()
|
||||
{
|
||||
delete fHelpingNavigator;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dumps status of propagator.
|
||||
//
|
||||
void
|
||||
G4VIntersectionLocator::printStatus( const G4FieldTrack& StartFT,
|
||||
const G4FieldTrack& CurrentFT,
|
||||
G4double requestStep,
|
||||
G4double safety,
|
||||
G4int stepNo)
|
||||
{
|
||||
const G4int verboseLevel= fVerboseLevel;
|
||||
const G4ThreeVector StartPosition = StartFT.GetPosition();
|
||||
const G4ThreeVector StartUnitVelocity = StartFT.GetMomentumDir();
|
||||
const G4ThreeVector CurrentPosition = CurrentFT.GetPosition();
|
||||
const G4ThreeVector CurrentUnitVelocity = CurrentFT.GetMomentumDir();
|
||||
|
||||
G4double step_len = CurrentFT.GetCurveLength() - StartFT.GetCurveLength();
|
||||
|
||||
if( ((stepNo == 0) && (verboseLevel <3)) || (verboseLevel >= 3) )
|
||||
{
|
||||
static G4int noPrecision= 4;
|
||||
G4cout.precision(noPrecision);
|
||||
// G4cout.setf(ios_base::fixed,ios_base::floatfield);
|
||||
G4cout << std::setw( 6) << " "
|
||||
<< std::setw( 25) << " Current Position and Direction" << " "
|
||||
<< G4endl;
|
||||
G4cout << std::setw( 5) << "Step#"
|
||||
<< std::setw(10) << " s " << " "
|
||||
<< std::setw(10) << "X(mm)" << " "
|
||||
<< std::setw(10) << "Y(mm)" << " "
|
||||
<< std::setw(10) << "Z(mm)" << " "
|
||||
<< std::setw( 7) << " N_x " << " "
|
||||
<< std::setw( 7) << " N_y " << " "
|
||||
<< std::setw( 7) << " N_z " << " " ;
|
||||
// << G4endl;
|
||||
G4cout // << " >>> "
|
||||
<< std::setw( 7) << " Delta|N|" << " "
|
||||
// << std::setw( 7) << " Delta(N_z) " << " "
|
||||
<< std::setw( 9) << "StepLen" << " "
|
||||
<< std::setw(12) << "StartSafety" << " "
|
||||
<< std::setw( 9) << "PhsStep" << " ";
|
||||
|
||||
G4cout << G4endl;
|
||||
}
|
||||
if((stepNo == 0) && (verboseLevel <=3))
|
||||
{
|
||||
// Recurse to print the start values
|
||||
//
|
||||
printStatus( StartFT, StartFT, -1.0, safety, -1);
|
||||
}
|
||||
if( verboseLevel <= 3 )
|
||||
{
|
||||
if( stepNo >= 0)
|
||||
{
|
||||
G4cout << std::setw( 4) << stepNo << " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
G4cout << std::setw( 5) << "Start" ;
|
||||
}
|
||||
G4cout.precision(8);
|
||||
G4cout << std::setw(10) << CurrentFT.GetCurveLength() << " ";
|
||||
G4cout.precision(8);
|
||||
G4cout << std::setw(10) << CurrentPosition.x() << " "
|
||||
<< std::setw(10) << CurrentPosition.y() << " "
|
||||
<< std::setw(10) << CurrentPosition.z() << " ";
|
||||
G4cout.precision(4);
|
||||
G4cout << std::setw( 7) << CurrentUnitVelocity.x() << " "
|
||||
<< std::setw( 7) << CurrentUnitVelocity.y() << " "
|
||||
<< std::setw( 7) << CurrentUnitVelocity.z() << " ";
|
||||
// G4cout << G4endl;
|
||||
// G4cout << " >>> " ;
|
||||
G4cout.precision(3);
|
||||
G4cout << std::setw( 7)
|
||||
<< CurrentFT.GetMomentum().mag()- StartFT.GetMomentum().mag()
|
||||
<< " ";
|
||||
// << std::setw( 7)
|
||||
// << CurrentUnitVelocity.z() - InitialUnitVelocity.z() << " ";
|
||||
G4cout << std::setw( 9) << step_len << " ";
|
||||
G4cout << std::setw(12) << safety << " ";
|
||||
if( requestStep != -1.0 )
|
||||
{
|
||||
G4cout << std::setw( 9) << requestStep << " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
G4cout << std::setw( 9) << "Init/NotKnown" << " ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
else // if( verboseLevel > 3 )
|
||||
{
|
||||
// Multi-line output
|
||||
|
||||
G4cout << "Step taken was " << step_len
|
||||
<< " out of PhysicalStep= " << requestStep << G4endl;
|
||||
G4cout << "Final safety is: " << safety << G4endl;
|
||||
|
||||
G4cout << "Chord length = " << (CurrentPosition-StartPosition).mag()
|
||||
<< G4endl;
|
||||
G4cout << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ReEstimateEndPoint.
|
||||
//
|
||||
G4FieldTrack G4VIntersectionLocator::
|
||||
ReEstimateEndpoint( const G4FieldTrack &CurrentStateA,
|
||||
const G4FieldTrack &EstimatedEndStateB,
|
||||
G4double linearDistSq,
|
||||
G4double curveDist )
|
||||
{
|
||||
G4FieldTrack newEndPoint( CurrentStateA );
|
||||
G4MagInt_Driver* integrDriver= GetChordFinderFor()->GetIntegrationDriver();
|
||||
|
||||
G4FieldTrack retEndPoint( CurrentStateA );
|
||||
G4bool goodAdvance;
|
||||
G4int itrial=0;
|
||||
const G4int no_trials= 20;
|
||||
|
||||
G4double endCurveLen= EstimatedEndStateB.GetCurveLength();
|
||||
do
|
||||
{
|
||||
G4double currentCurveLen= newEndPoint.GetCurveLength();
|
||||
G4double advanceLength= endCurveLen - currentCurveLen ;
|
||||
if (std::abs(advanceLength)<kCarTolerance)
|
||||
{
|
||||
advanceLength=(EstimatedEndStateB.GetPosition()
|
||||
-newEndPoint.GetPosition()).mag();
|
||||
}
|
||||
goodAdvance=
|
||||
integrDriver->AccurateAdvance(newEndPoint, advanceLength,
|
||||
GetEpsilonStepFor());
|
||||
}
|
||||
while( !goodAdvance && (++itrial < no_trials) );
|
||||
|
||||
if( goodAdvance )
|
||||
{
|
||||
retEndPoint= newEndPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
retEndPoint= EstimatedEndStateB; // Could not improve without major work !!
|
||||
}
|
||||
|
||||
// All the work is done
|
||||
// below are some diagnostics only -- before the return!
|
||||
//
|
||||
static const G4String MethodName("G4VIntersectionLocator::ReEstimateEndpoint");
|
||||
|
||||
#ifdef G4VERBOSE
|
||||
G4int latest_good_trials=0;
|
||||
if( itrial > 1)
|
||||
{
|
||||
if( fVerboseLevel > 0 )
|
||||
{
|
||||
G4cout << MethodName << " called - goodAdv= " << goodAdvance
|
||||
<< " trials = " << itrial
|
||||
<< " previous good= " << latest_good_trials
|
||||
<< G4endl;
|
||||
}
|
||||
latest_good_trials=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
latest_good_trials++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef G4DEBUG_FIELD
|
||||
G4double lengthDone = newEndPoint.GetCurveLength()
|
||||
- CurrentStateA.GetCurveLength();
|
||||
if( !goodAdvance )
|
||||
{
|
||||
if( fVerboseLevel >= 3 )
|
||||
{
|
||||
G4cout << MethodName << "> AccurateAdvance failed " ;
|
||||
G4cout << " in " << itrial << " integration trials/steps. " << G4endl;
|
||||
G4cout << " It went only " << lengthDone << " instead of " << curveDist
|
||||
<< " -- a difference of " << curveDist - lengthDone << G4endl;
|
||||
G4cout << " ReEstimateEndpoint> Reset endPoint to original value!"
|
||||
<< G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
static G4int noInaccuracyWarnings = 0;
|
||||
G4int maxNoWarnings = 10;
|
||||
if ( (noInaccuracyWarnings < maxNoWarnings )
|
||||
|| (fVerboseLevel > 1) )
|
||||
{
|
||||
G4cerr << "G4PropagatorInField::LocateIntersectionPoint():"
|
||||
<< G4endl
|
||||
<< " Warning: Integration inaccuracy requires"
|
||||
<< " an adjustment in the step's endpoint." << G4endl
|
||||
<< " Two mid-points are further apart than their"
|
||||
<< " curve length difference" << G4endl
|
||||
<< " Dist = " << std::sqrt(linearDistSq)
|
||||
<< " curve length = " << curveDist << G4endl;
|
||||
G4cerr << " Correction applied is "
|
||||
<< (newEndPoint.GetPosition()-EstimatedEndStateB.GetPosition()).mag()
|
||||
<< G4endl;
|
||||
}
|
||||
#else
|
||||
// Statistics on the RMS value of the corrections
|
||||
|
||||
static G4int noCorrections=0;
|
||||
static G4double sumCorrectionsSq = 0;
|
||||
noCorrections++;
|
||||
if( goodAdvance )
|
||||
{
|
||||
sumCorrectionsSq += (EstimatedEndStateB.GetPosition() -
|
||||
newEndPoint.GetPosition()).mag2();
|
||||
}
|
||||
linearDistSq -= curveDist; // To use linearDistSq ... !
|
||||
#endif
|
||||
|
||||
return retEndPoint;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Method for finding SurfaceNormal of Intersecting Solid
|
||||
//
|
||||
G4ThreeVector G4VIntersectionLocator::
|
||||
GetLocalSurfaceNormal(const G4ThreeVector &CurrentE_Point, G4bool &validNormal)
|
||||
{
|
||||
G4ThreeVector Normal(G4ThreeVector(0,0,0));
|
||||
G4VPhysicalVolume* located;
|
||||
|
||||
validNormal = false;
|
||||
fHelpingNavigator->SetWorldVolume(GetNavigatorFor()->GetWorldVolume());
|
||||
located = fHelpingNavigator->LocateGlobalPointAndSetup( CurrentE_Point );
|
||||
G4TouchableHistoryHandle aTouchable = fHelpingNavigator
|
||||
->CreateTouchableHistoryHandle();
|
||||
G4ThreeVector localPosition = aTouchable->GetHistory()
|
||||
->GetTopTransform().TransformPoint(CurrentE_Point);
|
||||
|
||||
if( located != 0)
|
||||
{
|
||||
if (located->GetLogicalVolume()
|
||||
->GetSolid()->Inside(localPosition)==kSurface)
|
||||
{
|
||||
Normal = located->GetLogicalVolume()
|
||||
->GetSolid()->SurfaceNormal(localPosition);
|
||||
validNormal = true;
|
||||
}
|
||||
}
|
||||
|
||||
return Normal;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Adjustment of Found Intersection
|
||||
//
|
||||
G4bool G4VIntersectionLocator::
|
||||
AdjustmentOfFoundIntersection( const G4ThreeVector &CurrentA_Point,
|
||||
const G4ThreeVector &CurrentE_Point,
|
||||
const G4ThreeVector &CurrentF_Point,
|
||||
const G4ThreeVector &MomentumDir,
|
||||
const G4bool IntersectAF,
|
||||
G4ThreeVector &IntersectionPoint, // I/O
|
||||
G4double &NewSafety, // I/O
|
||||
G4double &fPreviousSafety, // I/O
|
||||
G4ThreeVector &fPreviousSftOrigin )// I/O
|
||||
{
|
||||
G4double dist,lambda;
|
||||
G4ThreeVector Normal, NewPoint, Point_G;
|
||||
G4bool goodAdjust=false, Intersects_FP=false, validNormal=false;
|
||||
|
||||
// Get SurfaceNormal of Intersecting Solid
|
||||
//
|
||||
Normal=GetLocalSurfaceNormal(CurrentE_Point,validNormal);
|
||||
if(!validNormal) { return false; }
|
||||
|
||||
// Intersection between Line and Plane
|
||||
//
|
||||
G4double n_d_m = Normal.dot(MomentumDir);
|
||||
if ( std::abs(n_d_m)<kCarTolerance )
|
||||
{
|
||||
if ( fVerboseLevel>1 )
|
||||
{
|
||||
G4cerr << "WARNING - "
|
||||
<< "G4VIntersectionLocator::AdjustementOfFoundIntersection()"
|
||||
<< G4endl
|
||||
<< " No intersection. Parallels lines!" << G4endl;
|
||||
return false;
|
||||
}
|
||||
lambda =- Normal.dot(CurrentF_Point-CurrentE_Point)/n_d_m;
|
||||
|
||||
// New candidate for Intersection
|
||||
//
|
||||
NewPoint = CurrentF_Point+lambda*MomentumDir;
|
||||
|
||||
// Distance from CurrentF to Calculated Intersection
|
||||
//
|
||||
dist = std::abs(lambda);
|
||||
|
||||
if ( dist<kCarTolerance*0.001 ) { return false; }
|
||||
|
||||
// Calculation of new intersection point on the path.
|
||||
//
|
||||
if ( IntersectAF ) // First part intersects
|
||||
{
|
||||
G4double stepLengthFP;
|
||||
G4ThreeVector Point_P = CurrentA_Point;
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume(Point_P);
|
||||
Intersects_FP = IntersectChord( Point_P, NewPoint, NewSafety,
|
||||
fPreviousSafety, fPreviousSftOrigin,
|
||||
stepLengthFP, Point_G );
|
||||
|
||||
}
|
||||
else // Second part intersects
|
||||
{
|
||||
G4double stepLengthFP;
|
||||
GetNavigatorFor()->LocateGlobalPointWithinVolume(CurrentF_Point );
|
||||
Intersects_FP = IntersectChord( CurrentF_Point, NewPoint, NewSafety,
|
||||
fPreviousSafety, fPreviousSftOrigin,
|
||||
stepLengthFP, Point_G );
|
||||
}
|
||||
if ( Intersects_FP )
|
||||
{
|
||||
goodAdjust = true;
|
||||
IntersectionPoint = Point_G;
|
||||
}
|
||||
}
|
||||
|
||||
return goodAdjust;
|
||||
}
|
||||
@@ -24,8 +24,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4VoxelNavigation.cc,v 1.7 2007/05/11 13:43:59 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-01 $
|
||||
// $Id: G4VoxelNavigation.cc,v 1.9 2008/11/14 18:26:35 gcosmo Exp $
|
||||
// GEANT4 tag $Name: geant4-09-02 $
|
||||
//
|
||||
//
|
||||
// class G4VoxelNavigation Implementation
|
||||
@@ -253,9 +253,9 @@ G4VoxelNavigation::ComputeStep( const G4ThreeVector& localPoint,
|
||||
EInside insideIntPt= sampleSolid->Inside(intersectionPoint);
|
||||
G4String solidResponse = "-kInside-";
|
||||
if (insideIntPt == kOutside)
|
||||
solidResponse = "-kOutside-";
|
||||
{ solidResponse = "-kOutside-"; }
|
||||
else if (insideIntPt == kSurface)
|
||||
solidResponse = "-kSurface-";
|
||||
{ solidResponse = "-kSurface-"; }
|
||||
if( fVerbose == 1 )
|
||||
{
|
||||
G4cout << "*** G4VoxelNavigation::ComputeStep(): ***"<<G4endl
|
||||
@@ -265,6 +265,20 @@ G4VoxelNavigation::ComputeStep( const G4ThreeVector& localPoint,
|
||||
<< " For point p: " << intersectionPoint
|
||||
<< ", considered as 'intersection' point." << G4endl;
|
||||
}
|
||||
G4double safetyIn= -1, safetyOut= -1; // Set to invalid values
|
||||
G4double newDistIn= -1, newDistOut= -1;
|
||||
if( insideIntPt != kInside )
|
||||
{
|
||||
safetyIn= sampleSolid->DistanceToIn(intersectionPoint);
|
||||
newDistIn= sampleSolid->DistanceToIn(intersectionPoint,
|
||||
sampleDirection);
|
||||
}
|
||||
if( insideIntPt != kOutside )
|
||||
{
|
||||
safetyOut= sampleSolid->DistanceToOut(intersectionPoint);
|
||||
newDistOut= sampleSolid->DistanceToOut(intersectionPoint,
|
||||
sampleDirection);
|
||||
}
|
||||
if( insideIntPt != kSurface )
|
||||
{
|
||||
G4int oldcoutPrec = G4cout.precision(16);
|
||||
@@ -276,19 +290,54 @@ G4VoxelNavigation::ComputeStep( const G4ThreeVector& localPoint,
|
||||
<< sampleStep << " yet returns " << solidResponse
|
||||
<< " for this point !" << G4endl;
|
||||
G4cout << " Point = " << intersectionPoint << G4endl;
|
||||
G4cout << " Safety values: " << G4endl;
|
||||
if ( insideIntPt != kInside )
|
||||
G4cout << " DistanceToIn(p) = "
|
||||
<< sampleSolid->DistanceToIn(intersectionPoint)
|
||||
{
|
||||
G4cout << " DistanceToIn(p) = " << safetyIn
|
||||
<< G4endl;
|
||||
if ( insideIntPt != kOutside )
|
||||
G4cout << " DistanceToOut(p) = "
|
||||
<< sampleSolid->DistanceToOut(intersectionPoint)
|
||||
}
|
||||
if ( insideIntPt != kOutside )
|
||||
{
|
||||
G4cout << " DistanceToOut(p) = " << safetyOut
|
||||
<< G4endl;
|
||||
}
|
||||
G4Exception("G4VoxelNavigation::ComputeStep()",
|
||||
"InaccurateDistanceToIn", JustWarning,
|
||||
"Navigator gets conflicting response from Solid.");
|
||||
"Conflicting response from Solid.");
|
||||
G4cout.precision(oldcoutPrec);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If it is on the surface, *ensure* that either DistanceToIn
|
||||
// or DistanceToOut returns a finite value ( >= Tolerance).
|
||||
//
|
||||
if( std::max( newDistIn, newDistOut ) <= kCarTolerance )
|
||||
{
|
||||
G4cout << "ERROR - G4VoxelNavigation::ComputeStep()"
|
||||
<< G4endl
|
||||
<< " Identified point for which the solid "
|
||||
<< sampleSolid->GetName() << G4endl
|
||||
<< " has MAJOR problem: " << G4endl
|
||||
<< " --> Both DistanceToIn(p,v) and DistanceToOut(p,v) "
|
||||
<< "return Zero, an equivalent value or negative value."
|
||||
<< G4endl;
|
||||
G4cout << " Solid: " << sampleSolid << G4endl;
|
||||
G4cout << " Point p= " << intersectionPoint << G4endl;
|
||||
G4cout << " Direction v= " << sampleDirection << G4endl;
|
||||
G4cout << " DistanceToIn(p,v) = " << newDistIn
|
||||
<< G4endl;
|
||||
G4cout << " DistanceToOut(p,v,..) = " << newDistOut
|
||||
<< G4endl;
|
||||
G4cout << " Safety values: " << G4endl;
|
||||
G4cout << " DistanceToIn(p) = " << safetyIn
|
||||
<< G4endl;
|
||||
G4cout << " DistanceToOut(p) = " << safetyOut
|
||||
<< G4endl;
|
||||
G4Exception("G4VoxelNavigation::ComputeStep()",
|
||||
"DistanceToInAndOutAreZero", FatalException,
|
||||
"Zero from both Solid DistanceIn and Out(p,v).");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user