test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RectangularCylindricalMFGrid.cc
Go to the documentation of this file.
2 #include "binary_ifstream.h"
4 #include <iostream>
5 
6 using namespace std;
7 
9  const GloballyPositioned<float>& vol)
10  : MFGrid3D(vol)
11 {
12  // The parameters read from the data files are given in global coordinates.
13  // In version 85l, local frame has the same orientation of global frame for the reference
14  // volume, i.e. the r.f. transformation is only a translation.
15  // There is therefore no need to convert the field values to local coordinates.
16  // Check this assumption:
17  GlobalVector localXDir(frame().toGlobal(LocalVector(1,0,0)));
18  GlobalVector localYDir(frame().toGlobal(LocalVector(0,1,0)));
19 
20  if (localXDir.dot(GlobalVector(1,0,0)) > 0.999999 &&
21  localYDir.dot(GlobalVector(0,1,0)) > 0.999999) {
22  // "null" rotation - requires no conversion...
23  } else {
24  cout << "ERROR: RectangularCylindricalMFGrid: unexpected orientation: x: "
25  << localXDir << " y: " << localYDir << endl;
26  }
27 
28  int n1, n2, n3;
29  inFile >> n1 >> n2 >> n3;
30  double xref, yref, zref;
31  inFile >> xref >> yref >> zref;
32  double stepx, stepy, stepz;
33  inFile >> stepx >> stepy >> stepz;
34 
35  vector<BVector> fieldValues;
36  float Bx, By, Bz;
37  int nLines = n1*n2*n3;
38  fieldValues.reserve(nLines);
39  for (int iLine=0; iLine<nLines; ++iLine){
40  inFile >> Bx >> By >> Bz;
41  fieldValues.push_back(BVector(Bx,By,Bz));
42  }
43  // check completeness
44  string lastEntry;
45  inFile >> lastEntry;
46  if (lastEntry != "complete"){
47  cout << "ERROR during file reading: file is not complete" << endl;
48  }
49 
50  GlobalPoint grefp( GlobalPoint::Cylindrical( xref, yref, zref));
51  LocalPoint lrefp = frame().toLocal( grefp);
52 
53 #ifdef DEBUG_GRID
54  cout << "Grid reference point in grid system: " << xref << "," << yref << "," << zref << endl;
55  cout << "Grid reference point in global x,y,z: " << grefp << endl;
56  cout << "Grid reference point in local x,y,z: " << lrefp << endl;
57  cout << "steps " << stepx << "," << stepy << "," << stepz << endl;
58 #endif
59 
60  Grid1D gridX( lrefp.perp(), lrefp.perp() + stepx*(n1-1), n1);
61  //Grid1D gridY( lrefp.phi(), lrefp.phi() + stepy*(n2-1), n2); // wrong: gives zero
62  Grid1D gridY( yref, yref + stepy*(n2-1), n2);
63  Grid1D gridZ( lrefp.z(), lrefp.z() + stepz*(n3-1), n3);
64 
65  grid_ = GridType( gridX, gridY, gridZ, fieldValues);
66 
67 }
68 
70 {
71  cout << endl << "Dump of RectangularCylindricalMFGrid" << endl;
72  cout << "Number of points from Grid1D "
73  << grid_.grida().nodes() << " " << grid_.gridb().nodes() << " " << grid_.gridc().nodes() << endl;
74 
75  cout << "Reference Point from Grid1D "
76  << grid_.grida().lower() << " " << grid_.gridb().lower() << " " << grid_.gridc().lower() << endl;
77 
78  cout << "Basic Distance from Grid1D "
79  << grid_.grida().step() << " " << grid_.gridb().step() << " " << grid_.gridc().step() << endl;
80 
81 
82  cout << "Dumping " << grid_.data().size() << " field values " << endl;
83  // grid_.dump();
84 }
85 
87 {
88  const float minimalSignificantR = 1e-6; // [cm], points below this radius are treated as zero radius
89  float R = p.perp();
90  if (R < minimalSignificantR) {
91  if (grid_.grida().lower() < minimalSignificantR) {
92  int k = grid_.gridc().index(p.z());
93  double u = (p.z() - grid_.gridc().node(k)) / grid_.gridc().step();
94  LocalVector result((1-u)*grid_(0, 0, k) + u*grid_(0, 0, k+1));
95  return result;
96  }
97  }
98 
100  // FIXME: "OLD" convention of phi.
101  // GridType::ValueType value = interpol( R, Geom::pi() - p.phi(), p.z());
102  GridType::ReturnType value = interpol.interpolate( R, p.phi(), p.z());
103  return LocalVector(value);
104 }
105 
107  double& a, double& b, double& c) const
108 {
109  a = p.perp();
110  // FIXME: "OLD" convention of phi.
111  // b = Geom::pi() - p.phi();
112  b = p.phi();
113  c = p.z();
114 }
115 
117 {
118 
119  // FIXME: "OLD" convention of phi.
120  // return LocalPoint( LocalPoint::Cylindrical(a, Geom::pi() - b, c));
121  return LocalPoint( LocalPoint::Cylindrical(a, b, c));
122 }
Scalar step() const
Definition: Grid1D.h:21
const Grid1D & grida() const
Definition: Grid3D.h:67
virtual void toGridFrame(const LocalPoint &p, double &a, double &b, double &c) const
find grid coordinates for point. For debugging and validation only.
GloballyPositioned< float >::GlobalVector GlobalVector
Definition: MFGrid.h:33
GloballyPositioned< float >::LocalPoint LocalPoint
Definition: MFGrid.h:34
ReturnType interpolate(Scalar a, Scalar b, Scalar c)
Scalar node(int i) const
Definition: Grid1D.h:27
tuple result
Definition: mps_fire.py:84
int nodes() const
Definition: Grid1D.h:24
LocalPoint toLocal(const GlobalPoint &gp) const
const Grid1D & gridc() const
Definition: Grid3D.h:69
const Container & data() const
Definition: Grid3D.h:71
Scalar lower() const
Definition: Grid1D.h:22
GridType grid_
Definition: MFGrid3D.h:62
Definition: Grid1D.h:7
GloballyPositioned< float >::GlobalPoint GlobalPoint
Definition: MFGrid.h:32
Grid3D GridType
Definition: MFGrid3D.h:59
Grid3D::BVector BVector
Definition: MFGrid3D.h:60
double b
Definition: hdecay.h:120
virtual LocalPoint fromGridFrame(double a, double b, double c) const
find grid coordinates for point. For debugging and validation only.
GloballyPositioned< float >::LocalVector LocalVector
Definition: MFGrid.h:35
double a
Definition: hdecay.h:121
const GloballyPositioned< float > & frame() const
Local reference frame.
Definition: MFGrid.h:63
tuple cout
Definition: gather_cfg.py:145
RectangularCylindricalMFGrid(binary_ifstream &istr, const GloballyPositioned< float > &vol)
virtual LocalVector uncheckedValueInTesla(const LocalPoint &p) const
Interpolated field value at given point; does not check for exceptions.
int index(Scalar a, Scalar &f) const
Definition: Grid1D.h:34
const Grid1D & gridb() const
Definition: Grid3D.h:68