Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MbdVertexFastSimReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MbdVertexFastSimReco.cc
1 
2 #include "MbdVertexFastSimReco.h"
3 
6 
8 #include <g4main/PHG4VtxPoint.h>
9 
11 #include <fun4all/SubsysReco.h> // for SubsysReco
12 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h>
15 #include <phool/PHNode.h> // for PHNode
16 #include <phool/PHNodeIterator.h>
17 #include <phool/PHObject.h> // for PHObject
18 #include <phool/PHRandomSeed.h>
19 #include <phool/getClass.h>
20 #include <phool/phool.h> // for PHWHERE
21 
22 #include <gsl/gsl_randist.h>
23 #include <gsl/gsl_rng.h> // for gsl_rng_uniform_pos, gsl_...
24 
25 #include <cmath>
26 #include <cstdlib> // for exit
27 #include <iostream>
28 
29 using namespace std;
30 
32  : SubsysReco(name)
33  , m_T_Smear(NAN)
34  , m_Z_Smear(NAN)
35 {
36  RandomGenerator = gsl_rng_alloc(gsl_rng_mt19937);
37 }
38 
40 {
41  gsl_rng_free(RandomGenerator);
42 }
43 
45 {
47 }
48 
50 {
51  if (isnan(m_T_Smear) || isnan(m_Z_Smear))
52  {
53  cout << PHWHERE << "::ERROR - smearing must be defined via setm_T_Smearing(float) and set_z_smeaering(float)" << endl;
54  exit(-1);
55  }
56 
57  unsigned int seed = PHRandomSeed(); // fixed random seed handled in PHRandomSeed()
59 
60  if (Verbosity() > 0)
61  {
62  cout << "===================== MbdVertexFastSimReco::InitRun() =====================" << endl;
63  cout << " t smearing: " << m_T_Smear << " cm " << endl;
64  cout << " z smearing: " << m_Z_Smear << " cm " << endl;
65  cout << " random seed: " << seed << endl;
66  cout << "===========================================================================" << endl;
67  }
68 
69  return CreateNodes(topNode);
70 }
71 
73 {
74  if (Verbosity() > 1)
75  {
76  cout << "MbdVertexFastSimReco::process_event -- entered" << endl;
77  }
78 
79  //---------------------------------
80  // Get Objects off of the Node Tree
81  //---------------------------------
82  PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
83  if (!truthinfo)
84  {
85  cout << PHWHERE << "::ERROR - cannot find G4TruthInfo" << endl;
86  exit(-1);
87  }
88 
89  MbdVertexMap *vertexes = findNode::getClass<MbdVertexMap>(topNode, "MbdVertexMap");
90  if (!vertexes)
91  {
92  cout << PHWHERE << "::ERROR - cannot find MbdVertexMap" << endl;
93  exit(-1);
94  }
95 
96  //---------------------
97  // Smear Truth Vertexes (only one per crossing right now)
98  //---------------------
99 
100  PHG4VtxPoint *point = truthinfo->GetPrimaryVtx(truthinfo->GetPrimaryVertexIndex());
101  if (!point)
102  {
104  }
105 
106  MbdVertex *vertex = new MbdVertexv2();
107 
108  if (m_T_Smear >= 0.0)
109  {
110  vertex->set_t(point->get_t() + gsl_ran_gaussian(RandomGenerator, m_T_Smear));
111  vertex->set_t_err(m_T_Smear);
112  }
113  else
114  {
115  vertex->set_t(point->get_t() + 2.0 * gsl_rng_uniform_pos(RandomGenerator) * m_T_Smear);
116  vertex->set_t_err(fabs(m_T_Smear) / sqrt(12));
117  }
118 
119  if (m_Z_Smear >= 0.0)
120  {
121  vertex->set_z(point->get_z() + gsl_ran_gaussian(RandomGenerator, m_Z_Smear));
122  vertex->set_z_err(m_Z_Smear);
123  }
124  else
125  {
126  vertex->set_z(point->get_z() + 2.0 * gsl_rng_uniform_pos(RandomGenerator) * m_Z_Smear);
127  vertex->set_z_err(fabs(m_Z_Smear) / sqrt(12));
128  }
129 
130  vertexes->insert(vertex);
131 
133 }
134 
136 {
138 }
139 
141 {
142  PHNodeIterator iter(topNode);
143 
144  // Looking for the DST node
145  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
146  if (!dstNode)
147  {
148  cout << PHWHERE << "DST Node missing, doing nothing." << endl;
150  }
151 
152  // store the BBC stuff under a sub-node directory
153  PHCompositeNode *bbcNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "BBC"));
154  if (!bbcNode)
155  {
156  bbcNode = new PHCompositeNode("BBC");
157  dstNode->addNode(bbcNode);
158  }
159 
160  // create the MbdVertexMap
161  MbdVertexMap *vertexes = findNode::getClass<MbdVertexMap>(topNode, "MbdVertexMap");
162  if (!vertexes)
163  {
164  vertexes = new MbdVertexMapv1();
165  PHIODataNode<PHObject> *VertexMapNode = new PHIODataNode<PHObject>(vertexes, "MbdVertexMap", "PHObject");
166  bbcNode->addNode(VertexMapNode);
167  }
168  else
169  {
170  cout << PHWHERE << "::ERROR - MbdVertexMap pre-exists, but should not if running FastSim" << endl;
171  exit(-1);
172  }
173 
175 }