Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helixResiduals.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file helixResiduals.cc
1 #include "helixResiduals.h"
2 
5 #include <phool/getClass.h>
6 #include <trackbase/TrkrDefs.h>
7 
8 #include <TFile.h>
9 #include <TNtuple.h>
10 
12  : SubsysReco(name)
13 {
14  _fitter = new HelicalFitter;
15 }
16 
18 {
19  _fitter->InitRun(topNode);
20  const char *cfilepath = filepath.c_str();
21  fout = new TFile(cfilepath, "recreate");
22  ntp_residuals = new TNtuple("ntp_residuals", "Seed Residuals", "seed_id:layer:dphi:dz:x:y:z:pt:px:py:pz:crossing:isSilicon:isTpc");
23 
24  getNodes(topNode);
25 
26  return 0;
27 }
28 
30 {
31  fout->cd();
32  ntp_residuals->Write();
33  fout->Close();
34 
35  delete _fitter;
36 
37  return 0;
38 }
39 
41 {
42  _tracks = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
43  if (!_tracks)
44  {
45  std::cerr << PHWHERE << "No SvtxTrackMap on node tree, exiting." << std::endl;
47  }
48  _tpc_seeds = findNode::getClass<TrackSeedContainer>(topNode, "TpcTrackSeedContainer");
49  if (!_tpc_seeds)
50  {
51  std::cerr << PHWHERE << " ERROR: Can't find TpcTrackSeedContainer " << std::endl;
53  }
54  _si_seeds = findNode::getClass<TrackSeedContainer>(topNode, "SiliconTrackSeedContainer");
55  if (!_si_seeds)
56  {
57  std::cerr << PHWHERE << " ERROR: Can't find SiliconTrackSeedContainer" << std::endl;
59  }
60  _clusters = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER");
61  if (!_clusters)
62  {
63  std::cerr << PHWHERE << " ERROR: Can't find TRKR_CLUSTER" << std::endl;
65  }
66  tGeometry = findNode::getClass<ActsGeometry>(topNode, "ActsGeometry");
67  if (!tGeometry)
68  {
69  std::cerr << PHWHERE << "No acts tracking geometry, can't proceed" << std::endl;
71  }
73 }
74 
76 {
77  for (auto tpcseed_iter = _tpc_seeds->begin(); tpcseed_iter != _tpc_seeds->end(); ++tpcseed_iter)
78  {
79  int id = _tpc_seeds->index(tpcseed_iter);
80  TrackSeed *tpcseed = _tpc_seeds->get(id);
81  if (!tpcseed)
82  {
83  continue;
84  }
85  std::cout << "processing tpc seed " << id << std::endl;
86  fill_residuals(tpcseed, id, true);
87  }
88  for (auto siseed_iter = _si_seeds->begin(); siseed_iter != _si_seeds->end(); ++siseed_iter)
89  {
90  int id = _si_seeds->index(siseed_iter);
91  TrackSeed *siseed = _si_seeds->get(id);
92  if (!siseed)
93  {
94  continue;
95  }
96  std::cout << "processing si seed " << id << std::endl;
97  fill_residuals(siseed, id, false);
98  }
99  std::cout << "done" << std::endl;
101 }
102 
103 void helixResiduals::fill_residuals(TrackSeed *seed, int seed_id, bool isTpc)
104 {
105  if (seed->size_cluster_keys() == 0)
106  {
107  return;
108  }
109 
110  std::vector<Acts::Vector3> clusterPositions;
111  std::vector<TrkrDefs::cluskey> clusterKeys;
112  _fitter->getTrackletClusters(seed, clusterPositions, clusterKeys);
113  std::vector<float> fitparams = _fitter->fitClusters(clusterPositions, clusterKeys);
114 
115  float pt = seed->get_pt();
116  float px = seed->get_px(_clusters, tGeometry);
117  float py = seed->get_py(_clusters, tGeometry);
118  float pz = seed->get_pz();
119  unsigned int crossing = seed->get_crossing();
120 
121  for (size_t i = 0; i < clusterPositions.size(); i++)
122  {
123  unsigned int layer = TrkrDefs::getLayer(clusterKeys[i]);
124  Acts::Vector3 position = clusterPositions[i];
125  Acts::Vector3 pca = _fitter->get_helix_pca(fitparams, position);
126  float cluster_phi = atan2(position(1), position(0));
127  float pca_phi = atan2(pca(1), pca(0));
128  float dphi = cluster_phi - pca_phi;
129  if (dphi > M_PI)
130  {
131  dphi = 2 * M_PI - dphi;
132  }
133  if (dphi < -M_PI)
134  {
135  dphi = 2 * M_PI + dphi;
136  }
137  float dz = position(2) - pca(2);
138 
139  ntp_residuals->Fill(seed_id, layer, dphi, dz, position(0), position(1), position(2), pt, px, py, pz, crossing, !isTpc, isTpc);
140  }
141 }