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 
28 
29 template <class T, typename C = std::vector<typename T::ConstituentTypeFwdPtr>>
31 public:
32 
33  using JetsOutput = std::vector<T>;
35 
37  srcToken_{consumes<edm::View<T>>(params.getParameter<edm::InputTag>("src"))},
38  selector_{params.getParameter<std::string>("cut")}
39  {
40  produces<JetsOutput>();
41  produces<ConstituentsOutput>("constituents");
42  }
43 
45  {
47  desc.add<edm::InputTag>("src")->setComment("InputTag used for retrieving jets in event.");
48  desc.add<std::string>("cut")->setComment("Cut used by which to select jets. For example:\n"
49  " \"pt > 100.0 && abs(rapidity()) < 2.4\".");
50  descriptions.add("JetConsituentSelector", desc);
51  }
52 
53  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override
54  {
55  auto jets = std::make_unique<JetsOutput>();
56  auto candsOut = std::make_unique<ConstituentsOutput>();
57 
59  iEvent.getByToken(srcToken_, h_jets);
60 
61  // Now set the Ptrs with the orphan handles.
62  for (auto const& jet : *h_jets) {
63  // Check the selection
64  if (selector_(jet)) {
65  // Add the jets that pass to the output collection
66  jets->push_back(jet);
67  for (unsigned int ida {}; ida < jet.numberOfDaughters(); ++ida) {
68  candsOut->emplace_back(jet.daughterPtr(ida), jet.daughterPtr(ida));
69  }
70  }
71  }
72 
73  iEvent.put(std::move(jets));
74  iEvent.put(std::move(candsOut), "constituents");
75  }
76 
77 private:
80 };
81 
85 
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:122
StringCutObjectSelector< T > const selector_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
JetConstituentSelector(edm::ParameterSet const &params)
int iEvent
Definition: GenABIO.cc:230
vector< PseudoJet > jets
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< edm::View< T > > const srcToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
def move(src, dest)
Definition: eostools.py:510