ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4HeadReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4HeadReco.cc
1 #include "PHG4HeadReco.h"
2 
3 #include "PHG4EventHeader.h" // for PHG4EventHeader
4 #include "PHG4EventHeaderv1.h"
5 
6 #include <ffaobjects/FlagSave.h> // for FlagSave
8 
10 
11 #include <phool/getClass.h>
12 #include <phool/PHCompositeNode.h>
13 #include <phool/PHIODataNode.h> // for PHIODataNode
14 #include <phool/PHNode.h> // for PHNode
15 #include <phool/PHNodeIterator.h> // for PHNodeIterator
16 #include <phool/PHObject.h> // for PHObject
17 #include <phool/phool.h>
18 
19 #include <TSystem.h>
20 
21 #include <HepMC/GenEvent.h>
22 #include <HepMC/HeavyIon.h> // for HeavyIon
23 
24 #include <cstdlib>
25 #include <iostream>
26 
27 using namespace std;
28 
29 PHG4HeadReco::PHG4HeadReco(const std::string &name):
30  SubsysReco(name),
31  evtseq(0)
32 {}
33 
34 int
36 {
37  enum {DSTNODE, RUNNODE, LAST}; // leave LAST at end - it is used for loops
38  // first test if neccessary nodes have been created, if not bail out
39  const char *NName[] = {
40  "DST",
41  "RUN"};
42 
43  PHNodeIterator iter(topNode);
44  PHCompositeNode *outNode[LAST];
45  for (int i=0; i<LAST; i++)
46  {
47  outNode[i] = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode",NName[i]));
48  if (!outNode[i])
49  {
50  cout << PHWHERE << NName[i] << " node is missing, no point in continuing exiting now" << endl;
51  gSystem->Exit(1);
52  // just to make scan-build happy which does not know that gSystem->Exit() terminates
53  exit(1);
54  }
55  }
56  PHG4EventHeader *eventheader = new PHG4EventHeaderv1();
57  PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(eventheader,"EventHeader","PHObject");
58  outNode[DSTNODE]->addNode(newNode);
59 
60  FlagSave *flgsv = new FlagSavev1();
61  PHIODataNode<PHObject> *FlagSaveNode =
62  new PHIODataNode<PHObject>(flgsv, "Flags", "PHObject");
63  outNode[RUNNODE]->addNode(FlagSaveNode);
65 }
66 
67 int
69 {
70  HepMC::GenEvent *hepmcevt = findNode::getClass<HepMC::GenEvent>(topNode, "HEPMC");
71  PHG4EventHeader *evtheader = findNode::getClass<PHG4EventHeader>(topNode,"EventHeader");
72  evtseq++;
73  if (hepmcevt)
74  {
75  evtseq = hepmcevt->event_number();
76  HepMC::HeavyIon *hi = hepmcevt->heavy_ion();
77  if (hi)
78  {
79  evtheader->set_ImpactParameter(hi->impact_parameter());
80  evtheader->set_EventPlaneAngle(hi->event_plane_angle());
81  }
82  }
83  evtheader->set_EvtSequence(evtseq);
84  if (Verbosity() > 0)
85  {
86  evtheader->identify();
87  }
89 }