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 "HitToTracksterAssociatorProducer.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 "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0016 #include "CommonTools/RecoAlgos/interface/MultiVectorManager.h"
0017 
0018 HitToTracksterAssociatorProducer::HitToTracksterAssociatorProducer(const edm::ParameterSet &pset)
0019     : LCCollectionToken_(consumes<std::vector<reco::CaloCluster>>(pset.getParameter<edm::InputTag>("layer_clusters"))),
0020       tracksterCollectionToken_(consumes<std::vector<ticl::Trackster>>(pset.getParameter<edm::InputTag>("tracksters"))),
0021       hitMapToken_(
0022           consumes<std::unordered_map<DetId, const unsigned int>>(pset.getParameter<edm::InputTag>("hitMapTag"))) {
0023   auto hitsTags = pset.getParameter<std::vector<edm::InputTag>>("hits");
0024   for (const auto &tag : hitsTags) {
0025     hitsTokens_.push_back(consumes<HGCRecHitCollection>(tag));
0026   }
0027   produces<ticl::AssociationMap<ticl::mapWithFraction>>("hitToTracksterMap");
0028   produces<ticl::AssociationMap<ticl::mapWithFraction>>("tracksterToHitMap");
0029 }
0030 
0031 HitToTracksterAssociatorProducer::~HitToTracksterAssociatorProducer() {}
0032 
0033 void HitToTracksterAssociatorProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0034   using namespace edm;
0035 
0036   Handle<std::vector<reco::CaloCluster>> layer_clusters;
0037   iEvent.getByToken(LCCollectionToken_, layer_clusters);
0038 
0039   Handle<std::vector<ticl::Trackster>> tracksters;
0040   iEvent.getByToken(tracksterCollectionToken_, tracksters);
0041 
0042   Handle<std::unordered_map<DetId, const unsigned int>> hitMap;
0043   iEvent.getByToken(hitMapToken_, hitMap);
0044 
0045   MultiVectorManager<HGCRecHit> rechitManager;
0046   for (const auto &token : hitsTokens_) {
0047     Handle<HGCRecHitCollection> hitsHandle;
0048     iEvent.getByToken(token, hitsHandle);
0049     rechitManager.addVector(*hitsHandle);
0050   }
0051 
0052   // Create association map
0053   auto hitToTracksterMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(rechitManager.size());
0054   auto tracksterToHitMap = std::make_unique<ticl::AssociationMap<ticl::mapWithFraction>>(tracksters->size());
0055 
0056   // Loop over tracksters
0057   for (unsigned int tracksterId = 0; tracksterId < tracksters->size(); ++tracksterId) {
0058     const auto &trackster = (*tracksters)[tracksterId];
0059     // Loop over vertices in trackster
0060     for (unsigned int i = 0; i < trackster.vertices().size(); ++i) {
0061       // Get layerCluster
0062       const auto &lc = (*layer_clusters)[trackster.vertices()[i]];
0063       float invMultiplicity = 1.0f / trackster.vertex_multiplicity()[i];
0064 
0065       for (const auto &hitAndFraction : lc.hitsAndFractions()) {
0066         auto hitMapIter = hitMap->find(hitAndFraction.first);
0067         if (hitMapIter != hitMap->end()) {
0068           unsigned int rechitIndex = hitMapIter->second;
0069           float fraction = hitAndFraction.second * invMultiplicity;
0070           hitToTracksterMap->insert(rechitIndex, tracksterId, fraction);
0071           tracksterToHitMap->insert(tracksterId, rechitIndex, fraction);
0072         }
0073       }
0074     }
0075   }
0076   iEvent.put(std::move(hitToTracksterMap), "hitToTracksterMap");
0077   iEvent.put(std::move(tracksterToHitMap), "tracksterToHitMap");
0078 }
0079 
0080 void HitToTracksterAssociatorProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0081   edm::ParameterSetDescription desc;
0082   desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalMergeLayerClusters"));
0083   desc.add<edm::InputTag>("tracksters", edm::InputTag("ticlTracksters"));
0084   desc.add<edm::InputTag>("hitMapTag", edm::InputTag("recHitMapProducer", "hgcalRecHitMap"));
0085   desc.add<std::vector<edm::InputTag>>("hits",
0086                                        {edm::InputTag("HGCalRecHit", "HGCEERecHits"),
0087                                         edm::InputTag("HGCalRecHit", "HGCHEFRecHits"),
0088                                         edm::InputTag("HGCalRecHit", "HGCHEBRecHits")});
0089   descriptions.add("hitToTracksterAssociator", desc);
0090 }
0091 
0092 // Define this as a plug-in
0093 DEFINE_FWK_MODULE(HitToTracksterAssociatorProducer);