CMS 3D CMS Logo

SpecialCylindricalMFGrid.cc

Go to the documentation of this file.
00001 #include "MagneticField/Interpolation/src/SpecialCylindricalMFGrid.h"
00002 #include "MagneticField/Interpolation/src/binary_ifstream.h"
00003 #include "MagneticField/Interpolation/src/LinearGridInterpolator3D.h"
00004 
00005 
00006 #include <iostream>
00007 
00008 using namespace std;
00009 
00010 SpecialCylindricalMFGrid::SpecialCylindricalMFGrid( binary_ifstream& inFile, 
00011                                                     const GloballyPositioned<float>& vol, int gridType)
00012   : MFGrid3D(vol)
00013 {
00014   if (gridType == 5 ) {
00015     sector1 = false;
00016   } else if (gridType == 6 ) {
00017     sector1 = true;
00018   } else {
00019     cout << "ERROR wrong SpecialCylindricalMFGrid type " << gridType << endl;
00020     sector1 = false;
00021   }
00022 
00023   int n1, n2, n3;
00024   inFile >> n1 >> n2 >> n3;
00025 #ifdef DEBUG_GRID
00026   cout << "n1 " << n1 << " n2 " << n2 << " n3 " << n3 << endl;
00027 #endif
00028   double xref, yref, zref;
00029   inFile >> xref >> yref >> zref;
00030   double stepx, stepy, stepz;
00031   inFile >> stepx    >> stepy    >> stepz;
00032 
00033   double RParAsFunOfPhi[4];  // R = f(phi) or const. (0,2: const. par. ; 1,3: const./sin(phi));
00034   inFile >> RParAsFunOfPhi[0] >> RParAsFunOfPhi[1] >> RParAsFunOfPhi[2] >> RParAsFunOfPhi[3];
00035 
00036   vector<BVector> fieldValues;
00037   float Bx, By, Bz;
00038   int nLines = n1*n2*n3;
00039   for (int iLine=0; iLine<nLines; ++iLine){
00040     inFile >> Bx >> By >> Bz;
00041     // This would be fine only if local r.f. has the axes oriented as the global r.f.
00042     // For this volume we know that the local and global r.f. have different axis
00043     // orientation, so we do not try to be clever.
00044     //    fieldValues.push_back(BVector(Bx,By,Bz));
00045     
00046     // Preserve double precision!
00047     Vector3DBase<double, LocalTag>  lB = frame().toLocal(Vector3DBase<double, GlobalTag>(Bx,By,Bz));
00048     fieldValues.push_back(BVector(lB.x(), lB.y(), lB.z()));
00049   }
00050   // check completeness
00051   string lastEntry;
00052   inFile >> lastEntry;
00053   if (lastEntry != "complete"){
00054     cout << "ERROR during file reading: file is not complete" << endl;
00055   }
00056 
00057   GlobalPoint grefp( GlobalPoint::Cylindrical( xref, yref, zref));
00058 
00059 #ifdef DEBUG_GRID
00060   LocalPoint lrefp = frame().toLocal( grefp);
00061   cout << "Grid reference point in grid system: " << xref << "," << yref << "," << zref << endl;
00062   cout << "Grid reference point in global x,y,z: " << grefp << endl;
00063   cout << "Grid reference point in local x,y,z: " << lrefp << endl;
00064   cout << "steps " << stepx << "," <<  stepy << "," << stepz << endl;
00065   cout << "RParAsFunOfPhi[0...4] = ";
00066   for (int i=0; i<4; ++i) cout << RParAsFunOfPhi[i] << " "; cout << endl;
00067 #endif
00068 
00069   Grid1D<double> gridX( 0, n1-1, n1); // offset and step size not constant
00070   Grid1D<double> gridY( yref, yref + stepy*(n2-1), n2);
00071   Grid1D<double> gridZ( grefp.z(), grefp.z() + stepz*(n3-1), n3);
00072 
00073   grid_ = GridType( gridX, gridY, gridZ, fieldValues);
00074 
00075   stepConstTerm_ = (RParAsFunOfPhi[0] - RParAsFunOfPhi[2]) / (n1-1);
00076   stepPhiTerm_   = (RParAsFunOfPhi[1] - RParAsFunOfPhi[3]) / (n1-1);
00077   startConstTerm_ = RParAsFunOfPhi[2];
00078   startPhiTerm_   = RParAsFunOfPhi[3];
00079 
00080   // Activate/deactivate timers
00081 //   static SimpleConfigurable<bool> timerOn(false,"MFGrid:timing");
00082 //   (*TimingReport::current()).switchOn("MagneticFieldProvider::valueInTesla(SpecialCylindricalMFGrid)",timerOn);
00083 }
00084  
00085 
00086 MFGrid::LocalVector SpecialCylindricalMFGrid::uncheckedValueInTesla( const LocalPoint& p) const
00087 {
00088 //   static TimingReport::Item & timer= (*TimingReport::current())["MagneticFieldProvider::valueInTesla(SpecialCylindricalMFGrid)"];
00089 //   TimeMe t(timer,false);
00090 
00091   LinearGridInterpolator3D<GridType::ValueType, GridType::Scalar> interpol( grid_);
00092   double a, b, c;
00093   toGridFrame( p, a, b, c);
00094   // the following holds if B values was not converted to local coords -- see ctor
00095 //   GlobalVector gv( interpol.interpolate( a, b, c)); // grid in global frame
00096 //   return frame().toLocal(gv);           // must return a local vector
00097   return LocalVector(interpol.interpolate( a, b, c));
00098 }
00099 
00100 void SpecialCylindricalMFGrid::dump() const {}
00101 
00102 
00103 MFGrid::LocalPoint SpecialCylindricalMFGrid::fromGridFrame( double a, double b, double c) const
00104 {
00105   double sinPhi; // sin or cos depending on wether we are at phi=0 or phi=pi/2
00106   if (sector1) {
00107     sinPhi = cos(b);
00108   } else {
00109     sinPhi = sin(b);
00110   }
00111   
00112   double R = a*stepSize(sinPhi) + startingPoint(sinPhi);
00113   // "OLD" convention of phi.
00114   //  GlobalPoint gp( GlobalPoint::Cylindrical(R, Geom::pi() - b, c));
00115   GlobalPoint gp( GlobalPoint::Cylindrical(R, b, c));
00116   return frame().toLocal(gp);
00117 }
00118 
00119 void SpecialCylindricalMFGrid::toGridFrame( const LocalPoint& p, 
00120                                             double& a, double& b, double& c) const
00121 {
00122   GlobalPoint gp = frame().toGlobal(p);
00123   double sinPhi; // sin or cos depending on wether we are at phi=0 or phi=pi/2
00124   if (sector1) {
00125     sinPhi = cos(gp.phi());
00126   } else {
00127     sinPhi = sin(gp.phi());
00128   }
00129   a = (gp.perp()-startingPoint(sinPhi))/stepSize(sinPhi);
00130   // FIXME: "OLD" convention of phi.
00131   // b = Geom::pi() - gp.phi();
00132   b = gp.phi();
00133   c = gp.z();
00134 
00135 #ifdef DEBUG_GRID
00136   if (sector1) {
00137     cout << "toGridFrame: sinPhi " ;
00138   } else {
00139     cout << "toGridFrame: cosPhi " ;
00140   }
00141   cout << sinPhi << " LocalPoint " << p 
00142        << " GlobalPoint " << gp << endl 
00143        << " a " << a << " b " << b << " c " << c << endl;
00144     
00145 #endif
00146 }
00147 

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