Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DSTTrackInfoWriter.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DSTTrackInfoWriter.cc
1 
6 #include "DSTTrackInfoWriter.h"
7 
9 #include <g4main/PHG4Hit.h>
11 #include <g4main/PHG4Particle.h>
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHNodeIterator.h>
16 #include <phool/getClass.h>
17 #include <trackbase/InttDefs.h>
18 #include <trackbase/MvtxDefs.h>
19 #include <trackbase/TpcDefs.h>
20 #include <trackbase/TrkrCluster.h>
22 #include <trackbase/TrkrDefs.h>
23 // include new cluster
26 #include <trackbase/TrkrHit.h>
27 #include <trackbase/TrkrHitSet.h>
33 // include SvtxTrackMap_v1 to write data to it
39 
40 #include <algorithm>
41 #include <bitset>
42 #include <cassert>
43 #include <iostream>
44 #include <numeric>
45 
46 #include <TClonesArray.h>
47 #include <TFile.h>
48 #include <TLine.h>
49 #include <TTree.h>
50 //_____________________________________________________________________
51 
52 //_____________________________________________________________________
54  : SubsysReco(name)
55 {
56 }
57 
58 //_____________________________________________________________________
60 {
61  if (Verbosity() > 1)
62  {
63  std::cout << "Writer Init start" << std::endl;
64  }
65  // find DST node
66  PHNodeIterator iter(topNode);
67  auto dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
68  if (!dstNode)
69  {
70  std::cout << "DSTTrackInfoWriter::Init - DST Node missing" << std::endl;
72  }
73 
74  // get EVAL node
75  iter = PHNodeIterator(dstNode);
76  auto evalNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "EVAL"));
77  if (!evalNode)
78  {
79  // create
80  std::cout << "DSTTrackInfoWriter::Init - EVAL node missing - creating" << std::endl;
81  evalNode = new PHCompositeNode("EVAL");
82  dstNode->addNode(evalNode);
83  }
84 
85  // // TClonesArary
86  // m_container->arrClsDST = new TClonesArray("DSTContainerv3::ClusterStruct");
87  // m_container->trkrClsDST = new TClonesArray("TrkrClusterv4");
88 
89  auto newInfoNode = new PHIODataNode<PHObject>(new TrackInfoContainer_v1, "TrackInfoContainer", "PHObject");
90  evalNode->addNode(newInfoNode);
91 
92  // auto newTrackNode = new PHIODataNode<PHObject>(new SvtxTrackArray_v1, "TRACK_ARRAYV1", "PHObject");
93  // evalNode->addNode(newTrackNode);
94 
95  // TClonesArary
96  // fcl = new TFile("dstcl.root", "recreate");
97  // tcl = new TTree("tcl", "dst tree");
98  // arrEvt = new TClonesArray("DSTContainerv3::EventStruct");
99  // arrTrk = new TClonesArray("DSTContainerv3::TrackStruct");
100  // arrCls = new TClonesArray("DSTContainerv3::ClusterStruct");
101  // tcl->Branch("evt", &arrEvt);
102  // tcl->Branch("trk", &arrTrk);
103  // tcl->Branch("cls", &arrCls);
104  if (Verbosity() > 1)
105  {
106  std::cout << "Writer Init end" << std::endl;
107  }
109 }
110 
111 //_____________________________________________________________________
113 {
114  // make topNode run in Init
115  // Init(topNode);
116  // load nodes
117  if (Verbosity() > 1)
118  {
119  std::cout << __FILE__ << "::" << __func__ << "::" << __LINE__ << std::endl;
120  std::cout << "DSTTrackInfoWriter::process_event" << std::endl;
121  }
122  auto res = load_nodes(topNode);
123  if (res != Fun4AllReturnCodes::EVENT_OK)
124  {
125  return res;
126  }
127  if (Verbosity() > 1)
128  {
129  std::cout << "Return codes start" << Fun4AllReturnCodes::EVENT_OK << std::endl;
130  }
131  // cleanup output container
133  if (Verbosity() > 1)
134  {
135  std::cout << "Evalutate track info" << std::endl;
136  }
138  if (Verbosity() > 1)
139  {
140  std::cout << "exiting event"
141  << "\n";
142 
143  std::cout << "Return codes end" << Fun4AllReturnCodes::EVENT_OK << std::endl;
144  }
146 }
147 
148 //_____________________________________________________________________
150 {
151  // get necessary nodes
152  m_track_map = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
153 
154  m_track_info_container = findNode::getClass<TrackInfoContainer_v1>(topNode, "TrackInfoContainer");
155 
157 }
158 
159 //____________________________________________________________________
161 {
162  if (!(m_track_info_container))
163  {
164  return;
165  }
166 
168  // get track into track info
169  Int_t iTrk = 0;
170  // long unsigned int iKey = 0;
171  if (Verbosity() > 1)
172  {
173  std::cout << "Before loop"
174  << "\n";
175  }
176  for (const auto& trackpair : *m_track_map)
177  {
178  const auto track = trackpair.second;
179  // this track will have a TPC and Silicon seed
180 
181  uint64_t hitbitmap = 0;
182 
183  SvtxTrackInfo_v1* trackInfo = new SvtxTrackInfo_v1();
184  if (Verbosity() > 1)
185  {
186  std::cout << "Before seeds"
187  << "\n";
188  }
189  TrackSeed* TPCSeed = track->get_tpc_seed();
190  TrackSeed* SiliconSeed = track->get_silicon_seed();
191  if (TPCSeed)
192  {
193  for (auto key_iter = TPCSeed->begin_cluster_keys(); key_iter != TPCSeed->end_cluster_keys(); ++key_iter)
194  {
195  const auto& cluster_key = *key_iter;
196 
197  // store information in track array
198  // std::cout << "TPC clusterkey: " << cluster_key <<"\n";
199  // std::cout << "TPC subsurfkey: " << cluster->getSubSurfKey() << std::endl;
200  uint8_t layer = TrkrDefs::getLayer(cluster_key);
201  if (Verbosity() > 1)
202  {
203  std::cout << "Layer is: " << unsigned(layer) << std::endl;
204  }
205  hitbitmap = hitbitmap + ((uint64_t) 1 << layer);
206 
207  // TrkrDefs::
208  }
209  }
210  if (Verbosity() > 1)
211  {
212  std::cout << "Before Silicon seeds"
213  << "\n";
214  }
215  if (!SiliconSeed)
216  {
217  if (Verbosity() > 1)
218  {
219  std::cout << "Silicon Seed does not exist" << std::endl;
220  }
221  }
222 
223  if (SiliconSeed)
224  {
225  for (auto key_iter = SiliconSeed->begin_cluster_keys(); key_iter != SiliconSeed->end_cluster_keys(); ++key_iter)
226  {
227  const auto& cluster_key = *key_iter;
228 
229  uint8_t layer = TrkrDefs::getLayer(cluster_key);
230  if (Verbosity() > 1)
231  {
232  std::cout << "Layer is: " << unsigned(layer) << std::endl;
233  }
234  hitbitmap = hitbitmap + ((uint64_t) 1 << layer);
235  }
236  }
237  if (Verbosity() > 1)
238  {
239  std::cout << "After Track seeds"
240  << "\n";
241  }
242  trackInfo->set_hitbitmap(hitbitmap);
243  trackInfo->set_chisq(track->get_chisq());
244  trackInfo->set_ndf(track->get_ndf());
245  trackInfo->set_crossing(track->get_crossing());
246 
247  trackInfo->set_x(track->get_x());
248  trackInfo->set_y(track->get_y());
249  trackInfo->set_z(track->get_z());
250  trackInfo->set_px(track->get_px());
251  trackInfo->set_py(track->get_py());
252  trackInfo->set_pz(track->get_pz());
253  if (Verbosity() > 1)
254  {
255  std::cout << "track crossing: " << track->get_crossing() << std::endl;
256 
257  std::cout << "track.get_z(): " << track->get_z() << std::endl;
258  std::cout << "trackInfo.get_z(): " << trackInfo->get_z() << std::endl;
259  std::cout << "Hitbitmap: " << trackInfo->get_hitbitmap() << std::endl;
260  std::cout << "crossing: " << trackInfo->get_crossing() << std::endl;
261  std::cout << "chi^2: " << trackInfo->get_chisq() << std::endl;
262  std::cout << "ndf: " << unsigned(trackInfo->get_ndf()) << std::endl;
263  }
264 
265  for (int i = 0; i < 6; i++)
266  {
267  for (int j = i; j < 6; j++)
268  {
269  trackInfo->set_covariance(i, j, track->get_error(i, j));
270  }
271  }
272  if (Verbosity() > 1)
273  {
274  std::cout << "Right before adding track info" << iTrk << std::endl;
275  }
276  m_track_info_container->add_trackinfo(iTrk, trackInfo);
277  if (Verbosity() > 1)
278  {
279  std::cout << "Right after adding track info" << std::endl;
280  }
281  delete trackInfo;
282  ++iTrk;
283  }
284 
285  // add trackinfo to trackinfocontainer
286 }
287 //_____________________________________________________________________
288 
289 //_____________________________________________________________________