CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes
pat::PATJetSelector Class Reference

#include <PATJetSelector.h>

Inheritance diagram for pat::PATJetSelector:
edm::EDFilter edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual void beginJob ()
 
virtual void endJob ()
 
virtual bool filter (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 PATJetSelector (edm::ParameterSet const &params)
 
virtual ~PATJetSelector ()
 
- Public Member Functions inherited from edm::EDFilter
 EDFilter ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDFilter ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Protected Attributes

std::string cut_
 
bool filter_
 
StringCutObjectSelector< Jetselector_
 
edm::EDGetTokenT< edm::View
< pat::Jet > > 
srcToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDFilter
typedef EDFilter ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDFilter
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 24 of file PATJetSelector.h.

Constructor & Destructor Documentation

pat::PATJetSelector::PATJetSelector ( edm::ParameterSet const &  params)
inline

Definition at line 28 of file PATJetSelector.h.

References edm::ParameterSet::exists(), filter_, and edm::ParameterSet::getParameter().

28  :
29  edm::EDFilter( ),
30  srcToken_(consumes<edm::View<pat::Jet> >( params.getParameter<edm::InputTag>("src") )),
31  cut_( params.getParameter<std::string>("cut") ),
32  filter_(false),
33  selector_( cut_ )
34  {
35  produces< std::vector<pat::Jet> >();
36  produces<reco::GenJetCollection> ("genJets");
37  produces<std::vector<CaloTower> > ("caloTowers");
38  produces<reco::PFCandidateCollection > ("pfCandidates");
39  produces<edm::OwnVector<reco::BaseTagInfo> > ("tagInfos");
40 
41  if ( params.exists("filter") ) {
42  filter_ = params.getParameter<bool>("filter");
43  }
44  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
StringCutObjectSelector< Jet > selector_
edm::EDGetTokenT< edm::View< pat::Jet > > srcToken_
virtual pat::PATJetSelector::~PATJetSelector ( )
inlinevirtual

Definition at line 46 of file PATJetSelector.h.

46 {}

Member Function Documentation

virtual void pat::PATJetSelector::beginJob ( void  )
inlinevirtual

Reimplemented from edm::EDFilter.

Definition at line 48 of file PATJetSelector.h.

48 {}
virtual void pat::PATJetSelector::endJob ( void  )
inlinevirtual

Reimplemented from edm::EDFilter.

Definition at line 49 of file PATJetSelector.h.

49 {}
virtual bool pat::PATJetSelector::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
inlineoverridevirtual

Implements edm::EDFilter.

Definition at line 51 of file PATJetSelector.h.

References edm::OwnVector< T, P >::begin(), edm::OwnVector< T, P >::end(), filter_, edm::Event::getByToken(), edm::Event::getRefBeforePut(), jetProducer_cfi::patJets, edm::Event::put(), selector_, and srcToken_.

51  {
52 
53  std::auto_ptr< std::vector<Jet> > patJets ( new std::vector<Jet>() );
54 
55  std::auto_ptr<reco::GenJetCollection > genJetsOut ( new reco::GenJetCollection() );
56  std::auto_ptr<std::vector<CaloTower> > caloTowersOut( new std::vector<CaloTower> () );
57  std::auto_ptr<reco::PFCandidateCollection > pfCandidatesOut( new reco::PFCandidateCollection() );
58  std::auto_ptr<edm::OwnVector<reco::BaseTagInfo> > tagInfosOut ( new edm::OwnVector<reco::BaseTagInfo>() );
59 
60 
62  edm::RefProd<std::vector<CaloTower> > h_caloTowersOut = iEvent.getRefBeforePut<std::vector<CaloTower> > ( "caloTowers" );
63  edm::RefProd<reco::PFCandidateCollection > h_pfCandidatesOut = iEvent.getRefBeforePut<reco::PFCandidateCollection > ( "pfCandidates" );
65 
67  iEvent.getByToken( srcToken_, h_jets );
68 
69  // First loop over the products and make the secondary output collections
70  for ( edm::View<pat::Jet>::const_iterator ibegin = h_jets->begin(),
71  iend = h_jets->end(), ijet = ibegin;
72  ijet != iend; ++ijet ) {
73 
74  // Check the selection
75  if ( selector_(*ijet) ) {
76  // Copy over the calo towers
77  for ( CaloTowerFwdPtrVector::const_iterator itowerBegin = ijet->caloTowersFwdPtr().begin(),
78  itowerEnd = ijet->caloTowersFwdPtr().end(), itower = itowerBegin;
79  itower != itowerEnd; ++itower ) {
80  // Add to global calo tower list
81  caloTowersOut->push_back( **itower );
82  }
83 
84 
85  // Copy over the pf candidates
86  for ( reco::PFCandidateFwdPtrVector::const_iterator icandBegin = ijet->pfCandidatesFwdPtr().begin(),
87  icandEnd = ijet->pfCandidatesFwdPtr().end(), icand = icandBegin;
88  icand != icandEnd; ++icand ) {
89  // Add to global pf candidate list
90  pfCandidatesOut->push_back( **icand );
91  }
92 
93  // Copy the tag infos
94  for ( TagInfoFwdPtrCollection::const_iterator iinfoBegin = ijet->tagInfosFwdPtr().begin(),
95  iinfoEnd = ijet->tagInfosFwdPtr().end(), iinfo = iinfoBegin;
96  iinfo != iinfoEnd; ++iinfo ) {
97  // Add to global calo tower list
98  tagInfosOut->push_back( **iinfo );
99  }
100 
101  // Copy the gen jet
102  if ( ijet->genJet() != 0 ) {
103  genJetsOut->push_back( *(ijet->genJet()) );
104  }
105 
106  }
107  }
108 
109 
110  // Output the secondary collections.
111  edm::OrphanHandle<reco::GenJetCollection> oh_genJetsOut = iEvent.put( genJetsOut, "genJets" );
112  edm::OrphanHandle<std::vector<CaloTower> > oh_caloTowersOut = iEvent.put( caloTowersOut, "caloTowers" );
113  edm::OrphanHandle<reco::PFCandidateCollection> oh_pfCandidatesOut = iEvent.put( pfCandidatesOut, "pfCandidates" );
114  edm::OrphanHandle<edm::OwnVector<reco::BaseTagInfo> > oh_tagInfosOut = iEvent.put( tagInfosOut, "tagInfos" );
115 
116 
117 
118 
119 
120  unsigned int caloTowerIndex = 0;
121  unsigned int pfCandidateIndex = 0;
122  unsigned int tagInfoIndex = 0;
123  unsigned int genJetIndex = 0;
124  // Now set the Ptrs with the orphan handles.
125  for ( edm::View<pat::Jet>::const_iterator ibegin = h_jets->begin(),
126  iend = h_jets->end(), ijet = ibegin;
127  ijet != iend; ++ijet ) {
128 
129  // Check the selection
130  if ( selector_(*ijet) ) {
131  // Add the jets that pass to the output collection
132  patJets->push_back( *ijet );
133 
134  // Copy over the calo towers
135  for ( CaloTowerFwdPtrVector::const_iterator itowerBegin = ijet->caloTowersFwdPtr().begin(),
136  itowerEnd = ijet->caloTowersFwdPtr().end(), itower = itowerBegin;
137  itower != itowerEnd; ++itower ) {
138  // Update the "forward" bit of the FwdPtr to point at the new tower collection.
139 
140  // ptr to "this" tower in the global list
141  edm::Ptr<CaloTower> outPtr( oh_caloTowersOut, caloTowerIndex);
142  patJets->back().updateFwdCaloTowerFwdPtr( itower - itowerBegin,// index of "this" tower in the jet
143  outPtr
144  );
145  ++caloTowerIndex;
146  }
147 
148 
149  // Copy over the pf candidates
150  for ( reco::PFCandidateFwdPtrVector::const_iterator icandBegin = ijet->pfCandidatesFwdPtr().begin(),
151  icandEnd = ijet->pfCandidatesFwdPtr().end(), icand = icandBegin;
152  icand != icandEnd; ++icand ) {
153  // Update the "forward" bit of the FwdPtr to point at the new tower collection.
154 
155  // ptr to "this" cand in the global list
156  edm::Ptr<reco::PFCandidate> outPtr( oh_pfCandidatesOut, pfCandidateIndex );
157  patJets->back().updateFwdPFCandidateFwdPtr( icand - icandBegin,// index of "this" tower in the jet
158  outPtr
159  );
160  ++pfCandidateIndex;
161  }
162 
163  // Copy the tag infos
164  for ( TagInfoFwdPtrCollection::const_iterator iinfoBegin = ijet->tagInfosFwdPtr().begin(),
165  iinfoEnd = ijet->tagInfosFwdPtr().end(), iinfo = iinfoBegin;
166  iinfo != iinfoEnd; ++iinfo ) {
167  // Update the "forward" bit of the FwdPtr to point at the new tower collection.
168 
169  // ptr to "this" info in the global list
170  edm::Ptr<reco::BaseTagInfo > outPtr( oh_tagInfosOut, tagInfoIndex );
171  patJets->back().updateFwdTagInfoFwdPtr( iinfo - iinfoBegin,// index of "this" tower in the jet
172  outPtr
173  );
174  ++tagInfoIndex;
175  }
176 
177  // Copy the gen jet
178  if ( ijet->genJet() != 0 ) {
179  patJets->back().updateFwdGenJetFwdRef( edm::Ref<reco::GenJetCollection>( oh_genJetsOut, genJetIndex) // ref to "this" genjet in the global list
180  );
181  ++genJetIndex;
182  }
183 
184  }
185  }
186 
187 
188  // put genEvt in Event
189  bool pass = patJets->size() > 0;
190  iEvent.put(patJets);
191 
192  if ( filter_ )
193  return pass;
194  else
195  return true;
196  }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
std::vector< GenJet > GenJetCollection
collection of GenJet objects
iterator begin()
Definition: OwnVector.h:228
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
StringCutObjectSelector< Jet > selector_
RefProd< PROD > getRefBeforePut()
Definition: Event.h:128
edm::EDGetTokenT< edm::View< pat::Jet > > srcToken_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
iterator end()
Definition: OwnVector.h:233

Member Data Documentation

std::string pat::PATJetSelector::cut_
protected

Definition at line 200 of file PATJetSelector.h.

bool pat::PATJetSelector::filter_
protected

Definition at line 201 of file PATJetSelector.h.

Referenced by filter(), and PATJetSelector().

StringCutObjectSelector<Jet> pat::PATJetSelector::selector_
protected

Definition at line 202 of file PATJetSelector.h.

Referenced by filter().

edm::EDGetTokenT<edm::View<pat::Jet> > pat::PATJetSelector::srcToken_
protected

Definition at line 199 of file PATJetSelector.h.

Referenced by filter().