Analysis Software
Documentation for sPHENIX simulation 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 
10 #include <calobase/TowerInfo.h>
11 #include <calobase/TowerInfoContainer.h>
12 
14 #include <fun4all/SubsysReco.h>
15 
16 #include <phool/PHCompositeNode.h>
17 #include <phool/PHIODataNode.h>
18 #include <phool/PHNode.h>
19 #include <phool/PHNodeIterator.h>
20 #include <phool/PHObject.h>
21 #include <phool/getClass.h>
22 #include <phool/phool.h>
23 
24 // standard includes
25 #include <iostream>
26 #include <map>
27 #include <utility>
28 #include <vector>
29 
31  : SubsysReco(name)
32  , _WEIGHTED_ENERGY_DISTRIBUTION(1)
33  , _NETA(-1)
34  , _NPHI(-1)
35 {
36 }
37 
39 {
40  CreateNode(topNode);
41 
43 }
44 
46 {
47  if (Verbosity() > 0)
48  std::cout << "RetowerCEMC::process_event: entering" << std::endl;
49 
50  // pull out the tower containers and geometry objects at the start
51  RawTowerContainer *towersEM3 = nullptr;
52  TowerInfoContainer *towerinfosEM3 = nullptr;
53  if (m_use_towerinfo)
54  {
55  towerinfosEM3= findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC");
56 
57  }
58  else
59  {
60  towersEM3= findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC");
61  if (Verbosity() > 0)
62  {
63  std::cout << "RetowerCEMC::process_event: " << towersEM3->size() << " TOWER_CALIB_CEMC towers" << std::endl;
64  }
65  }
66 
67 
68  RawTowerGeomContainer *geomEM = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
69  RawTowerGeomContainer *geomIH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
70 
71 
72 
73  // setup grid
74 
75  if (_NETA < 0)
76  {
77  _NETA = geomIH->get_etabins();
78  _NPHI = geomIH->get_phibins();
79 
80  _EMCAL_RETOWER_E.resize(_NETA, std::vector<float>(_NPHI, 0));
81  _EMCAL_RETOWER_T.resize(_NETA, std::vector<int>(_NPHI, 0));
82  }
83 
84  for (int eta = 0; eta < _NETA; eta++)
85  {
86  for (int phi = 0; phi < _NPHI; phi++)
87  {
88  _EMCAL_RETOWER_E[eta][phi] = 0;
89  _EMCAL_RETOWER_T[eta][phi] = 0;
90  }
91  }
92 
93  // partition existing CEMC energies among grid
94  if (m_use_towerinfo)
95  {
96  if (!towerinfosEM3)
97  {
98  std::cout << PHWHERE << "no emcal tower info object, doing nothing" << std::endl;
100  }
101  unsigned int nchannels = towerinfosEM3->size();
102  for (unsigned int channel = 0; channel < nchannels;channel++)
103  {
104  TowerInfo *tower = towerinfosEM3->get_tower_at_channel(channel);
105  unsigned int channelkey = towerinfosEM3->encode_key(channel);
106  int ieta = towerinfosEM3->getTowerEtaBin(channelkey);
107  int iphi = towerinfosEM3->getTowerPhiBin(channelkey);
109  RawTowerGeom *tower_geom = geomEM->get_tower_geometry(key);
110  int this_IHetabin = geomIH->get_etabin(tower_geom->get_eta());
111  double fractionalcontribution[3] = {0};
112 
114  {
115  std::pair<double, double> range_embin= geomEM->get_etabounds(tower_geom->get_bineta());
116  for (int etabin_iter = -1;etabin_iter <= 1;etabin_iter++)
117  {
118  if (this_IHetabin+etabin_iter < 0 || this_IHetabin+etabin_iter >= _NETA){continue;}
119  std::pair<double, double> range_ihbin= geomIH->get_etabounds(this_IHetabin + etabin_iter);
120  if (range_ihbin.first <= range_embin.first && range_ihbin.second >= range_embin.second)
121  {
122  fractionalcontribution[etabin_iter+1] = 1;
123  }
124  else if ( range_ihbin.first <= range_embin.first && range_ihbin.second < range_embin.second && range_embin.first < range_ihbin.second)
125  {
126  fractionalcontribution[etabin_iter+1] = (range_ihbin.second - range_embin.first) / (range_embin.second- range_embin.first);
127  }
128  else if (range_ihbin.first > range_embin.first && range_ihbin.second >= range_embin.second && range_embin.second > range_ihbin.first)
129  {
130  fractionalcontribution[etabin_iter+1] = (range_embin.second - range_ihbin.first) / (range_embin.second- range_embin.first);
131  }
132  else
133  {
134  fractionalcontribution[etabin_iter+1] = 0;
135  }
136  }
137  }
138  else
139  {
140  fractionalcontribution[0] = 0;
141  fractionalcontribution[1] = 1;
142  fractionalcontribution[2] = 0;
143  }
144 
145  int this_IHphibin = geomIH->get_phibin(tower_geom->get_phi());
146  float this_E = tower->get_energy();
147  int this_T = tower->get_time();
148  for (int etabin_iter = -1 ; etabin_iter <= 1;etabin_iter++)
149  {
150  if (this_IHetabin+etabin_iter < 0 || this_IHetabin+etabin_iter >= _NETA){continue;}
151  _EMCAL_RETOWER_E[this_IHetabin+etabin_iter][this_IHphibin] += this_E * fractionalcontribution[etabin_iter+1];
152  if(this_T == -10 || this_T == -11) //if a tower in this retower is masked, mask the retower as well. Masking is noted by time = -10 or -11
153  {
154  //currently just set the retowered tower to -10 even if the original tower was -11
155  _EMCAL_RETOWER_T[this_IHetabin+etabin_iter][this_IHphibin] = -10;
156  }
157  }
158  }
159 
160  }
161 
162  else
163  {
164  RawTowerContainer::ConstRange begin_end_EM = towersEM3->getTowers();
165  for (RawTowerContainer::ConstIterator rtiter = begin_end_EM.first; rtiter != begin_end_EM.second; ++rtiter)
166  {
167  RawTower *tower = rtiter->second;
168  RawTowerGeom *tower_geom = geomEM->get_tower_geometry(tower->get_key());
169 
170  int this_IHetabin = geomIH->get_etabin(tower_geom->get_eta());
171  double fractionalcontribution[3] = {0};
172 
173  // distribute energy based on shadowing of the inner hcal geometry
175  {
176  std::pair<double, double> range_embin= geomEM->get_etabounds(tower_geom->get_bineta());
177  for (int etabin_iter = -1;etabin_iter <= 1;etabin_iter++)
178  {
179  if (this_IHetabin+etabin_iter < 0 || this_IHetabin+etabin_iter >= _NETA){continue;}
180  std::pair<double, double> range_ihbin= geomIH->get_etabounds(this_IHetabin + etabin_iter);
181  if (range_ihbin.first <= range_embin.first && range_ihbin.second >= range_embin.second)
182  {
183  fractionalcontribution[etabin_iter+1] = 1;
184  }
185  else if ( range_ihbin.first <= range_embin.first && range_ihbin.second < range_embin.second && range_embin.first < range_ihbin.second)
186  {
187  fractionalcontribution[etabin_iter+1] = (range_ihbin.second - range_embin.first) / (range_embin.second- range_embin.first);
188  }
189  else if (range_ihbin.first > range_embin.first && range_ihbin.second >= range_embin.second && range_embin.second > range_ihbin.first)
190  {
191  fractionalcontribution[etabin_iter+1] = (range_embin.second - range_ihbin.first) / (range_embin.second- range_embin.first);
192  }
193  else
194  {
195  fractionalcontribution[etabin_iter+1] = 0;
196  }
197  }
198  }
199  else
200  {
201  fractionalcontribution[0] = 0;
202  fractionalcontribution[1] = 1;
203  fractionalcontribution[2] = 0;
204  }
205 
206  int this_IHphibin = geomIH->get_phibin(tower_geom->get_phi());
207  float this_E = tower->get_energy();
208 
209  for (int etabin_iter = -1 ; etabin_iter <= 1;etabin_iter++)
210  {
211  if (this_IHetabin+etabin_iter < 0 || this_IHetabin+etabin_iter >= _NETA){continue;}
212  _EMCAL_RETOWER_E[this_IHetabin+etabin_iter][this_IHphibin] += this_E * fractionalcontribution[etabin_iter+1];
213  }
214  }
215 
216  }
217 
218 
219 
220  if (m_use_towerinfo)
221  {
222  TowerInfoContainer *emcal_retower = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC_RETOWER");
223  if (Verbosity() > 0) std::cout << "RetowerCEMC::process_event: filling TOWERINFO_CALIB_CEMC_RETOWER node" << std::endl;
224  // create new towers
225  for (int eta = 0; eta < _NETA; eta++)
226  {
227  for (int phi = 0; phi < _NPHI; phi++)
228  {
229  unsigned int towerkey = (eta << 16U) + phi;
230  unsigned int towerindex = emcal_retower->decode_key(towerkey);
231  TowerInfo *towerinfo = emcal_retower->get_tower_at_channel(towerindex);
232  towerinfo->set_energy(_EMCAL_RETOWER_E[eta][phi]);
233  if(_EMCAL_RETOWER_T[eta][phi] == -10) towerinfo->set_energy(0);
234  towerinfo->set_time(_EMCAL_RETOWER_T[eta][phi]);
235  }
236  }
237  }
238  else
239  {
240  RawTowerContainer *emcal_retower = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER");
241  if (Verbosity() > 0) std::cout << "RetowerCEMC::process_event: filling TOWER_CALIB_CEMC_RETOWER node, with initial size = " << emcal_retower->size() << std::endl;
242  // create new towers
243  for (int eta = 0; eta < _NETA; eta++)
244  {
245  for (int phi = 0; phi < _NPHI; phi++)
246  {
247  RawTower *new_tower = new RawTowerv1();
248 
249  new_tower->set_energy(_EMCAL_RETOWER_E[eta][phi]);
250  emcal_retower->AddTower(eta, phi, new_tower);
251  }
252  }
253 
254  if (Verbosity() > 0) std::cout << "RetowerCEMC::process_event: finished filling TOWER_CALIB_CEMC_RETOWER node, with final size = " << emcal_retower->size() << std::endl;
255  }
256  if (Verbosity() > 0) std::cout << "RetowerCEMC::process_event: exiting" << std::endl;
258 }
259 
261 {
262  PHNodeIterator iter(topNode);
263 
264  // Looking for the DST node
265  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
266  if (!dstNode)
267  {
268  std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
270  }
271 
272  // store the new EMCal towers
273  PHCompositeNode *emcalNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "CEMC"));
274  if (!emcalNode)
275  {
276  std::cout << PHWHERE << "EMCal Node note found, doing nothing." << std::endl;
277  }
278 
279 
280 
281  if (m_use_towerinfo)
282  {
283  TowerInfoContainer *test_emcal_retower = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_CEMC_RETOWER");
284  TowerInfoContainer *hcal_towers = findNode::getClass<TowerInfoContainer>(topNode, "TOWERINFO_CALIB_HCALIN");
285  if (!test_emcal_retower)
286  {
287  if (Verbosity() > 0) std::cout << "RetowerCEMC::CreateNode : creating TOWERINFO_CALIB_CEMC_RETOWER node " << std::endl;
288 
289  TowerInfoContainer *emcal_retower = dynamic_cast<TowerInfoContainer *> (hcal_towers->CloneMe());
290  PHIODataNode<PHObject> *emcalTowerNode = new PHIODataNode<PHObject>(emcal_retower, "TOWERINFO_CALIB_CEMC_RETOWER", "PHObject");
291  emcalNode->addNode(emcalTowerNode);
292  }
293  else
294  {
295  std::cout << "RetowerCEMC::CreateNode : TOWERINFO_CALIB_CEMC_RETOWER already exists! " << std::endl;
296  }
297  }
298  else
299  {
300  RawTowerContainer *test_emcal_retower = findNode::getClass<RawTowerContainer>(topNode, "TOWER_CALIB_CEMC_RETOWER");
301  if (!test_emcal_retower)
302  {
303  if (Verbosity() > 0) std::cout << "RetowerCEMC::CreateNode : creating TOWER_CALIB_CEMC_RETOWER node " << std::endl;
304 
306  PHIODataNode<PHObject> *emcalTowerNode = new PHIODataNode<PHObject>(emcal_retower, "TOWER_CALIB_CEMC_RETOWER", "PHObject");
307  emcalNode->addNode(emcalTowerNode);
308  }
309  else
310  {
311  std::cout << "RetowerCEMC::CreateNode : TOWER_CALIB_CEMC_RETOWER already exists! " << std::endl;
312  }
313  }
314 
315 
316 
317 
318 
320 }