Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackProjectorPid.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackProjectorPid.cc
1 #include "TrackProjectorPid.h"
2 
3 /* Fun4All includes */
5 #include <phool/PHIODataNode.h>
6 
8 
9 #include <phgeom/PHGeomUtility.h>
10 
11 #include <g4hough/SvtxTrack.h>
12 #include <g4hough/SvtxTrackState_v1.h>
13 #include <g4hough/PHG4HoughTransform.h>
14 
15 #include <phfield/PHFieldUtility.h>
16 
17 #include <phgenfit/Fitter.h>
18 #include <phgenfit/PlanarMeasurement.h>
19 #include <phgenfit/Track.h>
20 #include <phgenfit/SpacepointMeasurement.h>
21 
22 #include <GenFit/RKTrackRep.h>
23 #include <GenFit/FieldManager.h>
24 
25 using namespace std;
26 
28  _fitter(nullptr)
29 {
30  TGeoManager* tgeo_manager = PHGeomUtility::GetTGeoManager(topNode);
31 
32  PHField * field = PHFieldUtility::GetFieldMapNode(nullptr, topNode);
33 
34  _fitter = PHGenFit::Fitter::getInstance(tgeo_manager,field,
35  "DafRef",
36  "RKTrackRep", false);
37 
39 
40  if (!_fitter) {
41  cerr << "No fitter found at: " << endl;
42  cerr << PHWHERE << endl;
43  }
44 }
45 
46 bool
47 TrackProjectorPid::get_projected_position( SvtxTrack * track, double arr_pos[3], const PROJECTION_SURFACE surf, const float surface_par )
48 {
49  /* set position components to 0 */
50  arr_pos[0] = 0;
51  arr_pos[1] = 0;
52  arr_pos[2] = 0;
53 
54  /* project track */
55  auto state = project_track( track, surf, surface_par );
56 
57  /* Set position at extrapolate position */
58  if ( state )
59  {
60  arr_pos[0] = state->get_x();
61  arr_pos[1] = state->get_y();
62  arr_pos[2] = state->get_z();
63  return true;
64  }
65 
66  return false;
67 }
68 
69 bool
70 TrackProjectorPid::get_projected_momentum( SvtxTrack * track, double arr_mom[3], const PROJECTION_SURFACE surf, const float surface_par )
71 {
72  /* set momentum components to 0 */
73  arr_mom[0] = 0;
74  arr_mom[1] = 0;
75  arr_mom[2] = 0;
76 
77  /* project track */
78  auto state = project_track( track, surf, surface_par );
79 
80  /* Set momentum at extrapolate position */
81  if ( state )
82  {
83  arr_mom[0] = state->get_px();
84  arr_mom[1] = state->get_py();
85  arr_mom[2] = state->get_pz();
86  return true;
87  }
88 
89  return false;
90 }
91 
93 TrackProjectorPid::project_track( SvtxTrack * track, const PROJECTION_SURFACE surf, const float surface_par )
94 {
95  /* Do projection */
96  std::vector<double> point;
97  point.assign(3, -9999.);
98 
99  auto last_state_iter = --track->end_states();
100 
101  SvtxTrackState * trackstate = last_state_iter->second;
102 
103  if(!trackstate) {
104  cout << "No state found here!" << endl;
105  return NULL;
106  }
107 
108  int _pid_guess = -211;
109  auto rep = unique_ptr<genfit::AbsTrackRep> (new genfit::RKTrackRep(_pid_guess));
110 
111  unique_ptr<genfit::MeasuredStateOnPlane> msop80 = nullptr;
112 
113  {
114  TVector3 pos(trackstate->get_x(), trackstate->get_y(), trackstate->get_z());
115  TVector3 mom(trackstate->get_px(), trackstate->get_py(), trackstate->get_pz());
116 
117  TMatrixDSym cov(6);
118  for (int i = 0; i < 6; ++i) {
119  for (int j = 0; j < 6; ++j) {
120  cov[i][j] = trackstate->get_error(i, j);
121  }
122  }
123 
124  msop80 = unique_ptr<genfit::MeasuredStateOnPlane> (new genfit::MeasuredStateOnPlane(rep.get()));
125 
126  msop80->setPosMomCov(pos, mom, cov);
127  }
128 
129  /* This is where the actual extrapolation of the track to a surface (cylinder, plane, cone, sphere) happens. */
130  try {
131 
132  /* 'rep 'is of type AbsTrackRep (see documentation or header for extrapolation function options ) */
133  if ( surf == SPHERE )
134  rep->extrapolateToSphere(*msop80, surface_par, TVector3(0,0,0), false, false);
135 
136  else if ( surf == CYLINDER )
137  rep->extrapolateToCylinder(*msop80, surface_par, TVector3(0,0,0), TVector3(0,0,1));
138 
139 
140  else if ( surf == PLANEXY )
141  rep->extrapolateToPlane(*msop80, genfit::SharedPlanePtr( new genfit::DetPlane( TVector3(0, 0, surface_par), TVector3(0, 0, 1) ) ), false, false);
142 
143  } catch (...) {
144  cout << "track extrapolateToXX failed" << endl;
145  return NULL;
146  }
147 
148  /* Create SvtxTrackState object as storage version of the track state
149  * to pass projected track state information to other member functions. */
150  SvtxTrackState_v1 *svtx_state = new SvtxTrackState_v1();
151 
152  svtx_state->set_x( msop80->getPos().X() );
153  svtx_state->set_y( msop80->getPos().Y() );
154  svtx_state->set_z( msop80->getPos().Z() );
155 
156  svtx_state->set_px( msop80->getMom().x() );
157  svtx_state->set_py( msop80->getMom().y() );
158  svtx_state->set_pz( msop80->getMom().z() );
159 
160  for (int i = 0; i < 6; i++) {
161  for (int j = i; j < 6; j++) {
162  svtx_state->set_error(i, j, msop80->get6DCov()[i][j]);
163  }
164  }
165 
166  return svtx_state;
167 }
168 
169 bool
171 {
172  double eta = atanh( momv[2] );
173 
174  // rough pseudorapidity cut
175  if (eta > 1.45 && eta < 7.5)
176  return true;
177 
178  return false;
179 }