![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
Go to the documentation of this file.
6 #ifndef XAOD_STANDALONE
24 return StatusCode::SUCCESS;
29 ATH_MSG_INFO(
"==============================================================");
30 ATH_MSG_INFO(
"========== xAOD -> HepMC Tool :: Run Summary ==========");
31 ATH_MSG_INFO(
"==============================================================");
35 ATH_MSG_INFO(
" ... check input particle/vertex barcodes.");
52 ATH_MSG_INFO(
"Inconsistencies with the beam particles storage in the event record!");
59 ATH_MSG_INFO(
"==============================================================");
60 ATH_MSG_INFO(
"=================== End Run Summary ===================");
61 ATH_MSG_INFO(
"==============================================================");
62 return StatusCode::SUCCESS;
70 std::vector<HepMC::GenEvent> mcEventCollection;
84 std::shared_ptr<HepMC3::GenRunInfo>
runinfo = std::make_shared<HepMC3::GenRunInfo>(*(hepmcEvent.run_info().get()));
87 mcEventCollection.push_back(std::move(hepmcEvent));
89 mcEventCollection[mcEventCollection.size()-1].set_run_info(
runinfo);
99 return mcEventCollection;
106 HepMC::GenEvent genEvt;
112 genEvt.set_event_number(evtNum);
113 ATH_MSG_DEBUG(
"Start createHepMCEvent for event " << evtNum);
116 #ifndef XAOD_STANDALONE
117 const std::vector<float> weights = xEvt->
weights();
118 std::map<std::string, int> weightNameMap;
123 std::shared_ptr<HepMC3::GenRunInfo>
runinfo = std::make_shared<HepMC3::GenRunInfo>();
125 std::vector<std::string> wnames;
126 wnames.reserve(weights.size());
128 for (
const auto&
it : weightNameMap) {
129 if (
it.second ==
idx) {
130 wnames.push_back(
it.first);
135 genEvt.run_info()->set_weight_names(wnames);
136 for ( std::vector<float>::const_iterator wgt = weights.begin(); wgt != weights.end(); ++wgt ) {
137 genEvt.weights().push_back(*wgt);
140 if (weightNameMap.size()) {
141 HepMC::WeightContainer& wc = genEvt.weights();
144 for (
const auto&
it : weightNameMap) {
145 if (
it.second ==
idx) {
146 wc[
it.first ] = weights[
idx];
153 for ( std::vector<float>::const_iterator wgt = weights.begin(); wgt != weights.end(); ++wgt ) {
154 genEvt.weights().push_back(*wgt);
162 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> vertexMap;
167 if (!tlink.isValid()) {
continue; }
171 if (xPart ==
nullptr) {
172 ATH_MSG_WARNING(
"xAOD TruthParticle is equal to NULL. This should not happen!");
195 hepmcParticle->set_status(2);
203 bool prodVtxSeenBefore(
false);
204 auto hepmcProdVtx =
vertexHelper(xAODProdVtx, vertexMap, prodVtxSeenBefore);
207 hepmcProdVtx->add_particle_out(hepmcParticle);
209 hepmcProdVtx->add_particle_out(hepmcParticle.get());
212 if (!prodVtxSeenBefore) {
213 genEvt.add_vertex(hepmcProdVtx);
235 if (xPart->
hasProdVtx()) { (void)hepmcParticle.release(); }
239 bool decayVtxSeenBefore(
false);
240 auto hepmcDecayVtx =
vertexHelper(xAODDecayVtx, vertexMap, decayVtxSeenBefore);
243 hepmcDecayVtx->add_particle_in(hepmcParticle);
245 hepmcDecayVtx->add_particle_in(hepmcParticle.get());
248 if (!decayVtxSeenBefore) {
249 genEvt.add_vertex(hepmcDecayVtx);
258 ATH_MSG_DEBUG(
"suggest_barcode failed for particle " << bcpart);
265 (void)hepmcParticle.release();
276 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> &vertexMap,
277 bool &seenBefore)
const
282 vMapItr = vertexMap.find(xaodVertex);
284 if (vMapItr != vertexMap.end()) {
286 hepmcVertex = (*vMapItr).second;
292 hepmcVertex = vertexMap[xaodVertex];
306 return hepmcParticle;
324 std::vector<int> uidPars;
325 std::vector<int> uidKids;
329 std::cout <<
"======================================================================================" << std::endl;
330 std::cout <<
"xAODTruth Event " << evtNum << std::endl;
331 std::cout <<
" UniqueID PDG Id Status px(GeV) py(GeV) pz(GeV) E(GeV) Parent: Decay" << std::endl;
332 std::cout <<
" -----------------------------------------------------------------------------------" << std::endl;
334 int nPart =
event->nTruthParticles();
335 for (
int i = 0;
i < nPart; ++
i)
338 if (
part ==
nullptr)
continue;
340 int id =
part->pdgId();
341 if (
id != 25)
continue;
343 float px =
part->px() / 1000.;
344 float py =
part->py() / 1000.;
345 float pz =
part->pz() / 1000.;
346 float e =
part->e() / 1000.;
350 if (
part->hasProdVtx())
357 if (
part->hasDecayVtx())
365 << std::setw(8) <<
stat
366 << std::setprecision(2) << std::fixed
367 << std::setw(10) <<
px << std::setw(10) <<
py
368 << std::setw(10) <<
pz << std::setw(10) <<
e <<
" ";
370 for (
unsigned int k = 0;
k < uidPars.size(); ++
k)
372 std::cout << uidPars[
k] <<
" ";
375 for (
unsigned int k = 0;
k < uidKids.size(); ++
k)
377 std::cout << uidKids[
k] <<
" ";
379 std::cout << std::endl;
381 std::cout <<
"======================================================================================" << std::endl;
HepMC::GenVertex * GenVertexPtr
JetConstituentVector::iterator iterator
bool suggest_barcode(T &p, int i)
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
uint64_t eventNumber() const
The current event's event number.
GenParticle * GenParticlePtr
#define ATH_MSG_VERBOSE(x)
void line(std::ostream &os, const GenEvent &e)
bool hasDecayVtx() const
Check for a decay vertex on this particle.
constexpr int SPECIALSTATUS
Constant that the meaning of which is currently lost, to be recovered...
POOL::TEvent event(POOL::TEvent::kClassAccess)
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...
GenVertexPtr newGenVertexPtr(const HepMC::FourVector &pos=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), const int i=0)
::StatusCode StatusCode
StatusCode definition for legacy code.
Class describing a truth particle in the MC record.
bool hasProdVtx() const
Check for a production vertex on this particle.
Class describing a signal truth event in the MC record.
bool is_simulation_vertex(const T &v)
Method to establish if the vertex was created during simulation (TODO migrate to be based on status).
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
const std::vector< float > & weights() const
Const access to the weights vector.
const TruthVertex_v1 * prodVtx() const
The production vertex of this particle.
Class describing a truth vertex in the MC record.
Class describing the basic event information.
GenParticlePtr newGenParticlePtr(const HepMC::FourVector &mom=HepMC::FourVector(0.0, 0.0, 0.0, 0.0), int pid=0, int status=0)
#define ATH_MSG_WARNING(x)
const TruthParticleLinks_t & truthParticleLinks() const
Get all the truth particles.
int generations(const T &p)
Method to return how many interactions a particle has undergone during simulation (TODO migrate to be...
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....