CMS 3D CMS Logo

TrapezoidalCylindricalMFGrid.cc
Go to the documentation of this file.
2 #include "binary_ifstream.h"
5 
6 #include <iostream>
7 
8 using namespace std;
9 
11  const GloballyPositioned<float>& vol)
12  : MFGrid3D(vol)
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: TrapezoidalCylindricalMFGrid: 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  double BasicDistance1[3][3]; // linear step
38  double BasicDistance2[3][3]; // linear offset
39  bool easya, easyb, easyc;
40 
41  inFile >> BasicDistance1[0][0] >> BasicDistance1[1][0] >> BasicDistance1[2][0];
42  inFile >> BasicDistance1[0][1] >> BasicDistance1[1][1] >> BasicDistance1[2][1];
43  inFile >> BasicDistance1[0][2] >> BasicDistance1[1][2] >> BasicDistance1[2][2];
44  inFile >> BasicDistance2[0][0] >> BasicDistance2[1][0] >> BasicDistance2[2][0];
45  inFile >> BasicDistance2[0][1] >> BasicDistance2[1][1] >> BasicDistance2[2][1];
46  inFile >> BasicDistance2[0][2] >> BasicDistance2[1][2] >> BasicDistance2[2][2];
47  inFile >> easya >> easyb >> easyc;
48 
49  vector<BVector> fieldValues;
50  float Bx, By, Bz;
51  int nLines = n1*n2*n3;
52  fieldValues.reserve(nLines);
53  for (int iLine=0; iLine<nLines; ++iLine){
54  inFile >> Bx >> By >> Bz;
55  fieldValues.push_back(BVector(Bx,By,Bz));
56  }
57  // check completeness
58  string lastEntry;
59  inFile >> lastEntry;
60  if (lastEntry != "complete") {
61  cout << "ERROR during file reading: file is not complete" << endl;
62  }
63 
64 #ifdef DEBUG_GRID
65  cout << "easya " << easya << " easyb " << easyb << " easyc " << easyc << endl;
66 #endif
67 
68  if (!easyb || !easyc) {
69  throw MagGeometryError("TrapezoidalCartesianMFGrid only implemented for first coordinate");
70  }
71 
72 #ifdef DEBUG_GRID
73  cout << "Grid reference point in grid system: " << xref << "," << yref << "," << zref << endl;
74  cout << "steps " << stepx << "," << stepy << "," << stepz << endl;
75  cout << "ns " << n1 << "," << n2 << "," << n3 << endl;
76 
77  for (int i=0; i<3; ++i) for (int j=0; j<3; ++j) {
78  cout << "BasicDistance1[" << i << "][" << j << "] = " << BasicDistance1[i][j]
79  << "BasicDistance2[" << i << "][" << j << "] = " << BasicDistance2[i][j] << endl;
80  }
81 #endif
82 
83  // the "not easy" coordinate is x
84  double a = stepx * (n1 -1);
85  double b = a + BasicDistance1[0][1] * (n2-1)*(n1-1) + BasicDistance1[0][2] * (n3-1)*(n1-1);
86  // double h = stepy * (n2-1);
87  double h = stepz * (n3-1);
88  double delta = -BasicDistance2[0][1] * (n2-1) -BasicDistance2[0][2] * (n3-1);
89 
90 #ifdef DEBUG_GRID
91  cout << "Trapeze size (a,b,h) = " << a << "," << b << "," << h << endl;
92 #endif
93 
94  GlobalPoint grefp( GlobalPoint::Cylindrical( xref, Geom::pi() - yref, zref));
95  LocalPoint lrefp = frame().toLocal( grefp);
96 
97 #ifdef DEBUG_GRID
98  cout << "Global origin " << grefp << endl;
99  cout << "Local origin " << lrefp << endl;
100 #endif
101 
102  double baMinus1 = BasicDistance1[0][2]*(n3-1) / stepx;
103  if (std::abs(baMinus1) > 0.000001) {
104  double b_over_a = 1 + baMinus1;
105  double a1 = std::abs(baMinus1) > 0.000001 ? delta / baMinus1 : a/2;
106 #ifdef DEBUG_GRID
107  cout << "a1 = " << a1 << endl;
108 #endif
109 
110  // transform reference point to grid frame
111  double x0 = lrefp.perp() + a1;
112  double y0 = lrefp.z() + h/2.;
113  mapping_ = Trapezoid2RectangleMappingX( x0, y0, b_over_a, h);
114  }
115  else { // parallelogram
116  mapping_ = Trapezoid2RectangleMappingX( 0, 0, delta/h);
117  }
118  double xrec, yrec;
119  mapping_.rectangle( lrefp.perp(), lrefp.z(), xrec, yrec);
120 
121  Grid1D gridX( xrec, xrec + (a+b)/2., n1);
122  Grid1D gridY( yref, yref + stepy*(n2-1), n2);
123  Grid1D gridZ( yrec, yrec + h, n3);
124  grid_ = GridType( gridX, gridY, gridZ, fieldValues);
125 
126  // Activate/deactivate timers
127 // static SimpleConfigurable<bool> timerOn(false,"MFGrid:timing");
128 // (*TimingReport::current()).switchOn("MagneticFieldProvider::valueInTesla(TrapezoidalCylindricalMFGrid)",timerOn);
129 }
130 
132 {}
133 
136 {
137 // static TimingReport::Item & timer= (*TimingReport::current())["MagneticFieldProvider::valueInTesla(TrapezoidalCylindricalMFGrid)"];
138 // TimeMe t(timer,false);
139 
140  LinearGridInterpolator3D interpol( grid_);
141  double a, b, c;
142  toGridFrame( p, a, b, c);
143  GlobalVector gv( interpol.interpolate( a, b, c)); // grid in global frame
144  return frame().toLocal(gv); // must return a local vector
145 }
146 
148  double& a, double& b, double& c) const
149 {
150  mapping_.rectangle( p.perp(), p.z(), a, c);
151  // FIXME: "OLD" convention of phi.
152  // b = Geom::pi() - p.phi();
153  b = p.phi();
154 }
155 
157 TrapezoidalCylindricalMFGrid::fromGridFrame( double a, double b, double c) const
158 {
159  double rtrap, ztrap;
160  mapping_.trapezoid( a, c, rtrap, ztrap);
161  // FIXME: "OLD" convention of phi.
162  // return LocalPoint(LocalPoint::Cylindrical(rtrap, Geom::pi() - b, ztrap));
163  return LocalPoint(LocalPoint::Cylindrical(rtrap, b, ztrap));
164 }
dbl * delta
Definition: mlp_gen.cc:36
void trapezoid(double xrec, double yrec, double &xtrap, double &ytrap) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void toGridFrame(const LocalPoint &p, double &a, double &b, double &c) const override
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)
void rectangle(double xtrap, double ytrap, double &xrec, double &yrec) const
LocalVector uncheckedValueInTesla(const LocalPoint &p) const override
Interpolated field value at given point; does not check for exceptions.
LocalPoint toLocal(const GlobalPoint &gp) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TrapezoidalCylindricalMFGrid(binary_ifstream &istr, const GloballyPositioned< float > &vol)
Trapezoid2RectangleMappingX mapping_
LocalPoint fromGridFrame(double a, double b, double c) const override
find grid coordinates for point. For debugging and validation only.
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
constexpr double pi()
Definition: Pi.h:31