ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
TruthIO
src
HepMCReadFromFile.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/HepMCReadFromFile.h
"
6
#include "
GeneratorObjects/McEventCollection.h
"
7
#include "
AtlasHepMC/GenEvent.h
"
8
#include "
AtlasHepMC/HEPEVT_Wrapper.h
"
9
#include "
AtlasHepMC/GenCrossSection.h
"
10
#include "
AtlasHepMC/ReaderFactory.h
"
11
#include "GaudiKernel/DataSvc.h"
12
13
#include "
StoreGate/StoreGateSvc.h
"
14
15
16
HepMCReadFromFile::HepMCReadFromFile
(
const
std::string& name, ISvcLocator* pSvcLocator) :
17
GenBase
(name, pSvcLocator)
18
{
19
declareProperty
(
"InputFile"
,
m_input_file
=
"events.hepmc"
);
20
m_event_number
= 0;
21
m_sum_xs
= 0;
22
}
23
24
25
StatusCode
HepMCReadFromFile::initialize
() {
26
CHECK
(
GenBase::initialize
());
27
28
// Initialize input file and event number
29
m_hepmcio
= HepMC3::deduce_reader(
m_input_file
);
30
m_event_number
= 0;
31
return
StatusCode::SUCCESS;
32
}
33
34
35
StatusCode
HepMCReadFromFile::execute
(
const
EventContext&
/*ctx*/
) {
36
37
McEventCollection
* mcEvtColl =
nullptr
;
38
39
if
(
evtStore
()->
contains<McEventCollection>
(
m_mcEventKey
) &&
evtStore
()->retrieve(mcEvtColl,
m_mcEventKey
).isSuccess() ) {
40
if
(
msgLvl
(MSG::VERBOSE))
msg
(MSG::VERBOSE) <<
"found an McEventCollecion in store"
<<
endmsg
;
41
}
else
{
42
// McCollection doesn't exist. Create it (empty)
43
if
(
msgLvl
(MSG::VERBOSE))
msg
(MSG::VERBOSE) <<
"create new McEventCollecion in store"
<<
endmsg
;
44
mcEvtColl =
new
McEventCollection
;
45
StatusCode status =
evtStore
()->record( mcEvtColl,
m_mcEventKey
);
46
if
(status.isFailure()) {
47
msg
(MSG::ERROR) <<
"Could not record McEventCollection"
<<
endmsg
;
48
return
status;
49
}
50
}
51
HepMC3::GenEvent* evt =
new
HepMC3::GenEvent();
52
if
(
m_hepmcio
) {
53
m_hepmcio
->read_event(*evt);
54
if
(!evt->run_info()) evt->set_run_info(
m_hepmcio
->run_info());
55
++
m_event_number
;
56
evt->set_event_number(
m_event_number
);
57
evt->set_units(HepMC3::Units::MEV, HepMC3::Units::MM);
58
mcEvtColl->
push_back
(evt);
59
const
auto
cs = evt->cross_section();
60
double
xs = 0;
61
if
( cs ){
62
xs=cs->xsec();
63
}
64
m_sum_xs
=
m_sum_xs
+xs;
65
66
}
67
return
StatusCode::SUCCESS;
68
}
69
70
StatusCode
HepMCReadFromFile::finalize
() {
71
72
if
(
m_sum_xs
>0) std::cout <<
"MetaData: cross-section (nb)= "
<<
m_sum_xs
/(1000*
m_event_number
) <<std::endl;
73
74
return
StatusCode::SUCCESS;
75
}
76
77
78
79
80
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition
Control/AthenaKernel/AthenaKernel/errorcheck.h:422
GenCrossSection.h
GenEvent.h
HEPEVT_Wrapper.h
HepMCReadFromFile.h
McEventCollection.h
ReaderFactory.h
StoreGateSvc.h
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
AthCommonAlgorithm< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition
AthCommonMsg.h:30
AthCommonAlgorithm< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
GenBase::m_mcEventKey
std::string m_mcEventKey
StoreGate key for the MC event collection (defaults to GEN_EVENT).
Definition
GenBase.h:108
GenBase::initialize
virtual StatusCode initialize() override
Definition
GenBase.cxx:17
GenBase::GenBase
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
GenBase.cxx:11
HepMCReadFromFile::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
HepMCReadFromFile.cxx:35
HepMCReadFromFile::finalize
virtual StatusCode finalize() override
Definition
HepMCReadFromFile.cxx:70
HepMCReadFromFile::m_sum_xs
double m_sum_xs
Definition
HepMCReadFromFile.h:26
HepMCReadFromFile::HepMCReadFromFile
HepMCReadFromFile(const std::string &name, ISvcLocator *pSvcLocator)
Definition
HepMCReadFromFile.cxx:16
HepMCReadFromFile::m_hepmcio
std::shared_ptr< HepMC3::Reader > m_hepmcio
Definition
HepMCReadFromFile.h:28
HepMCReadFromFile::m_input_file
std::string m_input_file
Definition
HepMCReadFromFile.h:24
HepMCReadFromFile::m_event_number
int m_event_number
Definition
HepMCReadFromFile.h:25
HepMCReadFromFile::initialize
virtual StatusCode initialize() override
Definition
HepMCReadFromFile.cxx:25
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Definition
McEventCollection.h:31
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
Generated on
for ATLAS Offline Software by
1.17.0