CMS 3D CMS Logo

SimpleJetConstituentTableProducer.cc
Go to the documentation of this file.
3 
6 
9 
13 
15 
18 
19 template <typename T>
21 public:
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
26 
27 private:
28  void produce(edm::Event &, const edm::EventSetup &) override;
29 
33 
36 
38 
40 };
41 
42 //
43 // constructors and destructor
44 //
45 template <typename T>
47  : name_(iConfig.getParameter<std::string>("name")),
48  candIdxName_(iConfig.getParameter<std::string>("candIdxName")),
49  candIdxDoc_(iConfig.getParameter<std::string>("candIdxDoc")),
50  jet_token_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("jets"))),
51  cand_token_(consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("candidates"))),
52  jetCut_(iConfig.getParameter<std::string>("jetCut")) {
53  produces<nanoaod::FlatTable>(name_);
54  produces<std::vector<reco::CandidatePtr>>();
55 }
56 
57 template <typename T>
59 
60 template <typename T>
62  // elements in all these collections must have the same order!
63  auto outCands = std::make_unique<std::vector<reco::CandidatePtr>>();
64 
65  auto jets = iEvent.getHandle(jet_token_);
66 
67  iEvent.getByToken(cand_token_, cands_);
68  auto candPtrs = cands_->ptrs();
69 
70  //
71  // First, select jets
72  //
73  std::vector<T> jetsPassCut;
74  for (unsigned jetIdx = 0; jetIdx < jets->size(); ++jetIdx) {
75  const auto &jet = jets->at(jetIdx);
76  if (!jetCut_(jet))
77  continue;
78  jetsPassCut.push_back(jets->at(jetIdx));
79  }
80 
81  //
82  // Then loop over selected jets
83  //
84  std::vector<int> parentJetIdx;
85  std::vector<int> candIdx;
86  for (unsigned jetIdx = 0; jetIdx < jetsPassCut.size(); ++jetIdx) {
87  const auto &jet = jetsPassCut.at(jetIdx);
88 
89  //
90  // Loop over jet constituents
91  //
92  std::vector<reco::CandidatePtr> const &daughters = jet.daughterPtrVector();
93  for (const auto &cand : daughters) {
94  auto candInNewList = std::find(candPtrs.begin(), candPtrs.end(), cand);
95  if (candInNewList == candPtrs.end()) {
96  continue;
97  }
98  outCands->push_back(cand);
99  parentJetIdx.push_back(jetIdx);
100  candIdx.push_back(candInNewList - candPtrs.begin());
101  }
102  } // end jet loop
103 
104  auto candTable = std::make_unique<nanoaod::FlatTable>(outCands->size(), name_, false);
105  // We fill from here only stuff that cannot be created with the SimpleFlatTableProducer
106  candTable->addColumn<int>(candIdxName_, candIdx, candIdxDoc_);
107 
108  std::string parentJetIdxName("jetIdx");
109  std::string parentJetIdxDoc("Index of the parent jet");
111  parentJetIdxName = "genJetIdx";
112  parentJetIdxDoc = "Index of the parent gen jet";
113  }
114  candTable->addColumn<int>(parentJetIdxName, parentJetIdx, parentJetIdxDoc);
115 
116  iEvent.put(std::move(candTable), name_);
117  iEvent.put(std::move(outCands));
118 }
119 
120 template <typename T>
123  desc.add<std::string>("name", "FatJetPFCand");
124  desc.add<std::string>("candIdxName", "PFCandIdx");
125  desc.add<std::string>("candIdxDoc", "Index in PFCand table");
126  desc.add<edm::InputTag>("jets", edm::InputTag("finalJetsAK8"));
127  desc.add<edm::InputTag>("candidates", edm::InputTag("packedPFCandidates"));
128  desc.add<std::string>("jetCut", "");
129  descriptions.addWithDefaultLabel(desc);
130 }
131 
134 
edm::EDGetTokenT< edm::View< T > > jet_token_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
SimpleJetConstituentTableProducer< pat::Jet > SimplePatJetConstituentTableProducer
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
const StringCutObjectSelector< T > jetCut_
SimpleJetConstituentTableProducer< reco::GenJet > SimpleGenJetConstituentTableProducer
void produce(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SimpleJetConstituentTableProducer(const edm::ParameterSet &)
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::CandidateView > cand_token_
long double T
def move(src, dest)
Definition: eostools.py:511
edm::View< Candidate > CandidateView
view of a collection containing candidates
Definition: CandidateFwd.h:23
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)