CMS 3D CMS Logo

SimClusterToCaloParticleAssociatorProducer.cc
Go to the documentation of this file.
1 // Author: Felice Pantaleo, felice.pantaleo@cern.ch 07/2024
2 
8 
10  : simClusterToken_(consumes<std::vector<SimCluster>>(pset.getParameter<edm::InputTag>("simClusters"))),
11  caloParticleToken_(consumes<std::vector<CaloParticle>>(pset.getParameter<edm::InputTag>("caloParticles"))) {
12  produces<ticl::AssociationMap<ticl::oneToOneMapWithFraction, std::vector<SimCluster>, std::vector<CaloParticle>>>(
13  "simClusterToCaloParticleMap");
14 }
15 
17 
20  const edm::EventSetup &iSetup) const {
21  using namespace edm;
22 
23  Handle<std::vector<CaloParticle>> caloParticlesHandle;
24  iEvent.getByToken(caloParticleToken_, caloParticlesHandle);
25  const auto &caloParticles = *caloParticlesHandle;
26 
27  Handle<std::vector<SimCluster>> simClustersHandle;
28  iEvent.getByToken(simClusterToken_, simClustersHandle);
29 
30  // Create association map
31  auto simClusterToCaloParticleMap = std::make_unique<
33  simClustersHandle, caloParticlesHandle, iEvent);
34 
35  // Loop over caloParticles
36  for (unsigned int cpId = 0; cpId < caloParticles.size(); ++cpId) {
37  const auto &caloParticle = caloParticles[cpId];
38  // Loop over simClusters in caloParticle
39  for (const auto &simClusterRef : caloParticle.simClusters()) {
40  const auto &simCluster = *simClusterRef;
41  unsigned int scId = simClusterRef.key();
42  // Calculate the fraction of the simCluster energy to the caloParticle energy
43  float fraction = simCluster.energy() / caloParticle.energy();
44  // Insert association
45  simClusterToCaloParticleMap->insert(scId, cpId, fraction);
46  }
47  }
48  iEvent.put(std::move(simClusterToCaloParticleMap), "simClusterToCaloParticleMap");
49 }
50 
53  desc.add<edm::InputTag>("simClusters", edm::InputTag("mix", "MergedCaloTruth"));
54  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
55  descriptions.add("SimClusterToCaloParticleAssociatorProducer", desc);
56 }
57 
58 // Define this as a plug-in
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:224
Monte Carlo truth information used for tracking validation.
Definition: SimCluster.h:33
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< std::vector< SimCluster > > simClusterToken_
HLT enums.
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< std::vector< CaloParticle > > caloParticleToken_