/
PHG4ForwardCalCellReco.cc
186 lines (167 loc) · 6.04 KB
/
PHG4ForwardCalCellReco.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "PHG4ForwardCalCellReco.h"
#include <g4detectors/PHG4CylinderCell.h> // for PHG4CylinderCell
#include <g4detectors/PHG4CylinderCellContainer.h>
#include <g4detectors/PHG4CylinderCellv3.h>
#include <g4main/PHG4Hit.h>
#include <g4main/PHG4HitContainer.h>
#include <fun4all/Fun4AllReturnCodes.h>
#include <fun4all/SubsysReco.h> // for SubsysReco
#include <phool/PHCompositeNode.h>
#include <phool/PHIODataNode.h>
#include <phool/PHNode.h> // for PHNode
#include <phool/PHNodeIterator.h>
#include <phool/PHObject.h> // for PHObject
#include <phool/getClass.h>
#include <phool/phool.h> // for PHWHERE
#include <cmath>
#include <cstdlib>
#include <cstring> // for memset
#include <iostream>
#include <sstream>
using namespace std;
PHG4ForwardCalCellReco::PHG4ForwardCalCellReco(const string &name)
: SubsysReco(name)
, chkenergyconservation(0)
, tmin_default(0.0)
, // ns
tmax_default(60.0)
, // ns
tmin_max()
{
memset(nbins, 0, sizeof(nbins));
}
int PHG4ForwardCalCellReco::InitRun(PHCompositeNode *topNode)
{
PHNodeIterator iter(topNode);
// Looking for the DST node
PHCompositeNode *dstNode;
dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
if (!dstNode)
{
std::cout << PHWHERE << "DST Node missing, doing nothing." << std::endl;
exit(1);
}
hitnodename = "G4HIT_" + detector;
PHG4HitContainer *g4hit = findNode::getClass<PHG4HitContainer>(topNode, hitnodename.c_str());
if (!g4hit)
{
cout << "Could not locate g4 hit node " << hitnodename << endl;
exit(1);
}
cellnodename = "G4CELL_" + detector;
PHG4CylinderCellContainer *cells = findNode::getClass<PHG4CylinderCellContainer>(topNode, cellnodename);
if (!cells)
{
PHNodeIterator dstiter(dstNode);
PHCompositeNode *DetNode =
dynamic_cast<PHCompositeNode *>(dstiter.findFirst("PHCompositeNode",
detector));
if (!DetNode)
{
DetNode = new PHCompositeNode(detector);
dstNode->addNode(DetNode);
}
cells = new PHG4CylinderCellContainer();
PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(cells, cellnodename.c_str(), "PHObject");
DetNode->addNode(newNode);
}
return Fun4AllReturnCodes::EVENT_OK;
}
int PHG4ForwardCalCellReco::process_event(PHCompositeNode *topNode)
{
PHG4HitContainer *g4hit = findNode::getClass<PHG4HitContainer>(topNode, hitnodename.c_str());
if (!g4hit)
{
cout << "Could not locate g4 hit node " << hitnodename << endl;
exit(1);
}
PHG4CylinderCellContainer *cells = findNode::getClass<PHG4CylinderCellContainer>(topNode, cellnodename);
if (!cells)
{
cout << "could not locate cell node " << cellnodename << endl;
exit(1);
}
PHG4HitContainer::LayerIter layer;
pair<PHG4HitContainer::LayerIter, PHG4HitContainer::LayerIter> layer_begin_end = g4hit->getLayers();
for (layer = layer_begin_end.first; layer != layer_begin_end.second; ++layer)
{
PHG4HitContainer::ConstIterator hiter;
PHG4HitContainer::ConstRange hit_begin_end = g4hit->getHits(*layer);
for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; ++hiter)
{
// checking ADC timing integration window cut
if (hiter->second->get_t(0) > tmax_default) continue;
if (hiter->second->get_t(1) < tmin_default) continue;
// only hits that deposited energy (or geantinos)
if (hiter->second->get_edep() <= 0)
continue;
unsigned int key = (hiter->second->get_index_j() << 16) + hiter->second->get_index_k();
if (celllist.find(key) == celllist.end())
{
celllist[key] = new PHG4CylinderCellv3();
celllist[key]->set_layer(*layer);
celllist[key]->set_j_index(hiter->second->get_index_j());
celllist[key]->set_k_index(hiter->second->get_index_k());
celllist[key]->set_l_index(hiter->second->get_index_l());
}
celllist[key]->add_edep(hiter->first, hiter->second->get_edep(), hiter->second->get_light_yield());
celllist[key]->add_shower_edep(hiter->second->get_shower_id(), hiter->second->get_edep());
}
int numcells = 0;
for (map<unsigned int, PHG4CylinderCell *>::const_iterator mapiter = celllist.begin(); mapiter != celllist.end(); ++mapiter)
{
cells->AddCylinderCellSpecifyKey(mapiter->first, mapiter->second);
numcells++;
}
celllist.clear();
if (Verbosity() > 0)
{
cout << Name() << ": found " << numcells << " eta/slat cells with energy deposition" << endl;
}
}
if (chkenergyconservation)
{
CheckEnergy(topNode);
}
return Fun4AllReturnCodes::EVENT_OK;
}
int PHG4ForwardCalCellReco::End(PHCompositeNode *topNode)
{
return Fun4AllReturnCodes::EVENT_OK;
}
int PHG4ForwardCalCellReco::CheckEnergy(PHCompositeNode *topNode)
{
PHG4HitContainer *g4hit = findNode::getClass<PHG4HitContainer>(topNode, hitnodename.c_str());
PHG4CylinderCellContainer *cells = findNode::getClass<PHG4CylinderCellContainer>(topNode, cellnodename);
double sum_energy_g4hit = 0.;
double sum_energy_cells = 0.;
PHG4HitContainer::ConstRange hit_begin_end = g4hit->getHits();
PHG4HitContainer::ConstIterator hiter;
for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; ++hiter)
{
sum_energy_g4hit += hiter->second->get_edep();
}
PHG4CylinderCellContainer::ConstRange cell_begin_end = cells->getCylinderCells();
PHG4CylinderCellContainer::ConstIterator citer;
for (citer = cell_begin_end.first; citer != cell_begin_end.second; ++citer)
{
sum_energy_cells += citer->second->get_edep();
}
// the fractional eloss for particles traversing eta bins leads to minute rounding errors
if (fabs(sum_energy_cells - sum_energy_g4hit) / sum_energy_g4hit > 1e-6)
{
cout << "energy mismatch between cells: " << sum_energy_cells
<< " and hits: " << sum_energy_g4hit
<< " diff sum(cells) - sum(hits): " << sum_energy_cells - sum_energy_g4hit
<< endl;
return -1;
}
else
{
if (Verbosity() > 0)
{
cout << Name() << ": total energy for this event: " << sum_energy_g4hit << " GeV" << endl;
}
}
return 0;
}