CMS 3D CMS Logo

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