File indexing completed on 2024-04-06 12:22:34
0001
0002
0003
0004
0005
0006 #include "PolyFit2DParametrizedMagneticField.h"
0007 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0008 #include <FWCore/MessageLogger/interface/MessageLogger.h>
0009
0010 #include "BFit.h"
0011
0012 using namespace std;
0013 using namespace magfieldparam;
0014
0015 PolyFit2DParametrizedMagneticField::PolyFit2DParametrizedMagneticField(double bVal) : theParam(new BFit()) {
0016 theParam->SetField(bVal);
0017 setNominalValue();
0018 }
0019
0020 PolyFit2DParametrizedMagneticField::PolyFit2DParametrizedMagneticField(const edm::ParameterSet& parameters)
0021 : theParam(new BFit()) {
0022 theParam->SetField(parameters.getParameter<double>("BValue"));
0023 setNominalValue();
0024 }
0025
0026 PolyFit2DParametrizedMagneticField::~PolyFit2DParametrizedMagneticField() { delete theParam; }
0027
0028 GlobalVector PolyFit2DParametrizedMagneticField::inTesla(const GlobalPoint& gp) const {
0029 if (isDefined(gp)) {
0030 return inTeslaUnchecked(gp);
0031 } else {
0032 edm::LogWarning("MagneticField") << " Point " << gp
0033 << " is outside the validity region of PolyFit2DParametrizedMagneticField";
0034 return GlobalVector();
0035 }
0036 }
0037
0038 GlobalVector PolyFit2DParametrizedMagneticField::inTeslaUnchecked(const GlobalPoint& gp) const {
0039 double Br, Bz, Bphi;
0040 theParam->GetField(gp.perp() / 100., gp.z() / 100., gp.phi(), Br, Bz, Bphi);
0041
0042 double cosphi = cos(gp.phi());
0043 double sinphi = sin(gp.phi());
0044
0045 return GlobalVector(Br * cosphi - Bphi * sinphi, Br * sinphi + Bphi * cosphi, Bz);
0046 }
0047
0048 bool PolyFit2DParametrizedMagneticField::isDefined(const GlobalPoint& gp) const {
0049 double z = fabs(gp.z());
0050 double r = gp.perp();
0051
0052 if (z > 350. || r > 190 || z + 2.5 * r > 670.)
0053 return false;
0054 return true;
0055 }