CMS 3D CMS Logo

AllHitToTracksterAssociatorsProducer.cc
Go to the documentation of this file.
1 // Author: Felice Pantaleo, felice.pantaleo@cern.ch 08/2024
2 
14 
16 public:
18  ~AllHitToTracksterAssociatorsProducer() override = default;
19 
20  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
21 
22 private:
23  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
24 
25  std::vector<std::pair<std::string, edm::EDGetTokenT<std::vector<ticl::Trackster>>>> tracksterCollectionTokens_;
28  std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hitsTokens_;
29 };
30 
32  : layerClustersToken_(consumes<std::vector<reco::CaloCluster>>(pset.getParameter<edm::InputTag>("layerClusters"))),
33  hitMapToken_(
34  consumes<std::unordered_map<DetId, const unsigned int>>(pset.getParameter<edm::InputTag>("hitMapTag"))) {
35  const auto& tracksterCollections = pset.getParameter<std::vector<edm::InputTag>>("tracksterCollections");
36  for (const auto& tag : tracksterCollections) {
37  tracksterCollectionTokens_.emplace_back(tag.label() + tag.instance(), consumes<std::vector<ticl::Trackster>>(tag));
38  }
39 
40  for (const auto& tag : pset.getParameter<std::vector<edm::InputTag>>("hits")) {
41  hitsTokens_.emplace_back(consumes<HGCRecHitCollection>(tag));
42  }
43 
44  for (const auto& tracksterToken : tracksterCollectionTokens_) {
45  produces<ticl::AssociationMap<ticl::mapWithFraction>>("hitTo" + tracksterToken.first);
46  produces<ticl::AssociationMap<ticl::mapWithFraction>>(tracksterToken.first + "ToHit");
47  }
48 }
49 
51  using namespace edm;
52 
55 
57  iEvent.getByToken(hitMapToken_, hitMap);
58 
59  MultiVectorManager<HGCRecHit> rechitManager;
60  for (const auto& token : hitsTokens_) {
61  Handle<HGCRecHitCollection> hitsHandle;
62  iEvent.getByToken(token, hitsHandle);
63  rechitManager.addVector(*hitsHandle);
64  }
65 
66  for (const auto& tracksterToken : tracksterCollectionTokens_) {
68  iEvent.getByToken(tracksterToken.second, tracksters);
69 
70  auto hitToTracksterMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(rechitManager.size());
71  auto tracksterToHitMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(tracksters->size());
72 
73  for (unsigned int tracksterId = 0; tracksterId < tracksters->size(); ++tracksterId) {
74  const auto& trackster = (*tracksters)[tracksterId];
75  for (unsigned int j = 0; j < trackster.vertices().size(); ++j) {
76  const auto& lc = (*layer_clusters)[trackster.vertices()[j]];
77  float invMultiplicity = 1.0f / trackster.vertex_multiplicity()[j];
78 
79  for (const auto& hitAndFraction : lc.hitsAndFractions()) {
80  auto hitMapIter = hitMap->find(hitAndFraction.first);
81  if (hitMapIter != hitMap->end()) {
82  unsigned int rechitIndex = hitMapIter->second;
83  float fraction = hitAndFraction.second * invMultiplicity;
84  hitToTracksterMap->insert(rechitIndex, tracksterId, fraction);
85  tracksterToHitMap->insert(tracksterId, rechitIndex, fraction);
86  }
87  }
88  }
89  }
90 
91  iEvent.put(std::move(hitToTracksterMap), "hitTo" + tracksterToken.first);
92  iEvent.put(std::move(tracksterToHitMap), tracksterToken.first + "ToHit");
93  }
94 }
95 
98  desc.add<std::vector<edm::InputTag>>("tracksterCollections",
99  {edm::InputTag("ticlTrackstersCLUE3DHigh"),
100  edm::InputTag("ticlTrackstersLinks"),
101  edm::InputTag("ticlCandidate")});
102  desc.add<edm::InputTag>("layerClusters", edm::InputTag("hgcalMergeLayerClusters"));
103  desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
104  desc.add<std::vector<edm::InputTag>>("hits",
105  {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
106  edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
107  edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
108  descriptions.add("AllHitToTracksterAssociatorsProducer", desc);
109 }
110 
111 // Define this as a plug-in
std::vector< edm::EDGetTokenT< HGCRecHitCollection > > hitsTokens_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
~AllHitToTracksterAssociatorsProducer() override=default
edm::EDGetTokenT< std::unordered_map< DetId, const unsigned int > > hitMapToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: DetId.h:17
edm::EDGetTokenT< std::vector< reco::CaloCluster > > layerClustersToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void addVector(std::span< const T > vec)
fixed size matrix
HLT enums.
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
std::vector< std::pair< std::string, edm::EDGetTokenT< std::vector< ticl::Trackster > > > > tracksterCollectionTokens_
def move(src, dest)
Definition: eostools.py:511