CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/MagneticField/ParametrizedEngine/plugins/BFit3D.h

Go to the documentation of this file.
00001 #ifndef BFit3D_h
00002 #define BFit3D_h
00003 
00004 #include <iostream>
00005 #include "HarmBasis3DCyl.h"
00006 
00007 //_______________________________________________________________________________
00008 namespace magfieldparam {
00009 class BFit3D {
00010 
00011 private:
00012 
00013    //The following constants are defined in BFit3D_data.h
00014    static const double B_nom[4];   //Nom. field values at measurements
00015    static const double C0[360][4]; //Expansion coeffs. at measurements
00016    static const double C1[360][5]; //First derivatives of coeffs.
00017    static const double C2[360][3]; //Second derivatives of coeffs.
00018 
00019    double C[360]; //interpolated expansion coeefs. for the field B_set
00020    
00021    bool   use_spline;
00022    bool   signed_rad;
00023    double B_set;
00024 
00025    HarmBasis3DCyl *HB;
00026  
00027    void SetCoeff_Linear(const double B);
00028    void SetCoeff_Spline(const double B);
00029 
00030 public:
00031 
00032    //Defaults: piecewise linear interpolation is used to calculate
00033    //expansion coefficients for intermidiate field values,
00034    //Signed "R" coordinate is accepted
00035    BFit3D() : use_spline(false), signed_rad(true), B_set(0.), 
00036               HB(new HarmBasis3DCyl(18)) {}
00037 
00038    virtual ~BFit3D() { delete HB;}
00039    
00040    //Set the interpolation type (cubic spline or linear piecewise)
00041    void UseSpline   (const bool flag = true) { use_spline = flag;}
00042 
00043    //Switch between signed and unsigned "R" modes
00044    void UseSignedRad(const bool flag = true) { signed_rad = flag;}
00045    
00046    //BASIC FUNCTION: Set nominal field
00047    void SetField(const double B) {
00048       if (use_spline) SetCoeff_Spline(B); else SetCoeff_Linear(B);
00049       B_set = B;
00050    }
00051 
00052    //BASIC FUNCTION: Return field components at the point (r,z,phi)
00053    void GetField(const double r, const double z, const double phi,
00054                  double &Br, double &Bz, double &Bphi);
00055 
00056    //All the following functions are provided for diagnostic purposes
00057 
00058    unsigned GetLen() { return HB->GetLen();} //Ret. the basis length
00059    double GetBnom() { return B_set;}         //Ret. nominal field
00060    double GetC(const int k) { return C[k];}  //Ret. k-th expansion coefficient
00061 
00062    //The following functions return values of the k-th basis component
00063    //(B_r, B_z or B_phi) at the point which is set by last GetField(...)
00064    double GetBr_k  (const unsigned k) { return HB->GetBr_k  (k);}
00065    double GetBz_k  (const unsigned k) { return HB->GetBz_k  (k);}
00066    double GetBphi_k(const unsigned k) { return HB->GetBphi_k(k);}
00067    
00068    //The following functions prints the basis polynomials for the scalar
00069    //field potential, B_r, B_z or B_phi.
00070    void PrintPtnPoly (std::ostream &out = std::cout) { HB->PrintPtB  (out);}
00071    void PrintBrPoly  (std::ostream &out = std::cout) { HB->PrintBrB  (out);}
00072    void PrintBzPoly  (std::ostream &out = std::cout) { HB->PrintBzB  (out);}
00073    void PrintBphiPoly(std::ostream &out = std::cout) { HB->PrintBphiB(out);}
00074    void PrintPoly    (std::ostream &out = std::cout) { HB->Print     (out);}
00075 
00076 };
00077 }
00078 #endif