30 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
32 #include <HepMC/GenEvent.h>
33 #pragma GCC diagnostic pop
52 using ContainerMap = std::map<std::string, PHG4HitContainer *>;
55 const ContainerMap &containers()
const
65 if (node->
getType() !=
"PHIODataNode")
return;
72 m_containers.insert(std::make_pair(node->
getName(),
data));
78 ContainerMap m_containers;
87 m_geneventmap = findNode::getClass<PHHepMCGenEventMap>(dstNode,
"PHHepMCGenEventMap");
90 std::cout <<
"Fun4AllDstPileupMerger::load_nodes - creating PHHepMCGenEventMap" << std::endl;
96 FindG4HitContainer nodeFinder;
101 m_g4truthinfo = findNode::getClass<PHG4TruthInfoContainer>(dstNode,
"G4TruthInfo");
104 std::cout <<
"Fun4AllDstPileupMerger::load_nodes - creating node G4TruthInfo" << std::endl;
114 const auto map = findNode::getClass<PHHepMCGenEventMap>(dstNode,
"PHHepMCGenEventMap");
117 int new_embed_id = -1;
121 if (map->size() != 1)
123 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - cannot merge events that contain more than one PHHepMCGenEventMap" << std::endl;
128 auto genevent = map->get_map().begin()->second;
139 newevent->moveVertex(0, 0, 0, delta_t);
140 new_embed_id = newevent->get_embedding_id();
145 using ConversionMap = std::map<int, int>;
146 ConversionMap vtxid_map;
147 ConversionMap trkid_map;
149 const auto container_truth = findNode::getClass<PHG4TruthInfoContainer>(dstNode,
"G4TruthInfo");
155 const auto range = container_truth->GetPrimaryVtxRange();
156 for (
auto iter = range.first; iter != range.second; ++iter)
159 const auto &sourceVertex = iter->second;
160 auto newVertex =
new PHG4VtxPoint_t(sourceVertex);
161 newVertex->set_t(sourceVertex->get_t() + delta_t);
163 vtxid_map.insert(std::make_pair(sourceVertex->get_id(), key));
170 const auto range = container_truth->GetSecondaryVtxRange();
174 auto iter = std::reverse_iterator<PHG4TruthInfoContainer::ConstVtxIterator>(range.second);
175 iter != std::reverse_iterator<PHG4TruthInfoContainer::ConstVtxIterator>(range.first);
179 const auto &sourceVertex = iter->second;
180 auto newVertex =
new PHG4VtxPoint_t(sourceVertex);
181 newVertex->set_t(sourceVertex->get_t() + delta_t);
183 vtxid_map.insert(std::make_pair(sourceVertex->get_id(), key));
190 const auto range = container_truth->GetPrimaryParticleRange();
191 for (
auto iter = range.first; iter != range.second; ++iter)
193 const auto &
source = iter->second;
196 dest->set_track_id(key);
199 dest->set_parent_id(0);
202 dest->set_primary_id(
dest->get_track_id());
205 const auto keyiter = vtxid_map.find(
source->get_vtx_id());
206 if (keyiter != vtxid_map.end())
207 dest->set_vtx_id(keyiter->second);
209 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - vertex id " <<
source->get_vtx_id() <<
" not found in map" << std::endl;
212 trkid_map.insert(std::make_pair(
source->get_track_id(),
dest->get_track_id()));
219 const auto range = container_truth->GetSecondaryParticleRange();
226 auto iter = std::reverse_iterator<PHG4TruthInfoContainer::ConstIterator>(range.second);
227 iter != std::reverse_iterator<PHG4TruthInfoContainer::ConstIterator>(range.first);
230 const auto &
source = iter->second;
233 dest->set_track_id(key);
236 auto keyiter = trkid_map.find(
source->get_parent_id());
237 if (keyiter != trkid_map.end())
238 dest->set_parent_id(keyiter->second);
240 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - track id " <<
source->get_parent_id() <<
" not found in map" << std::endl;
243 keyiter = trkid_map.find(
source->get_primary_id());
244 if (keyiter != trkid_map.end())
245 dest->set_primary_id(keyiter->second);
247 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - track id " <<
source->get_primary_id() <<
" not found in map" << std::endl;
250 keyiter = vtxid_map.find(
source->get_vtx_id());
251 if (keyiter != vtxid_map.end())
252 dest->set_vtx_id(keyiter->second);
254 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - vertex id " <<
source->get_vtx_id() <<
" not found in map" << std::endl;
257 trkid_map.insert(std::make_pair(
source->get_track_id(),
dest->get_track_id()));
263 for (
const auto &pair : vtxid_map)
270 for (
const auto &pair : trkid_map)
283 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - invalid destination container " << pair.first << std::endl;
288 auto container_hit = findNode::getClass<PHG4HitContainer>(dstNode, pair.first);
291 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - invalid source container " << pair.first << std::endl;
298 if (delta_t < detiter->second.first || delta_t > detiter->second.second)
305 const auto range = container_hit->getHits();
306 for (
auto iter = range.first; iter != range.second; ++iter)
309 const auto &sourceHit = iter->second;
310 auto newHit =
new PHG4Hit_t(sourceHit);
313 newHit->set_t(0, sourceHit->get_t(0) + delta_t);
314 newHit->set_t(1, sourceHit->get_t(1) + delta_t);
317 const auto keyiter = trkid_map.find(sourceHit->get_trkid());
318 if (keyiter != trkid_map.end())
319 newHit->set_trkid(keyiter->second);
321 std::cout <<
"Fun4AllDstPileupMerger::copy_background_event - track id " << sourceHit->get_trkid() <<
" not found in map" << std::endl;
328 newHit->set_shower_id(INT_MIN);
334 pair.second->AddHit(newHit->get_detid(), newHit);
340 const auto range = container_hit->getLayers();
341 for (
auto iter = range.first; iter != range.second; ++iter)
343 pair.second->AddLayer(*iter);