00001 00008 #include <MagneticField/ParametrizedEngine/src/PolyFit2DParametrizedMagneticField.h> 00009 #include <FWCore/ParameterSet/interface/ParameterSet.h> 00010 #include <FWCore/MessageLogger/interface/MessageLogger.h> 00011 00012 #include <MagneticField/ParametrizedEngine/src/BFit.h> 00013 00014 00015 using namespace std; 00016 using namespace magfieldparam; 00017 00018 PolyFit2DParametrizedMagneticField::PolyFit2DParametrizedMagneticField(double bVal) : 00019 theParam(new BFit()) 00020 { 00021 theParam->SetField(bVal); 00022 } 00023 00024 00025 PolyFit2DParametrizedMagneticField::PolyFit2DParametrizedMagneticField(const edm::ParameterSet& parameters) : theParam(new BFit()) { 00026 theParam->SetField(parameters.getParameter<double>("BValue")); 00027 } 00028 00029 00030 PolyFit2DParametrizedMagneticField::~PolyFit2DParametrizedMagneticField() { 00031 delete theParam; 00032 } 00033 00034 00035 GlobalVector 00036 PolyFit2DParametrizedMagneticField::inTesla(const GlobalPoint& gp) const { 00037 00038 if (isDefined(gp)) { 00039 return inTeslaUnchecked(gp); 00040 } else { 00041 edm::LogWarning("MagneticField|FieldOutsideValidity") << " Point " << gp << " is outside the validity region of PolyFit2DParametrizedMagneticField"; 00042 return GlobalVector(); 00043 } 00044 } 00045 00046 GlobalVector 00047 PolyFit2DParametrizedMagneticField::inTeslaUnchecked(const GlobalPoint& gp) const { 00048 double Br, Bz, Bphi; 00049 theParam->GetField(gp.perp()/100., gp.z()/100., gp.phi(), 00050 Br, Bz, Bphi); 00051 00052 double cosphi = cos(gp.phi()); 00053 double sinphi = sin(gp.phi()); 00054 00055 return GlobalVector(Br*cosphi - Bphi*sinphi, 00056 Br*sinphi + Bphi*cosphi, 00057 Bz); 00058 } 00059 00060 bool 00061 PolyFit2DParametrizedMagneticField::isDefined(const GlobalPoint& gp) const { 00062 double z = fabs(gp.z()); 00063 double r = gp.perp(); 00064 //"rectangle" |z|<3.5, r<1.9 _except_ the "corners" |z|+2.5*r>6.7, everything in meters 00065 if (z>350. || r>190 || z+2.5*r>670.) return false; 00066 return true; 00067 }