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)
 
virtual void produce (edm::StreamID iID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
 
virtual ~PFMatchedCandidateRefExtractor ()
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
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
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::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 15 of file PFMatchedCandidateRefExtractor.cc.

Constructor & Destructor Documentation

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

Definition at line 35 of file PFMatchedCandidateRefExtractor.cc.

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

35  :
38  moduleLabel_(iConfig.getParameter<std::string>("@module_label"))
39 {
40  //register products
41 
42  extractPFCands_=iConfig.getParameter<bool>("extractPFCandidates");
43 
44  produces<edm::PtrVector<reco::Candidate> >("col1");
45  produces<edm::PtrVector<reco::Candidate> >("col2");
46  if(extractPFCands_) {
47  pfCandToken_=mayConsume<edm::View<reco::PFCandidate> >( iConfig.getParameter<edm::InputTag>("pfCandCollection") );
48  produces<edm::PtrVector<reco::PFCandidate> >("pfCandCol1");
49  produces<edm::PtrVector<reco::PFCandidate> >("pfCandCol2");
50  }
51 
52 }
T getParameter(std::string const &) const
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 ( )
virtual

Definition at line 55 of file PFMatchedCandidateRefExtractor.cc.

55  {
56 }

Member Function Documentation

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

Definition at line 61 of file PFMatchedCandidateRefExtractor.cc.

References EnergyCorrector::c, col1Token_, col2Token_, DEFINE_FWK_MODULE, reco::deltaR2(), extractPFCands_, edm::Event::getByToken(), electronMatch_cfi::matched, eostools::move(), pfCandToken_, and edm::Event::put().

62 {
63 
64 
65  std::unique_ptr<edm::PtrVector<reco::Candidate> > outcol1(new edm::PtrVector<reco::Candidate>());
66  std::unique_ptr<edm::PtrVector<reco::Candidate> > outcol2(new edm::PtrVector<reco::Candidate>());
67 
68  std::unique_ptr<edm::PtrVector<reco::PFCandidate> > outPFCandCol1(new edm::PtrVector<reco::PFCandidate>());
69  std::unique_ptr<edm::PtrVector<reco::PFCandidate> > outPFCandCol2(new edm::PtrVector<reco::PFCandidate>());
70 
74 
75  iEvent.getByToken( col1Token_, col1Handle );
76  iEvent.getByToken( col2Token_, col2Handle );
77  if(extractPFCands_) {
78  iEvent.getByToken( pfCandToken_, pfCandHandle );
79  }
80 
81  for(size_t iC1=0;iC1<col1Handle->size();iC1++) {
82  for(size_t iC2=0;iC2<col2Handle->size();iC2++) {
83 
84  bool matched=(col1Handle->ptrAt(iC1)==col2Handle->ptrAt(iC2));
85  if(!matched &&
86  deltaR2(col1Handle->ptrAt(iC1)->p4(), col2Handle->ptrAt(iC2)->p4() )< 0.000001) {
87  matched=true;
88  }
89 
90  if(matched) {
91  outcol1->push_back( col1Handle->ptrAt(iC1) );
92  outcol2->push_back( col2Handle->ptrAt(iC2) );
93 
94  if(!extractPFCands_) continue;
95  std::set<reco::CandidatePtr> sc1s;
96  std::set<reco::CandidatePtr> sc2s;
97  for(size_t ics1=0;ics1<col1Handle->ptrAt(iC1)->numberOfSourceCandidatePtrs();
98  ics1++ ) {
99  sc1s.insert( col1Handle->ptrAt(iC1)->sourceCandidatePtr(ics1));
100  }
101  for(size_t ics2=0;ics2<col2Handle->ptrAt(iC2)->numberOfSourceCandidatePtrs();
102  ics2++ ) {
103  sc2s.insert( col2Handle->ptrAt(iC2)->sourceCandidatePtr(ics2));
104  }
105 
106  for(size_t ic=0;ic<pfCandHandle->size(); ++ic) {
107  reco::PFCandidatePtr c = pfCandHandle->ptrAt(ic);
108 
109  bool match1=(sc1s.find(c)!=sc1s.end());
110  bool match2=(sc2s.find(c)!=sc2s.end());
111 
112  if(!match1) {//recovery when pfcandidate sources are not equivalent
113  for(size_t ics1=0;ics1<sc1s.size();ics1++) {
114  if(deltaR2(c->p4(),
115  col1Handle->ptrAt(iC1)->sourceCandidatePtr(ics1)->p4())<0.0000001) { //tight dR, pfcandidates should be the same
116  match1=true;
117  break;
118  }
119  }
120  }
121  if(!match2) {//recovery when pfcandidate sources are not equivalent
122  for(size_t ics2=0;ics2<sc2s.size();ics2++) {
123  if(deltaR2(c->p4(),
124  col2Handle->ptrAt(iC2)->sourceCandidatePtr(ics2)->p4())<0.00001) { //tight dR
125  match2=true;
126  break;
127  }
128  }
129  }
130 
131  if(match1) {
132  outPFCandCol1->push_back(c);
133  }
134  if(match2) {
135  outPFCandCol2->push_back(c);
136  }
137  } //pfcand loop
138 
139  } //matching
140  } //col2
141  } //col1
142 
143  iEvent.put(std::move(outcol1),"col1");
144  iEvent.put(std::move(outcol2),"col2");
145  if(extractPFCands_) {
146  iEvent.put(std::move(outPFCandCol1),"pfCandCol1");
147  iEvent.put(std::move(outPFCandCol2),"pfCandCol2");
148  }
149 
150 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
edm::EDGetTokenT< edm::View< reco::Candidate > > col1Token_
edm::EDGetTokenT< edm::View< reco::Candidate > > col2Token_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfCandToken_
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

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

Definition at line 25 of file PFMatchedCandidateRefExtractor.cc.

Referenced by produce().

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

Definition at line 26 of file PFMatchedCandidateRefExtractor.cc.

Referenced by produce().

bool PFMatchedCandidateRefExtractor::extractPFCands_
private

Definition at line 30 of file PFMatchedCandidateRefExtractor.cc.

Referenced by PFMatchedCandidateRefExtractor(), and produce().

std::string PFMatchedCandidateRefExtractor::moduleLabel_
private
edm::EDGetTokenT<edm::View<reco::PFCandidate> > PFMatchedCandidateRefExtractor::pfCandToken_
private

Definition at line 28 of file PFMatchedCandidateRefExtractor.cc.

Referenced by PFMatchedCandidateRefExtractor(), and produce().