Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef MagneticFieldGrid_H
0002 #define MagneticFieldGrid_H
0003 
0004 /** \class MagneticFieldGrid
0005  *
0006  * load magnetic field grid from binary file
0007  * remark: units are either (cm,cm,cm) or (cm,rad,cm)
0008  *         and Tesla for the magnetic field
0009  *
0010  * additional functions either translate indices <-> coordinates,
0011  * transfer data, or activate the interpolation between grid points
0012  *
0013  * \author : <Volker.Drollinger@cern.ch>
0014  *
0015  * Modifications:
0016  *
0017  */
0018 
0019 // interpolation package
0020 #include "FWCore/Utilities/interface/Visibility.h"
0021 #include "VectorFieldInterpolation.h"
0022 
0023 // used libs
0024 #include <vector>
0025 #include <algorithm>
0026 #include <cmath>
0027 #include <string>
0028 #include <iostream>
0029 #include <fstream>
0030 
0031 class dso_internal MagneticFieldGrid {
0032 public:
0033   // constructor
0034   MagneticFieldGrid() {
0035     GridType = 0;
0036     for (int i = 0; i < 3; ++i) {
0037       NumberOfPoints[i] = 0;
0038     };
0039     for (int i = 0; i < 3; ++i) {
0040       ReferencePoint[i] = 0.;
0041     };
0042     for (int i = 0; i < 3; ++i) {
0043       BasicDistance0[i] = 0.;
0044     };
0045     for (int i = 0; i < 3; ++i) {
0046       for (int j = 0; j < 3; ++j) {
0047         BasicDistance1[i][j] = 0.;
0048       };
0049     };
0050     for (int i = 0; i < 3; ++i) {
0051       for (int j = 0; j < 3; ++j) {
0052         BasicDistance2[i][j] = 0.;
0053       };
0054     };
0055     for (int i = 0; i < 4; ++i) {
0056       RParAsFunOfPhi[i] = 0.;
0057     };
0058     for (int i = 0; i < 3; ++i) {
0059       EasyCoordinate[i] = false;
0060     };
0061   }
0062   // destructor
0063   ~MagneticFieldGrid() {}
0064 
0065 private:
0066   // header classes (5: one for each type)
0067   class dso_internal HeaderType3 {
0068   public:
0069     // constructor
0070     HeaderType3() {}
0071     // destructor
0072     ~HeaderType3() {}
0073 
0074   private:
0075   public:
0076     void printInfo();
0077   };
0078   // b-field container
0079   class dso_internal BVector {
0080   public:
0081     // constructor
0082     BVector() {}
0083     // destructor
0084     ~BVector() {}
0085 
0086   private:
0087     // three component vector in float precision
0088     float B3[3];
0089 
0090   public:
0091     // Accessors
0092     void putB3(float Bx, float By, float Bz);
0093     float bx();
0094     float by();
0095     float bz();
0096   };
0097 
0098   // DEFINITION OF GRID
0099   // type
0100   int GridType;
0101   // header
0102   int NumberOfPoints[3];
0103   double ReferencePoint[3];
0104   double BasicDistance0[3];     // constant step
0105   double BasicDistance1[3][3];  // linear step
0106   double BasicDistance2[3][3];  // linear offset
0107   double RParAsFunOfPhi[4];     // R = f(phi) or const. (0,2: const. par. ; 1,3: const./sin(phi))
0108   bool EasyCoordinate[3];
0109   // field (Bx,By,Bz) container
0110   std::vector<BVector> FieldValues;
0111 
0112 public:
0113   /// load grid binary file
0114   void load(const std::string &name);
0115   /// returns value of GridType (and eventually prints the type + short description)
0116   int gridType();
0117 
0118   /// interpolates the magnetic field at input coordinate point and returns field values
0119   void interpolateAtPoint(double X1, double X2, double X3, float &Bx, float &By, float &Bz);
0120 
0121   // calculates indices from coordinates
0122   void putCoordGetInd(double X1, double X2, double X3, int &Index1, int &Index2, int &Index3);
0123   // takes indices and returns magnetic field values
0124   void putIndicesGetB(int Index1, int Index2, int Index3, float &Bx, float &By, float &Bz);
0125   // takes indices, calculates coordinates, and returns coordinates
0126   void putIndGetCoord(int Index1, int Index2, int Index3, double &X1, double &X2, double &X3);
0127   // converts three indices into one number (for the vector FieldValues)
0128   int lineNumber(int Index1, int Index2, int Index3);
0129 };
0130 
0131 #endif