diff --git a/RecCalorimeter/src/components/CreateTruthJet.cpp b/RecCalorimeter/src/components/CreateTruthJet.cpp index f2ea535e..b1c5f15a 100644 --- a/RecCalorimeter/src/components/CreateTruthJet.cpp +++ b/RecCalorimeter/src/components/CreateTruthJet.cpp @@ -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"); } @@ -24,9 +29,10 @@ StatusCode CreateTruthJet::initialize() { } -edm4hep::ReconstructedParticleCollection CreateTruthJet::operator()(const edm4hep::MCParticleCollection& input) const{ +std::tuple CreateTruthJet::operator()(const edm4hep::MCParticleCollection& input) const { + std::vector 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()); @@ -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; @@ -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)); } diff --git a/RecCalorimeter/src/components/CreateTruthJet.h b/RecCalorimeter/src/components/CreateTruthJet.h index cce2362e..cf8cafb9 100644 --- a/RecCalorimeter/src/components/CreateTruthJet.h +++ b/RecCalorimeter/src/components/CreateTruthJet.h @@ -13,6 +13,7 @@ #include "edm4hep/MCParticleCollection.h" #include "edm4hep/MCRecoParticleAssociation.h" #include "edm4hep/MCRecoParticleAssociationCollection.h" +#include #include "ClusterJet.h" @@ -20,7 +21,8 @@ /** @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 @@ -34,19 +36,16 @@ */ -class CreateTruthJet : public Gaudi::Functional::Transformer { +struct CreateTruthJet final : Gaudi::Functional::MultiTransformer (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 m_outputAssocCollection{"MCRecoParticleAssociation", - Gaudi::DataHandle::Writer, this}; - double m_minPt = 1; double m_jetRadius = 0.4; std::string m_jetAlg = "antikt"; diff --git a/RecCalorimeter/tests/options/runTruthJetReco.py b/RecCalorimeter/tests/options/runTruthJetReco.py index d1647521..18f540bb 100644 --- a/RecCalorimeter/tests/options/runTruthJetReco.py +++ b/RecCalorimeter/tests/options/runTruthJetReco.py @@ -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 @@ -97,7 +97,9 @@ createJets = CreateTruthJet("createTruthJets", InputCollection="FilteredGenParticles", - OutputCollection = "TruthJets") + OutputCollectionJets = "TruthJets", + OutputCollectionAssociation = "TruthJetsAssociations", + MinPt = 5) ApplicationMgr().TopAlg += [createJets]