Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MyTrajectoryGrkuta.cc
Go to the documentation of this file.
1 #include "MyTrajectoryGrkuta.h"
2 #define M_CHARGED_PI 0.13957018
3 #define c 29.9792548
4 
5 #define TRACKING_RADIUS_MAX 60.0
6 #define TIME_STEP_SIZE 0.03
7 
9 
10 MyTrajectoryGrkuta::MyTrajectoryGrkuta(const HepVector B_in, int level) : MyTrajectoryBfield(B_in), debug_level(level) {
11 }
12 
14  int level)
15  : MyTrajectoryBfield(bfield_in, level), debug_level(level) {
16  return;
17 }
18 
19 extern "C" {
20  void grkuta_(float* charge, float* step, float* vect, float* vout);
21  void gufld_(float* x, float* f);
22 }
23 
24 // The following member function is a cut and paste from
25 // MyTrajectoryBfield. Is there a better way?
26 
27 void MyTrajectoryGrkuta::swim(const HepVector& param) {
28  double xp0, z0, theta0, phi0, ptinv;
29  xp0 = param(1);
30  z0 = param(2);
31  theta0 = param(3);
32  phi0 = param(4);
33  ptinv = param(5);
34  MyTrajectoryGrkuta::swim(xp0, z0, theta0, phi0, ptinv);
35  return;
36 }
37 
38 void MyTrajectoryGrkuta::swim(double xp0, double z0, double theta, double phi,
39  double ptinv) {
40 
41  // store input parameters as member data
42  params(1) = xp0;
43  params(2) = z0;
44  params(3) = theta;
45  params(4) = phi;
46  params(5) = ptinv;
47  checkClear();
48 
49  double sinTheta = sin(theta);
50  double cosTheta = cos(theta);
51  double sinPhi = sin(phi);
52  double cosPhi = cos(phi);
53  double xStart = xp0*sinPhi; // = xp0*cos(alpha) where alpha = phi - pi/2
54  double yStart = -xp0*cosPhi; // = xp0*sin(alpha)
55  double zStart = z0;
56 
57  HepLorentzVector* thisVectorPtr;
58  float charge, step, vect[7], vout[7];
59  if (ptinv > 0.0) {charge = 1.0;} else {charge = -1.0;}
60  vect[0] = xStart; vect[1] = yStart; vect[2] = zStart;
61  vect[3] = sinTheta*cosPhi; vect[4] = sinTheta*sinPhi; vect[5] = cosTheta;
62  double ptot = abs(1.0/(ptinv*sinTheta));
63  vect[6] = ptot;
64  double energy = sqrt(M_CHARGED_PI*M_CHARGED_PI + ptot*ptot);
65  double gamma = energy/M_CHARGED_PI;
66  double beta = sqrt(1.0 - 1.0/(gamma*gamma));
67  double tStep = TIME_STEP_SIZE;
68  double ctStep = c*tStep;
69  step = (float)(beta*ctStep);
70  double ct = 0.0;
71  globalGrkutaPtr = this;
72  thisVectorPtr = new HepLorentzVector;
73  thisVectorPtr->setX(vect[0]);
74  thisVectorPtr->setY(vect[1]);
75  thisVectorPtr->setZ(vect[2]);
76  thisVectorPtr->setT(ct);
77  traj.push_back(thisVectorPtr);
78  for (int i = 0; i < 2000; i++) {
79  grkuta_(&charge, &step, vect, vout);
80  ct += ctStep;
81  thisVectorPtr = new HepLorentzVector;
82  thisVectorPtr->setX(vout[0]);
83  thisVectorPtr->setY(vout[1]);
84  thisVectorPtr->setZ(vout[2]);
85  thisVectorPtr->setT(ct);
86  if (debug_level > 3) cout << setprecision(14) << "MyTrajectoryGrcuta::swim: i = " << i << " LorentzVector = " << *thisVectorPtr << endl;
87  traj.push_back(thisVectorPtr);
88  if (sqrt(vout[0]*vout[0] + vout[1]*vout[1]) > TRACKING_RADIUS_MAX) break;
89  for (int j = 0; j < 7; j++) {vect[j] = vout[j];}
90  }
91  return;
92 }
93 
94 void gufld_(float* x, float* f) {
95  const double kGperT = 10.0; // kilogauss per Tesla
96  HepVector r(3);
97  r(1) = (double)x[0];
98  r(2) = (double)x[1];
99  r(3) = (double)x[2];
100  HepVector B = globalGrkutaPtr->getField(r);
101  f[0] = kGperT*B(1);
102  f[1] = kGperT*B(2);
103  f[2] = kGperT*B(3);
104  return;
105 }
void gufld_(float *x, float *f)
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
#define c
HepVector getField(HepVector &r)
MyTrajectoryGrkuta * globalGrkutaPtr
#define TIME_STEP_SIZE
#define TRACKING_RADIUS_MAX
vector< HepLorentzVector * > traj
Definition: MyTrajectory.h:40
TF1 * f
Definition: FitGains.C:21
MyTrajectoryGrkuta(const DMagneticFieldMap *bfield, int level=1)
void checkClear()
void swim(const HepVector &param)
#define M_CHARGED_PI
double sqrt(double)
double sin(double)
int grkuta_(double *CHARGE, double *STEP, double *VECT, double *VOUT, const DMagneticFieldMap *bfield)
Definition: grkuta.cc:270