00001 #include "SimG4Core/MagneticField/interface/Field.h" 00002 #include "MagneticField/Engine/interface/MagneticField.h" 00003 00004 //#include "Geometry/Vector/interface/GlobalPoint.h" 00005 #include "DataFormats/GeometryVector/interface/GlobalPoint.h" 00006 00007 #include "G4Mag_UsualEqRhs.hh" 00008 00009 #include "CLHEP/Units/SystemOfUnits.h" 00010 00011 #include "SimG4Core/Notification/interface/SimG4Exception.h" 00012 00013 using namespace sim; 00014 00015 G4Mag_UsualEqRhs * Field::fieldEquation() { return theFieldEquation; } 00016 00017 Field::Field(const MagneticField * f, double d) 00018 : G4MagneticField(), theCMSMagneticField(f),theDelta(d) 00019 { 00020 } 00021 00022 Field::~Field() {} 00023 00024 void Field::GetFieldValue(const double xyz[3],double bfield[3]) const 00025 { 00026 00027 // 00028 // this is another trick to check on a NaN, maybe it's even CPU-faster... 00029 // but ler's stick to system function isnan(...) for now 00030 // 00031 // if ( !(xyz[0]==xyz[0]) || !(xyz[1]==xyz[1]) || !(xyz[2]==xyz[2]) ) 00032 if ( isnan(xyz[0]+xyz[1]+xyz[2]) != 0 ) 00033 { 00034 throw SimG4Exception( "SimG4CoreMagneticField: Corrupted Event - NaN detected (position)" ) ; 00035 } 00036 00037 static float oldx[3] = {1.0e12,1.0e12,1.0e12}; 00038 static double b[3]; 00039 00040 if (theDelta>0. && 00041 fabs(oldx[0]-xyz[0])<theDelta && 00042 fabs(oldx[1]-xyz[1])<theDelta && 00043 fabs(oldx[2]-xyz[2])<theDelta) 00044 { 00045 // old b good enough 00046 bfield[0] = b[0]; 00047 bfield[1] = b[1]; 00048 bfield[2] = b[2]; 00049 return; 00050 } 00051 00052 const GlobalPoint g(xyz[0]/cm,xyz[1]/cm,xyz[2]/cm); 00053 GlobalVector v = theCMSMagneticField->inTesla(g); 00054 b[0] = v.x()*tesla; 00055 b[1] = v.y()*tesla; 00056 b[2] = v.z()*tesla; 00057 00058 oldx[0] = xyz[0]; 00059 oldx[1] = xyz[1]; 00060 oldx[2] = xyz[2]; 00061 00062 bfield[0] = b[0]; 00063 bfield[1] = b[1]; 00064 bfield[2] = b[2]; 00065 } 00066 00067 void Field::fieldEquation(G4Mag_UsualEqRhs* e) { theFieldEquation = e; } 00068