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