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