Skip to content

Commit

Permalink
Adding more improvements to the jet tool (#95)
Browse files Browse the repository at this point in the history
* Small changes to cmake lists

* Adding tools for jet reconstruction

* Adding truth jet algorithms

* Fixing CMake change

* Addressing some comments from the PR

* Switching to thread safe Gaudi functional

* Minor code cleanup

* More code cleanup

* Adding an extra algorithm to filter truth particles

* One last removal for filtering

* Adding separate jet clustering helper class

* Adding some checks of the configuration in ClusterJet

* A few updates to namespace etc

* Addressing some changes from MR

* Removing some commented lines

* Update RecCalorimeter/src/components/FilterTruthParticles.cpp

Co-authored-by: Brieuc Francois <[email protected]>

* Removing more unnecessary code

* Adding tool descriptions

* Addressing a few more MR comments

* Fixing the tests in the CMake file

* Changing the naming for truth particle filter

* Fixing naming for truth jet test

* Switching to using associations for truth jets

* Making it thread safe again

---------

Co-authored-by: Brieuc Francois <[email protected]>
  • Loading branch information
jroloff and BrieucF committed Jul 10, 2024
1 parent e252f8c commit 3e9ea8d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
21 changes: 14 additions & 7 deletions RecCalorimeter/src/components/CreateTruthJet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

DECLARE_COMPONENT(CreateTruthJet)

CreateTruthJet::CreateTruthJet(const std::string& name, ISvcLocator* svcLoc) : Transformer(name, svcLoc,
KeyValue("InputCollection", "MCParticles"),
KeyValue("OutputCollection", "TruthJets")) {
CreateTruthJet::CreateTruthJet(const std::string& name, ISvcLocator* svcLoc) : MultiTransformer(name, svcLoc,
{
KeyValue("InputCollection", "MCParticles")
}
,
{
KeyValue("OutputCollectionJets", "TruthJets") ,
KeyValue("OutputCollectionAssociation", "TruthJetParticleAssociations")
}) {
declareProperty("JetAlg", m_jetAlg, "Name of jet clustering algorithm");
declareProperty("JetRadius", m_jetRadius, "Jet clustering radius");
declareProperty("MinPt", m_minPt, "Minimum pT for saved jets");
declareProperty("isExclusiveClustering", m_isExclusive, "1 if exclusive, 0 if inclusive");
declareProperty("outputAssociation", m_outputAssocCollection, "TruthJetParticleAssociation");
}


Expand All @@ -24,9 +29,10 @@ StatusCode CreateTruthJet::initialize() {

}

edm4hep::ReconstructedParticleCollection CreateTruthJet::operator()(const edm4hep::MCParticleCollection& input) const{
std::tuple<edm4hep::ReconstructedParticleCollection, edm4hep::MCRecoParticleAssociationCollection> CreateTruthJet::operator()(const edm4hep::MCParticleCollection& input) const {

std::vector<fastjet::PseudoJet> clustersPJ;
auto& assoc = *(m_outputAssocCollection.createAndPut());

int i=0;
for(auto particle: input){
fastjet::PseudoJet clusterPJ(particle.getMomentum().x, particle.getMomentum().y, particle.getMomentum().z, particle.getEnergy());
Expand All @@ -39,6 +45,7 @@ edm4hep::ReconstructedParticleCollection CreateTruthJet::operator()(const edm4h


edm4hep::ReconstructedParticleCollection edmJets = edm4hep::ReconstructedParticleCollection();
edm4hep::MCRecoParticleAssociationCollection assoc = edm4hep::MCRecoParticleAssociationCollection();

for(auto cjet : inclusiveJets){
edm4hep::MutableReconstructedParticle jet;
Expand All @@ -60,7 +67,7 @@ edm4hep::ReconstructedParticleCollection CreateTruthJet::operator()(const edm4h
edmJets.push_back(jet);
}

return edmJets;
return std::make_tuple(std::move(edmJets), std::move(assoc));
}


Expand Down
13 changes: 6 additions & 7 deletions RecCalorimeter/src/components/CreateTruthJet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/MCRecoParticleAssociation.h"
#include "edm4hep/MCRecoParticleAssociationCollection.h"
#include <tuple>

#include "ClusterJet.h"


/** @class CreateTruthJet k4RecCalorimeter/RecCalorimeter/src/components/CreateTruthJet.h
*
* Tool for reconstructing jets from truth particles.
* It takes as input an MCParticleCollection, and it outputs a ReconstructedParticleCollection with the jets.
* It takes as input an MCParticleCollection, and it outputs a ReconstructedParticleCollection with the jets and
* a MCRecoParticleAssociationCollection with the links between the jets and the truth particles.
*
* JetAlg: A string corresponding to the jet algorithm for clustering
* JetRadius: The radius of the jets being clustered
Expand All @@ -34,19 +36,16 @@
*/


class CreateTruthJet : public Gaudi::Functional::Transformer <edm4hep::ReconstructedParticleCollection(const edm4hep::MCParticleCollection&), BaseClass_t> {
struct CreateTruthJet final : Gaudi::Functional::MultiTransformer<std::tuple< edm4hep::ReconstructedParticleCollection, edm4hep::MCRecoParticleAssociationCollection> (const edm4hep::MCParticleCollection&), BaseClass_t> {

public:
CreateTruthJet(const std::string& name, ISvcLocator* svcLoc);
edm4hep::ReconstructedParticleCollection operator()(const edm4hep::MCParticleCollection& input) const override final;
std::tuple< edm4hep::ReconstructedParticleCollection, edm4hep::MCRecoParticleAssociationCollection> operator()(const edm4hep::MCParticleCollection& input) const override;

StatusCode initialize() override final;

private:


mutable DataHandle<edm4hep::MCRecoParticleAssociationCollection> m_outputAssocCollection{"MCRecoParticleAssociation",
Gaudi::DataHandle::Writer, this};

double m_minPt = 1;
double m_jetRadius = 0.4;
std::string m_jetAlg = "antikt";
Expand Down
8 changes: 5 additions & 3 deletions RecCalorimeter/tests/options/runTruthJetReco.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
guntool.ThetaMax = 135 * constants.pi / 180.
guntool.PhiMin = 0.
guntool.PhiMax = 2. * constants.pi
guntool.MomentumMin = 1. *units.GeV
guntool.MomentumMax = 1. *units.GeV
guntool.MomentumMin = 10. *units.GeV
guntool.MomentumMax = 10. *units.GeV
guntool.PdgCodes = [11] # 11 electron, 13 muon, 22 photon, 111 pi0, 211 pi+

from Configurables import GenAlg
Expand Down Expand Up @@ -97,7 +97,9 @@

createJets = CreateTruthJet("createTruthJets",
InputCollection="FilteredGenParticles",
OutputCollection = "TruthJets")
OutputCollectionJets = "TruthJets",
OutputCollectionAssociation = "TruthJetsAssociations",
MinPt = 5)


ApplicationMgr().TopAlg += [createJets]
Expand Down

0 comments on commit 3e9ea8d

Please sign in to comment.