CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GenJetFlavourTableProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
9 
13 
18 
20 
23 
25 public:
27  : name_(iConfig.getParameter<std::string>("name")),
28  src_(consumes<std::vector<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("src"))),
29  cut_(iConfig.getParameter<std::string>("cut"), true),
30  deltaR_(iConfig.getParameter<double>("deltaR")),
32  consumes<reco::JetFlavourInfoMatchingCollection>(iConfig.getParameter<edm::InputTag>("jetFlavourInfos"))) {
33  produces<nanoaod::FlatTable>();
34  }
35 
37 
38  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
40  desc.add<edm::InputTag>("src")->setComment("input genJet collection");
41  desc.add<edm::InputTag>("jetFlavourInfos")->setComment("input flavour info collection");
42  desc.add<std::string>("name")->setComment("name of the genJet FlatTable we are extending with flavour information");
43  desc.add<std::string>("cut")->setComment("cut on input genJet collection");
44  desc.add<double>("deltaR")->setComment("deltaR to match genjets");
45  descriptions.add("genJetFlavourTable", desc);
46  }
47 
48 private:
49  void produce(edm::Event&, edm::EventSetup const&) override;
50 
54  const double deltaR_;
56 };
57 
58 // ------------ method called to produce the data ------------
61  iEvent.getByToken(src_, jets);
62 
64  iEvent.getByToken(jetFlavourInfosToken_, jetFlavourInfos);
65 
66  unsigned int ncand = 0;
67  std::vector<int> partonFlavour;
68  std::vector<uint8_t> hadronFlavour;
69 
70  for (const reco::GenJet& jet : *jets) {
71  if (!cut_(jet))
72  continue;
73  ++ncand;
74  bool matched = false;
75  for (const reco::JetFlavourInfoMatching& jetFlavourInfoMatching : *jetFlavourInfos) {
76  if (deltaR(jet.p4(), jetFlavourInfoMatching.first->p4()) < deltaR_) {
77  partonFlavour.push_back(jetFlavourInfoMatching.second.getPartonFlavour());
78  hadronFlavour.push_back(jetFlavourInfoMatching.second.getHadronFlavour());
79  matched = true;
80  break;
81  }
82  }
83  if (!matched) {
84  partonFlavour.push_back(0);
85  hadronFlavour.push_back(0);
86  }
87  }
88 
89  auto tab = std::make_unique<nanoaod::FlatTable>(ncand, name_, false, true);
90  tab->addColumn<int>("partonFlavour", partonFlavour, "flavour from parton matching");
91  tab->addColumn<uint8_t>("hadronFlavour", hadronFlavour, "flavour from hadron ghost clustering");
92 
93  iEvent.put(std::move(tab));
94 }
95 
97 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
GenJetFlavourTableProducer(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollection > jetFlavourInfosToken_
vector< PseudoJet > jets
def move
Definition: eostools.py:511
edm::EDGetTokenT< std::vector< reco::GenJet > > src_
Jets made from MC generator particles.
Definition: GenJet.h:23
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void produce(edm::Event &, edm::EventSetup const &) override
JetFlavourInfoMatchingCollection::value_type JetFlavourInfoMatching
const StringCutObjectSelector< reco::GenJet > cut_
void add(std::string const &label, ParameterSetDescription const &psetDescription)