CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HitToSimClusterCaloParticleAssociatorProducer.cc
Go to the documentation of this file.
1 // Author: Felice Pantaleo, felice.pantaleo@cern.ch 06/2024
17 
19  const edm::ParameterSet &pset)
20  : simClusterToken_(consumes<std::vector<SimCluster>>(pset.getParameter<edm::InputTag>("simClusters"))),
21  caloParticleToken_(consumes<std::vector<CaloParticle>>(pset.getParameter<edm::InputTag>("caloParticles"))),
22  hitMapToken_(
23  consumes<std::unordered_map<DetId, const unsigned int>>(pset.getParameter<edm::InputTag>("hitMap"))) {
24  auto hitsTags = pset.getParameter<std::vector<edm::InputTag>>("hits");
25  for (const auto &tag : hitsTags) {
26  hitsTokens_.push_back(consumes<HGCRecHitCollection>(tag));
27  }
28  produces<ticl::AssociationMap<ticl::mapWithFraction>>("hitToSimClusterMap");
29  produces<ticl::AssociationMap<ticl::mapWithFraction>>("hitToCaloParticleMap");
30 }
31 
33 
36  const edm::EventSetup &iSetup) const {
37  using namespace edm;
38 
39  Handle<std::vector<CaloParticle>> caloParticlesHandle;
40  iEvent.getByToken(caloParticleToken_, caloParticlesHandle);
41  const auto &caloParticles = *caloParticlesHandle;
42 
43  Handle<std::vector<SimCluster>> simClustersHandle;
44  iEvent.getByToken(simClusterToken_, simClustersHandle);
46  iEvent.getByToken(hitMapToken_, hitMap);
47 
48  MultiVectorManager<HGCRecHit> rechitManager;
49  for (const auto &token : hitsTokens_) {
50  Handle<HGCRecHitCollection> hitsHandle;
51  iEvent.getByToken(token, hitsHandle);
52  rechitManager.addVector(*hitsHandle);
53  }
54 
55  // Create association maps
56  auto hitToSimClusterMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(rechitManager.size());
57  auto hitToCaloParticleMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(rechitManager.size());
58 
59  // Loop over caloParticles
60  for (unsigned int cpId = 0; cpId < caloParticles.size(); ++cpId) {
61  const auto &caloParticle = caloParticles[cpId];
62  // Loop over simClusters in caloParticle
63  for (const auto &simCluster : caloParticle.simClusters()) {
64  // Loop over hits in simCluster
65  for (const auto &hitAndFraction : simCluster->hits_and_fractions()) {
66  auto hitMapIter = hitMap->find(hitAndFraction.first);
67  if (hitMapIter != hitMap->end()) {
68  unsigned int rechitIndex = hitMapIter->second;
69  float fraction = hitAndFraction.second;
70  hitToSimClusterMap->insert(rechitIndex, simCluster.key(), fraction);
71  hitToCaloParticleMap->insert(rechitIndex, cpId, fraction);
72  }
73  }
74  }
75  }
76  iEvent.put(std::move(hitToSimClusterMap), "hitToSimClusterMap");
77  iEvent.put(std::move(hitToCaloParticleMap), "hitToCaloParticleMap");
78 }
79 
82  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
83  desc.add<edm::InputTag>("simClusters", edm::InputTag("mix", "MergedCaloTruth"));
84 
85  desc.add<edm::InputTag>("hitMap", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
86  desc.add<std::vector<edm::InputTag>>("hits",
87  {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
88  edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
89  edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
90  descriptions.add("hitToSimClusterCaloParticleAssociator", desc);
91 }
92 
93 // Define this as a plug-in
edm::EDGetTokenT< std::vector< CaloParticle > > caloParticleToken_
edm::EDGetTokenT< std::unordered_map< DetId, const unsigned int > > hitMapToken_
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DetId.h:17
std::vector< edm::EDGetTokenT< HGCRecHitCollection > > hitsTokens_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void addVector(std::span< const T > vec)
HLT enums.
def move(src, dest)
Definition: eostools.py:511