Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:34

0001 #ifndef BFit3D_h
0002 #define BFit3D_h
0003 
0004 #include <iostream>
0005 #include "HarmBasis3DCyl.h"
0006 
0007 //_______________________________________________________________________________
0008 namespace magfieldparam {
0009   class BFit3D {
0010   private:
0011     //The following constants are defined in BFit3D_data.h
0012     static const double B_nom[4];    //Nom. field values at measurements
0013     static const double C0[360][4];  //Expansion coeffs. at measurements
0014     static const double C1[360][5];  //First derivatives of coeffs.
0015     static const double C2[360][3];  //Second derivatives of coeffs.
0016 
0017     double C[360];  //interpolated expansion coeefs. for the field B_set
0018 
0019     bool use_spline;
0020     bool signed_rad;
0021     double B_set;
0022 
0023     HarmBasis3DCyl *HB;
0024 
0025     void SetCoeff_Linear(const double B);
0026     void SetCoeff_Spline(const double B);
0027 
0028   public:
0029     //Defaults: piecewise linear interpolation is used to calculate
0030     //expansion coefficients for intermidiate field values,
0031     //Signed "R" coordinate is accepted
0032     BFit3D() : use_spline(false), signed_rad(true), B_set(0.), HB(new HarmBasis3DCyl(18)) {}
0033 
0034     virtual ~BFit3D() { delete HB; }
0035 
0036     //Set the interpolation type (cubic spline or linear piecewise)
0037     void UseSpline(const bool flag = true) { use_spline = flag; }
0038 
0039     //Switch between signed and unsigned "R" modes
0040     void UseSignedRad(const bool flag = true) { signed_rad = flag; }
0041 
0042     //BASIC FUNCTION: Set nominal field
0043     void SetField(const double B) {
0044       if (use_spline)
0045         SetCoeff_Spline(B);
0046       else
0047         SetCoeff_Linear(B);
0048       B_set = B;
0049     }
0050 
0051     //BASIC FUNCTION: Return field components at the point (r,z,phi)
0052     void GetField(const double r, const double z, const double phi, double &Br, double &Bz, double &Bphi);
0053 
0054     //All the following functions are provided for diagnostic purposes
0055 
0056     unsigned GetLen() { return HB->GetLen(); }  //Ret. the basis length
0057     double GetBnom() { return B_set; }          //Ret. nominal field
0058     double GetC(const int k) { return C[k]; }   //Ret. k-th expansion coefficient
0059 
0060     //The following functions return values of the k-th basis component
0061     //(B_r, B_z or B_phi) at the point which is set by last GetField(...)
0062     double GetBr_k(const unsigned k) { return HB->GetBr_k(k); }
0063     double GetBz_k(const unsigned k) { return HB->GetBz_k(k); }
0064     double GetBphi_k(const unsigned k) { return HB->GetBphi_k(k); }
0065 
0066     //The following functions prints the basis polynomials for the scalar
0067     //field potential, B_r, B_z or B_phi.
0068     void PrintPtnPoly(std::ostream &out = std::cout) { HB->PrintPtB(out); }
0069     void PrintBrPoly(std::ostream &out = std::cout) { HB->PrintBrB(out); }
0070     void PrintBzPoly(std::ostream &out = std::cout) { HB->PrintBzB(out); }
0071     void PrintBphiPoly(std::ostream &out = std::cout) { HB->PrintBphiB(out); }
0072     void PrintPoly(std::ostream &out = std::cout) { HB->Print(out); }
0073   };
0074 }  // namespace magfieldparam
0075 #endif