StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StHelixHelper.cxx
1 
5 /***************************************************************************
6  *
7  * $Id: StHelixHelper.cxx,v 1.2 2017/04/26 21:08:28 perev Exp $
8  *
9  * Author: Valeri Fine, July 2009
10  ***************************************************************************/
11 #include "StHelixHelper.h"
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <assert.h>
15 #if ROOT_VERSION_CODE < 331013
16 # include "TCL.h"
17 #else
18 # include "TCernLib.h"
19 #endif
20 #include "TMath.h"
21 #include "TVirtualPad.h"
22 #include "TView.h"
23 
24 #include "StObject.h"
25 #include "THelixTrack.h"
26 #include "StPhysicalHelixD.hh"
27 
31 //______________________________________________________________________________
32 ClassImp(StHelixHelper)
34  ,const StPhysicalHelix &outerHelix, double length)
35  :fLength(length)
36 {
37  fHelx[0]=new StPhysicalHelixD(helix);
38  fHelx[1]=new StPhysicalHelixD(outerHelix);
39  fTHlx[0]=0; fTHlx[1]=0;
40 }
41 
42 //______________________________________________________________________________
43 StHelixHelper::StHelixHelper() : TObject(),fLength(-1)
44 {
45  fHelx[0] = fHelx[1] = 0;
46  fTHlx[0] = fTHlx[1] = 0;
47 }
48 
49 //______________________________________________________________________________
50 StHelixHelper::StHelixHelper(const StHelixHelper &helper) : TObject (helper)
51  ,fLength(helper.fLength)
52 {
53  fHelx[0]=new StPhysicalHelixD(*helper.fHelx[0]);
54  fHelx[1]=new StPhysicalHelixD(*helper.fHelx[1]);
55 
56  fTHlx[0] = helper.fTHlx[0] ? new THelixTrack(*helper.fTHlx[0]) : 0;
57  fTHlx[1] = helper.fTHlx[1] ? new THelixTrack(*helper.fTHlx[1]) : 0;
58 
59 }
60 
61 //______________________________________________________________________________
62 StHelixHelper::~StHelixHelper()
63 {
64  delete fHelx[0];delete fHelx[1];
65  delete fTHlx[0];delete fTHlx[1];
66 }
67 //______________________________________________________________________________
68 float StHelixHelper::GetLength() const {return fLength;}
69 //______________________________________________________________________________
70 StPhysicalHelixD *StHelixHelper::GetHelix(int idx) const
71 {
72  return fHelx[idx];
73 }
74 //______________________________________________________________________________
75 THelixTrack *StHelixHelper::MyHelix(THelixTrack *myHlx,const StHelixD *evHlx)
76 {
77  if (!myHlx) myHlx= new THelixTrack;
78  double curv = evHlx->curvature();
79  double phase = evHlx->phase();
80  double dip = evHlx->dipAngle();
81  int h = evHlx->h();
82 
83  double myDir[3];
84  myDir[0]= -sin(phase)*cos(dip);
85  myDir[1]= cos(phase)*cos(dip);
86  myDir[2]= sin(dip);
87  if (h<0) {myDir[0]=-myDir[0]; myDir[1]=-myDir[1];}
88  double myX[3];
89  myX[0]= evHlx->x(0.);
90  myX[1]= evHlx->y(0.);
91  myX[2]= evHlx->z(0.);
92 
93  myHlx->Set(myX,myDir,curv*h);
94  return myHlx;
95 }
96 //______________________________________________________________________________
97 THelixTrack *StHelixHelper::GetTHelix(int idx) const
98 {
99  StPhysicalHelixD *hlx = GetHelix(idx);
100  fTHlx[idx] = StHelixHelper::MyHelix(fTHlx[idx],hlx);
101  return fTHlx[idx];
102 }
103 
106 // the output arry to free the memory
107 //______________________________________________________________________________
108 Float_t *StHelixHelper::GetPoints(int &npoints) const
109 {
110  static int ndebug=0; ndebug++;
111  npoints=0;
112  double len,len0,len1;
113  len = GetLength();
114  if (len <= 0.0001) {
115  // Warning("GetPoints","Zero length %s(%p), IGNORED",fTrk->ClassName(),(void*)fTrk);
116  return 0;
117  }
118 
119  GetHelix(0); GetHelix(1);
120  for (int i=0;i<2;i++) {fTHlx[i] = StHelixHelper::MyHelix(fTHlx[i],fHelx[i]);}
121 
122  len0 = fTHlx[0]->Path(fTHlx[1]->Pos());
123  double rho0 = fTHlx[0]->GetRho();
124 // double rho1 = fTHlx[1]->GetRho();
125 // double drho = (rho1-rho0)/(len0*fTHlx[0]->GetCos());
126 // fTHlx[0]->Set(rho0,drho);
127 // fTHlx[1]->Set(rho1,drho);
128  fTHlx[1]->Backward();
129  npoints = abs(int(len*fTHlx[0]->GetCos()*rho0*90))+2;
130  double step = 1./(npoints-1);
131  len0 = fTHlx[0]->Path(fTHlx[1]->Pos());
132  len1 = fTHlx[1]->Path(fTHlx[0]->Pos());
133  float *arr = new Float_t[npoints*3];
134  double xyz[3][3];
135  for (int i =0;i<npoints;i++)
136  {
137  double s0 = i*step;
138  double s1 = 1.-s0;
139  fTHlx[0]->Eval(s0*len0,xyz[0]);
140  fTHlx[1]->Eval(s1*len1,xyz[1]);
141  s0 = s0*s0*s0; s1 = s1*s1*s1;
142  double tmp = s0+s1;
143  s0 /=tmp; s1 /=tmp;
144  TCL::vlinco(xyz[0],s1,xyz[1],s0,xyz[2],3);
145  TCL::ucopy(xyz[2],arr+i*3,3);
146  }
147  return arr;
148 }
double Eval(double step, double *xyz, double *dir, double &rho) const
Evaluate params with given step along helix.
int h() const
y-center of circle in xy-plane
Definition: StHelix.hh:174
double x(double s) const
coordinates of helix at point s
Definition: StHelix.hh:182
void Backward()
Change direction.
virtual Float_t * GetPoints(int &npoints) const
double phase() const
1/R in xy-plane
Definition: StHelix.hh:180