20 namespace {
class ImplBase; }
34 std::unique_ptr<::ImplBase>
impl_;
41 virtual ~ImplBase() =
default;
49 const unsigned int maxElement_;
52 std::vector<unsigned> layerPairBegins_;
55 maxElement_(iConfig.
getParameter<
unsigned int>(
"maxElement")),
56 generator_(0, 1,
nullptr, maxElement_),
57 layerPairBegins_(iConfig.
getParameter<std::vector<unsigned> >(
"layerPairs"))
59 if(layerPairBegins_.empty())
60 throw cms::Exception(
"Configuration") <<
"HitPairEDProducer requires at least index for layer pairs (layerPairs parameter), none was given";
64 template <
typename T_SeedingHitSets,
typename T_IntermediateHitDoublets,
typename T_RegionLayers>
65 class Impl:
public ImplBase {
67 template <
typename... Args>
70 regionsLayers_(&layerPairBegins_, std::forward<Args>(
args)...)
72 ~Impl()
override =
default;
75 T_SeedingHitSets::produces(producer);
76 T_IntermediateHitDoublets::produces(producer);
80 auto regionsLayers = regionsLayers_.beginEvent(iEvent);
82 auto seedingHitSetsProducer = T_SeedingHitSets(&localRA_);
83 auto intermediateHitDoubletsProducer = T_IntermediateHitDoublets(regionsLayers.seedingLayerSetsHitsPtr());
86 seedingHitSetsProducer.putEmpty(iEvent);
87 intermediateHitDoubletsProducer.putEmpty(iEvent);
91 seedingHitSetsProducer.reserve(regionsLayers.regionsSize());
92 intermediateHitDoubletsProducer.reserve(regionsLayers.regionsSize());
94 for(
const auto& regionLayers: regionsLayers) {
96 auto hitCachePtr_filler_shs = seedingHitSetsProducer.beginRegion(®ion,
nullptr);
97 auto hitCachePtr_filler_ihd = intermediateHitDoubletsProducer.beginRegion(®ion, std::get<0>(hitCachePtr_filler_shs));
98 auto hitCachePtr = std::get<0>(hitCachePtr_filler_ihd);
101 auto doublets = generator_.doublets(region, iEvent, iSetup, layerSet, *hitCachePtr);
102 LogTrace(
"HitPairEDProducer") <<
" created " <<
doublets.size() <<
" doublets for layers " << layerSet[0].index() <<
"," << layerSet[1].index();
104 seedingHitSetsProducer.fill(std::get<1>(hitCachePtr_filler_shs),
doublets);
105 intermediateHitDoubletsProducer.fill(std::get<1>(hitCachePtr_filler_ihd), layerSet,
std::move(
doublets));
109 seedingHitSetsProducer.put(iEvent);
110 intermediateHitDoubletsProducer.put(iEvent);
114 T_RegionLayers regionsLayers_;
125 void reserve(
size_t) {}
128 return std::make_tuple(ptr, 0);
139 class ImplSeedingHitSets {
142 seedingHitSets_(std::make_unique<RegionsSeedingHitSets>()),
150 void reserve(
size_t regionsSize) {
151 seedingHitSets_->
reserve(regionsSize, localRA_->upper());
155 hitCacheTmp_.clear();
156 return std::make_tuple(&hitCacheTmp_, seedingHitSets_->beginRegion(region));
167 seedingHitSets_->shrink_to_fit();
168 localRA_->update(seedingHitSets_->size());
177 std::unique_ptr<RegionsSeedingHitSets> seedingHitSets_;
183 class ImplIntermediateHitDoublets {
186 intermediateHitDoublets_(std::make_unique<IntermediateHitDoublets>(layers)),
194 void reserve(
size_t regionsSize) {
195 intermediateHitDoublets_->
reserve(regionsSize, layers_->size());
199 auto filler = intermediateHitDoublets_->beginRegion(region);
208 intermediateHitDoublets_->shrink_to_fit();
217 std::unique_ptr<IntermediateHitDoublets> intermediateHitDoublets_;
223 class RegionsLayersSeparate {
228 region_(region), layerPairs_(layerPairs) {}
231 const std::vector<SeedingLayerSetsHits::SeedingLayerSet>&
layerPairs()
const {
return *layerPairs_; }
235 const std::vector<SeedingLayerSetsHits::SeedingLayerSet> *layerPairs_;
240 class const_iterator {
244 using difference_type = internal_iterator_type::difference_type;
246 const_iterator(internal_iterator_type iter,
const std::vector<SeedingLayerSetsHits::SeedingLayerSet> *
layerPairs):
247 iter_(iter), layerPairs_(layerPairs) {}
251 const_iterator& operator++() { ++iter_;
return *
this; }
252 const_iterator operator++(
int) {
253 const_iterator
clone(*
this);
258 bool operator==(
const const_iterator&
other)
const {
return iter_ == other.iter_; }
262 internal_iterator_type iter_;
263 const std::vector<SeedingLayerSetsHits::SeedingLayerSet> *layerPairs_;
268 const std::vector<unsigned>& layerPairBegins):
269 seedingLayerSetsHits_(seedingLayerSetsHits), regions_(regions) {
272 if(seedingLayerSetsHits_->numberOfLayersInSet() > 2) {
273 for(
const auto& layerSet: *seedingLayerSetsHits_) {
274 for(
const auto pairBeginIndex: layerPairBegins) {
276 throw cms::Exception(
"LogicError") <<
"Layer pair index " << pairBeginIndex <<
" is out of bounds, input SeedingLayerSetsHits has only " << seedingLayerSetsHits->
numberOfLayersInSet() <<
" layers per set, and the index+1 must be < than the number of layers in set";
286 return pair[0].index() == pairCandidate[0].index() && pair[1].index() == pairCandidate[1].index();
296 if(layerPairBegins.size() != 1) {
297 throw cms::Exception(
"LogicError") <<
"With pairs of input layers, it doesn't make sense to specify more than one input layer pair, got " << layerPairBegins.size();
299 if(layerPairBegins[0] != 0) {
300 throw cms::Exception(
"LogicError") <<
"With pairs of input layers, it doesn't make sense to specify other input layer pair than 0; got " << layerPairBegins[0];
304 for(
const auto&
set: *seedingLayerSetsHits)
311 size_t regionsSize()
const {
return regions_->
size(); }
313 const_iterator
begin()
const {
return const_iterator(regions_->begin(), &
layerPairs); }
314 const_iterator cbegin()
const {
return begin(); }
315 const_iterator
end()
const {
return const_iterator(regions_->end(), &
layerPairs); }
316 const_iterator cend()
const {
return end(); }
321 std::vector<SeedingLayerSetsHits::SeedingLayerSet>
layerPairs;
324 RegionsLayersSeparate(
const std::vector<unsigned> *layerPairBegins,
328 layerPairBegins_(layerPairBegins),
335 iEvent.
getByToken(seedingLayerToken_, hlayers);
337 if(
layers->numberOfLayersInSet() < 2)
338 throw cms::Exception(
"LogicError") <<
"HitPairEDProducer expects SeedingLayerSetsHits::numberOfLayersInSet() to be >= 2, got " <<
layers->numberOfLayersInSet() <<
". This is likely caused by a configuration error of this module, or SeedingLayersEDProducer.";
342 return EventTmp(
layers, hregions.
product(), *layerPairBegins_);
346 const std::vector<unsigned> *layerPairBegins_;
354 class RegionsLayersTogether {
361 regionsLayers_(regionsLayers) {
367 const SeedingLayerSetsHits *seedingLayerSetsHitsPtr()
const {
return &(regionsLayers_->seedingLayerSetsHits()); }
369 size_t regionsSize()
const {
return regionsLayers_->regionsSize(); }
371 const_iterator
begin()
const {
return regionsLayers_->begin(); }
372 const_iterator cbegin()
const {
return begin(); }
373 const_iterator
end()
const {
return regionsLayers_->end(); }
374 const_iterator cend()
const {
return end(); }
380 RegionsLayersTogether(
const std::vector<unsigned> *layerPairBegins,
385 if(layerPairBegins->size() != 1) {
386 throw cms::Exception(
"LogicError") <<
"With trackingRegionsSeedingLayers mode, it doesn't make sense to specify more than one input layer pair, got " << layerPairBegins->size();
388 if((*layerPairBegins)[0] != 0) {
389 throw cms::Exception(
"LogicError") <<
"With trackingRegionsSeedingLayers mode, it doesn't make sense to specify other input layer pair than 0; got " << (*layerPairBegins)[0];
395 iEvent.
getByToken(regionLayerToken_, hregions);
396 return EventTmp(hregions.
product());
410 const bool useRegionLayers = regionLayerTag.
label() !=
"";
411 if(useRegionLayers) {
412 if(regionTag.
label() !=
"") {
413 throw cms::Exception(
"Configuration") <<
"HitPairEDProducer requires either trackingRegions or trackingRegionsSeedingLayers to be set, now both are set to non-empty value. Set the unneeded parameter to empty value.";
415 if(layersTag.label() !=
"") {
416 throw cms::Exception(
"Configuration") <<
"With non-empty trackingRegionsSeedingLayers, please set also seedingLayers to empty value to reduce confusion, because the parameter is not used";
419 if(regionTag.
label() ==
"" && regionLayerTag.
label() ==
"") {
420 throw cms::Exception(
"Configuration") <<
"HitPairEDProducer requires either trackingRegions or trackingRegionsSeedingLayers to be set, now both are set to empty value. Set the needed parameter to a non-empty value.";
426 if(produceSeedingHitSets && produceIntermediateHitDoublets) {
427 if(useRegionLayers)
throw cms::Exception(
"Configuration") <<
"Mode 'trackingRegionsSeedingLayers' makes sense only with 'produceSeedingHitsSets', now also 'produceIntermediateHitDoublets is active";
428 impl_ = std::make_unique<::Impl<::ImplSeedingHitSets, ::ImplIntermediateHitDoublets, ::RegionsLayersSeparate>>(iConfig, layersTag, regionTag, consumesCollector());
430 else if(produceSeedingHitSets) {
431 if(useRegionLayers) {
432 impl_ = std::make_unique<::Impl<::ImplSeedingHitSets, ::DoNothing, ::RegionsLayersTogether>>(iConfig, regionLayerTag, consumesCollector());
435 impl_ = std::make_unique<::Impl<::ImplSeedingHitSets, ::DoNothing, ::RegionsLayersSeparate>>(iConfig, layersTag, regionTag, consumesCollector());
438 else if(produceIntermediateHitDoublets) {
439 if(useRegionLayers)
throw cms::Exception(
"Configuration") <<
"Mode 'trackingRegionsSeedingLayers' makes sense only with 'produceSeedingHitsSets', now 'produceIntermediateHitDoublets is active instead";
440 impl_ = std::make_unique<::Impl<::DoNothing, ::ImplIntermediateHitDoublets, ::RegionsLayersSeparate>>(iConfig, layersTag, regionTag, consumesCollector());
443 throw cms::Exception(
"Configuration") <<
"HitPairEDProducer requires either produceIntermediateHitDoublets or produceSeedingHitSets to be True. If neither are needed, just remove this module from your sequence/path as it doesn't do anything useful";
446 if(clusterCheckTag.label() !=
"")
449 impl_->produces(*
this);
455 desc.
add<
edm::InputTag>(
"seedingLayers",
edm::InputTag(
"seedingLayersEDProducer"))->setComment(
"Set this empty if 'trackingRegionsSeedingLayers' is non-empty");
456 desc.
add<
edm::InputTag>(
"trackingRegions",
edm::InputTag(
"globalTrackingRegionFromBeamSpot"))->setComment(
"Input tracking regions when using all layer sets in 'seedingLayers' (conflicts with 'trackingRegionsSeedingLayers', set this empty to use the other)");
457 desc.
add<
edm::InputTag>(
"trackingRegionsSeedingLayers",
edm::InputTag(
""))->setComment(
"Input tracking regions and corresponding layer sets in case of dynamically limiting the seeding layers (conflicts with 'trackingRegions', set this empty to use the other; if using this set also 'seedingLayers' to empty)");
459 desc.
add<
bool>(
"produceSeedingHitSets",
false);
460 desc.
add<
bool>(
"produceIntermediateHitDoublets",
false);
461 desc.
add<
unsigned int>(
"maxElement", 1000000);
462 desc.
add<std::vector<unsigned> >(
"layerPairs", std::vector<unsigned>{0})->setComment(
"Indices to the pairs of consecutive layers, i.e. 0 means (0,1), 1 (1,2) etc.");
464 descriptions.
add(
"hitPairEDProducerDefault", desc);
468 bool clusterCheckOk =
true;
472 clusterCheckOk = *hclusterCheck;
475 impl_->produce(clusterCheckOk, iEvent, iSetup);
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
T getParameter(std::string const &) const
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)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
SeedingLayerSet slice(size_t begin, size_t end) const
std::unique_ptr<::ImplBase > impl_
#define DEFINE_FWK_MODULE(type)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void put(edm::Event &evt, double value, const char *instanceName)
~HitPairEDProducer() override=default
Container::value_type value_type
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
edm::EDGetTokenT< bool > clusterCheckToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
HitPairEDProducer(const edm::ParameterSet &iConfig)
void reserve(size_t nregions, size_t nhitsets)
Helper class enforcing correct way of filling the doublets of a region.
void emplace_back(Args &&...args)
T const * product() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
produceIntermediateHitDoublets
const SeedingLayerSetsHits & seedingLayerSetsHits() const
Hit const & hit(int i, layer l) const
bool isUninitialized() const
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
unsigned short size() const
Get the number of SeedingLayerSets.