1 #ifndef RecoPixelVertexing_PixelTriplets_HitTripletEDProducerT_H 2 #define RecoPixelVertexing_PixelTriplets_HitTripletEDProducerT_H 22 template <
typename T_HitTripletGenerator>
35 std::unique_ptr<hitTripletEDProducerT::ImplBase>
impl_;
53 template <
typename T_HitTripletGenerator>
57 generator_(iConfig, iC)
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);
92 seedingHitSetsProducer.reserve(regionDoublets.
regionSize(), this->localRA_.upper());
93 intermediateHitTripletsProducer.reserve(regionDoublets.
regionSize(), this->localRA_.upper());
99 triplets.reserve(this->localRA_.upper());
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);
153 this->localRA_.update(triplets_total);
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) {
201 seedingHitSets_->reserve(regionsSize, localRAupper);
205 hitCacheTmp_.clear();
206 return std::make_tuple(&hitCacheTmp_, seedingHitSets_->beginRegion(region));
210 for(
const auto& trpl: triplets) {
211 filler.
emplace_back(trpl.inner(), trpl.middle(), trpl.outer());
216 seedingHitSets_->shrink_to_fit();
240 void reserve(
size_t regionsSize,
size_t localRAupper) {
241 intermediateHitTriplets_->reserve(regionsSize, layers_->size(), localRAupper);
242 tripletLastLayerIndex_.reserve(localRAupper);
246 auto filler = intermediateHitTriplets_->beginRegion(region);
251 return &tripletLastLayerIndex_;
256 const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
258 if(tripletLastLayerIndex_.size() != triplets.
size()) {
259 throw cms::Exception(
"LogicError") <<
"tripletLastLayerIndex_.size() " << tripletLastLayerIndex_.size()
260 <<
" triplets.size() " << triplets.
size();
262 tripletPermutation_.resize(tripletLastLayerIndex_.size());
263 std::iota(tripletPermutation_.begin(), tripletPermutation_.end(), 0);
264 std::stable_sort(tripletPermutation_.begin(), tripletPermutation_.end(), [&](
size_t i,
size_t j) {
265 return tripletLastLayerIndex_[
i] < tripletLastLayerIndex_[j];
269 filler.
addTriplets(layerPair, thirdLayers, triplets, tripletLastLayerIndex_, tripletPermutation_);
270 tripletLastLayerIndex_.clear();
274 intermediateHitTriplets_->shrink_to_fit();
291 template <
typename T_HitTripletGenerator>
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
static void produces(edm::ProducerBase &producer)
static void produces(edm::ProducerBase &)
produceIntermediateHitTriplets
void reserve(size_t regionsSize, size_t localRAupper)
std::unique_ptr< hitTripletEDProducerT::ImplBase > impl_
Impl(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
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)
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)
void produces(edm::ProducerBase &producer) const override
std::vector< int > * tripletLastLayerIndexVector()
HitTripletEDProducerT(const edm::ParameterSet &iConfig)
void put(edm::Event &iEvent)
virtual unsigned int size() const
ImplGeneratorBase(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
void reserve(size_t, size_t)