StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StG2TrackVertexMap.cxx
1 #include <assert.h>
2 #include "StG2TrackVertexMap.h"
3 #include "TVector3.h"
4 StG2TrackVertexMap *StG2TrackVertexMap::fgInstance = 0;
5 //________________________________________________________________________________
6 StG2TrackVertexMap *StG2TrackVertexMap::instance(St_g2t_track *track, St_g2t_vertex *vertex) {
7  if (! fgInstance) {fgInstance = new StG2TrackVertexMap(track,vertex); }
8  else if (track && vertex) {
9  fgInstance->Reset(track,vertex);
10  }
11  return fgInstance;
12 }
13 //________________________________________________________________________________
14 void StG2TrackVertexMap::Reset(St_g2t_track *track, St_g2t_vertex *vertex) {
15  fTrack2Vertex.clear();
16  fVertex2ParentTrack.clear();
17  if (! track || ! vertex) return;
18  Int_t Nt = track->GetNRows();
19  Int_t NV = vertex->GetNRows();
20  g2t_track_st *t = track->GetTable();
21  g2t_vertex_st *v = vertex->GetTable();
22  for (Int_t i = 0; i < Nt; i++) {
23  Int_t IdT = t[i].id - 1; assert(IdT >= 0 && IdT < Nt);
24  Int_t IdV = t[i].start_vertex_p - 1; assert(IdV >= 0 && IdV < NV);
25  TVector3 Vx1(v[IdV].ge_x);
26  Float_t tof1 = v[IdV].ge_tof;
27  Int_t IdP = v[IdV].parent_p - 1;
28  if (IdP >= 0 && IdP < Nt) {
29  Int_t IdVxP = t[IdP].start_vertex_p - 1; assert(IdVxP >= 0 && IdVxP < NV);
30  TVector3 Vx2(v[IdVxP].ge_x);
31  Vx2 -= Vx1;
32  while ((Vx2.Mag() < 10e-4 && TMath::Abs(tof1-v[IdVxP].ge_tof) < 1e-9)) {
33  IdV = IdVxP;
34  IdP = v[IdV].parent_p - 1; if (IdP < 0) break;
35  IdVxP = t[IdP].start_vertex_p - 1; if (IdVxP < 0) break;
36  Vx2 = TVector3(v[IdVxP].ge_x);
37  Vx2 -= Vx1;
38  }
39  }
40  fTrack2Vertex[IdT+1] = IdV+1;
41  }
42  for (Int_t i = 0; i < NV; i++) {
43  fVertex2ParentTrack[v[i].id] = v[i].parent_p;
44  }
45 }