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::ProductRegistryHelper

Public Member Functions

virtual void beginRun (edm::Run &run, const edm::EventSetup &es)
 
 PFLinker (const edm::ParameterSet &)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 
 ~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 &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

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
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

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:
2011/07/20 09:57:25
Revision:
1.6
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_, and producePFCandidates_.

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:83
edm::InputTag inputTagMuons_
Input Muons.
Definition: PFLinker.h:68
std::string nameOutputElectronsPF_
name of output ValueMap electrons
Definition: PFLinker.h:74
std::string nameOutputPhotonsPF_
name of output ValueMap photons
Definition: PFLinker.h:77
std::string nameOutputPF_
name of output collection of PFCandidate
Definition: PFLinker.h:71
edm::InputTag inputTagPhotons_
Input Photons.
Definition: PFLinker.h:65
bool fillMuonRefs_
Set muon refs and produce the value map?
Definition: PFLinker.h:86
edm::InputTag inputTagGsfElectrons_
Input GsfElectrons.
Definition: PFLinker.h:62
std::string const & label() const
Definition: InputTag.h:25
std::vector< edm::InputTag > inputTagPFCandidates_
Input PFCandidates.
Definition: PFLinker.h:59
std::string nameOutputMergedPF_
name of output merged ValueMap
Definition: PFLinker.h:80
PFLinker::~PFLinker ( )

Definition at line 58 of file PFLinker.cc.

58 {;}

Member Function Documentation

void PFLinker::beginRun ( edm::Run run,
const edm::EventSetup es 
)
virtual

Reimplemented from edm::EDProducer.

Definition at line 60 of file PFLinker.cc.

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

Definition at line 221 of file PFLinker.cc.

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

223  {
224 
225  bool found = iEvent.getByLabel(tag, c);
226 
227  if(!found )
228  {
229  std::ostringstream err;
230  err<<" cannot get " <<tag<<std::endl;
231  edm::LogError("PFLinker")<<err.str();
232  }
233  return found;
234 }
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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 239 of file PFLinker.cc.

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

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

Implements edm::EDProducer.

Definition at line 62 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().

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

Member Data Documentation

bool PFLinker::fillMuonRefs_
private

Set muon refs and produce the value map?

Definition at line 86 of file PFLinker.h.

Referenced by PFLinker(), and produce().

edm::InputTag PFLinker::inputTagGsfElectrons_
private

Input GsfElectrons.

Definition at line 62 of file PFLinker.h.

Referenced by PFLinker(), and produce().

edm::InputTag PFLinker::inputTagMuons_
private

Input Muons.

Definition at line 68 of file PFLinker.h.

Referenced by PFLinker(), and produce().

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

Input PFCandidates.

Definition at line 59 of file PFLinker.h.

Referenced by PFLinker(), and produce().

edm::InputTag PFLinker::inputTagPhotons_
private

Input Photons.

Definition at line 65 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputElectronsPF_
private

name of output ValueMap electrons

Definition at line 74 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputMergedPF_
private

name of output merged ValueMap

Definition at line 80 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputPF_
private

name of output collection of PFCandidate

Definition at line 71 of file PFLinker.h.

Referenced by PFLinker(), and produce().

std::string PFLinker::nameOutputPhotonsPF_
private

name of output ValueMap photons

Definition at line 77 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 83 of file PFLinker.h.

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