Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
caloTowerEmbed.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file caloTowerEmbed.cc
1 #include "caloTowerEmbed.h"
2 
3 #include <calobase/TowerInfo.h> // for TowerInfo
4 #include <calobase/TowerInfoContainer.h>
5 #include <calobase/TowerInfoContainerv1.h>
6 #include <calobase/TowerInfoContainerv2.h>
7 #include <calobase/TowerInfov1.h>
8 #include <calobase/TowerInfoDefs.h>
9 #include <calobase/RawTowerGeom.h>
10 #include <calobase/RawTowerGeomContainer.h>
11 
12 #include <cdbobjects/CDBTTree.h> // for CDBTTree
13 
15 
16 #include <ffaobjects/EventHeader.h>
17 
18 #include <fun4all/Fun4AllServer.h>
20 #include <fun4all/SubsysReco.h> // for SubsysReco
21 
22 #include <phool/PHCompositeNode.h>
23 #include <phool/PHIODataNode.h> // for PHIODataNode
24 #include <phool/PHNode.h> // for PHNode
25 #include <phool/PHNodeIterator.h> // for PHNodeIterator
26 #include <phool/PHObject.h> // for PHObject
27 #include <phool/getClass.h>
28 #include <phool/phool.h>
29 #include <phool/recoConsts.h>
30 
31 #include <cstdlib> // for exit
32 #include <exception> // for exception
33 #include <iostream> // for operator<<, basic_ostream
34 #include <stdexcept> // for runtime_error
35 
36 
37 //____________________________________________________________________________..
39  : SubsysReco(name)
40  , m_runNumber(-1)
41  , m_eventNumber(-1)
42 {
43  std::cout << "caloTowerEmbed::caloTowerEmbed(const std::string &name) Calling ctor" << std::endl;
44 }
45 
46 //____________________________________________________________________________..
48 {
49  std::cout << "caloTowerEmbed::~caloTowerEmbed() Calling dtor" << std::endl;
50 }
51 
52 //____________________________________________________________________________..
54 {
55 
57 
58  PHCompositeNode *simTopNode = se->topNode("TOPSim");
59 
60  EventHeader *evtHeader = findNode::getClass<EventHeader>(topNode, "EventHeader");
61 
62  if (evtHeader)
63  {
64  m_runNumber = evtHeader->get_RunNumber();
65  }
66  else
67  {
68  m_runNumber = -1;
69  }
70  if(Verbosity()) std::cout << "at run" << m_runNumber << std::endl;
71 
72  try
73  {
74  CreateNodeTree(topNode);
75  }
76  catch (std::exception &e)
77  {
78  std::cout << e.what() << std::endl;
80  }
81  topNode->print();
82  simTopNode->print();
83 
85 }
86 
87 //____________________________________________________________________________..
89 {
90  ++m_eventNumber;
91 
92  for(int caloIndex=0; caloIndex<3; caloIndex++){
93 
94  if(Verbosity()) std::cout << "event " << m_eventNumber << " working on caloIndex " << caloIndex;
95  if(caloIndex == 0) std::cout << " CEMC" << std::endl;
96  else if(caloIndex == 1) std::cout << " HCALIN" << std::endl;
97  else if(caloIndex == 2) std::cout << " HCALOUT" << std::endl;
98  RawTowerDefs::keytype keyData = 0;
99  RawTowerDefs::keytype keySim = 0;
100 
101  unsigned int ntowers = _data_towers[caloIndex]->size();
102  for (unsigned int channel = 0; channel < ntowers; channel++)
103  {
104  unsigned int data_key = _data_towers[caloIndex]->encode_key(channel);
105  unsigned int sim_key = _sim_towers[caloIndex]->encode_key(channel);
106 
107  int ieta_data = _data_towers[caloIndex]->getTowerEtaBin(data_key);
108  int iphi_data = _data_towers[caloIndex]->getTowerPhiBin(data_key);
109  int ieta_sim = _sim_towers[caloIndex]->getTowerEtaBin(sim_key);
110  int iphi_sim = _sim_towers[caloIndex]->getTowerPhiBin(sim_key);
111 
112  if(caloIndex == 0){
113  if(!m_useRetower){
114  keyData = RawTowerDefs::encode_towerid(RawTowerDefs::CalorimeterId::CEMC, ieta_data, iphi_data);
116  }
117  else{
118  keyData = RawTowerDefs::encode_towerid(RawTowerDefs::CalorimeterId::HCALIN, ieta_data, iphi_data);
120  }
121  }else if(caloIndex == 1){
122  keyData = RawTowerDefs::encode_towerid(RawTowerDefs::CalorimeterId::HCALIN, ieta_data, iphi_data);
124  }else if(caloIndex == 2){
127  }
128 
129  TowerInfo *caloinfo_data = _data_towers[caloIndex]->get_tower_at_channel(channel);
130  TowerInfo *caloinfo_sim = _sim_towers[caloIndex]->get_tower_at_channel(channel);
131 
132  float data_E = caloinfo_data->get_energy();
133  float sim_E = caloinfo_sim->get_energy();
134  float embed_E = data_E + sim_E;
135 
136  float data_phi = 0.0;
137  float sim_phi = 0.0;
138 
139  float data_eta = 0.0;
140  float sim_eta = 0.0;
141 
142  if(caloIndex == 0){
143  if(!m_useRetower){
144  data_phi = tower_geom->get_tower_geometry(keyData)->get_phi();
145  data_eta = tower_geom->get_tower_geometry(keyData)->get_eta();
146 
147  sim_phi = tower_geom->get_tower_geometry(keySim)->get_phi();
148  sim_eta = tower_geom->get_tower_geometry(keySim)->get_eta();
149  }else{
150  data_phi = tower_geomIH->get_tower_geometry(keyData)->get_phi();
151  data_eta = tower_geomIH->get_tower_geometry(keyData)->get_eta();
152 
153  sim_phi = tower_geomIH->get_tower_geometry(keySim)->get_phi();
154  sim_eta = tower_geomIH->get_tower_geometry(keySim)->get_eta();
155  }
156 
157  if(data_phi == sim_phi && data_eta == sim_eta){
158  _data_towers[caloIndex]->get_tower_at_channel(channel)->set_energy(embed_E);
159  }else{
160  if(Verbosity()) std::cout << "eta and phi values in CEMC do not match between data and simulation, removing this event" << std::endl;
162  }
163 
164  }else if(caloIndex == 1){
165  data_phi = tower_geomIH->get_tower_geometry(keyData)->get_phi();
166  data_eta = tower_geomIH->get_tower_geometry(keyData)->get_eta();
167 
168  sim_phi = tower_geomIH->get_tower_geometry(keySim)->get_phi();
169  sim_eta = tower_geomIH->get_tower_geometry(keySim)->get_eta();
170 
171  if(data_phi == sim_phi && data_eta == sim_eta){
172  _data_towers[caloIndex]->get_tower_at_channel(channel)->set_energy(embed_E);
173  }else{
174  if(Verbosity()) std::cout << "eta and phi values in HCALIN do not match between data and simulation, removing this event" << std::endl;
176  }
177 
178  }else if(caloIndex == 2){
179  data_phi = tower_geomOH->get_tower_geometry(keyData)->get_phi();
180  data_eta = tower_geomOH->get_tower_geometry(keyData)->get_eta();
181 
182  sim_phi = tower_geomOH->get_tower_geometry(keySim)->get_phi();
183  sim_eta = tower_geomOH->get_tower_geometry(keySim)->get_eta();
184 
185  if(data_phi == sim_phi && data_eta == sim_eta){
186  _data_towers[caloIndex]->get_tower_at_channel(channel)->set_energy(embed_E);
187  }else{
188  if(Verbosity()) std::cout << "eta and phi values in HCALOUT do not match between data and simulation, removing this event" << std::endl;
190  }
191 
192  }
193  }//end loop over channels
194  }//end loop over calorimeters
195 
197 }
198 
200 {
201 
203 
204 }
205 
207 {
208  std::cout << "creating node" << std::endl;
209 
211  PHCompositeNode *simTopNode = se->topNode("TOPSim");
212 
213  tower_geom = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_CEMC");
214  if(!tower_geom){
215  std::cerr << Name() << "::" << __PRETTY_FUNCTION__
216  << "tower geom CEMC missing, doing nothing." << std::endl;
217  throw std::runtime_error(
218  "Failed to find TOWERGEOM_CEMC node");
219  }
220 
221  tower_geomIH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALIN");
222  if(!tower_geomIH){
223  std::cerr << Name() << "::" << __PRETTY_FUNCTION__
224  << "tower geom HCALIN missing, doing nothing." << std::endl;
225  throw std::runtime_error(
226  "Failed to find TOWERGEOM_HCALIN node");
227  }
228 
229 
230  tower_geomOH = findNode::getClass<RawTowerGeomContainer>(topNode, "TOWERGEOM_HCALOUT");
231  if(!tower_geomOH){
232  std::cerr << Name() << "::" << __PRETTY_FUNCTION__
233  << "tower geom HCALOUT missing, doing nothing." << std::endl;
234  throw std::runtime_error(
235  "Failed to find TOWERGEOM_HCALOUT node");
236  }
237 
238  PHNodeIterator dataIter(topNode);
239  PHNodeIterator simIter(simTopNode);
240 
241  //data top node first
242 
243  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(dataIter.findFirst(
244  "PHCompositeNode", "DST"));
245  if (!dstNode)
246  {
247  std::cerr << Name() << "::" << __PRETTY_FUNCTION__
248  << "DST Node missing, doing nothing." << std::endl;
249  throw std::runtime_error(
250  "Failed to find DST node in RawTowerCalibration::CreateNodes");
251  }
252 
253 
254  PHCompositeNode *dstNodeSim = dynamic_cast<PHCompositeNode *>(simIter.findFirst(
255  "PHCompositeNode", "DST"));
256  if (!dstNodeSim)
257  {
258  std::cerr << Name() << "::" << __PRETTY_FUNCTION__
259  << "DSTsim Node missing, doing nothing." << std::endl;
260  throw std::runtime_error(
261  "Failed to find DSTsim node in RawTowerCalibration::CreateNodes");
262  }
263 
264  for(int i=0; i<3; i++){
265 
266  std::string detector = "CEMC";
267  if(i==0 && m_useRetower) detector = "CEMC_RETOWER";
268  if(i==1) detector = "HCALIN";
269  else if(i==2) detector = "HCALOUT";
270 
271 
272  //data
273  std::string DataTowerNodeName = "TOWERINFO_CALIB_" + detector;
274  _data_towers[i] = findNode::getClass<TowerInfoContainer>(dstNode,
275  DataTowerNodeName);
276  if (!_data_towers[i])
277  {
278  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
279  << "Tower Calib Node missing, doing nothing." << std::endl;
280  throw std::runtime_error(
281  "Failed to find Calib Tower node in caloTowerEmbed::CreateNodes");
282  }
283 
284 
285  //sim
286  std::string SimTowerNodeName = "TOWERINFO_CALIB_" + detector;
287  _sim_towers[i] = findNode::getClass<TowerInfoContainer>(dstNodeSim,
288  SimTowerNodeName);
289  if (!_sim_towers[i])
290  {
291  std::cerr << Name() << "::" << detector << "::" << __PRETTY_FUNCTION__
292  << "Tower Calib Sim Node missing, doing nothing." << std::endl;
293  throw std::runtime_error(
294  "Failed to find Calib Tower Sim node in caloTowerEmbed::CreateNodes");
295  }
296 
297  }//end loop over calorimeter types
298 
299  return;
300 }