File indexing completed on 2024-10-16 05:06:38
0001
0002
0003 #include "FWCore/Framework/interface/global/EDProducer.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "DataFormats/HGCalReco/interface/Trackster.h"
0010 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
0011 #include "SimDataFormats/Associations/interface/TICLAssociationMap.h"
0012 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0013 #include "CommonTools/RecoAlgos/interface/MultiVectorManager.h"
0014
0015 class AllHitToTracksterAssociatorsProducer : public edm::global::EDProducer<> {
0016 public:
0017 explicit AllHitToTracksterAssociatorsProducer(const edm::ParameterSet&);
0018 ~AllHitToTracksterAssociatorsProducer() override = default;
0019
0020 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0021
0022 private:
0023 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0024
0025 std::vector<std::pair<std::string, edm::EDGetTokenT<std::vector<ticl::Trackster>>>> tracksterCollectionTokens_;
0026 edm::EDGetTokenT<std::vector<reco::CaloCluster>> layerClustersToken_;
0027 edm::EDGetTokenT<std::unordered_map<DetId, const unsigned int>> hitMapToken_;
0028 std::vector<edm::EDGetTokenT<HGCRecHitCollection>> hitsTokens_;
0029 };
0030
0031 AllHitToTracksterAssociatorsProducer::AllHitToTracksterAssociatorsProducer(const edm::ParameterSet& pset)
0032 : layerClustersToken_(consumes<std::vector<reco::CaloCluster>>(pset.getParameter<edm::InputTag>("layerClusters"))),
0033 hitMapToken_(
0034 consumes<std::unordered_map<DetId, const unsigned int>>(pset.getParameter<edm::InputTag>("hitMapTag"))) {
0035 const auto& tracksterCollections = pset.getParameter<std::vector<edm::InputTag>>("tracksterCollections");
0036 for (const auto& tag : tracksterCollections) {
0037 tracksterCollectionTokens_.emplace_back(tag.label() + tag.instance(), consumes<std::vector<ticl::Trackster>>(tag));
0038 }
0039
0040 for (const auto& tag : pset.getParameter<std::vector<edm::InputTag>>("hits")) {
0041 hitsTokens_.emplace_back(consumes<HGCRecHitCollection>(tag));
0042 }
0043
0044 for (const auto& tracksterToken : tracksterCollectionTokens_) {
0045 produces<ticl::AssociationMap<ticl::mapWithFraction>>("hitTo" + tracksterToken.first);
0046 produces<ticl::AssociationMap<ticl::mapWithFraction>>(tracksterToken.first + "ToHit");
0047 }
0048 }
0049
0050 void AllHitToTracksterAssociatorsProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0051 using namespace edm;
0052
0053 Handle<std::vector<reco::CaloCluster>> layer_clusters;
0054 iEvent.getByToken(layerClustersToken_, layer_clusters);
0055
0056 Handle<std::unordered_map<DetId, const unsigned int>> hitMap;
0057 iEvent.getByToken(hitMapToken_, hitMap);
0058
0059 MultiVectorManager<HGCRecHit> rechitManager;
0060 for (const auto& token : hitsTokens_) {
0061 Handle<HGCRecHitCollection> hitsHandle;
0062 iEvent.getByToken(token, hitsHandle);
0063 rechitManager.addVector(*hitsHandle);
0064 }
0065
0066 for (const auto& tracksterToken : tracksterCollectionTokens_) {
0067 Handle<std::vector<ticl::Trackster>> tracksters;
0068 iEvent.getByToken(tracksterToken.second, tracksters);
0069
0070 auto hitToTracksterMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(rechitManager.size());
0071 auto tracksterToHitMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(tracksters->size());
0072
0073 for (unsigned int tracksterId = 0; tracksterId < tracksters->size(); ++tracksterId) {
0074 const auto& trackster = (*tracksters)[tracksterId];
0075 for (unsigned int j = 0; j < trackster.vertices().size(); ++j) {
0076 const auto& lc = (*layer_clusters)[trackster.vertices()[j]];
0077 float invMultiplicity = 1.0f / trackster.vertex_multiplicity()[j];
0078
0079 for (const auto& hitAndFraction : lc.hitsAndFractions()) {
0080 auto hitMapIter = hitMap->find(hitAndFraction.first);
0081 if (hitMapIter != hitMap->end()) {
0082 unsigned int rechitIndex = hitMapIter->second;
0083 float fraction = hitAndFraction.second * invMultiplicity;
0084 hitToTracksterMap->insert(rechitIndex, tracksterId, fraction);
0085 tracksterToHitMap->insert(tracksterId, rechitIndex, fraction);
0086 }
0087 }
0088 }
0089 }
0090
0091 iEvent.put(std::move(hitToTracksterMap), "hitTo" + tracksterToken.first);
0092 iEvent.put(std::move(tracksterToHitMap), tracksterToken.first + "ToHit");
0093 }
0094 }
0095
0096 void AllHitToTracksterAssociatorsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0097 edm::ParameterSetDescription desc;
0098 desc.add<std::vector<edm::InputTag>>("tracksterCollections",
0099 {edm::InputTag("ticlTrackstersCLUE3DHigh"),
0100 edm::InputTag("ticlTrackstersLinks"),
0101 edm::InputTag("ticlCandidate")});
0102 desc.add<edm::InputTag>("layerClusters", edm::InputTag("hgcalMergeLayerClusters"));
0103 desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
0104 desc.add<std::vector<edm::InputTag>>("hits",
0105 {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
0106 edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
0107 edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
0108 descriptions.add("AllHitToTracksterAssociatorsProducer", desc);
0109 }
0110
0111
0112 DEFINE_FWK_MODULE(AllHitToTracksterAssociatorsProducer);