Skip to content

Commit

Permalink
Migrate CAHiTripletGenerator and generalize
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Oct 13, 2016
1 parent 0fa1666 commit 4e971b4
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 163 deletions.
118 changes: 118 additions & 0 deletions RecoPixelVertexing/PixelTriplets/plugins/CAHitNtupletEDProducerT.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Common/interface/Handle.h"
#include "FWCore/Utilities/interface/RunningAverage.h"

#include "RecoTracker/TkHitPairs/interface/RegionsSeedingHitSets.h"
#include "RecoPixelVertexing/PixelTriplets/interface/OrderedHitTriplets.h"
#include "RecoPixelVertexing/PixelTriplets/interface/OrderedHitSeeds.h"
#include "RecoTracker/TkHitPairs/interface/IntermediateHitDoublets.h"

namespace {
void fillNtuplets(RegionsSeedingHitSets::RegionFiller& seedingHitSetsFiller,
const OrderedHitTriplets& triplets) {
for(const auto& triplet: triplets) {
seedingHitSetsFiller.emplace_back(triplet[0], triplet[1], triplet[2]);
}
}

void fillNtuplets(RegionsSeedingHitSets::RegionFiller& seedingHitSetsFiller,
const OrderedHitSeeds& quadruplets) {
for(const auto& quad: quadruplets) {
seedingHitSetsFiller.emplace_back(quad[0], quad[1], quad[2], quad[3]);
}
}
}

template <typename T_Generator>
class CAHitNtupletEDProducerT: public edm::stream::EDProducer<> {
public:
CAHitNtupletEDProducerT(const edm::ParameterSet& iConfig);
~CAHitNtupletEDProducerT() = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

virtual void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;

private:
edm::EDGetTokenT<IntermediateHitDoublets> doubletToken_;

edm::RunningAverage localRA_;

T_Generator generator_;
};

template <typename T_Generator>
CAHitNtupletEDProducerT<T_Generator>::CAHitNtupletEDProducerT(const edm::ParameterSet& iConfig):
doubletToken_(consumes<IntermediateHitDoublets>(iConfig.getParameter<edm::InputTag>("doublets"))),
generator_(iConfig, consumesCollector(), false)
{
produces<RegionsSeedingHitSets>();
}

template <typename T_Generator>
void CAHitNtupletEDProducerT<T_Generator>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;

desc.add<edm::InputTag>("doublets", edm::InputTag("hitPairEDProducer"));
T_Generator::fillDescriptions(desc);

auto label = T_Generator::fillDescriptionsLabel() + std::string("EDProducer");
descriptions.add(label, desc);
}

template <typename T_Generator>
void CAHitNtupletEDProducerT<T_Generator>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
edm::Handle<IntermediateHitDoublets> hdoublets;
iEvent.getByToken(doubletToken_, hdoublets);
const auto& regionDoublets = *hdoublets;

const SeedingLayerSetsHits& seedingLayerHits = regionDoublets.seedingLayerHits();
if(seedingLayerHits.numberOfLayersInSet() < T_Generator::minLayers) {
throw cms::Exception("Configuration") << "CAHitNtupletEDProducer expects SeedingLayerSetsHits::numberOfLayersInSet() to be >= " << T_Generator::minLayers << ", got " << seedingLayerHits.numberOfLayersInSet();
}

auto seedingHitSets = std::make_unique<RegionsSeedingHitSets>();
if(regionDoublets.empty()) {
iEvent.put(std::move(seedingHitSets));
return;
}
seedingHitSets->reserve(regionDoublets.regionSize(), localRA_.upper());
generator_.initEvent(iEvent, iSetup);

LogDebug("CAHitNtupletEDProducer") << "Creating ntuplets for " << regionDoublets.regionSize() << " regions, and " << regionDoublets.layerPairsSize() << " layer pairs";

typename T_Generator::ResultType ntuplets;
ntuplets.reserve(localRA_.upper());

for(const auto& regionLayerPairs: regionDoublets) {
const TrackingRegion& region = regionLayerPairs.region();
auto seedingHitSetsFiller = seedingHitSets->beginRegion(&region);

LogTrace("CAHitNtupletEDProducer") << " starting region";

generator_.hitNtuplets(regionLayerPairs, ntuplets, iSetup, seedingLayerHits);
LogTrace("CAHitNtupletEDProducer") << " created " << ntuplets.size() << " ntuplets";
fillNtuplets(seedingHitSetsFiller, ntuplets);

ntuplets.clear();
}
localRA_.update(seedingHitSets->size());

iEvent.put(std::move(seedingHitSets));
}

#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "CAHitQuadrupletGenerator.h"
using CAHitQuadrupletEDProducer = CAHitNtupletEDProducerT<CAHitQuadrupletGenerator>;
DEFINE_FWK_MODULE(CAHitQuadrupletEDProducer);

#include "CAHitTripletGenerator.h"
using CAHitTripletEDProducer = CAHitNtupletEDProducerT<CAHitTripletGenerator>;
DEFINE_FWK_MODULE(CAHitTripletEDProducer);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void CAHitQuadrupletGenerator::hitQuadruplets(const TrackingRegion& region,
theLayerCache.clear();
}

void CAHitQuadrupletGenerator::hitQuadruplets(const IntermediateHitDoublets::RegionLayerSets& regionLayerPairs,
void CAHitQuadrupletGenerator::hitNtuplets(const IntermediateHitDoublets::RegionLayerSets& regionLayerPairs,
OrderedHitSeeds& result,
const edm::EventSetup& es,
const SeedingLayerSetsHits& layers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class CAHitQuadrupletGenerator : public HitQuadrupletGenerator {
public:
typedef LayerHitMapCache LayerCacheType;

static constexpr unsigned int minLayers = 4;
typedef OrderedHitSeeds ResultType;

public:

CAHitQuadrupletGenerator(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC, bool needSeedingLayerSetsHits=true): CAHitQuadrupletGenerator(cfg, iC, needSeedingLayerSetsHits) {}
Expand All @@ -41,6 +44,7 @@ class CAHitQuadrupletGenerator : public HitQuadrupletGenerator {
virtual ~CAHitQuadrupletGenerator();

static void fillDescriptions(edm::ParameterSetDescription& desc);
static const char *fillDescriptionsLabel() { return "caHitQuadruplet"; }

void initEvent(const edm::Event& ev, const edm::EventSetup& es);

Expand All @@ -50,10 +54,10 @@ class CAHitQuadrupletGenerator : public HitQuadrupletGenerator {
const edm::Event & ev, const edm::EventSetup& es);

// new-style
void hitQuadruplets(const IntermediateHitDoublets::RegionLayerSets& regionLayerPairs,
OrderedHitSeeds& result,
const edm::EventSetup& es,
const SeedingLayerSetsHits& layers);
void hitNtuplets(const IntermediateHitDoublets::RegionLayerSets& regionLayerPairs,
OrderedHitSeeds& result,
const edm::EventSetup& es,
const SeedingLayerSetsHits& layers);

private:
// actual work
Expand Down
Loading

0 comments on commit 4e971b4

Please sign in to comment.