CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFLinker.cc
Go to the documentation of this file.
2 
8 
12 
13 
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 }
57 
59 
61 
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 }
219 
220 template<typename T>
222  const edm::InputTag& tag,
223  const edm::Event& iEvent) const {
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 }
235 
236 
237 
238 template<typename TYPE>
240  std::string label,
241  edm::Handle<TYPE>& inputObjCollection,
242  const std::map<edm::Ref<TYPE>, reco::PFCandidatePtr> & mapToTheCandidate,
243  const edm::OrphanHandle<reco::PFCandidateCollection> & newPFCandColl) const {
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 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void setGsfElectronRef(const reco::GsfElectronRef &ref)
set GsfElectronRef
Definition: PFCandidate.cc:474
float mva_nothing_gamma() const
mva for gamma detection
Definition: PFCandidate.h:294
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: PFLinker.cc:62
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
bool producePFCandidates_
Flags - if true: References will be towards new collection ; if false to the original one...
Definition: PFLinker.h:83
~PFLinker()
Definition: PFLinker.cc:58
PFLinker(const edm::ParameterSet &)
Definition: PFLinker.cc:14
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
Definition: PFLinker.cc:239
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
edm::InputTag inputTagMuons_
Input Muons.
Definition: PFLinker.h:68
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
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
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool fetchCollection(edm::Handle< T > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
Definition: PFLinker.cc:221
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:355
edm::InputTag inputTagPhotons_
Input Photons.
Definition: PFLinker.h:65
virtual void beginRun(edm::Run &run, const edm::EventSetup &es)
Definition: PFLinker.cc:60
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
void setPhotonRef(const reco::PhotonRef &phRef)
set ref to the corresponding reco::Photon if any
Definition: PFCandidate.cc:506
std::string const & label() const
Definition: InputTag.h:25
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:33
void setMuonRef(const reco::MuonRef &ref)
set muon reference
Definition: PFCandidate.cc:342
tuple muons
Definition: patZpeak.py:38
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:376
void setSuperClusterRef(const reco::SuperClusterRef &scRef)
Definition: PFCandidate.cc:522
std::vector< edm::InputTag > inputTagPFCandidates_
Input PFCandidates.
Definition: PFLinker.h:59
tuple status
Definition: ntuplemaker.py:245
virtual ParticleType particleId() const
Definition: PFCandidate.h:324
Definition: Run.h:33
std::string nameOutputMergedPF_
name of output merged ValueMap
Definition: PFLinker.h:80
reco::SuperClusterRef superClusterRef() const
return a reference to the corresponding SuperCluster if any
Definition: PFCandidate.cc:502