ATLAS Offline Software
GenBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/ISvcLocator.h"
7 #include "GaudiKernel/DataSvc.h"
8 #include <fstream>
9 
10 
11 GenBase::GenBase(const std::string& name, ISvcLocator* pSvcLocator)
12  : AthAlgorithm(name, pSvcLocator)
13 {
14 }
15 
16 
20 
21  // Get the particle property service
22  ATH_CHECK(m_ppSvc.retrieve());
23  return StatusCode::SUCCESS;
24 }
25 
26 
29  // Make a new MC event collection if necessary
30  McEventCollection* mcevents = nullptr;
31  if (!evtStore()->contains<McEventCollection>(m_mcEventKey) && m_mkMcEvent) {
32  ATH_MSG_DEBUG("Creating new McEventCollection in the event store");
33  mcevents = new McEventCollection();
34  if (evtStore()->record(mcevents, m_mcEventKey).isFailure())
35  ATH_MSG_ERROR("Failed to record a new McEventCollection");
36  }
37  else {
38  const McEventCollection* mecc = 0;
39 
40  if (evtStore()->retrieve (mecc, m_mcEventKey).isFailure())
41  ATH_MSG_ERROR("Failed to retrieve McEventCollection");
42 
43  mcevents = const_cast<McEventCollection*> (&(*mecc));
44  }
45 
46  return mcevents;
47 }
48 
49 
52 #ifdef HEPMC3
53 void GenBase::GeVToMeV(HepMC::GenEvent* evt) { for (auto& p: evt->particles()) { p->set_momentum(p->momentum()*1000); p->set_generated_mass(1000* p->generated_mass());}}
54 void GenBase::MeVToGeV(HepMC::GenEvent* evt) { for (auto& p: evt->particles()) { p->set_momentum(p->momentum()*1.0/1000); p->set_generated_mass(1.0/1000* p->generated_mass());} }
55 void GenBase::cmTomm(HepMC::GenEvent* evt) { for (auto& v: evt->vertices()) v->set_position(v->position()*10);}
56 void GenBase::mmTocm(HepMC::GenEvent* evt) { for (auto& v: evt->vertices()) v->set_position(v->position()*1.0/10);}
57 #else
58 void GenBase::GeVToMeV(HepMC::GenEvent* evt) {
59  for (HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p) {
60  const HepMC::FourVector fv((*p)->momentum().px() * 1000,
61  (*p)->momentum().py() * 1000,
62  (*p)->momentum().pz() * 1000,
63  (*p)->momentum().e() * 1000);
64  (*p)->set_momentum(fv);
65  (*p)->set_generated_mass(1000 * (*p)->generated_mass());
66  }
67 }
68 void GenBase::MeVToGeV(HepMC::GenEvent* evt) {
69  for (HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p) {
70  const HepMC::FourVector fv((*p)->momentum().px() / 1000,
71  (*p)->momentum().py() / 1000,
72  (*p)->momentum().pz() / 1000,
73  (*p)->momentum().e() / 1000);
74  (*p)->set_momentum(fv);
75  (*p)->set_generated_mass((*p)->generated_mass() / 1000);
76  }
77 }
78 void GenBase::cmTomm(HepMC::GenEvent* evt) {
79  for (HepMC::GenEvent::vertex_iterator vtx = evt->vertices_begin(); vtx != evt->vertices_end(); ++vtx) {
80  const HepMC::FourVector fv((*vtx)->position().x() * 10,
81  (*vtx)->position().y() * 10,
82  (*vtx)->position().z() * 10,
83  (*vtx)->position().t() * 10);
84  (*vtx)->set_position(fv);
85  }
86 }
87 void GenBase::mmTocm(HepMC::GenEvent* evt) {
88  for (HepMC::GenEvent::vertex_iterator vtx = evt->vertices_begin(); vtx != evt->vertices_end(); ++vtx) {
89  const HepMC::FourVector fv((*vtx)->position().x() / 10,
90  (*vtx)->position().y() / 10,
91  (*vtx)->position().z() / 10,
92  (*vtx)->position().t() / 10);
93  (*vtx)->set_position(fv);
94  }
95 }
96 #endif
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
GenBase::mmTocm
void mmTocm(HepMC::GenEvent *evt)
Scale event lengths by x 1/10.
Definition: GenBase.cxx:87
GenBase::GeVToMeV
void GeVToMeV(HepMC::GenEvent *evt)
Scale event energies/momenta by x 1000.
Definition: GenBase.cxx:58
GenBase::m_mcEventKey
std::string m_mcEventKey
StoreGate key for the MC event collection (defaults to GEN_EVENT)
Definition: GenBase.h:137
McEventCollection
McEventCollection
Definition: GeneratorObjectsTPCnv.cxx:60
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
GenBase::MeVToGeV
void MeVToGeV(HepMC::GenEvent *evt)
Scale event energies/momenta by x 1/1000.
Definition: GenBase.cxx:68
GenBase::m_ppSvc
ServiceHandle< IPartPropSvc > m_ppSvc
Handle on the particle property service.
Definition: GenBase.h:160
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
GenBase::m_mcevents_const
SG::ReadHandleKey< McEventCollection > m_mcevents_const
Const handle to the MC event collection.
Definition: GenBase.h:163
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
AthAlgorithm
Definition: AthAlgorithm.h:47
GenBase.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.PyAthena.v
v
Definition: PyAthena.py:154
ATLAS_NOT_CONST_THREAD_SAFE
McEventCollection *GenBase::events ATLAS_NOT_CONST_THREAD_SAFE()
Access the current event's McEventCollection.
Definition: GenBase.cxx:28
GenBase::GenBase
GenBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: GenBase.cxx:11
GenBase::cmTomm
void cmTomm(HepMC::GenEvent *evt)
Scale event lengths by x 10.
Definition: GenBase.cxx:78
GenBase::initialize
virtual StatusCode initialize() override
Definition: GenBase.cxx:17