Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CaloAna.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CaloAna.cc
1 #include "CaloAna.h"
2 
3 // G4Hits includes
4 #include <g4main/PHG4Hit.h>
6 
7 // G4Cells includes
8 #include <g4detectors/PHG4Cell.h>
10 
11 // Tower includes
12 #include <calobase/RawTower.h>
13 #include <calobase/RawTowerContainer.h>
14 #include <calobase/RawTowerGeom.h>
15 #include <calobase/RawTowerGeomContainer.h>
16 
17 // Cluster includes
18 #include <calobase/RawCluster.h>
19 #include <calobase/RawClusterContainer.h>
20 
23 
24 #include <phool/getClass.h>
25 
26 #include <TFile.h>
27 #include <TNtuple.h>
28 
29 #include <cassert>
30 #include <sstream>
31 #include <string>
32 
33 using namespace std;
34 
36  : SubsysReco(name)
37  , detector("HCALIN")
38  , outfilename(filename)
39 {
40 }
41 
43 {
44  delete hm;
45  delete g4hitntuple;
46  delete g4cellntuple;
47  delete towerntuple;
48  delete clusterntuple;
49 }
50 
52 {
53  hm = new Fun4AllHistoManager(Name());
54  // create and register your histos (all types) here
55  // TH1 *h1 = new TH1F("h1",....)
56  // hm->registerHisto(h1);
57  outfile = new TFile(outfilename.c_str(), "RECREATE");
58  g4hitntuple = new TNtuple("hitntup", "G4Hits", "x0:y0:z0:x1:y1:z1:edep");
59  g4cellntuple = new TNtuple("cellntup", "G4Cells", "phi:eta:edep");
60  towerntuple = new TNtuple("towerntup", "Towers", "phi:eta:energy");
61  clusterntuple = new TNtuple("clusterntup", "Clusters", "phi:z:energy:towers");
62  return 0;
63 }
64 
66 {
67  // For the calorimeters we have the following node name convention
68  // where detector is the calorimeter name (CEMC, HCALIN, HCALOUT)
69  // this is the order in which they are reconstructed
70  // G4HIT_<detector>: G4 Hits
71  // G4CELL_<detector>: Cells (combined hits inside a cell - scintillator, eta/phi bin)
72  // TOWER_SIM_<detector>: simulated tower (before pedestal and noise)
73  // TOWER_RAW_<detector>: Raw Tower (adc/tdc values - from sims or real data)
74  // TOWER_CALIB_<detector>: Calibrated towers
75  // CLUSTER_<detector>: clusters
76  process_g4hits(topNode);
77  process_g4cells(topNode);
78  process_towers(topNode);
79  process_clusters(topNode);
81 }
82 
84 {
85  ostringstream nodename;
86 
87  // loop over the G4Hits
88  nodename.str("");
89  nodename << "G4HIT_" << detector;
90  PHG4HitContainer* hits = findNode::getClass<PHG4HitContainer>(topNode, nodename.str().c_str());
91  if (hits)
92  {
93  // this returns an iterator to the beginning and the end of our G4Hits
94  PHG4HitContainer::ConstRange hit_range = hits->getHits();
95  for (PHG4HitContainer::ConstIterator hit_iter = hit_range.first; hit_iter != hit_range.second; hit_iter++)
96 
97  {
98  // the pointer to the G4Hit is hit_iter->second
99  g4hitntuple->Fill(hit_iter->second->get_x(0),
100  hit_iter->second->get_y(0),
101  hit_iter->second->get_z(0),
102  hit_iter->second->get_x(1),
103  hit_iter->second->get_y(1),
104  hit_iter->second->get_z(1),
105  hit_iter->second->get_edep());
106  }
107  }
109 }
110 
112 {
113  ostringstream nodename;
114 
115  // loop over the G4Hits
116  nodename.str("");
117  nodename << "G4CELL_" << detector;
118  PHG4CellContainer* cells = findNode::getClass<PHG4CellContainer>(topNode, nodename.str());
119  if (cells)
120  {
121  PHG4CellContainer::ConstRange cell_range = cells->getCells();
122  int phibin = -999;
123  int etabin = -999;
124  for (PHG4CellContainer::ConstIterator cell_iter = cell_range.first; cell_iter != cell_range.second; cell_iter++)
125  {
126  if (cell_iter->second->has_binning(PHG4CellDefs::scintillatorslatbinning))
127  {
128  phibin = PHG4CellDefs::ScintillatorSlatBinning::get_row(cell_iter->second->get_cellid());
129  etabin = PHG4CellDefs::ScintillatorSlatBinning::get_column(cell_iter->second->get_cellid());
130  }
131  else if (cell_iter->second->has_binning(PHG4CellDefs::sizebinning))
132  {
133  phibin = PHG4CellDefs::SizeBinning::get_phibin(cell_iter->second->get_cellid());
134  etabin = PHG4CellDefs::SizeBinning::get_zbin(cell_iter->second->get_cellid());
135  }
136  else if (cell_iter->second->has_binning(PHG4CellDefs::spacalbinning))
137  {
138  phibin = PHG4CellDefs::SpacalBinning::get_phibin(cell_iter->second->get_cellid());
139  etabin = PHG4CellDefs::SpacalBinning::get_etabin(cell_iter->second->get_cellid());
140  }
141  else
142  {
143  cout << "unknown cell binning, implement 0x" << hex << PHG4CellDefs::get_binning(cell_iter->second->get_cellid()) << dec << endl;
144  }
145  g4cellntuple->Fill(
146  phibin,
147  etabin,
148  cell_iter->second->get_edep());
149  }
150  }
152 }
153 
155 {
156  ostringstream nodename;
157  ostringstream geonodename;
158 
159  // loop over the G4Hits
160  nodename.str("");
161  nodename << "TOWER_CALIB_" << detector;
162  geonodename.str("");
163  geonodename << "TOWERGEOM_" << detector;
164  RawTowerGeomContainer* towergeom = findNode::getClass<RawTowerGeomContainer>(topNode, geonodename.str().c_str());
165  if (!towergeom)
166  {
168  }
169  RawTowerContainer* towers = findNode::getClass<RawTowerContainer>(topNode, nodename.str().c_str());
170  if (towers)
171  {
172  // again pair of iterators to begin and end of tower map
173  RawTowerContainer::ConstRange tower_range = towers->getTowers();
174  for (RawTowerContainer::ConstIterator tower_iter = tower_range.first; tower_iter != tower_range.second; tower_iter++)
175 
176  {
177  int phibin = tower_iter->second->get_binphi();
178  int etabin = tower_iter->second->get_bineta();
179  double phi = towergeom->get_phicenter(phibin);
180  double eta = towergeom->get_etacenter(etabin);
181  towerntuple->Fill(phi,
182  eta,
183  tower_iter->second->get_energy());
184  }
185  }
187 }
188 
190 {
191  ostringstream nodename;
192 
193  // loop over the G4Hits
194  nodename.str("");
195  nodename << "CLUSTER_" << detector;
196  RawClusterContainer* clusters = findNode::getClass<RawClusterContainer>(topNode, nodename.str().c_str());
197  if (clusters)
198  {
199  RawClusterContainer::ConstRange cluster_range = clusters->getClusters();
200  for (RawClusterContainer::ConstIterator cluster_iter = cluster_range.first; cluster_iter != cluster_range.second; cluster_iter++)
201  {
202  clusterntuple->Fill(cluster_iter->second->get_phi(),
203  cluster_iter->second->get_z(),
204  cluster_iter->second->get_energy(),
205  cluster_iter->second->getNTowers());
206  }
207  }
209 }
210 
211 int CaloAna::End(PHCompositeNode* /*topNode*/)
212 {
213  outfile->cd();
214  g4hitntuple->Write();
215  g4cellntuple->Write();
216  towerntuple->Write();
217  clusterntuple->Write();
218  outfile->Write();
219  outfile->Close();
220  delete outfile;
221  hm->dumpHistos(outfilename, "UPDATE");
222  return 0;
223 }