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 
32 
33 
34 template <class T, typename C = std::vector<typename T::ConstituentTypeFwdPtr>>
36 public:
37 
38  using JetsOutput = std::vector<T>;
40  using ValueType = typename C::value_type;
41 
43  srcToken_{consumes<edm::View<T>>(params.getParameter<edm::InputTag>("src"))},
44  selector_{params.getParameter<std::string>("cut")}
45  {
46  produces<JetsOutput>();
47  produces<ConstituentsOutput>("constituents");
48  }
49 
51  {
53  desc.add<edm::InputTag>("src")->setComment("InputTag used for retrieving jets in event.");
54  desc.add<std::string>("cut")->setComment("Cut used by which to select jets. For example:\n"
55  " \"pt > 100.0 && abs(rapidity()) < 2.4\".");
56 
57  // addDefault must be used here instead of add unless this function is specialized
58  // for different sets of template parameter types. Each specialization would need
59  // a different module label. Otherwise the generated cfi filenames will conflict
60  // for the different plugins.
61  descriptions.addDefault(desc);
62  }
63 
64  // Default initialization is for edm::FwdPtr. Specialization (below) is for edm::Ptr.
66  return typename ConstituentsOutput::value_type( dau, dau );
67  }
68 
69  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override
70  {
71  auto jets = std::make_unique<JetsOutput>();
72  auto candsOut = std::make_unique<ConstituentsOutput>();
73 
75  iEvent.getByToken(srcToken_, h_jets);
76 
77 
78  // Now set the Ptrs with the orphan handles.
79  for (auto const& jet : *h_jets) {
80  // Check the selection
81  if (selector_(jet)) {
82  // Add the jets that pass to the output collection
83  jets->push_back(jet);
84 
85  for (unsigned int ida {}; ida < jet.numberOfDaughters(); ++ida) {
86  candsOut->emplace_back( initptr(jet.daughterPtr(ida)) );
87  }
88  }
89  }
90 
91  iEvent.put(std::move(jets));
92  iEvent.put(std::move(candsOut), "constituents");
93  }
94 
95 private:
98 };
99 
100 template<>
103  edm::Ptr<pat::PackedCandidate> retval( dau );
104  return retval;
105 }
106 
107 template<>
110  edm::Ptr<pat::PackedGenParticle> retval( dau );
111  return retval;
112 }
113 
122 
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:127
StringCutObjectSelector< T > const selector_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#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
typename C::value_type ValueType
def move(src, dest)
Definition: eostools.py:510
ConstituentsOutput::value_type const initptr(edm::Ptr< reco::Candidate > const &dau) const