ATLAS Offline Software
Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRUTHHELPER_GENACCESSIO_H
6 #define TRUTHHELPER_GENACCESSIO_H
7 
11 #include "StoreGate/StoreGateSvc.h"
12 
13 #include <vector>
14 #include <string>
15 
16 typedef std::vector<HepMC::ConstGenParticlePtr> MCParticleCollection;
17 typedef std::vector<HepMC::ConstGenParticlePtr>::const_iterator MCParticleCollectionCIter;
18 
19 namespace TruthHelper {
20 
21 class GenAccessIO {
22 public:
23 
24  GenAccessIO() : m_sgSvc("StoreGateSvc", "GenAccessIO") {
25  if (m_sgSvc.retrieve().isFailure()) {
26  throw StatusCode::FAILURE;
27  }
28  }
29  StatusCode getMC(MCParticleCollection& mcParticles, const bool ifgen=false, const std::string& key="GEN_EVENT") const {
30  MsgStream log(Athena::getMessageSvc(), "GenAccessIO");
31 
32  // Retrieve iterators for McEventCollections objects
35  if ( (m_sgSvc->retrieve(firstMEC, lastMEC)).isFailure() ) {
36  log << MSG::ERROR << "Could not retrieve iterators for McEventCollections" << endmsg;
37  }
38  const McEventCollection& mcColl = *firstMEC;
39  int icount = 0;
40  for ( ; firstMEC!= lastMEC; ++firstMEC) icount++;
41  log << MSG::DEBUG << "Number of McEventCollections= "<< icount << endmsg;
42 
43  // If there is more than one then do the retrieve with the key
44  if (icount > 1) {
45  log << MSG::DEBUG << "Key = " << key << endmsg;
46  const McEventCollection* mcCollptr = nullptr;
47  return this->getDH(mcCollptr, key);
48  }
49 
50  if (icount > 0) {
51  // Iterate over all McEvent records
53  for (itr = mcColl.begin(); itr!=mcColl.end(); ++itr) {
54  // Access the HepMC record which is wrapped within McEvent
55  const HepMC::GenEvent* genEvt = (*itr);
56  if (genEvt == 0) return StatusCode::FAILURE;
57  if (ifgen) {
58  for (auto it: *genEvt) {
59  if (!HepMC::is_simulation_particle(it)) mcParticles.push_back(it);
60  }
61  } else {
62  for (auto it: *genEvt) {
63  mcParticles.push_back(it);
64  }
65  }
66  }
67  }
68  return StatusCode::SUCCESS;
69  }
71  return m_sgSvc->retrieve(dh);
72  }
73  StatusCode getDH(const McEventCollection*& dh, const std::string& key) const {
74  return m_sgSvc->retrieve(dh, key);
75  }
76  StatusCode store (McEventCollection* storee, const std::string& key) const {
77  return m_sgSvc->record(storee, key);
78  }
79 private:
81 };
82 }
83 
84 #endif
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
skel.it
it
Definition: skel.GENtoEVGEN.py:396
PyPoolBrowser.dh
dh
Definition: PyPoolBrowser.py:102
GenParticle.h
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
TruthHelper::GenAccessIO::getDH
StatusCode getDH(const McEventCollection *&dh, const std::string &key) const
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:73
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:355
McEventCollection.h
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TruthHelper::GenAccessIO::getMC
StatusCode getMC(MCParticleCollection &mcParticles, const bool ifgen=false, const std::string &key="GEN_EVENT") const
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:29
TruthHelper::GenAccessIO::getDH
StatusCode getDH(const McEventCollection *&dh) const
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:70
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
TruthHelper
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:19
MCParticleCollectionCIter
std::vector< HepMC::ConstGenParticlePtr >::const_iterator MCParticleCollectionCIter
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:17
TruthHelper::GenAccessIO::m_sgSvc
ServiceHandle< StoreGateSvc > m_sgSvc
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:80
TruthHelper::GenAccessIO
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:21
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TruthHelper::GenAccessIO::store
StatusCode store(McEventCollection *storee, const std::string &key) const
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:76
TruthHelper::GenAccessIO::GenAccessIO
GenAccessIO()
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:24
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MCParticleCollection
std::vector< HepMC::ConstGenParticlePtr > MCParticleCollection
Definition: Generators/FlowAfterburner/FlowAfterburner/GenAccessIO.h:16
StoreGateSvc.h
SG::ConstIterator
Definition: SGIterator.h:163
HepMCHelpers.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
ServiceHandle< StoreGateSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37