CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  */
17 
18 
20 
26 
30 
31 template < class T, typename C = std::vector<typename T::ConstituentTypeFwdPtr> >
33 
34 public:
35 
36  typedef std::vector<T> JetsOutput;
38 
40  srcToken_( consumes< typename edm::View<T> >( params.getParameter<edm::InputTag>("src") ) ),
41  cut_( params.getParameter<std::string>("cut") ),
42  filter_(false),
43  selector_( cut_ )
44  {
45  produces< JetsOutput >();
46  produces< ConstituentsOutput > ("constituents");
47  }
48 
50 
51  virtual void beginJob() override {}
52  virtual void endJob() override {}
53 
54  virtual bool filter(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
55 
56  std::auto_ptr< JetsOutput > jets ( new std::vector<T>() );
57  std::auto_ptr< ConstituentsOutput > candsOut( new ConstituentsOutput );
58 
60  iEvent.getByToken( srcToken_, h_jets );
61 
62  // Now set the Ptrs with the orphan handles.
63  for ( typename edm::View<T>::const_iterator ibegin = h_jets->begin(),
64  iend = h_jets->end(), ijet = ibegin;
65  ijet != iend; ++ijet ) {
66 
67  // Check the selection
68  if ( selector_(*ijet) ) {
69  // Add the jets that pass to the output collection
70  jets->push_back( *ijet );
71  for ( unsigned int ida = 0; ida < ijet->numberOfDaughters(); ++ida ) {
72  candsOut->push_back( typename ConstituentsOutput::value_type( ijet->daughterPtr(ida), ijet->daughterPtr(ida) ) );
73  }
74  }
75  }
76 
77  // put in Event
78  bool pass = jets->size() > 0;
79  iEvent.put(jets);
80  iEvent.put(candsOut, "constituents");
81 
82  if ( filter_ )
83  return pass;
84  else
85  return true;
86 
87  }
88 
89  protected:
92  bool filter_;
94 
95 };
96 
100 
JetConstituentSelector< reco::PFJet, std::vector< edm::FwdPtr< pat::PackedCandidate > > > MiniAODJetConstituentSelector
JetConstituentSelector< reco::PFJet > PFJetConstituentSelector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void endJob() override
JetConstituentSelector(edm::ParameterSet const &params)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
StringCutObjectSelector< T > selector_
edm::EDGetTokenT< typename edm::View< T > > srcToken_
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
vector< PseudoJet > jets
Container::value_type value_type
JetConstituentSelector< pat::Jet, std::vector< edm::FwdPtr< pat::PackedCandidate > > > PatJetConstituentSelector
volatile std::atomic< bool > shutdown_flag false
long double T
virtual void beginJob() override
virtual bool filter(edm::Event &iEvent, const edm::EventSetup &iSetup) override