Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EdepNtuple.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EdepNtuple.cc
1 #include "EdepNtuple.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("ed", "G4Hits", "ES:EA:HIS:HIA:HOS:HOA:BH:MAG");
45  // ntup->SetDirectory(0);
46  TH1 *h1 = new TH1F("edep1GeV","edep 0-1GeV",1000,0,1);
47  eloss.push_back(h1);
48  h1 = new TH1F("edep100GeV","edep 0-100GeV",1000,0,100);
49  eloss.push_back(h1);
50  return 0;
51 }
52 
53 int
55 {
56  ostringstream nodename;
57  set<string>::const_iterator iter;
58  vector<TH1 *>::const_iterator eiter;
59  float ntvar[8]={0};
60  PHG4HitContainer *hits = nullptr;
61 
62  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_CEMC");
63 
64  if (hits)
65  {
66  // double numhits = hits->size();
67  // nhits[i]->Fill(numhits);
68  PHG4HitContainer::ConstRange hit_range = hits->getHits();
69  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
70 
71  {
72  ntvar[0] += hit_iter->second->get_edep();
73  }
74  }
75 
76  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_ABSORBER_CEMC");
77 
78  if (hits)
79  {
80  // double numhits = hits->size();
81  // nhits[i]->Fill(numhits);
82  PHG4HitContainer::ConstRange hit_range = hits->getHits();
83  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
84 
85  {
86  ntvar[1] += hit_iter->second->get_edep();
87  }
88  }
89 
90  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_HCALIN");
91 
92  if (hits)
93  {
94  // double numhits = hits->size();
95  // nhits[i]->Fill(numhits);
96  PHG4HitContainer::ConstRange hit_range = hits->getHits();
97  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
98 
99  {
100  ntvar[2] += hit_iter->second->get_edep();
101  }
102  }
103 
104  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_ABSORBER_HCALIN");
105 
106  if (hits)
107  {
108  // double numhits = hits->size();
109  // nhits[i]->Fill(numhits);
110  PHG4HitContainer::ConstRange hit_range = hits->getHits();
111  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
112 
113  {
114  ntvar[3] += hit_iter->second->get_edep();
115  }
116  }
117 
118  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_HCALOUT");
119 
120  if (hits)
121  {
122  // double numhits = hits->size();
123  // nhits[i]->Fill(numhits);
124  PHG4HitContainer::ConstRange hit_range = hits->getHits();
125  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
126 
127  {
128  ntvar[4] += hit_iter->second->get_edep();
129  }
130  }
131 
132  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_ABSORBER_HCALOUT");
133 
134  if (hits)
135  {
136  // double numhits = hits->size();
137  // nhits[i]->Fill(numhits);
138  PHG4HitContainer::ConstRange hit_range = hits->getHits();
139  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
140 
141  {
142  ntvar[5] += hit_iter->second->get_edep();
143  }
144  }
145 
146  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_BH_1");
147 
148  if (hits)
149  {
150  // double numhits = hits->size();
151  // nhits[i]->Fill(numhits);
152  PHG4HitContainer::ConstRange hit_range = hits->getHits();
153  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
154 
155  {
156  ntvar[6] += hit_iter->second->get_edep();
157  }
158  }
159 
160  hits = findNode::getClass<PHG4HitContainer>(topNode,"G4HIT_MAGNET");
161 
162  if (hits)
163  {
164  // double numhits = hits->size();
165  // nhits[i]->Fill(numhits);
166  PHG4HitContainer::ConstRange hit_range = hits->getHits();
167  for ( PHG4HitContainer::ConstIterator hit_iter = hit_range.first ; hit_iter != hit_range.second; hit_iter++ )
168 
169  {
170  ntvar[7] += hit_iter->second->get_edep();
171  }
172  }
173 
174  ntupe->Fill(ntvar);
175  return 0;
176 }
177 
178 int
180 {
181  outfile->cd();
182  // ntup->Write();
183  ntupe->Write();
184  outfile->Write();
185  outfile->Close();
186  delete outfile;
187  hm->dumpHistos(_filename, "UPDATE");
188  return 0;
189 }
190 
191 void
192 EdepNtuple::AddNode(const std::string &name, const int detid)
193 {
194  _node_postfix.insert(name);
195  _detid[name] = detid;
196  return;
197 }