ECCE @ EIC 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 
20 
22 
23 #include <phool/PHCompositeNode.h>
24 #include <phool/PHIODataNode.h>
25 #include <phool/PHNodeIterator.h>
26 #include <phool/getClass.h>
27 
28 
31 
33 {
34  PHNodeIterator iter(topNode);
35 
36  PHCompositeNode* lowerNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
37  if (!lowerNode)
38  {
39  lowerNode = new PHCompositeNode("DST");
40  topNode->addNode(lowerNode);
41  std::cout << "DST node added" << std::endl;
42  }
43 
44  std::string baseName;
45  std::string trackNodeName;
46  std::string particleNodeName;
47 
48  if (m_container_name.empty())
49  baseName = "reconstructedParticles";
50  else
51  baseName = m_container_name;
52 
53  //Cant have forward slashes in DST or else you make a subdirectory on save!!!
54  size_t pos;
55  std::string undrscr = "_";
56  std::string nothing = "";
57  std::map<std::string, std::string> forbiddenStrings;
58  forbiddenStrings["/"] = undrscr;
59  forbiddenStrings["("] = undrscr;
60  forbiddenStrings[")"] = nothing;
61  forbiddenStrings["+"] = "plus";
62  forbiddenStrings["-"] = "minus";
63  forbiddenStrings["*"] = "star";
64  for (auto const& [badString, goodString] : forbiddenStrings)
65  {
66  while ((pos = baseName.find(badString)) != std::string::npos) baseName.replace(pos, 1, goodString);
67  }
68 
69  trackNodeName = baseName + "_SvtxTrackMap";
70  particleNodeName = baseName + "_KFParticle_Container";
71 
73  {
75  PHIODataNode<PHObject>* trackNode = new PHIODataNode<PHObject>(m_recoTrackMap, trackNodeName.c_str(), "PHObject");
76  lowerNode->addNode(trackNode);
77  std::cout << trackNodeName << " node added" << std::endl;
78  }
79 
81  {
83  PHIODataNode<PHObject>* particleNode = new PHIODataNode<PHObject>(m_recoParticleMap, particleNodeName.c_str(), "PHObject");
84  lowerNode->addNode(particleNode);
85  std::cout << particleNodeName << " node added" << std::endl;
86  }
87 
89  {
90  std::cout << "You have asked to put your selection on the node tree but disabled both the SvtxTrackMap and KFParticle_Container\n";
91  std::cout << "Check your options" << std::endl;
92  exit(0);
93  }
94 
96 }
97 
98 void KFParticle_DST::fillParticleNode(PHCompositeNode* topNode, const KFParticle& motherParticle,
99  const std::vector<KFParticle>& daughters,
100  const std::vector<KFParticle>& intermediates)
101 {
103  {
104  fillParticleNode_Track(topNode, motherParticle, daughters, intermediates);
105  }
107  {
108  fillParticleNode_Particle(topNode, motherParticle, daughters, intermediates);
109  }
110 }
111 
112 void KFParticle_DST::fillParticleNode_Track(PHCompositeNode* topNode, const KFParticle& motherParticle,
113  std::vector<KFParticle> daughters,
114  std::vector<KFParticle> intermediates)
115 {
116  std::string baseName;
117  std::string trackNodeName;
118 
119  if (m_container_name.empty())
120  baseName = "reconstructedParticles";
121  else
122  baseName = m_container_name;
123 
124  //Cant have forward slashes in DST or else you make a subdirectory on save!!!
125  size_t pos;
126  std::string undrscr = "_";
127  std::string nothing = "";
128  std::map<std::string, std::string> forbiddenStrings;
129  forbiddenStrings["/"] = undrscr;
130  forbiddenStrings["("] = undrscr;
131  forbiddenStrings[")"] = nothing;
132  forbiddenStrings["+"] = "plus";
133  forbiddenStrings["-"] = "minus";
134  forbiddenStrings["*"] = "star";
135  for (auto const& [badString, goodString] : forbiddenStrings)
136  {
137  while ((pos = baseName.find(badString)) != std::string::npos) baseName.replace(pos, 1, goodString);
138  }
139 
140  trackNodeName = baseName + "_SvtxTrackMap";
141 
142  m_recoTrackMap = findNode::getClass<SvtxTrackMap>(topNode, trackNodeName.c_str());
143 
144  SvtxTrack* m_recoTrack = new SvtxTrack_v1();
145 
146  m_recoTrack = buildSvtxTrack(motherParticle);
147  m_recoTrackMap->insert(m_recoTrack);
148  m_recoTrack->Reset();
149 
151  {
152  KFParticle* intermediateArray = &intermediates[0];
153 
154  for (unsigned int k = 0; k < intermediates.size(); ++k)
155  {
156  m_recoTrack = buildSvtxTrack(intermediateArray[k]);
157  m_recoTrackMap->insert(m_recoTrack);
158  m_recoTrack->Reset();
159  }
160  }
161 
162  SvtxTrackMap* originalTrackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
163  KFParticle* daughterArray = &daughters[0];
164 
165  for (unsigned int k = 0; k < daughters.size(); ++k)
166  {
167  if (originalTrackMap->size() == 0)
168  {
169  std::cout << "There was no original track map found, the tracks will have no cluster information!" << std::endl;
170  m_recoTrack = buildSvtxTrack(daughterArray[k]);
171  }
172  else
173  {
174  m_recoTrack = kfpTruthTools_DST.getTrack(daughterArray[k].Id(), originalTrackMap);
175  }
176 
177  m_recoTrackMap->insert(m_recoTrack);
178  }
179 }
180 
181 void KFParticle_DST::fillParticleNode_Particle(PHCompositeNode* topNode, const KFParticle& motherParticle,
182  std::vector<KFParticle> daughters,
183  std::vector<KFParticle> intermediates)
184 {
185  std::string baseName;
186  std::string particleNodeName;
187 
188  if (m_container_name.empty())
189  baseName = "reconstructedParticles";
190  else
191  baseName = m_container_name;
192 
193  //Cant have forward slashes in DST or else you make a subdirectory on save!!!
194  size_t pos;
195  std::string undrscr = "_";
196  std::string nothing = "";
197  std::map<std::string, std::string> forbiddenStrings;
198  forbiddenStrings["/"] = undrscr;
199  forbiddenStrings["("] = undrscr;
200  forbiddenStrings[")"] = nothing;
201  forbiddenStrings["+"] = "plus";
202  forbiddenStrings["-"] = "minus";
203  forbiddenStrings["*"] = "star";
204  for (auto const& [badString, goodString] : forbiddenStrings)
205  {
206  while ((pos = baseName.find(badString)) != std::string::npos) baseName.replace(pos, 1, goodString);
207  }
208 
209  particleNodeName = baseName + "_KFParticle_Container";
210 
211  m_recoParticleMap = findNode::getClass<KFParticle_Container>(topNode, particleNodeName.c_str());
212 
213  m_recoParticleMap->insert(&motherParticle);
214 
216  {
217  KFParticle* intermediateArray = &intermediates[0];
218 
219  for (unsigned int k = 0; k < intermediates.size(); ++k)
220  m_recoParticleMap->insert(&intermediateArray[k]);
221  }
222 
223  KFParticle* daughterArray = &daughters[0];
224  for (unsigned int k = 0; k < daughters.size(); ++k)
225  m_recoParticleMap->insert(&daughterArray[k]);
226 }
227 
229 {
230  SvtxTrack* track = new SvtxTrack_v1();
231 
232  track->set_id(std::abs(particle.GetPDG()));
233  track->set_charge((int) particle.GetQ());
234  track->set_chisq(particle.GetChi2());
235  track->set_ndf(particle.GetNDF());
236 
237  track->set_x(particle.GetX());
238  track->set_y(particle.GetY());
239  track->set_z(particle.GetZ());
240 
241  track->set_px(particle.GetPx());
242  track->set_py(particle.GetPy());
243  track->set_pz(particle.GetPz());
244 
245  for (int i = 0; i < 6; ++i)
246  for (int j = 0; j < 6; ++j)
247  track->set_error(i, j, particle.GetCovariance(i, j));
248 
249  return track;
250 }
251 
253 {
254  std::string baseName;
255  std::string trackNodeName;
256  std::string particleNodeName;
257 
258  if (m_container_name.empty())
259  baseName = "reconstructedParticles";
260  else
261  baseName = m_container_name;
262 
263  //Cant have forward slashes in DST or else you make a subdirectory on save!!!
264  size_t pos;
265  std::string undrscr = "_";
266  std::string nothing = "";
267  std::map<std::string, std::string> forbiddenStrings;
268  forbiddenStrings["/"] = undrscr;
269  forbiddenStrings["("] = undrscr;
270  forbiddenStrings[")"] = nothing;
271  forbiddenStrings["+"] = "plus";
272  forbiddenStrings["-"] = "minus";
273  forbiddenStrings["*"] = "star";
274  for (auto const& [badString, goodString] : forbiddenStrings)
275  {
276  while ((pos = baseName.find(badString)) != std::string::npos) baseName.replace(pos, 1, goodString);
277  }
278 
280  {
281  trackNodeName = baseName + "_SvtxTrackMap";
282  std::cout << "----------------";
283  std::cout << " KFParticle_DST: " << trackNodeName << " information ";
284  std::cout << "----------------" << std::endl;
285  SvtxTrackMap* trackmap = findNode::getClass<SvtxTrackMap>(topNode, trackNodeName.c_str());
286  for (SvtxTrackMap::Iter iter = trackmap->begin(); iter != trackmap->end(); ++iter)
287  {
288  SvtxTrack* track = iter->second;
289  track->identify();
290  }
291  std::cout << "--------------------------------------------------------------------------------------------------" << std::endl;
292  }
293 
295  {
296  particleNodeName = baseName + "_KFParticle_Container";
297  std::cout << "----------------";
298  std::cout << " KFParticle_DST: " << particleNodeName << " information ";
299  std::cout << "----------------" << std::endl;
300  KFParticle_Container* particlemap = findNode::getClass<KFParticle_Container>(topNode, particleNodeName.c_str());
301  for (KFParticle_Container::Iter iter = particlemap->begin(); iter != particlemap->end(); ++iter)
302  {
303  KFParticle* particle = iter->second;
304  kfpTupleTools_DST.identify(*particle);
305  }
306  std::cout << "--------------------------------------------------------------------------------------------------" << std::endl;
307  }
308 }