Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MbdReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MbdReco.cc
1 #include "MbdReco.h"
2 #include "MbdEvent.h"
3 #include "MbdGeomV1.h"
4 #include "MbdOutV2.h"
5 #include "MbdPmtContainerV1.h"
6 
9 
11 
12 #include <Event/Event.h>
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h>
15 #include <phool/PHNode.h>
16 #include <phool/PHNodeIterator.h>
17 #include <phool/PHObject.h>
18 #include <phool/PHRandomSeed.h>
19 #include <phool/getClass.h>
20 #include <phool/phool.h>
21 
22 #include <TF1.h>
23 #include <TH1.h>
24 
25 using namespace std;
26 using namespace Fun4AllReturnCodes;
27 
28 //____________________________________________________________________________..
30  : SubsysReco(name)
31 {
32 }
33 
34 //____________________________________________________________________________..
35 MbdReco::~MbdReco() = default;
36 
37 //____________________________________________________________________________..
38 int MbdReco::Init(PHCompositeNode * /*unused*/)
39 {
40  m_gaussian = std::make_unique<TF1>("gaussian", "gaus", 0, 20);
41  m_gaussian->FixParameter(2, m_tres);
42 
43  m_mbdevent = std::make_unique<MbdEvent>();
44 
46 }
47 
48 //____________________________________________________________________________..
50 {
52  {
54  }
55 
56  int ret = getNodes(topNode);
57 
58  m_mbdevent->SetSim(_simflag);
59  m_mbdevent->InitRun();
60 
61  return ret;
62 }
63 
64 //____________________________________________________________________________..
66 {
67  getNodes(topNode);
68 
69  if (m_event != nullptr && m_mbdpmts != nullptr)
70  {
71  int status = m_mbdevent->SetRawData(m_event, m_mbdpmts);
72  if (status == Fun4AllReturnCodes::ABORTEVENT)
73  {
74  return Fun4AllReturnCodes::ABORTEVENT; // there wasn't good data in BBC/MBD
75  }
76  else if (status == Fun4AllReturnCodes::DISCARDEVENT)
77  {
79  }
80  else if (status < 0)
81  {
83  }
84  }
85 
86  m_mbdevent->Calculate(m_mbdpmts, m_mbdout);
87 
88  // For multiple global vertex
89  if (m_mbdevent->get_bbcn(0) > 0 && m_mbdevent->get_bbcn(1) > 0)
90  {
91  auto vertex = std::make_unique<MbdVertexv2>();
92  vertex->set_t(m_mbdevent->get_bbct0());
93  vertex->set_z(m_mbdevent->get_bbcz());
94  vertex->set_z_err(0.6);
95  vertex->set_t_err(m_tres);
96 
97  /*
98  for (int iarm = 0; iarm < 2; iarm++)
99  {
100  vertex->set_bbc_ns( iarm, m_mbdevent->get_bbcn(iarm), m_mbdevent->get_bbcq(iarm), m_mbdevent->get_bbct(iarm) );
101  }
102  */
103 
104  m_mbdvtxmap->insert(vertex.release());
105  }
106 
107  if (Verbosity() > 0)
108  {
109  std::cout << "mbd vertex z and t0 " << m_mbdevent->get_bbcz() << ", " << m_mbdevent->get_bbct0() << std::endl;
110  }
111 
113 }
114 
115 //____________________________________________________________________________..
116 int MbdReco::End(PHCompositeNode * /*unused*/)
117 {
119 }
120 
122 {
123  PHNodeIterator iter(topNode);
124  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
125  if (!dstNode)
126  {
127  std::cout << PHWHERE << "DST Node missing doing nothing" << std::endl;
129  }
130 
131  PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
132  if (!runNode)
133  {
134  std::cout << PHWHERE << "RUN Node missing doing nothing" << std::endl;
136  }
137 
138  PHNodeIterator dstiter(dstNode);
139  PHCompositeNode *bbcNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", "MBD"));
140  if (!bbcNode)
141  {
142  bbcNode = new PHCompositeNode("MBD");
143  dstNode->addNode(bbcNode);
144  }
145 
146  PHNodeIterator runiter(runNode);
147  PHCompositeNode *bbcRunNode = dynamic_cast<PHCompositeNode *>(runiter.findFirst("PHCompositeNode", "MBD"));
148  if (!bbcRunNode)
149  {
150  bbcRunNode = new PHCompositeNode("MBD");
151  runNode->addNode(bbcRunNode);
152  }
153 
154  m_mbdout = findNode::getClass<MbdOut>(bbcNode, "MbdOut");
155  if (!m_mbdout)
156  {
157  m_mbdout = new MbdOutV2();
158  PHIODataNode<PHObject> *MbdOutNode = new PHIODataNode<PHObject>(m_mbdout, "MbdOut", "PHObject");
159  bbcNode->addNode(MbdOutNode);
160  }
161 
162  m_mbdpmts = findNode::getClass<MbdPmtContainerV1>(bbcNode, "MbdPmtContainer");
163  if (!m_mbdpmts)
164  {
166  PHIODataNode<PHObject> *MbdPmtContainerNode = new PHIODataNode<PHObject>(m_mbdpmts, "MbdPmtContainer", "PHObject");
167  bbcNode->addNode(MbdPmtContainerNode);
168  }
169 
170  m_mbdvtxmap = findNode::getClass<MbdVertexMap>(bbcNode, "MbdVertexMap");
171  if (!m_mbdvtxmap)
172  {
173  m_mbdvtxmap = new MbdVertexMapv1();
174  PHIODataNode<PHObject> *VertexMapNode = new PHIODataNode<PHObject>(m_mbdvtxmap, "MbdVertexMap", "PHObject");
175  bbcNode->addNode(VertexMapNode);
176  }
177 
178  m_mbdgeom = findNode::getClass<MbdGeom>(runNode, "MbdGeom");
179  if (!m_mbdgeom)
180  {
181  m_mbdgeom = new MbdGeomV1();
182  PHIODataNode<PHObject> *MbdGeomNode = new PHIODataNode<PHObject>(m_mbdgeom, "MbdGeom", "PHObject");
183  bbcRunNode->addNode(MbdGeomNode);
184  }
185 
187 }
188 
190 {
191  // Get the bbc prdf data to mpcRawContent
192  m_event = findNode::getClass<Event>(topNode, "PRDF");
193  // cout << "event addr " << (unsigned int)m_event << endl;
194 
195  if (m_event == nullptr)
196  {
197  _simflag = 1;
198 
199  static int counter = 0;
200  if (counter < 1)
201  {
202  cout << PHWHERE << "Unable to get PRDF, assuming this is simulation" << endl;
203  counter++;
204  }
205  }
206 
207  // MbdPmtContainer
208  m_mbdpmts = findNode::getClass<MbdPmtContainer>(topNode, "MbdPmtContainer");
209  if (!m_mbdpmts)
210  {
211  std::cout << PHWHERE << " MbdPmtContainer node not found on node tree" << std::endl;
213  }
214 
215  m_mbdvtxmap = findNode::getClass<MbdVertexMap>(topNode, "MbdVertexMap");
216  if (!m_mbdvtxmap)
217  {
218  std::cout << PHWHERE << "MbdVertexMap node not found on node tree" << std::endl;
220  }
221 
223 }