CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
PFLinker Class Reference

#include <PFLinker.h>

Inheritance diagram for PFLinker:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PFLinker (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PFLinker ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- 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 ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

template<typename T >
bool fetchCollection (edm::Handle< T > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
 
template<typename TYPE >
edm::ValueMap
< reco::PFCandidatePtr
fillValueMap (edm::Event &event, std::string label, edm::Handle< TYPE > &inputObjCollection, const std::map< edm::Ref< TYPE >, reco::PFCandidatePtr > &mapToTheCandidate, const edm::OrphanHandle< reco::PFCandidateCollection > &newPFCandColl) const
 

Private Attributes

bool fillMuonRefs_
 Set muon refs and produce the value map? More...
 
edm::InputTag inputTagGsfElectrons_
 Input GsfElectrons. More...
 
edm::InputTag inputTagMuons_
 Input Muons. More...
 
std::vector< edm::InputTaginputTagPFCandidates_
 Input PFCandidates. More...
 
edm::InputTag inputTagPhotons_
 Input Photons. More...
 
std::string nameOutputElectronsPF_
 name of output ValueMap electrons More...
 
std::string nameOutputMergedPF_
 name of output merged ValueMap More...
 
std::string nameOutputPF_
 name of output collection of PFCandidate More...
 
std::string nameOutputPhotonsPF_
 name of output ValueMap photons More...
 
bool producePFCandidates_
 Flags - if true: References will be towards new collection ; if false to the original one. More...
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- 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

Producer meant for the Post PF reconstruction.

Fills the GsfElectron, Photon and Muon Ref into the PFCandidate Produces the ValueMap between GsfElectronRef/Photon/Mupns with PFCandidateRef

Date:
2013/02/26 16:32:20
Revision:
1.7
Author
R. Bellan - UCSB ricca.nosp@m.rdo..nosp@m.bella.nosp@m.n@ce.nosp@m.rn.ch, F. Beaudette - CERN Flori.nosp@m.an.B.nosp@m.eaude.nosp@m.tte@.nosp@m.cern..nosp@m.ch

Definition at line 31 of file PFLinker.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file PFLinker.cc.

References fillMuonRefs_, edm::ParameterSet::getParameter(), inputTagGsfElectrons_, inputTagMuons_, inputTagPFCandidates_, inputTagPhotons_, edm::InputTag::label(), nameOutputElectronsPF_, nameOutputMergedPF_, nameOutputPF_, nameOutputPhotonsPF_, producePFCandidates_, and AlCaHLTBitMon_QueryRunRegistry::string.

14  {
15  // vector of InputTag; more than 1 is not for RECO, it is for analysis
17  = iConfig.getParameter<std::vector<edm::InputTag> >("PFCandidate");
19  = iConfig.getParameter<edm::InputTag>("GsfElectrons");
21  = iConfig.getParameter<edm::InputTag>("Photons");
23  = iConfig.getParameter<edm::InputTag>("Muons");
24 
26  = iConfig.getParameter<std::string>("OutputPF");
27 
29  = iConfig.getParameter<std::string>("ValueMapElectrons");
30 
32  = iConfig.getParameter<std::string>("ValueMapPhotons");
33 
35  = iConfig.getParameter<bool>("ProducePFCandidates");
36 
38  = iConfig.getParameter<std::string>("ValueMapMerged");
39 
41  = iConfig.getParameter<bool>("FillMuonRefs");
42 
43  // should not produce PFCandidates and read seve
44  if(producePFCandidates_ && inputTagPFCandidates_.size()>1) {
45  edm::LogError("PFLinker") << " cannot read several collections of PFCandidates and produce a new collection at the same time. " << std::endl;
46  assert(0);
47  }
48  if(producePFCandidates_) {
49  produces<reco::PFCandidateCollection>(nameOutputPF_);
50  }
51  produces<edm::ValueMap<reco::PFCandidatePtr> > (nameOutputElectronsPF_);
52  produces<edm::ValueMap<reco::PFCandidatePtr> > (nameOutputPhotonsPF_);
53  produces<edm::ValueMap<reco::PFCandidatePtr> > (nameOutputMergedPF_);
54  if(fillMuonRefs_) produces<edm::ValueMap<reco::PFCandidatePtr> > (inputTagMuons_.label());
55 
56 }
T getParameter(std::string const &) const
bool producePFCandidates_
Flags - if true: References will be towards new collection ; if false to the original one...
Definition: PFLinker.h:81
edm::InputTag inputTagMuons_
Input Muons.
Definition: PFLinker.h:66
std::string nameOutputElectronsPF_
name of output ValueMap electrons
Definition: PFLinker.h:72
std::string nameOutputPhotonsPF_
name of output ValueMap photons
Definition: PFLinker.h:75
std::string nameOutputPF_
name of output collection of PFCandidate
Definition: PFLinker.h:69
edm::InputTag inputTagPhotons_
Input Photons.
Definition: PFLinker.h:63
bool fillMuonRefs_
Set muon refs and produce the value map?
Definition: PFLinker.h:84
edm::InputTag inputTagGsfElectrons_
Input GsfElectrons.
Definition: PFLinker.h:60
std::string const & label() const
Definition: InputTag.h:42
std::vector< edm::InputTag > inputTagPFCandidates_
Input PFCandidates.
Definition: PFLinker.h:57
std::string nameOutputMergedPF_
name of output merged ValueMap
Definition: PFLinker.h:78
PFLinker::~PFLinker ( )

Definition at line 58 of file PFLinker.cc.

58 {;}

Member Function Documentation

template<typename T >
bool PFLinker::fetchCollection ( edm::Handle< T > &  c,
const edm::InputTag tag,
const edm::Event iEvent 
) const
private

Definition at line 219 of file PFLinker.cc.

References newFWLiteAna::found, and edm::Event::getByLabel().

221  {
222 
223  bool found = iEvent.getByLabel(tag, c);
224 
225  if(!found )
226  {
227  std::ostringstream err;
228  err<<" cannot get " <<tag<<std::endl;
229  edm::LogError("PFLinker")<<err.str();
230  }
231  return found;
232 }
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
template<typename TYPE >
edm::ValueMap< reco::PFCandidatePtr > PFLinker::fillValueMap ( edm::Event event,
std::string  label,
edm::Handle< TYPE > &  inputObjCollection,
const std::map< edm::Ref< TYPE >, reco::PFCandidatePtr > &  mapToTheCandidate,
const edm::OrphanHandle< reco::PFCandidateCollection > &  newPFCandColl 
) const
private

Definition at line 237 of file PFLinker.cc.

References edm::helper::Filler< Map >::fill(), edm::helper::Filler< Map >::insert(), producePFCandidates_, and makeHLTPrescaleTable::values.

241  {
242 
243  std::auto_ptr<edm::ValueMap<reco::PFCandidatePtr> > pfMap_p(new edm::ValueMap<reco::PFCandidatePtr>());
245 
246  typedef typename std::map<edm::Ref<TYPE>, reco::PFCandidatePtr>::const_iterator MapTYPE_it;
247 
248  unsigned nObj=inputObjCollection->size();
249  std::vector<reco::PFCandidatePtr> values(nObj);
250 
251  for(unsigned iobj=0; iobj < nObj; ++iobj) {
252 
253  edm::Ref<TYPE> objRef(inputObjCollection, iobj);
254  MapTYPE_it itcheck = mapToTheCandidate.find(objRef);
255 
256  reco::PFCandidatePtr candPtr;
257 
258  if(itcheck != mapToTheCandidate.end())
259  candPtr = producePFCandidates_ ? reco::PFCandidatePtr(newPFCandColl,itcheck->second.key()) : itcheck->second;
260 
261  values[iobj] = candPtr;
262  }
263 
264  filler.insert(inputObjCollection,values.begin(),values.end());
265  filler.fill();
266  edm::ValueMap<reco::PFCandidatePtr> returnValue = *pfMap_p;
267  event.put(pfMap_p,label);
268  return returnValue;
269 }
bool producePFCandidates_
Flags - if true: References will be towards new collection ; if false to the original one...
Definition: PFLinker.h:81
void PFLinker::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Implements edm::EDProducer.

Definition at line 60 of file PFLinker.cc.

References reco::PFCandidate::e, fillMuonRefs_, reco::PFCandidate::gamma, gsfElectrons_cfi::gsfElectrons, reco::PFCandidate::gsfTrackRef(), i, iEvent, inputTagGsfElectrons_, inputTagMuons_, inputTagPFCandidates_, inputTagPhotons_, edm::Ref< C, T, F >::isNonnull(), reco::PFCandidate::muonRef(), patZpeak::muons, reco::PFCandidate::mva_nothing_gamma(), nameOutputElectronsPF_, nameOutputMergedPF_, nameOutputPF_, nameOutputPhotonsPF_, reco::PFCandidate::particleId(), reco::tau::pfCandidates(), interactiveExample::photons, producePFCandidates_, edm::Event::put(), reco::PFCandidate::setGsfElectronRef(), reco::PFCandidate::setMuonRef(), reco::PFCandidate::setPhotonRef(), reco::PFCandidate::setSuperClusterRef(), ntuplemaker::status, and reco::PFCandidate::superClusterRef().

60  {
61 
62  std::auto_ptr<reco::PFCandidateCollection>
63  pfCandidates_p(new reco::PFCandidateCollection);
64 
66  bool status=fetchCollection<reco::GsfElectronCollection>(gsfElectrons,
68  iEvent );
69  std::map<reco::GsfElectronRef,reco::PFCandidatePtr> electronCandidateMap;
70 
71  if(!status) {
72  std::ostringstream err;
73  err << " Problem in PFLinker: no electron collection called " << inputTagGsfElectrons_ << std::endl;
74  edm::LogError("PFLinker") << err.str();
75  }
76 
77 
79  status=fetchCollection<reco::PhotonCollection>(photons,
81  iEvent );
82  if(!status) {
83  std::ostringstream err;
84  err << " Problem in PFLinker: no photon collection called " << inputTagPhotons_ << std::endl;
85  edm::LogError("PFLinker") << err.str();
86  }
87 
88 
89  std::map<reco::PhotonRef,reco::PFCandidatePtr> photonCandidateMap;
90 
91 
93  if(fillMuonRefs_)
94  status=fetchCollection<reco::MuonToMuonMap>(muonMap,
96  iEvent);
97  std::map<reco::MuonRef,reco::PFCandidatePtr> muonCandidateMap;
98 
99  unsigned nColPF=inputTagPFCandidates_.size();
100 
101  if(!status) {
102  std::ostringstream err;
103  err << " Problem in PFLinker: no muon collection called " << inputTagMuons_ << std::endl;
104  edm::LogError("PFLinker") << err.str();
105  }
106 
107 
109  for(unsigned icol=0;icol<nColPF;++icol) {
110 
111  bool status=fetchCollection<reco::PFCandidateCollection>(pfCandidates,
112  inputTagPFCandidates_[icol],
113  iEvent );
114 
115  unsigned ncand=(status)?pfCandidates->size():0;
116 
117  for( unsigned i=0; i<ncand; ++i) {
118  edm::Ptr<reco::PFCandidate> candPtr(pfCandidates,i);
119  reco::PFCandidate cand(candPtr);
120 
121  bool isphoton = cand.particleId() == reco::PFCandidate::gamma && cand.mva_nothing_gamma()>0.;
122  bool iselectron = cand.particleId() == reco::PFCandidate::e;
123  // PFCandidates may have a valid MuonRef though they are not muons.
124  bool hasNonNullMuonRef = cand.muonRef().isNonnull() && fillMuonRefs_;
125 
126  // if not an electron or a photon or a muon just fill the PFCandidate collection
127  if ( !(isphoton || iselectron || hasNonNullMuonRef)){pfCandidates_p->push_back(cand); continue;}
128 
129 
130  if (hasNonNullMuonRef) {
131  reco::MuonRef muRef = (*muonMap)[cand.muonRef()];
132  cand.setMuonRef(muRef);
133  muonCandidateMap[muRef] = candPtr;
134  }
135 
136 
137  // if it is an electron. Find the GsfElectron with the same GsfTrack
138  if (iselectron) {
139  const reco::GsfTrackRef & gsfTrackRef(cand.gsfTrackRef());
140  GsfElectronEqual myEqual(gsfTrackRef);
141  std::vector<reco::GsfElectron>::const_iterator itcheck=find_if(gsfElectrons->begin(),gsfElectrons->end(),myEqual);
142  if(itcheck==gsfElectrons->end()) {
143  std::ostringstream err;
144  err << " Problem in PFLinker: no GsfElectron " << std::endl;
145  edm::LogError("PFLinker") << err.str();
146  continue; // Watch out ! Continue
147  }
148  reco::GsfElectronRef electronRef(gsfElectrons,itcheck-gsfElectrons->begin());
149  cand.setGsfElectronRef(electronRef);
150  cand.setSuperClusterRef(electronRef->superCluster());
151  electronCandidateMap[electronRef] = candPtr;
152  }
153 
154  // if it is a photon, find the one with the same PF super-cluster
155  if (isphoton) {
156  const reco::SuperClusterRef & scRef(cand.superClusterRef());
157  PhotonEqual myEqual(scRef);
158  std::vector<reco::Photon>::const_iterator itcheck=find_if(photons->begin(),photons->end(),myEqual);
159  if(itcheck==photons->end()) {
160  std::ostringstream err;
161  err << " Problem in PFLinker: no Photon " << std::endl;
162  edm::LogError("PFLinker") << err.str();
163  continue; // Watch out ! Continue
164  }
165  reco::PhotonRef photonRef(photons,itcheck-photons->begin());
166  cand.setPhotonRef(photonRef);
167  cand.setSuperClusterRef(photonRef->superCluster());
168  photonCandidateMap[photonRef] = candPtr;
169  }
170 
171  pfCandidates_p->push_back(cand);
172  }
173  // save the PFCandidates and get a valid handle
174  }
175  const edm::OrphanHandle<reco::PFCandidateCollection> pfCandidateRefProd = (producePFCandidates_) ? iEvent.put(pfCandidates_p,nameOutputPF_) :
177 
178 
179  // now make the valuemaps
180 
181  edm::ValueMap<reco::PFCandidatePtr> pfMapGsfElectrons = fillValueMap<reco::GsfElectronCollection>(iEvent,
183  gsfElectrons,
184  electronCandidateMap,
185  pfCandidateRefProd);
186 
187  edm::ValueMap<reco::PFCandidatePtr> pfMapPhotons = fillValueMap<reco::PhotonCollection>(iEvent,
189  photons,
190  photonCandidateMap,
191  pfCandidateRefProd);
192 
193 
195 
196  if(fillMuonRefs_){
198  iEvent.getByLabel(inputTagMuons_.label(), muons);
199 
200  pfMapMuons = fillValueMap<reco::MuonCollection>(iEvent,
201  inputTagMuons_.label(),
202  muons,
203  muonCandidateMap,
204  pfCandidateRefProd);
205  }
206 
207  std::auto_ptr<edm::ValueMap<reco::PFCandidatePtr> >
208  pfMapMerged(new edm::ValueMap<reco::PFCandidatePtr>());
209  edm::ValueMap<reco::PFCandidatePtr>::Filler pfMapMergedFiller(*pfMapMerged);
210 
211  *pfMapMerged += pfMapGsfElectrons;
212  *pfMapMerged += pfMapPhotons;
213  if(fillMuonRefs_) *pfMapMerged += pfMapMuons;
214 
215  iEvent.put(pfMapMerged,nameOutputMergedPF_);
216 }
int i
Definition: DBlmapReader.cc:9
bool producePFCandidates_
Flags - if true: References will be towards new collection ; if false to the original one...
Definition: PFLinker.h:81
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
edm::InputTag inputTagMuons_
Input Muons.
Definition: PFLinker.h:66
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::string nameOutputElectronsPF_
name of output ValueMap electrons
Definition: PFLinker.h:72
std::string nameOutputPhotonsPF_
name of output ValueMap photons
Definition: PFLinker.h:75
std::string nameOutputPF_
name of output collection of PFCandidate
Definition: PFLinker.h:69
edm::InputTag inputTagPhotons_
Input Photons.
Definition: PFLinker.h:63
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
bool fillMuonRefs_
Set muon refs and produce the value map?
Definition: PFLinker.h:84
edm::InputTag inputTagGsfElectrons_
Input GsfElectrons.
Definition: PFLinker.h:60
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:35
tuple muons
Definition: patZpeak.py:38
std::vector< edm::InputTag > inputTagPFCandidates_
Input PFCandidates.
Definition: PFLinker.h:57
tuple status
Definition: ntuplemaker.py:245
std::string nameOutputMergedPF_
name of output merged ValueMap
Definition: PFLinker.h:78

Member Data Documentation

bool PFLinker::fillMuonRefs_
private

Set muon refs and produce the value map?

Definition at line 84 of file PFLinker.h.

Referenced by PFLinker(), and produce().

edm::InputTag PFLinker::inputTagGsfElectrons_
private

Input GsfElectrons.

Definition at line 60 of file PFLinker.h.

Referenced by PFLinker(), and produce().

edm::InputTag PFLinker::inputTagMuons_
private

Input Muons.

Definition at line 66 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::vector<edm::InputTag> PFLinker::inputTagPFCandidates_
private

Input PFCandidates.

Definition at line 57 of file PFLinker.h.

Referenced by PFLinker(), and produce().

edm::InputTag PFLinker::inputTagPhotons_
private

Input Photons.

Definition at line 63 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputElectronsPF_
private

name of output ValueMap electrons

Definition at line 72 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputMergedPF_
private

name of output merged ValueMap

Definition at line 78 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputPF_
private

name of output collection of PFCandidate

Definition at line 69 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputPhotonsPF_
private

name of output ValueMap photons

Definition at line 75 of file PFLinker.h.

Referenced by PFLinker(), and produce().

bool PFLinker::producePFCandidates_
private

Flags - if true: References will be towards new collection ; if false to the original one.

Definition at line 81 of file PFLinker.h.

Referenced by fillValueMap(), PFLinker(), and produce().