ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RetowerCEMC.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RetowerCEMC.cc
1 #include "RetowerCEMC.h"
2 
3 #include <calobase/RawTower.h>
4 #include <calobase/RawTowerContainer.h>
5 #include <calobase/RawTowerDefs.h>
6 #include <calobase/RawTowerGeom.h>
7 #include <calobase/RawTowerGeomContainer.h>
8 #include <calobase/RawTowerv1.h>
9 
11 #include <fun4all/SubsysReco.h>
12 
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/getClass.h>
19 #include <phool/phool.h>
20 
21 // standard includes
22 #include <iostream>
23 #include <map>
24 #include <utility>
25 #include <vector>
26 
27 RetowerCEMC::RetowerCEMC(const std::string &name)
28  : SubsysReco(name)
29  , _NETA(-1)
30  , _NPHI(-1)
31 {
32 }
33 
35 {
36  CreateNode(topNode);
37 
39 }
40 
42 {
43  if (Verbosity() > 0)
44  std::cout << "RetowerCEMC::process_event: entering" << std::endl;
45 
46  // pull out the tower containers and geometry objects at the start
47 
48  RawTowerContainer *towersEM3 = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC");
49 
50  RawTowerGeomContainer *geomEM = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
51  RawTowerGeomContainer *geomIH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
52 
53  if (Verbosity() > 0)
54  {
55  std::cout << "RetowerCEMC::process_event: " << towersEM3->size() << " TOWER_CALIB_CEMC towers" << std::endl;
56  }
57 
58  // setup grid
59 
60  if (_NETA < 0)
61  {
62  _NETA = geomIH->get_etabins();
63  _NPHI = geomIH->get_phibins();
64 
65  _EMCAL_RETOWER_E.resize(_NETA, std::vector<float>(_NPHI, 0));
66  }
67 
68  for (int eta = 0; eta < _NETA; eta++)
69  {
70  for (int phi = 0; phi < _NPHI; phi++)
71  {
72  _EMCAL_RETOWER_E[eta][phi] = 0;
73  }
74  }
75 
76  // partition existing CEMC energies among grid
77 
78  RawTowerContainer::ConstRange begin_end_EM = towersEM3->getTowers();
79  for (RawTowerContainer::ConstIterator rtiter = begin_end_EM.first; rtiter != begin_end_EM.second; ++rtiter)
80  {
81  RawTower *tower = rtiter->second;
82  RawTowerGeom *tower_geom = geomEM->get_tower_geometry(tower->get_key());
83 
84  int this_IHetabin = geomIH->get_etabin(tower_geom->get_eta());
85  int this_IHphibin = geomIH->get_phibin(tower_geom->get_phi());
86  float this_E = tower->get_energy();
87 
88  _EMCAL_RETOWER_E[this_IHetabin][this_IHphibin] += this_E;
89  }
90 
91  RawTowerContainer *emcal_retower = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER");
92 
93  if (Verbosity() > 0) std::cout << "RetowerCEMC::process_event: filling TOWER_CALIB_CEMC_RETOWER node, with initial size = " << emcal_retower->size() << std::endl;
94 
95  // create new towers
96  for (int eta = 0; eta < _NETA; eta++)
97  {
98  for (int phi = 0; phi < _NPHI; phi++)
99  {
100  RawTower *new_tower = new RawTowerv1();
101 
102  new_tower->set_energy(_EMCAL_RETOWER_E[eta][phi]);
103  emcal_retower->AddTower(eta, phi, new_tower);
104  }
105  }
106 
107  if (Verbosity() > 0) std::cout << "RetowerCEMC::process_event: finished filling TOWER_CALIB_CEMC_RETOWER node, with final size = " << emcal_retower->size() << std::endl;
108 
109  if (Verbosity() > 0) std::cout << "RetowerCEMC::process_event: exiting" << std::endl;
110 
112 }
113 
115 {
116  PHNodeIterator iter(topNode);
117 
118  // Looking for the DST node
119  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
120  if (!dstNode)
121  {
122  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
124  }
125 
126  // store the new EMCal towers
127  PHCompositeNode *emcalNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "CEMC"));
128  if (!emcalNode)
129  {
130  std::cout << PHWHERE << "EMCal Node note found, doing nothing." << std::endl;
131  }
132 
133  RawTowerContainer *test_emcal_retower = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER");
134  if (!test_emcal_retower)
135  {
136  if (Verbosity() > 0) std::cout << "RetowerCEMC::CreateNode : creating TOWER_CALIB_CEMC_RETOWER node " << std::endl;
137 
139  PHIODataNode<PHObject> *emcalTowerNode = new PHIODataNode<PHObject>(emcal_retower, "TOWER_CALIB_CEMC_RETOWER", "PHObject");
140  emcalNode->addNode(emcalTowerNode);
141  }
142  else
143  {
144  std::cout << "RetowerCEMC::CreateNode : TOWER_CALIB_CEMC_RETOWER already exists! " << std::endl;
145  }
146 
148 }