Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-11 16:23:17

0001 #ifndef RecoTracker_TkSeedGenerator_SeedCreatorFromRegionHitsEDProducerT_H
0002 #define RecoTracker_TkSeedGenerator_SeedCreatorFromRegionHitsEDProducerT_H
0003 
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "FWCore/Framework/interface/stream/EDProducer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013 
0014 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0015 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitorFactory.h"
0016 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitor.h"
0017 
0018 #include "RecoTracker/TkHitPairs/interface/RegionsSeedingHitSets.h"
0019 
0020 template <typename T_SeedCreator>
0021 class SeedCreatorFromRegionHitsEDProducerT : public edm::stream::EDProducer<> {
0022 public:
0023   SeedCreatorFromRegionHitsEDProducerT(const edm::ParameterSet& iConfig);
0024   ~SeedCreatorFromRegionHitsEDProducerT() override = default;
0025 
0026   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0027 
0028   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0029 
0030 private:
0031   edm::EDGetTokenT<RegionsSeedingHitSets> seedingHitSetsToken_;
0032   T_SeedCreator seedCreator_;
0033   std::unique_ptr<SeedComparitor> comparitor_;
0034 };
0035 
0036 template <typename T_SeedCreator>
0037 SeedCreatorFromRegionHitsEDProducerT<T_SeedCreator>::SeedCreatorFromRegionHitsEDProducerT(
0038     const edm::ParameterSet& iConfig)
0039     : seedingHitSetsToken_(consumes<RegionsSeedingHitSets>(iConfig.getParameter<edm::InputTag>("seedingHitSets"))),
0040       seedCreator_(iConfig, consumesCollector()) {
0041   edm::ConsumesCollector iC = consumesCollector();
0042   edm::ParameterSet comparitorPSet = iConfig.getParameter<edm::ParameterSet>("SeedComparitorPSet");
0043   std::string comparitorName = comparitorPSet.getParameter<std::string>("ComponentName");
0044   if (comparitorName != "none") {
0045     comparitor_ = SeedComparitorFactory::get()->create(comparitorName, comparitorPSet, iC);
0046   }
0047 
0048   produces<TrajectorySeedCollection>();
0049 }
0050 
0051 template <typename T_SeedCreator>
0052 void SeedCreatorFromRegionHitsEDProducerT<T_SeedCreator>::fillDescriptions(
0053     edm::ConfigurationDescriptions& descriptions) {
0054   edm::ParameterSetDescription desc;
0055 
0056   desc.add<edm::InputTag>("seedingHitSets", edm::InputTag("hitPairEDProducer"));
0057   T_SeedCreator::fillDescriptions(desc);
0058 
0059   edm::ParameterSetDescription descComparitor;
0060   descComparitor.add<std::string>("ComponentName", "none");
0061   descComparitor.setAllowAnything();  // until we have moved SeedComparitor too to EDProducers
0062   desc.add<edm::ParameterSetDescription>("SeedComparitorPSet", descComparitor);
0063 
0064   auto label = std::string("seedCreatorFromRegion") + T_SeedCreator::fillDescriptionsLabel() + "EDProducer";
0065   descriptions.add(label, desc);
0066 }
0067 
0068 template <typename T_SeedCreator>
0069 void SeedCreatorFromRegionHitsEDProducerT<T_SeedCreator>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0070   edm::Handle<RegionsSeedingHitSets> hseedingHitSets;
0071   iEvent.getByToken(seedingHitSetsToken_, hseedingHitSets);
0072   const auto& seedingHitSets = *hseedingHitSets;
0073 
0074   auto seeds = std::make_unique<TrajectorySeedCollection>();
0075   seeds->reserve(seedingHitSets.size());
0076 
0077   if (comparitor_)
0078     comparitor_->init(iEvent, iSetup);
0079 
0080   for (const auto& regionSeedingHitSets : seedingHitSets) {
0081     const TrackingRegion& region = regionSeedingHitSets.region();
0082     seedCreator_.init(region, iSetup, comparitor_.get());
0083 
0084     for (const SeedingHitSet& hits : regionSeedingHitSets) {
0085       // TODO: do we really need a comparitor at this point? It is
0086       // used in triplet and quadruplet generators, as well as inside
0087       // seedCreator.
0088       if (!comparitor_ || comparitor_->compatible(hits)) {
0089         seedCreator_.makeSeed(*seeds, hits);
0090       }
0091     }
0092   }
0093 
0094   seeds->shrink_to_fit();
0095   iEvent.put(std::move(seeds));
0096 }
0097 
0098 #endif