ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
TruthParticleID
McParticleTools
src
PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef TRUTHHELPER_GENACCESSIO_H
6
#define TRUTHHELPER_GENACCESSIO_H
7
8
#include "
GeneratorObjects/McEventCollection.h
"
9
#include "
AtlasHepMC/GenParticle.h
"
10
#include "
TruthUtils/HepMCHelpers.h
"
11
12
#include "GaudiKernel/Bootstrap.h"
13
#include "GaudiKernel/ISvcLocator.h"
14
#include "
StoreGate/StoreGateSvc.h
"
15
16
#include <vector>
17
#include <string>
18
19
typedef
std::vector<HepMC::ConstGenParticlePtr>
MCParticleCollection
;
20
typedef
std::vector<HepMC::ConstGenParticlePtr>::const_iterator
MCParticleCollectionCIter
;
21
22
namespace
TruthHelper
{
23
24
class
GenAccessIO {
25
public
:
26
27
GenAccessIO
() {
28
if
(
m_sgSvc
.retrieve().isFailure()) {
29
throw
StatusCode::FAILURE;
30
}
31
}
32
StatusCode
getMC
(
MCParticleCollection
& mcParticles,
const
bool
ifgen=
false
,
const
std::string& key=
"GEN_EVENT"
)
const
{
33
MsgStream log(
Athena::getMessageSvc
(),
"GenAccessIO"
);
34
35
// Retrieve iterators for McEventCollections objects
36
SG::ConstIterator<McEventCollection>
firstMEC;
37
SG::ConstIterator<McEventCollection>
lastMEC;
38
if
( (
m_sgSvc
->retrieve(firstMEC, lastMEC)).isFailure() ) {
39
log << MSG::ERROR <<
"Could not retrieve iterators for McEventCollections"
<<
endmsg
;
40
}
41
const
McEventCollection
& mcColl = *firstMEC;
42
int
icount = 0;
43
for
( ; firstMEC!= lastMEC; ++firstMEC) icount++;
44
log << MSG::DEBUG <<
"Number of McEventCollections= "
<< icount <<
endmsg
;
45
46
// If there is more than one then do the retrieve with the key
47
if
(icount > 1) {
48
log << MSG::DEBUG <<
"Key = "
<< key <<
endmsg
;
49
const
McEventCollection
* mcCollptr =
nullptr
;
50
return
this->
getDH
(mcCollptr, key);
51
}
52
53
if
(icount > 0) {
54
// Iterate over all McEvent records
55
McEventCollection::const_iterator
itr;
56
for
(itr = mcColl.
begin
(); itr!=mcColl.
end
(); ++itr) {
57
// Access the HepMC record which is wrapped within McEvent
58
const
HepMC::GenEvent
* genEvt = (*itr);
59
if
(genEvt == 0)
return
StatusCode::FAILURE;
60
if
(ifgen) {
61
for
(
auto
it: *genEvt) {
62
if
(!
HepMC::is_simulation_particle
(it)) mcParticles.push_back(std::move(it));
63
}
64
}
else
{
65
for
(
auto
it: *genEvt) {
66
mcParticles.push_back(std::move(it));
67
}
68
}
69
}
70
}
71
return
StatusCode::SUCCESS;
72
}
73
StatusCode
getDH
(
const
McEventCollection
*& dh)
const
{
74
return
m_sgSvc
->retrieve(dh);
75
}
76
StatusCode
getDH
(
const
McEventCollection
*& dh,
const
std::string& key)
const
{
77
return
m_sgSvc
->retrieve(dh, key);
78
}
79
StatusCode
store
(
McEventCollection
* storee,
const
std::string& key)
const
{
80
return
m_sgSvc
->record(storee, key);
81
}
82
private
:
83
ServiceHandle<StoreGateSvc>
m_sgSvc
{
"StoreGateSvc"
,
"GenAccessIO"
};
84
};
85
}
86
87
#endif
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
GenParticle.h
MCParticleCollection
std::vector< HepMC::ConstGenParticlePtr > MCParticleCollection
Definition
Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:16
MCParticleCollectionCIter
std::vector< HepMC::ConstGenParticlePtr >::const_iterator MCParticleCollectionCIter
Definition
Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:17
HepMCHelpers.h
ATLAS-specific HepMC functions.
McEventCollection.h
StoreGateSvc.h
DataVector< HepMC::GenEvent >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
Definition
McEventCollection.h:31
SG::ConstIterator
a const_iterator facade to DataHandle.
Definition
SGIterator.h:164
ServiceHandle
Definition
ClusterMakerTool.h:36
TruthHelper::GenAccessIO::getMC
StatusCode getMC(MCParticleCollection &mcParticles, const bool ifgen=false, const std::string &key="GEN_EVENT") const
Definition
PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h:32
TruthHelper::GenAccessIO::m_sgSvc
ServiceHandle< StoreGateSvc > m_sgSvc
Definition
Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:80
TruthHelper::GenAccessIO::getDH
StatusCode getDH(const McEventCollection *&dh, const std::string &key) const
Definition
PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h:76
TruthHelper::GenAccessIO::store
StatusCode store(McEventCollection *storee, const std::string &key) const
Definition
PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h:79
TruthHelper::GenAccessIO::GenAccessIO
GenAccessIO()
Definition
PhysicsAnalysis/TruthParticleID/McParticleTools/src/GenAccessIO.h:27
TruthHelper::GenAccessIO::getDH
StatusCode getDH(const McEventCollection *&dh) const
Definition
Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:70
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition
getMessageSvc.cxx:20
HepMC::is_simulation_particle
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...
Definition
MagicNumbers.h:322
HepMC::GenEvent
HepMC3::GenEvent GenEvent
Definition
GenEvent.h:39
TruthHelper
Definition
CheckFlow_New.h:22
Generated on
for ATLAS Offline Software by
1.17.0