CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Protected Attributes
pat::PATJetSelector Class Reference

#include <PATJetSelector.h>

Inheritance diagram for pat::PATJetSelector:
edm::stream::EDFilter<> edm::stream::EDFilterBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual void beginJob ()
 
virtual void endJob ()
 
bool filter (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 PATJetSelector (edm::ParameterSet const &params)
 
 ~PATJetSelector () override
 
- Public Member Functions inherited from edm::stream::EDFilter<>
 EDFilter ()=default
 
- Public Member Functions inherited from edm::stream::EDFilterBase
 EDFilterBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDFilterBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::stream::EDFilterBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Protected Attributes

const std::string cut_
 
const std::string cutLoose_
 
const bool filter_
 
const unsigned nLoose_
 
const StringCutObjectSelector< Jetselector_
 
const StringCutObjectSelector< JetselectorLoose_
 
const edm::EDGetTokenT< edm::View< pat::Jet > > srcToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDFilter<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDFilterBase
typedef EDFilterAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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.

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

Definition at line 44 of file PATJetSelector.h.

44 {}

Member Function Documentation

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

Definition at line 46 of file PATJetSelector.h.

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

Definition at line 47 of file PATJetSelector.h.

47 {}
static void pat::PATJetSelector::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 210 of file PATJetSelector.h.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

210  {
212  iDesc.setComment("Energy Correlation Functions adder");
213  iDesc.add<edm::InputTag>("src", edm::InputTag("no default"))->setComment("input collection");
214  iDesc.add<std::string> ("cut", "")->setComment("Jet selection.");
215  iDesc.add<std::string> ("cutLoose", "")->setComment("Loose jet selection. Will keep nLoose loose jets.");
216  iDesc.add<bool> ("filter", false)->setComment("Filter selection?");
217  iDesc.add<unsigned>("nLoose", 0)->setComment("Keep nLoose loose jets that satisfy cutLoose");
218  descriptions.add("PATJetSelector", iDesc);
219  }
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool pat::PATJetSelector::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
inlineoverride

Definition at line 49 of file PATJetSelector.h.

References edm::OwnVector< T, P >::begin(), edm::OwnVector< T, P >::end(), filter_, edm::Event::getByToken(), edm::Event::getRefBeforePut(), eostools::move(), nLoose_, nullptr, hemisphereProducer_cfi::patJets, edm::Event::put(), selector_, selectorLoose_, and srcToken_.

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

Member Data Documentation

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

Definition at line 223 of file PATJetSelector.h.

const std::string pat::PATJetSelector::cutLoose_
protected

Definition at line 224 of file PATJetSelector.h.

const bool pat::PATJetSelector::filter_
protected

Definition at line 225 of file PATJetSelector.h.

Referenced by filter().

const unsigned pat::PATJetSelector::nLoose_
protected

Definition at line 226 of file PATJetSelector.h.

Referenced by filter().

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

Definition at line 227 of file PATJetSelector.h.

Referenced by filter().

const StringCutObjectSelector<Jet> pat::PATJetSelector::selectorLoose_
protected

Definition at line 228 of file PATJetSelector.h.

Referenced by filter().

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

Definition at line 222 of file PATJetSelector.h.

Referenced by filter().