ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EICG4ZDCNtuple.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EICG4ZDCNtuple.cc
1 // - 1/June/2021 Ntuple production for ZDC G4 hits Shima Shimizu
2 //
3 #include "EICG4ZDCNtuple.h"
4 
5 #include <g4main/PHG4Hit.h>
7 
9 #include <fun4all/SubsysReco.h> // for SubsysReco
10 
11 #include <phool/getClass.h>
12 
13 #include <TFile.h>
14 #include <TH1.h>
15 #include <TNtuple.h>
16 
17 #include <sstream>
18 #include <utility>
19 
20 using namespace std;
21 
22 EICG4ZDCNtuple::EICG4ZDCNtuple(const std::string &name, const std::string &filename)
23  : SubsysReco(name)
24  , nblocks(0)
25  , hm(nullptr)
26  , _filename(filename)
27  , ntup(nullptr)
28  , outfile(nullptr){
29 }
30 
32  // delete ntup;
33  delete hm;
34 }
35 
37  {
38  hm = new Fun4AllHistoManager(Name());
39  outfile = new TFile(_filename.c_str(), "RECREATE");
40  ntup = new TNtuple("zdchit", "ZDCs", "detid:layer:xid:yid:x0:y0:z0:x1:y1:z1:t0:t1:edep");
41  // ntup->SetDirectory(0);
42  return 0;
43  }
44 
46  {
47  ostringstream nodename;
48  set<string>::const_iterator iter;
49  for (iter = _node_postfix.begin(); iter != _node_postfix.end(); ++iter)
50  {
51  //int detid = (_detid.find(*iter))->second;
52  nodename.str("");
53  nodename << "G4HIT_" << *iter;
54  PHG4HitContainer *hits = findNode::getClass<PHG4HitContainer>(topNode, nodename.str());
55  if (!hits) return 0;
56 
57  double esum = 0;
58  // double numhits = hits->size();
59  // nhits[i]->Fill(numhits);
60  PHG4HitContainer::ConstRange hit_range = hits->getHits();
61  for (PHG4HitContainer::ConstIterator hit_iter = hit_range.first; hit_iter != hit_range.second; hit_iter++){
62  if(hit_iter->second->get_hit_type()<0) continue;
63 
64  esum += hit_iter->second->get_edep();
65  ntup->Fill(hit_iter->second->get_hit_type(),
66  hit_iter->second->get_layer(),
67  hit_iter->second->get_index_i(),
68  hit_iter->second->get_index_j(),
69  hit_iter->second->get_x(0),
70  hit_iter->second->get_y(0),
71  hit_iter->second->get_z(0),
72  hit_iter->second->get_x(1),
73  hit_iter->second->get_y(1),
74  hit_iter->second->get_z(1),
75  hit_iter->second->get_t(0),
76  hit_iter->second->get_t(1),
77  hit_iter->second->get_edep());
78  }
79  }
80 
81  return 0;
82  }
83 
85  {
86  outfile->cd();
87  ntup->Write();
88  outfile->Write();
89  outfile->Close();
90  delete outfile;
91  hm->dumpHistos(_filename, "UPDATE");
92  return 0;
93  }
94 
95  void EICG4ZDCNtuple::AddNode(const std::string &name, const int detid)
96  {
97  _node_postfix.insert(name);
98  _detid[name] = detid;
99  return;
100  }