Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHG4TruthSubsystem.cc
Go to the documentation of this file.
1 #include "PHG4TruthSubsystem.h"
2 #include "PHG4TruthEventAction.h"
5 
6 
8 
9 #include "PHG4VtxPointv1.h"
10 #include "PHG4Particlev2.h"
11 
12 #include "PHG4InEvent.h"
13 
15 #include <phool/getClass.h>
16 
17 #include <Geant4/G4ParticleTable.hh>
18 #include <Geant4/G4ParticleDefinition.hh>
19 #include <Geant4/G4SystemOfUnits.hh>
20 
21 #include <cassert>
22 #include <iostream>
23 
24 using namespace std;
25 
26 //_______________________________________________________________________
28  PHG4Subsystem( name ),
29  eventAction_( NULL ),
30  steppingAction_( NULL ),
31  trackingAction_( NULL ),
32  saveOnlyEmbeded_(false)
33 {}
34 
35 //_______________________________________________________________________
37 {
38 
39  PHNodeIterator iter( topNode );
40  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST" ));
41 
42  // create truth information container
43  PHG4TruthInfoContainer* truthInfoList = findNode::getClass<PHG4TruthInfoContainer>( topNode , "G4TruthInfo" );
44  if ( !truthInfoList )
45  {
46  truthInfoList = new PHG4TruthInfoContainer();
47  dstNode->addNode( new PHIODataNode<PHObject>( truthInfoList, "G4TruthInfo", "PHObject" ));
48  }
49 
50  // event action
51  eventAction_ = new PHG4TruthEventAction();
52 
53  // create stepping action
54  //steppingAction_ = new PHG4TruthSteppingAction( eventAction_ );
55 
56  // create tracking action
57  trackingAction_ = new PHG4TruthTrackingAction( eventAction_ );
58 
59  return 0;
60 }
61 
62 //_______________________________________________________________________
63 int
65 {
66  // pass top node to stepping action so that it gets
67  // relevant nodes needed internally
68  if ( eventAction_ )
69  {
70  eventAction_->SetInterfacePointers( topNode );
71  }
72  else
73  {
74  cout << PHWHERE << " No EventAction registered" << endl;
75  exit(1);
76  }
77 
78  if ( trackingAction_ )
79  {
80  trackingAction_->SetInterfacePointers( topNode );
81  }
82  else
83  {
84  cout << PHWHERE << " No TrackingAction registered" << endl;
85  exit(1);
86  }
87 
89 }
90 
92 {
93  if (saveOnlyEmbeded_)
94  {
95  if (Verbosity()>1)
96  {
97  cout <<__PRETTY_FUNCTION__<<" - INFO - only save the G4 truth information that is associated with the embedded particle"<<endl;
98  }
99 
100  PHG4TruthInfoContainer* truthInfoList = findNode::getClass<PHG4TruthInfoContainer>( topNode , "G4TruthInfo" );
101  assert(truthInfoList);
102 
103  set<int> savevtxlist;
104 
105  // remove particle that is not embedd associated
106  PHG4TruthInfoContainer::Range truth_range = truthInfoList->GetParticleRange();
107  PHG4TruthInfoContainer::Iterator truthiter = truth_range.first;
108  while (truthiter != truth_range.second)
109  {
110  const int primary_id = (truthiter->second)->get_primary_id();
111  if (truthInfoList->isEmbeded(primary_id) <= 0)
112  {
113  // not a embed associated particle
114 
115  truthInfoList->delete_particle(truthiter++);
116  }
117  else
118  {
119  // save vertex id for primary particle which leaves no hit
120  // in active area
121  savevtxlist.insert((truthiter->second)->get_vtx_id());
122  ++truthiter;
123  }
124  }
125 
126  // remove vertex that is not embedd associated
127  PHG4TruthInfoContainer::VtxRange vtxrange = truthInfoList->GetVtxRange();
128  PHG4TruthInfoContainer::VtxIterator vtxiter = vtxrange.first;
129  while (vtxiter != vtxrange.second)
130  {
131  if (savevtxlist.find(vtxiter->first) == savevtxlist.end())
132  {
133  truthInfoList->delete_vtx(vtxiter++);
134  }
135  else
136  {
137  ++vtxiter;
138  }
139  }
140  }
141 
142  return 0;
143 }
144 
145 int
147 {
148  trackingAction_->ResetEvent(topNode);
149  eventAction_->ResetEvent(topNode);
150  return 0;
151 }
152 
153 //_______________________________________________________________________
155 { return eventAction_; }
156 
157 
158 //_______________________________________________________________________
160 { return steppingAction_; }
161 
164 {
165  return trackingAction_;
166 }
int InitRun(PHCompositeNode *)
init
int ResetEvent(PHCompositeNode *)
Clean up after each event.
int isEmbeded(const int trackid) const
int ResetEvent(PHCompositeNode *)
PHNode * findFirst(const std::string &, const std::string &)
std::pair< Iterator, Iterator > Range
#define PHWHERE
Definition: phool.h:23
virtual PHG4SteppingAction * GetSteppingAction(void) const
return pointer to this subsystem stepping action
PHBoolean addNode(PHNode *)
PHG4TruthSubsystem(const std::string &name="TRUTH")
constructor
int process_event(PHCompositeNode *)
event processing
VtxRange GetVtxRange()
Get a range of iterators covering the entire vertex container.
Range GetParticleRange()
Get a range of iterators covering the entire container.
void delete_vtx(VtxIterator viter)
#define NULL
Definition: Pdb.h:9
virtual int Verbosity() const
Gets the verbosity of this module.
Definition: Fun4AllBase.h:64
void SetInterfacePointers(PHCompositeNode *)
get relevant nodes from top node passed as argument
int ResetEvent(PHCompositeNode *)
virtual void SetInterfacePointers(PHCompositeNode *)
Set pointers to the i/o nodes.
virtual int process_after_geant(PHCompositeNode *)
event processing
virtual PHG4TrackingAction * GetTrackingAction(void) const
return pointer to this subsystem stepping action
void delete_particle(Iterator piter)
std::pair< VtxIterator, VtxIterator > VtxRange
virtual PHG4EventAction * GetEventAction(void) const
accessors (reimplemented)