CMS 3D CMS Logo

PropagationMPlexCommon.cc
Go to the documentation of this file.
5 
6 #include "PropagationMPlex.h"
7 
8 //#define DEBUG
9 #include "Debug.h"
10 
11 namespace mkfit {
12 
13  // this version does not assume to know which elements are 0 or 1, so it does the full multiplication
14  void MultHelixPropFull(const MPlexLL& A, const MPlexLS& B, MPlexLL& C) {
15  for (int n = 0; n < NN; ++n) {
16  for (int i = 0; i < 6; ++i) {
17 // optimization reports indicate only the inner two loops are good
18 // candidates for vectorization
19 #pragma omp simd
20  for (int j = 0; j < 6; ++j) {
21  C(n, i, j) = 0.;
22  for (int k = 0; k < 6; ++k)
23  C(n, i, j) += A.constAt(n, i, k) * B.constAt(n, k, j);
24  }
25  }
26  }
27  }
28 
29  // this version does not assume to know which elements are 0 or 1, so it does the full mupltiplication
30  void MultHelixPropTranspFull(const MPlexLL& A, const MPlexLL& B, MPlexLS& C) {
31  for (int n = 0; n < NN; ++n) {
32  for (int i = 0; i < 6; ++i) {
33 // optimization reports indicate only the inner two loops are good
34 // candidates for vectorization
35 #pragma omp simd
36  for (int j = 0; j < 6; ++j) {
37  C(n, i, j) = 0.;
38  for (int k = 0; k < 6; ++k)
39  C(n, i, j) += B.constAt(n, i, k) * A.constAt(n, j, k);
40  }
41  }
42  }
43  }
44 
45 #ifdef UNUSED
46  // this version does not assume to know which elements are 0 or 1, so it does the full multiplication
47  void MultHelixPropFull(const MPlexLL& A, const MPlexLL& B, MPlexLL& C) {
48 #pragma omp simd
49  for (int n = 0; n < NN; ++n) {
50  for (int i = 0; i < 6; ++i) {
51  for (int j = 0; j < 6; ++j) {
52  C(n, i, j) = 0.;
53  for (int k = 0; k < 6; ++k)
54  C(n, i, j) += A.constAt(n, i, k) * B.constAt(n, k, j);
55  }
56  }
57  }
58  }
59 
60  // this version does not assume to know which elements are 0 or 1, so it does the full mupltiplication
61  void MultHelixPropTranspFull(const MPlexLL& A, const MPlexLL& B, MPlexLL& C) {
62 #pragma omp simd
63  for (int n = 0; n < NN; ++n) {
64  for (int i = 0; i < 6; ++i) {
65  for (int j = 0; j < 6; ++j) {
66  C(n, i, j) = 0.;
67  for (int k = 0; k < 6; ++k)
68  C(n, i, j) += B.constAt(n, i, k) * A.constAt(n, j, k);
69  }
70  }
71  }
72  }
73 #endif
74 
75  //==============================================================================
76 
77  void applyMaterialEffects(const MPlexQF& hitsRl,
78  const MPlexQF& hitsXi,
79  const MPlexQF& propSign,
80  const MPlexHV& plNrm,
81  MPlexLS& outErr,
82  MPlexLV& outPar,
83  const int N_proc) {
84 #pragma omp simd
85  for (int n = 0; n < NN; ++n) {
86  if (n >= N_proc)
87  continue;
88  float radL = hitsRl.constAt(n, 0, 0);
89  if (radL < 1e-13f)
90  continue; //ugly, please fixme
91  const float theta = outPar.constAt(n, 5, 0);
92  // const float pt = 1.f / outPar.constAt(n, 3, 0); //fixme, make sure it is positive?
93  const float ipt = outPar.constAt(n, 3, 0);
94  const float pt = 1.f / ipt; //fixme, make sure it is positive?
95  const float ipt2 = ipt * ipt;
96  const float p = pt / std::sin(theta);
97  const float pz = p * std::cos(theta);
98  const float p2 = p * p;
99  constexpr float mpi = 0.140; // m=140 MeV, pion
100  constexpr float mpi2 = mpi * mpi; // m=140 MeV, pion
101  const float beta2 = p2 / (p2 + mpi2);
102  const float beta = std::sqrt(beta2);
103  //radiation lenght, corrected for the crossing angle (cos alpha from dot product of radius vector and momentum)
104  const float invCos =
105  p / std::abs(pt * std::cos(outPar.constAt(n, 4, 0)) * plNrm.constAt(n, 0, 0) +
106  pt * std::sin(outPar.constAt(n, 4, 0)) * plNrm.constAt(n, 1, 0) + pz * plNrm.constAt(n, 2, 0));
107  radL = radL * invCos; //fixme works only for barrel geom
108  // multiple scattering
109  //vary independently phi and theta by the rms of the planar multiple scattering angle
110  // XXX-KMD radL < 0, see your fixme above! Repeating bailout
111  if (radL < 1e-13f)
112  continue;
113  // const float thetaMSC = 0.0136f*std::sqrt(radL)*(1.f+0.038f*std::log(radL))/(beta*p);// eq 32.15
114  // const float thetaMSC2 = thetaMSC*thetaMSC;
115  const float thetaMSC = 0.0136f * (1.f + 0.038f * std::log(radL)) / (beta * p); // eq 32.15
116  const float thetaMSC2 = thetaMSC * thetaMSC * radL;
117  if /*constexpr*/ (Config::usePtMultScat) {
118  outErr.At(n, 3, 3) += thetaMSC2 * pz * pz * ipt2 * ipt2;
119  outErr.At(n, 3, 5) -= thetaMSC2 * pz * ipt2;
120  outErr.At(n, 4, 4) += thetaMSC2 * p2 * ipt2;
121  outErr.At(n, 5, 5) += thetaMSC2;
122  } else {
123  outErr.At(n, 4, 4) += thetaMSC2;
124  outErr.At(n, 5, 5) += thetaMSC2;
125  }
126  //std::cout << "beta=" << beta << " p=" << p << std::endl;
127  //std::cout << "multiple scattering thetaMSC=" << thetaMSC << " thetaMSC2=" << thetaMSC2 << " radL=" << radL << std::endl;
128  //std::cout << "radL=" << hitsRl.constAt(n, 0, 0) << " beta=" << beta << " invCos=" << invCos << " radLCorr=" << radL << " thetaMSC=" << thetaMSC << " thetaMSC2=" << thetaMSC2 << std::endl;
129  // energy loss
130  // XXX-KMD beta2 = 1 => 1 / sqrt(0)
131  // const float gamma = 1.f/std::sqrt(1.f - std::min(beta2, 0.999999f));
132  // const float gamma2 = gamma*gamma;
133  const float gamma2 = (p2 + mpi2) / mpi2;
134  const float gamma = std::sqrt(gamma2); //1.f/std::sqrt(1.f - std::min(beta2, 0.999999f));
135  constexpr float me = 0.0005; // m=0.5 MeV, electron
136  const float wmax = 2.f * me * beta2 * gamma2 / (1.f + 2.f * gamma * me / mpi + me * me / (mpi * mpi));
137  constexpr float I = 16.0e-9 * 10.75;
138  const float deltahalf = std::log(28.816e-9f * std::sqrt(2.33f * 0.498f) / I) + std::log(beta * gamma) - 0.5f;
139  const float dEdx =
140  beta < 1.f
141  ? (2.f * (hitsXi.constAt(n, 0, 0) * invCos *
142  (0.5f * std::log(2.f * me * beta2 * gamma2 * wmax / (I * I)) - beta2 - deltahalf) / beta2))
143  : 0.f; //protect against infs and nans
144  // dEdx = dEdx*2.;//xi in cmssw is defined with an extra factor 0.5 with respect to formula 27.1 in pdg
145  //std::cout << "dEdx=" << dEdx << " delta=" << deltahalf << " wmax=" << wmax << " Xi=" << hitsXi.constAt(n,0,0) << std::endl;
146  const float dP = propSign.constAt(n, 0, 0) * dEdx / beta;
147  outPar.At(n, 3, 0) = p / (std::max(p - dP, 0.001f) * pt); //stay above 1MeV
148  //assume 100% uncertainty
149  outErr.At(n, 3, 3) += dP * dP / (p2 * pt * pt);
150  }
151  }
152 
153 } // namespace mkfit
Matriplex::Matriplex< float, LL, LL, NN > MPlexLL
Definition: Matrix.h:53
Definition: APVGainStruct.h:7
Matriplex::Matriplex< float, HH, 1, NN > MPlexHV
Definition: Matrix.h:58
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void applyMaterialEffects(const MPlexQF &hitsRl, const MPlexQF &hitsXi, const MPlexQF &propSign, const MPlexHV &plNrm, MPlexLS &outErr, MPlexLV &outPar, const int N_proc)
Matriplex::Matriplex< float, LL, 1, NN > MPlexLV
Definition: Matrix.h:54
T sqrt(T t)
Definition: SSEVec.h:23
constexpr Matriplex::idx_t NN
Definition: Matrix.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void MultHelixPropFull(const MPlexLL &A, const MPlexLS &B, MPlexLL &C)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::complex< double > I
Definition: I.h:8
double f[11][100]
bool usePtMultScat
Definition: Config.cc:8
Matriplex::Matriplex< float, 1, 1, NN > MPlexQF
Definition: Matrix.h:80
void MultHelixPropTranspFull(const MPlexLL &A, const MPlexLL &B, MPlexLS &C)
Matriplex::MatriplexSym< float, LL, NN > MPlexLS
Definition: Matrix.h:55
Definition: APVGainStruct.h:7
__host__ __device__ V V wmax