Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:56:58

0001 #ifndef rz_harm_poly_h
0002 #define rz_harm_poly_h
0003 
0004 #include <cmath>
0005 #include "poly2d_base.h"
0006 
0007 /////////////////////////////////////////////////////////////////////////////////
0008 //                                                                             //
0009 //  Pair (Cos(phi),Sin(Phi)). Intended for internal use by rz_harm_poly.       //
0010 //                                                                             //
0011 /////////////////////////////////////////////////////////////////////////////////
0012 
0013 //_______________________________________________________________________________
0014 namespace magfieldparam {
0015   struct trig_pair {
0016     double CosPhi;
0017     double SinPhi;
0018 
0019     trig_pair() : CosPhi(1.), SinPhi(0.) {}
0020     trig_pair(const trig_pair &tp) : CosPhi(tp.CosPhi), SinPhi(tp.SinPhi) {}
0021     trig_pair(const double C, const double S) : CosPhi(C), SinPhi(S) {}
0022     trig_pair(const double phi) : CosPhi(cos(phi)), SinPhi(sin(phi)) {}
0023 
0024     //Return trig_pair fo angle increased by angle of tp.
0025     trig_pair Add(const trig_pair &tp) {
0026       return trig_pair(this->CosPhi * tp.CosPhi - this->SinPhi * tp.SinPhi,
0027                        this->SinPhi * tp.CosPhi + this->CosPhi * tp.SinPhi);
0028     }
0029   };
0030 
0031   /////////////////////////////////////////////////////////////////////////////////
0032   //                                                                             //
0033   //  Harmonic homogeneous polynomial in cylindrical system.                     //
0034   //                                                                             //
0035   /////////////////////////////////////////////////////////////////////////////////
0036 
0037   //_______________________________________________________________________________
0038   class rz_harm_poly : public poly2d_base {
0039   private:
0040     unsigned L;
0041     int M;
0042 
0043     static unsigned Cnt;   //Number of the "rz_harm_poly" objects
0044     static double phival;  //Last phi value used
0045     static bool phi_set;   //TRUE if phi value is set
0046     static unsigned MaxM;  //Max. M among "rz_harm_poly" objects
0047 
0048     static unsigned TASize;     //TrigArr size
0049     static trig_pair *TrigArr;  //Array with angular data
0050 
0051     static void SetTrigArrSize(const unsigned N);
0052     static void FillTrigArr(const double phi);
0053 
0054     void PrintLM(std::ostream &out = std::cout) {
0055       out << "L=" << std::setw(3) << std::left << L << ", M=" << std::setw(3) << std::left << M << "; ";
0056     }
0057 
0058   public:
0059     static int GetMaxM();  //return Max. M for the class
0060     static unsigned ParentCount() { return poly2d_base::Count(); }
0061     static unsigned Count() { return Cnt; }
0062     static void SetPhi(const double phi);
0063     static void SetPoint(const double r, const double z, const double phi) {
0064       poly2d_base::SetPoint(r, z);
0065       SetPhi(phi);
0066     }
0067 
0068     rz_harm_poly() : poly2d_base(), L(0), M(0) { ++Cnt; }
0069     rz_harm_poly(const poly2d_base &S) : poly2d_base(S), L(0), M(0) { ++Cnt; }
0070     rz_harm_poly(const rz_harm_poly &S) : poly2d_base(S), L(S.L), M(S.M) { ++Cnt; }
0071     rz_harm_poly(const unsigned N);
0072     ~rz_harm_poly() override;
0073 
0074     bool IsPhiSet() { return phi_set; }
0075 
0076     rz_harm_poly GetDiff(int nvar) {
0077       rz_harm_poly R(*this);
0078       R.Diff(nvar);
0079       return R;
0080     }
0081     rz_harm_poly GetInt(int nvar) {
0082       rz_harm_poly R(*this);
0083       R.Int(nvar);
0084       return R;
0085     }
0086     rz_harm_poly GetIncPow(int nvar) {
0087       rz_harm_poly R(*this);
0088       R.IncPow(nvar);
0089       return R;
0090     }
0091     rz_harm_poly GetDecPow(int nvar) {
0092       rz_harm_poly R(*this);
0093       R.DecPow(nvar);
0094       return R;
0095     }
0096 
0097     rz_harm_poly LadderUp();
0098     rz_harm_poly LadderDwn();
0099 
0100     unsigned GetL() { return L; }
0101     int GetM() { return M; }
0102 
0103     //Next functions return value of angular terms.
0104     //No check is made, wheither the TrigArr is initialized.
0105     //User can check if IsPhiSet() == true
0106     double GetCos() { return TrigArr[M].CosPhi; }
0107     double GetSin() { return TrigArr[M].SinPhi; }
0108 
0109     void CheatL(const unsigned newL) { L = newL; }
0110     void Print(std::ostream &out = std::cout, const std::streamsize prec = 5) {
0111       PrintLM(out);
0112       poly2d_base::Print(out, prec);
0113     }
0114 
0115     static void PrintTrigArr(std::ostream &out = std::cout, const std::streamsize prec = 5);
0116 
0117   };  //class rz_harm_poly
0118 }  // namespace magfieldparam
0119 
0120 #endif