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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 // G4ErrorCylSurfaceTarget class implementation
 27 // 
 28 // Created: P.Arce, September 2004
 29 // --------------------------------------------------------------------
 30 
 31 #include "G4ErrorCylSurfaceTarget.hh"
 32 #include "G4GeometryTolerance.hh"
 33 
 34 #ifdef G4VERBOSE
 35 #include "G4ErrorPropagatorData.hh" // for verbosity checking
 36 #endif
 37 
 38 #include "geomdefs.hh"
 39 #include "G4Normal3D.hh"
 40 #include "G4Plane3D.hh"
 41 
 42 //---------------------------------------------------------------------
 43 
 44 G4ErrorCylSurfaceTarget::
 45 G4ErrorCylSurfaceTarget( const G4double& radius,
 46                          const G4ThreeVector& trans,
 47                          const G4RotationMatrix& rotm )
 48   : fradius(radius)
 49 {
 50   theType = G4ErrorTarget_CylindricalSurface;
 51 
 52   ftransform = G4AffineTransform( rotm.inverse(), -trans );
 53 #ifdef G4VERBOSE
 54   if(G4ErrorPropagatorData::verbose() >= 2 )
 55   { 
 56     Dump( " $$$ creating G4ErrorCylSurfaceTarget ");
 57   }
 58 #endif
 59 }
 60 
 61 //---------------------------------------------------------------------
 62 
 63 G4ErrorCylSurfaceTarget::
 64 G4ErrorCylSurfaceTarget( const G4double& radius,
 65                          const G4AffineTransform& trans )
 66   : fradius(radius), ftransform(trans.Inverse())
 67 {
 68   theType = G4ErrorTarget_CylindricalSurface;
 69 
 70 #ifdef G4VERBOSE
 71   if(G4ErrorPropagatorData::verbose() >= 2 )
 72   { 
 73     Dump( " $$$ creating G4ErrorCylSurfaceTarget ");
 74   }
 75 #endif
 76 }
 77 
 78 //---------------------------------------------------------------------
 79 
 80 G4double G4ErrorCylSurfaceTarget::
 81 GetDistanceFromPoint( const G4ThreeVector& point,
 82                       const G4ThreeVector& dir ) const
 83 {
 84   if( dir.mag() == 0. )
 85   {
 86     G4Exception("G4ErrorCylSurfaceTarget::GetDistanceFromPoint()",
 87                 "GeomMgt0003", FatalException, "Direction is zero !");
 88   }
 89 
 90   //----- Get intersection point
 91   G4ThreeVector localPoint = ftransform.TransformPoint( point );
 92   G4ThreeVector localDir = ftransform.TransformAxis( dir ); 
 93   G4ThreeVector inters = IntersectLocal(localPoint, localDir);
 94 
 95   G4double dist = (localPoint-inters).mag();
 96   
 97 #ifdef G4VERBOSE
 98   if(G4ErrorPropagatorData::verbose() >= 3 )
 99   { 
100     G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint():" << G4endl
101            << " Global point " << point << " dir " << dir << G4endl
102            << " Intersection " << inters << G4endl
103            << " Distance " << dist << G4endl;
104     Dump( " CylSurface: " );
105   }
106 #endif
107 
108   return dist;
109 }
110 
111 
112 //---------------------------------------------------------------------
113 
114 G4double G4ErrorCylSurfaceTarget::
115 GetDistanceFromPoint( const G4ThreeVector& point ) const
116 {
117   G4ThreeVector localPoint = ftransform.TransformPoint( point );
118 
119 #ifdef G4VERBOSE
120   if(G4ErrorPropagatorData::verbose() >= 3 )
121   { 
122     G4cout << " G4ErrorCylSurfaceTarget::GetDistanceFromPoint:" << G4endl
123            << " Global point " << point << G4endl
124            << " Distance " << fradius - localPoint.perp() << G4endl;
125     Dump( " CylSurface: " );
126   }
127 #endif
128 
129   return fradius - localPoint.perp();
130 }
131 
132 //---------------------------------------------------------------------
133 
134 G4ThreeVector G4ErrorCylSurfaceTarget::
135 IntersectLocal( const G4ThreeVector& localPoint,
136                 const G4ThreeVector& localDir ) const
137 {
138   G4double eqa = localDir.x()*localDir.x()+localDir.y()*localDir.y();
139   G4double eqb = 2*(localPoint.x()*localDir.x()+localPoint.y()*localDir.y());
140   G4double eqc = -fradius*fradius+localPoint.x()*localPoint.x()
141                  +localPoint.y()*localPoint.y();
142   G4int inside = (localPoint.perp() > fradius) ? -1 : 1;
143   G4double lambda;
144 
145   if( eqa*inside > 0. )
146   {
147     lambda = (-eqb + std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa);
148   }
149   else if( eqa*inside < 0. )
150   {
151     lambda = (-eqb - std::sqrt(eqb*eqb-4*eqa*eqc) ) / (2.*eqa);
152   }
153   else
154   {
155     if( eqb != 0. )
156     {
157       lambda = -eqc/eqb;
158     }
159     else
160     {
161       std::ostringstream message;
162       message << "Intersection not possible !" << G4endl
163               << "          Point: " << localPoint << ", direction: "
164               << localDir;
165       Dump( " CylSurface: " ); 
166       G4Exception("G4ErrorCylSurfaceTarget::IntersectLocal()",
167                   "GeomMgt1002", JustWarning, message);
168       lambda = kInfinity;
169     }
170   }
171 
172   G4ThreeVector inters = localPoint + lambda*localDir/localDir.mag();
173 
174 #ifdef G4VERBOSE
175   if(G4ErrorPropagatorData::verbose() >= 4 ) { 
176     G4cout << " G4ErrorCylSurfaceTarget::IntersectLocal " << inters << " "
177            << inters.perp() << " localPoint " << localPoint << " localDir "
178            << localDir << G4endl;
179   } 
180 #endif
181 
182   return inters;
183 }
184 
185 //---------------------------------------------------------------------
186 
187 G4Plane3D G4ErrorCylSurfaceTarget::
188 GetTangentPlane( const G4ThreeVector& point ) const
189 {
190   G4ThreeVector localPoint = ftransform.TransformPoint( point );
191 
192   // check that point is at cylinder surface
193   //
194   if( std::fabs( localPoint.perp() - fradius )
195       > 1000.*G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() )
196   {
197     std::ostringstream message;
198     message << "Local point not at surface !" << G4endl
199             << "          Point: " << point << ", local: " << localPoint
200             << G4endl
201             << "          is not at surface, but far away by: "
202             << localPoint.perp() - fradius << " !";
203     G4Exception("G4ErrorCylSurfaceTarget::GetTangentPlane()",
204                 "GeomMgt1002", JustWarning, message);
205   }
206 
207   G4Normal3D normal = localPoint - ftransform.NetTranslation();
208 
209   return G4Plane3D( normal, point );
210 }
211 
212 
213 //---------------------------------------------------------------------
214 
215 void G4ErrorCylSurfaceTarget::Dump( const G4String& msg ) const
216 {
217   G4cout << msg << " radius " << fradius
218                 << " centre " << ftransform.NetTranslation()
219                 << " rotation " << ftransform.NetRotation() << G4endl;
220 }
221