1 #ifndef RecoPixelVertexing_PixelTriplets_HitTripletEDProducerT_H 2 #define RecoPixelVertexing_PixelTriplets_HitTripletEDProducerT_H 24 template <
typename T_HitTripletGenerator>
37 std::unique_ptr<hitTripletEDProducerT::ImplBase>
impl_;
55 template <
typename T_HitTripletGenerator>
59 generator_(iConfig, iC)
68 template <
typename T_HitTripletGenerator,
69 typename T_SeedingHitSets,
typename T_IntermediateHitTriplets>
74 ~
Impl()
override =
default;
77 T_SeedingHitSets::produces(producer);
78 T_IntermediateHitTriplets::produces(producer);
85 auto seedingHitSetsProducer = T_SeedingHitSets();
86 auto intermediateHitTripletsProducer = T_IntermediateHitTriplets(&seedingLayerHits);
88 if(regionDoublets.
empty()) {
89 seedingHitSetsProducer.putEmpty(iEvent);
90 intermediateHitTripletsProducer.putEmpty(iEvent);
94 seedingHitSetsProducer.reserve(regionDoublets.
regionSize(), this->localRA_.upper());
95 intermediateHitTripletsProducer.reserve(regionDoublets.
regionSize(), this->localRA_.upper());
101 triplets.reserve(this->localRA_.upper());
102 size_t triplets_total = 0;
104 LogDebug(
"HitTripletEDProducer") <<
"Creating triplets for " << regionDoublets.
regionSize() <<
" regions, and " << trilayers.size() <<
" pair+3rd layers from " << regionDoublets.
layerPairsSize() <<
" layer pairs";
106 for(
const auto& regionLayerPairs: regionDoublets) {
109 auto hitCachePtr_filler_shs = seedingHitSetsProducer.beginRegion(®ion,
nullptr);
110 auto hitCachePtr_filler_iht = intermediateHitTripletsProducer.beginRegion(®ion, std::get<0>(hitCachePtr_filler_shs));
111 auto hitCachePtr = std::get<0>(hitCachePtr_filler_iht);
114 hitCache.
extend(regionLayerPairs.layerHitMapCache());
116 LogTrace(
"HitTripletEDProducer") <<
" starting region";
118 for(
const auto& layerPair: regionLayerPairs) {
119 LogTrace(
"HitTripletEDProducer") <<
" starting layer pair " << layerPair.innerLayerIndex() <<
"," << layerPair.outerLayerIndex();
122 return a.first[0].index() == layerPair.innerLayerIndex() &&
a.first[1].index() == layerPair.outerLayerIndex();
124 if(
found == trilayers.end()) {
125 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";
126 exp <<
"I was looking for layer pair " << layerPair.innerLayerIndex() <<
"," << layerPair.outerLayerIndex() <<
". Triplets have the following pairs:\n";
127 for(
const auto&
a: trilayers) {
128 exp <<
" " <<
a.first[0].index() <<
"," <<
a.first[1].index() <<
": 3rd layers";
129 for(
const auto&
b:
a.second) {
130 exp <<
" " <<
b.index();
136 const auto& thirdLayers =
found->second;
138 this->generator_.hitTriplets(region, triplets, iEvent, iSetup, layerPair.doublets(), thirdLayers,
139 intermediateHitTripletsProducer.tripletLastLayerIndexVector(), hitCache);
142 LogTrace(
"HitTripletEDProducer") <<
" created " << triplets.
size() <<
" triplets for layer pair " << layerPair.innerLayerIndex() <<
"," << layerPair.outerLayerIndex() <<
" and 3rd layers";
143 for(
const auto&
l: thirdLayers) {
144 LogTrace(
"HitTripletEDProducer") <<
" " <<
l.index();
148 triplets_total += triplets.
size();
149 seedingHitSetsProducer.fill(std::get<1>(hitCachePtr_filler_shs), triplets);
150 intermediateHitTripletsProducer.fill(std::get<1>(hitCachePtr_filler_iht), layerPair.layerPair(), thirdLayers, triplets);
155 this->localRA_.update(triplets_total);
157 seedingHitSetsProducer.put(iEvent);
158 intermediateHitTripletsProducer.put(iEvent);
174 return std::make_tuple(ptr, 0);
183 const std::vector<SeedingLayerSetsHits::SeedingLayer>&,
202 void reserve(
size_t regionsSize,
size_t localRAupper) {
203 seedingHitSets_->reserve(regionsSize, localRAupper);
207 hitCacheTmp_.clear();
208 return std::make_tuple(&hitCacheTmp_, seedingHitSets_->beginRegion(region));
212 for(
const auto& trpl: triplets) {
213 filler.
emplace_back(trpl.inner(), trpl.middle(), trpl.outer());
218 seedingHitSets_->shrink_to_fit();
242 void reserve(
size_t regionsSize,
size_t localRAupper) {
243 intermediateHitTriplets_->reserve(regionsSize, layers_->size(), localRAupper);
244 tripletLastLayerIndex_.reserve(localRAupper);
248 auto filler = intermediateHitTriplets_->beginRegion(region);
253 return &tripletLastLayerIndex_;
258 const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
260 if(tripletLastLayerIndex_.size() != triplets.
size()) {
261 throw cms::Exception(
"LogicError") <<
"tripletLastLayerIndex_.size() " << tripletLastLayerIndex_.size()
262 <<
" triplets.size() " << triplets.
size();
264 tripletPermutation_.resize(tripletLastLayerIndex_.size());
265 std::iota(tripletPermutation_.begin(), tripletPermutation_.end(), 0);
266 std::stable_sort(tripletPermutation_.begin(), tripletPermutation_.end(), [&](
size_t i,
size_t j) {
267 return tripletLastLayerIndex_[
i] < tripletLastLayerIndex_[j];
271 filler.
addTriplets(layerPair, thirdLayers, triplets, tripletLastLayerIndex_, tripletPermutation_);
272 tripletLastLayerIndex_.clear();
276 intermediateHitTriplets_->shrink_to_fit();
293 template <
typename T_HitTripletGenerator>
304 if(produceSeedingHitSets && produceIntermediateHitTriplets)
305 impl_ = std::make_unique<Impl<T_HitTripletGenerator, ImplSeedingHitSets, ImplIntermediateHitTriplets>>(iConfig, iC);
306 else if(produceSeedingHitSets)
307 impl_ = std::make_unique<Impl<T_HitTripletGenerator, ImplSeedingHitSets, DoNothing>>(iConfig, iC);
308 else if(produceIntermediateHitTriplets)
309 impl_ = std::make_unique<Impl<T_HitTripletGenerator, DoNothing, ImplIntermediateHitTriplets>>(iConfig, iC);
311 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";
313 impl_->produces(*
this);
316 template <
typename T_HitTripletGenerator>
321 desc.
add<
bool>(
"produceSeedingHitSets",
false);
322 desc.
add<
bool>(
"produceIntermediateHitTriplets",
false);
324 T_HitTripletGenerator::fillDescriptions(desc);
326 auto label = T_HitTripletGenerator::fillDescriptionsLabel() +
std::string(
"EDProducerDefault");
330 template <
typename T_HitTripletGenerator>
334 const auto& regionDoublets = *hdoublets;
338 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.";
341 impl_->produce(regionDoublets, iEvent, iSetup);
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
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 &)
void reserve(size_t regionsSize, size_t localRAupper)
std::unique_ptr< hitTripletEDProducerT::ImplBase > impl_
Impl(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
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.
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)
unsigned int size() const override
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)
produceIntermediateHitTriplets
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)
ImplGeneratorBase(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
void reserve(size_t, size_t)