Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use GaudiAlg #37

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion k4Gen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ gaudi_add_module(k4Gen
SOURCES ${k4gen_plugin_sources}
LINK Gaudi::GaudiKernel
${HEPMC3_LIBRARIES}
Gaudi::GaudiAlgLib
k4FWCore::k4FWCore
HepPDT::heppdt
EvtGen::EvtGen
Expand Down
4 changes: 2 additions & 2 deletions k4Gen/src/components/ConstPileUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
DECLARE_COMPONENT(ConstPileUp)

ConstPileUp::ConstPileUp(const std::string& type, const std::string& name, const IInterface* parent)
: GaudiTool(type, name, parent) {
: AlgTool(type, name, parent) {
declareInterface<IPileUpTool>(this);
}

ConstPileUp::~ConstPileUp() { ; }

StatusCode ConstPileUp::initialize() {
StatusCode sc = GaudiTool::initialize();
StatusCode sc = AlgTool::initialize();
printPileUpCounters();
return sc;
}
Expand Down
4 changes: 2 additions & 2 deletions k4Gen/src/components/ConstPileUp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define GENERATION_CONSTPILEUP_H

#include "Generation/IPileUpTool.h"
#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/AlgTool.h"

/** @class ConstPileUp
*
Expand All @@ -14,7 +14,7 @@
* @author Valentin Volkl
* @date 2015-12-16
*/
class ConstPileUp : public GaudiTool, virtual public IPileUpTool {
class ConstPileUp : public AlgTool, virtual public IPileUpTool {
public:
ConstPileUp(const std::string& type, const std::string& name, const IInterface* parent);
virtual ~ConstPileUp();
Expand Down
16 changes: 11 additions & 5 deletions k4Gen/src/components/ConstPtParticleGun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@
DECLARE_COMPONENT(ConstPtParticleGun)

ConstPtParticleGun::ConstPtParticleGun(const std::string& type, const std::string& name, const IInterface* parent)
: GaudiTool(type, name, parent) {
: AlgTool(type, name, parent) {
declareInterface<IParticleGunTool>(this);
}

ConstPtParticleGun::~ConstPtParticleGun() {}

StatusCode ConstPtParticleGun::initialize() {
StatusCode sc = GaudiTool::initialize();
StatusCode sc = AlgTool::initialize();
if (!sc.isSuccess()) return sc;
// initialize random number generator
IRndmGenSvc* randSvc = svc<IRndmGenSvc>("RndmGenSvc", true);
IRndmGenSvc* randSvc = service<IRndmGenSvc>("RndmGenSvc", true);
sc = m_flatGenerator.initialize(randSvc, Rndm::Flat(0., 1.));
if (!sc.isSuccess()) return Error("Cannot initialize flat generator");
if (!sc.isSuccess()) {
error() << "Cannot initialize flat generator";
return StatusCode::FAILURE;
}
// check momentum and angles
if ((m_minEta > m_maxEta) || (m_minPhi > m_maxPhi)) return Error("Incorrect values for eta or phi!");
if ((m_minEta > m_maxEta) || (m_minPhi > m_maxPhi)) {
error() << "Incorrect values for eta or phi!";
return StatusCode::FAILURE;
}
m_deltaPhi = m_maxPhi - m_minPhi;
m_deltaEta = m_maxEta - m_minEta;
// setup particle information
Expand Down
4 changes: 2 additions & 2 deletions k4Gen/src/components/ConstPtParticleGun.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define GENERATION_CONSTPTPARTICLEGUN_H

#include "k4FWCore/DataHandle.h"
#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/AlgTool.h"
#include "GaudiKernel/PhysicalConstants.h"
#include "GaudiKernel/RndmGenerators.h"
#include "GaudiKernel/SystemOfUnits.h"
Expand All @@ -14,7 +14,7 @@
* To be more flexible, the gun uses only pt and eta values from a list, if given,
* and only if the lists are empty draws the values from a distribution between min and max.
*/
class ConstPtParticleGun : public GaudiTool, virtual public IParticleGunTool {
class ConstPtParticleGun : public AlgTool, virtual public IParticleGunTool {
public:
ConstPtParticleGun(const std::string& type, const std::string& name, const IInterface* parent);
virtual ~ConstPtParticleGun();
Expand Down
8 changes: 4 additions & 4 deletions k4Gen/src/components/EDMToHepMCConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ using HepMC3::GenParticle;

DECLARE_COMPONENT(EDMToHepMCConverter)

EDMToHepMCConverter::EDMToHepMCConverter(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {
EDMToHepMCConverter::EDMToHepMCConverter(const std::string& name, ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) {
declareProperty("hepmc", m_hepmchandle, "HepMC event handle (output)");
declareProperty("GenParticles", m_genphandle, "Generated particles collection (input)");
}

StatusCode EDMToHepMCConverter::initialize() { return GaudiAlgorithm::initialize(); }
StatusCode EDMToHepMCConverter::initialize() { return Gaudi::Algorithm::initialize(); }

StatusCode EDMToHepMCConverter::execute() {
StatusCode EDMToHepMCConverter::execute(const EventContext&) const {

auto particles = m_genphandle.get();
// ownership of event given to data service at the end of execute
Expand Down Expand Up @@ -51,4 +51,4 @@ StatusCode EDMToHepMCConverter::execute() {
return StatusCode::SUCCESS;
}

StatusCode EDMToHepMCConverter::finalize() { return GaudiAlgorithm::finalize(); }
StatusCode EDMToHepMCConverter::finalize() { return Gaudi::Algorithm::finalize(); }
10 changes: 5 additions & 5 deletions k4Gen/src/components/EDMToHepMCConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
#define GENERATION_EDMTOHEPMCCONVERTER_H

#include "k4FWCore/DataHandle.h"
#include "GaudiAlg/GaudiAlgorithm.h"
#include "Gaudi/Algorithm.h"
#include "HepMC3/GenEvent.h"
#include "HepMC3/Units.h"

namespace edm4hep {
class MCParticleCollection;
}

class EDMToHepMCConverter : public GaudiAlgorithm {
class EDMToHepMCConverter : public Gaudi::Algorithm {

public:
/// Constructor.
EDMToHepMCConverter(const std::string& name, ISvcLocator* svcLoc);
/// Initialize.
virtual StatusCode initialize();
/// Execute.
virtual StatusCode execute();
virtual StatusCode execute(const EventContext&) const;
/// Finalize.
virtual StatusCode finalize();

private:
/// Handle for the HepMC to be read
DataHandle<HepMC3::GenEvent> m_hepmchandle{"hepmc", Gaudi::DataHandle::Writer, this};
mutable DataHandle<HepMC3::GenEvent> m_hepmchandle{"hepmc", Gaudi::DataHandle::Writer, this};
/// Handle for the genparticles to be written
DataHandle<edm4hep::MCParticleCollection> m_genphandle{"GenParticles", Gaudi::DataHandle::Reader, this};
mutable DataHandle<edm4hep::MCParticleCollection> m_genphandle{"GenParticles", Gaudi::DataHandle::Reader, this};
};

#endif
30 changes: 21 additions & 9 deletions k4Gen/src/components/FlatSmearVertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DECLARE_COMPONENT(FlatSmearVertex)

/// Standard constructor, initializes variables
FlatSmearVertex::FlatSmearVertex(const std::string& type, const std::string& name, const IInterface* parent)
: GaudiTool(type, name, parent) {
: AlgTool(type, name, parent) {
declareInterface<IVertexSmearingTool>(this);
}

Expand All @@ -25,13 +25,22 @@ FlatSmearVertex::~FlatSmearVertex() { ; }
// Initialize
//=============================================================================
StatusCode FlatSmearVertex::initialize() {
StatusCode sc = GaudiTool::initialize();
StatusCode sc = AlgTool::initialize();
if (sc.isFailure()) return sc;

IRndmGenSvc* randSvc = svc<IRndmGenSvc>("RndmGenSvc", true);
if (m_xmin > m_xmax) return Error("xMin > xMax !");
if (m_ymin > m_ymax) return Error("yMin > yMax !");
if (m_zmin > m_zmax) return Error("zMin > zMax !");
IRndmGenSvc* randSvc = service<IRndmGenSvc>("RndmGenSvc", true);
if (m_xmin > m_xmax) {
error() << "xMin > xMax !";
return StatusCode::FAILURE;
}
if (m_ymin > m_ymax) {
error() << "yMin > yMax !";
return StatusCode::FAILURE;
}
if (m_zmin > m_zmax) {
error() << "zMin > zMax !";
return StatusCode::FAILURE;
}

sc = m_flatDist.initialize(randSvc, Rndm::Flat(0., 1.));

Expand All @@ -43,7 +52,8 @@ StatusCode FlatSmearVertex::initialize() {
} else if (m_zDir == 0) {
infoMsg = " with TOF of interaction equal to zero ";
} else {
return Error("BeamDirection can only be set to -1 or 1, or 0 to switch off TOF");
error() << "BeamDirection can only be set to -1 or 1, or 0 to switch off TOF";
return StatusCode::FAILURE;
}

info() << "Smearing of interaction point with flat distribution "
Expand All @@ -53,9 +63,11 @@ StatusCode FlatSmearVertex::initialize() {
<< m_ymin / Gaudi::Units::mm << " mm <= y <= " << m_ymax / Gaudi::Units::mm << " mm and "
<< m_zmin / Gaudi::Units::mm << " mm <= z <= " << m_zmax / Gaudi::Units::mm << " mm." << endmsg;

if (!sc.isSuccess()) return Error("Could not initialize flat random number generator");
if (!sc.isSuccess()) {
error() << "Could not initialize flat random number generator";
return StatusCode::FAILURE;
}

release(randSvc).ignore();
return sc;
}

Expand Down
4 changes: 2 additions & 2 deletions k4Gen/src/components/FlatSmearVertex.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef GENERATION_FLATSMEARVERTEX_H
#define GENERATION_FLATSMEARVERTEX_H

#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/AlgTool.h"
#include "GaudiKernel/RndmGenerators.h"
#include "GaudiKernel/SystemOfUnits.h"

Expand All @@ -18,7 +18,7 @@
* @author Daniel Funke
* @date 2008-05-18
*/
class FlatSmearVertex : public GaudiTool, virtual public IVertexSmearingTool {
class FlatSmearVertex : public AlgTool, virtual public IVertexSmearingTool {
public:
/// Standard constructor
FlatSmearVertex(const std::string& type, const std::string& name, const IInterface* parent);
Expand Down
12 changes: 7 additions & 5 deletions k4Gen/src/components/GaussSmearVertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DECLARE_COMPONENT(GaussSmearVertex)

/// Standard constructor, initializes variables
GaussSmearVertex::GaussSmearVertex(const std::string& type, const std::string& name, const IInterface* parent)
: GaudiTool(type, name, parent) {
: AlgTool(type, name, parent) {
declareInterface<IVertexSmearingTool>(this);

}
Expand All @@ -26,10 +26,10 @@ GaussSmearVertex::~GaussSmearVertex() { ; }
// Initialize
//=============================================================================
StatusCode GaussSmearVertex::initialize() {
StatusCode sc = GaudiTool::initialize();
StatusCode sc = AlgTool::initialize();
if (sc.isFailure()) return sc;

IRndmGenSvc* randSvc = svc<IRndmGenSvc>("RndmGenSvc", true);
IRndmGenSvc* randSvc = service<IRndmGenSvc>("RndmGenSvc", true);



Expand All @@ -42,9 +42,11 @@ StatusCode GaussSmearVertex::initialize() {
info() << " with " << m_xsig / Gaudi::Units::mm << " mm standard deviation in x " << m_ysig / Gaudi::Units::mm
<< " mm in y and " << m_zsig / Gaudi::Units::mm << " mm in z." << endmsg;

if (!sc.isSuccess()) return Error("Could not initialize normal random number generator");
if (!sc.isSuccess()) {
error() << "Could not initialize normal random number generator";
return StatusCode::FAILURE;
}

release(randSvc).ignore();
return sc;
}

Expand Down
4 changes: 2 additions & 2 deletions k4Gen/src/components/GaussSmearVertex.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef GENERATION_GAUSSSMEARVERTEX_H
#define GENERATION_GAUSSSMEARVERTEX_H

#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/AlgTool.h"
#include "GaudiKernel/PhysicalConstants.h"
#include "GaudiKernel/RndmGenerators.h"

Expand All @@ -13,7 +13,7 @@
* Concrete implementation of a IVertexSmearingTool.
*
*/
class GaussSmearVertex : public GaudiTool, virtual public IVertexSmearingTool {
class GaussSmearVertex : public AlgTool, virtual public IVertexSmearingTool {
public:
/// Standard constructor
GaussSmearVertex(const std::string& type, const std::string& name, const IInterface* parent);
Expand Down
8 changes: 4 additions & 4 deletions k4Gen/src/components/GenAlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

DECLARE_COMPONENT(GenAlg)

GenAlg::GenAlg(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {
GenAlg::GenAlg(const std::string& name, ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) {

declareProperty("PileUpTool", m_pileUpTool);

Expand All @@ -24,12 +24,12 @@ GenAlg::GenAlg(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(na
}

StatusCode GenAlg::initialize() {
StatusCode sc = GaudiAlgorithm::initialize();
StatusCode sc = Gaudi::Algorithm::initialize();
if (!sc.isSuccess()) return sc;
return sc;
}

StatusCode GenAlg::execute() {
StatusCode GenAlg::execute(const EventContext&) const {
HepMC3::GenEvent* theEvent = m_hepmchandle.createAndPut();
theEvent->set_units(HepMC3::Units::GEV, HepMC3::Units::MM);
const unsigned int numPileUp = m_pileUpTool->numberOfPileUp();
Expand Down Expand Up @@ -57,4 +57,4 @@ StatusCode GenAlg::execute() {
return m_HepMCMergeTool->merge(*theEvent, eventVector);
}

StatusCode GenAlg::finalize() { return GaudiAlgorithm::finalize(); }
StatusCode GenAlg::finalize() { return Gaudi::Algorithm::finalize(); }
18 changes: 9 additions & 9 deletions k4Gen/src/components/GenAlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Generation/IVertexSmearingTool.h"


#include "GaudiAlg/GaudiAlgorithm.h"
#include "Gaudi/Algorithm.h"
#include "GaudiKernel/ToolHandle.h"


Expand All @@ -17,30 +17,30 @@ namespace HepMC3 {
class GenEvent;
}

class GenAlg : public GaudiAlgorithm {
class GenAlg : public Gaudi::Algorithm {

public:
/// Constructor.
GenAlg(const std::string& name, ISvcLocator* svcLoc);
/// Initialize.
virtual StatusCode initialize();
/// Execute.
virtual StatusCode execute();
virtual StatusCode execute(const EventContext&) const;
/// Finalize.
virtual StatusCode finalize();

private:
/// Tools to handle input from HepMC-file
ToolHandle<IHepMCProviderTool> m_signalProvider{"MomentumRangeParticleGun/HepMCProviderTool", this};
ToolHandle<IHepMCProviderTool> m_pileUpProvider{"MomentumRangeParticleGun/HepMCProviderTool", this};
ToolHandle<IPileUpTool> m_pileUpTool{"ConstPileUp/PileUpTool", this};
mutable ToolHandle<IHepMCProviderTool> m_signalProvider{"MomentumRangeParticleGun/HepMCProviderTool", this};
mutable ToolHandle<IHepMCProviderTool> m_pileUpProvider{"MomentumRangeParticleGun/HepMCProviderTool", this};
mutable ToolHandle<IPileUpTool> m_pileUpTool{"ConstPileUp/PileUpTool", this};

/// Tool to merge HepMC events
ToolHandle<IHepMCMergeTool> m_HepMCMergeTool{"HepMCSimpleMerge/HepMCMergeTool", this};
mutable ToolHandle<IHepMCMergeTool> m_HepMCMergeTool{"HepMCSimpleMerge/HepMCMergeTool", this};
// Tool to smear vertices
ToolHandle<IVertexSmearingTool> m_vertexSmearingTool{"FlatSmearVertex/VertexSmearingTool", this};
mutable ToolHandle<IVertexSmearingTool> m_vertexSmearingTool{"FlatSmearVertex/VertexSmearingTool", this};
// output handle for finished event
DataHandle<HepMC3::GenEvent> m_hepmchandle{"hepmc", Gaudi::DataHandle::Writer, this};
mutable DataHandle<HepMC3::GenEvent> m_hepmchandle{"hepmc", Gaudi::DataHandle::Writer, this};
};

#endif // GENERATION_GENALG_H
8 changes: 4 additions & 4 deletions k4Gen/src/components/GenParticleFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

DECLARE_COMPONENT(GenParticleFilter)

GenParticleFilter::GenParticleFilter(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {
GenParticleFilter::GenParticleFilter(const std::string& name, ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) {
declareProperty("GenParticles", m_iGenpHandle, "Generator Particles to filter (input)");
declareProperty("GenParticlesFiltered", m_oGenpHandle, "Filtered Generator particles (output)");
}

StatusCode GenParticleFilter::initialize() { return GaudiAlgorithm::initialize(); }
StatusCode GenParticleFilter::initialize() { return Gaudi::Algorithm::initialize(); }

StatusCode GenParticleFilter::execute() {
StatusCode GenParticleFilter::execute(const EventContext&) const {
const auto inparticles = m_iGenpHandle.get();
auto particles = m_oGenpHandle.createAndPut();
bool accept = false;
Expand All @@ -32,4 +32,4 @@ StatusCode GenParticleFilter::execute() {
return StatusCode::SUCCESS;
}

StatusCode GenParticleFilter::finalize() { return GaudiAlgorithm::finalize(); }
StatusCode GenParticleFilter::finalize() { return Gaudi::Algorithm::finalize(); }
Loading
Loading