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 
51  // addDefault must be used here instead of add unless this function is specialized
52  // for different sets of template parameter types. Each specialization would need
53  // a different module label. Otherwise the generated cfi filenames will conflict
54  // for the different plugins.
55  descriptions.addDefault(desc);
56  }
57 
58  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override
59  {
60  auto jets = std::make_unique<JetsOutput>();
61  auto candsOut = std::make_unique<ConstituentsOutput>();
62 
64  iEvent.getByToken(srcToken_, h_jets);
65 
66  // Now set the Ptrs with the orphan handles.
67  for (auto const& jet : *h_jets) {
68  // Check the selection
69  if (selector_(jet)) {
70  // Add the jets that pass to the output collection
71  jets->push_back(jet);
72  for (unsigned int ida {}; ida < jet.numberOfDaughters(); ++ida) {
73  candsOut->emplace_back(jet.daughterPtr(ida), 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 
90 
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:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
JetConstituentSelector(edm::ParameterSet const &params)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
vector< PseudoJet > jets
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
def move(src, dest)
Definition: eostools.py:510