StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiHit.cxx
1 //StiHit.cxx
2 //M.L. Miller (Yale Software)
3 //04/01
4 #include "RVersion.h"
5 #if ROOT_VERSION_CODE < 331013
6 #include "TCL.h"
7 #else
8 #include "TCernLib.h"
9 #endif
10 #include <Stiostream.h>
11 #include "StEventTypes.h"
12 #include "StiHit.h"
13 #include "StiDetector.h"
14 #include "StiPlacement.h"
15 #include "StiShape.h"
16 #include "StiUtilities/StiDebug.h"
17 
18 
19 //_____________________________________________________________________________
21 {
22  reset();
23 }
24 
25 
26 //_____________________________________________________________________________
27 StiHit::StiHit(const StiHit &h)
28 {
29  memcpy(mBeg,h.mBeg,mEnd-mBeg+1);
30 }
31 
32 //_____________________________________________________________________________
33 const StiHit& StiHit::operator=(const StiHit & h)
34 {
35  memcpy(mBeg,h.mBeg,mEnd-mBeg+1);
36  return *this;
37 }
38 
39 //_____________________________________________________________________________
41 {}
42 
43 //_____________________________________________________________________________
46 void StiHit::rotate(double alpha)
47 {
48  assert(!mdetector);
49 static float rotMx[3][3]={{1,0,0},{0,1,0},{0,0,1}}, s[6];
50 
51  mrefangle+=alpha;
52  double ca = cos(alpha);
53  double sa = sin(alpha);
54  rotMx[0][0] = ca; rotMx[0][1] = sa;
55  rotMx[1][0] =-sa; rotMx[1][1] = ca;
56 
57  double x = rotMx[0][0]*mx + rotMx[0][1]*my;
58  double y = rotMx[1][0]*mx + rotMx[1][1]*my;
59  mx = x; my = y;
60 
61 // S=R*S*Rt
62  memcpy(s,&msxx,sizeof(s));
63  TCL::trasat(rotMx[0],s,&msxx,3,3);
64 }
65 
66 //_____________________________________________________________________________
67 void StiHit::setError(const StMatrixF& matrix)
68 {
69  enum Labels {x=1, y=2, z=3};
70 
71  //Set Diagonal elements
72  msxx = matrix(x,x);
73  msyy = matrix(y,y);
74  mszz = matrix(z,z);
75  //Off Diagonal
76  msxy = matrix(x,y);
77  msxz = matrix(x,z);
78  msyz = matrix(y,z);
79  return;
80 }
81 //_____________________________________________________________________________
82 void StiHit::setError(const float matrix[6])
83 {
84  memcpy(&msxx,matrix,6*sizeof(msxx));
85 }
86 
87 //_____________________________________________________________________________
89 ostream& operator<<(ostream& os, const StiHit& hit)
90 {
91  return os <<hit.refangle() <<" "<<hit.position()
92  <<"L:"<<hit.x() <<" "<<hit.y() <<" "<<hit.z()
93  <<"G:"<<hit.x_g()<<" "<<hit.y_g()<<" "<<hit.z_g();
94 }
95 
96 
97 //_____________________________________________________________________________
98 double StiHit::getValue(int key) const
99 {
100  double value;
101  switch (key)
102  {
103  case kZ: value = _zg; break;
104  case kR: value = ::sqrt(_xg*_xg+_yg*_yg); break;
105  case kPseudoRapidity: value = getPseudoRapidity(); break;
106  case kPhi: value = atan2(_yg,_xg);break;
107  default: value = -999999.; break;
108  }
109  return value;
110 }
111 
112 //_____________________________________________________________________________
113 double StiHit::getPseudoRapidity() const
114 {
115  double r=::sqrt(_xg*_xg+_yg*_yg);
116  double tanTheta = ::tan(::atan2(r,_zg)/2.);
117  if (tanTheta>0.)
118  return -::log(tanTheta);
119  else
120  return 1.e10;
121 }
122 //_____________________________________________________________________________
123 void StiHit::reset()
124 {
125  memset(mBeg,0,mEnd-mBeg+1);
126  mMaxTimes = 1;
127 static unsigned int myCount=0;
128  mCount = ++myCount;
129 }
130 
131 
132 //_____________________________________________________________________________
133 void StiHit::setGlobal(const StiDetector * detector,
134  const StMeasuredPoint * stHit,
135  float gx, float gy, float gz,
136  float energy)
137 {
138 static int nCall =0; nCall++;
139 
140  if (detector)
141  {
142  StiPlacement * placement = detector->getPlacement();
143  mrefangle = placement->getLayerAngle();
144  mposition = placement->getLayerRadius();
145  mx = detector->_cos*gx + detector->_sin*gy;
146  my = -detector->_sin*gx + detector->_cos*gy;
147  mz = gz;
148  double dd[3]={mx,my,mz};
149 
150 
151  if (!detector->insideL(dd,7,1.2)) {
152  LOG_ERROR <<
153  Form("**** StiHit.%s outside (%d) by %g (%g) ****"
154  ,detector->getName().c_str()
155  ,StiDetector::mgIndex
156  ,StiDetector::mgValue[0],StiDetector::mgValue[1])
157  << endm;
158  assert( detector->insideL(dd,7,1.5)); //
159  }
160 
161  mx = detector->_cos*gx + detector->_sin*gy;
162  my = -detector->_sin*gx + detector->_cos*gy;
163  }
164  else
165  {
166  mrefangle = 0.;
167  mposition = 0.;
168  mx = gx;
169  my = gy;
170  mz = gz;
171  }
172  msxx = -1.;//sxx;
173  msyy = -1.;//syy;
174  mszz = -1.;//szz;
175  msxy = 0.;//sxy;
176  msxz = 0.;//sxz;
177  msyz = 0.;//syz;
178  _xg = gx;
179  _yg = gy;
180  _zg = gz;
181  mTimesUsed = 0;
182  mdetector = detector; msthit = stHit;
183  _energy = energy;
184 }
185 
186 
187 //_____________________________________________________________________________
188  void StiHit::set(const StiDetector * detector,
189  const StMeasuredPoint * stHit,
190  float energy,
191  float x, float y, float z,
192  float sxx, float sxy, float sxz, float syy, float syz, float szz)
193 {
194  if (detector)
195  {
196  StiPlacement * placement = detector->getPlacement();
197  mrefangle = placement->getLayerAngle();
198  mposition = placement->getLayerRadius();
199  _xg = detector->_cos*x - detector->_sin*y;
200  _yg = detector->_sin*x + detector->_cos*y;
201  }
202  else
203  {
204  mrefangle = 0.;
205  mposition = 0.;
206  _xg = x;
207  _yg = y;
208  }
209  mx = x;
210  my = y;
211  mz = z;
212  msxx = sxx;
213  msyy = syy;
214  mszz = szz;
215  msxy = sxy;
216  msxz = sxz;
217  msyz = syz;
218  mTimesUsed = 0;
219  mdetector = detector;
220  msthit = stHit;
221  _energy = energy;
222  _zg = z;
223  if (!stHit) return;
224  assert( fabs(stHit->position().x()-_xg)< 1.e-6
225  && fabs(stHit->position().y()-_yg)< 1.e-6
226  && fabs(stHit->position().z()-_zg)< 1.e-6);
227 
228  if (!detector) return;
229  double pos = detector->getPlacement()->getNormalRadius();
230  double dif = mx-pos;
231  if (fabs(dif)<1.) return;
232  LOG_ERROR <<
233 
234  Form("**** StiHit.%s too far: x=%f pos=%g dif=%g ****\n"
235  ,detector->getName().c_str(),mx,pos,dif)
236  << endm;
237 }
238 
239 //_____________________________________________________________________________
241 {
242  mTimesUsed++;
243  assert(mTimesUsed <=mMaxTimes);
244 }
245 //_____________________________________________________________________________
246  void StiHit::subTimesUsed()
247 {
248  mTimesUsed--;
249  assert(mTimesUsed>=0);
250 }
251 
252 //_____________________________________________________________________________
254 {
255  return _energy;
256 }
257 
258 //_____________________________________________________________________________
260 {
261  return StThreeVectorF(_xg,_yg,_zg);
262 }
263 
264 //_____________________________________________________________________________
265 void StiHit::set(float position, float angle, float y, float z)
266 {
267  memset(mBeg,0,mEnd-mBeg+1);
268  mrefangle = angle;
269  mposition = position;
270  mx = position;
271  my = y;
272  mz = z;
273 // add crazy values
274  _xg = 100000.;
275  _yg = 100000.;
276  _zg = 100000.;
277 }
278 //_____________________________________________________________________________
280 {
281  memset(mBeg,0,mEnd-mBeg+1);
282  mszz = 1e12;
283 }
284 //_____________________________________________________________________________
285 int StiHit::isDca() const
286 {
287  if (mdetector) return 0;
288  if (mx || my || mz) return 0;
289  if (mszz<1000) return 0;
290  return 1;
291 }
292 //_____________________________________________________________________________
293 //_____________________________________________________________________________
294 //_____________________________________________________________________________
295 
296 #include "StEvent/StHit.h"
297 //_____________________________________________________________________________
298 int StiHit::idTruth() const
299 {
300  StHit *stHit = (StHit*)msthit;
301  if (!stHit) return 0;
302  return stHit->idTruth();
303 }
304 
305 //_____________________________________________________________________________
306 int StiHit::qaTruth() const
307 {
308  StHit *stHit = (StHit*)msthit;
309  if (!stHit) return 0;
310  return stHit->qaTruth();
311 }
312 
313 
314 
315 
StiHit()
Default constructor.
Definition: StiHit.cxx:20
void setError(const StMatrixF &)
Definition: StiHit.cxx:67
void makeDca()
Make fake hit for dca calculation.
Definition: StiHit.cxx:279
double _cos
Convenience storage of cos(refAngle)
Definition: StiDetector.h:132
Definition: StHit.h:125
void setGlobal(const StiDetector *detector, const StMeasuredPoint *stHit, Float_t x, Float_t y, Float_t z, Float_t energy)
Definition: StiHit.cxx:133
Definition: StiHit.h:51
const Float_t & x() const
Return the local x, y, z values.
Definition: StiHit.h:67
void rotate(double angle)
Definition: StiHit.cxx:46
~StiHit()
Default destructor.
Definition: StiHit.cxx:40
const StiDetector * detector() const
Definition: StiHit.h:96
Float_t x_g() const
Return the global x, y, z values.
Definition: StiHit.h:73
Float_t refangle() const
Return the refAngle of the detector plane from which the hit arose.
Definition: StiHit.h:91
void addTimesUsed()
???
Definition: StiHit.cxx:240
static float * trasat(const float *a, const float *s, float *r, int m, int n)
Definition: TCernLib.cxx:540
Int_t isDca() const
Test for DCA. Fake hit for dca calculation.
Definition: StiHit.cxx:285
Float_t getEloss()
Return the energy deposition associated with this point.
Definition: StiHit.cxx:253
Float_t sxx() const
Return components of the error matrix.
Definition: StiHit.h:81
double _sin
Convenience storage of sin(refAngle)
Definition: StiDetector.h:134
Float_t position() const
Return the position of the detector plane from which the hit arose.
Definition: StiHit.h:93
const StMeasuredPoint * stHit() const
Definition: StiHit.h:104
const StThreeVectorF globalPosition() const
Definition: StiHit.cxx:259
const string & getName() const
Get the name of the object.
Definition: Named.cxx:22