Skip to content

Commit

Permalink
Adjusting JetCluster class (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt authored Jul 24, 2024
1 parent 92e9e63 commit 52b4333
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 46 deletions.
27 changes: 13 additions & 14 deletions RecCaloCommon/include/RecCaloCommon/ClusterJet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@

// std
#include <map>
#include <string>
#include <vector>

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

// FastJet
#include "fastjet/ClusterSequence.hh"
#include "fastjet/JetDefinition.hh"

// EDM4hep
#include "edm4hep/ClusterCollection.h"
#include "fastjet/PseudoJet.hh"

namespace k4::recCalo {

class ClusterInfo : public fastjet::PseudoJet::UserInfoBase {
public:
ClusterInfo(const int &index) : _index(index) {}
explicit ClusterInfo(const int &index) : _index(index) {}
int index() const { return _index; }

protected:
int _index;
int _index = 0;
};

/** @class ClusterJet
Expand All @@ -46,17 +44,17 @@ class ClusterInfo : public fastjet::PseudoJet::UserInfoBase {

class ClusterJet {
public:
ClusterJet(std::string jetAlg, double jetRadius,
ClusterJet(const std::string &jetAlg, double jetRadius,
int isExclusiveClustering = 0, double minPt = 0,
int clusterArgs = 0);
StatusCode initialize();
bool initialize();
~ClusterJet() {
if (m_clustSeq)
delete m_clustSeq;
delete m_jetDef;
delete m_clustSeq;
}

std::vector<fastjet::PseudoJet>
cluster(const std::vector<fastjet::PseudoJet> clustersPJ);
cluster(const std::vector<fastjet::PseudoJet> &clustersPJ);

private:
std::map<std::string, fastjet::JetAlgorithm> m_jetAlgMap = {
Expand All @@ -74,7 +72,8 @@ class ClusterJet {
double m_minPt = 10; // Only relevant for inclusive clustering
int m_njets = 0; // Only relevant for exclusive clustering

fastjet::ClusterSequence *m_clustSeq;
fastjet::JetDefinition *m_jetDef = nullptr;
fastjet::ClusterSequence *m_clustSeq = nullptr;
};

} /* namespace k4::recCalo */
Expand Down
33 changes: 18 additions & 15 deletions RecCaloCommon/src/ClusterJet.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
#include "RecCaloCommon/ClusterJet.h"

// std
#include <iostream>

namespace k4::recCalo {

ClusterJet::ClusterJet(std::string jetAlg, double jetRadius,
ClusterJet::ClusterJet(const std::string &jetAlg, double jetRadius,
int isExclusiveClustering, double minPt, int njets)
: m_jetAlg(jetAlg), m_jetRadius(jetRadius),
m_isExclusiveClustering(isExclusiveClustering), m_minPt(minPt),
m_njets(njets) {
m_clustSeq = nullptr;
}
m_njets(njets) {}

StatusCode ClusterJet::initialize() {
bool ClusterJet::initialize() {
if (m_jetAlgMap.find(m_jetAlg) == m_jetAlgMap.end()) {
std::cout << "ERROR: "
<< " is not in the list of supported jet algorithms" << std::endl;
;
return StatusCode::FAILURE;
return false;
}

m_jetDef = new fastjet::JetDefinition(m_jetAlgMap.at(m_jetAlg), m_jetRadius);

if (m_isExclusiveClustering > 1) {
std::cout << "ERROR: "
<< "Clustering of " << m_isExclusiveClustering
<< " is currently not supported" << std::endl;
;
return StatusCode::FAILURE;
return false;
}
return StatusCode::SUCCESS;

return true;
}

std::vector<fastjet::PseudoJet>
ClusterJet::cluster(const std::vector<fastjet::PseudoJet> clustersPJ) {
ClusterJet::cluster(const std::vector<fastjet::PseudoJet> &clustersPJ) {
// Deleting cluster sequence from previous event
delete m_clustSeq;

std::vector<fastjet::PseudoJet> jets;

fastjet::JetDefinition *jetDef =
new fastjet::JetDefinition(m_jetAlgMap.at(m_jetAlg), m_jetRadius);
if (m_clustSeq)
delete m_clustSeq;
m_clustSeq = new fastjet::ClusterSequence(clustersPJ, *jetDef);
m_clustSeq = new fastjet::ClusterSequence(clustersPJ, *m_jetDef);

// Note: initialize has already checked if m_isExclusiveClustering has the
// right range
Expand Down
32 changes: 22 additions & 10 deletions RecCalorimeter/src/components/CreateCaloJet.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// Gaudi
#include "Gaudi/Property.h"
#include <GaudiKernel/StatusCode.h>

// k4FWCore
#include "k4FWCore/Transformer.h"

// std
#include <math.h>
#include <vector>

// EDM4hep
#include "edm4hep/ClusterCollection.h"
#include "edm4hep/ReconstructedParticleCollection.h"

// k4RecCalorimeter
#include "RecCaloCommon/ClusterJet.h"

// std
#include <math.h>
#include <string>
#include <vector>

/** @class CreateCaloJet
* k4RecCalorimeter/RecFCCeeCalorimeter/src/components/CreateCaloJet.h
*
Expand All @@ -41,11 +43,15 @@ struct CreateCaloJet final
{KeyValues("InputClusterCollection", {"CorrectedCaloClusters"})},
{KeyValues("OutputJetCollection", {"Jets"})}) {}

StatusCode initialize() {
clusterer = new k4::recCalo::ClusterJet(m_jetAlg, m_jetRadius,
m_isExclusive, m_minPt);
StatusCode initialize() override {
m_clusterer = new k4::recCalo::ClusterJet(m_jetAlg, m_jetRadius,
m_isExclusive, m_minPt);

if (!m_clusterer->initialize()) {
return StatusCode::FAILURE;
}

return clusterer->initialize();
return StatusCode::SUCCESS;
}

edm4hep::ReconstructedParticleCollection
Expand Down Expand Up @@ -75,7 +81,7 @@ struct CreateCaloJet final
}

std::vector<fastjet::PseudoJet> inclusiveJets =
clusterer->cluster(clustersPJ);
m_clusterer->cluster(clustersPJ);

edm4hep::ReconstructedParticleCollection edmJets =
edm4hep::ReconstructedParticleCollection();
Expand All @@ -98,6 +104,12 @@ struct CreateCaloJet final
return edmJets;
}

StatusCode finalize() override {
delete m_clusterer;

return StatusCode::SUCCESS;
}

private:
Gaudi::Property<std::string> m_jetAlg{this, "JetAlg", "antikt",
"Name of jet clustering algorithm"};
Expand All @@ -108,7 +120,7 @@ struct CreateCaloJet final
Gaudi::Property<int> m_isExclusive{this, "IsExclusiveClustering", 0,
"1 if exclusive, 0 if inclusive"};

k4::recCalo::ClusterJet *clusterer;
k4::recCalo::ClusterJet *m_clusterer = nullptr;
};

DECLARE_COMPONENT(CreateCaloJet)
24 changes: 17 additions & 7 deletions RecCalorimeter/src/components/CreateTruthJet.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Gaudi
#include "Gaudi/Property.h"
#include <GaudiKernel/StatusCode.h>

// k4FWCore
#include "k4FWCore/Transformer.h"
Expand Down Expand Up @@ -49,10 +50,14 @@ struct CreateTruthJet final
KeyValues("OutputAssociationsCollection",
{"TruthJetParticleAssociations"})}) {}

StatusCode initialize() {
clusterer = new k4::recCalo::ClusterJet(m_jetAlg, m_jetRadius,
m_isExclusive, m_minPt);
return clusterer->initialize();
StatusCode initialize() override {
m_clusterer = new k4::recCalo::ClusterJet(m_jetAlg, m_jetRadius,
m_isExclusive, m_minPt);
if (!m_clusterer->initialize()) {
return StatusCode::FAILURE;
}

return StatusCode::SUCCESS;
}

std::tuple<edm4hep::ReconstructedParticleCollection,
Expand All @@ -71,7 +76,7 @@ struct CreateTruthJet final
}

std::vector<fastjet::PseudoJet> inclusiveJets =
clusterer->cluster(clustersPJ);
m_clusterer->cluster(clustersPJ);

auto edmJets = edm4hep::ReconstructedParticleCollection();
auto assoc = edm4hep::MCRecoParticleAssociationCollection();
Expand Down Expand Up @@ -99,8 +104,13 @@ struct CreateTruthJet final
return std::make_tuple(std::move(edmJets), std::move(assoc));
}

private:
StatusCode finalize() override {
delete m_clusterer;

return StatusCode::SUCCESS;
}

private:
Gaudi::Property<std::string> m_jetAlg{this, "JetAlg", "antikt",
"Name of jet clustering algorithm"};
Gaudi::Property<double> m_jetRadius{this, "JetRadius", 0.4,
Expand All @@ -109,7 +119,7 @@ struct CreateTruthJet final
"Minimum pT for saved jets"};
Gaudi::Property<bool> m_isExclusive{this, "isExclusiveClustering", false,
"true if exclusive, false if inclusive"};
k4::recCalo::ClusterJet *clusterer;
k4::recCalo::ClusterJet *m_clusterer = nullptr;
};

DECLARE_COMPONENT(CreateTruthJet)

0 comments on commit 52b4333

Please sign in to comment.