18 ATH_MSG_INFO(
"Initializing xAODtoHepMCTool " << name() <<
"...");
20 return StatusCode::SUCCESS;
23StatusCode xAODtoHepMCTool ::finalize()
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;
70 std::shared_ptr<HepMC3::GenRunInfo> runinfo = std::make_shared<HepMC3::GenRunInfo>(*(hepmcEvent.run_info().get()));
74 HepMC::Print::line(std::cout, hepmcEvent);
77 mcEventCollection.push_back(std::move(hepmcEvent));
78 mcEventCollection[mcEventCollection.size()-1].set_run_info(std::move(runinfo));
83 return mcEventCollection;
91 genEvt.set_units(HepMC3::Units::MEV, HepMC3::Units::MM);
94 genEvt.set_event_number(evtNum);
98 #ifndef XAOD_STANDALONE
100 std::map<std::string, int> weightNameMap;
104 std::shared_ptr<HepMC3::GenRunInfo> runinfo = std::make_shared<HepMC3::GenRunInfo>();
105 genEvt.set_run_info(std::move(runinfo));
106 std::vector<std::string> wnames;
107 wnames.reserve(
weights.size());
108 for (
int idx = 0; idx < int(
weights.size()); ++idx) {
109 for (
const auto& it : weightNameMap) {
110 if (it.second == idx) {
111 wnames.push_back(it.first);
116 genEvt.run_info()->set_weight_names(wnames);
117 for ( std::vector<float>::const_iterator wgt =
weights.begin(); wgt !=
weights.end(); ++wgt ) {
118 genEvt.weights().push_back(*wgt);
124 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> vertexMap;
128 if (!tlink.isValid()) {
continue; }
132 if (xPart ==
nullptr) {
133 ATH_MSG_WARNING(
"xAOD TruthParticle is equal to NULL. This should not happen!");
154 bool prodVtxSeenBefore(
false);
155 auto hepmcProdVtx =
vertexHelper(xAODProdVtx, vertexMap, prodVtxSeenBefore);
157 hepmcProdVtx->add_particle_out(hepmcParticle);
159 if (!prodVtxSeenBefore) {
160 genEvt.add_vertex(std::move(hepmcProdVtx));
174 bool decayVtxSeenBefore(
false);
175 auto hepmcDecayVtx =
vertexHelper(xAODDecayVtx, vertexMap, decayVtxSeenBefore);
177 hepmcDecayVtx->add_particle_in(std::move(hepmcParticle));
179 if (!decayVtxSeenBefore) {
180 genEvt.add_vertex(std::move(hepmcDecayVtx));
192 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> &vertexMap,
193 bool &seenBefore)
const
197 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr>::iterator vMapItr;
198 vMapItr = vertexMap.find(xaodVertex);
200 if (vMapItr != vertexMap.end()) {
202 hepmcVertex = (*vMapItr).second;
208 hepmcVertex = vertexMap[xaodVertex];
220 hepmcParticle->set_generated_mass(
m_momFac * particle->m());
221 return hepmcParticle;
238 std::vector<int> uidPars;
239 std::vector<int> uidKids;
243 std::cout <<
"======================================================================================" << std::endl;
244 std::cout <<
"xAODTruth Event " << evtNum << std::endl;
245 std::cout <<
" UniqueID PDG Id Status px(GeV) py(GeV) pz(GeV) E(GeV) Parent: Decay" << std::endl;
246 std::cout <<
" -----------------------------------------------------------------------------------" << std::endl;
248 int nPart =
event->nTruthParticles();
249 std::ios oldState(
nullptr);
250 oldState.copyfmt(std::cout);
251 for (
int i = 0; i < nPart; ++i)
254 if (part ==
nullptr)
continue;
256 int id = part->pdgId();
257 if (
id != 25)
continue;
258 int stat = part->status();
259 float px = part->px() / 1000.;
260 float py = part->py() / 1000.;
261 float pz = part->pz() / 1000.;
262 float e = part->e() / 1000.;
266 if (part->hasProdVtx())
273 if (part->hasDecayVtx())
281 std::cout << std::setw(10) <<
HepMC::uniqueID(part) << std::setw(12) <<
id
282 << std::setw(8) << stat
283 << std::setprecision(2) << std::fixed
284 << std::setw(10) << px << std::setw(10) << py
285 << std::setw(10) << pz << std::setw(10) << e <<
" ";
287 for (
unsigned int k = 0; k < uidPars.size(); ++k)
289 std::cout << uidPars[k] <<
" ";
292 for (
unsigned int k = 0; k < uidKids.size(); ++k)
294 std::cout << uidKids[k] <<
" ";
296 std::cout << std::endl;
298 std::cout <<
"======================================================================================" << std::endl;
299 std::cout.copyfmt(oldState);
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
static std::string retrieveMetadata(const std::string &folder, const std::string &key, const ServiceHandle< StoreGateSvc > &inputMetaStore)
method that always returns as a string you can use from, e.g, pyROOT with evt = ROOT....
uint64_t eventNumber() const
The current event's event number.
const TruthParticleLinks_t & truthParticleLinks() const
Get all the truth particles.
const std::vector< float > & weights() const
Const access to the weights vector.
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
bool hasProdVtx() const
Check for a production vertex on this particle.
bool hasDecayVtx() const
Check for a decay vertex on this particle.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (TODO migrate to be based on status).
HepMC3::FourVector FourVector
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
HepMC3::GenParticlePtr GenParticlePtr
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
HepMC3::GenVertexPtr GenVertexPtr
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
HepMC3::GenEvent GenEvent
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
EventInfo_v1 EventInfo
Definition of the latest event info version.
TruthVertex_v1 TruthVertex
Typedef to implementation.
TruthEvent_v1 TruthEvent
Typedef to implementation.
TruthParticle_v1 TruthParticle
Typedef to implementation.