EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackFastSimEval.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackFastSimEval.cc
1 
2 #include <iostream>
3 
4 #include <TVector3.h>
5 #include <TH1D.h>
6 
9 
10 #include <g4main/PHG4Particle.h>
12 
14 #include <fun4all/PHTFileServer.h>
15 #include <fun4all/SubsysReco.h>
16 
17 #include <phool/getClass.h>
18 
19 #include "TrackFastSimEval.h"
20 
21 using namespace std;
22 
23 // ---------------------------------------------------------------------------------------
24 
25 TrackFastSimEval::TrackFastSimEval(const string &name, const string &filename,
26  const string &trackmapname)
27  : SubsysReco(name)
28  , _outfile_name(filename)
29  , _trackmapname(trackmapname)
30  , _event(0)
31  , _h1d_Delta_mom(nullptr)
32 {
33 } // TrackFastSimEval::TrackFastSimEval()
34 
35 // ---------------------------------------------------------------------------------------
36 
38 {
39  cout << PHWHERE << " Opening file " << _outfile_name << endl;
40  PHTFileServer::get().open(_outfile_name, "RECREATE");
41 
42  _h1d_Delta_mom = new TH1D("_h1d_Delta_mom", "#frac{#Delta p}{truth p}", 100, -0.2, 0.2);
43 
45 } // TrackFastSimEval::Init()
46 
47 // ---------------------------------------------------------------------------------------
48 
50 {
51  if (++_event % 100 == 0) cout << PHWHERE << "Events processed: " << _event << endl;
52 
53  auto _truth_container = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
54  auto _trackmap = findNode::getClass<SvtxTrackMap>(topNode, _trackmapname);
55  if (!_truth_container || !_trackmap) {
56  cout << PHWHERE << " Either PHG4TruthInfoContainer or SvtxTrackMap node not found on node tree"
57  << endl;
59  } //if
60 
61  {
63 
64  // Loop through all the truth particles;
65  for (auto truth_itr = range.first; truth_itr != range.second; ++truth_itr) {
66  auto g4particle = truth_itr->second;
67  if (!g4particle) continue;
68 
69  // Loop through all the reconstructed particles and find a match; how about std::map?;
70  for (auto track_itr = _trackmap->begin(); track_itr != _trackmap->end(); track_itr++) {
71  auto track = dynamic_cast<SvtxTrack_FastSim *>(track_itr->second);
72  if (!track) {
73  std::cout << "ERROR CASTING PARTICLE!" << std::endl;
74  continue;
75  } //if
76 
77  // Matching reconstructed particle found, use it and break;
78  if ((track->get_truth_track_id() - g4particle->get_track_id()) == 0) {
79  TVector3 truth_mom(g4particle->get_px(), g4particle->get_py(), g4particle->get_pz());
80  TVector3 reco_mom ( track->get_px(), track->get_py(), track->get_pz());
81 
82  _h1d_Delta_mom->Fill((reco_mom.Mag() - truth_mom.Mag()) / truth_mom.Mag());
83 
84  break;
85  } //if
86  } //for
87  }
88  }
90 } // TrackFastSimEval::process_event()
91 
92 // ---------------------------------------------------------------------------------------
93 
95 {
97 
98  _h1d_Delta_mom->Write();
99 
101 } // TrackFastSimEval::End()
102 
103 // ---------------------------------------------------------------------------------------