CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
PFMatchedCandidateRefExtractor Class Reference
Inheritance diagram for PFMatchedCandidateRefExtractor:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PFMatchedCandidateRefExtractor (const edm::ParameterSet &iConfig)
 
void produce (edm::StreamID iID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 
 ~PFMatchedCandidateRefExtractor () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () 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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- 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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

edm::EDGetTokenT< edm::View< reco::Candidate > > col1Token_
 
edm::EDGetTokenT< edm::View< reco::Candidate > > col2Token_
 
bool extractPFCands_
 
std::string moduleLabel_
 
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandToken_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 15 of file PFMatchedCandidateRefExtractor.cc.

Constructor & Destructor Documentation

◆ PFMatchedCandidateRefExtractor()

PFMatchedCandidateRefExtractor::PFMatchedCandidateRefExtractor ( const edm::ParameterSet iConfig)
explicit

Definition at line 31 of file PFMatchedCandidateRefExtractor.cc.

References extractPFCands_, edm::ParameterSet::getParameter(), and pfCandToken_.

34  moduleLabel_(iConfig.getParameter<std::string>("@module_label")) {
35  //register products
36 
37  extractPFCands_ = iConfig.getParameter<bool>("extractPFCandidates");
38 
39  produces<edm::PtrVector<reco::Candidate>>("col1");
40  produces<edm::PtrVector<reco::Candidate>>("col2");
41  if (extractPFCands_) {
42  pfCandToken_ = mayConsume<edm::View<reco::PFCandidate>>(iConfig.getParameter<edm::InputTag>("pfCandCollection"));
43  produces<edm::PtrVector<reco::PFCandidate>>("pfCandCol1");
44  produces<edm::PtrVector<reco::PFCandidate>>("pfCandCol2");
45  }
46 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< edm::View< reco::Candidate > > col1Token_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::View< reco::Candidate > > col2Token_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandToken_

◆ ~PFMatchedCandidateRefExtractor()

PFMatchedCandidateRefExtractor::~PFMatchedCandidateRefExtractor ( )
override

Definition at line 48 of file PFMatchedCandidateRefExtractor.cc.

48 {}

Member Function Documentation

◆ produce()

void PFMatchedCandidateRefExtractor::produce ( edm::StreamID  iID,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overridevirtual

Implements edm::global::EDProducerBase.

Definition at line 51 of file PFMatchedCandidateRefExtractor.cc.

References DummyCfis::c, col1Token_, col2Token_, HLTMuonOfflineAnalyzer_cfi::deltaR2, extractPFCands_, iEvent, muonTagProbeFilters_cff::matched, eostools::move(), and pfCandToken_.

51  {
52  std::unique_ptr<edm::PtrVector<reco::Candidate>> outcol1(new edm::PtrVector<reco::Candidate>());
53  std::unique_ptr<edm::PtrVector<reco::Candidate>> outcol2(new edm::PtrVector<reco::Candidate>());
54 
55  std::unique_ptr<edm::PtrVector<reco::PFCandidate>> outPFCandCol1(new edm::PtrVector<reco::PFCandidate>());
56  std::unique_ptr<edm::PtrVector<reco::PFCandidate>> outPFCandCol2(new edm::PtrVector<reco::PFCandidate>());
57 
61 
62  iEvent.getByToken(col1Token_, col1Handle);
63  iEvent.getByToken(col2Token_, col2Handle);
64  if (extractPFCands_) {
65  iEvent.getByToken(pfCandToken_, pfCandHandle);
66  }
67 
68  for (size_t iC1 = 0; iC1 < col1Handle->size(); iC1++) {
69  for (size_t iC2 = 0; iC2 < col2Handle->size(); iC2++) {
70  bool matched = (col1Handle->ptrAt(iC1) == col2Handle->ptrAt(iC2));
71  if (!matched && deltaR2(col1Handle->ptrAt(iC1)->p4(), col2Handle->ptrAt(iC2)->p4()) < 0.000001) {
72  matched = true;
73  }
74 
75  if (matched) {
76  outcol1->push_back(col1Handle->ptrAt(iC1));
77  outcol2->push_back(col2Handle->ptrAt(iC2));
78 
79  if (!extractPFCands_)
80  continue;
81  std::set<reco::CandidatePtr> sc1s;
82  std::set<reco::CandidatePtr> sc2s;
83  for (size_t ics1 = 0; ics1 < col1Handle->ptrAt(iC1)->numberOfSourceCandidatePtrs(); ics1++) {
84  sc1s.insert(col1Handle->ptrAt(iC1)->sourceCandidatePtr(ics1));
85  }
86  for (size_t ics2 = 0; ics2 < col2Handle->ptrAt(iC2)->numberOfSourceCandidatePtrs(); ics2++) {
87  sc2s.insert(col2Handle->ptrAt(iC2)->sourceCandidatePtr(ics2));
88  }
89 
90  for (size_t ic = 0; ic < pfCandHandle->size(); ++ic) {
91  reco::PFCandidatePtr c = pfCandHandle->ptrAt(ic);
92 
93  bool match1 = (sc1s.find(c) != sc1s.end());
94  bool match2 = (sc2s.find(c) != sc2s.end());
95 
96  if (!match1) { //recovery when pfcandidate sources are not equivalent
97  for (size_t ics1 = 0; ics1 < sc1s.size(); ics1++) {
98  if (deltaR2(c->p4(),
99  col1Handle->ptrAt(iC1)->sourceCandidatePtr(ics1)->p4()) <
100  0.0000001) { //tight dR, pfcandidates should be the same
101  match1 = true;
102  break;
103  }
104  }
105  }
106  if (!match2) { //recovery when pfcandidate sources are not equivalent
107  for (size_t ics2 = 0; ics2 < sc2s.size(); ics2++) {
108  if (deltaR2(c->p4(),
109  col2Handle->ptrAt(iC2)->sourceCandidatePtr(ics2)->p4()) < 0.00001) { //tight dR
110  match2 = true;
111  break;
112  }
113  }
114  }
115 
116  if (match1) {
117  outPFCandCol1->push_back(c);
118  }
119  if (match2) {
120  outPFCandCol2->push_back(c);
121  }
122  } //pfcand loop
123 
124  } //matching
125  } //col2
126  } //col1
127 
128  iEvent.put(std::move(outcol1), "col1");
129  iEvent.put(std::move(outcol2), "col2");
130  if (extractPFCands_) {
131  iEvent.put(std::move(outPFCandCol1), "pfCandCol1");
132  iEvent.put(std::move(outPFCandCol2), "pfCandCol2");
133  }
134 }
edm::EDGetTokenT< edm::View< reco::Candidate > > col1Token_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::View< reco::Candidate > > col2Token_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandToken_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ col1Token_

edm::EDGetTokenT<edm::View<reco::Candidate> > PFMatchedCandidateRefExtractor::col1Token_
private

Definition at line 23 of file PFMatchedCandidateRefExtractor.cc.

Referenced by produce().

◆ col2Token_

edm::EDGetTokenT<edm::View<reco::Candidate> > PFMatchedCandidateRefExtractor::col2Token_
private

Definition at line 24 of file PFMatchedCandidateRefExtractor.cc.

Referenced by produce().

◆ extractPFCands_

bool PFMatchedCandidateRefExtractor::extractPFCands_
private

Definition at line 28 of file PFMatchedCandidateRefExtractor.cc.

Referenced by PFMatchedCandidateRefExtractor(), and produce().

◆ moduleLabel_

std::string PFMatchedCandidateRefExtractor::moduleLabel_
private

◆ pfCandToken_

edm::EDGetTokenT<edm::View<reco::PFCandidate> > PFMatchedCandidateRefExtractor::pfCandToken_
private

Definition at line 26 of file PFMatchedCandidateRefExtractor.cc.

Referenced by PFMatchedCandidateRefExtractor(), and produce().