CMS 3D CMS Logo

L1TPFCandMultiMerger.cc
Go to the documentation of this file.
2 
9 #include <vector>
10 
12 public:
13  explicit L1TPFCandMultiMerger(const edm::ParameterSet&);
14  ~L1TPFCandMultiMerger() override;
15 
16 private:
17  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
18 
19  std::vector<std::string> instances_, regionalInstances_;
20  std::vector<bool> alsoRegional_; // aligned with instances_
21  std::vector<edm::EDGetTokenT<l1t::PFCandidateCollection>> tokens_;
22  std::vector<edm::EDGetTokenT<l1t::PFCandidateRegionalOutput>> regionalTokens_;
23 };
24 
26  : instances_(iConfig.getParameter<std::vector<std::string>>("labelsToMerge")),
27  regionalInstances_(iConfig.getParameter<std::vector<std::string>>("regionalLabelsToMerge")) {
28  const std::vector<edm::InputTag>& pfProducers = iConfig.getParameter<std::vector<edm::InputTag>>("pfProducers");
29  tokens_.reserve(instances_.size() * pfProducers.size());
30  for (const std::string& instance : instances_) {
31  for (const edm::InputTag& tag : pfProducers) {
32  tokens_.push_back(consumes<l1t::PFCandidateCollection>(edm::InputTag(tag.label(), instance, tag.process())));
33  }
34  produces<l1t::PFCandidateCollection>(instance);
35  // check if regional output is needed too
37  alsoRegional_.push_back(true);
38  for (const edm::InputTag& tag : pfProducers) {
39  regionalTokens_.push_back(
40  consumes<l1t::PFCandidateRegionalOutput>(edm::InputTag(tag.label(), instance + "Regional", tag.process())));
41  }
42  produces<l1t::PFCandidateRegionalOutput>(instance + "Regional");
43  } else {
44  alsoRegional_.push_back(false);
45  }
46  }
47  // check that regional output is not requested without the standard one
48  for (const std::string& instance : regionalInstances_) {
49  auto match = std::find(instances_.begin(), instances_.end(), instance);
50  if (match == instances_.end()) {
51  throw cms::Exception("Configuration", "The regional label '" + instance + "' is not in labelsToMerge\n");
52  }
53  }
54 }
55 
57 
61  unsigned int ninstances = instances_.size(), nproducers = tokens_.size() / ninstances;
62  std::vector<int> keys;
63  for (unsigned int ii = 0, it = 0, irt = 0; ii < ninstances; ++ii) {
64  auto out = std::make_unique<l1t::PFCandidateCollection>();
65  std::unique_ptr<l1t::PFCandidateRegionalOutput> regout;
66  if (alsoRegional_[ii]) {
67  auto refprod = iEvent.getRefBeforePut<l1t::PFCandidateCollection>(instances_[ii]);
68  regout = std::make_unique<l1t::PFCandidateRegionalOutput>(edm::RefProd<l1t::PFCandidateCollection>(refprod));
69  }
70  for (unsigned int ip = 0; ip < nproducers; ++ip, ++it) {
71  iEvent.getByToken(tokens_[it], handle);
72  unsigned int offset = out->size();
73  out->insert(out->end(), handle->begin(), handle->end());
74  if (alsoRegional_[ii]) {
75  iEvent.getByToken(regionalTokens_[irt++], regionalHandle);
76  const auto& src = *regionalHandle;
77  for (unsigned int ireg = 0, nreg = src.nRegions(); ireg < nreg; ++ireg) {
78  auto region = src.region(ireg);
79  keys.clear();
80  for (auto iter = region.begin(), iend = region.end(); iter != iend; ++iter) {
81  keys.push_back(iter.idx() + offset);
82  }
83  regout->addRegion(keys, src.eta(ireg), src.phi(ireg));
84  }
85  }
86  }
88  if (alsoRegional_[ii]) {
89  iEvent.put(std::move(regout), instances_[ii] + "Regional");
90  }
91  }
92 }
93 
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static PFTauRenderPlugin instance
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:82
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
int iEvent
Definition: GenABIO.cc:224
std::vector< bool > alsoRegional_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ii
Definition: cuy.py:589
std::vector< edm::EDGetTokenT< l1t::PFCandidateCollection > > tokens_
std::vector< std::string > instances_
L1TPFCandMultiMerger(const edm::ParameterSet &)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::vector< edm::EDGetTokenT< l1t::PFCandidateRegionalOutput > > regionalTokens_
std::vector< std::string > regionalInstances_
def move(src, dest)
Definition: eostools.py:511