CMS 3D CMS Logo

PFElectronTranslator.cc
Go to the documentation of this file.
28 
29 class DetId;
30 namespace edm {
31  class EventSetup;
32 } // namespace edm
33 
35 public:
36  explicit PFElectronTranslator(const edm::ParameterSet&);
37  ~PFElectronTranslator() override;
38 
39  void produce(edm::Event&, const edm::EventSetup&) override;
40 
41  typedef std::vector<edm::Handle<edm::ValueMap<double>>> IsolationValueMaps;
42 
43 private:
44  // to retrieve the collection from the event
45  bool fetchCandidateCollection(edm::Handle<reco::PFCandidateCollection>& c,
46  const edm::InputTag& tag,
47  const edm::Event& iEvent) const;
48  // to retrieve the collection from the event
49  void fetchGsfCollection(edm::Handle<reco::GsfTrackCollection>& c,
50  const edm::InputTag& tag,
51  const edm::Event& iEvent) const;
52 
53  // makes a basic cluster from PFBlockElement and add it to the collection ; the corrected energy is taken
54  // from the PFCandidate
55  void createBasicCluster(const reco::PFBlockElement&,
56  reco::BasicClusterCollection& basicClusters,
57  std::vector<const reco::PFCluster*>&,
58  const reco::PFCandidate& coCandidate) const;
59  // makes a preshower cluster from of PFBlockElement and add it to the collection
60  void createPreshowerCluster(const reco::PFBlockElement& PFBE,
61  reco::PreshowerClusterCollection& preshowerClusters,
62  unsigned plane) const;
63 
64  // make a super cluster from its ingredients and add it to the collection
65  void createSuperClusters(const reco::PFCandidateCollection&, reco::SuperClusterCollection& superClusters) const;
66 
67  // make GsfElectronCores from ingredients
68  void createGsfElectronCores(reco::GsfElectronCoreCollection&) const;
69 
70  // create the basic cluster Ptr
71  void createBasicClusterPtrs(const edm::OrphanHandle<reco::BasicClusterCollection>& basicClustersHandle);
72 
73  // create the preshower cluster Refs
74  void createPreshowerClusterPtrs(const edm::OrphanHandle<reco::PreshowerClusterCollection>& preshowerClustersHandle);
75 
76  // create the super cluster Refs
77  void createSuperClusterGsfMapRefs(const edm::OrphanHandle<reco::SuperClusterCollection>& superClustersHandle);
78 
79  // create the GsfElectronCore Refs
80  void createGsfElectronCoreRefs(const edm::OrphanHandle<reco::GsfElectronCoreCollection>& gsfElectronCoreHandle);
81 
82  // create the GsfElectrons
83  void createGsfElectrons(const reco::PFCandidateCollection&,
84  const IsolationValueMaps& isolationValues,
86 
87  // The following methods are used to fill the value maps
88  void fillMVAValueMap(edm::Event& iEvent, edm::ValueMap<float>::Filler& filler);
89  void fillValueMap(edm::Event& iEvent, edm::ValueMap<float>::Filler& filler) const;
91  void getAmbiguousGsfTracks(const reco::PFBlockElement& PFBE, std::vector<reco::GsfTrackRef>&) const;
92 
93  const reco::PFCandidate& correspondingDaughterCandidate(const reco::PFCandidate& cand,
94  const reco::PFBlockElement& pfbe) const;
95 
96 private:
100  std::vector<edm::InputTag> inputTagIsoVals_;
108  double MVACut_;
110 
111  // The following vectors correspond to a GSF track, but the order is not
112  // the order of the tracks in the GSF track collection
113  std::vector<reco::GsfTrackRef> GsfTrackRef_;
114  // the list of candidatePtr
115  std::vector<reco::CandidatePtr> CandidatePtr_;
116  //the list of KfTrackRef
117  std::vector<reco::TrackRef> kfTrackRef_;
118  // the list of ambiguous tracks
119  std::vector<std::vector<reco::GsfTrackRef>> ambiguousGsfTracks_;
120  // the collection of basic clusters associated to a GSF track
121  std::vector<reco::BasicClusterCollection> basicClusters_;
122  // the correcsponding PFCluster ref
123  std::vector<std::vector<const reco::PFCluster*>> pfClusters_;
124  // the collection of preshower clusters associated to a GSF track
125  std::vector<reco::PreshowerClusterCollection> preshowerClusters_;
126  // the super cluster collection (actually only one) associated to a GSF track
127  std::vector<reco::SuperClusterCollection> superClusters_;
128  // the references to the basic clusters associated to a GSF track
129  std::vector<reco::CaloClusterPtrVector> basicClusterPtr_;
130  // the references to the basic clusters associated to a GSF track
131  std::vector<reco::CaloClusterPtrVector> preshowerClusterPtr_;
132  // the references to the GsfElectonCore associated to a GSF track
133  std::vector<reco::GsfElectronCoreRef> gsfElectronCoreRefs_;
134  // keep track of the index of the PF Candidate
135  std::vector<int> gsfPFCandidateIndex_;
136  // maps to ease the creation of the Value Maps
137  std::map<reco::GsfTrackRef, reco::SuperClusterRef> scMap_;
138  std::map<reco::GsfTrackRef, float> gsfMvaMap_;
139 
141 };
142 
144 
146  inputTagPFCandidates_ = iConfig.getParameter<edm::InputTag>("PFCandidate");
147  inputTagPFCandidateElectrons_ = iConfig.getParameter<edm::InputTag>("PFCandidateElectron");
148  inputTagGSFTracks_ = iConfig.getParameter<edm::InputTag>("GSFTracks");
149 
150  bool useIsolationValues = iConfig.getParameter<bool>("useIsolationValues");
151  if (useIsolationValues) {
152  if (!iConfig.exists("isolationValues"))
153  throw cms::Exception("PFElectronTranslator|InternalError") << "Missing ParameterSet isolationValues";
154  else {
155  edm::ParameterSet isoVals = iConfig.getParameter<edm::ParameterSet>("isolationValues");
156  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfSumChargedHadronPt"));
157  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfSumPhotonEt"));
158  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfSumNeutralHadronEt"));
159  inputTagIsoVals_.push_back(isoVals.getParameter<edm::InputTag>("pfSumPUPt"));
160  }
161  }
162 
163  PFBasicClusterCollection_ = iConfig.getParameter<std::string>("PFBasicClusters");
164  PFPreshowerClusterCollection_ = iConfig.getParameter<std::string>("PFPreshowerClusters");
165  PFSuperClusterCollection_ = iConfig.getParameter<std::string>("PFSuperClusters");
166  GsfElectronCoreCollection_ = iConfig.getParameter<std::string>("PFGsfElectronCore");
167  GsfElectronCollection_ = iConfig.getParameter<std::string>("PFGsfElectron");
168 
169  PFMVAValueMap_ = iConfig.getParameter<std::string>("ElectronMVA");
170  PFSCValueMap_ = iConfig.getParameter<std::string>("ElectronSC");
171  MVACut_ = (iConfig.getParameter<edm::ParameterSet>("MVACutBlock")).getParameter<double>("MVACut");
172  checkStatusFlag_ = iConfig.getParameter<bool>("CheckStatusFlag");
173 
174  if (iConfig.exists("emptyIsOk"))
175  emptyIsOk_ = iConfig.getParameter<bool>("emptyIsOk");
176  else
177  emptyIsOk_ = false;
178 
179  produces<reco::BasicClusterCollection>(PFBasicClusterCollection_);
180  produces<reco::PreshowerClusterCollection>(PFPreshowerClusterCollection_);
181  produces<reco::SuperClusterCollection>(PFSuperClusterCollection_);
182  produces<reco::GsfElectronCoreCollection>(GsfElectronCoreCollection_);
183  produces<reco::GsfElectronCollection>(GsfElectronCollection_);
184  produces<edm::ValueMap<float>>(PFMVAValueMap_);
185  produces<edm::ValueMap<reco::SuperClusterRef>>(PFSCValueMap_);
186 }
187 
189 
191  auto gsfElectronCores_p = std::make_unique<reco::GsfElectronCoreCollection>();
192 
193  auto gsfElectrons_p = std::make_unique<reco::GsfElectronCollection>();
194 
195  auto superClusters_p = std::make_unique<reco::SuperClusterCollection>();
196 
197  auto basicClusters_p = std::make_unique<reco::BasicClusterCollection>();
198 
199  auto psClusters_p = std::make_unique<reco::PreshowerClusterCollection>();
200 
201  auto mvaMap_p = std::make_unique<edm::ValueMap<float>>();
202  edm::ValueMap<float>::Filler mvaFiller(*mvaMap_p);
203 
204  auto scMap_p = std::make_unique<edm::ValueMap<reco::SuperClusterRef>>();
205  edm::ValueMap<reco::SuperClusterRef>::Filler scRefFiller(*scMap_p);
206 
208  bool status = fetchCandidateCollection(pfCandidates, inputTagPFCandidates_, iEvent);
209 
210  IsolationValueMaps isolationValues(inputTagIsoVals_.size());
211  for (size_t j = 0; j < inputTagIsoVals_.size(); ++j) {
212  iEvent.getByLabel(inputTagIsoVals_[j], isolationValues[j]);
213  }
214 
215  // clear the vectors
216  GsfTrackRef_.clear();
217  CandidatePtr_.clear();
218  ambiguousGsfTracks_.clear();
219  kfTrackRef_.clear();
220  basicClusters_.clear();
221  pfClusters_.clear();
222  preshowerClusters_.clear();
223  superClusters_.clear();
224  basicClusterPtr_.clear();
225  preshowerClusterPtr_.clear();
226  gsfPFCandidateIndex_.clear();
227  gsfElectronCoreRefs_.clear();
228  scMap_.clear();
229 
230  // loop on the candidates
231  //CC@@
232  // we need first to create AND put the SuperCluster,
233  // basic clusters and presh clusters collection
234  // in order to get a working Handle
235  unsigned ncand = (status) ? pfCandidates->size() : 0;
236  unsigned iGSF = 0;
237  for (unsigned i = 0; i < ncand; ++i) {
238  const reco::PFCandidate& cand = (*pfCandidates)[i];
239  if (cand.particleId() != reco::PFCandidate::e)
240  continue;
241  if (cand.gsfTrackRef().isNull())
242  continue;
243  // Note that -1 will still cut some total garbage candidates
244  // Fill the MVA map
245  if (cand.mva_e_pi() < MVACut_)
246  continue;
247 
248  // Check the status flag
249  if (checkStatusFlag_ && !cand.electronExtraRef()->electronStatus(reco::PFCandidateElectronExtra::Selected)) {
250  continue;
251  }
252 
253  GsfTrackRef_.push_back(cand.gsfTrackRef());
254  kfTrackRef_.push_back(cand.trackRef());
255  gsfPFCandidateIndex_.push_back(i);
256 
257  reco::PFCandidatePtr ptrToPFElectron(pfCandidates, i);
258  //CandidatePtr_.push_back(ptrToPFElectron->sourceCandidatePtr(0));
259  CandidatePtr_.push_back(ptrToPFElectron);
260 
261  basicClusters_.push_back(reco::BasicClusterCollection());
262  pfClusters_.push_back(std::vector<const reco::PFCluster*>());
263  preshowerClusters_.push_back(reco::PreshowerClusterCollection());
264  ambiguousGsfTracks_.push_back(std::vector<reco::GsfTrackRef>());
265 
266  for (unsigned iele = 0; iele < cand.elementsInBlocks().size(); ++iele) {
267  // first get the block
268  reco::PFBlockRef blockRef = cand.elementsInBlocks()[iele].first;
269  //
270  unsigned elementIndex = cand.elementsInBlocks()[iele].second;
271  // check it actually exists
272  if (blockRef.isNull())
273  continue;
274 
275  // then get the elements of the block
276  const edm::OwnVector<reco::PFBlockElement>& elements = (*blockRef).elements();
277 
278  const reco::PFBlockElement& pfbe(elements[elementIndex]);
279  // The first ECAL element should be the cluster associated to the GSF; defined as the seed
280  if (pfbe.type() == reco::PFBlockElement::ECAL) {
281  // const reco::PFCandidate * coCandidate = &cand;
282  // the Brem photons are saved as daughter PFCandidate; this
283  // is convenient to access the corrected energy
284  // std::cout << " Found candidate " << correspondingDaughterCandidate(coCandidate,pfbe) << " " << coCandidate << std::endl;
285  createBasicCluster(pfbe, basicClusters_[iGSF], pfClusters_[iGSF], correspondingDaughterCandidate(cand, pfbe));
286  }
287  if (pfbe.type() == reco::PFBlockElement::PS1) {
288  createPreshowerCluster(pfbe, preshowerClusters_[iGSF], 1);
289  }
290  if (pfbe.type() == reco::PFBlockElement::PS2) {
291  createPreshowerCluster(pfbe, preshowerClusters_[iGSF], 2);
292  }
293  if (pfbe.type() == reco::PFBlockElement::GSF) {
294  getAmbiguousGsfTracks(pfbe, ambiguousGsfTracks_[iGSF]);
295  }
296 
297  } // loop on the elements
298 
299  // save the basic clusters
300  basicClusters_p->insert(basicClusters_p->end(), basicClusters_[iGSF].begin(), basicClusters_[iGSF].end());
301  // save the preshower clusters
302  psClusters_p->insert(psClusters_p->end(), preshowerClusters_[iGSF].begin(), preshowerClusters_[iGSF].end());
303 
304  ++iGSF;
305  } // loop on PFCandidates
306 
307  //Save the basic clusters and get an handle as to be able to create valid Refs (thanks to Claude)
308  // std::cout << " Number of basic clusters " << basicClusters_p->size() << std::endl;
310  iEvent.put(std::move(basicClusters_p), PFBasicClusterCollection_);
311 
312  //preshower clusters
314  iEvent.put(std::move(psClusters_p), PFPreshowerClusterCollection_);
315 
316  // now that the Basic clusters are in the event, the Ref can be created
317  createBasicClusterPtrs(bcRefProd);
318  // now that the preshower clusters are in the event, the Ref can be created
319  createPreshowerClusterPtrs(psRefProd);
320 
321  // and now the Super cluster can be created with valid references
322  if (status)
323  createSuperClusters(*pfCandidates, *superClusters_p);
324 
325  // Let's put the super clusters in the event
327  iEvent.put(std::move(superClusters_p), PFSuperClusterCollection_);
328  // create the super cluster Ref
329  createSuperClusterGsfMapRefs(scRefProd);
330 
331  // Now create the GsfElectronCoers
332  createGsfElectronCores(*gsfElectronCores_p);
333  // Put them in the as to get to be able to build a Ref
334  const edm::OrphanHandle<reco::GsfElectronCoreCollection> gsfElectronCoreRefProd =
335  iEvent.put(std::move(gsfElectronCores_p), GsfElectronCoreCollection_);
336 
337  // now create the Refs
338  createGsfElectronCoreRefs(gsfElectronCoreRefProd);
339 
340  // now make the GsfElectron
341  createGsfElectrons(*pfCandidates, isolationValues, *gsfElectrons_p);
342  iEvent.put(std::move(gsfElectrons_p), GsfElectronCollection_);
343 
344  fillMVAValueMap(iEvent, mvaFiller);
345  mvaFiller.fill();
346 
347  fillSCRefValueMap(iEvent, scRefFiller);
348  scRefFiller.fill();
349 
350  // MVA map
351  iEvent.put(std::move(mvaMap_p), PFMVAValueMap_);
352  // Gsf-SC map
353  iEvent.put(std::move(scMap_p), PFSCValueMap_);
354 }
355 
357  const edm::InputTag& tag,
358  const edm::Event& iEvent) const {
359  bool found = iEvent.getByLabel(tag, c);
360 
361  if (!found && !emptyIsOk_) {
362  std::ostringstream err;
363  err << " cannot get PFCandidates: " << tag << std::endl;
364  edm::LogError("PFElectronTranslator") << err.str();
365  }
366  return found;
367 }
368 
370  const edm::InputTag& tag,
371  const edm::Event& iEvent) const {
372  bool found = iEvent.getByLabel(tag, c);
373 
374  if (!found) {
375  std::ostringstream err;
376  err << " cannot get GSFTracks: " << tag << std::endl;
377  edm::LogError("PFElectronTranslator") << err.str();
378  throw cms::Exception("MissingProduct", err.str());
379  }
380 }
381 
382 // The basic cluster is a copy of the PFCluster -> the energy is not corrected
383 // It should be possible to get the corrected energy (including the associated PS energy)
384 // from the PFCandidate daugthers ; Needs some work
386  reco::BasicClusterCollection& basicClusters,
387  std::vector<const reco::PFCluster*>& pfClusters,
388  const reco::PFCandidate& coCandidate) const {
389  const reco::PFClusterRef& myPFClusterRef = PFBE.clusterRef();
390  if (myPFClusterRef.isNull())
391  return;
392 
393  const reco::PFCluster& myPFCluster(*myPFClusterRef);
394  pfClusters.push_back(&myPFCluster);
395  // std::cout << " Creating BC " << myPFCluster.energy() << " " << coCandidate.ecalEnergy() <<" "<< coCandidate.rawEcalEnergy() <<std::endl;
396  // std::cout << " # hits " << myPFCluster.hitsAndFractions().size() << std::endl;
397 
398  // basicClusters.push_back(reco::CaloCluster(myPFCluster.energy(),
399  basicClusters.push_back(reco::CaloCluster(
400  // myPFCluster.energy(),
401  coCandidate.rawEcalEnergy(),
402  myPFCluster.position(),
403  myPFCluster.caloID(),
404  myPFCluster.hitsAndFractions(),
405  myPFCluster.algo(),
406  myPFCluster.seed()));
407 }
408 
410  reco::PreshowerClusterCollection& preshowerClusters,
411  unsigned plane) const {
412  const reco::PFClusterRef& myPFClusterRef = PFBE.clusterRef();
413  preshowerClusters.push_back(reco::PreshowerCluster(
414  myPFClusterRef->energy(), myPFClusterRef->position(), myPFClusterRef->hitsAndFractions(), plane));
415 }
416 
418  const edm::OrphanHandle<reco::BasicClusterCollection>& basicClustersHandle) {
419  unsigned size = GsfTrackRef_.size();
420  unsigned basicClusterCounter = 0;
421  basicClusterPtr_.resize(size);
422 
423  for (unsigned iGSF = 0; iGSF < size; ++iGSF) // loop on tracks
424  {
425  unsigned nbc = basicClusters_[iGSF].size();
426  for (unsigned ibc = 0; ibc < nbc; ++ibc) // loop on basic clusters
427  {
428  // std::cout << "Track "<< iGSF << " ref " << basicClusterCounter << std::endl;
429  reco::CaloClusterPtr bcPtr(basicClustersHandle, basicClusterCounter);
430  basicClusterPtr_[iGSF].push_back(bcPtr);
431  ++basicClusterCounter;
432  }
433  }
434 }
435 
437  const edm::OrphanHandle<reco::PreshowerClusterCollection>& preshowerClustersHandle) {
438  unsigned size = GsfTrackRef_.size();
439  unsigned psClusterCounter = 0;
440  preshowerClusterPtr_.resize(size);
441 
442  for (unsigned iGSF = 0; iGSF < size; ++iGSF) // loop on tracks
443  {
444  unsigned nbc = preshowerClusters_[iGSF].size();
445  for (unsigned ibc = 0; ibc < nbc; ++ibc) // loop on basic clusters
446  {
447  // std::cout << "Track "<< iGSF << " ref " << basicClusterCounter << std::endl;
448  reco::CaloClusterPtr psPtr(preshowerClustersHandle, psClusterCounter);
449  preshowerClusterPtr_[iGSF].push_back(psPtr);
450  ++psClusterCounter;
451  }
452  }
453 }
454 
456  const edm::OrphanHandle<reco::SuperClusterCollection>& superClustersHandle) {
457  unsigned size = GsfTrackRef_.size();
458 
459  for (unsigned iGSF = 0; iGSF < size; ++iGSF) // loop on tracks
460  {
461  edm::Ref<reco::SuperClusterCollection> scRef(superClustersHandle, iGSF);
462  scMap_[GsfTrackRef_[iGSF]] = scRef;
463  }
464 }
465 
467  gsfMvaMap_.clear();
469  bool status = fetchCandidateCollection(pfCandidates, inputTagPFCandidateElectrons_, iEvent);
470 
471  unsigned ncand = (status) ? pfCandidates->size() : 0;
472  for (unsigned i = 0; i < ncand; ++i) {
473  const reco::PFCandidate& cand = (*pfCandidates)[i];
474  if (cand.particleId() != reco::PFCandidate::e)
475  continue;
476  if (cand.gsfTrackRef().isNull())
477  continue;
478  // Fill the MVA map
479  gsfMvaMap_[cand.gsfTrackRef()] = cand.mva_e_pi();
480  }
481 
483  fetchGsfCollection(gsfTracks, inputTagGSFTracks_, iEvent);
484  unsigned ngsf = gsfTracks->size();
485  std::vector<float> values;
486  for (unsigned igsf = 0; igsf < ngsf; ++igsf) {
487  reco::GsfTrackRef theTrackRef(gsfTracks, igsf);
488  std::map<reco::GsfTrackRef, float>::const_iterator itcheck = gsfMvaMap_.find(theTrackRef);
489  if (itcheck == gsfMvaMap_.end()) {
490  // edm::LogWarning("PFElectronTranslator") << "MVA Map, missing GSF track ref " << std::endl;
491  values.push_back(-99.);
492  // std::cout << " Push_back -99. " << std::endl;
493  } else {
494  // std::cout << " Value " << itcheck->second << std::endl;
495  values.push_back(itcheck->second);
496  }
497  }
498  filler.insert(gsfTracks, values.begin(), values.end());
499 }
500 
504  fetchGsfCollection(gsfTracks, inputTagGSFTracks_, iEvent);
505  unsigned ngsf = gsfTracks->size();
506  std::vector<reco::SuperClusterRef> values;
507  for (unsigned igsf = 0; igsf < ngsf; ++igsf) {
508  reco::GsfTrackRef theTrackRef(gsfTracks, igsf);
509  std::map<reco::GsfTrackRef, reco::SuperClusterRef>::const_iterator itcheck = scMap_.find(theTrackRef);
510  if (itcheck == scMap_.end()) {
511  // edm::LogWarning("PFElectronTranslator") << "SCRef Map, missing GSF track ref" << std::endl;
512  values.push_back(reco::SuperClusterRef());
513  } else {
514  values.push_back(itcheck->second);
515  }
516  }
517  filler.insert(gsfTracks, values.begin(), values.end());
518 }
519 
522  unsigned nGSF = GsfTrackRef_.size();
523  for (unsigned iGSF = 0; iGSF < nGSF; ++iGSF) {
524  // Computes energy position a la e/gamma
525  double sclusterE = 0;
526  double posX = 0.;
527  double posY = 0.;
528  double posZ = 0.;
529 
530  unsigned nbasics = basicClusters_[iGSF].size();
531  for (unsigned ibc = 0; ibc < nbasics; ++ibc) {
532  double e = basicClusters_[iGSF][ibc].energy();
533  sclusterE += e;
534  posX += e * basicClusters_[iGSF][ibc].position().X();
535  posY += e * basicClusters_[iGSF][ibc].position().Y();
536  posZ += e * basicClusters_[iGSF][ibc].position().Z();
537  }
538  posX /= sclusterE;
539  posY /= sclusterE;
540  posZ /= sclusterE;
541 
542  if (pfCand[gsfPFCandidateIndex_[iGSF]].gsfTrackRef() != GsfTrackRef_[iGSF]) {
543  edm::LogError("PFElectronTranslator") << " Major problem in PFElectron Translator" << std::endl;
544  }
545 
546  // compute the width
547  PFClusterWidthAlgo pfwidth(pfClusters_[iGSF]);
548 
549  double correctedEnergy = pfCand[gsfPFCandidateIndex_[iGSF]].ecalEnergy();
550  reco::SuperCluster mySuperCluster(correctedEnergy, math::XYZPoint(posX, posY, posZ));
551  // protection against empty basic cluster collection ; the value is -2 in this case
552  if (nbasics) {
553  // std::cout << "SuperCluster creation; energy " << pfCand[gsfPFCandidateIndex_[iGSF]].ecalEnergy();
554  // std::cout << " " << pfCand[gsfPFCandidateIndex_[iGSF]].rawEcalEnergy() << std::endl;
555  // std::cout << "Seed energy from basic " << basicClusters_[iGSF][0].energy() << std::endl;
556  mySuperCluster.setSeed(basicClusterPtr_[iGSF][0]);
557  } else {
558  // std::cout << "SuperCluster creation ; seed energy " << 0 << std::endl;
559  // std::cout << "SuperCluster creation ; energy " << pfCand[gsfPFCandidateIndex_[iGSF]].ecalEnergy();
560  // std::cout << " " << pfCand[gsfPFCandidateIndex_[iGSF]].rawEcalEnergy() << std::endl;
561  // std::cout << " No seed found " << 0 << std::endl;
562  // std::cout << " MVA " << pfCand[gsfPFCandidateIndex_[iGSF]].mva_e_pi() << std::endl;
563  mySuperCluster.setSeed(reco::CaloClusterPtr());
564  }
565  // the seed should be the first basic cluster
566 
567  for (unsigned ibc = 0; ibc < nbasics; ++ibc) {
568  mySuperCluster.addCluster(basicClusterPtr_[iGSF][ibc]);
569  // std::cout <<"Adding Ref to SC " << basicClusterPtr_[iGSF][ibc].index() << std::endl;
570  const std::vector<std::pair<DetId, float>>& v1 = basicClusters_[iGSF][ibc].hitsAndFractions();
571  // std::cout << " Number of cells " << v1.size() << std::endl;
572  for (std::vector<std::pair<DetId, float>>::const_iterator diIt = v1.begin(); diIt != v1.end(); ++diIt) {
573  // std::cout << " Adding DetId " << (diIt->first).rawId() << " " << diIt->second << std::endl;
574  mySuperCluster.addHitAndFraction(diIt->first, diIt->second);
575  } // loop over rechits
576  }
577 
578  unsigned nps = preshowerClusterPtr_[iGSF].size();
579  for (unsigned ips = 0; ips < nps; ++ips) {
580  mySuperCluster.addPreshowerCluster(preshowerClusterPtr_[iGSF][ips]);
581  }
582 
583  // Set the preshower energy
584  mySuperCluster.setPreshowerEnergy(pfCand[gsfPFCandidateIndex_[iGSF]].pS1Energy() +
585  pfCand[gsfPFCandidateIndex_[iGSF]].pS2Energy());
586 
587  // Set the cluster width
588  mySuperCluster.setEtaWidth(pfwidth.pflowEtaWidth());
589  mySuperCluster.setPhiWidth(pfwidth.pflowPhiWidth());
590  // Force the computation of rawEnergy_ of the reco::SuperCluster
591  mySuperCluster.rawEnergy();
592  superClusters.push_back(mySuperCluster);
593  }
594 }
595 
597  const reco::PFBlockElement& pfbe) const {
598  unsigned refindex = pfbe.index();
599  // std::cout << " N daughters " << cand.numberOfDaughters() << std::endl;
600  reco::PFCandidate::const_iterator myDaughterCandidate = cand.begin();
601  reco::PFCandidate::const_iterator itend = cand.end();
602 
603  for (; myDaughterCandidate != itend; ++myDaughterCandidate) {
604  const reco::PFCandidate* myPFCandidate = (const reco::PFCandidate*)&*myDaughterCandidate;
605  if (myPFCandidate->elementsInBlocks().size() != 1) {
606  // std::cout << " Daughter with " << myPFCandidate.elementsInBlocks().size()<< " element in block " << std::endl;
607  return cand;
608  }
609  if (myPFCandidate->elementsInBlocks()[0].second == refindex) {
610  // std::cout << " Found it " << cand << std::endl;
611  return *myPFCandidate;
612  }
613  }
614  return cand;
615 }
616 
618  unsigned nGSF = GsfTrackRef_.size();
619  for (unsigned iGSF = 0; iGSF < nGSF; ++iGSF) {
620  reco::GsfElectronCore myElectronCore(GsfTrackRef_[iGSF]);
621  myElectronCore.setCtfTrack(kfTrackRef_[iGSF], -1.);
622  std::map<reco::GsfTrackRef, reco::SuperClusterRef>::const_iterator itcheck = scMap_.find(GsfTrackRef_[iGSF]);
623  if (itcheck != scMap_.end())
624  myElectronCore.setParentSuperCluster(itcheck->second);
625  gsfElectronCores.push_back(myElectronCore);
626  }
627 }
628 
630  const edm::OrphanHandle<reco::GsfElectronCoreCollection>& gsfElectronCoreHandle) {
631  unsigned size = GsfTrackRef_.size();
632 
633  for (unsigned iGSF = 0; iGSF < size; ++iGSF) // loop on tracks
634  {
635  edm::Ref<reco::GsfElectronCoreCollection> elecCoreRef(gsfElectronCoreHandle, iGSF);
636  gsfElectronCoreRefs_.push_back(elecCoreRef);
637  }
638 }
639 
641  std::vector<reco::GsfTrackRef>& tracks) const {
642  const reco::PFBlockElementGsfTrack* GsfEl = dynamic_cast<const reco::PFBlockElementGsfTrack*>(&PFBE);
643  if (GsfEl == nullptr)
644  return;
645  const std::vector<reco::GsfPFRecTrackRef>& ambPFRecTracks(GsfEl->GsftrackRefPF()->convBremGsfPFRecTrackRef());
646  unsigned ntracks = ambPFRecTracks.size();
647  for (unsigned it = 0; it < ntracks; ++it) {
648  tracks.push_back(ambPFRecTracks[it]->gsfTrackRef());
649  }
650 }
651 
654  reco::GsfElectronCollection& gsfelectrons) {
655  unsigned size = GsfTrackRef_.size();
656 
657  for (unsigned iGSF = 0; iGSF < size; ++iGSF) // loop on tracks
658  {
659  const reco::PFCandidate& pfCandidate(pfcand[gsfPFCandidateIndex_[iGSF]]);
660  // Electron
661  reco::GsfElectron myElectron(gsfElectronCoreRefs_[iGSF]);
662  // Warning set p4 error !
663  myElectron.setP4(reco::GsfElectron::P4_PFLOW_COMBINATION, pfCandidate.p4(), pfCandidate.deltaP(), true);
664 
665  // MVA inputs
666  reco::GsfElectron::MvaInput myMvaInput;
667  myMvaInput.earlyBrem = pfCandidate.electronExtraRef()->mvaVariable(reco::PFCandidateElectronExtra::MVA_FirstBrem);
668  myMvaInput.lateBrem = pfCandidate.electronExtraRef()->mvaVariable(reco::PFCandidateElectronExtra::MVA_LateBrem);
669  myMvaInput.deltaEta =
671  myMvaInput.sigmaEtaEta = pfCandidate.electronExtraRef()->sigmaEtaEta();
672  myMvaInput.hadEnergy = pfCandidate.electronExtraRef()->hadEnergy();
673 
674  // Mustache
675  reco::Mustache myMustache;
676  myMustache.MustacheID(
677  *(myElectron.parentSuperCluster()), myMvaInput.nClusterOutsideMustache, myMvaInput.etOutsideMustache);
678 
679  myElectron.setMvaInput(myMvaInput);
680 
681  // MVA output
682  reco::GsfElectron::MvaOutput myMvaOutput;
683  myMvaOutput.status = pfCandidate.electronExtraRef()->electronStatus();
684  myMvaOutput.mva_e_pi = pfCandidate.mva_e_pi();
685  myElectron.setMvaOutput(myMvaOutput);
686 
687  // ambiguous tracks
688  unsigned ntracks = ambiguousGsfTracks_[iGSF].size();
689  for (unsigned it = 0; it < ntracks; ++it) {
690  myElectron.addAmbiguousGsfTrack(ambiguousGsfTracks_[iGSF][it]);
691  }
692 
693  // isolation
694  if (!isolationValues.empty()) {
696  myPFIso.sumChargedHadronPt = (*isolationValues[0])[CandidatePtr_[iGSF]];
697  myPFIso.sumPhotonEt = (*isolationValues[1])[CandidatePtr_[iGSF]];
698  myPFIso.sumNeutralHadronEt = (*isolationValues[2])[CandidatePtr_[iGSF]];
699  myPFIso.sumPUPt = (*isolationValues[3])[CandidatePtr_[iGSF]];
700  myElectron.setPfIsolationVariables(myPFIso);
701  }
702 
703  gsfelectrons.push_back(myElectron);
704  }
705 }
size
Write out results.
T getParameter(std::string const &) const
std::string PFPreshowerClusterCollection_
Abstract base class for a PFBlock element (track, cluster...)
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:153
void setCtfTrack(const TrackRef &closestCtfTrack, float ctfGsfOverlap)
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:188
void MustacheID(const CaloClusterPtrVector &clusters, int &nclusters, float &EoutsideMustache)
Definition: Mustache.cc:148
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool fetchCandidateCollection(edm::Handle< reco::PFCandidateCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
double rawEcalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:223
virtual SuperClusterRef parentSuperCluster() const
Definition: GsfElectron.h:160
void addHitAndFraction(DetId id, float fraction)
Definition: CaloCluster.h:202
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:46
void produce(edm::Event &, const edm::EventSetup &) override
void createGsfElectronCoreRefs(const edm::OrphanHandle< reco::GsfElectronCoreCollection > &gsfElectronCoreHandle)
virtual const PFClusterRef & clusterRef() const
Type type() const
std::vector< reco::CaloClusterPtrVector > basicClusterPtr_
std::vector< reco::GsfElectronCoreRef > gsfElectronCoreRefs_
double pflowPhiWidth() const
void setMvaInput(const MvaInput &mi)
Definition: GsfElectron.h:660
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
void createBasicClusterPtrs(const edm::OrphanHandle< reco::BasicClusterCollection > &basicClustersHandle)
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:607
bool exists(std::string const &parameterName) const
checks if a parameter exists
const GsfPFRecTrackRef & GsftrackRefPF() const
void setSeed(const CaloClusterPtr &r)
list of used xtals by DetId // now inherited by CaloCluster
Definition: SuperCluster.h:107
std::vector< std::vector< const reco::PFCluster * > > pfClusters_
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:659
void setPhiWidth(double pw)
Definition: SuperCluster.h:73
void setMvaOutput(const MvaOutput &mo)
Definition: GsfElectron.h:661
double pflowEtaWidth() const
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::map< reco::GsfTrackRef, float > gsfMvaMap_
void fillSCRefValueMap(edm::Event &iEvent, edm::ValueMap< reco::SuperClusterRef >::Filler &filler) const
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:408
AlgoId algo() const
algorithm identifier
Definition: CaloCluster.h:189
std::map< reco::GsfTrackRef, reco::SuperClusterRef > scMap_
void setEtaWidth(double ew)
Definition: SuperCluster.h:74
std::vector< reco::GsfTrackRef > GsfTrackRef_
int iEvent
Definition: GenABIO.cc:224
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:209
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void fillMVAValueMap(edm::Event &iEvent, edm::ValueMap< float >::Filler &filler)
void setParentSuperCluster(const SuperClusterRef &scl)
const CaloID & caloID() const
Definition: CaloCluster.h:200
const reco::PFCandidate & correspondingDaughterCandidate(const reco::PFCandidate &cand, const reco::PFBlockElement &pfbe) const
unsigned index() const
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:602
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:146
std::vector< GsfElectronCore > GsfElectronCoreCollection
std::vector< reco::PreshowerClusterCollection > preshowerClusters_
void createSuperClusterGsfMapRefs(const edm::OrphanHandle< reco::SuperClusterCollection > &superClustersHandle)
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
const LorentzVector & p4() const final
four-momentum Lorentz vector
float sumNeutralHadronEt
sum pt of neutral hadrons // old float neutralHadronIso ;
Definition: GsfElectron.h:601
std::vector< int > gsfPFCandidateIndex_
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
edm::InputTag inputTagPFCandidateElectrons_
bool isNull() const
Checks for null.
Definition: Ref.h:235
std::vector< reco::CandidatePtr > CandidatePtr_
edm::InputTag inputTagPFCandidates_
std::vector< std::vector< reco::GsfTrackRef > > ambiguousGsfTracks_
edm::InputTag inputTagGSFTracks_
float mva_e_pi() const
mva for electron-pion discrimination
Definition: PFCandidate.h:316
Definition: DetId.h:17
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:58
reco::PFCandidateElectronExtraRef electronExtraRef() const
return a reference to the electron extra
Definition: PFCandidate.cc:544
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:218
void fetchGsfCollection(edm::Handle< reco::GsfTrackCollection > &c, const edm::InputTag &tag, const edm::Event &iEvent) const
void createBasicCluster(const reco::PFBlockElement &, reco::BasicClusterCollection &basicClusters, std::vector< const reco::PFCluster * > &, const reco::PFCandidate &coCandidate) const
std::vector< reco::SuperClusterCollection > superClusters_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< reco::CaloClusterPtrVector > preshowerClusterPtr_
void createSuperClusters(const reco::PFCandidateCollection &, reco::SuperClusterCollection &superClusters) const
void addPreshowerCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
Definition: SuperCluster.h:128
void getAmbiguousGsfTracks(const reco::PFBlockElement &PFBE, std::vector< reco::GsfTrackRef > &) const
std::string GsfElectronCoreCollection_
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
std::vector< edm::InputTag > inputTagIsoVals_
void addCluster(const CaloClusterPtr &r)
add reference to constituent BasicCluster
Definition: SuperCluster.h:122
std::vector< reco::BasicClusterCollection > basicClusters_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
std::vector< reco::TrackRef > kfTrackRef_
HLT enums.
void createPreshowerCluster(const reco::PFBlockElement &PFBE, reco::PreshowerClusterCollection &preshowerClusters, unsigned plane) const
PFElectronTranslator(const edm::ParameterSet &)
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:440
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
void createGsfElectronCores(reco::GsfElectronCoreCollection &) const
virtual ParticleType particleId() const
Definition: PFCandidate.h:366
void createGsfElectrons(const reco::PFCandidateCollection &, const IsolationValueMaps &isolationValues, reco::GsfElectronCollection &)
const ElementsInBlocks & elementsInBlocks() const
Definition: PFCandidate.cc:636
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:600
void addAmbiguousGsfTrack(const reco::GsfTrackRef &t)
Definition: GsfElectron.h:691
void createPreshowerClusterPtrs(const edm::OrphanHandle< reco::PreshowerClusterCollection > &preshowerClustersHandle)
def move(src, dest)
Definition: eostools.py:511
double deltaP() const
uncertainty on 3-momentum
Definition: PFCandidate.h:300
void setPreshowerEnergy(double preshowerEnergy)
Definition: SuperCluster.h:70