CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/MagneticField/Interpolation/src/MagneticFieldGrid.h

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