File indexing completed on 2024-10-16 05:06:39
0001
0002
0003 #include "SimClusterToCaloParticleAssociatorProducer.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "SimDataFormats/Associations/interface/TICLAssociationMap.h"
0008
0009 SimClusterToCaloParticleAssociatorProducer::SimClusterToCaloParticleAssociatorProducer(const edm::ParameterSet &pset)
0010 : simClusterToken_(consumes<std::vector<SimCluster>>(pset.getParameter<edm::InputTag>("simClusters"))),
0011 caloParticleToken_(consumes<std::vector<CaloParticle>>(pset.getParameter<edm::InputTag>("caloParticles"))) {
0012 produces<ticl::AssociationMap<ticl::oneToOneMapWithFraction, std::vector<SimCluster>, std::vector<CaloParticle>>>(
0013 "simClusterToCaloParticleMap");
0014 }
0015
0016 SimClusterToCaloParticleAssociatorProducer::~SimClusterToCaloParticleAssociatorProducer() {}
0017
0018 void SimClusterToCaloParticleAssociatorProducer::produce(edm::StreamID,
0019 edm::Event &iEvent,
0020 const edm::EventSetup &iSetup) const {
0021 using namespace edm;
0022
0023 Handle<std::vector<CaloParticle>> caloParticlesHandle;
0024 iEvent.getByToken(caloParticleToken_, caloParticlesHandle);
0025 const auto &caloParticles = *caloParticlesHandle;
0026
0027 Handle<std::vector<SimCluster>> simClustersHandle;
0028 iEvent.getByToken(simClusterToken_, simClustersHandle);
0029
0030
0031 auto simClusterToCaloParticleMap = std::make_unique<
0032 ticl::AssociationMap<ticl::oneToOneMapWithFraction, std::vector<SimCluster>, std::vector<CaloParticle>>>(
0033 simClustersHandle, caloParticlesHandle, iEvent);
0034
0035
0036 for (unsigned int cpId = 0; cpId < caloParticles.size(); ++cpId) {
0037 const auto &caloParticle = caloParticles[cpId];
0038
0039 for (const auto &simClusterRef : caloParticle.simClusters()) {
0040 const auto &simCluster = *simClusterRef;
0041 unsigned int scId = simClusterRef.key();
0042
0043 float fraction = simCluster.energy() / caloParticle.energy();
0044
0045 simClusterToCaloParticleMap->insert(scId, cpId, fraction);
0046 }
0047 }
0048 iEvent.put(std::move(simClusterToCaloParticleMap), "simClusterToCaloParticleMap");
0049 }
0050
0051 void SimClusterToCaloParticleAssociatorProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0052 edm::ParameterSetDescription desc;
0053 desc.add<edm::InputTag>("simClusters", edm::InputTag("mix", "MergedCaloTruth"));
0054 desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
0055 descriptions.add("SimClusterToCaloParticleAssociatorProducer", desc);
0056 }
0057
0058
0059 DEFINE_FWK_MODULE(SimClusterToCaloParticleAssociatorProducer);