Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HitCountNtuple.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HitCountNtuple.cc
1 #include "HitCountNtuple.h"
2 
4 #include <g4main/PHG4Hit.h>
5 
7 
8 #include <phool/getClass.h>
9 
10 #include <TFile.h>
11 #include <TH1.h>
12 #include <TH2.h>
13 #include <TNtuple.h>
14 
15 #include <boost/foreach.hpp>
16 
17 #include<sstream>
18 
19 using namespace std;
20 
22  SubsysReco( name ),
23  nblocks(0),
24  hm(NULL),
25  _filename(filename),
26  ntup(NULL),
27  outfile(NULL)
28 {}
29 
31 {
32  // delete ntup;
33  delete hm;
34 }
35 
36 
37 int
39 {
40  ostringstream hname, htit;
41  hm = new Fun4AllHistoManager(Name());
42  outfile = new TFile(_filename.c_str(), "RECREATE");
43  //ntup = new TNtuple("hitntup", "G4Hits", "detid:layer:x0:y0:z0:x1:y1:z1:edep");
44  ntupe = new TNtuple("hitcnt", "NHits", "cemc:cemc_abs:ihcal:ihcal_abs:ohcal:ohcal_abs");
45  // ntup->SetDirectory(0);
46  return 0;
47 }
48 
49 int
51 {
52  set<string>::const_iterator iter;
53  vector<TH1 *>::const_iterator eiter;
54  float ntvar[6]={0};
55  PHG4HitContainer *hits = nullptr;
56  string nodename[6] = {"G4HIT_CEMC", "G4HIT_ABSORBER_CEMC",
57  "G4HIT_HCALIN", "G4HIT_ABSORBER_HCALIN",
58  "G4HIT_HCALOUT", "G4HIT_ABSORBER_HCALOUT"};
59 
60  for (int i=0; i<6; i++)
61  {
62  hits = findNode::getClass<PHG4HitContainer>(topNode,nodename[i]);
63 
64  if (hits)
65  {
66  // double numhits = hits->size();
67  // nhits[i]->Fill(numhits);
68  ntvar[i] = hits->size();
69  }
70  }
71  ntupe->Fill(ntvar);
72  return 0;
73 }
74 
75 int
77 {
78  outfile->cd();
79  // ntup->Write();
80  ntupe->Write();
81  outfile->Write();
82  outfile->Close();
83  delete outfile;
84  hm->dumpHistos(_filename, "UPDATE");
85  return 0;
86 }
87 
88 void
89 HitCountNtuple::AddNode(const std::string &name, const int detid)
90 {
91  _node_postfix.insert(name);
92  _detid[name] = detid;
93  return;
94 }