StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TrackData.cxx
1 #include <cmath>
2 #include <St_base/StMessMgr.h>
3 #include "StEvent/StDcaGeometry.h"
4 
5 #include "StGenericVertexMaker/StiPPVertex/TrackData.h"
6 #include "StGenericVertexMaker/StiPPVertex/VertexData.h"
7 #include "StMuDSTMaker/COMMON/StMuTrack.h"
8 
9 
10 
11 TrackData::TrackData(const void* motherTrack, const StDcaGeometry* motherDca) :
12  vertexID(0),
13  mother(motherTrack),
14  dca(motherDca),
15  mIdTruth(0),
16  mQuality(0),
17  mIdParentVx(0),
18  dcaTrack(), zDca(0), ezDca(0), rxyDca(0),
19  gPt(0),
20  mBtof(0), mCtb(0), mBemc(0), mEemc(0), mTpc(0),
21  anyMatch(false), anyVeto(false),
22  weight(1),
23  btofBin(-1), ctbBin(-1), bemcBin(-1), eemcBin(-1)
24 { }
25 
26 
27 //==========================================================
28 //==========================================================
29 bool
30 TrackData::matchVertex(VertexData &V, float dzMax) {
31 
32  float dz = zDca - V.r.z();
33  bool ret = fabs(dz) < dzMax + ezDca;
34 
35  if (ret)
36  LOG_DEBUG<< Form("PPV::matchTr2Ver VerID=%d weight=%.2f anyM=%d anyV=%d m: ctb=%d bemc=%d eemc=%d tpc=%d dz=%.2f +/- %.2f\n",V.id,weight,anyMatch,anyVeto,mCtb,mBemc,mEemc,mTpc,dz,ezDca)<<endm;
37 
38  return ret;
39 }
40 
41 
42 double TrackData::calcChi2DCA(const VertexData &V) const
43 {
44  double err2;
45  double vxyz[3];
46  V.r.GetXYZ(vxyz);
47 
48  double dist = dca->thelix().Dca(vxyz, &err2);
49  double chi2 = dist*dist/err2;
50 
51  return chi2;
52 }
53 
54 
55 //==========================================================
56 //==========================================================
57 void
58 TrackData::scanNodes(vector<int> &hit, int jz0){
59  /* INPUT: vector of hits for active nodes
60  i=[0,jz0-1] is on one side of z-Axis
61  i=[jz0,mx-1] on another side
62  */
63 
64  // params
65  const int minCenter=4 , minMiss=6; // criteria for Match & Veto
66  const int mxDev=2; // max # of deviations from expected pattern
67 
68  // printf("patt size=%d, jz0=%d\n",hit.size(),jz0);
69 
70  int nPatt[2]{};
71  int i;
72  bool vetoL=false, vetoR=false, matchL=false, matchR=false;
73 
74  // Scan Left end for missing hits
75  for(i=0;i<(int)hit.size();i++) {
76  // printf("i=%d hit=%d\n",i,hit[i]);
77  nPatt[hit[i]]++;
78  if(nPatt[1]>mxDev) break;
79  if(nPatt[0]<minMiss) continue;
80  vetoL=true;
81  break;
82  }
83 
84  // printf("vetoL=%d nUp=%d nDwn=%d\n\n",vetoL, nPatt[1],nPatt[0]);
85 
86  // Scan Right end for missing hits
87  memset(nPatt,0,sizeof(nPatt));
88  for(i=hit.size()-1; i>=0;i--) {
89  // printf("i=%d hit=%d\n",i,hit[i]);
90  nPatt[hit[i]]++;
91  if(nPatt[1]>mxDev) break;
92  if(nPatt[0]<minMiss) continue;
93  vetoR=true;
94  break;
95  }
96 
97  // printf("vetoR=%d nUp=%d nDwn=%d\n\n",vetoR, nPatt[1],nPatt[0]);
98 
99  if(jz0>minCenter && jz0<(int)hit.size()-minCenter) { // examin membrane
100  // Scan Left half at membrane
101  memset(nPatt,0,sizeof(nPatt));
102  for(i=jz0-1; i>=0;i--) {
103  // printf("i=%d hit=%d\n",i,hit[i]);
104  nPatt[hit[i]]++;
105  if(nPatt[0]>mxDev) break;
106  if(nPatt[1]<minCenter) continue;
107  matchL=true;
108  break;
109  }
110 
111  // printf("matchL=%d nUp=%d nDwn=%d\n\n",matchL, nPatt[1],nPatt[0]);
112 
113 
114  // Scan Right half at membrane
115  memset(nPatt,0,sizeof(nPatt));
116  for(i=jz0;i<(int)hit.size();i++) {
117  // printf("i=%d hit=%d\n",i,hit[i]);
118  nPatt[hit[i]]++;
119  if(nPatt[0]>mxDev) break;
120  if(nPatt[1]<minCenter) continue;
121  matchR=true;
122  break;
123  }
124 
125  // printf("matchR=%d nUp=%d nDwn=%d\n\n",matchR, nPatt[1],nPatt[0]);
126 
127  } // end of membrane test
128 
129  bool match= matchL && matchR;
130  bool veto=(vetoL || vetoR) && !match;
131 
132  // printf(" TPC Conclusion: tpcMatch=%d tpcVeto=%d \n\n",match,veto);
133  updateAnyMatch(match,veto,mTpc);
134  weight*=getTpcWeight();
135 }
136 
137 //==========================================================
138 //==========================================================
139 void
140 TrackData::updateAnyMatch(bool match, bool veto, int & mXXX){
141  if(match) {
142  anyMatch=true;
143  anyVeto=false;
144  mXXX=1;
145  // } else if(veto && (!anyMatch) ) {
146  } else if(veto && (!match) ) {
147  anyVeto=true;
148  mXXX=-1;
149  } else {
150  mXXX=0;
151  }
152 }
153 
154 //==========================================================
155 //==========================================================
156 float
157 TrackData:: getTpcWeight(){
158  const float Wdunno=1, Wmatch=5, Wveto=0.2;
159  if(mTpc>0) return Wmatch;
160  if(mTpc<0) return Wveto;
161  return Wdunno;
162 }
163 
164 
165 void TrackData::print(ostream& os) const
166 {
167  os << Form("vertID=%d track@z0=%.2f +/- %.2f gPt=%.3f, rxyDca: %.3f, idTruth: %d, qaTruth: %d, idParentVx: %d",
168  vertexID, zDca, ezDca, gPt, rxyDca, mIdTruth, mQuality, mIdParentVx);
169 
170  if (dca) {
171  os << Form(" dca: (%5.3f, %5.3f, %5.3f) +/- (imp: %5.3f, %5.3f)",
172  dca->origin().x(), dca->origin().y(), dca->origin().z(),
173  std::sqrt( dca->errMatrix()[0] ), std::sqrt( dca->errMatrix()[2] ) );
174  }
175 
176  os << endl;
177 }
178 
179 
181 template<>
182 TrackDataT<StMuTrack>::TrackDataT(const StMuTrack &motherTrack, const StDcaGeometry* trackDca) :
183  TrackData(&motherTrack, trackDca)
184 {
185  mIdTruth = motherTrack.idTruth();
186  mQuality = motherTrack.qaTruth();
187  mIdParentVx = motherTrack.idParentVx();
188 
189  if (trackDca) {
190  zDca = trackDca->z();
191  ezDca = std::sqrt(trackDca->errMatrix()[2]);
192  rxyDca = trackDca->impact();
193  gPt = trackDca->pt();
194  }
195 };
double calcChi2DCA(const VertexData &V) const
Calculates chi^2 at track DCA w.r.t. the vertex.
Definition: TrackData.cxx:42