Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-26 04:12:40

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/ConsumesCollector.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "FWCore/Utilities/interface/RunningAverage.h"
0010 
0011 #include "RecoTracker/TkHitPairs/interface/RegionsSeedingHitSets.h"
0012 #include "RecoPixelVertexing/PixelTriplets/interface/OrderedHitSeeds.h"
0013 #include "RecoTracker/TkHitPairs/interface/IntermediateHitDoublets.h"
0014 
0015 namespace {
0016   void fillNtuplets(RegionsSeedingHitSets::RegionFiller& seedingHitSetsFiller, const OrderedHitSeeds& quadruplets) {
0017     for (const auto& quad : quadruplets) {
0018       if (quad.size() == 3)
0019         seedingHitSetsFiller.emplace_back(quad[0], quad[1], quad[2]);
0020       if (quad.size() == 4)
0021         seedingHitSetsFiller.emplace_back(quad[0], quad[1], quad[2], quad[3]);
0022     }
0023   }
0024 }  // namespace
0025 
0026 template <typename T_Generator>
0027 class CAHitNtupletEDProducerT : public edm::stream::EDProducer<> {
0028 public:
0029   CAHitNtupletEDProducerT(const edm::ParameterSet& iConfig);
0030   ~CAHitNtupletEDProducerT() override = default;
0031 
0032   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0033 
0034   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0035 
0036 private:
0037   edm::EDGetTokenT<IntermediateHitDoublets> doubletToken_;
0038 
0039   edm::RunningAverage localRA_;
0040 
0041   T_Generator generator_;
0042 };
0043 
0044 template <typename T_Generator>
0045 CAHitNtupletEDProducerT<T_Generator>::CAHitNtupletEDProducerT(const edm::ParameterSet& iConfig)
0046     : doubletToken_(consumes<IntermediateHitDoublets>(iConfig.getParameter<edm::InputTag>("doublets"))),
0047       generator_(iConfig, consumesCollector()) {
0048   produces<RegionsSeedingHitSets>();
0049 }
0050 
0051 template <typename T_Generator>
0052 void CAHitNtupletEDProducerT<T_Generator>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0053   edm::ParameterSetDescription desc;
0054 
0055   desc.add<edm::InputTag>("doublets", edm::InputTag("hitPairEDProducer"));
0056   T_Generator::fillDescriptions(desc);
0057 
0058   auto label = T_Generator::fillDescriptionsLabel() + std::string("EDProducer");
0059   descriptions.add(label, desc);
0060 }
0061 
0062 template <typename T_Generator>
0063 void CAHitNtupletEDProducerT<T_Generator>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0064   edm::Handle<IntermediateHitDoublets> hdoublets;
0065   iEvent.getByToken(doubletToken_, hdoublets);
0066   const auto& regionDoublets = *hdoublets;
0067 
0068   const SeedingLayerSetsHits& seedingLayerHits = regionDoublets.seedingLayerHits();
0069   if (seedingLayerHits.numberOfLayersInSet() < T_Generator::minLayers) {
0070     throw cms::Exception("LogicError")
0071         << "CAHitNtupletEDProducer expects SeedingLayerSetsHits::numberOfLayersInSet() to be >= "
0072         << T_Generator::minLayers << ", got " << seedingLayerHits.numberOfLayersInSet()
0073         << ". This is likely caused by a configuration error of this module, HitPairEDProducer, or "
0074            "SeedingLayersEDProducer.";
0075   }
0076 
0077   auto seedingHitSets = std::make_unique<RegionsSeedingHitSets>();
0078   if (regionDoublets.empty()) {
0079     iEvent.put(std::move(seedingHitSets));
0080     return;
0081   }
0082   seedingHitSets->reserve(regionDoublets.regionSize(), localRA_.upper());
0083   generator_.initEvent(iEvent, iSetup);
0084 
0085   LogDebug("CAHitNtupletEDProducer") << "Creating ntuplets for " << regionDoublets.regionSize() << " regions, and "
0086                                      << regionDoublets.layerPairsSize() << " layer pairs";
0087   std::vector<OrderedHitSeeds> ntuplets;
0088   ntuplets.resize(regionDoublets.regionSize());
0089   for (auto& ntuplet : ntuplets)
0090     ntuplet.reserve(localRA_.upper());
0091 
0092   generator_.hitNtuplets(regionDoublets, ntuplets, seedingLayerHits);
0093   int index = 0;
0094   for (const auto& regionLayerPairs : regionDoublets) {
0095     const TrackingRegion& region = regionLayerPairs.region();
0096     auto seedingHitSetsFiller = seedingHitSets->beginRegion(&region);
0097 
0098     fillNtuplets(seedingHitSetsFiller, ntuplets[index]);
0099     ntuplets[index].clear();
0100     index++;
0101   }
0102   localRA_.update(seedingHitSets->size());
0103 
0104   iEvent.put(std::move(seedingHitSets));
0105 }
0106 
0107 #include "FWCore/PluginManager/interface/ModuleDef.h"
0108 #include "FWCore/Framework/interface/MakerMacros.h"
0109 #include "RecoPixelVertexing/PixelTriplets/interface/CAHitQuadrupletGenerator.h"
0110 using CAHitQuadrupletEDProducer = CAHitNtupletEDProducerT<CAHitQuadrupletGenerator>;
0111 DEFINE_FWK_MODULE(CAHitQuadrupletEDProducer);
0112 
0113 #include "RecoPixelVertexing/PixelTriplets/interface/CAHitTripletGenerator.h"
0114 using CAHitTripletEDProducer = CAHitNtupletEDProducerT<CAHitTripletGenerator>;
0115 DEFINE_FWK_MODULE(CAHitTripletEDProducer);