Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TowerJetInput.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TowerJetInput.cc
1 #include "TowerJetInput.h"
2 
3 #include "Jet.h"
4 #include "Jetv2.h"
5 
6 #include <calobase/RawTower.h>
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/TowerInfo.h>
9 #include <calobase/TowerInfoContainer.h>
10 #include <calobase/RawTowerDefs.h> // for encode_towerid
11 #include <calobase/RawTowerGeom.h>
12 #include <calobase/RawTowerGeomContainer.h>
15 
16 #include <phool/getClass.h>
17 
18 #include <cassert>
19 #include <cmath> // for asinh, atan2, cos, cosh
20 #include <iostream>
21 #include <map> // for _Rb_tree_const_iterator
22 #include <utility> // for pair
23 #include <vector>
24 
26  : m_input(input)
27 {
28 }
29 
30 void TowerJetInput::identify(std::ostream &os)
31 {
32  os << " TowerJetInput: ";
33  if (m_input == Jet::CEMC_TOWER)
34  {
35  os << "TOWER_CEMC to Jet::CEMC_TOWER";
36  }
37  else if (m_input == Jet::EEMC_TOWER)
38  {
39  os << "TOWER_EEMC to Jet::EEMC_TOWER";
40  }
41  else if (m_input == Jet::HCALIN_TOWER)
42  {
43  os << "TOWER_HCALIN to Jet::HCALIN_TOWER";
44  }
45  else if (m_input == Jet::HCALOUT_TOWER)
46  {
47  os << "TOWER_HCALOUT to Jet::HCALOUT_TOWER";
48  }
49  else if (m_input == Jet::FEMC_TOWER)
50  {
51  os << "TOWER_FEMC to Jet::FEMC_TOWER";
52  }
53  else if (m_input == Jet::FHCAL_TOWER)
54  {
55  os << "TOWER_FHCAL to Jet::FHCAL_TOWER";
56  }
57  os << std::endl;
58 }
59 
60 std::vector<Jet *> TowerJetInput::get_input(PHCompositeNode *topNode)
61 {
62  if (Verbosity() > 0) std::cout << "TowerJetInput::process_event -- entered" << std::endl;
63 
64  GlobalVertexMap *vertexmap = findNode::getClass<GlobalVertexMap>(topNode, "GlobalVertexMap");
65  if (!vertexmap)
66  {
67  std::cout << "TowerJetInput::get_input - Fatal Error - GlobalVertexMap node is missing. Please turn on the do_global flag in the main macro in order to reconstruct the global vertex." << std::endl;
68  assert(vertexmap); // force quit
69 
70  return std::vector<Jet *>();
71  }
72 
73  if (vertexmap->empty())
74  {
75  std::cout << "TowerJetInput::get_input - Fatal Error - GlobalVertexMap node is empty. Please turn on the do_bbc or tracking reco flags in the main macro in order to reconstruct the global vertex." << std::endl;
76  return std::vector<Jet *>();
77  }
78  m_use_towerinfo = false;
79 
80  /* std::string name =(m_input == Jet::CEMC_TOWER ? "CEMC_TOWER" */
81  /* : m_input == Jet::CEMC_TOWERINFO ? "CEMC_TOWERINFO" */
82  /* : m_input == Jet::EEMC_TOWER ? "Jet::EEMC_TOWER" */
83  /* : m_input == Jet::HCALIN_TOWER ? "Jet::HCALIN_TOWER" */
84  /* : m_input == Jet::HCALIN_TOWERINFO ? "Jet::HCALIN_TOWERINFO" */
85  /* : m_input == Jet::HCALOUT_TOWER ? "Jet::HCALOUT_TOWER" */
86  /* : m_input == Jet::HCALOUT_TOWERINFO ? "Jet::HCALOUT_TOWERINFO" */
87  /* : m_input == Jet::FEMC_TOWER ? "Jet::FEMC_TOWER" */
88  /* : m_input == Jet::FHCAL_TOWER ? "Jet::FHCAL_TOWER" */
89  /* : m_input == Jet::CEMC_TOWER_RETOWER ? "Jet::CEMC_TOWER_RETOWER" */
90  /* : m_input == Jet::CEMC_TOWERINFO_RETOWER ? "Jet::CEMC_TOWERINFO_RETOWER" */
91  /* : m_input == Jet::CEMC_TOWER_SUB1 ? "Jet::CEMC_TOWER_SUB1" */
92  /* : m_input == Jet::CEMC_TOWERINFO_SUB1 ? "Jet::CEMC_TOWERINFO_SUB1" */
93  /* : m_input == Jet::HCALIN_TOWER_SUB1 ? "Jet::HCALIN_TOWER_SUB1" */
94  /* : m_input == Jet::HCALIN_TOWERINFO_SUB1 ? "Jet::HCALIN_TOWERINFO_SUB1" */
95  /* : m_input == Jet::HCALOUT_TOWER_SUB1 ? "Jet::HCALOUT_TOWER_SUB1" */
96  /* : m_input == Jet::HCALOUT_TOWERINFO_SUB1 ? "Jet::HCALOUT_TOWERINFO_SUB1" */
97  /* : m_input == Jet::CEMC_TOWER_SUB1CS ? "Jet::CEMC_TOWER_SUB1CS" */
98  /* : m_input == Jet::HCALIN_TOWER_SUB1CS ? "Jet::HCALIN_TOWER_SUB1CS" */
99  /* : m_input == Jet::HCALOUT_TOWER_SUB1CS ? "Jet::HCALOUT_TOWER_SUB1CS" */
100  /* : "NO NAME"); */
101  /* std::cout << " TowerJetInput (" << name << ")" << std::endl; */
102 
103  RawTowerContainer *towers = nullptr;
104  TowerInfoContainer *towerinfos = nullptr;
105  RawTowerGeomContainer *geom = nullptr;
106  if (m_input == Jet::CEMC_TOWER)
107  {
108  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC");
109  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
110  if ((!towers) || !geom)
111  {
112  return std::vector<Jet *>();
113  }
114  }
115  else if (m_input == Jet::CEMC_TOWERINFO)
116  {
117  m_use_towerinfo = true;
118  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC");
119  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
121  if ((!towerinfos) || !geom)
122  {
123  return std::vector<Jet *>();
124  }
125  }
127  {
128  m_use_towerinfo = true;
129  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_EMBED_CEMC");
130  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
132  if ((!towerinfos) || !geom)
133  {
134  return std::vector<Jet *>();
135  }
136  }
137  else if (m_input == Jet::CEMC_TOWERINFO_SIM)
138  {
139  m_use_towerinfo = true;
140  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_SIM_CEMC");
141  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
143  if ((!towerinfos) || !geom)
144  {
145  return std::vector<Jet *>();
146  }
147  }
148  else if (m_input == Jet::EEMC_TOWER)
149  {
150  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_EEMC");
151  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_EEMC");
152  if ((!towers && !towerinfos) || !geom)
153  {
154  return std::vector<Jet *>();
155  }
156  }
157  else if (m_input == Jet::HCALIN_TOWER)
158  {
159  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALIN");
160  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
161  if ((!towers) || !geom)
162  {
163  return std::vector<Jet *>();
164  }
165  }
166  else if (m_input == Jet::HCALIN_TOWERINFO)
167  {
168  m_use_towerinfo = true;
169  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN");
171  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
172  if ((!towerinfos) || !geom)
173  {
174  return std::vector<Jet *>();
175  }
176  }
178  {
179  m_use_towerinfo = true;
180  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_EMBED_HCALIN");
181  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
183  if ((!towerinfos) || !geom)
184  {
185  return std::vector<Jet *>();
186  }
187  }
189  {
190  m_use_towerinfo = true;
191  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_SIM_HCALIN");
192  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
194  if ((!towerinfos) || !geom)
195  {
196  return std::vector<Jet *>();
197  }
198  }
199  else if (m_input == Jet::HCALOUT_TOWER)
200  {
201  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALOUT");
202  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
203  if ((!towers) || !geom)
204  {
205  return std::vector<Jet *>();
206  }
207  }
208  else if (m_input == Jet::HCALOUT_TOWERINFO)
209  {
210  m_use_towerinfo = true;
211  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT");
213  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
214  if ((!towerinfos) || !geom)
215  {
216  return std::vector<Jet *>();
217  }
218  }
220  {
221  m_use_towerinfo = true;
222  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_EMBED_HCALOUT");
223  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
225  if ((!towerinfos) || !geom)
226  {
227  return std::vector<Jet *>();
228  }
229  }
231  {
232  m_use_towerinfo = true;
233  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_SIM_HCALOUT");
234  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
236  if ((!towerinfos) || !geom)
237  {
238  return std::vector<Jet *>();
239  }
240  }
241 
242 
243  else if (m_input == Jet::FEMC_TOWER)
244  {
245  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_FEMC");
246  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_FEMC");
247  if ((!towers) || !geom)
248  {
249  return std::vector<Jet *>();
250  }
251  }
252  else if (m_input == Jet::FHCAL_TOWER)
253  {
254  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_FHCAL");
255  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_FHCAL");
256  if ((!towers) || !geom)
257  {
258  return std::vector<Jet *>();
259  }
260  }
261  else if (m_input == Jet::CEMC_TOWER_RETOWER)
262  {
263  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER");
264  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
265  if ((!towers) || !geom)
266  {
267  return std::vector<Jet *>();
268  }
269  }
271  {
272  m_use_towerinfo = true;
273  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC_RETOWER");
275  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
276  if ((!towerinfos) || !geom)
277  {
278  return std::vector<Jet *>();
279  }
280  }
281  else if (m_input == Jet::CEMC_TOWER_SUB1)
282  {
283  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER_SUB1");
284  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
285  if ((!towers) || !geom)
286  {
287  return std::vector<Jet *>();
288  }
289  }
290  else if (m_input == Jet::CEMC_TOWERINFO_SUB1)
291  {
292  m_use_towerinfo = true;
293  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC_RETOWER_SUB1");
295  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
296  if ((!towerinfos) || !geom)
297  {
298  return std::vector<Jet *>();
299  }
300  }
301  else if (m_input == Jet::HCALIN_TOWER_SUB1)
302  {
303  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALIN_SUB1");
304  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
305  if ((!towers) || !geom)
306  {
307  return std::vector<Jet *>();
308  }
309  }
311  {
312  m_use_towerinfo = true;
313  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN_SUB1");
315  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
316  if ((!towerinfos) || !geom)
317  {
318  return std::vector<Jet *>();
319  }
320  }
321  else if (m_input == Jet::HCALOUT_TOWER_SUB1)
322  {
323  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALOUT_SUB1");
324  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
325  if ((!towers) || !geom)
326  {
327  return std::vector<Jet *>();
328  }
329  }
331  {
332  m_use_towerinfo = true;
333  towerinfos = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALOUT_SUB1");
335  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
336  if ((!towerinfos) || !geom)
337  {
338  return std::vector<Jet *>();
339  }
340  }
341  else if (m_input == Jet::CEMC_TOWER_SUB1CS)
342  {
343  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER_SUB1CS");
344  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
345  if ((!towers) || !geom)
346  {
347  return std::vector<Jet *>();
348  }
349  }
350  else if (m_input == Jet::HCALIN_TOWER_SUB1CS)
351  {
352  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALIN_SUB1CS");
353  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
354  if ((!towers) || !geom)
355  {
356  return std::vector<Jet *>();
357  }
358  }
360  {
361  towers = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_HCALOUT_SUB1CS");
362  geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
363  if ((!towers) || !geom)
364  {
365  return std::vector<Jet *>();
366  }
367  }
368  else
369  {
370  return std::vector<Jet *>();
371  }
372 
373  // first grab the event vertex or bail
374  GlobalVertex *vtx = vertexmap->begin()->second;
375  float vtxz = NAN;
376  if (vtx)
377  {
378  vtxz = vtx->get_z();
379  }
380  else
381  {
382  return std::vector<Jet *>();
383  }
384 
385  if (std::isnan(vtxz))
386  {
387  static bool once = true;
388  if (once)
389  {
390  once = false;
391 
392  std::cout << "TowerJetInput::get_input - WARNING - vertex is NAN. Drop all tower inputs (further NAN-vertex warning will be suppressed)." << std::endl;
393  }
394 
395  return std::vector<Jet *>();
396  }
397 
398  std::vector<Jet *> pseudojets;
399  if (m_use_towerinfo)
400  {
401  if (!towerinfos)
402  {
403  return std::vector<Jet *>();
404  }
405 
406  unsigned int nchannels = towerinfos->size();
407  for (unsigned int channel = 0; channel < nchannels;channel++)
408  {
410  assert(tower);
411 
412  unsigned int calokey = towerinfos->encode_key(channel);
413  int ieta = towerinfos->getTowerEtaBin(calokey);
414  int iphi = towerinfos->getTowerPhiBin(calokey);
416  //skip masked towers
417  if (tower->get_time()==-10 || tower->get_time()==-11) continue;
418  RawTowerGeom *tower_geom = geom->get_tower_geometry(key);
419  assert(tower_geom);
420 
421  double r = tower_geom->get_center_radius();
422  double phi = atan2(tower_geom->get_center_y(), tower_geom->get_center_x());
423  double z0 = tower_geom->get_center_z();
424  double z = z0 - vtxz;
425  double eta = asinh(z / r); // eta after shift from vertex
426  double pt = tower->get_energy() / cosh(eta);
427  if (tower->get_energy() == NAN) {pt = 0/cosh(eta);}
428  double px = pt * cos(phi);
429  double py = pt * sin(phi);
430  double pz = pt * sinh(eta);
431 
432  Jet *jet = new Jetv2();
433  jet->set_px(px);
434  jet->set_py(py);
435  jet->set_pz(pz);
436  jet->set_e(tower->get_energy());
438  pseudojets.push_back(jet);
439  }
440  }
441  else
442  {
443  RawTowerContainer::ConstRange begin_end = towers->getTowers();
445  for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
446  {
447  RawTower *tower = rtiter->second;
448 
449  RawTowerGeom *tower_geom = geom->get_tower_geometry(tower->get_key());
450  assert(tower_geom);
451 
452  double r = tower_geom->get_center_radius();
453  double phi = atan2(tower_geom->get_center_y(), tower_geom->get_center_x());
454  double z0 = tower_geom->get_center_z();
455  double z = z0 - vtxz;
456  double eta = asinh(z / r); // eta after shift from vertex
457  double pt = tower->get_energy() / cosh(eta);
458  double px = pt * cos(phi);
459  double py = pt * sin(phi);
460  double pz = pt * sinh(eta);
461 
462  Jet *jet = new Jetv2();
463  jet->set_px(px);
464  jet->set_py(py);
465  jet->set_pz(pz);
466  jet->set_e(tower->get_energy());
467  jet->insert_comp(m_input, tower->get_id());
468  pseudojets.push_back(jet);
469  }
470  }
471  if (Verbosity() > 0) std::cout << "TowerJetInput::process_event -- exited" << std::endl;
472 
473  return pseudojets;
474 }