18 namespace {
class ImplBase; }
34 std::unique_ptr<::ImplBase>
impl_;
41 virtual ~ImplBase() =
default;
52 const unsigned int maxElement_;
55 std::vector<unsigned> layerPairBegins_;
58 maxElement_(iConfig.
getParameter<
unsigned int>(
"maxElement")),
59 generator_(0, 1,
nullptr, maxElement_),
60 layerPairBegins_(iConfig.
getParameter<std::vector<unsigned> >(
"layerPairs"))
62 if(layerPairBegins_.empty())
63 throw cms::Exception(
"Configuration") <<
"HitPairEDProducer requires at least index for layer pairs (layerPairs parameter), none was given";
67 for(
const auto& layerSet: layers) {
68 for(
const auto pairBeginIndex: layerPairBegins_) {
69 if(pairBeginIndex+1 >= layers.numberOfLayersInSet()) {
70 throw cms::Exception(
"LogicError") <<
"Layer pair index " << pairBeginIndex <<
" is out of bounds, input SeedingLayerSetsHits has only " << layers.numberOfLayersInSet() <<
" layers per set, and the index+1 must be < than the number of layers in set";
80 return pair[0].index() == pairCandidate[0].index() && pair[1].index() == pairCandidate[1].index();
82 if(
found != layerPairs.end())
85 layerPairs.push_back(pairCandidate);
90 if(layerPairBegins_.size() != 1) {
91 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();
93 if(layerPairBegins_[0] != 0) {
94 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];
97 layerPairs.reserve(layers.
size());
98 for(
const auto&
set: layers)
99 layerPairs.push_back(
set);
105 template <
typename T_SeedingHitSets,
typename T_IntermediateHitDoublets>
106 struct Impl:
public ImplBase {
111 T_SeedingHitSets::produces(producer);
112 T_IntermediateHitDoublets::produces(producer);
117 auto seedingHitSetsProducer = T_SeedingHitSets(&localRA_);
118 auto intermediateHitDoubletsProducer = T_IntermediateHitDoublets(&layers);
120 if(!clusterCheckOk) {
121 seedingHitSetsProducer.putEmpty(iEvent);
122 intermediateHitDoubletsProducer.putEmpty(iEvent);
126 seedingHitSetsProducer.reserve(regions.
size());
127 intermediateHitDoubletsProducer.reserve(regions.
size());
129 std::vector<SeedingLayerSetsHits::SeedingLayerSet>
layerPairs;
130 makeLayerPairs(layers, layerPairs);
133 auto hitCachePtr_filler_shs = seedingHitSetsProducer.beginRegion(®ion,
nullptr);
134 auto hitCachePtr_filler_ihd = intermediateHitDoubletsProducer.beginRegion(®ion, std::get<0>(hitCachePtr_filler_shs));
135 auto hitCachePtr = std::get<0>(hitCachePtr_filler_ihd);
138 auto doublets = generator_.doublets(region, iEvent, iSetup, layerSet, *hitCachePtr);
139 LogTrace(
"HitPairEDProducer") <<
" created " <<
doublets.size() <<
" doublets for layers " << layerSet[0].index() <<
"," << layerSet[1].index();
141 seedingHitSetsProducer.fill(std::get<1>(hitCachePtr_filler_shs),
doublets);
142 intermediateHitDoubletsProducer.fill(std::get<1>(hitCachePtr_filler_ihd), layerSet,
std::move(
doublets));
146 seedingHitSetsProducer.put(iEvent);
147 intermediateHitDoubletsProducer.put(iEvent);
159 void reserve(
size_t) {}
162 return std::make_tuple(ptr, 0);
173 class ImplSeedingHitSets {
176 seedingHitSets_(std::make_unique<RegionsSeedingHitSets>()),
184 void reserve(
size_t regionsSize) {
185 seedingHitSets_->
reserve(regionsSize, localRA_->upper());
189 hitCacheTmp_.clear();
190 return std::make_tuple(&hitCacheTmp_, seedingHitSets_->beginRegion(region));
201 seedingHitSets_->shrink_to_fit();
202 localRA_->update(seedingHitSets_->size());
211 std::unique_ptr<RegionsSeedingHitSets> seedingHitSets_;
217 class ImplIntermediateHitDoublets {
220 intermediateHitDoublets_(std::make_unique<IntermediateHitDoublets>(layers)),
228 void reserve(
size_t regionsSize) {
229 intermediateHitDoublets_->
reserve(regionsSize, layers_->size());
233 auto filler = intermediateHitDoublets_->beginRegion(region);
242 intermediateHitDoublets_->shrink_to_fit();
251 std::unique_ptr<IntermediateHitDoublets> intermediateHitDoublets_;
265 if(produceSeedingHitSets && produceIntermediateHitDoublets)
266 impl_ = std::make_unique<::Impl<::ImplSeedingHitSets, ::ImplIntermediateHitDoublets>>(iConfig);
267 else if(produceSeedingHitSets)
268 impl_ = std::make_unique<::Impl<::ImplSeedingHitSets, ::DoNothing>>(iConfig);
269 else if(produceIntermediateHitDoublets)
270 impl_ = std::make_unique<::Impl<::DoNothing, ::ImplIntermediateHitDoublets>>(iConfig);
272 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";
275 if(clusterCheckTag.label() !=
"")
278 impl_->produces(*
this);
287 desc.
add<
bool>(
"produceSeedingHitSets",
false);
288 desc.
add<
bool>(
"produceIntermediateHitDoublets",
false);
289 desc.
add<
unsigned int>(
"maxElement", 1000000);
290 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.");
292 descriptions.
add(
"hitPairEDProducerDefault", desc);
296 bool clusterCheckOk =
true;
300 clusterCheckOk = *hclusterCheck;
305 const auto&
layers = *hlayers;
306 if(
layers.numberOfLayersInSet() < 2)
307 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.";
312 impl_->produce(
layers, *hregions, clusterCheckOk, iEvent, iSetup);
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)
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< edm::OwnVector< TrackingRegion > > regionToken_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void put(edm::Event &evt, double value, const char *instanceName)
TypeLabelItem const & produces()
declare what type of product will make and with which optional label
edm::EDGetTokenT< bool > clusterCheckToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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)
edm::EDGetTokenT< SeedingLayerSetsHits > seedingLayerToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~HitPairEDProducer()=default
produceIntermediateHitDoublets
Hit const & hit(int i, layer l) const
bool isUninitialized() const
unsigned short size() const
Get the number of SeedingLayerSets.