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")->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"
50  " \"pt > 100.0 && abs(rapidity()) < 2.4\".");
51 
52  // addDefault must be used here instead of add unless this function is specialized
53  // for different sets of template parameter types. Each specialization would need
54  // a different module label. Otherwise the generated cfi filenames will conflict
55  // for the different plugins.
56  descriptions.addDefault(desc);
57  }
58 
59  // Default initialization is for edm::FwdPtr. Specialization (below) is for edm::Ptr.
61  return typename ConstituentsOutput::value_type(dau, dau);
62  }
63 
64  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override {
65  auto jets = std::make_unique<JetsOutput>();
66  auto candsOut = std::make_unique<ConstituentsOutput>();
67 
69  iEvent.getByToken(srcToken_, h_jets);
70 
71  // Now set the Ptrs with the orphan handles.
72  for (auto const& jet : *h_jets) {
73  // Check the selection
74  if (selector_(jet)) {
75  // Add the jets that pass to the output collection
76  jets->push_back(jet);
77 
78  for (unsigned int ida{}; ida < jet.numberOfDaughters(); ++ida) {
79  candsOut->emplace_back(initptr(jet.daughterPtr(ida)));
80  }
81  }
82  }
83 
84  iEvent.put(std::move(jets));
85  iEvent.put(std::move(candsOut), "constituents");
86  }
87 
88 private:
91 };
92 
93 template <>
96  edm::Ptr<reco::Candidate> const& dau) const {
98  return retval;
99 }
100 
101 template <>
104  edm::Ptr<reco::Candidate> const& dau) const {
106  return retval;
107 }
108 
121 
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
StringCutObjectSelector< T > const selector_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
JetConstituentSelector(edm::ParameterSet const &params)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
ConstituentsOutput::value_type const initptr(edm::Ptr< reco::Candidate > const &dau) const