Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlobalVertexFastSimReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GlobalVertexFastSimReco.cc
2 
3 #include <globalvertex/GlobalVertex.h> // for GlobalVertex
4 #include <globalvertex/GlobalVertexMap.h> // for GlobalVertexMap
7 
9 #include <g4main/PHG4VtxPoint.h>
10 
12 #include <fun4all/SubsysReco.h> // for SubsysReco
13 
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHIODataNode.h>
16 #include <phool/PHNode.h> // for PHNode
17 #include <phool/PHNodeIterator.h>
18 #include <phool/PHObject.h> // for PHObject
19 #include <phool/PHRandomSeed.h>
20 #include <phool/getClass.h>
21 #include <phool/phool.h> // for PHWHERE
22 
23 #include <gsl/gsl_randist.h>
24 #include <gsl/gsl_rng.h> // for gsl_rng_alloc, gsl_rng_free
25 
26 #include <cmath>
27 #include <cstdlib> // for exit
28 #include <iostream>
29 
31  : SubsysReco(name)
32 {
33  RandomGenerator = gsl_rng_alloc(gsl_rng_mt19937);
34 }
35 
37 {
38  gsl_rng_free(RandomGenerator);
39 }
40 
42 {
43  if (isnan(_x_smear) ||
44  isnan(_y_smear) ||
45  isnan(_z_smear) ||
46  isnan(_t_smear))
47  {
48  std::cout << PHWHERE << "::ERROR - smearing must be defined for (x,y,z,t) via set_?_smearing(float)" << std::endl;
49  exit(-1);
50  }
51 
52  unsigned int seed = PHRandomSeed(); // fixed seed handled in PHRandomSeed()
54 
55  if (Verbosity() > 0)
56  {
57  std::cout << "=================== GlobalVertexFastSimReco::InitRun() ====================" << std::endl;
58  std::cout << " x smearing: " << _x_smear << " cm " << std::endl;
59  std::cout << " y smearing: " << _y_smear << " cm " << std::endl;
60  std::cout << " z smearing: " << _z_smear << " cm " << std::endl;
61  std::cout << " t smearing: " << _t_smear << " cm " << std::endl;
62  std::cout << " random seed: " << seed << std::endl;
63  std::cout << "===========================================================================" << std::endl;
64  }
65 
66  return CreateNodes(topNode);
67 }
68 
70 {
71  if (Verbosity() > 1)
72  {
73  std::cout << "GlobalVertexFastSimReco::process_event -- entered" << std::endl;
74  }
75 
76  //---------------------------------
77  // Get Objects off of the Node Tree
78  //---------------------------------
79  PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
80  if (!truthinfo)
81  {
82  std::cout << PHWHERE << "::ERROR - cannot find G4TruthInfo" << std::endl;
83  exit(-1);
84  }
85 
86  GlobalVertexMap *vertexes = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
87  if (!vertexes)
88  {
89  std::cout << PHWHERE << "::ERROR - cannot find GlobalVertexMap" << std::endl;
90  exit(-1);
91  }
92 
93  //---------------------
94  // Smear Truth Vertexes (only one per crossing right now)
95  //---------------------
96 
97  PHG4VtxPoint *point = truthinfo->GetPrimaryVtx(truthinfo->GetPrimaryVertexIndex());
98 
100  vertex->set_x(point->get_x());
101  vertex->set_y(point->get_y());
102  vertex->set_z(point->get_z());
103  vertex->set_t(point->get_t());
104  vertex->set_t_err(0.);
105  for (int i = 0; i < 3; i++)
106  {
107  for (int j = 0; j < 3; j++)
108  {
109  vertex->set_error(i, j, 0.0);
110  }
111  }
112  vertexes->insert(vertex);
113 
115 
116  vertex->set_x(point->get_x() + gsl_ran_gaussian(RandomGenerator, _x_smear));
117  vertex->set_y(point->get_y() + gsl_ran_gaussian(RandomGenerator, _y_smear));
118  vertex->set_z(point->get_z() + gsl_ran_gaussian(RandomGenerator, _z_smear));
119 
120  vertex->set_error(0, 0, _x_smear * _x_smear);
121  vertex->set_error(0, 1, 0.0);
122  vertex->set_error(0, 2, 0.0);
123 
124  vertex->set_error(1, 0, 0.0);
125  vertex->set_error(1, 1, _y_smear * _y_smear);
126  vertex->set_error(1, 2, 0.0);
127 
128  vertex->set_error(2, 0, 0.0);
129  vertex->set_error(2, 1, 0.0);
130  vertex->set_error(2, 2, _z_smear * _z_smear);
131 
132  vertex->set_t(point->get_t() + gsl_ran_gaussian(RandomGenerator, _t_smear));
133  vertex->set_t_err(_t_smear);
134 
135  vertexes->insert(vertex);
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  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
150  }
151 
152  // store the GLOBAL stuff under a sub-node directory
153  PHCompositeNode *globalNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "GLOBAL"));
154  if (!globalNode)
155  {
156  globalNode = new PHCompositeNode("GLOBAL");
157  dstNode->addNode(globalNode);
158  }
159 
160  // create the GlobalVertexMap
161  GlobalVertexMap *vertexes = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
162  if (!vertexes)
163  {
164  vertexes = new GlobalVertexMapv1();
165  PHIODataNode<PHObject> *VertexMapNode = new PHIODataNode<PHObject>(vertexes, "GlobalVertexMap", "PHObject");
166  globalNode->addNode(VertexMapNode);
167  }
168  else
169  {
170  std::cout << PHWHERE << "::ERROR - GlobalVertexMap pre-exists, but should not if running FastSim" << std::endl;
171  exit(-1);
172  }
173 
175 }