Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnaSvtxTracksForGenFit.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AnaSvtxTracksForGenFit.cc
1 
2 //
3 // This module is desgined to grab svtx tracks and put truth and cluster
4 // information into a TTree for GenFit testing
5 //
7 //
8 // Darren McGlinchey
9 // 1 Apr 2016
10 //
12 
13 
14 #include "AnaSvtxTracksForGenFit.h"
15 
16 #include <phool/phool.h>
17 #include <phool/getClass.h>
20 #include <g4main/PHG4Particle.h>
21 #include <g4main/PHG4Hit.h>
22 #include <g4main/PHG4VtxPoint.h>
23 #include <fun4all/PHTFileServer.h>
24 #include <fun4all/Fun4AllServer.h>
25 
26 #include <g4hough/SvtxVertexMap.h>
27 #include <g4hough/SvtxVertex.h>
28 #include <g4hough/SvtxTrackMap.h>
29 #include <g4hough/SvtxTrack.h>
30 #include <g4hough/SvtxClusterMap.h>
31 #include <g4hough/SvtxCluster.h>
32 #include <g4hough/SvtxHitMap.h>
33 #include <g4hough/SvtxHit.h>
34 
35 #include <g4eval/SvtxEvalStack.h>
36 #include <g4eval/SvtxTrackEval.h>
37 #include <g4eval/SvtxClusterEval.h>
38 #include <g4eval/SvtxTruthEval.h>
39 #include <g4eval/SvtxVertexEval.h>
40 #include <g4eval/SvtxHitEval.h>
41 
42 #include <TTree.h>
43 
44 #include <iostream>
45 
46 using namespace std;
47 
48 //----------------------------------------------------------------------------//
49 //-- Constructor:
50 //-- simple initialization
51 //----------------------------------------------------------------------------//
53  SubsysReco( name ),
54  _flags( NONE ),
55  _tracks( NULL ),
56  _svtxevalstack( NULL )
57 {
58  //initialize
59  _event = 0;
60  _outfile = "AnaSvtxTracksForGenFit.root";
61 }
62 
63 //----------------------------------------------------------------------------//
64 //-- Init():
65 //-- Intialize all histograms, trees, and ntuples
66 //----------------------------------------------------------------------------//
68 {
69  cout << PHWHERE << " Openning file " << _outfile << endl;
70  PHTFileServer::get().open( _outfile, "RECREATE");
71 
72 
73  // create TTree
74  _tracks = new TTree("tracks", "Svtx Tracks");
75  _tracks->Branch("event", &event, "event/I");
76  _tracks->Branch("gtrackID", &gtrackID, "gtrackID/I");
77  _tracks->Branch("gflavor", &gflavor, "gflavor/I");
78  _tracks->Branch("gpx", &gpx, "gpx/F");
79  _tracks->Branch("gpy", &gpy, "gpy/F");
80  _tracks->Branch("gpz", &gpz, "gpz/F");
81  _tracks->Branch("gvx", &gvx, "gvx/F");
82  _tracks->Branch("gvy", &gvy, "gvy/F");
83  _tracks->Branch("gvz", &gvz, "gvz/F");
84  _tracks->Branch("trackID", &trackID, "trackID/I");
85  _tracks->Branch("charge", &charge, "charge/I");
86  _tracks->Branch("nhits", &nhits, "nhits/I");
87  _tracks->Branch("px", &px, "px/F");
88  _tracks->Branch("py", &py, "py/F");
89  _tracks->Branch("pz", &pz, "pz/F");
90  _tracks->Branch("dca2d", &dca2d, "dca2d/F");
91  _tracks->Branch("clusterID", &clusterID, "clusterID[nhits]/I");
92  _tracks->Branch("layer", &layer, "layer[nhits]/I");
93  _tracks->Branch("x", &x, "x[nhits]/F");
94  _tracks->Branch("y", &y, "y[nhits]/F");
95  _tracks->Branch("z", &z, "z[nhits]/F");
96  _tracks->Branch("size_dphi", &size_dphi, "size_dphi[nhits]/F");
97  _tracks->Branch("size_dz", &size_dz, "size_dz[nhits]/F");
98 
99 
100  return 0;
101 }
102 
103 //----------------------------------------------------------------------------//
104 //-- process_event():
105 //-- Call user instructions for every event.
106 //-- This function contains the analysis structure.
107 //----------------------------------------------------------------------------//
109 {
110  _event++;
111  if (_event % 1000 == 0)
112  cout << PHWHERE << "Events processed: " << _event << endl;
113 
114  GetNodes(topNode);
115 
116  if (!_svtxevalstack) {
117  _svtxevalstack = new SvtxEvalStack(topNode);
118  _svtxevalstack->set_strict(false);
120  } else {
121  _svtxevalstack->next_event(topNode);
122  }
123 
124  fill_tree(topNode);
125 
126  return 0;
127 }
128 
129 //----------------------------------------------------------------------------//
130 //-- End():
131 //-- End method, wrap everything up
132 //----------------------------------------------------------------------------//
134 {
135 
137 
138  _tracks->Write();
139 
140  if (_svtxevalstack) delete _svtxevalstack;
141 
142  return 0;
143 }
144 
145 
146 //----------------------------------------------------------------------------//
147 //-- fill_tree():
148 //-- Fill the trees with truth, track fit, and cluster information
149 //----------------------------------------------------------------------------//
151 {
152  // Make sure to reset all the TTree variables before trying to set them.
153  reset_variables();
154 
155  // get evaluators
158 
159  if (_truth_container)
160  {
161 
164 
165  for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
166  iter != range.second;
167  ++iter)
168  {
169 
170  PHG4Particle* g4particle = iter->second;
171 
172  gtrackID = g4particle->get_track_id();
173  gflavor = g4particle->get_pid();
174 
175  PHG4VtxPoint* vtx = trutheval->get_vertex(g4particle);
176  gvx = vtx->get_x();
177  gvy = vtx->get_y();
178  gvz = vtx->get_z();
179 
180  gpx = g4particle->get_px();
181  gpy = g4particle->get_py();
182  gpz = g4particle->get_pz();
183 
184  SvtxTrack* track = trackeval->best_track_from(g4particle);
185  if (track)
186  {
187  trackID = track->get_id();
188  charge = track->get_charge();
189  nhits = track->size_clusters();
190  px = track->get_px();
191  py = track->get_py();
192  pz = track->get_pz();
193  dca2d = track->get_dca2d();
194 
195 
196  int iclus = 0;
197  for (SvtxTrack::ConstClusterIter iter = track->begin_clusters();
198  iter != track->end_clusters();
199  ++iter)
200  {
201  unsigned int cluster_id = *iter;
202  SvtxCluster* cluster = _clustermap->get(cluster_id);
203  unsigned int l = cluster->get_layer();
204 
205  clusterID[iclus] = (int)cluster_id;
206  layer[iclus] = (int)l;
207  x[iclus] = cluster->get_x();
208  y[iclus] = cluster->get_y();
209  z[iclus] = cluster->get_z();
210  size_dphi[iclus] = cluster->get_phi_size();
211  size_dz[iclus] = cluster->get_z_size();
212 
213  ++iclus;
214  }
215 
216  } // if(track)
217  } // for( iter)
218  } //if (_truth_container)
219 
220  _tracks->Fill();
221  return;
222 
223 }
224 
225 //----------------------------------------------------------------------------//
226 //-- reset_variables():
227 //-- Reset all the tree variables to their default values.
228 //-- Needs to be called at the start of every event
229 //----------------------------------------------------------------------------//
231 {
232  event = -9999;
233 
234  //-- truth
235  gtrackID = -9999;
236  gflavor = -9999;
237  gpx = -9999;
238  gpy = -9999;
239  gpz = -9999;
240  gvx = -9999;
241  gvy = -9999;
242  gvz = -9999;
243 
244  //-- reco
245  trackID = -9999;
246  charge = -9999;
247  nhits = -9999;
248  px = -9999;
249  py = -9999;
250  pz = -9999;
251  dca2d = -9999;
252 
253  //-- clusters
254  for (int i = 0; i < 7; i++)
255  {
256  clusterID[i] = -9999;
257  layer[i] = -9999;
258  x[i] = -9999;
259  y[i] = -9999;
260  z[i] = -9999;
261  size_dphi[i] = -9999;
262  size_dz[i] = -9999;
263  }
264 
265 }
266 
267 //----------------------------------------------------------------------------//
268 //-- GetNodes():
269 //-- Get all the all the required nodes off the node tree
270 //----------------------------------------------------------------------------//
272 {
273  //DST objects
274  //Truth container
275  _truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
276  if (!_truth_container && _event < 2)
277  {
278  cout << PHWHERE
279  << " PHG4TruthInfoContainer node not found on node tree"
280  << endl;
281  }
282 
283  //Svtx Clusters
284  _clustermap = findNode::getClass<SvtxClusterMap>(topNode, "SvtxClusterMap");
285  if (!_clustermap && _event < 2)
286  {
287  cout << PHWHERE
288  << " SvtxClusterMap node not found on node tree"
289  << endl;
290  }
291 
292 }
293 
294 
295 
296