CMS 3D CMS Logo

JetConstituentSelector.cc
Go to the documentation of this file.
1 /* \class PFJetSelector
2  *
3  * Selects jets with a configurable string-based cut,
4  * and also writes out the constituents of the jet
5  * into a separate collection.
6  *
7  * \author: Sal Rappoccio
8  *
9  *
10  * for more details about the cut syntax, see the documentation
11  * page below:
12  *
13  * https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePhysicsCutParser
14  *
15  */
16 
30 
31 template <class T, typename C = std::vector<typename T::ConstituentTypeFwdPtr>>
33 public:
34  using JetsOutput = std::vector<T>;
36  using ValueType = typename C::value_type;
37 
39  : srcToken_{consumes<edm::View<T>>(params.getParameter<edm::InputTag>("src"))},
40  selector_{params.getParameter<std::string>("cut")} {
41  produces<JetsOutput>();
42  produces<ConstituentsOutput>("constituents");
43  }
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
47  desc.add<edm::InputTag>("src", edm::InputTag(""))->setComment("InputTag used for retrieving jets in event.");
48  desc.add<std::string>("cut", "")->setComment(
49  "Cut used by which to select jets. For example:\n \"pt > 100.0 && abs(rapidity()) < 2.4\".");
50  descriptions.addWithDefaultLabel(desc);
51  }
52 
53  // Default initialization is for edm::FwdPtr. Specialization (below) is for edm::Ptr.
55  return typename ConstituentsOutput::value_type(dau, dau);
56  }
57 
58  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override {
59  auto jets = std::make_unique<JetsOutput>();
60  auto candsOut = std::make_unique<ConstituentsOutput>();
61 
63  iEvent.getByToken(srcToken_, h_jets);
64 
65  // Now set the Ptrs with the orphan handles.
66  for (auto const& jet : *h_jets) {
67  // Check the selection
68  if (selector_(jet)) {
69  // Add the jets that pass to the output collection
70  jets->push_back(jet);
71 
72  for (unsigned int ida{}; ida < jet.numberOfDaughters(); ++ida) {
73  candsOut->emplace_back(initptr(jet.daughterPtr(ida)));
74  }
75  }
76  }
77 
78  iEvent.put(std::move(jets));
79  iEvent.put(std::move(candsOut), "constituents");
80  }
81 
82 private:
85 };
86 
87 template <>
90  edm::Ptr<reco::Candidate> const& dau) const {
92  return retval;
93 }
94 
95 template <>
98  edm::Ptr<reco::Candidate> const& dau) const {
100  return retval;
101 }
102 
115 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ConstituentsOutput::value_type const initptr(edm::Ptr< reco::Candidate > const &dau) const
StringCutObjectSelector< T > const selector_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
JetConstituentSelector(edm::ParameterSet const &params)
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::View< T > > const srcToken_
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
typename C::value_type ValueType
def move(src, dest)
Definition: eostools.py:511