CMS 3D CMS Logo

RectangularCartesianMFGrid.cc
Go to the documentation of this file.
2 #include "binary_ifstream.h"
4 
5 #include <iostream>
6 
7 using namespace std;
8 
10  const GloballyPositioned<float>& vol)
11  : MFGrid3D(vol)
12 {
13 
14  // The parameters read from the data files are given in global coordinates.
15  // In version 85l, local frame has the same orientation of global frame for the reference
16  // volume, i.e. the r.f. transformation is only a translation.
17  // There is therefore no need to convert the field values to local coordinates.
18  // Check this assumption:
19  GlobalVector localXDir(frame().toGlobal(LocalVector(1,0,0)));
20  GlobalVector localYDir(frame().toGlobal(LocalVector(0,1,0)));
21 
22  if (localXDir.dot(GlobalVector(1,0,0)) > 0.999999 &&
23  localYDir.dot(GlobalVector(0,1,0)) > 0.999999) {
24  // "null" rotation - requires no conversion...
25  } else {
26  cout << "ERROR: RectangularCartesianMFGrid: unexpected orientation: x: "
27  << localXDir << " y: " << localYDir << endl;
28  }
29 
30  int n1, n2, n3;
31  inFile >> n1 >> n2 >> n3;
32  double xref, yref, zref;
33  inFile >> xref >> yref >> zref;
34  double stepx, stepy, stepz;
35  inFile >> stepx >> stepy >> stepz;
36 
37  vector<BVector> fieldValues;
38  float Bx, By, Bz;
39  int nLines = n1*n2*n3;
40  fieldValues.reserve(nLines);
41  for (int iLine=0; iLine<nLines; ++iLine){
42  inFile >> Bx >> By >> Bz;
43  fieldValues.push_back(BVector(Bx,By,Bz));
44  }
45  // check completeness
46  string lastEntry;
47  inFile >> lastEntry;
48  if (lastEntry != "complete"){
49  cout << "ERROR during file reading: file is not complete" << endl;
50  }
51 
52  GlobalPoint grefp( xref, yref, zref);
53  LocalPoint lrefp = frame().toLocal( grefp);
54 
55  Grid1D gridX( lrefp.x(), lrefp.x() + stepx*(n1-1), n1);
56  Grid1D gridY( lrefp.y(), lrefp.y() + stepy*(n2-1), n2);
57  Grid1D gridZ( lrefp.z(), lrefp.z() + stepz*(n3-1), n3);
58  grid_ = GridType( gridX, gridY, gridZ, fieldValues);
59 
60  // Activate/deactivate timers
61 // static SimpleConfigurable<bool> timerOn(false,"MFGrid:timing");
62 // (*TimingReport::current()).switchOn("MagneticFieldProvider::valueInTesla(RectangularCartesianMFGrid)",timerOn);
63 
64 }
65 
67 {
68  cout << endl << "Dump of RectangularCartesianMFGrid" << endl;
69 // cout << "Number of points from file "
70 // << n1 << " " << n2 << " " << n3 << endl;
71  cout << "Number of points from Grid1D "
72  << grid_.grida().nodes() << " " << grid_.gridb().nodes() << " " << grid_.gridc().nodes() << endl;
73 
74 // cout << "Reference Point from file "
75 // << xref << " " << yref << " " << zref << endl;
76  cout << "Reference Point from Grid1D "
77  << grid_.grida().lower() << " " << grid_.gridb().lower() << " " << grid_.gridc().lower() << endl;
78 
79 // cout << "Basic Distance from file "
80 // << stepx << " " << stepy << " " << stepz << endl;
81  cout << "Basic Distance from Grid1D "
82  << grid_.grida().step() << " " << grid_.gridb().step() << " " << grid_.gridc().step() << endl;
83 
84 
85  cout << "Dumping " << grid_.data().size() << " field values " << endl;
86  // grid_.dump();
87 }
88 
91 {
92 // static TimingReport::Item & timer= (*TimingReport::current())["MagneticFieldProvider::valueInTesla(RectangularCartesianMFGrid)"];
93 // TimeMe t(timer,false);
94 
96  GridType::ReturnType value = interpol.interpolate( p.x(), p.y(), p.z());
97  return LocalVector(value);
98 }
99 
101  double& a, double& b, double& c) const
102 {
103  a = p.x();
104  b = p.y();
105  c = p.z();
106 }
107 
109 {
110  return LocalPoint( a, b, c);
111 }
Scalar step() const
Definition: Grid1D.h:21
RectangularCartesianMFGrid(binary_ifstream &istr, const GloballyPositioned< float > &vol)
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)
virtual LocalVector uncheckedValueInTesla(const LocalPoint &p) const
Interpolated field value at given point; does not check for exceptions.
virtual LocalPoint fromGridFrame(double a, double b, double c) const
find grid coordinates for point. For debugging and validation only.
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
Definition: value.py:1
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
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
const Grid1D & gridb() const
Definition: Grid3D.h:68