forked from sPHENIX-Collaboration/coresoftware
/
JetReco.cc
184 lines (154 loc) · 5 KB
/
JetReco.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
#include "JetReco.h"
#include "Jet.h"
#include "JetAlgo.h"
#include "JetInput.h"
#include "JetMap.h"
#include "JetMapv1.h"
// PHENIX includes
#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/PHTypedNodeIterator.h>
#include <phool/PHObject.h> // for PHObject
#include <phool/getClass.h>
#include <phool/phool.h> // for PHWHERE
// standard includes
#include <cstdlib> // for exit
#include <iostream>
#include <memory> // for allocator_traits<>::value_type
#include <vector>
using namespace std;
JetReco::JetReco(const string &name)
: SubsysReco(name)
, _inputs()
, _algos()
, _algonode()
, _inputnode()
, _outputs()
{
}
JetReco::~JetReco()
{
for (unsigned int i = 0; i < _inputs.size(); ++i) delete _inputs[i];
_inputs.clear();
for (unsigned int i = 0; i < _algos.size(); ++i) delete _algos[i];
_algos.clear();
_outputs.clear();
}
int JetReco::Init(PHCompositeNode */*topNode*/)
{
return Fun4AllReturnCodes::EVENT_OK;
}
int JetReco::InitRun(PHCompositeNode *topNode)
{
if (Verbosity() > 0)
{
cout << "========================== JetReco::InitRun() =============================" << endl;
cout << " Input Selections:" << endl;
for (unsigned int i = 0; i < _inputs.size(); ++i) _inputs[i]->identify();
cout << " Algorithms:" << endl;
for (unsigned int i = 0; i < _algos.size(); ++i) _algos[i]->identify();
cout << "===========================================================================" << endl;
}
return CreateNodes(topNode);
}
int JetReco::process_event(PHCompositeNode *topNode)
{
if (Verbosity() > 1) cout << "JetReco::process_event -- entered" << endl;
//---------------------------------
// Get Objects off of the Node Tree
//---------------------------------
std::vector<Jet *> inputs; // owns memory
for (unsigned int iselect = 0; iselect < _inputs.size(); ++iselect)
{
std::vector<Jet *> parts = _inputs[iselect]->get_input(topNode);
for (unsigned int ipart = 0; ipart < parts.size(); ++ipart)
{
inputs.push_back(parts[ipart]);
inputs.back()->set_id(inputs.size() - 1); // unique ids ensured
}
}
//---------------------------
// Run the jet reconstruction
//---------------------------
for (unsigned int ialgo = 0; ialgo < _algos.size(); ++ialgo)
{
std::vector<Jet *> jets = _algos[ialgo]->get_jets(inputs); // owns memory
// send the output somewhere on the DST
FillJetNode(topNode, ialgo, jets);
}
// clean up input vector
for (unsigned int i = 0; i < inputs.size(); ++i) delete inputs[i];
inputs.clear();
if (Verbosity() > 1) cout << "JetReco::process_event -- exited" << endl;
return Fun4AllReturnCodes::EVENT_OK;
}
int JetReco::End(PHCompositeNode */*topNode*/)
{
return Fun4AllReturnCodes::EVENT_OK;
}
int JetReco::CreateNodes(PHCompositeNode *topNode)
{
PHNodeIterator iter(topNode);
// Looking for the DST node
PHCompositeNode *dstNode = static_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
if (!dstNode)
{
cout << PHWHERE << "DST Node missing, doing nothing." << endl;
return Fun4AllReturnCodes::ABORTRUN;
}
// Create the AntiKt node if required
PHCompositeNode *AlgoNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", _algonode.c_str()));
if (!AlgoNode)
{
AlgoNode = new PHCompositeNode(_algonode.c_str());
dstNode->addNode(AlgoNode);
}
// Create the Input node if required
PHCompositeNode *InputNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", _inputnode.c_str()));
if (!InputNode)
{
InputNode = new PHCompositeNode(_inputnode.c_str());
AlgoNode->addNode(InputNode);
}
for (unsigned i = 0; i < _outputs.size(); ++i)
{
JetMap *jets = findNode::getClass<JetMap>(topNode, _outputs[i]);
if (!jets)
{
jets = new JetMapv1();
PHIODataNode<PHObject> *JetMapNode = new PHIODataNode<PHObject>(jets, _outputs[i].c_str(), "PHObject");
InputNode->addNode(JetMapNode);
}
}
return Fun4AllReturnCodes::EVENT_OK;
}
void JetReco::FillJetNode(PHCompositeNode *topNode, int ipos, std::vector<Jet *> jets)
{
JetMap *jetmap = nullptr;
PHTypedNodeIterator<JetMap> jetmapiter(topNode);
PHIODataNode<JetMap> *JetMapNode = jetmapiter.find(_outputs[ipos].c_str());
if (!JetMapNode)
{
cout << PHWHERE << " ERROR: Can't find JetMap: " << _outputs[ipos] << endl;
exit(-1);
}
else
{
jetmap = dynamic_cast<JetMap *> (JetMapNode->getData());
}
jetmap->set_algo(_algos[ipos]->get_algo());
jetmap->set_par(_algos[ipos]->get_par());
for (unsigned int i = 0; i < _inputs.size(); ++i)
{
jetmap->insert_src(_inputs[i]->get_src());
}
for (unsigned int i = 0; i < jets.size(); ++i)
{
jetmap->insert(jets[i]); // map takes ownership, sets unique id
}
return;
}