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 
29 
30 template <class T, typename C = std::vector<typename T::ConstituentTypeFwdPtr>>
32 public:
33 
34  using JetsOutput = std::vector<T>;
36 
38  srcToken_{consumes<edm::View<T>>(params.getParameter<edm::InputTag>("src"))},
39  selector_{params.getParameter<std::string>("cut")}
40  {
41  produces<JetsOutput>();
42  produces<ConstituentsOutput>("constituents");
43  }
44 
46  {
48  desc.add<edm::InputTag>("src")->setComment("InputTag used for retrieving jets in event.");
49  desc.add<std::string>("cut")->setComment("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  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override
60  {
61  auto jets = std::make_unique<JetsOutput>();
62  auto candsOut = std::make_unique<ConstituentsOutput>();
63 
65  iEvent.getByToken(srcToken_, h_jets);
66 
67  // Now set the Ptrs with the orphan handles.
68  for (auto const& jet : *h_jets) {
69  // Check the selection
70  if (selector_(jet)) {
71  // Add the jets that pass to the output collection
72  jets->push_back(jet);
73  for (unsigned int ida {}; ida < jet.numberOfDaughters(); ++ida) {
74  candsOut->emplace_back(jet.daughterPtr(ida), jet.daughterPtr(ida));
75  }
76  }
77  }
78 
79  iEvent.put(std::move(jets));
80  iEvent.put(std::move(candsOut), "constituents");
81  }
82 
83 private:
86 };
87 
92 
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:136
StringCutObjectSelector< T > const selector_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#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