Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Prototype2RawTowerBuilder.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Prototype2RawTowerBuilder.cc
3 
4 #include <calobase/RawTowerContainer.h>
5 #include <calobase/RawTowerDefs.h> // for convert_name_...
6 #include <calobase/RawTowerGeomContainer.h> // for RawTowerGeomC...
7 #include <calobase/RawTowerGeomContainer_Cylinderv1.h>
8 #include <calobase/RawTowerGeomv1.h>
9 #include <calobase/RawTower.h> // for RawTower
10 #include <calobase/RawTowerv1.h>
11 
14 
15 #include <phparameter/PHParameters.h>
16 #include <phparameter/PHParameterInterface.h> // for PHParameterIn...
17 
19 #include <fun4all/Fun4AllServer.h>
20 #include <fun4all/SubsysReco.h> // for SubsysReco
21 
22 #include <pdbcalbase/PdbParameterMapContainer.h>
23 
24 #include <phool/PHCompositeNode.h>
25 #include <phool/PHIODataNode.h>
26 #include <phool/PHNode.h> // for PHNode
27 #include <phool/PHNodeIterator.h>
28 #include <phool/PHObject.h> // for PHObject
29 #include <phool/getClass.h>
30 #include <phool/phool.h> // for PHWHERE
31 
32 #include <TSystem.h>
33 
34 #include <cmath> // for fabs, NAN
35 #include <iostream>
36 #include <map>
37 #include <utility> // for pair
38 
39 using namespace std;
40 
42  : SubsysReco(name)
43  , PHParameterInterface(name)
44  , m_Detector("NONE")
45  , m_Emin(NAN)
46  , m_CheckEnergyConservationFlag(0)
47  , m_TowerEnergySrc(kLightYield)
48  , m_NumCellToTower(5)
49 
50 {
52 }
53 
55 {
56  PHNodeIterator iter(topNode);
57  PHCompositeNode *parNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "PAR"));
58  PHCompositeNode *runNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "RUN"));
59  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
60  if (!runNode || !dstNode || !parNode)
61  {
62  cout << PHWHERE << "Top Nodes missing, quitting after printing node tree" << endl;
64  se->Print("NODETREE");
65  gSystem->Exit(1);
66  }
67  string paramnodename = "G4TOWERPARAM_" + m_Detector;
68  string geonodename = "G4TOWERGEO_" + m_Detector;
69 
70  if (m_SimTowerNodePrefix.empty())
71  {
72  // no prefix, consistent with older convension
73  m_TowerNodeName = "TOWER_" + m_Detector;
74  }
75  else
76  {
77  m_TowerNodeName = "TOWER_" + m_SimTowerNodePrefix + "_" + m_Detector;
78  }
79  RawTowerContainer *towers = findNode::getClass<RawTowerContainer>(topNode, m_TowerNodeName);
80  if (!towers)
81  {
82  PHNodeIterator dstiter(dstNode);
83  PHCompositeNode *DetNode = dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode", m_Detector));
84  if (!DetNode)
85  {
86  DetNode = new PHCompositeNode(m_Detector);
87  dstNode->addNode(DetNode);
88  }
90  PHIODataNode<PHObject> *towerNode = new PHIODataNode<PHObject>(towers, m_TowerNodeName, "PHObject");
91  DetNode->addNode(towerNode);
92  }
93  // order first default,
94  // then parameter from g4detector on node tree
95  ReadParamsFromNodeTree(topNode);
96  // then macro setting
98  PHNodeIterator runIter(runNode);
99  PHCompositeNode *RunDetNode = dynamic_cast<PHCompositeNode *>(runIter.findFirst("PHCompositeNode", m_Detector));
100  if (!RunDetNode)
101  {
102  RunDetNode = new PHCompositeNode(m_Detector);
103  runNode->addNode(RunDetNode);
104  }
105  SaveToNodeTree(RunDetNode, paramnodename);
106  // save this to the parNode for use
107  PHNodeIterator parIter(parNode);
108  PHCompositeNode *ParDetNode = dynamic_cast<PHCompositeNode *>(parIter.findFirst("PHCompositeNode", m_Detector));
109  if (!ParDetNode)
110  {
111  ParDetNode = new PHCompositeNode(m_Detector);
112  parNode->addNode(ParDetNode);
113  }
114  PutOnParNode(ParDetNode, geonodename);
115 
116  m_TowerGeomNodeName = "TOWERGEOM_" + m_Detector;
117  RawTowerGeomContainer *rawtowergeom = findNode::getClass<RawTowerGeomContainer>(topNode, m_TowerGeomNodeName);
118  if (!rawtowergeom)
119  {
121  PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(rawtowergeom, m_TowerGeomNodeName, "PHObject");
122  runNode->addNode(newNode);
123  }
124  rawtowergeom->set_phibins(4);
125  rawtowergeom->set_etabins(4);
126  for (int irow = 0; irow < rawtowergeom->get_phibins(); irow++)
127  {
128  for (int icolumn = 0; icolumn < rawtowergeom->get_etabins(); icolumn++)
129  {
131  tg->set_center_x(irow * 10 + icolumn);
132  tg->set_center_y(irow * 10 + icolumn);
133  tg->set_center_z(irow * 10 + icolumn);
134 
135  rawtowergeom->add_tower_geometry(tg);
136  }
137  }
138 
139  if (Verbosity() >= 1)
140  {
141  cout << "Prototype2RawTowerBuilder::InitRun :";
143  {
144  cout << "save Geant4 energy deposition as the weight of the cells"
145  << endl;
146  }
147  else if (m_TowerEnergySrc == kLightYield)
148  {
149  cout << "save light yield as the weight of the cells" << endl;
150  }
151  }
153  m_Emin = get_double_param("emin");
155 }
156 
158 {
159  if (Verbosity() > 3)
160  {
161  std::cout << PHWHERE << "Process event entered" << std::endl;
162  }
163 
164  // get cells
165  string cellnodename = "G4CELL_" + m_Detector;
166  PHG4ScintillatorSlatContainer *slats = findNode::getClass<PHG4ScintillatorSlatContainer>(topNode, cellnodename);
167  if (!slats)
168  {
169  cout << PHWHERE << " " << cellnodename << " Node missing, doing nothing." << endl;
171  }
172  RawTowerContainer *towers = findNode::getClass<RawTowerContainer>(topNode, m_TowerNodeName);
173  if (!towers)
174  {
175  cout << PHWHERE << " " << m_TowerNodeName << " Node missing, doing nothing." << endl;
177  }
178 
179  // loop over all slats in an event
182  for (cell_iter = cell_range.first; cell_iter != cell_range.second;
183  ++cell_iter)
184  {
185  PHG4ScintillatorSlat *cell = cell_iter->second;
186 
187  if (Verbosity() > 2)
188  {
189  std::cout << PHWHERE << " print out the cell:" << std::endl;
190  cell->identify();
191  }
192  short twrrow = get_tower_row(cell->get_row());
193  // add the energy to the corresponding tower
194  // towers are addressed column/row to make the mapping more intuitive
195  RawTower *tower = towers->getTower(cell->get_column(), twrrow);
196  if (!tower)
197  {
198  tower = new RawTowerv1();
199  tower->set_energy(0);
200  towers->AddTower(cell->get_column(), twrrow, tower);
201  }
202  double cell_weight = 0;
204  {
205  cell_weight = cell->get_edep();
206  }
207  else if (m_TowerEnergySrc == kLightYield)
208  {
209  cell_weight = cell->get_light_yield();
210  }
212  {
213  cell_weight = cell->get_eion();
214  }
215 
216  tower->add_ecell(cell->get_key(), cell_weight);
217 
218  tower->set_energy(tower->get_energy() + cell_weight);
219  }
220  double towerE = 0;
222  {
223  double cellE = slats->getTotalEdep();
224  towerE = towers->getTotalEdep();
225  if (fabs(cellE - towerE) / cellE > 1e-5)
226  {
227  cout << "towerE: " << towerE << ", cellE: " << cellE << ", delta: "
228  << cellE - towerE << endl;
229  }
230  }
231  if (Verbosity())
232  {
233  towerE = towers->getTotalEdep();
234  }
235 
236  towers->compress(m_Emin);
237  if (Verbosity())
238  {
239  cout << "Energy lost by dropping towers with less than " << m_Emin
240  << " energy, lost energy: " << towerE - towers->getTotalEdep()
241  << endl;
242  towers->identify();
243  RawTowerContainer::ConstRange begin_end = towers->getTowers();
245  for (iter = begin_end.first; iter != begin_end.second; ++iter)
246  {
247  iter->second->identify();
248  }
249  }
250 
252 }
253 
254 short Prototype2RawTowerBuilder::get_tower_row(const short cellrow) const
255 {
256  short twrrow = cellrow / m_NumCellToTower;
257  return twrrow;
258 }
259 
261 {
263  set_default_double_param("emin", 1.e-6);
264  return;
265 }
266 
268 {
269  PHParameters *pars = new PHParameters("temp");
270  // we need the number of scintillator plates per tower
271  string geonodename = "G4GEOPARAM_" + m_Detector;
272  PdbParameterMapContainer *saveparams = findNode::getClass<PdbParameterMapContainer>(topNode, geonodename);
273  if (!saveparams)
274  {
275  cout << "could not find " << geonodename << endl;
277  se->Print("NODETREE");
278  return;
279  }
280  pars->FillFrom(saveparams, 0);
282  delete pars;
283  return;
284 }
285 
287 {
288  cout << "m_NumCellToTower: " << m_NumCellToTower << endl;
289  return;
290 }