6 #ifndef XAOD_STANDALONE
20 return StatusCode::SUCCESS;
25 ATH_MSG_INFO(
"==============================================================");
26 ATH_MSG_INFO(
"========== xAOD -> HepMC Tool :: Run Summary ==========");
27 ATH_MSG_INFO(
"==============================================================");
39 ATH_MSG_INFO(
"Inconsistencies with the beam particles storage in the event record!");
46 ATH_MSG_INFO(
"==============================================================");
47 ATH_MSG_INFO(
"=================== End Run Summary ===================");
48 ATH_MSG_INFO(
"==============================================================");
49 return StatusCode::SUCCESS;
57 std::vector<HepMC::GenEvent> mcEventCollection;
71 std::shared_ptr<HepMC3::GenRunInfo>
runinfo = std::make_shared<HepMC3::GenRunInfo>(*(hepmcEvent.run_info().get()));
74 mcEventCollection.push_back(std::move(hepmcEvent));
76 mcEventCollection[mcEventCollection.size()-1].set_run_info(
runinfo);
86 return mcEventCollection;
93 HepMC::GenEvent genEvt;
98 long long int evtNum = eventInfo->eventNumber();
99 genEvt.set_event_number(evtNum);
100 ATH_MSG_DEBUG(
"Start createHepMCEvent for event " << evtNum);
103 #ifndef XAOD_STANDALONE
105 std::map<std::string, int> weightNameMap;
110 std::shared_ptr<HepMC3::GenRunInfo>
runinfo = std::make_shared<HepMC3::GenRunInfo>();
112 std::vector<std::string> wnames;
113 wnames.reserve(
weights.size());
115 for (
const auto&
it : weightNameMap) {
116 if (
it.second ==
idx) {
117 wnames.push_back(
it.first);
122 genEvt.run_info()->set_weight_names(wnames);
123 for ( std::vector<float>::const_iterator wgt =
weights.begin(); wgt !=
weights.end(); ++wgt ) {
124 genEvt.weights().push_back(*wgt);
127 if (weightNameMap.size()) {
128 HepMC::WeightContainer& wc = genEvt.weights();
131 for (
const auto&
it : weightNameMap) {
132 if (
it.second ==
idx) {
140 for ( std::vector<float>::const_iterator wgt =
weights.begin(); wgt !=
weights.end(); ++wgt ) {
141 genEvt.weights().push_back(*wgt);
149 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> vertexMap;
153 if (!tlink.isValid()) {
continue; }
157 if (xPart ==
nullptr) {
158 ATH_MSG_WARNING(
"xAOD TruthParticle is equal to NULL. This should not happen!");
184 bool prodVtxSeenBefore(
false);
185 auto hepmcProdVtx =
vertexHelper(xAODProdVtx, vertexMap, prodVtxSeenBefore);
188 hepmcProdVtx->add_particle_out(hepmcParticle);
190 hepmcProdVtx->add_particle_out(hepmcParticle.get());
193 if (!prodVtxSeenBefore) {
194 genEvt.add_vertex(hepmcProdVtx);
216 if (xPart->
hasProdVtx()) { (void)hepmcParticle.release(); }
220 bool decayVtxSeenBefore(
false);
221 auto hepmcDecayVtx =
vertexHelper(xAODDecayVtx, vertexMap, decayVtxSeenBefore);
224 hepmcDecayVtx->add_particle_in(hepmcParticle);
226 hepmcDecayVtx->add_particle_in(hepmcParticle.get());
229 if (!decayVtxSeenBefore) {
230 genEvt.add_vertex(hepmcDecayVtx);
239 ATH_MSG_DEBUG(
"suggest_barcode failed for particle " << bcpart);
246 (void)hepmcParticle.release();
257 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> &vertexMap,
258 bool &seenBefore)
const
263 vMapItr = vertexMap.find(xaodVertex);
265 if (vMapItr != vertexMap.end()) {
267 hepmcVertex = (*vMapItr).second;
273 hepmcVertex = vertexMap[xaodVertex];
286 return hepmcParticle;
303 std::vector<int> uidPars;
304 std::vector<int> uidKids;
306 long long int evtNum = eventInfo->eventNumber();
308 std::cout <<
"======================================================================================" << std::endl;
309 std::cout <<
"xAODTruth Event " << evtNum << std::endl;
310 std::cout <<
" UniqueID PDG Id Status px(GeV) py(GeV) pz(GeV) E(GeV) Parent: Decay" << std::endl;
311 std::cout <<
" -----------------------------------------------------------------------------------" << std::endl;
313 int nPart =
event->nTruthParticles();
314 for (
int i = 0;
i < nPart; ++
i)
317 if (
part ==
nullptr)
continue;
319 int id =
part->pdgId();
320 if (
id != 25)
continue;
322 float px =
part->px() / 1000.;
323 float py =
part->py() / 1000.;
324 float pz =
part->pz() / 1000.;
325 float e =
part->e() / 1000.;
329 if (
part->hasProdVtx())
336 if (
part->hasDecayVtx())
344 << std::setw(8) <<
stat
345 << std::setprecision(2) << std::fixed
346 << std::setw(10) <<
px << std::setw(10) <<
py
347 << std::setw(10) <<
pz << std::setw(10) <<
e <<
" ";
349 for (
unsigned int k = 0;
k < uidPars.size(); ++
k)
351 std::cout << uidPars[
k] <<
" ";
354 for (
unsigned int k = 0;
k < uidKids.size(); ++
k)
356 std::cout << uidKids[
k] <<
" ";
358 std::cout << std::endl;
360 std::cout <<
"======================================================================================" << std::endl;