ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4TruthSubsystem.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4TruthSubsystem.cc
1 #include "PHG4TruthSubsystem.h"
2 
3 #include "PHG4Particle.h" // for PHG4Particle
4 #include "PHG4TruthEventAction.h"
7 
9 
10 #include <phool/PHCompositeNode.h>
11 #include <phool/PHIODataNode.h> // for PHIODataNode
12 #include <phool/PHNode.h> // for PHNode
13 #include <phool/PHNodeIterator.h> // for PHNodeIterator
14 #include <phool/PHObject.h> // for PHObject
15 #include <phool/getClass.h>
16 #include <phool/phool.h> // for PHWHERE
17 
18 #include <cassert>
19 #include <cstdlib> // for exit
20 #include <iostream>
21 #include <set> // for _Rb_tree_iterator, set, _Rb_...
22 #include <utility> // for pair
23 
24 class PHG4EventAction;
25 class PHG4TrackingAction;
26 
27 using namespace std;
28 
29 //_______________________________________________________________________
31  : PHG4Subsystem(name)
32  , m_EventAction(nullptr)
33  , m_TrackingAction(nullptr)
34  , m_SaveOnlyEmbededFlag(false)
35 {
36 }
37 
38 //_______________________________________________________________________
40 {
41  PHNodeIterator iter(topNode);
42  PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
43 
44  // create truth information container
45  PHG4TruthInfoContainer* truthInfoList = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
46  if (!truthInfoList)
47  {
48  truthInfoList = new PHG4TruthInfoContainer();
49  dstNode->addNode(new PHIODataNode<PHObject>(truthInfoList, "G4TruthInfo", "PHObject"));
50  }
51 
52  // event action
54 
55  // create tracking action
57 
58  return 0;
59 }
60 
61 //_______________________________________________________________________
63 {
64  // pass top node to event action so that it gets
65  // relevant nodes needed internally
66  if (m_EventAction)
67  {
69  }
70  else
71  {
72  cout << PHWHERE << " No EventAction registered" << endl;
73  exit(1);
74  }
75 
76  if (m_TrackingAction)
77  {
79  }
80  else
81  {
82  cout << PHWHERE << " No TrackingAction registered" << endl;
83  exit(1);
84  }
85 
87 }
88 
90 {
92  {
93  if (Verbosity() > 1)
94  {
95  cout << __PRETTY_FUNCTION__ << " - INFO - only save the G4 truth information that is associated with the embedded particle" << endl;
96  }
97 
98  PHG4TruthInfoContainer* truthInfoList = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
99  assert(truthInfoList);
100 
101  set<int> savevtxlist;
102 
103  // remove particle that is not embedd associated
104  PHG4TruthInfoContainer::Range truth_range = truthInfoList->GetParticleRange();
105  PHG4TruthInfoContainer::Iterator truthiter = truth_range.first;
106  while (truthiter != truth_range.second)
107  {
108  const int primary_id = (truthiter->second)->get_primary_id();
109  if (truthInfoList->isEmbeded(primary_id) <= 0)
110  {
111  // not a embed associated particle
112 
113  truthInfoList->delete_particle(truthiter++);
114  }
115  else
116  {
117  // save vertex id for primary particle which leaves no hit
118  // in active area
119  savevtxlist.insert((truthiter->second)->get_vtx_id());
120  ++truthiter;
121  }
122  }
123 
124  // remove vertex that is not embedd associated
125  PHG4TruthInfoContainer::VtxRange vtxrange = truthInfoList->GetVtxRange();
126  PHG4TruthInfoContainer::VtxIterator vtxiter = vtxrange.first;
127  while (vtxiter != vtxrange.second)
128  {
129  if (savevtxlist.find(vtxiter->first) == savevtxlist.end())
130  {
131  truthInfoList->delete_vtx(vtxiter++);
132  }
133  else
134  {
135  ++vtxiter;
136  }
137  }
138  }
139 
140  return 0;
141 }
142 
144 {
145  m_TrackingAction->ResetEvent(topNode);
146  m_EventAction->ResetEvent(topNode);
147  return 0;
148 }
149 
150 //_______________________________________________________________________
152 {
153  return m_EventAction;
154 }
155 
156 //_______________________________________________________________________
157 
160 {
161  return m_TrackingAction;
162 }