ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4InEvent.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4InEvent.cc
1 #include "PHG4InEvent.h"
2 
3 #include "PHG4Particle.h"
4 #include "PHG4VtxPoint.h"
5 #include "PHG4VtxPointv1.h"
6 
7 #include <cmath>
8 #include <cstdlib>
9 #include <algorithm>
10 using namespace std;
11 
13 {
14 
15  vtxlist.clear();
16  particlelist.clear();
17  return;
18 }
19 
20 int
21 PHG4InEvent::AddVtx(const int /*id*/, const PHG4VtxPoint &vtx)
22 {
23  PHG4VtxPoint *newvtx = new PHG4VtxPoint(vtx);
24  int iret = AddVtxCommon(newvtx);
25  return iret;
26 }
27 
28 int
29 PHG4InEvent::AddVtxHepMC(const int id, const double x, const double y, const double z, const double t0 = NAN)
30 {
31  PHG4VtxPoint *newvtx = new PHG4VtxPointv1(x,y,z,t0);
32  vtxlist[id]=newvtx;
33  return 0;
34 }
35 
36 int
37 PHG4InEvent::AddVtx(const double x, const double y, const double z, const double t0 = NAN)
38 {
39  PHG4VtxPoint *newvtx = new PHG4VtxPointv1(x,y,z,t0);
40  int iret = AddVtxCommon(newvtx);
41  return iret;
42 }
43 
44 int
46 {
47  std::pair< std::map<int, PHG4VtxPoint *>::const_iterator, std::map<int, PHG4VtxPoint *>::const_iterator > vtxbegin_end = GetVertices();
48  for (map<int, PHG4VtxPoint *>::const_iterator viter = vtxbegin_end.first; viter != vtxbegin_end.second; ++viter)
49  {
53  const auto distepsilon = 0.0001;
54  const auto timeepsilon = 0.0001;
55  auto xlist = {1.0, std::abs(newvtx->get_x()), std::abs(viter->second->get_x())};
56  auto ylist = {1.0, std::abs(newvtx->get_y()), std::abs(viter->second->get_y())};
57  auto zlist = {1.0, std::abs(newvtx->get_z()), std::abs(viter->second->get_z())};
58  auto tlist = {1.0, std::abs(newvtx->get_t()), std::abs(viter->second->get_t())};
59 
60  bool xcomp = std::abs(newvtx->get_x() - viter->second->get_x())
61  <= distepsilon * (*std::max_element(xlist.begin(), xlist.end()));
62  bool ycomp = std::abs(newvtx->get_y() - viter->second->get_y())
63  <= distepsilon * (*std::max_element(ylist.begin(), ylist.end()));
64  bool zcomp = std::abs(newvtx->get_z() - viter->second->get_z())
65  <= distepsilon * (*std::max_element(zlist.begin(), zlist.end()));
66  bool tcomp = std::abs(newvtx->get_t() - viter->second->get_t())
67  <= timeepsilon * (*std::max_element(tlist.begin(), tlist.end()));
68 
69  if (*newvtx == *(viter->second) or
70  (xcomp and ycomp and zcomp and tcomp) )
71  {
72  delete newvtx;
73  return viter->first;
74  }
75  }
76  int id = GetNVtx()+1;
77  vtxlist[id]=newvtx;
78  return id;
79 }
80 
81 int
83 {
84  if (vtxlist.find(vtxid) == vtxlist.end())
85  {
86  cout << "cannot add particle to non existing vertex, id: " << vtxid << endl;
87  exit(1);
88  }
89  // checking for duplicate particles - sometimes interesting
90  // std::pair< std::multimap<int,PHG4Particle *>::const_iterator, std::multimap<int,PHG4Particle *>::const_iterator > particles = GetParticles(vtxid);
91 
92 // for (multimap<int,PHG4Particle *>::const_iterator piter = particles.first; piter != particles.second; piter++)
93 // {
94 // if (*particle == *(piter->second))
95 // {
96 // cout << PHWHERE << "Particle already added (same pid and momentum), dropping it since duplication will cause problems down the line particle:" << endl;
97 // particle->identify();
98 // delete particle;
99 // return -1;
100 // }
101 // }
102  particlelist.insert(pair<int,PHG4Particle *>(vtxid, particle) );
103  return 0;
104 }
105 
106 void
108 {
109  embedded_particlelist.clear(); // just pointers - we can clear it without deleting
110  while(vtxlist.begin() != vtxlist.end())
111  {
112  delete vtxlist.begin()->second;
113  vtxlist.erase(vtxlist.begin());
114  }
115  while(particlelist.begin() != particlelist.end())
116  {
117  delete particlelist.begin()->second;
118  particlelist.erase(particlelist.begin());
119  }
120  return;
121 }
122 
123 pair< map<int, PHG4VtxPoint *>::const_iterator, map<int, PHG4VtxPoint *>::const_iterator >
125 {
126  pair< map<int, PHG4VtxPoint *>::const_iterator, map<int, PHG4VtxPoint *>::const_iterator > retpair(vtxlist.begin(), vtxlist.end());
127  return retpair;
128 }
129 
130 
131 pair< multimap<int,PHG4Particle *>::const_iterator, multimap<int,PHG4Particle *>::const_iterator >
132 PHG4InEvent::GetParticles(const int vtxid) const
133 {
134  pair<multimap<int,PHG4Particle *>::const_iterator, multimap<int,PHG4Particle *>::const_iterator > retpair(particlelist.lower_bound(vtxid),particlelist.upper_bound(vtxid));
135  return retpair;
136 }
137 
138 pair< multimap<int,PHG4Particle *>::const_iterator, multimap<int,PHG4Particle *>::const_iterator >
140 {
141  pair<multimap<int,PHG4Particle *>::const_iterator, multimap<int,PHG4Particle *>::const_iterator > retpair(particlelist.begin(),particlelist.end());
142  return retpair;
143 }
144 
145 pair< multimap<int,PHG4Particle *>::iterator, multimap<int,PHG4Particle *>::iterator >
147 {
148  pair<multimap<int,PHG4Particle *>::iterator, multimap<int,PHG4Particle *>::iterator > retpair(particlelist.begin(),particlelist.end());
149  return retpair;
150 }
151 
152 void
153 PHG4InEvent::identify(ostream& os) const
154 {
155  os << "vtx: " << endl;
156  multimap<int,PHG4Particle *>::const_iterator particle_iter;
157  for(map<int,PHG4VtxPoint *>::const_iterator iter = vtxlist.begin(); iter != vtxlist.end(); ++iter)
158  {
159  os << "vtx " << iter->first << " , ";
160  iter->second->identify(os);
161  pair<multimap<int, PHG4Particle *>::const_iterator, multimap<int, PHG4Particle *>::const_iterator > particlebegin_end = GetParticles(iter->first);
162  for(particle_iter = particlebegin_end.first; particle_iter != particlebegin_end.second; ++particle_iter)
163  {
164  os << "vtx " << particle_iter->first << ", ";
165  particle_iter->second->identify(os);
166  }
167  }
168  if (!embedded_particlelist.empty())
169  {
170  os << "embedded particles:" << endl;
171  for (map<PHG4Particle *,int>::const_iterator iter = embedded_particlelist.begin(); iter != embedded_particlelist.end(); ++iter)
172  {
173  (iter->first)->identify(os);
174  }
175  }
176  else
177  {
178  os << "no embedded particles" << endl;
179  }
180  return;
181 }
182 
183 int
185 {
186  std::map<PHG4Particle*,int>::const_iterator iter = embedded_particlelist.find(p);
187  if (iter == embedded_particlelist.end()) {
188  return 0;
189  }
190 
191  return iter->second;
192 }
193 
194 void
195 PHG4InEvent::DeleteParticle(std::multimap<int, PHG4Particle *>::iterator &iter)
196 {
197  delete iter->second;
198  particlelist.erase(iter);
199 }