Go to the documentation of this file.00001 #include "SimG4Core/MagneticField/interface/Field.h"
00002 #include "MagneticField/Engine/interface/MagneticField.h"
00003
00004
00005 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00006
00007 #include "G4Mag_UsualEqRhs.hh"
00008
00009 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00010
00011 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00012 #include "FWCore/Utilities/interface/isFinite.h"
00013
00014 using namespace sim;
00015
00016 G4Mag_UsualEqRhs * Field::fieldEquation() { return theFieldEquation; }
00017
00018 Field::Field(const MagneticField * f, double d)
00019 : G4MagneticField(), theCMSMagneticField(f),theDelta(d)
00020 {
00021 }
00022
00023 Field::~Field() {}
00024
00025 void Field::GetFieldValue(const double xyz[3],double bfield[3]) const
00026 {
00027
00028
00029
00030
00031
00032
00033 if ( edm::isNotFinite(xyz[0]+xyz[1]+xyz[2]) != 0 )
00034 {
00035 throw SimG4Exception( "SimG4CoreMagneticField: Corrupted Event - NaN detected (position)" ) ;
00036 }
00037
00038 static float oldx[3] = {1.0e12,1.0e12,1.0e12};
00039 static double b[3];
00040
00041 if (theDelta>0. &&
00042 fabs(oldx[0]-xyz[0])<theDelta &&
00043 fabs(oldx[1]-xyz[1])<theDelta &&
00044 fabs(oldx[2]-xyz[2])<theDelta)
00045 {
00046
00047 bfield[0] = b[0];
00048 bfield[1] = b[1];
00049 bfield[2] = b[2];
00050 return;
00051 }
00052
00053 const GlobalPoint g(xyz[0]/cm,xyz[1]/cm,xyz[2]/cm);
00054 GlobalVector v = theCMSMagneticField->inTesla(g);
00055 b[0] = v.x()*tesla;
00056 b[1] = v.y()*tesla;
00057 b[2] = v.z()*tesla;
00058
00059 oldx[0] = xyz[0];
00060 oldx[1] = xyz[1];
00061 oldx[2] = xyz[2];
00062
00063 bfield[0] = b[0];
00064 bfield[1] = b[1];
00065 bfield[2] = b[2];
00066 }
00067
00068 void Field::fieldEquation(G4Mag_UsualEqRhs* e) { theFieldEquation = e; }
00069