1 #ifndef RecoPixelVertexing_PixelTriplets_HitTripletEDProducerT_H
2 #define RecoPixelVertexing_PixelTriplets_HitTripletEDProducerT_H
20 namespace hitTripletEDProducerT {
class ImplBase; }
22 template <
typename T_HitTripletGenerator>
35 std::unique_ptr<hitTripletEDProducerT::ImplBase>
impl_;
38 namespace hitTripletEDProducerT {
53 template <
typename T_HitTripletGenerator>
66 template <
typename T_HitTripletGenerator,
67 typename T_SeedingHitSets,
typename T_IntermediateHitTriplets>
75 T_SeedingHitSets::produces(producer);
76 T_IntermediateHitTriplets::produces(producer);
83 auto seedingHitSetsProducer = T_SeedingHitSets();
84 auto intermediateHitTripletsProducer = T_IntermediateHitTriplets(&seedingLayerHits);
86 if(regionDoublets.
empty()) {
87 seedingHitSetsProducer.putEmpty(iEvent);
88 intermediateHitTripletsProducer.putEmpty(iEvent);
100 size_t triplets_total = 0;
102 LogDebug(
"HitTripletEDProducer") <<
"Creating triplets for " << regionDoublets.
regionSize() <<
" regions, and " << trilayers.size() <<
" pair+3rd layers from " << regionDoublets.
layerPairsSize() <<
" layer pairs";
104 for(
const auto& regionLayerPairs: regionDoublets) {
107 auto hitCachePtr_filler_shs = seedingHitSetsProducer.beginRegion(®ion,
nullptr);
108 auto hitCachePtr_filler_iht = intermediateHitTripletsProducer.beginRegion(®ion, std::get<0>(hitCachePtr_filler_shs));
109 auto hitCachePtr = std::get<0>(hitCachePtr_filler_iht);
112 hitCache.
extend(regionLayerPairs.layerHitMapCache());
114 LogTrace(
"HitTripletEDProducer") <<
" starting region";
116 for(
const auto& layerPair: regionLayerPairs) {
117 LogTrace(
"HitTripletEDProducer") <<
" starting layer pair " << layerPair.innerLayerIndex() <<
"," << layerPair.outerLayerIndex();
120 return a.first[0].index() == layerPair.innerLayerIndex() &&
a.first[1].index() == layerPair.outerLayerIndex();
122 if(
found == trilayers.end()) {
123 auto exp =
cms::Exception(
"LogicError") <<
"Did not find the layer pair from vector<pair+third layers>. This is a sign of some internal inconsistency\n";
124 exp <<
"I was looking for layer pair " << layerPair.innerLayerIndex() <<
"," << layerPair.outerLayerIndex() <<
". Triplets have the following pairs:\n";
125 for(
const auto&
a: trilayers) {
126 exp <<
" " <<
a.first[0].index() <<
"," <<
a.first[1].index() <<
": 3rd layers";
127 for(
const auto&
b:
a.second) {
128 exp <<
" " <<
b.index();
134 const auto& thirdLayers =
found->second;
136 this->
generator_.hitTriplets(region, triplets, iEvent, iSetup, layerPair.doublets(), thirdLayers,
137 intermediateHitTripletsProducer.tripletLastLayerIndexVector(), hitCache);
140 LogTrace(
"HitTripletEDProducer") <<
" created " << triplets.
size() <<
" triplets for layer pair " << layerPair.innerLayerIndex() <<
"," << layerPair.outerLayerIndex() <<
" and 3rd layers";
141 for(
const auto&
l: thirdLayers) {
142 LogTrace(
"HitTripletEDProducer") <<
" " <<
l.index();
146 triplets_total += triplets.
size();
147 seedingHitSetsProducer.fill(std::get<1>(hitCachePtr_filler_shs), triplets);
148 intermediateHitTripletsProducer.fill(std::get<1>(hitCachePtr_filler_iht), layerPair.layerPair(), thirdLayers, triplets);
155 seedingHitSetsProducer.put(iEvent);
156 intermediateHitTripletsProducer.put(iEvent);
172 return std::make_tuple(ptr, 0);
181 const std::vector<SeedingLayerSetsHits::SeedingLayer>&,
200 void reserve(
size_t regionsSize,
size_t localRAupper) {
210 for(
const auto& trpl: triplets) {
211 filler.
emplace_back(trpl.inner(), trpl.middle(), trpl.outer());
240 void reserve(
size_t regionsSize,
size_t localRAupper) {
247 return std::make_tuple(&(filler.layerHitMapCache()),
std::move(filler));
256 const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
260 <<
" triplets.size() " << triplets.
size();
291 template <
typename T_HitTripletGenerator>
300 using namespace hitTripletEDProducerT;
302 if(produceSeedingHitSets && produceIntermediateHitTriplets)
303 impl_ = std::make_unique<Impl<T_HitTripletGenerator, ImplSeedingHitSets, ImplIntermediateHitTriplets>>(iConfig, iC);
304 else if(produceSeedingHitSets)
305 impl_ = std::make_unique<Impl<T_HitTripletGenerator, ImplSeedingHitSets, DoNothing>>(iConfig, iC);
306 else if(produceIntermediateHitTriplets)
307 impl_ = std::make_unique<Impl<T_HitTripletGenerator, DoNothing, ImplIntermediateHitTriplets>>(iConfig, iC);
309 throw cms::Exception(
"Configuration") <<
"HitTripletEDProducerT requires either produceIntermediateHitTriplets or produceSeedingHitSets to be True. If neither are needed, just remove this module from your sequence/path as it doesn't do anything useful";
311 impl_->produces(*
this);
314 template <
typename T_HitTripletGenerator>
319 desc.
add<
bool>(
"produceSeedingHitSets",
false);
320 desc.
add<
bool>(
"produceIntermediateHitTriplets",
false);
322 T_HitTripletGenerator::fillDescriptions(desc);
324 auto label = T_HitTripletGenerator::fillDescriptionsLabel() +
std::string(
"EDProducerDefault");
328 template <
typename T_HitTripletGenerator>
332 const auto& regionDoublets = *hdoublets;
336 throw cms::Exception(
"LogicError") <<
"HitTripletEDProducerT expects SeedingLayerSetsHits::numberOfLayersInSet() to be >= 3, got " << seedingLayerHits.
numberOfLayersInSet() <<
". This is likely caused by a configuration error of this module, HitPairEDProducer, or SeedingLayersEDProducer.";
339 impl_->produce(regionDoublets, iEvent, iSetup);
void fill(int, const IntermediateHitTriplets::LayerPair &, const std::vector< SeedingLayerSetsHits::SeedingLayer > &, const OrderedHitTriplets &)
T getParameter(std::string const &) const
auto beginRegion(const TrackingRegion *, LayerHitMapCache *ptr)
unsigned short numberOfLayersInSet() const
Get number of layers in each SeedingLayerSets.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
T_HitTripletGenerator generator_
void fill(int, const OrderedHitTriplets &)
void putEmpty(edm::Event &iEvent)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual void produces(edm::ProducerBase &producer) const =0
~ImplGeneratorBase()=default
static void produces(edm::ProducerBase &producer)
static void produces(edm::ProducerBase &)
void reserve(size_t regionsSize, size_t localRAupper)
std::unique_ptr< hitTripletEDProducerT::ImplBase > impl_
Impl(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
void produces(edm::ProducerBase &producer) const override
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
LayerHitMapCache hitCacheTmp_
std::unique_ptr< RegionsSeedingHitSets > seedingHitSets_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
TypeLabelItem const & produces()
declare what type of product will make and with which optional label
DoNothing(const SeedingLayerSetsHits *layers)
virtual void produce(const IntermediateHitDoublets ®ionDoublets, edm::Event &iEvent, const edm::EventSetup &iSetup)=0
produceIntermediateHitTriplets
void produce(const IntermediateHitDoublets ®ionDoublets, edm::Event &iEvent, const edm::EventSetup &iSetup) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
auto beginRegion(const TrackingRegion *region, LayerHitMapCache *ptr)
edm::RunningAverage localRA_
std::pair< LayerSet, std::vector< Layer > > LayerSetAndLayers
void put(edm::Event &iEvent)
Helper class enforcing correct way of filling the doublets of a region.
void emplace_back(Args &&...args)
void fill(RegionsSeedingHitSets::RegionFiller &filler, const OrderedHitTriplets &triplets)
edm::EDGetTokenT< IntermediateHitDoublets > doubletToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void putEmpty(edm::Event &iEvent)
void extend(const LayerHitMapCache &other)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual ~ImplBase()=default
~HitTripletEDProducerT()=default
std::vector< int > * tripletLastLayerIndexVector()
HitTripletEDProducerT(const edm::ParameterSet &iConfig)
void put(edm::Event &iEvent)
virtual unsigned int size() const
unsigned short size() const
Get the number of SeedingLayerSets.
void update(unsigned int q)
ImplGeneratorBase(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
void reserve(size_t, size_t)