CMS 3D CMS Logo

TkBfield.cc
Go to the documentation of this file.
1 #include "TkBfield.h"
2 
4 
5 // #include <iostream>
6 // #include <iomanip>
7 #include <cmath>
8 #include <algorithm>
9 
10 using namespace magfieldparam;
11 
12 namespace {
13 
14  const BCylParam<float> fpar1{
15  4.90541f, 17.8768f, 2.02355f, 0.0210538f, 0.000321885f, 2.37511f, 0.00326725f, 2.07656f, 1.71879f}; // 2.0T-2G
16  const BCylParam<float> fpar2{
17  4.41982f, 15.7732f, 3.02621f, 0.0197814f, 0.000515759f, 2.43385f, 0.00584258f, 2.11333f, 1.76079f}; // 3.0T-2G
18  const BCylParam<float> fpar3{
19  4.30161f, 15.2586f, 3.51926f, 0.0183494f, 0.000606773f, 2.45110f, 0.00709986f, 2.12161f, 1.77038f}; // 3.5T-2G
20  const BCylParam<float> fpar4{
21  4.24326f, 15.0201f, 3.81492f, 0.0178712f, 0.000656527f, 2.45818f, 0.00778695f, 2.12500f, 1.77436f}; // 3.8T-2G
22  const BCylParam<float> fpar5{
23  4.21136f, 14.8824f, 4.01683f, 0.0175932f, 0.000695541f, 2.45311f, 0.00813447f, 2.11688f, 1.76076f}; // 4.0T-2G
24  std::string const flds[] = {"2_0T", "3_0T", "3_5T", "3_8T", "4_0T"};
25  constexpr float flds_f[] = {2.0, 3.0, 3.5, 3.8, 4.0};
26  BCylParam<float> const fpars[]{fpar1, fpar2, fpar3, fpar4, fpar5};
27 
28  BCylParam<float> const& findPar(float fld) {
29  for (int i = 0; i < 5; ++i) {
30  if (fabs(fld - flds_f[i]) < 0.001) {
31  return fpars[i];
32  }
33  }
34  throw cms::Exception("BadParameters") << "Undefined field value " << fld;
35  }
36 
37  BCylParam<float> const& findPar(std::string fld) {
38  auto f = std::find(flds, flds + 5, fld);
39  if (f - flds > 4)
40  throw cms::Exception("BadParameters") << "Undefined key - " // abort!\n";
41  << "Defined keys are: \"2_0T\" \"3_0T\" \"3_5T\" \"3_8T\" and \"4_0T\"\n";
42  return fpars[f - flds];
43  }
44 
45 } // namespace
46 
47 TkBfield::TkBfield(float fld) : bcyl(findPar(fld)) {}
48 
49 TkBfield::TkBfield(std::string fld) : bcyl(findPar(fld)) {}
50 
51 void TkBfield::getBrfz(float const* __restrict__ x, float* __restrict__ Brfz) const {
52  float br;
53  float bz;
54  float r2 = x[0] * x[0] + x[1] * x[1];
55  bcyl(x[0] * x[0] + x[1] * x[1], x[2], br, bz);
56  Brfz[0] = std::sqrt(r2) * br;
57  Brfz[1] = 0;
58  Brfz[2] = bz;
59 }
60 
61 void TkBfield::getBxyz(float const* __restrict__ x, float* __restrict__ Bxyz) const {
62  float br;
63  float bz;
64  float r2 = x[0] * x[0] + x[1] * x[1];
65  bcyl(r2, x[2], br, bz);
66  Bxyz[0] = br * x[0];
67  Bxyz[1] = br * x[1];
68  Bxyz[2] = bz;
69 }
mps_fire.i
i
Definition: mps_fire.py:355
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
magfieldparam::TkBfield::getBrfz
void getBrfz(float const *__restrict__ x, float *__restrict__ Brfz) const
B out in cylindrical.
Definition: TkBfield.cc:51
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
TkBfield.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
magfieldparam
Definition: BCyl.h:23
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
beamvalidation.br
br
Definition: beamvalidation.py:398
magfieldparam::TkBfield::bcyl
BCycl< float > bcyl
Definition: TkBfield.h:38
magfieldparam::BCylParam< float >
magfieldparam::TkBfield::getBxyz
void getBxyz(float const *__restrict__ x, float *__restrict__ Bxyz) const
B out in cartesian.
Definition: TkBfield.cc:61
Exception
Definition: hltDiff.cc:246
Exception.h
magfieldparam::TkBfield::TkBfield
TkBfield(std::string T)
Definition: TkBfield.cc:49