Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4EPDModuleReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4EPDModuleReco.cc
1 #include "PHG4EPDModuleReco.h"
2 
3 #include <calobase/TowerInfo.h>
4 #include <calobase/TowerInfoContainer.h>
5 #include <calobase/TowerInfoContainerv1.h>
6 #include <calobase/TowerInfoDefs.h>
7 
8 #include <epd/EPDDefs.h>
9 #include <epd/EpdGeomV1.h>
10 
11 #include <g4main/PHG4Hit.h>
13 #include <g4main/PHG4HitDefs.h> // for hit_idbits
14 
15 #include <phparameter/PHParameterInterface.h>
16 
18 #include <fun4all/SubsysReco.h> // for SubsysReco
19 
20 #include <phool/PHCompositeNode.h>
21 #include <phool/PHIODataNode.h>
22 #include <phool/PHNode.h> // for PHNode
23 #include <phool/PHNodeIterator.h>
24 #include <phool/PHObject.h> // for PHObject
25 #include <phool/getClass.h>
26 #include <phool/phool.h> // for PHWHERE
27 
28 #include <TSystem.h>
29 
30 #include <cstdlib>
31 #include <iostream>
32 #include <map> // for _Rb_tree_const_iterator
33 #include <utility> // for pair
34 
36  : SubsysReco(name)
37  , PHParameterInterface(name)
38 {
40 }
41 
43 {
45 
46  tmin = get_double_param("tmin");
47  tmax = get_double_param("tmax");
48  m_DeltaT = get_double_param("delta_t");
49  m_EpdMpv = get_double_param("epdmpv");
50 
51  CreateNodes(topNode);
52  PHNodeIterator node_itr(topNode);
53  PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(node_itr.findFirst("PHCompositeNode", "RUN"));
54  if (!runNode)
55  {
56  std::cout << PHWHERE << "RUN Node not found - that is fatal" << std::endl;
57  gSystem->Exit(1);
58  exit(1);
59  }
60 
61  PHNodeIterator runiter(runNode);
62  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(runiter.findFirst("PHCompositeNode", m_Detector));
63  if (!DetNode)
64  {
65  DetNode = new PHCompositeNode(m_Detector);
66  runNode->addNode(DetNode);
67  }
68 
69  EpdGeom *epdGeom = findNode::getClass<EpdGeom>(topNode, "TOWERGEOM_EPD");
70  if (!epdGeom)
71  {
72  epdGeom = new EpdGeomV1();
73  PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(epdGeom, "TOWERGEOM_EPD", "PHObject");
74  DetNode->addNode(newNode);
75  }
76 
77  // fill epd geometry
78  unsigned int epdchannels = 744;
79  for (unsigned int ch = 0; ch < epdchannels; ch++)
80  {
81  unsigned int thiskey = TowerInfoDefs::encode_epd(ch);
82  epdGeom->set_z(thiskey, GetTileZ(TowerInfoDefs::get_epd_arm(thiskey)));
83  epdGeom->set_r(thiskey, GetTileR(TowerInfoDefs::get_epd_rbin(thiskey)));
84  if (TowerInfoDefs::get_epd_rbin(thiskey) == 0)
85  {
86  epdGeom->set_phi0(thiskey, GetTilePhi0(TowerInfoDefs::get_epd_phibin(thiskey)));
87  }
88  else
89  {
90  epdGeom->set_phi(thiskey, GetTilePhi(TowerInfoDefs::get_epd_phibin(thiskey)));
91  }
92  }
93 
95 }
96 
98 {
99  PHG4HitContainer *g4hit = findNode::getClass<PHG4HitContainer>(topNode, m_Hitnodename);
100  if (!g4hit)
101  {
102  std::cout << "Could not locate g4 hit node " << m_Hitnodename << std::endl;
103  exit(1);
104  }
105 
106  TowerInfoContainer *m_TowerInfoContainer = findNode::getClass<TowerInfoContainer>(topNode, m_TowerInfoNodeName);
107  if (!m_TowerInfoContainer)
108  {
109  std::cout << PHWHERE << "Could not locate TowerInfoContainer node " << m_TowerInfoNodeName << std::endl;
110  exit(1);
111  }
112 
113  TowerInfoContainer *m_TowerInfoContainer_calib = findNode::getClass<TowerInfoContainer>(topNode, m_TowerInfoNodeName_calib);
114  if (!m_TowerInfoContainer_calib)
115  {
116  std::cout << PHWHERE << "Could not locate TowerInfoContainer node " << m_TowerInfoNodeName_calib << std::endl;
117  exit(1);
118  }
119 
121  PHG4HitContainer::ConstRange hit_begin_end = g4hit->getHits();
122  for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; ++hiter)
123  {
124  if (hiter->second->get_t(0) > tmax)
125  {
126  continue;
127  }
128  if (hiter->second->get_t(1) < tmin)
129  {
130  continue;
131  }
132  if (hiter->second->get_t(1) - hiter->second->get_t(0) > m_DeltaT)
133  {
134  continue;
135  }
136 
137  int sim_tileid = (hiter->second->get_hit_id() >> PHG4HitDefs::hit_idbits);
138  int this_tile = EPDDefs::get_tileid(sim_tileid);
139  int this_sector = EPDDefs::get_sector(sim_tileid);
140  int this_arm = EPDDefs::get_arm(sim_tileid);
141 
142  m_EpdTile_e[this_arm][this_sector][this_tile] += hiter->second->get_light_yield();
143  m_EpdTile_Calib_e[this_arm][this_sector][this_tile] += hiter->second->get_light_yield() / m_EpdMpv;
144 
145  } // end loop over g4hits
146 
147  for (unsigned int k = 0; k < 2; k++)
148  {
149  for (int i = 0; i < 12; i++)
150  {
151  for (int j = 0; j < 31; j++)
152  {
153  unsigned int globalphi = Getphimap(j) + 2 * i;
154  unsigned int r = Getrmap(j);
155 
156  if (r == 0)
157  {
158  globalphi = i;
159  }
160 
161  unsigned int key = TowerInfoDefs::encode_epd(k, r, globalphi);
162  unsigned int ch = m_TowerInfoContainer->decode_key(key);
163  m_TowerInfoContainer->get_tower_at_channel(ch)->set_energy(m_EpdTile_e[k][i][j]);
164  m_TowerInfoContainer_calib->get_tower_at_channel(ch)->set_energy(m_EpdTile_Calib_e[k][i][j]);
165  }
166  }
167  }
168 
170 }
171 
173 {
174  set_default_double_param("tmax", 60.0);
175  set_default_double_param("tmin", -20.0);
176  set_default_double_param("delta_t", 100.);
177  set_default_double_param("epdmpv", 1.);
178  return;
179 }
180 
181 void PHG4EPDModuleReco::set_timing_window(const double tmi, const double tma)
182 {
183  set_double_param("tmin", tmi);
184  set_double_param("tmax", tma);
185 }
186 
188 {
189  static const int rmap[31] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15};
190 
191  return rmap[rindex];
192 }
193 
195 {
196  static const int phimap[31] = {0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
197 
198  return phimap[phiindex];
199 }
200 
202 {
203  static const float tilephi[24] = {0.13089969, 0.39269908, 0.65449847, 0.91629786, 1.17809725, 1.43989663, 1.70169602, 1.96349541, 2.2252948, 2.48709418, 2.74889357, 3.01069296, 3.27249235, 3.53429174, 3.79609112, 4.05789051, 4.3196899, 4.58148929, 4.84328867, 5.10508806, 5.36688745, 5.62868684, 5.89048623, 6.15228561};
204  return tilephi[thisphi];
205 }
206 
208 {
209  static const float tilephi0[12] = {0.26179939, 0.78539816, 1.30899694, 1.83259571, 2.35619449, 2.87979327, 3.40339204, 3.92699082, 4.45058959, 4.97418837, 5.49778714, 6.02138592};
210  return tilephi0[thisphi0];
211 }
212 
214 {
215  static const float tileR[16] = {6.8, 11.2, 15.6, 20.565, 26.095, 31.625, 37.155, 42.685, 48.215, 53.745, 59.275, 64.805, 70.335, 75.865, 81.395, 86.925};
216  return tileR[thisr];
217 }
218 
220 {
221  static const float tileZ[2] = {-316.0, 316.0};
222  return tileZ[thisz];
223 }
224 
226 {
227  PHNodeIterator iter(topNode);
228  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
229  if (!dstNode)
230  {
231  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
232  gSystem->Exit(1);
233  exit(1);
234  }
235 
236  PHNodeIterator dstiter(dstNode);
237  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", m_Detector));
238  if (!DetNode)
239  {
240  DetNode = new PHCompositeNode(m_Detector);
241  dstNode->addNode(DetNode);
242  }
243 
244  m_TowerInfoNodeName = "TOWERINFO_" + m_EPDSimTowerNodePrefix + "_" + m_Detector; // detector name and prefix are set by now
245  TowerInfoContainer *m_TowerInfoContainer = findNode::getClass<TowerInfoContainer>(DetNode, m_TowerInfoNodeName);
246  if (m_TowerInfoContainer == nullptr)
247  {
248  m_TowerInfoContainer = new TowerInfoContainerv1(TowerInfoContainer::DETECTOR::SEPD);
249  PHIODataNode<PHObject> *TowerInfoNode = new PHIODataNode<PHObject>(m_TowerInfoContainer, m_TowerInfoNodeName, "PHObject");
250  DetNode->addNode(TowerInfoNode);
251  }
252 
253  m_TowerInfoNodeName_calib = "TOWERINFO_" + m_EPDCalibTowerNodePrefix + "_" + m_Detector; // detector name and prefix are set by now
254  TowerInfoContainer *m_TowerInfoContainer_calib = findNode::getClass<TowerInfoContainer>(DetNode, m_TowerInfoNodeName_calib);
255  if (m_TowerInfoContainer_calib == nullptr)
256  {
257  m_TowerInfoContainer_calib = new TowerInfoContainerv1(TowerInfoContainer::DETECTOR::SEPD);
258  PHIODataNode<PHObject> *TowerInfoNodecalib = new PHIODataNode<PHObject>(m_TowerInfoContainer_calib, m_TowerInfoNodeName_calib, "PHObject");
259  DetNode->addNode(TowerInfoNodecalib);
260  }
261 
262  return;
263 }
265 {
266  // this only works for initializing to zero
267  m_EpdTile_Calib_e = {};
268  m_EpdTile_e = {};
269  // if you ever want to initialize to a different value, do it this way:
270  // for (auto &entry : epd_tile_calib_e)
271  // {
272  // for (auto &entry1 : entry)
273  // {
274  // entry1.fill(NAN);
275  // }
276  // }
278 }
279 
281 {
283  m_Hitnodename = "G4HIT_" + m_Detector;
284 }