vertex1algs.cxx
Go to the documentation of this file.
1 #include<Reco/vertex1algs.h>
2 
3 //--------------------------------------------------------------------------------------------------
4 
5 // fitVertex returns 0 if success
6 // It does not cut tracks from the vertex candidate set -- may need to do that in the caller.
7 
8 int gar::rec::fitVertex(std::vector<TrackPar> &tracks,
9  std::vector<float> &xyz,
10  float &chisquared,
11  std::vector< std::vector<float> > &covmat,
12  double &time,
13  std::vector<TrackEnd> usebeg,
14  std::vector<float> &doca
15  )
16 {
17  // find the ends of the tracks that are closest to the other tracks' ends
18  // pick the end that minimizes the sums of the min(dist) to the other tracks' endpoints
19 
20  // todo -- iterate on this as the tracks are helices and not lines -- move to close point on track and re-do linear extrapolation
21 
22  if (tracks.size() < 2) return(1); // need at least two tracks to make a vertex
23 
24  // find the average time of the tracks
25 
26  time = 0;
27  for (size_t i=0; i<tracks.size(); ++i)
28  {
29  time += tracks.at(i).getTime();
30  }
31  if (tracks.size() > 0)
32  {
33  time /= tracks.size();
34  }
35 
36  xyz.resize(3);
37  covmat.resize(9);
38 
39  std::vector<TVectorF> dir;
40  std::vector<TVectorF> p;
41 
42  for (size_t itrack = 0; itrack < tracks.size(); ++itrack)
43  {
44  TVector3 trackbeg = tracks.at(itrack).getXYZBeg();
45  TVector3 trackend = tracks.at(itrack).getXYZEnd();
46  float phi=0;
47  float si=0;
48  if (usebeg.at(itrack)==TrackEndBeg)
49  {
50  float tmppos[3] = {(float) trackbeg.X(), (float) trackbeg.Y(), (float) trackbeg.Z()};
51  p.emplace_back(3,tmppos);
52  phi = tracks.at(itrack).getTrackParametersBegin()[3];
53  si = TMath::Tan(tracks.at(itrack).getTrackParametersBegin()[4]);
54  }
55  else
56  {
57  float tmppos[3] = {(float) trackend.X(), (float) trackend.Y(), (float) trackend.Z()};
58  p.emplace_back(3,tmppos);
59  phi = tracks.at(itrack).getTrackParametersEnd()[3];
60  si = TMath::Tan(tracks.at(itrack).getTrackParametersEnd()[4]);
61  }
62  TVectorF dtmp(3);
63  dtmp[0] = si;
64  dtmp[1] = TMath::Sin(phi);
65  dtmp[2] = TMath::Cos(phi);
66  float norminv = 1.0/TMath::Sqrt(dtmp.Norm2Sqr());
67  dtmp *= norminv;
68  dir.push_back(dtmp);
69  }
70 
71  TMatrixF I(3,3);
72  I[0][0] = 1;
73  I[1][1] = 1;
74  I[2][2] = 1;
75 
76  TMatrixF A(3,3);
77  TMatrixF VVT(3,3);
78  TMatrixF IMVVT(3,3);
79  TVectorF vsum(3);
80  vsum.Zero();
81  A *= 0;
82 
83  for (size_t itrack=0; itrack < tracks.size(); ++itrack)
84  {
85  for (size_t i=0; i<3; ++i)
86  {
87  for (size_t j=0; j<3; ++j)
88  {
89  VVT[i][j] = dir.at(itrack)[i]*dir.at(itrack)[j];
90  }
91  }
92  IMVVT = I - VVT;
93  A += IMVVT;
94  vsum += IMVVT*p.at(itrack);
95  }
96  double det;
97  A.Invert(&det);
98  if (det == 0) return(1);
99  TVectorF xyzsol = A*vsum;
100  xyz.at(0) = xyzsol[0];
101  xyz.at(1) = xyzsol[1];
102  xyz.at(2) = xyzsol[2];
103 
104  chisquared = 0;
105  //std::cout << "in vertexfit ntracks: " << tracks.size() << std::endl;
106  for (size_t itrack=0; itrack < tracks.size(); ++itrack)
107  {
108 
109  TVector3 dir3(dir.at(itrack)[0],dir.at(itrack)[1],dir.at(itrack)[2]);
110  TVectorF diff = xyzsol - p.at(itrack);
111  TVector3 diff3(diff[0],diff[1],diff[2]);
112  double dctmp = (diff3.Cross(dir3)).Mag2();
113  doca.push_back(dctmp);
114  chisquared += dctmp*dctmp; // todo -- include track errors in chisquared calc
115  }
116 
117  // to iterate -- extrapolate helical tracks to the closest point to the first found vertex and
118  // run the fitter again
119 
120  // to do: figure out what the vertex covariance matrix is
121 
122  covmat.clear();
123  for (size_t i=0;i<3;++i)
124  {
125  std::vector<float> cmr;
126  for (size_t j=0; j<3; ++j)
127  {
128  cmr.push_back(0);
129  }
130  covmat.push_back(cmr);
131  }
132  return 0;
133 
134 }
int fitVertex(std::vector< TrackPar > &tracks, std::vector< float > &xyz, float &chisquared, std::vector< std::vector< float > > &covmat, double &time, std::vector< TrackEnd > usebeg, std::vector< float > &doca)
Definition: vertex1algs.cxx:8
struct vector vector
string dir
p
Definition: test.py:223
Definition: tracks.py:1
TrackEnd const TrackEndBeg
Definition: Track.h:33
#define A
Definition: memgrp.cpp:38