 |
ATLAS Offline Software
|
Go to the documentation of this file.
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()));
79 mcEventCollection.push_back(std::move(hepmcEvent));
81 mcEventCollection[mcEventCollection.size()-1].set_run_info(
runinfo);
87 return mcEventCollection;
94 HepMC::GenEvent genEvt;
100 genEvt.set_event_number(evtNum);
101 ATH_MSG_DEBUG(
"Start createHepMCEvent for event " << evtNum);
104 #ifndef XAOD_STANDALONE
106 std::map<std::string, int> weightNameMap;
111 std::shared_ptr<HepMC3::GenRunInfo>
runinfo = std::make_shared<HepMC3::GenRunInfo>();
113 std::vector<std::string> wnames;
114 wnames.reserve(
weights.size());
116 for (
const auto&
it : weightNameMap) {
117 if (
it.second ==
idx) {
118 wnames.push_back(
it.first);
123 genEvt.run_info()->set_weight_names(wnames);
124 for ( std::vector<float>::const_iterator wgt =
weights.begin(); wgt !=
weights.end(); ++wgt ) {
125 genEvt.weights().push_back(*wgt);
128 if (weightNameMap.size()) {
129 HepMC::WeightContainer& wc = genEvt.weights();
132 for (
const auto&
it : weightNameMap) {
133 if (
it.second ==
idx) {
141 for ( std::vector<float>::const_iterator wgt =
weights.begin(); wgt !=
weights.end(); ++wgt ) {
142 genEvt.weights().push_back(*wgt);
150 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> vertexMap;
154 if (!tlink.isValid()) {
continue; }
158 if (xPart ==
nullptr) {
159 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);
207 if (xPart->
hasProdVtx()) { (void)hepmcParticle.release(); }
211 bool decayVtxSeenBefore(
false);
212 auto hepmcDecayVtx =
vertexHelper(xAODDecayVtx, vertexMap, decayVtxSeenBefore);
215 hepmcDecayVtx->add_particle_in(hepmcParticle);
217 hepmcDecayVtx->add_particle_in(hepmcParticle.get());
220 if (!decayVtxSeenBefore) {
221 genEvt.add_vertex(hepmcDecayVtx);
225 (void)hepmcParticle.release();
236 std::map<const xAOD::TruthVertex *, HepMC::GenVertexPtr> &vertexMap,
237 bool &seenBefore)
const
242 vMapItr = vertexMap.find(xaodVertex);
244 if (vMapItr != vertexMap.end()) {
246 hepmcVertex = (*vMapItr).second;
252 hepmcVertex = vertexMap[xaodVertex];
265 return hepmcParticle;
282 std::vector<int> uidPars;
283 std::vector<int> uidKids;
287 std::cout <<
"======================================================================================" << std::endl;
288 std::cout <<
"xAODTruth Event " << evtNum << std::endl;
289 std::cout <<
" UniqueID PDG Id Status px(GeV) py(GeV) pz(GeV) E(GeV) Parent: Decay" << std::endl;
290 std::cout <<
" -----------------------------------------------------------------------------------" << std::endl;
292 int nPart =
event->nTruthParticles();
293 for (
int i = 0;
i < nPart; ++
i)
296 if (
part ==
nullptr)
continue;
298 int id =
part->pdgId();
299 if (
id != 25)
continue;
301 float px =
part->px() / 1000.;
302 float py =
part->py() / 1000.;
303 float pz =
part->pz() / 1000.;
304 float e =
part->e() / 1000.;
308 if (
part->hasProdVtx())
315 if (
part->hasDecayVtx())
323 << std::setw(8) <<
stat
324 << std::setprecision(2) << std::fixed
325 << std::setw(10) <<
px << std::setw(10) <<
py
326 << std::setw(10) <<
pz << std::setw(10) <<
e <<
" ";
328 for (
unsigned int k = 0;
k < uidPars.size(); ++
k)
330 std::cout << uidPars[
k] <<
" ";
333 for (
unsigned int k = 0;
k < uidKids.size(); ++
k)
335 std::cout << uidKids[
k] <<
" ";
337 std::cout << std::endl;
339 std::cout <<
"======================================================================================" << std::endl;
HepMC::GenVertex * GenVertexPtr
JetConstituentVector::iterator iterator
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.
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....