Skip to content

Commit

Permalink
Campaing to fix tests / compilation warnings (#93)
Browse files Browse the repository at this point in the history
* Adjusting CreateCaloJet

* Moving ClusterJet to common directory

* Formatting

* Adjusting CreateTruthJet and FilterTruthParticlesForGenJets

* Debugging prints

* Moving debug printout elsewhere

* Executing external process

* Using edm4hep::labels everywhere

* Removing  from target creation

* Using fastjet link directories

* Removed unnecessary messages

* Fixed missing comma
  • Loading branch information
kjvbrt authored Jul 10, 2024
1 parent 3e9ea8d commit 8186bc7
Show file tree
Hide file tree
Showing 21 changed files with 465 additions and 482 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
find_package(ROOT COMPONENTS RIO Tree)
find_package(Gaudi)
find_package(k4FWCore) # implicit: Gaudi
find_package(EDM4HEP 0.10.1) # implicit: Podio
find_package(EDM4HEP) # implicit: Podio
find_package(DD4hep)
find_package(k4geo)
find_package(ONNXRuntime)
Expand Down Expand Up @@ -60,6 +60,7 @@ function(set_test_env _testname)
endfunction()


add_subdirectory(RecCaloCommon)
add_subdirectory(RecCalorimeter)
add_subdirectory(RecFCChhCalorimeter)
add_subdirectory(RecFCCeeCalorimeter)
Expand All @@ -72,4 +73,3 @@ install(EXPORT ${PROJECT_NAME}Targets
)

gaudi_install(CMAKE cmake/${PROJECT_NAME}Config.cmake)

22 changes: 22 additions & 0 deletions RecCaloCommon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
################################################################################
# Package: RecCaloCommon
################################################################################

file(GLOB _sources src/*.cpp )

gaudi_add_library(RecCaloCommon
SOURCES ${_sources}
LINK Gaudi::GaudiKernel
EDM4HEP::edm4hep
${FASTJET_LIBRARIES}
)

target_include_directories(RecCaloCommon PUBLIC ${FASTJET_INCLUDE_DIRS})
target_link_directories(RecCaloCommon PUBLIC ${FASTJET_LIBRARY_DIRS})

install(TARGETS RecCaloCommon
EXPORT k4RecCalorimeterTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
COMPONENT dev
)
81 changes: 81 additions & 0 deletions RecCaloCommon/include/RecCaloCommon/ClusterJet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#ifndef RECCALOCOMMON_CLUSTERJET_H
#define RECCALOCOMMON_CLUSTERJET_H

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

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

#include "fastjet/JetDefinition.hh"

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

namespace k4::recCalo {

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

protected:
int _index;
};

/** @class ClusterJet
* k4RecCalorimeter/RecCalorimeter/src/components/ClusterJet.h
*
* Helper class for reconstructing jets, used to avoid code duplication in the
* classes that require specific input types. It takes a vector of
* fastjet::PseudoJets as inputs, and returns the a vector of pseudojets after
* clustering.
*
* JetAlg: A string corresponding to the jet algorithm for clustering
* JetRadius: The radius of the jets being clustered
* MinPt: The pT threshold below which jets are ignored
* isExclusiveClustering: 1 if jets should use an exclusive clustering, 0
* otherwise clusterArgs: Any other clustering arguments, such as the number of
* jets for exclusive clustering. This is not used everywhere, so check the code
* to make sure it is implemented for your use-case.
*
* @author Jennifer Roloff
* @date 2024-7
*/

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

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

private:
std::map<std::string, fastjet::JetAlgorithm> m_jetAlgMap = {
{"kt", fastjet::JetAlgorithm::kt_algorithm},
{"cambridge", fastjet::JetAlgorithm::cambridge_algorithm},
{"antikt", fastjet::JetAlgorithm::antikt_algorithm},
{"genkt", fastjet::JetAlgorithm::genkt_algorithm},
{"ee_kt", fastjet::JetAlgorithm::ee_kt_algorithm},
{"ee_genkt", fastjet::JetAlgorithm::ee_genkt_algorithm},
};

std::string m_jetAlg = "antikt";
double m_jetRadius = 0.4;
int m_isExclusiveClustering = 0; // Inclusive clustering by default
double m_minPt = 10; // Only relevant for inclusive clustering
int m_njets = 0; // Only relevant for exclusive clustering

fastjet::ClusterSequence *m_clustSeq;
};

} /* namespace k4::recCalo */
#endif /* RECCALOCOMMON_CLUSTERJET_H */
51 changes: 51 additions & 0 deletions RecCaloCommon/src/ClusterJet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "RecCaloCommon/ClusterJet.h"

