ATLAS Offline Software
GenBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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  if (m_ppSvc.retrieve().isFailure()) {
23  ATH_MSG_ERROR("Could not initialize ATLAS Particle Property Service");
24  return StatusCode::FAILURE;
25  }
26  return StatusCode::SUCCESS;
27 }
28 
29 
32  // Make a new MC event collection if necessary
33  McEventCollection* mcevents = nullptr;
34  if (!evtStore()->contains<McEventCollection>(m_mcEventKey) && m_mkMcEvent) {
35  ATH_MSG_DEBUG("Creating new McEventCollection in the event store");
36  mcevents = new McEventCollection();
37  if (evtStore()->record(mcevents, m_mcEventKey).isFailure())
38  ATH_MSG_ERROR("Failed to record a new McEventCollection");
39  }
40  else {
41  const McEventCollection* mecc = 0;
42 
43  if (evtStore()->retrieve (mecc, m_mcEventKey).isFailure())
44  ATH_MSG_ERROR("Failed to retrieve McEventCollection");
45 
46  mcevents = const_cast<McEventCollection*> (&(*mecc));
47  }
48 
49  return mcevents;
50 }
51 
52 
55 #ifdef HEPMC3
56 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());}}
57 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());} }
58 void GenBase::cmTomm(HepMC::GenEvent* evt) { for (auto& v: evt->vertices()) v->set_position(v->position()*10);}
59 void GenBase::mmTocm(HepMC::GenEvent* evt) { for (auto& v: evt->vertices()) v->set_position(v->position()*1.0/10);}
60 #else
61 void GenBase::GeVToMeV(HepMC::GenEvent* evt) {
62  for (HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p) {
63  const HepMC::FourVector fv((*p)->momentum().px() * 1000,
64  (*p)->momentum().py() * 1000,
65  (*p)->momentum().pz() * 1000,
66  (*p)->momentum().e() * 1000);
67  (*p)->set_momentum(fv);
68  (*p)->set_generated_mass(1000 * (*p)->generated_mass());
69  }
70 }
71 void GenBase::MeVToGeV(HepMC::GenEvent* evt) {
72  for (HepMC::GenEvent::particle_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p) {
73  const HepMC::FourVector fv((*p)->momentum().px() / 1000,
74  (*p)->momentum().py() / 1000,
75  (*p)->momentum().pz() / 1000,
76  (*p)->momentum().e() / 1000);
77  (*p)->set_momentum(fv);
78  (*p)->set_generated_mass((*p)->generated_mass() / 1000);
79  }
80 }
81 void GenBase::cmTomm(HepMC::GenEvent* evt) {
82  for (HepMC::GenEvent::vertex_iterator vtx = evt->vertices_begin(); vtx != evt->vertices_end(); ++vtx) {
83  const HepMC::FourVector fv((*vtx)->position().x() * 10,
84  (*vtx)->position().y() * 10,
85  (*vtx)->position().z() * 10,
86  (*vtx)->position().t() * 10);
87  (*vtx)->set_position(fv);
88  }
89 }
90 void GenBase::mmTocm(HepMC::GenEvent* evt) {
91  for (HepMC::GenEvent::vertex_iterator vtx = evt->vertices_begin(); vtx != evt->vertices_end(); ++vtx) {
92  const HepMC::FourVector fv((*vtx)->position().x() / 10,
93  (*vtx)->position().y() / 10,
94  (*vtx)->position().z() / 10,
95  (*vtx)->position().t() / 10);
96  (*vtx)->set_position(fv);
97  }
98 }
99 #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:90
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
GenBase::GeVToMeV
void GeVToMeV(HepMC::GenEvent *evt)
Scale event energies/momenta by x 1000.
Definition: GenBase.cxx:61
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:71
GenBase::m_ppSvc
ServiceHandle< IPartPropSvc > m_ppSvc
Handle on the particle property service.
Definition: GenBase.h:160
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:192
python.PyAthena.v
v
Definition: PyAthena.py:157
ATLAS_NOT_CONST_THREAD_SAFE
McEventCollection *GenBase::events ATLAS_NOT_CONST_THREAD_SAFE()
Access the current event's McEventCollection.
Definition: GenBase.cxx:31
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:81
GenBase::initialize
virtual StatusCode initialize() override
Definition: GenBase.cxx:17