Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-10-16 05:06:39

0001 // Author: Felice Pantaleo, felice.pantaleo@cern.ch 06/2024
0002 
0003 // user include files
0004 #include "FWCore/Framework/interface/global/EDProducer.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "DataFormats/HGCalReco/interface/Trackster.h"
0012 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
0013 #include "SimDataFormats/Associations/interface/TICLAssociationMap.h"
0014 #include "DataFormats/Provenance/interface/ProductID.h"
0015 #include "LCToTSAssociatorProducer.h"
0016 
0017 LCToTSAssociatorProducer::LCToTSAssociatorProducer(const edm::ParameterSet &pset)
0018     : LCCollectionToken_(consumes<std::vector<reco::CaloCluster>>(pset.getParameter<edm::InputTag>("layer_clusters"))),
0019       tracksterCollectionToken_(
0020           consumes<std::vector<ticl::Trackster>>(pset.getParameter<edm::InputTag>("tracksters"))) {
0021   produces<ticl::AssociationMap<ticl::mapWithFraction, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>();
0022 }
0023 
0024 LCToTSAssociatorProducer::~LCToTSAssociatorProducer() {}
0025 
0026 //
0027 // member functions
0028 //
0029 
0030 // ------------ method called to produce the data  ------------
0031 void LCToTSAssociatorProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0032   using namespace edm;
0033 
0034   Handle<std::vector<reco::CaloCluster>> layer_clusters;
0035   iEvent.getByToken(LCCollectionToken_, layer_clusters);
0036 
0037   Handle<std::vector<ticl::Trackster>> tracksters;
0038   iEvent.getByToken(tracksterCollectionToken_, tracksters);
0039 
0040   // Create association map
0041   auto lcToTracksterMap = std::make_unique<
0042       ticl::AssociationMap<ticl::mapWithFraction, std::vector<reco::CaloCluster>, std::vector<ticl::Trackster>>>(
0043       layer_clusters, tracksters, iEvent);
0044 
0045   // Loop over tracksters
0046   for (unsigned int tracksterId = 0; tracksterId < tracksters->size(); ++tracksterId) {
0047     const auto &trackster = (*tracksters)[tracksterId];
0048     // Loop over vertices in trackster
0049     for (unsigned int i = 0; i < trackster.vertices().size(); ++i) {
0050       // Get layerCluster
0051       const auto &lc = (*layer_clusters)[trackster.vertices()[i]];
0052       float sharedEnergy = lc.energy() / trackster.vertex_multiplicity()[i];
0053       edm::Ref<std::vector<reco::CaloCluster>> lcRef(layer_clusters, trackster.vertices()[i]);
0054       edm::Ref<std::vector<ticl::Trackster>> tracksterRef(tracksters, tracksterId);
0055       lcToTracksterMap->insert(lcRef, tracksterRef, sharedEnergy);
0056     }
0057   }
0058   iEvent.put(std::move(lcToTracksterMap));
0059 }
0060 
0061 void LCToTSAssociatorProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0062   edm::ParameterSetDescription desc;
0063   desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalMergeLayerClusters"));
0064   desc.add<edm::InputTag>("tracksters", edm::InputTag("ticlTracksters"));
0065   descriptions.add("LCToTSAssociatorProducer", desc);
0066 }
0067 
0068 DEFINE_FWK_MODULE(LCToTSAssociatorProducer);