|
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()));
74 mcEventCollection.push_back(std::move(hepmcEvent));
76 mcEventCollection[mcEventCollection.size()-1].set_run_info(
runinfo);
86 return mcEventCollection;
93 HepMC::GenEvent genEvt;
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;
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;
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.
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....