StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiPlacement.cxx
1 #include <math.h>
2 #include <stdio.h>
3 #include "StiPlacement.h"
4 
5 using namespace std;
6 
7 
8 //______________________________________________________________________________
9 StiPlacement::StiPlacement(){
10  normalRefAngle=0;
11  normalRadius=0;
12  normalYoffset=0;
13  centerRefAngle=0;
14  centerRadius=0;
15  centerOrientation=0;
16  layerRadius=0;
17  zCenter=0;
18  setNormalRep(0., 0., 0.);
19 }
20 //______________________________________________________________________________
21 StiPlacement::StiPlacement(float normRefAngle,float normRadius,float normYOffset,float centralZ)
22 {
23  setNormalRep(normRefAngle,normRadius,normYOffset);
24  zCenter = centralZ;
25  setLayerRadius(centerRadius);
26  layerAngle = centerRefAngle;
27  mRegion = kMidRapidity;
28 
29 }
30 
31 
43 StiPlacement::StiPlacement(const TGeoMatrix& transMatrix, const TVector3& localCenter, const TVector3& normal)
44 {
45  double centerXyzLocal[3] = {localCenter.X(), localCenter.Y(), localCenter.Z()};
46  double centerXyzGlobal[3] = {};
47 
48  double normalXyzLocal[3] = {normal.X() + localCenter.X(), normal.Y() + localCenter.Y(), normal.Z() + localCenter.Z()};
49  double normalXyzGlobal[3] = {};
50 
51  // Translate the local coordinates to the global coordinate system
52  transMatrix.LocalToMaster(centerXyzLocal, centerXyzGlobal);
53  transMatrix.LocalToMaster(normalXyzLocal, normalXyzGlobal);
54 
55  TVector3 centralVec(centerXyzGlobal);
56  TVector3 normalVec(normalXyzGlobal);
57 
58  // We actually need the normal vector from the center rather than from the
59  // origin
60  normalVec -= centralVec;
61 
62  if (normalVec.Dot(centralVec) < 0) normalVec *= -1;
63 
64  double deltaPhi = centralVec.DeltaPhi(normalVec);
65  double normalVecMag = fabs(centralVec.Perp() * cos(deltaPhi));
66 
67  setNormalRep(normalVec.Phi(), normalVecMag, centralVec.Perp()*sin(deltaPhi));
68  zCenter = centralVec.Z();
69  setLayerRadius(centerRadius);
70  layerAngle = centerRefAngle;
71  mRegion = kMidRapidity;
72 }
73 
74 
75 //______________________________________________________________________________
76 void StiPlacement::setNormalRep(float refAngle_, float radius_, float yOffset_)
77 {
78 
79  if (radius_ < 0) {
80  radius_ *= -1;
81  refAngle_ += M_PI;
82  yOffset_ *=-1.;
83  }
84  while(refAngle_ < -M_PI){ refAngle_ += 2.*M_PI; }
85  while(refAngle_ >= M_PI){ refAngle_ -= 2.*M_PI; }
86  normalRefAngle = refAngle_;
87 
88  normalRadius = radius_;
89  normalYoffset = yOffset_;
90 
91  // the checking above makes these values within bounds, also
92  centerRadius = ::sqrt(normalRadius*normalRadius + normalYoffset*normalYoffset);
93  centerOrientation = atan2(normalYoffset,normalRadius);
94  centerRefAngle = normalRefAngle + centerOrientation;
95  while(centerRefAngle < -M_PI){ centerRefAngle += 2.*M_PI; }
96  while(centerRefAngle >= M_PI){ centerRefAngle -= 2.*M_PI; }
97 
98 }// setNormalRep()
99 
100 //______________________________________________________________________________
101 void StiPlacement::setLayerAngle(float layerAng)
102 {
103  layerAngle = layerAng;
104  while (layerAngle< -M_PI) {layerAngle+=2*M_PI;}
105  while (layerAngle> M_PI) {layerAngle-=2*M_PI;}
106 }
107 
108 
109 //______________________________________________________________________________
110 ostream& operator<<(ostream& os, const StiPlacement& p)
111 {
112  os << "StiPlacement:" << endl
113  << "normalRefAngle: " << p.normalRefAngle << " rad, "
114  << "normalRadius: " << p.normalRadius << " cm, "
115  << "normalYoffset: " << p.normalYoffset << " cm" << endl
116  << "centerRefAngle: " << p.centerRefAngle << " rad, "
117  << "centerRadius: " << p.centerRadius << " cm, "
118  << "centerOrientation: " << p.centerOrientation << " rad" << endl
119  << "zCenter: " << p.zCenter << " cm, "
120  << "layerRadius: " << p.layerRadius << " cm, "
121  << "layerAngle: " << p.layerAngle << " rad" << endl;
122 
123  return os;
124 }
125 //______________________________________________________________________________
126 void StiPlacement::setLayerRadius(float radius_)
127 {
128 static const double kMinRad=0.1,kMaxRad=200;
129 static const double kLogStep=(log(kMaxRad)-log(kMinRad))/10000;
130  int nStp = int(log(radius_+kMinRad)/kLogStep);
131  layerRadius = exp(nStp*kLogStep)-kMinRad;
132 }