CMS 3D CMS Logo

MagneticFieldGrid.h

Go to the documentation of this file.
00001 #ifndef MagneticFieldGrid_H
00002 #define MagneticFieldGrid_H
00003 
00020 // interpolation package
00021 #include "MagneticField/Interpolation/src/VectorFieldInterpolation.h"
00022 #include "MagneticField/Interpolation/src/binary_ifstream.h"
00023 
00024 // used libs
00025 #include <vector>
00026 #include <algorithm>
00027 #include <cmath>
00028 #include <string>
00029 #include <iostream>
00030 #include <fstream>
00031 
00032 class MagneticFieldGrid{
00033 public:
00034   // constructor
00035   MagneticFieldGrid(){
00036     GridType = 0;
00037     for (int i=0;i<3; ++i) {NumberOfPoints[i] = 0;};
00038     for (int i=0;i<3; ++i) {ReferencePoint[i] = 0.;};
00039     for (int i=0;i<3; ++i) {BasicDistance0[i] = 0.;};
00040     for (int i=0;i<3; ++i) {for (int j=0;j<3; ++j) {BasicDistance1[i][j] = 0.;};};
00041     for (int i=0;i<3; ++i) {for (int j=0;j<3; ++j) {BasicDistance2[i][j] = 0.;};};
00042     for (int i=0;i<4; ++i) {RParAsFunOfPhi[i] = 0.;};
00043     for (int i=0;i<3; ++i) {EasyCoordinate[i] = false;};
00044   }
00045   // destructor
00046   ~MagneticFieldGrid(){}
00047 
00048 private:
00049   // header classes (5: one for each type)
00050   class HeaderType3{
00051   public:
00052     // constructor
00053     HeaderType3(){}
00054     // destructor
00055     ~HeaderType3(){}
00056   private:
00057   public:
00058     void printInfo();
00059   };
00060   // b-field container
00061   class BVector{
00062   public:
00063     // constructor
00064     BVector(){}
00065     // destructor
00066     ~BVector(){}
00067   private:
00068     // three component vector in float precision
00069     float B3[3];
00070   public:
00071     // Accessors
00072     void putB3(float Bx, float By, float Bz);
00073     float bx();
00074     float by();
00075     float bz();
00076   };
00077 
00078   // DEFINITION OF GRID
00079   // type
00080   int GridType;
00081   // header
00082   int    NumberOfPoints[3];
00083   double ReferencePoint[3];
00084   double BasicDistance0[3];     // constant step
00085   double BasicDistance1[3][3];  // linear step
00086   double BasicDistance2[3][3];  // linear offset
00087   double RParAsFunOfPhi[4];     // R = f(phi) or const. (0,2: const. par. ; 1,3: const./sin(phi))
00088   bool   EasyCoordinate[3];
00089   // field (Bx,By,Bz) container
00090   std::vector<BVector> FieldValues;
00091 
00092 public:
00094   void load(const std::string& name);
00096   int gridType();
00097 
00099   void interpolateAtPoint(double X1, double X2, double X3, float &Bx, float &By, float &Bz);
00100 
00101   // calculates indices from coordinates
00102   void putCoordGetInd(double X1, double X2, double X3, int &Index1, int &Index2, int &Index3);
00103   // takes indices and returns magnetic field values 
00104   void putIndicesGetB(int Index1, int Index2, int Index3, float &Bx, float &By, float &Bz);
00105   // takes indices, calculates coordinates, and returns coordinates
00106   void putIndGetCoord(int Index1, int Index2, int Index3, double &X1, double &X2, double &X3);
00107   // converts three indices into one number (for the vector FieldValues)
00108   int lineNumber(int Index1, int Index2, int Index3);
00109 };
00110 
00111 
00112 #endif

Generated on Tue Jun 9 17:40:34 2009 for CMSSW by  doxygen 1.5.4