StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiHitTest.cxx
1 #include "StiHitTest.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <assert.h>
5 #include "TVectorD.h"
6 #include "TMatrixDSym.h"
7 #include "TMath.h"
8 #include "StiHit.h"
9 #include "StiKalmanTrack.h"
10 #include "StiUtilities/StiDebug.h"
11 #include "StEvent/StEnumerations.h"
12 
13 //______________________________________________________________________________
14 void StiHitTest::reset()
15 {
16  memset(fBeg, 0,fEnd-fBeg+1);
17  fW[0]=-1;
18 }
19 
20 //______________________________________________________________________________
21 void StiHitTest::add(double x,double y,double z)
22 {
23  double xx[3]; xx[0]=x;xx[1]=y;xx[2]=z;
24  add(xx);
25 }
26 //______________________________________________________________________________
27 void StiHitTest::add(double x[3])
28 {
29  fN++;
30  for (int i=0;i<3;i++) {
31  fX[i] += x[i];
32  for (int j=0;j<3;j++) {
33  fM[i][j] += x[i]*x[j];
34  }}
35 }
36 //______________________________________________________________________________
37 void StiHitTest::doIt()
38 {
39  if (!fN) return;
40  if (fW[0]>=0.) return;
41  for (int i=0;i<3;i++) {fX[i]/=fN;}
42  double *d = fM[0];
43  for (int i=0;i<9;i++) {d[i]/=fN;}
44  for (int i=0;i<3;i++) {
45  for (int j=0;j<3;j++) {
46  fM[i][j] -= fX[i]*fX[j];
47  }}
48  TMatrixDSym Sym(3,fM[0],"");
49  TVectorD vals(3);
50  TMatrixD vecs = Sym.EigenVectors(vals);
51 // vals.Print();
52  memcpy(fW, vals.GetMatrixArray(),sizeof(fW));
53  vecs.Transpose(vecs);
54  memcpy(fV[0],vecs.GetMatrixArray(),sizeof(fV));
55 }
56 //______________________________________________________________________________
57 double StiHitTest::width(int idx)
58 {
59  doIt();
60  return fW[idx];
61 }
62 
63 //______________________________________________________________________________
64 const double *StiHitTest::vector(int idx)
65 {
66  doIt();
67  return fV[idx];
68 }
69 //______________________________________________________________________________
70 double StiHitTest::yAngle() const
71 {
72  double dy = fV[2][1]; double dx = fV[2][0];
73  if (dx<0) {dx=-dx;dy=-dy;}
74  return TMath::ATan2(dy,dx);
75 }
76 //______________________________________________________________________________
77 double StiHitTest::zAngle() const
78 {
79  double dz = fV[2][2]; double dx = fV[2][0];
80  if (dx<0) {dx=-dx;dz=-dz;}
81  return TMath::ATan2(dz,dx);
82 }
83 //______________________________________________________________________________
84 //______________________________________________________________________________
85 //______________________________________________________________________________
86 void StiHftHits::hftHist(const char *name, const StiKalmanTrack* tk)
87 {
88 //PXL 1 -- 2 < R < 4 cm
89 //PXL 2 -- 7 < R < 9 cm
90 //IST 3 -- 12 < R < 17 cm
91 //SST 4 -- 21 < R < 28 cm
92 enum {kMinRadTpc = 50};
93 if (StiDebug::Debug()<2) return;
94 int nTpcHits = tk->getPointCount(kTpcId);
95 if (nTpcHits<11) return;
96 
97 static double Rxy[]={5,10,19,30,0};
98  int nHits=0,nHft=0,tally[9]={0};
99  double lastR=0;
100  TString forRxy(name); forRxy+="_xLoc";
101  StiKTNIterator it;
102  for (it=tk->rbegin();it!=tk->rend();it++) {
103  StiKalmanTrackNode *node = &(*it);
104  if (!node->isValid()) continue;
105  const StiDetector *detector = node->getDetector();
106  if (!detector) continue;
107  double rxy = node->getRxy();
108  if (rxy>kMinRadTpc) break;
109  if (!detector->isActive()) continue;
110  nHft++;
111  const StiHit *hit = node->getHit();
112  if (!hit ) continue;
113  if (!hit->detector()) continue;
114  if (node->getChi2()>1000) continue;
115  rxy = sqrt(pow(hit->x(),2)+pow(hit->y(),2));
116  if (rxy>kMinRadTpc) break;
117  if (rxy<lastR) {StiDebug::Count(name,"????"); return;}//wrong order, do not count at all
118  lastR = rxy;
119  int ih=0;
120  rxy = hit->x();
121  for (;Rxy[ih];ih++) { if (rxy<Rxy[ih]) break;}
122  tally[ih]++; nHits++;
123  StiDebug::Count(forRxy.Data(),rxy);
124  }
125  if (nHft) {
126 assert(strstr(name,"After") || nHits==0 || nHits >=3);
127  TString ts(name);ts+="_siHits:siDets";
128  StiDebug::Count(ts.Data(),100.*nHits/nHft);
129  }
130  if (!nHits) {
131  if (nHft) {StiDebug::Count(name,"0000");}
132  else {StiDebug::Count(name,"xxxx");}
133  return;
134  }
135  TString ts;
136  for (int i=0;i<4;i++) {
137  if (tally[i]>3) tally[i]=3;
138  ts += tally[i];
139  }
140  StiDebug::Count(name,ts.Data());
141 }
142 
Definition of Kalman Track.
static void hftHist(const char *tit, const StiKalmanTrack *tk)
Definition: StiHitTest.cxx:86
Definition: StiHit.h:51
const Float_t & x() const
Return the local x, y, z values.
Definition: StiHit.h:67
const StiDetector * detector() const
Definition: StiHit.h:96
int getPointCount(int detectorId=0) const
Return the number of hits associated with this track.
Definition of Kalman Track.