CMS 3D CMS Logo

MultiHitFromChi2EDProducer.cc
Go to the documentation of this file.
10 
16 
18 public:
20  ~MultiHitFromChi2EDProducer() override = default;
21 
22  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
23 
24  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
25 
26 private:
28 
30 
32 };
33 
35  doubletToken_(consumes<IntermediateHitDoublets>(iConfig.getParameter<edm::InputTag>("doublets"))),
36  generator_(iConfig)
37 {
38  produces<RegionsSeedingHitSets>();
39  produces<edm::OwnVector<BaseTrackerRecHit> >();
40 }
41 
44 
45  desc.add<edm::InputTag>("doublets", edm::InputTag("hitPairEDProducer"));
46 
48 
50  descriptions.add(label, desc);
51 }
52 
55  iEvent.getByToken(doubletToken_, hdoublets);
56  const auto& regionDoublets = *hdoublets;
57 
58  const SeedingLayerSetsHits& seedingLayerHits = regionDoublets.seedingLayerHits();
59  if(seedingLayerHits.numberOfLayersInSet() < 3) {
60  throw cms::Exception("LogicError") << "MultiHitFromChi2EDProducer expects SeedingLayerSetsHits::numberOfLayersInSet() to be >= 3, got " << seedingLayerHits.numberOfLayersInSet() << ". This is likely caused by a configuration error of this module, HitPairEDProducer, or SeedingLayersEDProducer.";
61  }
62 
63  auto seedingHitSets = std::make_unique<RegionsSeedingHitSets>();
64  if(regionDoublets.empty()) {
65  iEvent.put(std::move(seedingHitSets));
66  return;
67  }
68  seedingHitSets->reserve(regionDoublets.regionSize(), localRA_.upper());
69  generator_.initES(iSetup);
70 
71  // match-making of pair and triplet layers
72  std::vector<LayerTriplets::LayerSetAndLayers> trilayers = LayerTriplets::layers(seedingLayerHits);
73 
74  OrderedMultiHits multihits;
75  multihits.reserve(localRA_.upper());
76  std::vector<std::unique_ptr<BaseTrackerRecHit> > refittedHitStorage;
77  refittedHitStorage.reserve(localRA_.upper()*2);
78 
79  LogDebug("MultiHitFromChi2EDProducer") << "Creating multihits for " << regionDoublets.regionSize() << " regions, and " << trilayers.size() << " pair+3rd layers from " << regionDoublets.layerPairsSize() << " layer pairs";
80 
81  LayerHitMapCache hitCache;
82  for(const auto& regionLayerPairs: regionDoublets) {
83  const TrackingRegion& region = regionLayerPairs.region();
84 
85  auto seedingHitSetsFiller = RegionsSeedingHitSets::dummyFiller();
86  seedingHitSetsFiller = seedingHitSets->beginRegion(&region);
87 
88  hitCache.clear();
89  hitCache.extend(regionLayerPairs.layerHitMapCache());
90 
91  LogTrace("MultiHitFromChi2EDProducer") << " starting region";
92 
93  for(const auto& layerPair: regionLayerPairs) {
94  LogTrace("MultiHitFromChi2EDProducer") << " starting layer pair " << layerPair.innerLayerIndex() << "," << layerPair.outerLayerIndex();
95 
96  auto found = std::find_if(trilayers.begin(), trilayers.end(), [&](const LayerTriplets::LayerSetAndLayers& a) {
97  return a.first[0].index() == layerPair.innerLayerIndex() && a.first[1].index() == layerPair.outerLayerIndex();
98  });
99  if(found == trilayers.end()) {
100  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";
101  exp << "I was looking for layer pair " << layerPair.innerLayerIndex() << "," << layerPair.outerLayerIndex() << ". Triplets have the following pairs:\n";
102  for(const auto& a: trilayers) {
103  exp << " " << a.first[0].index() << "," << a.first[1].index() << ": 3rd layers";
104  for(const auto& b: a.second) {
105  exp << " " << b.index();
106  }
107  exp << "\n";
108  }
109  throw exp;
110  }
111  const auto& thirdLayers = found->second;
112 
113  generator_.hitSets(region, multihits, iEvent, iSetup, layerPair.doublets(), thirdLayers, hitCache, refittedHitStorage);
114 
115 #ifdef EDM_ML_DEBUG
116  LogTrace("MultiHitFromChi2EDProducer") << " created " << multihits.size() << " multihits for layer pair " << layerPair.innerLayerIndex() << "," << layerPair.outerLayerIndex() << " and 3rd layers";
117  for(const auto& l: thirdLayers) {
118  LogTrace("MultiHitFromChi2EDProducer") << " " << l.index();
119  }
120 #endif
121 
122  for(const SeedingHitSet& hitSet: multihits) {
123  seedingHitSetsFiller.emplace_back(hitSet);
124  }
125  multihits.clear();
126  }
127  }
128  localRA_.update(seedingHitSets->size());
129 
130  auto storage = std::make_unique<edm::OwnVector<BaseTrackerRecHit> >();
131  storage->reserve(refittedHitStorage.size());
132  for(auto& ptr: refittedHitStorage)
133  storage->push_back(ptr.release());
134 
135  seedingHitSets->shrink_to_fit();
136  storage->shrink_to_fit();
137  iEvent.put(std::move(seedingHitSets));
138  iEvent.put(std::move(storage));
139 }
140 
#define LogDebug(id)
unsigned short numberOfLayersInSet() const
Get number of layers in each SeedingLayerSets.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
unsigned int size() const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int upper() const
~MultiHitFromChi2EDProducer() override=default
int iEvent
Definition: GenABIO.cc:230
static RegionFiller dummyFiller()
void initES(const edm::EventSetup &es) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define LogTrace(id)
std::pair< LayerSet, std::vector< Layer > > LayerSetAndLayers
Definition: LayerTriplets.h:16
MultiHitGeneratorFromChi2 generator_
void hitSets(const TrackingRegion &region, OrderedMultiHits &trs, const edm::Event &ev, const edm::EventSetup &es, SeedingLayerSetsHits::SeedingLayerSet pairLayers, std::vector< SeedingLayerSetsHits::SeedingLayer > thirdLayers) override
double b
Definition: hdecay.h:120
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static const char * fillDescriptionsLabel()
void extend(const LayerHitMapCache &other)
HLT enums.
double a
Definition: hdecay.h:121
static void fillDescriptions(edm::ParameterSetDescription &desc)
edm::EDGetTokenT< IntermediateHitDoublets > doubletToken_
def move(src, dest)
Definition: eostools.py:510
void update(unsigned int q)
MultiHitFromChi2EDProducer(const edm::ParameterSet &iConfig)