30 #include <HepMC/GenEvent.h>
49 using ContainerMap = std::map<std::string, PHG4HitContainer *>;
52 const ContainerMap &containers()
const
62 if (node->
getType() !=
"PHIODataNode")
return;
69 m_containers.insert(std::make_pair(node->
getName(),
data));
75 ContainerMap m_containers;
84 m_geneventmap = findNode::getClass<PHHepMCGenEventMap>(dstNode,
"PHHepMCGenEventMap");
87 std::cout <<
"Fun4AllDstPileupMerger::load_nodes - creating PHHepMCGenEventMap" << std::endl;
93 FindG4HitContainer nodeFinder;
98 m_g4truthinfo = findNode::getClass<PHG4TruthInfoContainer>(dstNode,
"G4TruthInfo");
101 std::cout <<
"Fun4AllDstPileupMerger::load_nodes - creating node G4TruthInfo" << std::endl;
111 const auto map = findNode::getClass<PHHepMCGenEventMap>(dstNode,
"PHHepMCGenEventMap");
114 int new_embed_id = -1;
118 if (map->size() != 1)
120 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - cannot merge events that contain more than one PHHepMCGenEventMap" << std::endl;
125 auto genevent = map->get_map().begin()->second;
136 newevent->moveVertex(0, 0, 0, delta_t);
137 new_embed_id = newevent->get_embedding_id();
142 using ConversionMap = std::map<int, int>;
143 ConversionMap vtxid_map;
144 ConversionMap trkid_map;
146 const auto container_truth = findNode::getClass<PHG4TruthInfoContainer>(dstNode,
"G4TruthInfo");
152 const auto range = container_truth->GetPrimaryVtxRange();
153 for (
auto iter = range.first; iter != range.second; ++iter)
156 const auto &sourceVertex = iter->second;
157 auto newVertex =
new PHG4VtxPoint_t(sourceVertex);
158 newVertex->set_t(sourceVertex->get_t() + delta_t);
160 vtxid_map.insert(std::make_pair(sourceVertex->get_id(), key));
167 const auto range = container_truth->GetSecondaryVtxRange();
171 auto iter = std::reverse_iterator<PHG4TruthInfoContainer::ConstVtxIterator>(range.second);
172 iter != std::reverse_iterator<PHG4TruthInfoContainer::ConstVtxIterator>(range.first);
176 const auto &sourceVertex = iter->second;
177 auto newVertex =
new PHG4VtxPoint_t(sourceVertex);
178 newVertex->set_t(sourceVertex->get_t() + delta_t);
180 vtxid_map.insert(std::make_pair(sourceVertex->get_id(), key));
187 const auto range = container_truth->GetPrimaryParticleRange();
188 for (
auto iter = range.first; iter != range.second; ++iter)
190 const auto &source = iter->second;
191 auto dest =
new PHG4Particle_t(source);
193 dest->set_track_id(key);
196 dest->set_parent_id(0);
199 dest->set_primary_id(dest->get_track_id());
202 const auto keyiter = vtxid_map.find(source->get_vtx_id());
203 if (keyiter != vtxid_map.end())
204 dest->set_vtx_id(keyiter->second);
206 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - vertex id " << source->get_vtx_id() <<
" not found in map" << std::endl;
209 trkid_map.insert(std::make_pair(source->get_track_id(), dest->get_track_id()));
216 const auto range = container_truth->GetSecondaryParticleRange();
223 auto iter = std::reverse_iterator<PHG4TruthInfoContainer::ConstIterator>(range.second);
224 iter != std::reverse_iterator<PHG4TruthInfoContainer::ConstIterator>(range.first);
227 const auto &source = iter->second;
228 auto dest =
new PHG4Particle_t(source);
230 dest->set_track_id(key);
233 auto keyiter = trkid_map.find(source->get_parent_id());
234 if (keyiter != trkid_map.end())
235 dest->set_parent_id(keyiter->second);
237 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - track id " << source->get_parent_id() <<
" not found in map" << std::endl;
240 keyiter = trkid_map.find(source->get_primary_id());
241 if (keyiter != trkid_map.end())
242 dest->set_primary_id(keyiter->second);
244 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - track id " << source->get_primary_id() <<
" not found in map" << std::endl;
247 keyiter = vtxid_map.find(source->get_vtx_id());
248 if (keyiter != vtxid_map.end())
249 dest->set_vtx_id(keyiter->second);
251 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - vertex id " << source->get_vtx_id() <<
" not found in map" << std::endl;
254 trkid_map.insert(std::make_pair(source->get_track_id(), dest->get_track_id()));
260 for (
const auto &pair : vtxid_map)
267 for (
const auto &pair : trkid_map)
280 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - invalid destination container " << pair.first << std::endl;
285 auto container_hit = findNode::getClass<PHG4HitContainer>(dstNode, pair.first);
288 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - invalid source container " << pair.first << std::endl;
294 const auto range = container_hit->getHits();
295 for (
auto iter = range.first; iter != range.second; ++iter)
298 const auto &sourceHit = iter->second;
299 auto newHit =
new PHG4Hit_t(sourceHit);
302 newHit->set_t(0, sourceHit->get_t(0) + delta_t);
303 newHit->set_t(1, sourceHit->get_t(1) + delta_t);
306 const auto keyiter = trkid_map.find(sourceHit->get_trkid());
307 if (keyiter != trkid_map.end())
308 newHit->set_trkid(keyiter->second);
310 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - track id " << sourceHit->get_trkid() <<
" not found in map" << std::endl;
317 newHit->set_shower_id(
INT_MIN);
323 pair.second->AddHit(newHit->get_detid(), newHit);
329 const auto range = container_hit->getLayers();
330 for (
auto iter = range.first; iter != range.second; ++iter)
332 pair.second->AddLayer(*iter);