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  // The parameters read from the data files are given in global coordinates.
14  // In version 85l, local frame has the same orientation of global frame for the reference
15  // volume, i.e. the r.f. transformation is only a translation.
16  // There is therefore no need to convert the field values to local coordinates.
17  // Check this assumption:
18  GlobalVector localXDir(frame().toGlobal(LocalVector(1, 0, 0)));
19  GlobalVector localYDir(frame().toGlobal(LocalVector(0, 1, 0)));
20 
21  if (localXDir.dot(GlobalVector(1, 0, 0)) > 0.999999 && localYDir.dot(GlobalVector(0, 1, 0)) > 0.999999) {
22  // "null" rotation - requires no conversion...
23  } else {
24  cout << "ERROR: TrapezoidalCylindricalMFGrid: unexpected orientation: x: " << localXDir << " y: " << localYDir
25  << 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  double BasicDistance1[3][3]; // linear step
36  double BasicDistance2[3][3]; // linear offset
37  bool easya, easyb, easyc;
38 
39  inFile >> BasicDistance1[0][0] >> BasicDistance1[1][0] >> BasicDistance1[2][0];
40  inFile >> BasicDistance1[0][1] >> BasicDistance1[1][1] >> BasicDistance1[2][1];
41  inFile >> BasicDistance1[0][2] >> BasicDistance1[1][2] >> BasicDistance1[2][2];
42  inFile >> BasicDistance2[0][0] >> BasicDistance2[1][0] >> BasicDistance2[2][0];
43  inFile >> BasicDistance2[0][1] >> BasicDistance2[1][1] >> BasicDistance2[2][1];
44  inFile >> BasicDistance2[0][2] >> BasicDistance2[1][2] >> BasicDistance2[2][2];
45  inFile >> easya >> easyb >> easyc;
46 
47  vector<BVector> fieldValues;
48  float Bx, By, Bz;
49  int nLines = n1 * n2 * n3;
50  fieldValues.reserve(nLines);
51  for (int iLine = 0; iLine < nLines; ++iLine) {
52  inFile >> Bx >> By >> Bz;
53  fieldValues.push_back(BVector(Bx, By, Bz));
54  }
55  // check completeness
56  string lastEntry;
57  inFile >> lastEntry;
58  if (lastEntry != "complete") {
59  cout << "ERROR during file reading: file is not complete" << endl;
60  }
61 
62 #ifdef DEBUG_GRID
63  cout << "easya " << easya << " easyb " << easyb << " easyc " << easyc << endl;
64 #endif
65 
66  if (!easyb || !easyc) {
67  throw MagGeometryError("TrapezoidalCartesianMFGrid only implemented for first coordinate");
68  }
69 
70 #ifdef DEBUG_GRID
71  cout << "Grid reference point in grid system: " << xref << "," << yref << "," << zref << endl;
72  cout << "steps " << stepx << "," << stepy << "," << stepz << endl;
73  cout << "ns " << n1 << "," << n2 << "," << n3 << endl;
74 
75  for (int i = 0; i < 3; ++i)
76  for (int j = 0; j < 3; ++j) {
77  cout << "BasicDistance1[" << i << "][" << j << "] = " << BasicDistance1[i][j] << "BasicDistance2[" << i << "]["
78  << j << "] = " << BasicDistance2[i][j] << endl;
79  }
80 #endif
81 
82  // the "not easy" coordinate is x
83  double a = stepx * (n1 - 1);
84  double b = a + BasicDistance1[0][1] * (n2 - 1) * (n1 - 1) + BasicDistance1[0][2] * (n3 - 1) * (n1 - 1);
85  // double h = stepy * (n2-1);
86  double h = stepz * (n3 - 1);
87  double delta = -BasicDistance2[0][1] * (n2 - 1) - BasicDistance2[0][2] * (n3 - 1);
88 
89 #ifdef DEBUG_GRID
90  cout << "Trapeze size (a,b,h) = " << a << "," << b << "," << h << endl;
91 #endif
92 
93  GlobalPoint grefp(GlobalPoint::Cylindrical(xref, Geom::pi() - yref, zref));
94  LocalPoint lrefp = frame().toLocal(grefp);
95 
96 #ifdef DEBUG_GRID
97  cout << "Global origin " << grefp << endl;
98  cout << "Local origin " << lrefp << endl;
99 #endif
100 
101  double baMinus1 = BasicDistance1[0][2] * (n3 - 1) / stepx;
102  if (std::abs(baMinus1) > 0.000001) {
103  double b_over_a = 1 + baMinus1;
104  double a1 = std::abs(baMinus1) > 0.000001 ? delta / baMinus1 : a / 2;
105 #ifdef DEBUG_GRID
106  cout << "a1 = " << a1 << endl;
107 #endif
108 
109  // transform reference point to grid frame
110  double x0 = lrefp.perp() + a1;
111  double y0 = lrefp.z() + h / 2.;
112  mapping_ = Trapezoid2RectangleMappingX(x0, y0, b_over_a, h);
113  } else { // parallelogram
115  }
116  double xrec, yrec;
117  mapping_.rectangle(lrefp.perp(), lrefp.z(), xrec, yrec);
118 
119  Grid1D gridX(xrec, xrec + (a + b) / 2., n1);
120  Grid1D gridY(yref, yref + stepy * (n2 - 1), n2);
121  Grid1D gridZ(yrec, yrec + h, n3);
122  grid_ = GridType(gridX, gridY, gridZ, fieldValues);
123 
124  // Activate/deactivate timers
125  // static SimpleConfigurable<bool> timerOn(false,"MFGrid:timing");
126  // (*TimingReport::current()).switchOn("MagneticFieldProvider::valueInTesla(TrapezoidalCylindricalMFGrid)",timerOn);
127 }
128 
130 
132  // static TimingReport::Item & timer= (*TimingReport::current())["MagneticFieldProvider::valueInTesla(TrapezoidalCylindricalMFGrid)"];
133  // TimeMe t(timer,false);
134 
136  double a, b, c;
137  toGridFrame(p, a, b, c);
138  GlobalVector gv(interpol.interpolate(a, b, c)); // grid in global frame
139  return frame().toLocal(gv); // must return a local vector
140 }
141 
142 void TrapezoidalCylindricalMFGrid::toGridFrame(const LocalPoint& p, double& a, double& b, double& c) const {
143  mapping_.rectangle(p.perp(), p.z(), a, c);
144  // FIXME: "OLD" convention of phi.
145  // b = Geom::pi() - p.phi();
146  b = p.phi();
147 }
148 
150  double rtrap, ztrap;
151  mapping_.trapezoid(a, c, rtrap, ztrap);
152  // FIXME: "OLD" convention of phi.
153  // return LocalPoint(LocalPoint::Cylindrical(rtrap, Geom::pi() - b, ztrap));
154  return LocalPoint(LocalPoint::Cylindrical(rtrap, b, ztrap));
155 }
GloballyPositioned< float >
Trapezoid2RectangleMappingX::rectangle
void rectangle(double xtrap, double ytrap, double &xrec, double &yrec) const
Definition: Trapezoid2RectangleMappingX.h:42
LinearGridInterpolator3D
Definition: LinearGridInterpolator3D.h:22
mps_fire.i
i
Definition: mps_fire.py:355
TrapezoidalCylindricalMFGrid.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MFGrid::LocalVector
GloballyPositioned< float >::LocalVector LocalVector
Definition: MFGrid.h:32
TrapezoidalCylindricalMFGrid::fromGridFrame
LocalPoint fromGridFrame(double a, double b, double c) const override
find grid coordinates for point. For debugging and validation only.
Definition: TrapezoidalCylindricalMFGrid.cc:149
TrapezoidalCylindricalMFGrid::toGridFrame
void toGridFrame(const LocalPoint &p, double &a, double &b, double &c) const override
find grid coordinates for point. For debugging and validation only.
Definition: TrapezoidalCylindricalMFGrid.cc:142
MagExceptions.h
TrapezoidalCylindricalMFGrid::mapping_
Trapezoid2RectangleMappingX mapping_
Definition: TrapezoidalCylindricalMFGrid.h:23
submitDQMOfflineCAF.nLines
nLines
Definition: submitDQMOfflineCAF.py:676
MFGrid::frame
const GloballyPositioned< float > & frame() const
Local reference frame.
Definition: MFGrid.h:60
MFGrid3D::GridType
Grid3D GridType
Definition: MFGrid3D.h:56
MFGrid3D::grid_
GridType grid_
Definition: MFGrid3D.h:59
h
Geom::Cylindrical2Cartesian
Definition: CoordinateSets.h:34
Grid1D
Definition: Grid1D.h:7
Geom::pi
constexpr double pi()
Definition: Pi.h:31
binary_ifstream
Definition: binary_ifstream.h:8
MFGrid3D::BVector
Grid3D::BVector BVector
Definition: MFGrid3D.h:57
MFGrid::LocalPoint
GloballyPositioned< float >::LocalPoint LocalPoint
Definition: MFGrid.h:31
b
double b
Definition: hdecay.h:118
Trapezoid2RectangleMappingX
Definition: Trapezoid2RectangleMappingX.h:21
a
double a
Definition: hdecay.h:119
Trapezoid2RectangleMappingX::trapezoid
void trapezoid(double xrec, double yrec, double &xtrap, double &ytrap) const
Definition: Trapezoid2RectangleMappingX.h:54
binary_ifstream.h
TrapezoidalCylindricalMFGrid::uncheckedValueInTesla
LocalVector uncheckedValueInTesla(const LocalPoint &p) const override
Interpolated field value at given point; does not check for exceptions.
Definition: TrapezoidalCylindricalMFGrid.cc:131
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
TrapezoidalCylindricalMFGrid::TrapezoidalCylindricalMFGrid
TrapezoidalCylindricalMFGrid(binary_ifstream &istr, const GloballyPositioned< float > &vol)
Definition: TrapezoidalCylindricalMFGrid.cc:10
MagGeometryError
Definition: MagExceptions.h:18
std
Definition: JetResolutionObject.h:76
MFGrid::GlobalVector
GloballyPositioned< float >::GlobalVector GlobalVector
Definition: MFGrid.h:30
GloballyPositioned::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Definition: GloballyPositioned.h:98
LinearGridInterpolator3D::interpolate
ReturnType interpolate(Scalar a, Scalar b, Scalar c)
Definition: LinearGridInterpolator3D.cc:11
LinearGridInterpolator3D.h
TrapezoidalCylindricalMFGrid::dump
void dump() const override
Definition: TrapezoidalCylindricalMFGrid.cc:129
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MFGrid3D
Definition: MFGrid3D.h:17
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MFGrid::GlobalPoint
GloballyPositioned< float >::GlobalPoint GlobalPoint
Definition: MFGrid.h:29