EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrKalmanNode.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrKalmanNode.cxx
1 //
2 // AYK (ayk@bnl.gov)
3 //
4 // Forward detector tracking application of the Kalman filter stuff;
5 // ported from HERMES/OLYMPUS sources; cleaned up 2014/10/17;
6 //
7 
8 #include <cassert>
9 #include <cstdlib>
10 
11 #include <htclib.h>
12 
13 #include <MediaBank.h>
14 #include <MediaSliceArray.h>
15 #include <TrKalmanNode.h>
16 
17 // 1/p will be varied by this fraction; FIXME: do it better later;
18 #define _PSTEP_ (0.001)
19 
20 // =======================================================================================
21 
22 int TrKalmanNode::PerformRungeKuttaStep(KalmanFilter::Direction fb, double pout[], double rkd[5][5])
23 {
24  // Shape up request frame;
26  KalmanNode *to = GetNext(fb);
27 
28  // These parameters will not change;
29  rq.z0 = GetZ();
30  rq.h = to->GetZ() - GetZ();
31  rq.rk = mLocation->mRungeKutta + fb;
32 
33  {
34  double in[5], q0 = mInversedMomentum;
35  int ret = rq.serveRequest(x0->ARR(), q0, pout, 0);
36 
37  // Otherwise derivatives are of no interest;
38  if (rkd)
39  {
40  // Calculate drv_steps[4] by hand;
41  double drv_steps_qp = fabs(q0)*_PSTEP_;
42 
43  // Calculate derivatives vs <1/p>;
44  if (rq.serveRequest(x0->ARR(), q0 + drv_steps_qp, rkd[4], 1)) ret = -1;
45 
46  for(int ip=0; ip<4; ip++)
47  {
48  for(int iq=0; iq<4; iq++)
49  in[iq] = GetX0(iq) + (ip == iq ? _drv_steps[iq] : 0.0);
50 
51  if (rq.serveRequest(in, q0, rkd[ip], 1)) ret = -1;
52  } /*for iq*/
53 
54  for(int ip=0; ip<5; ip++)
55  for(int iq=0; iq<4; iq++)
56  {
57  rkd[ip][iq] -= pout [iq];
58  rkd[ip][iq] /= (ip == 4 ? drv_steps_qp : _drv_steps[ip]);
59  } /*for ip..iq*/
60  } /*if*/
61 
62  // Yes, return 0 in all cases; just set field_missing_flags[] in case
63  // of problems;
64  return 0;
65  }
66 } // TrKalmanNode::PerformRungeKuttaStep()
67 
68 // ---------------------------------------------------------------------------------------
69 
70 int TrKalmanNode::GetMagneticField(double xy[2], TVector3 &B)
71 {
72  TVector3 xx(xy[0], xy[1], GetZ());
73  // Does not matter which one; take KalmanFilter::Forward;
75 
76  // Put a lousy fix here; figure out what's wrong later;
77  if (rk && rk->m1)
78  return rk->m1->mGrid->getCartesianFieldValue(xx, B);
79  else {
80  VZERO(B);
81  return -1;
82  } //if
83 } // TrKalmanNode::GetMagneticField()
84 // ---------------------------------------------------------------------------------------
85 
87 {
88  for(unsigned iq=0; iq<mDim; iq++)
89  V->KFM(iq, iq) *= pow(scale, 2);
90 } // TrKalmanNode::InflateMeasurementNoise()
91 
92 // =======================================================================================