Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFParticle_DST.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFParticle_DST.cc
1 /*****************/
2 /* Cameron Dean */
3 /* LANL 2020 */
4 /* cdean@bnl.gov */
5 /*****************/
6 /*
7  * Class to append reconstructed events to node tree
8  */
9 
10 // Ideas taken from PHRaveVertexing
11 
12 #include "KFParticle_DST.h"
13 
14 #include "KFParticle_Container.h"
15 #include "KFParticle_Tools.h"
17 
18 #include <trackbase_historic/SvtxTrack.h> // for SvtxTrack
19 #include <trackbase_historic/SvtxTrackMap.h> // for SvtxTrackMap, SvtxTr...
22 
24 
25 #include <phool/PHCompositeNode.h>
26 #include <phool/PHIODataNode.h>
27 #include <phool/PHNode.h> // for PHNode
28 #include <phool/PHNodeIterator.h>
29 #include <phool/PHObject.h> // for PHObject
30 #include <phool/getClass.h>
31 
32 #include <KFParticle.h> // for KFParticle
33 
34 #include <cstdlib> // for exit, size_t, abs
35 #include <iostream> // for operator<<, endl
36 #include <map> // for map, map<>::mapped_type
37 #include <utility> // for pair
38 
41 
43 {
44  PHNodeIterator iter(topNode);
45 
46  PHCompositeNode* lowerNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
47  if (!lowerNode)
48  {
49  lowerNode = new PHCompositeNode("DST");
50  topNode->addNode(lowerNode);
51  std::cout << "DST node added" << std::endl;
52  }
53 
54  std::string baseName;
55  std::string trackNodeName;
56  std::string particleNodeName;
57 
58  if (m_container_name.empty())
59  {
60  baseName = "reconstructedParticles";
61  }
62  else
63  {
64  baseName = m_container_name;
65  }
66 
67  // Cant have forward slashes in DST or else you make a subdirectory on save!!!
68  std::string undrscr = "_";
69  std::string nothing = "";
70  std::map<std::string, std::string> forbiddenStrings;
71  forbiddenStrings["/"] = undrscr;
72  forbiddenStrings["("] = undrscr;
73  forbiddenStrings[")"] = nothing;
74  forbiddenStrings["+"] = "plus";
75  forbiddenStrings["-"] = "minus";
76  forbiddenStrings["*"] = "star";
77  for (auto const& [badString, goodString] : forbiddenStrings)
78  {
79  size_t pos;
80  while ((pos = baseName.find(badString)) != std::string::npos)
81  {
82  baseName.replace(pos, 1, goodString);
83  }
84  }
85 
86  trackNodeName = baseName + "_SvtxTrackMap";
87  particleNodeName = baseName + "_KFParticle_Container";
88 
90  {
92  PHIODataNode<PHObject>* trackNode = new PHIODataNode<PHObject>(m_recoTrackMap, trackNodeName.c_str(), "PHObject");
93  lowerNode->addNode(trackNode);
94  std::cout << trackNodeName << " node added" << std::endl;
95  }
96 
98  {
100  PHIODataNode<PHObject>* particleNode = new PHIODataNode<PHObject>(m_recoParticleMap, particleNodeName.c_str(), "PHObject");
101  lowerNode->addNode(particleNode);
102  std::cout << particleNodeName << " node added" << std::endl;
103  }
104 
106  {
107  std::cout << "You have asked to put your selection on the node tree but disabled both the SvtxTrackMap and KFParticle_Container\n";
108  std::cout << "Check your options" << std::endl;
109  exit(0);
110  }
111 
113 }
114 
115 void KFParticle_DST::fillParticleNode(PHCompositeNode* topNode, const KFParticle& motherParticle,
116  const std::vector<KFParticle>& daughters,
117  const std::vector<KFParticle>& intermediates)
118 {
120  {
121  fillParticleNode_Track(topNode, motherParticle, daughters, intermediates);
122  }
124  {
125  fillParticleNode_Particle(topNode, motherParticle, daughters, intermediates);
126  }
127 }
128 
130  std::vector<KFParticle> daughters,
131  std::vector<KFParticle> intermediates)
132 {
133  std::string baseName;
134  std::string trackNodeName;
135 
136  if (m_container_name.empty())
137  {
138  baseName = "reconstructedParticles";
139  }
140  else
141  {
142  baseName = m_container_name;
143  }
144 
145  // Cant have forward slashes in DST or else you make a subdirectory on save!!!
146  std::string undrscr = "_";
147  std::string nothing = "";
148  std::map<std::string, std::string> forbiddenStrings;
149  forbiddenStrings["/"] = undrscr;
150  forbiddenStrings["("] = undrscr;
151  forbiddenStrings[")"] = nothing;
152  forbiddenStrings["+"] = "plus";
153  forbiddenStrings["-"] = "minus";
154  forbiddenStrings["*"] = "star";
155  for (auto const& [badString, goodString] : forbiddenStrings)
156  {
157  size_t pos;
158  while ((pos = baseName.find(badString)) != std::string::npos)
159  {
160  baseName.replace(pos, 1, goodString);
161  }
162  }
163 
164  trackNodeName = baseName + "_SvtxTrackMap";
165 
166  m_recoTrackMap = findNode::getClass<SvtxTrackMap>(topNode, trackNodeName.c_str());
167 
168  SvtxTrack* m_recoTrack = new SvtxTrack_v2();
169 
170  m_recoTrack = buildSvtxTrack(motherParticle);
171  m_recoTrackMap->insert(m_recoTrack);
172  m_recoTrack->Reset();
173 
175  {
176  KFParticle* intermediateArray = &intermediates[0];
177 
178  for (unsigned int k = 0; k < intermediates.size(); ++k)
179  {
180  m_recoTrack = buildSvtxTrack(intermediateArray[k]);
181  m_recoTrackMap->insert(m_recoTrack);
182  m_recoTrack->Reset();
183  }
184  }
185 
186  SvtxTrackMap* originalTrackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
187  KFParticle* daughterArray = &daughters[0];
188 
189  for (unsigned int k = 0; k < daughters.size(); ++k)
190  {
191  if (originalTrackMap->size() == 0)
192  {
193  std::cout << "There was no original track map found, the tracks will have no cluster information!" << std::endl;
194  m_recoTrack = buildSvtxTrack(daughterArray[k]);
195  }
196  else
197  {
198  m_recoTrack = kfpTruthTools_DST.getTrack(daughterArray[k].Id(), originalTrackMap);
199  }
200 
201  m_recoTrackMap->insert(m_recoTrack);
202  }
203 }
204 
206  std::vector<KFParticle> daughters,
207  std::vector<KFParticle> intermediates)
208 {
209  std::string baseName;
210  std::string particleNodeName;
211 
212  if (m_container_name.empty())
213  {
214  baseName = "reconstructedParticles";
215  }
216  else
217  {
218  baseName = m_container_name;
219  }
220 
221  // Cant have forward slashes in DST or else you make a subdirectory on save!!!
222  std::string undrscr = "_";
223  std::string nothing = "";
224  std::map<std::string, std::string> forbiddenStrings;
225  forbiddenStrings["/"] = undrscr;
226  forbiddenStrings["("] = undrscr;
227  forbiddenStrings[")"] = nothing;
228  forbiddenStrings["+"] = "plus";
229  forbiddenStrings["-"] = "minus";
230  forbiddenStrings["*"] = "star";
231  for (auto const& [badString, goodString] : forbiddenStrings)
232  {
233  size_t pos;
234  while ((pos = baseName.find(badString)) != std::string::npos)
235  {
236  baseName.replace(pos, 1, goodString);
237  }
238  }
239 
240  particleNodeName = baseName + "_KFParticle_Container";
241 
242  m_recoParticleMap = findNode::getClass<KFParticle_Container>(topNode, particleNodeName.c_str());
243 
244  m_recoParticleMap->insert(&motherParticle);
245 
247  {
248  KFParticle* intermediateArray = &intermediates[0];
249 
250  for (unsigned int k = 0; k < intermediates.size(); ++k)
251  {
252  m_recoParticleMap->insert(&intermediateArray[k]);
253  }
254  }
255 
256  KFParticle* daughterArray = &daughters[0];
257  for (unsigned int k = 0; k < daughters.size(); ++k)
258  {
259  m_recoParticleMap->insert(&daughterArray[k]);
260  }
261 }
262 
264 {
265  SvtxTrack* track = new SvtxTrack_v2();
266 
267  track->set_id(std::abs(particle.GetPDG()));
268  track->set_charge((int) particle.GetQ());
269  track->set_chisq(particle.GetChi2());
270  track->set_ndf(particle.GetNDF());
271 
272  track->set_x(particle.GetX());
273  track->set_y(particle.GetY());
274  track->set_z(particle.GetZ());
275 
276  track->set_px(particle.GetPx());
277  track->set_py(particle.GetPy());
278  track->set_pz(particle.GetPz());
279 
280  for (int i = 0; i < 6; ++i)
281  {
282  for (int j = 0; j < 6; ++j)
283  {
284  track->set_error(i, j, particle.GetCovariance(i, j));
285  }
286  }
287 
288  return track;
289 }
290 
292 {
293  std::string baseName;
294  std::string trackNodeName;
295  std::string particleNodeName;
296 
297  if (m_container_name.empty())
298  {
299  baseName = "reconstructedParticles";
300  }
301  else
302  {
303  baseName = m_container_name;
304  }
305 
306  // Cant have forward slashes in DST or else you make a subdirectory on save!!!
307  std::string undrscr = "_";
308  std::string nothing = "";
309  std::map<std::string, std::string> forbiddenStrings;
310  forbiddenStrings["/"] = undrscr;
311  forbiddenStrings["("] = undrscr;
312  forbiddenStrings[")"] = nothing;
313  forbiddenStrings["+"] = "plus";
314  forbiddenStrings["-"] = "minus";
315  forbiddenStrings["*"] = "star";
316  for (auto const& [badString, goodString] : forbiddenStrings)
317  {
318  size_t pos;
319  while ((pos = baseName.find(badString)) != std::string::npos)
320  {
321  baseName.replace(pos, 1, goodString);
322  }
323  }
324 
326  {
327  trackNodeName = baseName + "_SvtxTrackMap";
328  std::cout << "----------------";
329  std::cout << " KFParticle_DST: " << trackNodeName << " information ";
330  std::cout << "----------------" << std::endl;
331  SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode, trackNodeName.c_str());
332  for (auto& iter : *trackmap)
333  {
334  SvtxTrack* track = iter.second;
335  track->identify();
336  }
337  std::cout << "--------------------------------------------------------------------------------------------------" << std::endl;
338  }
339 
341  {
342  particleNodeName = baseName + "_KFParticle_Container";
343  std::cout << "----------------";
344  std::cout << " KFParticle_DST: " << particleNodeName << " information ";
345  std::cout << "----------------" << std::endl;
346  KFParticle_Container* particlemap = findNode::getClass<KFParticle_Container>(topNode, particleNodeName.c_str());
347  for (auto& iter : *particlemap)
348  {
349  KFParticle* particle = iter.second;
350  kfpTupleTools_DST.identify(*particle);
351  }
352  std::cout << "--------------------------------------------------------------------------------------------------" << std::endl;
353  }
354 }