Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "RectangularCartesianMFGrid.h"
0002 #include "MagneticField/Interpolation/interface/binary_ifstream.h"
0003 #include "LinearGridInterpolator3D.h"
0004 
0005 #include <iostream>
0006 
0007 using namespace std;
0008 
0009 RectangularCartesianMFGrid::RectangularCartesianMFGrid(binary_ifstream& inFile, const GloballyPositioned<float>& vol)
0010     : MFGrid3D(vol) {
0011   // The parameters read from the data files are given in global coordinates.
0012   // In version 85l, local frame has the same orientation of global frame for the reference
0013   // volume, i.e. the r.f. transformation is only a translation.
0014   // There is therefore no need to convert the field values to local coordinates.
0015   // Check this assumption:
0016   GlobalVector localXDir(frame().toGlobal(LocalVector(1, 0, 0)));
0017   GlobalVector localYDir(frame().toGlobal(LocalVector(0, 1, 0)));
0018 
0019   if (localXDir.dot(GlobalVector(1, 0, 0)) > 0.999999 && localYDir.dot(GlobalVector(0, 1, 0)) > 0.999999) {
0020     // "null" rotation - requires no conversion...
0021   } else {
0022     cout << "ERROR: RectangularCartesianMFGrid: unexpected orientation: x: " << localXDir << " y: " << localYDir
0023          << endl;
0024   }
0025 
0026   int n1, n2, n3;
0027   inFile >> n1 >> n2 >> n3;
0028   double xref, yref, zref;
0029   inFile >> xref >> yref >> zref;
0030   double stepx, stepy, stepz;
0031   inFile >> stepx >> stepy >> stepz;
0032 
0033   vector<BVector> fieldValues;
0034   float Bx, By, Bz;
0035   int nLines = n1 * n2 * n3;
0036   fieldValues.reserve(nLines);
0037   for (int iLine = 0; iLine < nLines; ++iLine) {
0038     inFile >> Bx >> By >> Bz;
0039     fieldValues.push_back(BVector(Bx, By, Bz));
0040   }
0041   // check completeness
0042   string lastEntry;
0043   inFile >> lastEntry;
0044   if (lastEntry != "complete") {
0045     cout << "ERROR during file reading: file is not complete" << endl;
0046   }
0047 
0048   GlobalPoint grefp(xref, yref, zref);
0049   LocalPoint lrefp = frame().toLocal(grefp);
0050 
0051   Grid1D gridX(lrefp.x(), lrefp.x() + stepx * (n1 - 1), n1);
0052   Grid1D gridY(lrefp.y(), lrefp.y() + stepy * (n2 - 1), n2);
0053   Grid1D gridZ(lrefp.z(), lrefp.z() + stepz * (n3 - 1), n3);
0054   grid_ = GridType(gridX, gridY, gridZ, fieldValues);
0055 
0056   // Activate/deactivate timers
0057   //   static SimpleConfigurable<bool> timerOn(false,"MFGrid:timing");
0058   //   (*TimingReport::current()).switchOn("MagneticFieldProvider::valueInTesla(RectangularCartesianMFGrid)",timerOn);
0059 }
0060 
0061 void RectangularCartesianMFGrid::dump() const {
0062   cout << endl << "Dump of RectangularCartesianMFGrid" << endl;
0063   //   cout << "Number of points from file   "
0064   //        << n1 << " " << n2 << " " << n3 << endl;
0065   cout << "Number of points from Grid1D " << grid_.grida().nodes() << " " << grid_.gridb().nodes() << " "
0066        << grid_.gridc().nodes() << endl;
0067 
0068   //   cout << "Reference Point from file   "
0069   //        << xref << " " << yref << " " << zref << endl;
0070   cout << "Reference Point from Grid1D " << grid_.grida().lower() << " " << grid_.gridb().lower() << " "
0071        << grid_.gridc().lower() << endl;
0072 
0073   //   cout << "Basic Distance from file   "
0074   //        <<  stepx << " " << stepy << " " << stepz << endl;
0075   cout << "Basic Distance from Grid1D " << grid_.grida().step() << " " << grid_.gridb().step() << " "
0076        << grid_.gridc().step() << endl;
0077 
0078   cout << "Dumping " << grid_.data().size() << " field values " << endl;
0079   // grid_.dump();
0080 }
0081 
0082 MFGrid::LocalVector RectangularCartesianMFGrid::uncheckedValueInTesla(const LocalPoint& p) const {
0083   //   static TimingReport::Item & timer= (*TimingReport::current())["MagneticFieldProvider::valueInTesla(RectangularCartesianMFGrid)"];
0084   //   TimeMe t(timer,false);
0085 
0086   LinearGridInterpolator3D interpol(grid_);
0087   GridType::ReturnType value = interpol.interpolate(p.x(), p.y(), p.z());
0088   return LocalVector(value);
0089 }
0090 
0091 void RectangularCartesianMFGrid::toGridFrame(const LocalPoint& p, double& a, double& b, double& c) const {
0092   a = p.x();
0093   b = p.y();
0094   c = p.z();
0095 }
0096 
0097 MFGrid::LocalPoint RectangularCartesianMFGrid::fromGridFrame(double a, double b, double c) const {
0098   return LocalPoint(a, b, c);
0099 }