ATLAS Offline Software
WriteHepMC.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "TruthIO/WriteHepMC.h"
6 #ifdef HEPMC3
7 #include "HepMC3/WriterAscii.h"
8 #endif
9 
10 WriteHepMC::WriteHepMC(const std::string& name, ISvcLocator* pSvcLocator)
11  : GenBase(name, pSvcLocator)
12 {
13  declareProperty("OutputFile", m_outfile="events.hepmc");
14  declareProperty("Precision", m_precision=8);
15  declareProperty("Format", m_format="hepmc2");
16 }
17 
18 
21 #ifdef HEPMC3
22  if (m_format == "hepmc2") {
23  auto writer = new HepMC3::WriterAsciiHepMC2(m_outfile);
24  writer->set_precision(m_precision);
25  m_hepmcio.reset(writer);
26  }
27  if (m_format == "hepmc3") {
28  auto writer = new HepMC3::WriterAscii(m_outfile);
29  writer->set_precision(m_precision);
30  m_hepmcio.reset(writer);
31  }
32 #else
33  m_hepmcio.reset( new HepMC::IO_GenEvent(m_outfile) );
34  m_hepmcio->precision(m_precision);
35 #endif
36  return StatusCode::SUCCESS;
37 }
38 
39 
41  // Just write out the first (i.e. signal) event in the collection
42 #ifdef HEPMC3
43  m_hepmcio->write_event(*(event_const()));
44 #else
45  m_hepmcio->write_event(event_const());
46 #endif
47  return StatusCode::SUCCESS;
48 }
WriteHepMC::m_outfile
std::string m_outfile
Definition: WriteHepMC.h:21
WriteHepMC::m_format
std::string m_format
Definition: WriteHepMC.h:23
WriteHepMC::m_hepmcio
std::unique_ptr< HepMC::IO_GenEvent > m_hepmcio
Definition: WriteHepMC.h:28
WriteHepMC::m_precision
int m_precision
Definition: WriteHepMC.h:22
GenBase
Base class for common behaviour of MC truth algorithms.
Definition: GenBase.h:47
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
WriteHepMC::WriteHepMC
WriteHepMC(const std::string &name, ISvcLocator *pSvcLocator)
Definition: WriteHepMC.cxx:10
WriteHepMC::initialize
StatusCode initialize()
Definition: WriteHepMC.cxx:19
WriteHepMC::execute
StatusCode execute()
Definition: WriteHepMC.cxx:40
WriteHepMC.h
example.writer
writer
show summary of content
Definition: example.py:36
GenBase::initialize
virtual StatusCode initialize() override
Definition: GenBase.cxx:17
GenBase::event_const
const HepMC::GenEvent * event_const() const
Access the current signal event (const)
Definition: GenBase.h:83