CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/MagneticField/ParametrizedEngine/src/BFit3D.cc

Go to the documentation of this file.
00001 #include <cmath>
00002 #ifndef M_PI
00003 #define M_PI 3.1415926535897932385
00004 #endif
00005 
00006 #include "BFit3D.h"
00007 #include "BFit3D_data.h"
00008 
00009 using namespace magfieldparam;
00010 
00011 //_______________________________________________________________________________
00012 void BFit3D::SetCoeff_Linear(const double B)
00013 {
00014    unsigned jj, kk = 1;
00015    double w_0, w_1, B_mod = fabs(B);
00016    if (B_mod <= B_nom[0]) {
00017       w_0 = B / B_nom[0];
00018       for (jj = 0; jj < 360; ++jj) {
00019          C[jj] = w_0*C0[jj][0];
00020       }
00021    } else if (B_mod >= B_nom[3]) {
00022       w_0 = B / B_nom[3];
00023       for (jj = 0; jj < 360; ++jj) {
00024          C[jj] = w_0*C0[jj][3];
00025       }
00026    } else {
00027       while (B_nom[kk] < B_mod) ++kk; //Simple linear search
00028       w_1 = (B_mod - B_nom[kk-1])/(B_nom[kk] - B_nom[kk-1]);
00029       w_0 = 1.0 - w_1;
00030       if (B < 0.) {
00031          w_0 = -w_0;
00032          w_1 = -w_1;
00033       }
00034       for (jj = 0; jj < 360; ++jj) {
00035          C[jj] = w_0*C0[jj][kk-1] + w_1*C0[jj][kk];
00036       }
00037    }
00038 }
00039 
00040 //_______________________________________________________________________________
00041 void BFit3D::SetCoeff_Spline(const double B)
00042 {
00043    int jc, k0 = 0, k1 = 1;
00044    double dB2, dB = fabs(B);
00045    if (dB >= B_nom[3]) { //Linear extrapolation for a large field
00046       dB -= B_nom[3];
00047       for (jc = 0; jc < 360; ++jc) C[jc] = C0[jc][3] + C1[jc][4]*dB;
00048    } else {
00049       if (dB < B_nom[0]) {
00050          dB2 = dB*dB / (3.*B_nom[0]);
00051          for (jc = 0; jc < 360; ++jc) C[jc] = (C2[jc][0]*dB2 + C1[jc][0])*dB;
00052       } else {
00053          while (B_nom[k1] < dB) ++k1; //Simple linear search
00054          k0 = k1-1;
00055          dB2 = (dB -= B_nom[k0]) / (3.*(B_nom[k1] - B_nom[k0]));
00056          if (k1 < 3) { //"Regular" interval
00057             for (jc = 0; jc < 360; ++jc)
00058                C[jc] = (((C2[jc][k1] - C2[jc][k0])*dB2+C2[jc][k0])*dB + C1[jc][k1])*dB + C0[jc][k0];
00059          } else {      //The last interval
00060             dB2 = (1.- dB2)*dB;
00061             for (jc = 0; jc < 360; ++jc)
00062                C[jc] = (C2[jc][k0]*dB2 + C1[jc][k1])*dB + C0[jc][k0];
00063          }
00064       }
00065    }
00066    if (B < 0) for (jc = 0; jc < 360; ++jc) C[jc] = -C[jc];
00067 }
00068 
00069 //_______________________________________________________________________________
00070 void BFit3D::GetField(const double r, const double z, const double phi,
00071                       double &Br, double &Bz, double &Bphi)
00072 {
00073 //Return field components in Br, Bz, Bphi. SetField must be called before use.
00074 //
00075    if (signed_rad || (r >= 0.)) HB->SetPoint(r, z, phi);
00076    else HB->SetPoint(-r, z, phi+M_PI);
00077    HB->EvalBr();
00078    HB->EvalBz();
00079    HB->EvalBphi();
00080    Br   = HB->GetBr  (C);
00081    Bz   = HB->GetBz  (C);
00082    Bphi = HB->GetBphi(C);
00083 }
00084 
00086 //                                                                             //
00087 //                           T E S T  A R E A                                  //
00088 //                                                                             //
00090