namespace k4::recCalo {

ClusterJet::ClusterJet(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;
}

StatusCode 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;
}
if (m_isExclusiveClustering > 1) {
std::cout << "ERROR: "
<< "Clustering of " << m_isExclusiveClustering
<< " is currently not supported" << std::endl;
;
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}

std::vector<fastjet::PseudoJet>
ClusterJet::cluster(const std::vector<fastjet::PseudoJet> clustersPJ) {
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);

// Note: initialize has already checked if m_isExclusiveClustering has the
// right range
if (m_isExclusiveClustering == 0) {
jets = fastjet::sorted_by_pt(m_clustSeq->inclusive_jets(m_minPt));
} else if (m_isExclusiveClustering == 1) {
jets = fastjet::sorted_by_pt(m_clustSeq->exclusive_jets(m_njets));
}

return jets;
}

} /* namespace k4::recCalo */
10 changes: 4 additions & 6 deletions RecCalorimeter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# Package: RecCalorimeter
################################################################################


file(GLOB _module_sources src/components/*.cpp )

gaudi_add_module(k4RecCalorimeterPlugins
SOURCES ${_module_sources}
SOURCES ${_module_sources}
LINK k4FWCore::k4FWCore
k4FWCore::k4Interface
Gaudi::GaudiAlgLib
Expand All @@ -18,6 +17,7 @@ gaudi_add_module(k4RecCalorimeterPlugins
ROOT::Hist
k4geo::detectorSegmentations
k4geo::detectorCommon
RecCaloCommon
${FASTJET_LIBRARIES}
)

Expand All @@ -27,10 +27,8 @@ install(TARGETS k4RecCalorimeterPlugins
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
COMPONENT dev)



include_directories(${FASTJET_INCLUDE_DIRS} include/RecCalorimeter)
link_directories(${FASTJET_LIBRARIES})
target_include_directories(k4RecCalorimeterPlugins PUBLIC ${FASTJET_INCLUDE_DIRS})
target_link_directories(k4RecCalorimeterPlugins PUBLIC ${FASTJET_LIBRARY_DIRS})

include(CTest)

Expand Down
77 changes: 0 additions & 77 deletions RecCalorimeter/include/RecCalorimeter/ClusterJet.h

This file was deleted.

47 changes: 0 additions & 47 deletions RecCalorimeter/src/components/ClusterJet.cpp

This file was deleted.

4 changes: 2 additions & 2 deletions RecCalorimeter/src/components/CreateCaloCells.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class CreateCaloCells : public GaudiAlgorithm {
/// Handle for calo hits (input collection)
DataHandle<edm4hep::SimCalorimeterHitCollection> m_hits{"hits", Gaudi::DataHandle::Reader, this};
/// Handle for the cellID encoding string of the input collection
MetaDataHandle<std::string> m_hitsCellIDEncoding{m_hits, edm4hep::CellIDEncoding, Gaudi::DataHandle::Reader};
MetaDataHandle<std::string> m_hitsCellIDEncoding{m_hits, edm4hep::labels::CellIDEncoding, Gaudi::DataHandle::Reader};
/// Handle for calo cells (output collection)
DataHandle<edm4hep::CalorimeterHitCollection> m_cells{"cells", Gaudi::DataHandle::Writer, this};
MetaDataHandle<std::string> m_cellsCellIDEncoding{m_cells, edm4hep::CellIDEncoding, Gaudi::DataHandle::Writer};
MetaDataHandle<std::string> m_cellsCellIDEncoding{m_cells, edm4hep::labels::CellIDEncoding, Gaudi::DataHandle::Writer};
/// Name of the detector readout
Gaudi::Property<std::string> m_readoutName{this, "readoutName", "ECalBarrelPhiEta", "Name of the detector readout"};
/// Name of active volumes
Expand Down
Loading

0 comments on commit 8186bc7

Please sign in to comment.