CMS 3D CMS Logo

L1TPFCandMultiMerger.cc
Go to the documentation of this file.
2 
11 #include <vector>
12 
14 public:
15  explicit L1TPFCandMultiMerger(const edm::ParameterSet&);
16  ~L1TPFCandMultiMerger() override;
17  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
18 
19 private:
20  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
21 
22  std::vector<std::string> instances_, regionalInstances_;
23  std::vector<bool> alsoRegional_; // aligned with instances_
24  std::vector<edm::EDGetTokenT<l1t::PFCandidateCollection>> tokens_;
25  std::vector<edm::EDGetTokenT<l1t::PFCandidateRegionalOutput>> regionalTokens_;
26 };
27 
29  : instances_(iConfig.getParameter<std::vector<std::string>>("labelsToMerge")),
30  regionalInstances_(iConfig.getParameter<std::vector<std::string>>("regionalLabelsToMerge")) {
31  const std::vector<edm::InputTag>& pfProducers = iConfig.getParameter<std::vector<edm::InputTag>>("pfProducers");
32  tokens_.reserve(instances_.size() * pfProducers.size());
33  for (const std::string& instance : instances_) {
34  for (const edm::InputTag& tag : pfProducers) {
35  tokens_.push_back(consumes<l1t::PFCandidateCollection>(edm::InputTag(tag.label(), instance, tag.process())));
36  }
37  produces<l1t::PFCandidateCollection>(instance);
38  // check if regional output is needed too
40  alsoRegional_.push_back(true);
41  for (const edm::InputTag& tag : pfProducers) {
42  regionalTokens_.push_back(
43  consumes<l1t::PFCandidateRegionalOutput>(edm::InputTag(tag.label(), instance + "Regional", tag.process())));
44  }
45  produces<l1t::PFCandidateRegionalOutput>(instance + "Regional");
46  } else {
47  alsoRegional_.push_back(false);
48  }
49  }
50  // check that regional output is not requested without the standard one
51  for (const std::string& instance : regionalInstances_) {
52  auto match = std::find(instances_.begin(), instances_.end(), instance);
53  if (match == instances_.end()) {
54  throw cms::Exception("Configuration", "The regional label '" + instance + "' is not in labelsToMerge\n");
55  }
56  }
57 }
58 
60 
64  unsigned int ninstances = instances_.size(), nproducers = tokens_.size() / ninstances;
65  std::vector<int> keys;
66  for (unsigned int ii = 0, it = 0, irt = 0; ii < ninstances; ++ii) {
67  auto out = std::make_unique<l1t::PFCandidateCollection>();
68  std::unique_ptr<l1t::PFCandidateRegionalOutput> regout;
69  if (alsoRegional_[ii]) {
70  auto refprod = iEvent.getRefBeforePut<l1t::PFCandidateCollection>(instances_[ii]);
71  regout = std::make_unique<l1t::PFCandidateRegionalOutput>(edm::RefProd<l1t::PFCandidateCollection>(refprod));
72  }
73  for (unsigned int ip = 0; ip < nproducers; ++ip, ++it) {
74  iEvent.getByToken(tokens_[it], handle);
75  unsigned int offset = out->size();
76  out->insert(out->end(), handle->begin(), handle->end());
77  if (alsoRegional_[ii]) {
78  iEvent.getByToken(regionalTokens_[irt++], regionalHandle);
79  const auto& src = *regionalHandle;
80  for (unsigned int ireg = 0, nreg = src.nRegions(); ireg < nreg; ++ireg) {
81  auto region = src.region(ireg);
82  keys.clear();
83  for (auto iter = region.begin(), iend = region.end(); iter != iend; ++iter) {
84  keys.push_back(iter.idx() + offset);
85  }
86  regout->addRegion(keys, src.eta(ireg), src.phi(ireg));
87  }
88  }
89  }
91  if (alsoRegional_[ii]) {
92  iEvent.put(std::move(regout), instances_[ii] + "Regional");
93  }
94  }
95 }
96 
98  // l1tLayer1
100  desc.add<std::vector<edm::InputTag>>("pfProducers",
101  {
102  edm::InputTag("l1tLayer1Barrel"),
103  edm::InputTag("l1tLayer1HGCal"),
104  edm::InputTag("l1tLayer1HGCalNoTK"),
105  edm::InputTag("l1tLayer1HF"),
106  });
107  desc.add<std::vector<std::string>>("labelsToMerge",
108  {
109  "PF",
110  "Puppi",
111  "Calo",
112  "TK",
113  });
114  desc.add<std::vector<std::string>>("regionalLabelsToMerge",
115  {
116  "Puppi",
117  });
118  descriptions.addWithDefaultLabel(desc);
119 }
120 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static PFTauRenderPlugin instance
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:86
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_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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