File indexing completed on 2024-10-16 05:06:39
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/Provenance/interface/ProductID.h"
0013
0014 class AllLayerClusterToTracksterAssociatorsProducer : public edm::global::EDProducer<> {
0015 public:
0016 explicit AllLayerClusterToTracksterAssociatorsProducer(const edm::ParameterSet&);
0017 ~AllLayerClusterToTracksterAssociatorsProducer() override = default;
0018
0019 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020
0021 private:
0022 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0023
0024 edm::EDGetTokenT<std::vector<reco::CaloCluster>> layerClustersToken_;
0025 std::vector<std::pair<std::string, edm::EDGetTokenT<std::vector<ticl::Trackster>>>> tracksterCollectionTokens_;
0026 };
0027
0028 AllLayerClusterToTracksterAssociatorsProducer::AllLayerClusterToTracksterAssociatorsProducer(
0029 const edm::ParameterSet& pset)
0030 : layerClustersToken_(
0031 consumes<std::vector<reco::CaloCluster>>(pset.getParameter<edm::InputTag>("layer_clusters"))) {
0032 const auto& tracksterCollections = pset.getParameter<std::vector<edm::InputTag>>("tracksterCollections");
0033 for (const auto& tag : tracksterCollections) {
0034 std::string label = tag.label();
0035 if (tag.instance() != "") {
0036 label += tag.instance();
0037 }
0038 tracksterCollectionTokens_.emplace_back(label, consumes<std::vector<ticl::Trackster>>(tag));
0039 }
0040
0041
0042 for (const auto& tracksterToken : tracksterCollectionTokens_) {
0043 produces<ticl::AssociationMap<ticl::mapWithFraction, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>(
0044 tracksterToken.first);
0045 }
0046 }
0047
0048 void AllLayerClusterToTracksterAssociatorsProducer::produce(edm::StreamID,
0049 edm::Event& iEvent,
0050 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 for (const auto& tracksterToken : tracksterCollectionTokens_) {
0057 Handle<std::vector<ticl::Trackster>> tracksters;
0058 iEvent.getByToken(tracksterToken.second, tracksters);
0059
0060
0061 auto lcToTracksterMap = std::make_unique<
0062 ticl::AssociationMap<ticl::mapWithFraction, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>(
0063 layer_clusters, tracksters, iEvent);
0064
0065
0066 for (unsigned int tracksterId = 0; tracksterId < tracksters->size(); ++tracksterId) {
0067 const auto& trackster = (*tracksters)[tracksterId];
0068
0069 for (unsigned int i = 0; i < trackster.vertices().size(); ++i) {
0070
0071 const auto& lc = (*layer_clusters)[trackster.vertices()[i]];
0072 float sharedEnergy = lc.energy() / trackster.vertex_multiplicity()[i];
0073 edm::Ref<std::vector<reco::CaloCluster>> lcRef(layer_clusters, trackster.vertices()[i]);
0074 edm::Ref<std::vector<ticl::Trackster>> tracksterRef(tracksters, tracksterId);
0075 lcToTracksterMap->insert(lcRef, tracksterRef, sharedEnergy);
0076 }
0077 }
0078
0079 iEvent.put(std::move(lcToTracksterMap), tracksterToken.first);
0080 }
0081 }
0082
0083 void AllLayerClusterToTracksterAssociatorsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0084 edm::ParameterSetDescription desc;
0085 desc.add<std::vector<edm::InputTag>>("tracksterCollections",
0086 {edm::InputTag("ticlTrackstersCLUE3DHigh"),
0087 edm::InputTag("ticlTrackstersLinks"),
0088 edm::InputTag("ticlCandidate")});
0089 desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalMergeLayerClusters"));
0090 descriptions.add("AllLayerClusterToTracksterAssociatorsProducer", desc);
0091 }
0092
0093
0094 DEFINE_FWK_MODULE(AllLayerClusterToTracksterAssociatorsProducer);