9 #include <boost/foreach.hpp>
10 #include <boost/tuple/tuple.hpp>
22 particle_embed_flags(),
23 vertex_embed_flags() {
30 for (
Iterator iter = particlemap.begin(); iter != particlemap.end(); ++iter) {
35 for (
VtxIterator iter = vtxmap.begin(); iter != vtxmap.end(); ++iter) {
40 for (
ShowerIterator iter = showermap.begin(); iter != showermap.end(); ++iter) {
45 particle_embed_flags.clear();
46 vertex_embed_flags.clear();
53 cout <<
"---particlemap--------------------------" << endl;
54 for (
ConstIterator iter = particlemap.begin(); iter != particlemap.end(); ++iter) {
55 cout <<
"particle id " << iter->first << endl;
59 cout <<
"---vtxmap-------------------------------" << endl;
61 cout <<
"vtx id: " << vter ->first << endl;
65 cout <<
"---showermap-------------------------------" << endl;
67 cout <<
"shower id: " << ster ->first << endl;
71 cout <<
"---list of embeded track flags-------------------" << endl;
72 for (std::map<int,int>::const_iterator eter = particle_embed_flags.begin();
73 eter != particle_embed_flags.end();
75 cout <<
"embeded track id: " << eter->first
76 <<
" flag: " << eter->second << endl;
79 cout <<
"---list of embeded vtx flags-------------------" << endl;
80 for (std::map<int,int>::const_iterator eter = vertex_embed_flags.begin();
81 eter != vertex_embed_flags.end();
83 cout <<
"embeded vertex id: " << eter->first
84 <<
" flag: " << eter->second << endl;
87 cout <<
"---primary vertex-------------------" << endl;
99 boost::tie(it,added) = particlemap.insert(std::make_pair(key,newparticle));
100 if ( added )
return it;
102 cerr <<
"PHG4TruthInfoContainer::AddParticle"
103 <<
" - Attempt to add particle with existing trackid "
104 << trackid <<
": "<<newparticle ->
get_name()<<
" id "
106 <<
", p = ["<<newparticle->
get_px()
107 <<
", "<<newparticle->
get_py()
108 <<
", "<<newparticle->
get_pz()<<
"], "
111 return particlemap.end();
117 Iterator it = particlemap.find(key);
118 if ( it != particlemap.end() )
return it->second;
124 if (trackid <= 0)
return NULL;
125 Iterator it = particlemap.find(trackid);
126 if ( it != particlemap.end() )
return it->second;
134 if ( it != vtxmap.end() )
return it->second;
140 if (vtxid <= 0)
return NULL;
142 if ( it != vtxmap.end() )
return it->second;
150 if ( it != showermap.end() )
return it->second;
156 if (showerid <= 0)
return NULL;
158 if ( it != showermap.end() )
return it->second;
169 if (vtxmap.find(
id) != vtxmap.end()) {
170 cout <<
"trying to add existing vtx " <<
id
171 <<
" vtx pos: " << endl;
172 (vtxmap.find(
id)->second)->
identify();
176 boost::tie(it,added) = vtxmap.insert(std::make_pair(key,newvtx));
182 cerr <<
"PHG4TruthInfoContainer::AddVertex"
183 <<
" - Attempt to add vertex with existing id " <<
id << std::endl;
194 if (showermap.find(
id) != showermap.end()) {
195 cout <<
"trying to add existing shower " <<
id
196 <<
" shower pos: " << endl;
197 (showermap.find(
id)->second)->
identify();
201 boost::tie(it,added) = showermap.insert(std::make_pair(key,newshower));
207 cerr <<
"PHG4TruthInfoContainer::AddShower"
208 <<
" - Attempt to add shower with existing id " <<
id << std::endl;
209 return showermap.end();
215 if (!particlemap.empty()) key = particlemap.rbegin()->first;
216 if (key < 0) key = 0;
223 if (!particlemap.empty()) key = particlemap.begin()->first;
224 if (key > 0) key = 0;
231 if (!vtxmap.empty()) key = vtxmap.rbegin()->first;
232 if (key < 0) key = 0;
239 if (!vtxmap.empty()) key = vtxmap.begin()->first;
240 if (key > 0) key = 0;
247 if (!showermap.empty()) key = showermap.rbegin()->first;
248 if (key < 0) key = 0;
255 if (!showermap.empty()) key = showermap.begin()->first;
256 if (key > 0) key = 0;
262 delete piter->second;
263 particlemap.erase(piter);
269 delete viter->second;
276 delete siter->second;
277 showermap.erase(siter);
283 std::map<int,int>::const_iterator iter = particle_embed_flags.find(trackid);
284 if (iter == particle_embed_flags.end()) {
293 std::map<int,int>::const_iterator iter = vertex_embed_flags.find(vtxid);
294 if (iter == vertex_embed_flags.end()) {
317 int highest_embedding_ID = numeric_limits<int>::min();
318 int vtx_id_for_highest_embedding_ID = 0;
320 for (
auto iter = vrange.first; iter != vrange.second; ++iter)
326 if (embedding_ID >= highest_embedding_ID)
328 highest_embedding_ID = embedding_ID;
329 vtx_id_for_highest_embedding_ID = iter->first;
333 if (highest_embedding_ID == numeric_limits<int>::min())
335 cout <<
"PHG4TruthInfoContainer::GetPrimaryVertexIndex - "
336 <<
"WARNING: no valid primary vertex. Return an invalid ID of 0"
341 return vtx_id_for_highest_embedding_ID;
virtual int get_track_id() const
virtual int get_parent_id() const
virtual double get_px() const
virtual std::string get_name() const
virtual double get_py() const
virtual double get_pz() const
virtual void set_id(int id)
bool is_primary(const PHG4Particle *p) const
VtxMap::const_iterator ConstVtxIterator
void delete_shower(ShowerIterator piter)
ConstIterator AddParticle(const int particleid, PHG4Particle *newparticle)
Add a particle that the user has created.
int isEmbeded(const int trackid) const
int maxshowerindex() const
VtxRange GetPrimaryVtxRange()
void identify(std::ostream &os=std::cout) const
PHG4VtxPoint * GetVtx(const int vtxid)
ConstShowerIterator AddShower(const int showerid, PHG4Shower *newshower)
Add a shower that the user has created.
void delete_particle(Iterator piter)
Map::const_iterator ConstIterator
int isEmbededVtx(const int vtxid) const
VtxMap::iterator VtxIterator
PHG4Particle * GetPrimaryParticle(const int particleid)
ShowerMap::const_iterator ConstShowerIterator
PHG4Particle * GetParticle(const int particleid)
PHG4Shower * GetShower(const int showerid)
ConstVtxIterator AddVertex(const int vtxid, PHG4VtxPoint *vertex)
Add a vertex and return an iterator to the user.
PHG4Shower * GetPrimaryShower(const int showerid)
int minshowerindex() const
void delete_vtx(VtxIterator viter)
PHG4VtxPoint * GetPrimaryVtx(const int vtxid)
int GetPrimaryVertexIndex() const
ShowerMap::iterator ShowerIterator
bool is_primary_vtx(const PHG4VtxPoint *v) const
virtual ~PHG4TruthInfoContainer()
std::pair< ConstVtxIterator, ConstVtxIterator > ConstVtxRange
virtual int get_id() const
virtual void set_id(const int i)