Skip to content

Commit

Permalink
Do not use GaudiAlg (#101)
Browse files Browse the repository at this point in the history
* Do not use GaudiAlg

- Change headers and add EventContext in algorithms not to use GaudiAlg
- Replace `GaudiTool` with `AlgTool`

* Add many mutables in places where they are needed

* Bring back commented out lines related to ONNXRuntime

---------

Co-authored-by: jmcarcell <[email protected]>
  • Loading branch information
jmcarcell and jmcarcell committed Jul 29, 2024
1 parent 724d7cb commit 3afec78
Show file tree
Hide file tree
Showing 93 changed files with 453 additions and 456 deletions.
1 change: 0 additions & 1 deletion RecCalorimeter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ gaudi_add_module(k4RecCalorimeterPlugins
SOURCES ${_module_sources}
LINK k4FWCore::k4FWCore
k4FWCore::k4Interface
Gaudi::GaudiAlgLib
Gaudi::GaudiKernel
DD4hep::DDCore
DD4hep::DDG4
Expand Down
8 changes: 4 additions & 4 deletions RecCalorimeter/src/components/CalibrateBenchmarkMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DECLARE_COMPONENT(CalibrateBenchmarkMethod)


CalibrateBenchmarkMethod::CalibrateBenchmarkMethod(const std::string& aName, ISvcLocator* aSvcLoc)
: GaudiAlgorithm(aName, aSvcLoc),
: Gaudi::Algorithm(aName, aSvcLoc),
m_geoSvc("GeoSvc", aName),
m_histSvc("THistSvc", aName),
m_totalEnergyECal(nullptr),
Expand All @@ -43,7 +43,7 @@ CalibrateBenchmarkMethod::~CalibrateBenchmarkMethod() {}


StatusCode CalibrateBenchmarkMethod::initialize() {
if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE;
if (Gaudi::Algorithm::initialize().isFailure()) return StatusCode::FAILURE;

// Check geometry service
if (!m_geoSvc) {
Expand Down Expand Up @@ -102,7 +102,7 @@ StatusCode CalibrateBenchmarkMethod::initialize() {
}


StatusCode CalibrateBenchmarkMethod::execute() {
StatusCode CalibrateBenchmarkMethod::execute(const EventContext&) const {
double totalEnergyInECal = 0.;
double totalEnergyInHCal = 0.;
double energyInFirstLayerECal = 0;
Expand Down Expand Up @@ -253,7 +253,7 @@ StatusCode CalibrateBenchmarkMethod::finalize() {

runMinimization(n_param, variable, steps, m_fixedParameters);

return GaudiAlgorithm::finalize();
return Gaudi::Algorithm::finalize();
}

void CalibrateBenchmarkMethod::registerHistogram(const std::string& path, TH1F*& histogramName) {
Expand Down
28 changes: 14 additions & 14 deletions RecCalorimeter/src/components/CalibrateBenchmarkMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RECCALORIMETER_CALIBRATEBENCHMARKMETHOD_H

// GAUDI
#include "GaudiAlg/GaudiAlgorithm.h"
#include "Gaudi/Algorithm.h"

// Key4HEP
#include "k4FWCore/DataHandle.h"
Expand Down Expand Up @@ -39,7 +39,7 @@ class ITHistSvc;
* @author Michaela Mlynarikova
*/

class CalibrateBenchmarkMethod : public GaudiAlgorithm {
class CalibrateBenchmarkMethod : public Gaudi::Algorithm {
public:
explicit CalibrateBenchmarkMethod(const std::string&, ISvcLocator*);
virtual ~CalibrateBenchmarkMethod();
Expand All @@ -50,7 +50,7 @@ class CalibrateBenchmarkMethod : public GaudiAlgorithm {
/** Fills the histograms.
* @return status code
*/
virtual StatusCode execute() final;
virtual StatusCode execute(const EventContext&) const final;
/** Finalize.
* @return status code
*/
Expand All @@ -68,9 +68,9 @@ class CalibrateBenchmarkMethod : public GaudiAlgorithm {
void runMinimization(int n_param, const std::vector<double>& variable, const std::vector<double>& steps, const std::vector<int>& fixedParameters) const;

/// Handle for electromagnetic barrel cells (input collection)
DataHandle<edm4hep::CalorimeterHitCollection> m_ecalBarrelCells{"ecalBarrelCells", Gaudi::DataHandle::Reader, this};
mutable DataHandle<edm4hep::CalorimeterHitCollection> m_ecalBarrelCells{"ecalBarrelCells", Gaudi::DataHandle::Reader, this};
/// Handle for hadronic barrel cells (input collection)
DataHandle<edm4hep::CalorimeterHitCollection> m_hcalBarrelCells{"hcalBarrelCells", Gaudi::DataHandle::Reader, this};
mutable DataHandle<edm4hep::CalorimeterHitCollection> m_hcalBarrelCells{"hcalBarrelCells", Gaudi::DataHandle::Reader, this};

/// Histogram of total deposited energy in the calorimeters
TH1F* m_totalEnergyECal;
Expand All @@ -81,8 +81,8 @@ class CalibrateBenchmarkMethod : public GaudiAlgorithm {
TH1F* m_parameters;

/// vectors to store the energy in each ECal/HCal layer
std::vector<double> m_energyInLayerECal;
std::vector<double> m_energyInLayerHCal;
mutable std::vector<double> m_energyInLayerECal;
mutable std::vector<double> m_energyInLayerHCal;


/// Maximum energy for the x-axis range
Expand All @@ -103,17 +103,17 @@ class CalibrateBenchmarkMethod : public GaudiAlgorithm {
Gaudi::Property<uint> m_systemIDHCal{this, "HCalSystemID", 8, "ID of the HCal system"};

/// vectors containing the energy deposits to be used for minimization
std::vector<double> m_vecGeneratedEnergy;
std::vector<double> m_vecTotalEnergyinECal;
std::vector<double> m_vecTotalEnergyinHCal;
std::vector<double> m_vecEnergyInFirstLayerECal;
std::vector<double> m_vecEnergyInLastLayerECal;
std::vector<double> m_vecEnergyInFirstLayerHCal;
mutable std::vector<double> m_vecGeneratedEnergy;
mutable std::vector<double> m_vecTotalEnergyinECal;
mutable std::vector<double> m_vecTotalEnergyinHCal;
mutable std::vector<double> m_vecEnergyInFirstLayerECal;
mutable std::vector<double> m_vecEnergyInLastLayerECal;
mutable std::vector<double> m_vecEnergyInFirstLayerHCal;

// benchmark parameters which should be fixed
// p[1] because HCal is already calibrated to HAD scale
// p[5] is the constant term and was not bringing large improvement, hence not minimized for the moment (might be tried again in the future)
Gaudi::Property<std::vector<int>> m_fixedParameters = {this, "fixedParameters", {1,5},"Fixed parameters that will not be minimized"};

};
#endif /* RECCALORIMETER_CALIBRATEBENCHMARKMETHOD_H */
#endif /* RECCALORIMETER_CALIBRATEBENCHMARKMETHOD_H */
6 changes: 3 additions & 3 deletions RecCalorimeter/src/components/CalibrateCaloHitsTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
DECLARE_COMPONENT(CalibrateCaloHitsTool)

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

StatusCode CalibrateCaloHitsTool::initialize() {
StatusCode sc = GaudiTool::initialize();
StatusCode sc = AlgTool::initialize();
if (sc.isFailure()) {
return sc;
}
Expand All @@ -22,4 +22,4 @@ void CalibrateCaloHitsTool::calibrate(std::unordered_map<uint64_t, double>& aHit
[this](std::pair<const uint64_t, double>& p) { p.second *= m_invSamplingFraction; });
}

StatusCode CalibrateCaloHitsTool::finalize() { return GaudiTool::finalize(); }
StatusCode CalibrateCaloHitsTool::finalize() { return AlgTool::finalize(); }
4 changes: 2 additions & 2 deletions RecCalorimeter/src/components/CalibrateCaloHitsTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RECCALORIMETER_CALIBRATECALOHITSTOOL_H

// from Gaudi
#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/AlgTool.h"

// k4FWCore
#include "k4Interface/ICalibrateCaloHitsTool.h"
Expand All @@ -21,7 +21,7 @@
* @date 2016-09
*/

class CalibrateCaloHitsTool : public GaudiTool, virtual public ICalibrateCaloHitsTool {
class CalibrateCaloHitsTool : public AlgTool, virtual public ICalibrateCaloHitsTool {
public:
CalibrateCaloHitsTool(const std::string& type, const std::string& name, const IInterface* parent);
~CalibrateCaloHitsTool() = default;
Expand Down
6 changes: 3 additions & 3 deletions RecCalorimeter/src/components/CalibrateInLayersTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
DECLARE_COMPONENT(CalibrateInLayersTool)

CalibrateInLayersTool::CalibrateInLayersTool(const std::string& type, const std::string& name, const IInterface* parent)
: GaudiTool(type, name, parent), m_geoSvc("GeoSvc", "CalibrateInLayers") {
: AlgTool(type, name, parent), m_geoSvc("GeoSvc", "CalibrateInLayers") {
declareInterface<ICalibrateCaloHitsTool>(this);
}

StatusCode CalibrateInLayersTool::initialize() {
if (GaudiTool::initialize().isFailure()) {
if (AlgTool::initialize().isFailure()) {
return StatusCode::FAILURE;
}
// check if readout exists
Expand Down Expand Up @@ -44,4 +44,4 @@ void CalibrateInLayersTool::calibrate(std::unordered_map<uint64_t, double>& aHit
});
}

StatusCode CalibrateInLayersTool::finalize() { return GaudiTool::finalize(); }
StatusCode CalibrateInLayersTool::finalize() { return AlgTool::finalize(); }
4 changes: 2 additions & 2 deletions RecCalorimeter/src/components/CalibrateInLayersTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RECCALORIMETER_CALIBRATEINLAYERSTOOL_H

// from Gaudi
#include "GaudiAlg/GaudiTool.h"
#include "GaudiKernel/AlgTool.h"
#include "GaudiKernel/ServiceHandle.h"

// k4FWCore
Expand All @@ -26,7 +26,7 @@ class IGeoSvc;
* @author Anna Zaborowska
*/

class CalibrateInLayersTool : public GaudiTool, virtual public ICalibrateCaloHitsTool {
class CalibrateInLayersTool : public AlgTool, virtual public ICalibrateCaloHitsTool {
public:
CalibrateInLayersTool(const std::string& type, const std::string& name, const IInterface* parent);
~CalibrateInLayersTool() = default;
Expand Down
24 changes: 12 additions & 12 deletions RecCalorimeter/src/components/CaloTopoCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

DECLARE_COMPONENT(CaloTopoCluster)

CaloTopoCluster::CaloTopoCluster(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {
CaloTopoCluster::CaloTopoCluster(const std::string& name, ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) {
declareProperty("TopoClusterInput", m_inputTool, "Handle for input map of cells");
declareProperty("noiseTool", m_noiseTool, "Handle for the cells noise tool");
declareProperty("neigboursTool", m_neighboursTool, "Handle for tool to retrieve cell neighbours");
Expand All @@ -47,7 +47,7 @@ CaloTopoCluster::CaloTopoCluster(const std::string& name, ISvcLocator* svcLoc) :
declareProperty("clusterCells", m_clusterCellsCollection, "Handle for clusters (output collection)");
}
StatusCode CaloTopoCluster::initialize() {
if (GaudiAlgorithm::initialize().isFailure()) return StatusCode::FAILURE;
if (Gaudi::Algorithm::initialize().isFailure()) return StatusCode::FAILURE;
m_geoSvc = service("GeoSvc");
if (!m_geoSvc) {
error() << "Unable to locate Geometry Service. "
Expand Down Expand Up @@ -82,7 +82,7 @@ StatusCode CaloTopoCluster::initialize() {
return StatusCode::SUCCESS;
}

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

std::unordered_map<uint64_t, double> allCells;
std::vector<std::pair<uint64_t, double>> firstSeeds;
Expand Down Expand Up @@ -110,11 +110,11 @@ StatusCode CaloTopoCluster::execute() {
});

std::map<uint, std::vector<std::pair<uint64_t, int>>> preClusterCollection;
StatusCode sc = CaloTopoCluster::buildingProtoCluster(m_neighbourSigma,
m_lastNeighbourSigma,
firstSeeds,
allCells,
preClusterCollection);
StatusCode sc = buildingProtoCluster(m_neighbourSigma,
m_lastNeighbourSigma,
firstSeeds,
allCells,
preClusterCollection);
if (sc.isFailure()) {
error() << "Unable to build protocluster!" << endmsg;
return sc;
Expand Down Expand Up @@ -223,7 +223,7 @@ StatusCode CaloTopoCluster::execute() {

void CaloTopoCluster::findingSeeds(const std::unordered_map<uint64_t, double>& aCells,
int aNumSigma,
std::vector<std::pair<uint64_t, double>>& aSeeds) {
std::vector<std::pair<uint64_t, double>>& aSeeds) const {
for (const auto& cell : aCells) {
// retrieve the noise const and offset assigned to cell
double threshold = m_noiseTool->noiseOffset(cell.first) + ( m_noiseTool->noiseRMS(cell.first) * aNumSigma);
Expand All @@ -243,7 +243,7 @@ StatusCode CaloTopoCluster::buildingProtoCluster(
int aLastNumSigma,
std::vector<std::pair<uint64_t, double>>& aSeeds,
const std::unordered_map<uint64_t, double>& aCells,
std::map<uint, std::vector< std::pair<uint64_t, int>>>& aPreClusterCollection) {
std::map<uint, std::vector< std::pair<uint64_t, int>>>& aPreClusterCollection) const {
// Map of cellIDs to clusterIds
std::map<uint64_t, uint> clusterOfCell;

Expand Down Expand Up @@ -309,7 +309,7 @@ CaloTopoCluster::searchForNeighbours(const uint64_t aCellId,
const std::unordered_map<uint64_t, double>& aCells,
std::map<uint64_t, uint>& aClusterOfCell,
std::map<uint, std::vector<std::pair<uint64_t, int>>>& aPreClusterCollection,
bool aAllowClusterMerge) {
bool aAllowClusterMerge) const {
// Fill vector to be returned, next cell ids and cluster id for which neighbours are found
std::vector<std::pair<uint64_t, uint>> addedNeighbourIds;
// Retrieve cellIDs of neighbours
Expand Down Expand Up @@ -396,4 +396,4 @@ CaloTopoCluster::searchForNeighbours(const uint64_t aCellId,
return addedNeighbourIds;
}

StatusCode CaloTopoCluster::finalize() { return GaudiAlgorithm::finalize(); }
StatusCode CaloTopoCluster::finalize() { return Gaudi::Algorithm::finalize(); }
38 changes: 19 additions & 19 deletions RecCalorimeter/src/components/CaloTopoCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RECCALORIMETER_CALOTOPOCLUSTER_H

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

// k4FWCore
Expand Down Expand Up @@ -42,7 +42,7 @@ class Segmentation;
* @author Coralie Neubueser
*/

class CaloTopoCluster : public GaudiAlgorithm {
class CaloTopoCluster : public Gaudi::Algorithm {
public:
CaloTopoCluster(const std::string& name, ISvcLocator* svcLoc);

Expand All @@ -54,7 +54,7 @@ class CaloTopoCluster : public GaudiAlgorithm {
* @param[in] aSeeds, the vector of seed cell ids anf their energy to build proto-clusters.
*/
virtual void findingSeeds(const std::unordered_map<uint64_t, double>& aCells, int aNumSigma,
std::vector<std::pair<uint64_t, double>>& aSeeds);
std::vector<std::pair<uint64_t, double>>& aSeeds) const;

/** Building proto-clusters from the found seeds.
* First the function initialises a cluster in the preClusterCollection for the seed cells,
Expand All @@ -69,7 +69,7 @@ class CaloTopoCluster : public GaudiAlgorithm {
int aLastNumSigma,
std::vector<std::pair<uint64_t, double>>& aSeeds,
const std::unordered_map<uint64_t, double>& aCells,
std::map<uint, std::vector<std::pair<uint64_t, int>>>& aPreClusterCollection);
std::map<uint, std::vector<std::pair<uint64_t, int>>>& aPreClusterCollection) const;

/** Search for neighbours and add them to preClusterCollection
* The
Expand All @@ -86,41 +86,41 @@ class CaloTopoCluster : public GaudiAlgorithm {
searchForNeighbours(const uint64_t aCellId, uint& aClusterID, int aNumSigma, const std::unordered_map<uint64_t, double>& aCells,
std::map<uint64_t, uint>& aClusterOfCell,
std::map<uint, std::vector<std::pair<uint64_t, int>>>& aPreClusterCollection,
bool aAllowClusterMerge);
bool aAllowClusterMerge) const;

StatusCode execute();
StatusCode execute(const EventContext&) const;

StatusCode finalize();

private:
// Cluster collection
DataHandle<edm4hep::ClusterCollection> m_clusterCollection{"calo/clusters", Gaudi::DataHandle::Writer, this};
mutable DataHandle<edm4hep::ClusterCollection> m_clusterCollection{"calo/clusters", Gaudi::DataHandle::Writer, this};
// Cluster cells in collection
DataHandle<edm4hep::CalorimeterHitCollection> m_clusterCellsCollection{"calo/clusterCells", Gaudi::DataHandle::Writer, this};
mutable DataHandle<edm4hep::CalorimeterHitCollection> m_clusterCellsCollection{"calo/clusterCells", Gaudi::DataHandle::Writer, this};
/// Pointer to the geometry service
SmartIF<IGeoSvc> m_geoSvc;
/// Handle for the input tool
ToolHandle<ITopoClusterInputTool> m_inputTool{"TopoClusterInput", this};
mutable ToolHandle<ITopoClusterInputTool> m_inputTool{"TopoClusterInput", this};
/// Handle for the cells noise tool
ToolHandle<ICaloReadCellNoiseMap> m_noiseTool{"TopoCaloNoisyCells", this};
mutable ToolHandle<ICaloReadCellNoiseMap> m_noiseTool{"TopoCaloNoisyCells", this};
/// Handle for neighbours tool
ToolHandle<ICaloReadNeighboursMap> m_neighboursTool{"TopoCaloNeighbours", this};
mutable ToolHandle<ICaloReadNeighboursMap> m_neighboursTool{"TopoCaloNeighbours", this};
/// Handle for tool to get positions in ECal Barrel
ToolHandle<ICellPositionsTool> m_cellPositionsECalBarrelTool{"CellPositionsECalBarrelTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsECalBarrelTool{"CellPositionsECalBarrelTool", this};
/// Handle for tool to get positions in HCal Barrel
ToolHandle<ICellPositionsTool> m_cellPositionsHCalBarrelNoSegTool{"CellPositionsHCalBarrelNoSegTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsHCalBarrelNoSegTool{"CellPositionsHCalBarrelNoSegTool", this};
/// Handle for tool to get positions in HCal Barrel
ToolHandle<ICellPositionsTool> m_cellPositionsHCalBarrelTool{"CellPositionsHCalBarrelTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsHCalBarrelTool{"CellPositionsHCalBarrelTool", this};
/// Handle for tool to get positions in HCal Barrel and Ext Barrel, no Segmentation
ToolHandle<ICellPositionsTool> m_cellPositionsHCalExtBarrelTool{"CellPositionsHCalBarrelNoSegTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsHCalExtBarrelTool{"CellPositionsHCalBarrelNoSegTool", this};
/// Handle for tool to get positions in Calo Discs
ToolHandle<ICellPositionsTool> m_cellPositionsEMECTool{"CellPositionsCaloDiscsTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsEMECTool{"CellPositionsCaloDiscsTool", this};
/// Handle for tool to get positions in Calo Discs
ToolHandle<ICellPositionsTool> m_cellPositionsHECTool{"CellPositionsCaloDiscsTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsHECTool{"CellPositionsCaloDiscsTool", this};
/// Handle for tool to get positions in Calo Discs
ToolHandle<ICellPositionsTool> m_cellPositionsEMFwdTool{"CellPositionsCaloDiscsTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsEMFwdTool{"CellPositionsCaloDiscsTool", this};
/// Handle for tool to get positions in Calo Discs
ToolHandle<ICellPositionsTool> m_cellPositionsHFwdTool{"CellPositionsCaloDiscsTool", this};
mutable ToolHandle<ICellPositionsTool> m_cellPositionsHFwdTool{"CellPositionsCaloDiscsTool", this};

/// no segmentation used in HCal
Gaudi::Property<bool> m_noSegmentationHCalUsed{this, "noSegmentationHCal", true, "HCal Barrel readout without DD4hep eta-phi segmentation used."};
Expand Down
6 changes: 3 additions & 3 deletions RecCalorimeter/src/components/CaloTopoClusterInputTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DECLARE_COMPONENT(CaloTopoClusterInputTool)

CaloTopoClusterInputTool::CaloTopoClusterInputTool(const std::string& type, const std::string& name, const IInterface* parent)
: GaudiTool(type, name, parent) {
: AlgTool(type, name, parent) {
declareProperty("ecalBarrelCells", m_ecalBarrelCells, "");
declareProperty("ecalEndcapCells", m_ecalEndcapCells, "");
declareProperty("ecalFwdCells", m_ecalFwdCells, "");
Expand All @@ -26,7 +26,7 @@ CaloTopoClusterInputTool::CaloTopoClusterInputTool(const std::string& type, cons
}

StatusCode CaloTopoClusterInputTool::initialize() {
if (GaudiTool::initialize().isFailure()) {
if (AlgTool::initialize().isFailure()) {
return StatusCode::FAILURE;
}
m_geoSvc = service("GeoSvc");
Expand All @@ -39,7 +39,7 @@ StatusCode CaloTopoClusterInputTool::initialize() {
return StatusCode::SUCCESS;
}

StatusCode CaloTopoClusterInputTool::finalize() { return GaudiTool::finalize(); }
StatusCode CaloTopoClusterInputTool::finalize() { return AlgTool::finalize(); }

StatusCode CaloTopoClusterInputTool::cellIDMap(std::unordered_map<uint64_t, double>& aCells) {
uint totalNumberOfCells = 0;
Expand Down
Loading

0 comments on commit 3afec78

Please sign in to comment.