CMS 3D CMS Logo

GsfElectronAlgo.cc
Go to the documentation of this file.
32 
33 #include <Math/Point3D.h>
34 #include <memory>
35 
36 #include <algorithm>
37 #include <sstream>
38 
39 using namespace edm;
40 using namespace reco;
41 
43  // soft electron MVA
45  sconfig.vweightsfiles = conf.getParameter<std::vector<std::string>>("SoftElecMVAFilesString");
46  sElectronMVAEstimator = std::make_unique<SoftElectronMVAEstimator>(sconfig);
47  // isolated electron MVA
49  iconfig.vweightsfiles = conf.getParameter<std::vector<std::string>>("ElecMVAFilesString");
50  iElectronMVAEstimator = std::make_unique<ElectronMVAEstimator>(iconfig);
51 
52  // Here we will have to load the DNN PFID if present in the config
54  const auto& pset_dnn = conf.getParameter<edm::ParameterSet>("EleDNNPFid");
55  const bool dnnEnabled = pset_dnn.getParameter<bool>("enabled");
56  if (dnnEnabled) {
57  dconfig.inputTensorName = pset_dnn.getParameter<std::string>("inputTensorName");
58  dconfig.outputTensorName = pset_dnn.getParameter<std::string>("outputTensorName");
59  dconfig.modelsFiles = pset_dnn.getParameter<std::vector<std::string>>("modelsFiles");
60  dconfig.scalersFiles = pset_dnn.getParameter<std::vector<std::string>>("scalersFiles");
61  dconfig.outputDim = pset_dnn.getParameter<std::vector<unsigned int>>("outputDim");
62  const auto useEBModelInGap = pset_dnn.getParameter<bool>("useEBModelInGap");
63  iElectronDNNEstimator = std::make_unique<ElectronDNNEstimator>(dconfig, useEBModelInGap);
64  }
65 }
66 
67 //===================================================================
68 // GsfElectronAlgo::EventData
69 //===================================================================
70 
72  // utilities
73  void retreiveOriginalTrackCollections(const reco::TrackRef&, const reco::GsfTrackRef&);
74 
75  // general
76  edm::Event const* event;
78 
79  // input collections
87 
88  // isolation helpers
93 
98 
101 
102  bool originalCtfTrackCollectionRetreived = false;
103  bool originalGsfTrackCollectionRetreived = false;
104 
105  //PFCluster Isolation handles
107  std::vector<edm::Handle<reco::PFClusterCollection>> hcalClustersHandle;
108 };
109 
110 //===================================================================
111 // GsfElectronAlgo::ElectronData
112 //===================================================================
113 
115  // Refs to subproducts
122 
123  // constructors
125 
126  // utilities
127  void computeCharge(int& charge, reco::GsfElectron::ChargeInfo& info);
128  reco::CaloClusterPtr getEleBasicCluster(MultiTrajectoryStateTransform const&);
129  bool calculateTSOS(MultiTrajectoryStateTransform const&, GsfConstraintAtVertex const&);
130  void calculateMode();
131  reco::Candidate::LorentzVector calculateMomentum();
132 
133  // TSOS
141 
142  // mode
143  GlobalVector innMom, seedMom, eleMom, sclMom, vtxMom, outMom;
144  GlobalPoint innPos, seedPos, elePos, sclPos, vtxPos, outPos;
146 };
147 
149  const reco::GsfTrackRef& gsfTrack) {
150  if ((!originalCtfTrackCollectionRetreived) && (ctfTrack.isNonnull())) {
151  event->get(ctfTrack.id(), originalCtfTracks);
152  originalCtfTrackCollectionRetreived = true;
153  }
154  if ((!originalGsfTrackCollectionRetreived) && (gsfTrack.isNonnull())) {
155  event->get(gsfTrack.id(), originalGsfTracks);
156  originalGsfTrackCollectionRetreived = true;
157  }
158 }
159 
161  : coreRef(core),
162  gsfTrackRef(coreRef->gsfTrack()),
163  superClusterRef(coreRef->superCluster()),
164  ctfTrackRef(coreRef->ctfTrack()),
165  shFracInnerHits(coreRef->ctfGsfOverlap()),
166  beamSpot(bs) {}
167 
169  // determine charge from SC
170  GlobalPoint orig, scpos;
171  ele_convert(beamSpot.position(), orig);
172  ele_convert(superClusterRef->position(), scpos);
173  GlobalVector scvect(scpos - orig);
174  GlobalPoint inntkpos = innTSOS.globalPosition();
175  GlobalVector inntkvect = GlobalVector(inntkpos - orig);
176  float dPhiInnEle = normalizedPhi(scvect.barePhi() - inntkvect.barePhi());
177  if (dPhiInnEle > 0)
178  info.scPixCharge = -1;
179  else
180  info.scPixCharge = 1;
181 
182  // flags
183  int chargeGsf = gsfTrackRef->charge();
184  info.isGsfScPixConsistent = ((chargeGsf * info.scPixCharge) > 0);
185  info.isGsfCtfConsistent = (ctfTrackRef.isNonnull() && ((chargeGsf * ctfTrackRef->charge()) > 0));
186  info.isGsfCtfScPixConsistent = (info.isGsfScPixConsistent && info.isGsfCtfConsistent);
187 
188  // default charge
189  if (info.isGsfScPixConsistent || ctfTrackRef.isNull()) {
190  charge = info.scPixCharge;
191  } else {
192  charge = ctfTrackRef->charge();
193  }
194 }
195 
197  CaloClusterPtr eleRef;
198  TrajectoryStateOnSurface tempTSOS;
199  TrajectoryStateOnSurface outTSOS = mtsTransform.outerStateOnSurface(*gsfTrackRef);
200  float dphimin = 1.e30;
201  for (auto const& bc : superClusterRef->clusters()) {
202  GlobalPoint posclu(bc->position().x(), bc->position().y(), bc->position().z());
203  tempTSOS = mtsTransform.extrapolatedState(outTSOS, posclu);
204  if (!tempTSOS.isValid())
205  tempTSOS = outTSOS;
206  GlobalPoint extrap = tempTSOS.globalPosition();
207  float dphi = EleRelPointPair(posclu, extrap, beamSpot.position()).dPhi();
208  if (std::abs(dphi) < dphimin) {
209  dphimin = std::abs(dphi);
210  eleRef = bc;
211  eleTSOS = tempTSOS;
212  }
213  }
214  return eleRef;
215 }
216 
218  GsfConstraintAtVertex const& constraintAtVtx) {
219  //at innermost point
220  innTSOS = mtsTransform.innerStateOnSurface(*gsfTrackRef);
221  if (!innTSOS.isValid())
222  return false;
223 
224  //at vertex
225  // innermost state propagation to the beam spot position
227  ele_convert(beamSpot.position(), bsPos);
228  vtxTSOS = mtsTransform.extrapolatedState(innTSOS, bsPos);
229  if (!vtxTSOS.isValid())
230  vtxTSOS = innTSOS;
231 
232  //at seed
233  outTSOS = mtsTransform.outerStateOnSurface(*gsfTrackRef);
234  if (!outTSOS.isValid())
235  return false;
236 
237  // TrajectoryStateOnSurface seedTSOS
238  seedTSOS = mtsTransform.extrapolatedState(outTSOS,
239  GlobalPoint(superClusterRef->seed()->position().x(),
240  superClusterRef->seed()->position().y(),
241  superClusterRef->seed()->position().z()));
242  if (!seedTSOS.isValid())
243  seedTSOS = outTSOS;
244 
245  // at scl
246  sclTSOS = mtsTransform.extrapolatedState(
247  innTSOS, GlobalPoint(superClusterRef->x(), superClusterRef->y(), superClusterRef->z()));
248  if (!sclTSOS.isValid())
249  sclTSOS = outTSOS;
250 
251  // constrained momentum
252  constrainedVtxTSOS = constraintAtVtx.constrainAtBeamSpot(*gsfTrackRef, beamSpot);
253 
254  return true;
255 }
256 
270  multiTrajectoryStateMode::momentumFromModeCartesian(constrainedVtxTSOS, vtxMomWithConstraint);
271 }
272 
274  double scale = superClusterRef->energy() / vtxMom.mag();
276  vtxMom.x() * scale, vtxMom.y() * scale, vtxMom.z() * scale, superClusterRef->energy());
277 }
278 
280  EventData const& eventData) const {
282 
283  const reco::CaloCluster& seedCluster = *(theClus->seed());
284  DetId seedXtalId = seedCluster.seed();
285  int detector = seedXtalId.subdetId();
286  const EcalRecHitCollection* ecalRecHits = nullptr;
287  if (detector == EcalBarrel)
288  ecalRecHits = eventData.barrelRecHits.product();
289  else
290  ecalRecHits = eventData.endcapRecHits.product();
291 
292  int nSaturatedXtals = 0;
293  bool isSeedSaturated = false;
294  for (auto&& hitFractionPair : theClus->hitsAndFractions()) {
295  auto&& ecalRecHit = ecalRecHits->find(hitFractionPair.first);
296  if (ecalRecHit == ecalRecHits->end())
297  continue;
298  if (ecalRecHit->checkFlag(EcalRecHit::Flags::kSaturated)) {
299  nSaturatedXtals++;
300  if (seedXtalId == ecalRecHit->detid())
301  isSeedSaturated = true;
302  }
303  }
305  si.isSeedSaturated = isSeedSaturated;
306 
307  return si;
308 }
309 
310 template <bool full5x5>
312  ElectronHcalHelper const& hcalHelperCone,
313  ElectronHcalHelper const& hcalHelperBc,
314  EventData const& eventData,
315  CaloTopology const& topology,
316  CaloGeometry const& geometry,
318  const HcalPFCuts* hcalCuts) const {
319  using ClusterTools = EcalClusterToolsT<full5x5>;
320  reco::GsfElectron::ShowerShape showerShape;
321 
322  const reco::CaloCluster& seedCluster = *(theClus->seed());
323  // temporary, till CaloCluster->seed() is made available
324  DetId seedXtalId = seedCluster.hitsAndFractions()[0].first;
325  int detector = seedXtalId.subdetId();
326 
327  const EcalRecHitCollection* recHits = nullptr;
328  std::vector<int> recHitFlagsToBeExcluded;
329  std::vector<int> recHitSeverityToBeExcluded;
330  if (detector == EcalBarrel) {
331  recHits = eventData.barrelRecHits.product();
332  recHitFlagsToBeExcluded = cfg_.recHits.recHitFlagsToBeExcludedBarrel;
333  recHitSeverityToBeExcluded = cfg_.recHits.recHitSeverityToBeExcludedBarrel;
334  } else {
335  recHits = eventData.endcapRecHits.product();
336  recHitFlagsToBeExcluded = cfg_.recHits.recHitFlagsToBeExcludedEndcaps;
337  recHitSeverityToBeExcluded = cfg_.recHits.recHitSeverityToBeExcludedEndcaps;
338  }
339 
340  const auto& covariances = ClusterTools::covariances(seedCluster, recHits, &topology, &geometry);
341 
342  // do noise-cleaning for full5x5, by passing per crystal PF recHit thresholds and mult values
343  // mult values for EB and EE were obtained by dedicated studies
344  const auto& localCovariances = full5x5 ? ClusterTools::localCovariances(seedCluster,
345  recHits,
346  &topology,
348  &thresholds,
351  : ClusterTools::localCovariances(seedCluster, recHits, &topology);
352 
353  showerShape.sigmaEtaEta = sqrt(covariances[0]);
354  showerShape.sigmaIetaIeta = sqrt(localCovariances[0]);
355  if (!edm::isNotFinite(localCovariances[2]))
356  showerShape.sigmaIphiIphi = sqrt(localCovariances[2]);
357  showerShape.e1x5 = ClusterTools::e1x5(seedCluster, recHits, &topology);
358  showerShape.e2x5Max = ClusterTools::e2x5Max(seedCluster, recHits, &topology);
359  showerShape.e5x5 = ClusterTools::e5x5(seedCluster, recHits, &topology);
360  showerShape.r9 = ClusterTools::e3x3(seedCluster, recHits, &topology) / theClus->rawEnergy();
361 
362  const float scale = full5x5 ? showerShape.e5x5 : theClus->energy();
363 
364  for (uint id = 0; id < showerShape.hcalOverEcal.size(); ++id) {
365  showerShape.hcalOverEcal[id] = hcalHelperCone.hcalESum(*theClus, id + 1, hcalCuts) / scale;
366  showerShape.hcalOverEcalBc[id] = hcalHelperBc.hcalESum(*theClus, id + 1, hcalCuts) / scale;
367  }
368  showerShape.invalidHcal = !hcalHelperBc.hasActiveHcal(*theClus);
369  showerShape.hcalTowersBehindClusters = hcalHelperBc.hcalTowersBehindClusters(*theClus);
370  showerShape.pre7DepthHcal = false;
371 
372  // extra shower shapes
373  const float see_by_spp = showerShape.sigmaIetaIeta * showerShape.sigmaIphiIphi;
374  if (see_by_spp > 0) {
375  showerShape.sigmaIetaIphi = localCovariances[1] / see_by_spp;
376  } else if (localCovariances[1] > 0) {
377  showerShape.sigmaIetaIphi = 1.f;
378  } else {
379  showerShape.sigmaIetaIphi = -1.f;
380  }
381  showerShape.eMax = ClusterTools::eMax(seedCluster, recHits);
382  showerShape.e2nd = ClusterTools::e2nd(seedCluster, recHits);
383  showerShape.eTop = ClusterTools::eTop(seedCluster, recHits, &topology);
384  showerShape.eLeft = ClusterTools::eLeft(seedCluster, recHits, &topology);
385  showerShape.eRight = ClusterTools::eRight(seedCluster, recHits, &topology);
386  showerShape.eBottom = ClusterTools::eBottom(seedCluster, recHits, &topology);
387 
388  showerShape.e2x5Left = ClusterTools::e2x5Left(seedCluster, recHits, &topology);
389  showerShape.e2x5Right = ClusterTools::e2x5Right(seedCluster, recHits, &topology);
390  showerShape.e2x5Top = ClusterTools::e2x5Top(seedCluster, recHits, &topology);
391  showerShape.e2x5Bottom = ClusterTools::e2x5Bottom(seedCluster, recHits, &topology);
392 
393  return showerShape;
394 }
395 
396 //===================================================================
397 // GsfElectronAlgo
398 //===================================================================
399 
402  const CutsConfiguration& cuts,
403  const ElectronHcalHelper::Configuration& hcalCone,
404  const ElectronHcalHelper::Configuration& hcalBc,
406  const PFClusterIsolationConfiguration& pfiso,
408  std::unique_ptr<EcalClusterFunctionBaseClass>&& crackCorrectionFunction,
410  const edm::ParameterSet& tkIsol03,
411  const edm::ParameterSet& tkIsol04,
412  const edm::ParameterSet& tkIsolHEEP03,
413  const edm::ParameterSet& tkIsolHEEP04,
415  : cfg_{input, strategy, cuts, iso, pfiso, recHits},
416  tkIsol03CalcCfg_(tkIsol03),
417  tkIsol04CalcCfg_(tkIsol04),
418  tkIsolHEEP03CalcCfg_(tkIsolHEEP03),
419  tkIsolHEEP04CalcCfg_(tkIsolHEEP04),
420  magneticFieldToken_{cc.esConsumes()},
421  caloGeometryToken_{cc.esConsumes()},
422  caloTopologyToken_{cc.esConsumes()},
423  trackerGeometryToken_{cc.esConsumes()},
424  ecalSeveretyLevelAlgoToken_{cc.esConsumes()},
425  ecalPFRechitThresholdsToken_{cc.esConsumes()},
426  hcalHelperCone_{hcalCone, std::move(cc)},
427  hcalHelperBc_{hcalBc, std::move(cc)},
428  crackCorrectionFunction_{std::forward<std::unique_ptr<EcalClusterFunctionBaseClass>>(crackCorrectionFunction)},
429  regHelper_{reg, cfg_.strategy.useEcalRegression, cfg_.strategy.useCombinationRegression, cc}
430 
431 {
433  ecalisoAlgo_ = std::make_unique<ElectronEcalPFClusterIsolation>(pfiso.ecaldrMax,
434  pfiso.ecaldrVetoBarrel,
435  pfiso.ecaldrVetoEndcap,
436  pfiso.ecaletaStripBarrel,
437  pfiso.ecaletaStripEndcap,
438  pfiso.ecalenergyBarrel,
439  pfiso.ecalenergyEndcap);
440  hcalisoAlgo_ = std::make_unique<ElectronHcalPFClusterIsolation>(pfiso.hcaldrMax,
441  pfiso.hcaldrVetoBarrel,
442  pfiso.hcaldrVetoEndcap,
443  pfiso.hcaletaStripBarrel,
444  pfiso.hcaletaStripEndcap,
445  pfiso.hcalenergyBarrel,
446  pfiso.hcalenergyEndcap,
447  pfiso.hcaluseEt);
448 }
449 
453 
455  crackCorrectionFunction_->init(es);
456  }
457 }
458 
460  CaloGeometry const& caloGeometry,
461  EcalSeverityLevelAlgo const& ecalSeveretyLevelAlgo) {
462  auto const& hbheRecHits = event.get(cfg_.tokens.hbheRecHitsTag);
463 
464  // Isolation algos
465  float egHcalIsoConeSizeOutSmall = 0.3, egHcalIsoConeSizeOutLarge = 0.4;
466  float egHcalIsoConeSizeIn = cfg_.iso.intRadiusHcal, egHcalIsoPtMin = cfg_.iso.etMinHcal;
467 
468  float egIsoConeSizeOutSmall = 0.3, egIsoConeSizeOutLarge = 0.4, egIsoJurassicWidth = cfg_.iso.jurassicWidth;
469  float egIsoPtMinBarrel = cfg_.iso.etMinBarrel, egIsoEMinBarrel = cfg_.iso.eMinBarrel,
470  egIsoConeSizeInBarrel = cfg_.iso.intRadiusEcalBarrel;
471  float egIsoPtMinEndcap = cfg_.iso.etMinEndcaps, egIsoEMinEndcap = cfg_.iso.eMinEndcaps,
472  egIsoConeSizeInEndcap = cfg_.iso.intRadiusEcalEndcaps;
473 
474  auto barrelRecHits = event.getHandle(cfg_.tokens.barrelRecHitCollection);
475  auto endcapRecHits = event.getHandle(cfg_.tokens.endcapRecHitCollection);
476 
478  std::vector<edm::Handle<reco::PFClusterCollection>> hcalPFClusters;
480  ecalPFClusters = event.getHandle(cfg_.tokens.pfClusterProducer);
481  hcalPFClusters.push_back(event.getHandle(cfg_.tokens.pfClusterProducerHCAL));
482  if (cfg_.pfiso.useHF) {
483  hcalPFClusters.push_back(event.getHandle(cfg_.tokens.pfClusterProducerHFEM));
484  hcalPFClusters.push_back(event.getHandle(cfg_.tokens.pfClusterProducerHFHAD));
485  }
486  }
487 
488  auto ctfTracks = event.getHandle(cfg_.tokens.ctfTracks);
489 
490  EventData eventData{
491  .event = &event,
492  .beamspot = &event.get(cfg_.tokens.beamSpotTag),
493  .coreElectrons = event.getHandle(cfg_.tokens.gsfElectronCores),
494  .barrelRecHits = barrelRecHits,
495  .endcapRecHits = endcapRecHits,
496  .currentCtfTracks = ctfTracks,
497  .seeds = event.getHandle(cfg_.tokens.seedsTag),
498  .vertices = event.getHandle(cfg_.tokens.vtxCollectionTag),
499  .conversions = cfg_.strategy.fillConvVtxFitProb ? event.getHandle(cfg_.tokens.conversions)
501 
502  .hadIsolation03 = EgammaHcalIsolation(
504  egHcalIsoConeSizeOutSmall,
506  egHcalIsoConeSizeIn,
508  EgammaHcalIsolation::arrayHB{{egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin}},
511  EgammaHcalIsolation::arrayHE{{egHcalIsoPtMin,
512  egHcalIsoPtMin,
513  egHcalIsoPtMin,
514  egHcalIsoPtMin,
515  egHcalIsoPtMin,
516  egHcalIsoPtMin,
517  egHcalIsoPtMin}},
519  hbheRecHits,
520  caloGeometry,
525  .hadIsolation04 = EgammaHcalIsolation(
527  egHcalIsoConeSizeOutLarge,
529  egHcalIsoConeSizeIn,
531  EgammaHcalIsolation::arrayHB{{egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin}},
534  EgammaHcalIsolation::arrayHE{{egHcalIsoPtMin,
535  egHcalIsoPtMin,
536  egHcalIsoPtMin,
537  egHcalIsoPtMin,
538  egHcalIsoPtMin,
539  egHcalIsoPtMin,
540  egHcalIsoPtMin}},
542  hbheRecHits,
543  caloGeometry,
548  .hadIsolation03Bc = EgammaHcalIsolation(
550  egHcalIsoConeSizeOutSmall,
552  0.,
554  EgammaHcalIsolation::arrayHB{{egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin}},
557  EgammaHcalIsolation::arrayHE{{egHcalIsoPtMin,
558  egHcalIsoPtMin,
559  egHcalIsoPtMin,
560  egHcalIsoPtMin,
561  egHcalIsoPtMin,
562  egHcalIsoPtMin,
563  egHcalIsoPtMin}},
565  hbheRecHits,
566  caloGeometry,
571  .hadIsolation04Bc = EgammaHcalIsolation(
573  egHcalIsoConeSizeOutLarge,
575  0.,
577  EgammaHcalIsolation::arrayHB{{egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin, egHcalIsoPtMin}},
580  EgammaHcalIsolation::arrayHE{{egHcalIsoPtMin,
581  egHcalIsoPtMin,
582  egHcalIsoPtMin,
583  egHcalIsoPtMin,
584  egHcalIsoPtMin,
585  egHcalIsoPtMin,
586  egHcalIsoPtMin}},
588  hbheRecHits,
589  caloGeometry,
594 
595  .ecalBarrelIsol03 = EgammaRecHitIsolation(egIsoConeSizeOutSmall,
596  egIsoConeSizeInBarrel,
597  egIsoJurassicWidth,
598  egIsoPtMinBarrel,
599  egIsoEMinBarrel,
600  &caloGeometry,
601  *barrelRecHits,
602  &ecalSeveretyLevelAlgo,
603  DetId::Ecal),
604  .ecalBarrelIsol04 = EgammaRecHitIsolation(egIsoConeSizeOutLarge,
605  egIsoConeSizeInBarrel,
606  egIsoJurassicWidth,
607  egIsoPtMinBarrel,
608  egIsoEMinBarrel,
609  &caloGeometry,
610  *barrelRecHits,
611  &ecalSeveretyLevelAlgo,
612  DetId::Ecal),
613  .ecalEndcapIsol03 = EgammaRecHitIsolation(egIsoConeSizeOutSmall,
614  egIsoConeSizeInEndcap,
615  egIsoJurassicWidth,
616  egIsoPtMinEndcap,
617  egIsoEMinEndcap,
618  &caloGeometry,
619  *endcapRecHits,
620  &ecalSeveretyLevelAlgo,
621  DetId::Ecal),
622  .ecalEndcapIsol04 = EgammaRecHitIsolation(egIsoConeSizeOutLarge,
623  egIsoConeSizeInEndcap,
624  egIsoJurassicWidth,
625  egIsoPtMinEndcap,
626  egIsoEMinEndcap,
627  &caloGeometry,
628  *endcapRecHits,
629  &ecalSeveretyLevelAlgo,
630  DetId::Ecal),
631  .tkIsol03Calc = EleTkIsolFromCands(tkIsol03CalcCfg_, *ctfTracks),
632  .tkIsol04Calc = EleTkIsolFromCands(tkIsol04CalcCfg_, *ctfTracks),
633  .tkIsolHEEP03Calc = EleTkIsolFromCands(tkIsolHEEP03CalcCfg_, *ctfTracks),
634  .tkIsolHEEP04Calc = EleTkIsolFromCands(tkIsolHEEP04CalcCfg_, *ctfTracks),
635  .originalCtfTracks = {},
636  .originalGsfTracks = {},
637 
638  .ecalClustersHandle = ecalPFClusters,
639  .hcalClustersHandle = hcalPFClusters
640 
641  };
642 
643  eventData.ecalBarrelIsol03.setUseNumCrystals(cfg_.iso.useNumCrystals);
644  eventData.ecalBarrelIsol03.setVetoClustered(cfg_.iso.vetoClustered);
645  eventData.ecalBarrelIsol03.doSeverityChecks(eventData.barrelRecHits.product(),
647  eventData.ecalBarrelIsol03.doFlagChecks(cfg_.recHits.recHitFlagsToBeExcludedBarrel);
648  eventData.ecalBarrelIsol04.setUseNumCrystals(cfg_.iso.useNumCrystals);
649  eventData.ecalBarrelIsol04.setVetoClustered(cfg_.iso.vetoClustered);
650  eventData.ecalBarrelIsol04.doSeverityChecks(eventData.barrelRecHits.product(),
652  eventData.ecalBarrelIsol04.doFlagChecks(cfg_.recHits.recHitFlagsToBeExcludedBarrel);
653  eventData.ecalEndcapIsol03.setUseNumCrystals(cfg_.iso.useNumCrystals);
654  eventData.ecalEndcapIsol03.setVetoClustered(cfg_.iso.vetoClustered);
655  eventData.ecalEndcapIsol03.doSeverityChecks(eventData.endcapRecHits.product(),
657  eventData.ecalEndcapIsol03.doFlagChecks(cfg_.recHits.recHitFlagsToBeExcludedEndcaps);
658  eventData.ecalEndcapIsol04.setUseNumCrystals(cfg_.iso.useNumCrystals);
659  eventData.ecalEndcapIsol04.setVetoClustered(cfg_.iso.vetoClustered);
660  eventData.ecalEndcapIsol04.doSeverityChecks(eventData.endcapRecHits.product(),
662  eventData.ecalEndcapIsol04.doFlagChecks(cfg_.recHits.recHitFlagsToBeExcludedEndcaps);
663 
664  return eventData;
665 }
666 
670  const HcalPFCuts* hcalCuts) {
672 
673  auto const& magneticField = eventSetup.getData(magneticFieldToken_);
674  auto const& caloGeometry = eventSetup.getData(caloGeometryToken_);
675  auto const& caloTopology = eventSetup.getData(caloTopologyToken_);
676  auto const& trackerGeometry = eventSetup.getData(trackerGeometryToken_);
677  auto const& ecalSeveretyLevelAlgo = eventSetup.getData(ecalSeveretyLevelAlgoToken_);
678  auto const& thresholds = eventSetup.getData(ecalPFRechitThresholdsToken_);
679 
680  // prepare access to hcal data
683 
685  auto eventData = beginEvent(event, caloGeometry, ecalSeveretyLevelAlgo);
686  double magneticFieldInTesla = magneticField.inTesla(GlobalPoint(0., 0., 0.)).z();
687 
688  MultiTrajectoryStateTransform mtsTransform(&trackerGeometry, &magneticField);
689  GsfConstraintAtVertex constraintAtVtx(&trackerGeometry, &magneticField);
690 
691  std::optional<egamma::conv::TrackTable> ctfTrackTable = std::nullopt;
692  std::optional<egamma::conv::TrackTable> gsfTrackTable = std::nullopt;
693 
694  const GsfElectronCoreCollection* coreCollection = eventData.coreElectrons.product();
695  for (unsigned int i = 0; i < coreCollection->size(); ++i) {
696  // check there is no existing electron with this core
697  const GsfElectronCoreRef coreRef = edm::Ref<GsfElectronCoreCollection>(eventData.coreElectrons, i);
698 
699  // check there is a super-cluster
700  if (coreRef->superCluster().isNull())
701  continue;
702 
703  // prepare internal structure for electron specific data
704  ElectronData electronData(coreRef, *eventData.beamspot);
705 
706  // calculate and check Trajectory StatesOnSurface....
707  if (!electronData.calculateTSOS(mtsTransform, constraintAtVtx))
708  continue;
709 
710  eventData.retreiveOriginalTrackCollections(electronData.ctfTrackRef, electronData.coreRef->gsfTrack());
711 
712  if (!eventData.originalCtfTracks.isValid()) {
713  eventData.originalCtfTracks = eventData.currentCtfTracks;
714  }
715 
716  if (ctfTrackTable == std::nullopt) {
717  ctfTrackTable = egamma::conv::TrackTable(*eventData.originalCtfTracks);
718  }
719  if (gsfTrackTable == std::nullopt) {
720  gsfTrackTable = egamma::conv::TrackTable(*eventData.originalGsfTracks);
721  }
722 
724  electronData,
725  eventData,
726  caloTopology,
727  caloGeometry,
728  mtsTransform,
729  magneticFieldInTesla,
730  hoc,
731  ctfTrackTable.value(),
732  gsfTrackTable.value(),
733  thresholds,
734  hcalCuts);
735 
736  } // loop over tracks
737  return electrons;
738 }
739 
741  // default value
742  ele.setPassCutBasedPreselection(false);
743 
744  // kind of seeding
745  bool eg = ele.core()->ecalDrivenSeed();
746  bool pf = ele.core()->trackerDrivenSeed() && !ele.core()->ecalDrivenSeed();
747  if (eg && pf) {
748  throw cms::Exception("GsfElectronAlgo|BothEcalAndPureTrackerDriven")
749  << "An electron cannot be both egamma and purely pflow";
750  }
751  if ((!eg) && (!pf)) {
752  throw cms::Exception("GsfElectronAlgo|NeitherEcalNorPureTrackerDriven")
753  << "An electron cannot be neither egamma nor purely pflow";
754  }
755 
756  CutsConfiguration const& cfg = cfg_.cuts;
757 
758  // Et cut
759  double etaValue = EleRelPoint(ele.superCluster()->position(), bs.position()).eta();
760  double etValue = ele.superCluster()->energy() / cosh(etaValue);
761  LogTrace("GsfElectronAlgo") << "Et : " << etValue;
762  if (ele.isEB() && (etValue < cfg.minSCEtBarrel))
763  return;
764  if (ele.isEE() && (etValue < cfg.minSCEtEndcaps))
765  return;
766  LogTrace("GsfElectronAlgo") << "Et criteria are satisfied";
767 
768  // E/p cut
769  double eopValue = ele.eSuperClusterOverP();
770  LogTrace("GsfElectronAlgo") << "E/p : " << eopValue;
771  if (ele.isEB() && (eopValue > cfg.maxEOverPBarrel))
772  return;
773  if (ele.isEE() && (eopValue > cfg.maxEOverPEndcaps))
774  return;
775  if (ele.isEB() && (eopValue < cfg.minEOverPBarrel))
776  return;
777  if (ele.isEE() && (eopValue < cfg.minEOverPEndcaps))
778  return;
779  LogTrace("GsfElectronAlgo") << "E/p criteria are satisfied";
780 
781  // HoE cuts
782  LogTrace("GsfElectronAlgo") << "HoE : " << ele.hcalOverEcal();
783  double hoeCone = ele.hcalOverEcal();
784  double hoeBc = ele.hcalOverEcalBc();
785  const reco::CaloCluster& seedCluster = *(ele.superCluster()->seed());
786  int detector = seedCluster.hitsAndFractions()[0].first.subdetId();
787  bool HoEveto = false;
788  double scle = ele.superCluster()->energy();
789 
790  if (detector == EcalBarrel)
791  HoEveto = hoeCone * scle < cfg.maxHBarrelCone || hoeBc * scle < cfg.maxHBarrelBc ||
792  hoeCone < cfg.maxHOverEBarrelCone || hoeBc < cfg.maxHOverEBarrelBc;
793  else if (detector == EcalEndcap)
794  HoEveto = hoeCone * scle < cfg.maxHEndcapsCone || hoeBc * scle < cfg.maxHEndcapsBc ||
795  hoeCone < cfg.maxHOverEEndcapsCone || hoeBc < cfg.maxHOverEEndcapsBc;
796 
797  if (!HoEveto)
798  return;
799  LogTrace("GsfElectronAlgo") << "H/E criteria are satisfied";
800 
801  // delta eta criteria
802  double deta = ele.deltaEtaSuperClusterTrackAtVtx();
803  LogTrace("GsfElectronAlgo") << "delta eta : " << deta;
804  if (ele.isEB() && (std::abs(deta) > cfg.maxDeltaEtaBarrel))
805  return;
806  if (ele.isEE() && (std::abs(deta) > cfg.maxDeltaEtaEndcaps))
807  return;
808  LogTrace("GsfElectronAlgo") << "Delta eta criteria are satisfied";
809 
810  // delta phi criteria
811  double dphi = ele.deltaPhiSuperClusterTrackAtVtx();
812  LogTrace("GsfElectronAlgo") << "delta phi : " << dphi;
813  if (ele.isEB() && (std::abs(dphi) > cfg.maxDeltaPhiBarrel))
814  return;
815  if (ele.isEE() && (std::abs(dphi) > cfg.maxDeltaPhiEndcaps))
816  return;
817  LogTrace("GsfElectronAlgo") << "Delta phi criteria are satisfied";
818 
819  // sigma ieta ieta
820  LogTrace("GsfElectronAlgo") << "sigma ieta ieta : " << ele.sigmaIetaIeta();
821  if (ele.isEB() && (ele.sigmaIetaIeta() > cfg.maxSigmaIetaIetaBarrel))
822  return;
823  if (ele.isEE() && (ele.sigmaIetaIeta() > cfg.maxSigmaIetaIetaEndcaps))
824  return;
825  LogTrace("GsfElectronAlgo") << "Sigma ieta ieta criteria are satisfied";
826 
827  // fiducial
828  if (!ele.isEB() && cfg.isBarrel)
829  return;
830  if (!ele.isEE() && cfg.isEndcaps)
831  return;
832  if (cfg.isFiducial &&
833  (ele.isEBEEGap() || ele.isEBEtaGap() || ele.isEBPhiGap() || ele.isEERingGap() || ele.isEEDeeGap()))
834  return;
835  LogTrace("GsfElectronAlgo") << "Fiducial flags criteria are satisfied";
836 
837  // seed in TEC
838  edm::RefToBase<TrajectorySeed> seed = ele.gsfTrack()->extra()->seedRef();
839  ElectronSeedRef elseed = seed.castTo<ElectronSeedRef>();
840  if (eg && !cfg_.cuts.seedFromTEC) {
841  if (elseed.isNull()) {
842  throw cms::Exception("GsfElectronAlgo|NotElectronSeed") << "The GsfTrack seed is not an ElectronSeed ?!";
843  } else {
844  if (elseed->subDet(1) == 6)
845  return;
846  }
847  }
848 
849  // transverse impact parameter
850  if (std::abs(ele.gsfTrack()->dxy(bs.position())) > cfg.maxTIP)
851  return;
852  LogTrace("GsfElectronAlgo") << "TIP criterion is satisfied";
853 
854  LogTrace("GsfElectronAlgo") << "All cut based criteria are satisfied";
855  ele.setPassCutBasedPreselection(true);
856 }
857 
859  ElectronData& electronData,
860  EventData& eventData,
861  CaloTopology const& topology,
862  CaloGeometry const& geometry,
863  MultiTrajectoryStateTransform const& mtsTransform,
864  double magneticFieldInTesla,
869  const HcalPFCuts* hcalCuts) {
870  // charge ID
871  int eleCharge;
872  GsfElectron::ChargeInfo eleChargeInfo;
873  electronData.computeCharge(eleCharge, eleChargeInfo);
874 
875  // electron basic cluster
876  CaloClusterPtr elbcRef = electronData.getEleBasicCluster(mtsTransform);
877 
878  // Seed cluster
879  const reco::CaloCluster& seedCluster = *(electronData.superClusterRef->seed());
880 
881  // seed Xtal
882  // temporary, till CaloCluster->seed() is made available
883  DetId seedXtalId = seedCluster.hitsAndFractions()[0].first;
884 
885  electronData.calculateMode();
886 
887  //====================================================
888  // Candidate attributes
889  //====================================================
890 
891  Candidate::LorentzVector momentum = electronData.calculateMomentum();
892 
893  //====================================================
894  // Track-Cluster Matching
895  //====================================================
896 
898  tcMatching.electronCluster = elbcRef;
899  tcMatching.eSuperClusterOverP =
900  (electronData.vtxMom.mag() > 0) ? (electronData.superClusterRef->energy() / electronData.vtxMom.mag()) : (-1.);
901  tcMatching.eSeedClusterOverP =
902  (electronData.vtxMom.mag() > 0.) ? (seedCluster.energy() / electronData.vtxMom.mag()) : (-1);
903  tcMatching.eSeedClusterOverPout =
904  (electronData.seedMom.mag() > 0.) ? (seedCluster.energy() / electronData.seedMom.mag()) : (-1.);
905  tcMatching.eEleClusterOverPout =
906  (electronData.eleMom.mag() > 0.) ? (elbcRef->energy() / electronData.eleMom.mag()) : (-1.);
907 
908  EleRelPointPair scAtVtx(
909  electronData.superClusterRef->position(), electronData.sclPos, eventData.beamspot->position());
910  tcMatching.deltaEtaSuperClusterAtVtx = scAtVtx.dEta();
911  tcMatching.deltaPhiSuperClusterAtVtx = scAtVtx.dPhi();
912 
913  EleRelPointPair seedAtCalo(seedCluster.position(), electronData.seedPos, eventData.beamspot->position());
914  tcMatching.deltaEtaSeedClusterAtCalo = seedAtCalo.dEta();
915  tcMatching.deltaPhiSeedClusterAtCalo = seedAtCalo.dPhi();
916 
917  EleRelPointPair ecAtCalo(elbcRef->position(), electronData.elePos, eventData.beamspot->position());
918  tcMatching.deltaEtaEleClusterAtCalo = ecAtCalo.dEta();
919  tcMatching.deltaPhiEleClusterAtCalo = ecAtCalo.dPhi();
920 
921  //=======================================================
922  // Track extrapolations
923  //=======================================================
924 
926  ele_convert(electronData.vtxPos, tkExtra.positionAtVtx);
927  ele_convert(electronData.sclPos, tkExtra.positionAtCalo);
928  ele_convert(electronData.vtxMom, tkExtra.momentumAtVtx);
929  ele_convert(electronData.sclMom, tkExtra.momentumAtCalo);
930  ele_convert(electronData.seedMom, tkExtra.momentumOut);
931  ele_convert(electronData.eleMom, tkExtra.momentumAtEleClus);
933 
934  //=======================================================
935  // Closest Ctf Track
936  //=======================================================
937 
939  ctfInfo.ctfTrack = electronData.ctfTrackRef;
940  ctfInfo.shFracInnerHits = electronData.shFracInnerHits;
941 
942  //====================================================
943  // FiducialFlags, using nextToBoundary definition of gaps
944  //====================================================
945 
946  reco::GsfElectron::FiducialFlags fiducialFlags;
947  int region = seedXtalId.det();
948  int detector = seedXtalId.subdetId();
949  double feta = std::abs(electronData.superClusterRef->position().eta());
950  if (detector == EcalBarrel) {
951  fiducialFlags.isEB = true;
952  EBDetId ebdetid(seedXtalId);
953  if (EBDetId::isNextToEtaBoundary(ebdetid)) {
954  if (ebdetid.ietaAbs() == 85) {
955  fiducialFlags.isEBEEGap = true;
956  } else {
957  fiducialFlags.isEBEtaGap = true;
958  }
959  }
960  if (EBDetId::isNextToPhiBoundary(ebdetid)) {
961  fiducialFlags.isEBPhiGap = true;
962  }
963  } else if (detector == EcalEndcap) {
964  fiducialFlags.isEE = true;
965  EEDetId eedetid(seedXtalId);
966  if (EEDetId::isNextToRingBoundary(eedetid)) {
967  if (std::abs(feta) < 2.) {
968  fiducialFlags.isEBEEGap = true;
969  } else {
970  fiducialFlags.isEERingGap = true;
971  }
972  }
973  if (EEDetId::isNextToDBoundary(eedetid)) {
974  fiducialFlags.isEEDeeGap = true;
975  }
977  fiducialFlags.isEE = true;
978  //HGCalDetId eeDetid(seedXtalId);
979  // fill in fiducial information when we know how to use it...
980  } else {
981  throw cms::Exception("GsfElectronAlgo|UnknownXtalRegion")
982  << "createElectron(): do not know if it is a barrel or endcap seed cluster !!!!";
983  }
984 
985  //====================================================
986  // SaturationInfo
987  //====================================================
988 
989  auto saturationInfo = calculateSaturationInfo(electronData.superClusterRef, eventData);
990 
991  //====================================================
992  // ShowerShape
993  //====================================================
994 
995  reco::GsfElectron::ShowerShape showerShape;
996  reco::GsfElectron::ShowerShape full5x5_showerShape;
998  showerShape = calculateShowerShape<false>(electronData.superClusterRef,
1000  hcalHelperBc_,
1001  eventData,
1002  topology,
1003  geometry,
1004  thresholds,
1005  hcalCuts);
1006  full5x5_showerShape = calculateShowerShape<true>(electronData.superClusterRef,
1008  hcalHelperBc_,
1009  eventData,
1010  topology,
1011  geometry,
1012  thresholds,
1013  hcalCuts);
1014  }
1015 
1016  //====================================================
1017  // ConversionRejection
1018  //====================================================
1019 
1021  if (!ctfTracks.isValid()) {
1022  ctfTracks = eventData.currentCtfTracks;
1023  }
1024 
1025  {
1026  //get the references to the gsf and ctf tracks that are made
1027  //by the electron
1028  const reco::TrackRef el_ctftrack = electronData.coreRef->ctfTrack();
1029  const reco::GsfTrackRef& el_gsftrack = electronData.coreRef->gsfTrack();
1030 
1031  //protect against the wrong collection being passed to the function
1032  if (el_ctftrack.isNonnull() && el_ctftrack.id() != ctfTracks.id())
1033  throw cms::Exception("ConversionFinderError")
1034  << "ProductID of ctf track collection does not match ProductID of electron's CTF track! \n";
1035  if (el_gsftrack.isNonnull() && el_gsftrack.id() != eventData.originalGsfTracks.id())
1036  throw cms::Exception("ConversionFinderError")
1037  << "ProductID of gsf track collection does not match ProductID of electron's GSF track! \n";
1038  }
1039 
1040  // values of conversionInfo.flag
1041  // -9999 : Partner track was not found
1042  // 0 : Partner track found in the CTF collection using
1043  // 1 : Partner track found in the CTF collection using
1044  // 2 : Partner track found in the GSF collection using
1045  // 3 : Partner track found in the GSF collection using the electron's GSF track
1046  auto conversionInfo = egamma::conv::findConversion(*electronData.coreRef, ctfTable, gsfTable, magneticFieldInTesla);
1047 
1049  conversionVars.flags = conversionInfo.flag;
1050  conversionVars.dist = conversionInfo.dist;
1051  conversionVars.dcot = conversionInfo.dcot;
1052  conversionVars.radius = conversionInfo.radiusOfConversion;
1054  //this is an intentionally bugged version which ignores the GsfTrack
1055  //this is a bug which was introduced in reduced e/gamma where the GsfTrack gets
1056  //relinked to a new collection which means it can no longer match the conversion
1057  //as it matches based on product/id
1058  //we keep this defination for the MVAs
1059  const auto matchedConv = ConversionTools::matchedConversion(
1060  electronData.coreRef->ctfTrack(), *eventData.conversions, eventData.beamspot->position(), 2.0, 1e-6, 0);
1061  conversionVars.vtxFitProb = ConversionTools::getVtxFitProb(matchedConv);
1062  }
1063  if (conversionInfo.conversionPartnerCtfTkIdx) {
1064  conversionVars.partner = TrackBaseRef(reco::TrackRef(ctfTracks, conversionInfo.conversionPartnerCtfTkIdx.value()));
1065  } else if (conversionInfo.conversionPartnerGsfTkIdx) {
1066  conversionVars.partner =
1067  TrackBaseRef(reco::GsfTrackRef(eventData.originalGsfTracks, conversionInfo.conversionPartnerGsfTkIdx.value()));
1068  }
1069 
1070  //====================================================
1071  // Go !
1072  //====================================================
1073 
1074  electrons.emplace_back(eleCharge,
1075  eleChargeInfo,
1076  electronData.coreRef,
1077  tcMatching,
1078  tkExtra,
1079  ctfInfo,
1080  fiducialFlags,
1081  showerShape,
1082  full5x5_showerShape,
1083  conversionVars,
1084  saturationInfo);
1085  auto& ele = electrons.back();
1086  // Will be overwritten later in the case of the regression
1087  ele.setCorrectedEcalEnergyError(egamma::ecalClusterEnergyUncertaintyElectronSpecific(*(ele.superCluster())));
1088  ele.setP4(GsfElectron::P4_FROM_SUPER_CLUSTER, momentum, 0, true);
1089  ele.setMass(0.0);
1090 
1091  //====================================================
1092  // brems fractions
1093  //====================================================
1094 
1095  if (electronData.innMom.mag() > 0.) {
1096  ele.setTrackFbrem((electronData.innMom.mag() - electronData.outMom.mag()) / electronData.innMom.mag());
1097  }
1098 
1099  // the supercluster is the refined one The seed is not necessarily the first cluster
1100  // hence the use of the electronCluster
1101  SuperClusterRef sc = ele.superCluster();
1102  if (!(sc.isNull())) {
1103  CaloClusterPtr cl = ele.electronCluster();
1104  if (sc->clustersSize() > 1) {
1105  float pf_fbrem = (sc->energy() - cl->energy()) / sc->energy();
1106  ele.setSuperClusterFbrem(pf_fbrem);
1107  } else {
1108  ele.setSuperClusterFbrem(0);
1109  }
1110  }
1111 
1112  //====================================================
1113  // classification and corrections
1114  //====================================================
1115  // classification
1116  const auto elClass = egamma::classifyElectron(ele);
1117  ele.setClassification(elClass);
1118 
1119  bool unexpectedClassification = elClass == GsfElectron::UNKNOWN || elClass > GsfElectron::GAP;
1120  if (unexpectedClassification) {
1121  edm::LogWarning("GsfElectronAlgo") << "unexpected classification";
1122  }
1123 
1124  // ecal energy
1125  if (cfg_.strategy.useEcalRegression) // new
1126  {
1127  regHelper_.applyEcalRegression(ele, *eventData.vertices, *eventData.barrelRecHits, *eventData.endcapRecHits);
1128  } else // original implementation
1129  {
1131  if (ele.core()->ecalDrivenSeed()) {
1132  if (cfg_.strategy.ecalDrivenEcalEnergyFromClassBasedParameterization && !unexpectedClassification) {
1133  if (ele.isEcalEnergyCorrected()) {
1134  edm::LogWarning("ElectronEnergyCorrector::classBasedElectronEnergy") << "already done";
1135  } else {
1136  ele.setCorrectedEcalEnergy(
1138  }
1139  }
1141  ele.setCorrectedEcalEnergyError(egamma::classBasedElectronEnergyUncertainty(ele));
1142  }
1143  } else {
1145  ele.setCorrectedEcalEnergyError(egamma::simpleElectronEnergyUncertainty(ele));
1146  }
1147  }
1148  }
1149  }
1150 
1151  // momentum
1152  // Keep the default correction running first. The track momentum error is computed in there
1153  if (cfg_.strategy.useDefaultEnergyCorrection && ele.core()->ecalDrivenSeed() && !unexpectedClassification) {
1154  if (ele.p4Error(reco::GsfElectron::P4_COMBINATION) != 999.) {
1155  edm::LogWarning("ElectronMomentumCorrector::correct") << "already done";
1156  } else {
1157  auto p = egamma::correctElectronMomentum(ele, electronData.vtxTSOS);
1158  ele.correctMomentum(p.momentum, p.trackError, p.finalError);
1159  }
1160  }
1162  {
1164  }
1165 
1166  //====================================================
1167  // now isolation variables
1168  //====================================================
1170  dr03.tkSumPt = eventData.tkIsol03Calc(*ele.gsfTrack()).ptSum;
1171  dr04.tkSumPt = eventData.tkIsol04Calc(*ele.gsfTrack()).ptSum;
1172  dr03.tkSumPtHEEP = eventData.tkIsolHEEP03Calc(*ele.gsfTrack()).ptSum;
1173  dr04.tkSumPtHEEP = eventData.tkIsolHEEP04Calc(*ele.gsfTrack()).ptSum;
1174 
1176  for (uint id = 0; id < dr03.hcalRecHitSumEt.size(); ++id) {
1177  dr03.hcalRecHitSumEt[id] = eventData.hadIsolation03.getHcalEtSum(&ele, id + 1, hcalCuts);
1178  dr03.hcalRecHitSumEtBc[id] = eventData.hadIsolation03Bc.getHcalEtSumBc(&ele, id + 1, hcalCuts);
1179 
1180  dr04.hcalRecHitSumEt[id] = eventData.hadIsolation04.getHcalEtSum(&ele, id + 1, hcalCuts);
1181  dr04.hcalRecHitSumEtBc[id] = eventData.hadIsolation04Bc.getHcalEtSumBc(&ele, id + 1, hcalCuts);
1182  }
1183 
1184  dr03.ecalRecHitSumEt = eventData.ecalBarrelIsol03.getEtSum(&ele, thresholds);
1185  dr03.ecalRecHitSumEt += eventData.ecalEndcapIsol03.getEtSum(&ele, thresholds);
1186 
1187  dr04.ecalRecHitSumEt = eventData.ecalBarrelIsol04.getEtSum(&ele, thresholds);
1188  dr04.ecalRecHitSumEt += eventData.ecalEndcapIsol04.getEtSum(&ele, thresholds);
1189  }
1190 
1191  dr03.pre7DepthHcal = false;
1192  dr04.pre7DepthHcal = false;
1193 
1194  ele.setIsolation03(dr03);
1195  ele.setIsolation04(dr04);
1196 
1197  //====================================================
1198  // PFclusters based ISO !
1199  // Added in CMSSW_12_0_1 at this stage to be able to use them in PF ID DNN
1200  //====================================================
1203  isoVariables.sumEcalClusterEt = ecalisoAlgo_->getSum(ele, eventData.ecalClustersHandle);
1204  isoVariables.sumHcalClusterEt = hcalisoAlgo_->getSum(ele, eventData.hcalClustersHandle);
1205  // Other Pfiso variables are initialized at 0 and not used
1206  ele.setPfIsolationVariables(isoVariables);
1207  }
1208 
1209  //====================================================
1210  // preselection flag
1211  //====================================================
1212 
1213  setCutBasedPreselectionFlag(ele, *eventData.beamspot);
1214  //setting mva flag, currently GedGsfElectron and GsfElectron pre-selection flags have desynced
1215  //this is for GedGsfElectrons, GsfElectrons (ie old pre 7X std reco) resets this later on
1216  //in the function "addPfInfo"
1217  //yes this is awful, we'll fix it once we work out how to...
1218  float mvaValue = hoc->sElectronMVAEstimator->mva(ele, *(eventData.vertices));
1219  ele.setPassMvaPreselection(mvaValue > cfg_.strategy.PreSelectMVA);
1220 
1221  //====================================================
1222  // Pixel match variables
1223  //====================================================
1225 
1226  LogTrace("GsfElectronAlgo") << "Constructed new electron with energy " << ele.p4().e();
1227 }
1228 
1229 // Pixel match variables
1231  int sd1 = 0;
1232  int sd2 = 0;
1233  float dPhi1 = 0;
1234  float dPhi2 = 0;
1235  float dRz1 = 0;
1236  float dRz2 = 0;
1237  edm::RefToBase<TrajectorySeed> seed = ele.gsfTrack()->extra()->seedRef();
1238  ElectronSeedRef elseed = seed.castTo<ElectronSeedRef>();
1239  if (seed.isNull()) {
1240  } else {
1241  if (elseed.isNull()) {
1242  } else {
1243  sd1 = elseed->subDet(0);
1244  sd2 = elseed->subDet(1);
1245  dPhi1 = (ele.charge() > 0) ? elseed->dPhiPos(0) : elseed->dPhiNeg(0);
1246  dPhi2 = (ele.charge() > 0) ? elseed->dPhiPos(1) : elseed->dPhiNeg(1);
1247  dRz1 = (ele.charge() > 0) ? elseed->dRZPos(0) : elseed->dRZNeg(0);
1248  dRz2 = (ele.charge() > 0) ? elseed->dRZPos(1) : elseed->dRZNeg(1);
1249  }
1250  }
1251  ele.setPixelMatchSubdetectors(sd1, sd2);
1252  ele.setPixelMatchDPhi1(dPhi1);
1253  ele.setPixelMatchDPhi2(dPhi2);
1254  ele.setPixelMatchDRz1(dRz1);
1255  ele.setPixelMatchDRz2(dRz2);
1256 }
edm::EDGetTokenT< HBHERecHitCollection > hbheRecHitsTag
EleTkIsolFromCands tkIsol03Calc
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:153
EleTkIsolFromCands tkIsol04Calc
edm::Handle< reco::TrackCollection > originalCtfTracks
EgammaRecHitIsolation ecalEndcapIsol04
EgammaRecHitIsolation ecalBarrelIsol03
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
edm::Handle< reco::ElectronSeedCollection > seeds
EgammaHcalIsolation hadIsolation04Bc
static bool isHGCalDet(DetId::Detector thedet)
identify HGCal cells
Definition: EcalTools.h:49
std::array< float, 7 > hcalRecHitSumEt
Definition: GsfElectron.h:540
EgammaHcalIsolation::arrayHB eThresHB() const
void applyCombinationRegression(reco::GsfElectron &ele) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static bool isNextToEtaBoundary(EBDetId id)
Definition: EBDetId.cc:108
EgammaRecHitIsolation ecalEndcapIsol03
static const TGPicture * info(bool iBackgroundIsBlack)
void setPassCutBasedPreselection(bool flag)
Definition: GsfElectron.h:770
double classBasedElectronEnergyUncertainty(reco::GsfElectron const &)
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:209
void setPixelMatchDRz2(float dRz2)
Definition: GsfElectron.h:933
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
ProductID id() const
Definition: HandleBase.cc:29
edm::EDGetTokenT< reco::ConversionCollection > conversions
void setCutBasedPreselectionFlag(reco::GsfElectron &ele, const reco::BeamSpot &) const
const Point & position() const
position
Definition: BeamSpot.h:59
void retreiveOriginalTrackCollections(const reco::TrackRef &, const reco::GsfTrackRef &)
void setPixelMatchDPhi1(float dPhi1)
Definition: GsfElectron.h:930
bool hasActiveHcal(const reco::SuperCluster &sc) const
const auto towerMap() const
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
TrajectoryStateOnSurface outerStateOnSurface(const reco::GsfTrack &tk) const
bool isEBPhiGap() const
Definition: GsfElectron.h:334
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHFEM
constexpr T normalizedPhi(T phi)
Definition: normalizedPhi.h:8
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:218
std::array< float, 7 > hcalRecHitSumEtBc
Definition: GsfElectron.h:541
float sigmaIetaIeta() const
Definition: GsfElectron.h:419
void createElectron(reco::GsfElectronCollection &electrons, ElectronData &electronData, EventData &eventData, CaloTopology const &topology, CaloGeometry const &geometry, MultiTrajectoryStateTransform const &mtsTransform, double magneticFieldInTesla, const HeavyObjectCache *, egamma::conv::TrackTableView ctfTable, egamma::conv::TrackTableView gsfTable, EcalPFRecHitThresholds const &thresholds, const HcalPFCuts *hcalCuts)
bool isEERingGap() const
Definition: GsfElectron.h:337
EgammaHcalIsolation::arrayHE eThresHE() const
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHCAL
Definition: __init__.py:1
TrajectoryStateOnSurface sclTSOS
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
edm::Handle< EcalRecHitCollection > endcapRecHits
EgammaHcalIsolation hadIsolation03
ConversionInfo findConversion(const reco::GsfElectronCore &gsfElectron, TrackTableView ctfTable, TrackTableView gsfTable, float bFieldAtOrigin, float minFracSharedHits=0.45f)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
GsfElectronAlgo(const Tokens &, const StrategyConfiguration &, const CutsConfiguration &cutsCfg, const ElectronHcalHelper::Configuration &hcalCone, const ElectronHcalHelper::Configuration &hcalBc, const IsolationConfiguration &, const PFClusterIsolationConfiguration &, const EcalRecHitsConfiguration &, std::unique_ptr< EcalClusterFunctionBaseClass > &&crackCorrectionFunction, const RegressionHelper::Configuration &regCfg, const edm::ParameterSet &tkIsol03Cfg, const edm::ParameterSet &tkIsol04Cfg, const edm::ParameterSet &tkIsolHEEP03Cfg, const edm::ParameterSet &tkIsolHEEP04Cfg, edm::ConsumesCollector &&cc)
edm::Event const * event
edm::EDGetTokenT< reco::VertexCollection > vtxCollectionTag
float hcalOverEcalBc(const ShowerShape &ss, int depth) const
Definition: GsfElectron.h:442
static reco::Conversion const * matchedConversion(const reco::GsfElectron &ele, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
void computeCharge(int &charge, reco::GsfElectron::ChargeInfo &info)
edm::EDGetTokenT< EcalRecHitCollection > endcapRecHitCollection
TrajectoryStateOnSurface innTSOS
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHFHAD
bool isEBEtaGap() const
Definition: GsfElectron.h:333
void setPixelMatchSubdetectors(int sd1, int sd2)
Definition: GsfElectron.h:929
#define LogTrace(id)
float eSuperClusterOverP() const
Definition: GsfElectron.h:221
static std::string const input
Definition: EdmProvDump.cc:50
edm::EDGetTokenT< reco::GsfElectronCoreCollection > gsfElectronCores
T barePhi() const
Definition: PV3DBase.h:65
EgammaHcalIsolation hadIsolation03Bc
bool isEB() const
Definition: GsfElectron.h:328
RegressionHelper regHelper_
const Configuration cfg_
TrajectoryStateOnSurface constrainedVtxTSOS
reco::GsfElectronCollection completeElectrons(edm::Event const &event, edm::EventSetup const &eventSetup, const HeavyObjectCache *hoc, const HcalPFCuts *hcalCuts)
double getHcalEtSumBc(const reco::Candidate *c, int depth, const HcalPFCuts *hcalCuts) const
double simpleElectronEnergyUncertainty(reco::GsfElectron const &)
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
std::array< float, 7 > hcalOverEcal
Definition: GsfElectron.h:371
const edm::ESGetToken< EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd > ecalPFRechitThresholdsToken_
static float getVtxFitProb(const reco::Conversion *conv)
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:35
const edm::ESGetToken< EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd > ecalSeveretyLevelAlgoToken_
edm::soa::ViewFromTable_t< TrackTable > TrackTableView
void checkSetup(edm::EventSetup const &eventSetup)
bool positionFromModeCartesian(TrajectoryStateOnSurface const &tsos, GlobalPoint &position)
void beginEvent(const edm::Event &evt, const edm::EventSetup &eventSetup)
T sqrt(T t)
Definition: SSEVec.h:19
edm::Handle< reco::PFClusterCollection > ecalClustersHandle
static bool isNextToPhiBoundary(EBDetId id)
Definition: EBDetId.cc:113
TrajectoryStateOnSurface innerStateOnSurface(const reco::GsfTrack &tk) const
edm::Handle< EcalRecHitCollection > barrelRecHits
std::vector< GsfElectronCore > GsfElectronCoreCollection
bool isEBEEGap() const
Definition: GsfElectron.h:331
edm::EDGetTokenT< reco::BeamSpot > beamSpotTag
T mag() const
Definition: PV3DBase.h:64
const EleTkIsolFromCands::Configuration tkIsol03CalcCfg_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HeavyObjectCache(const edm::ParameterSet &)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
std::vector< CaloTowerDetId > hcalTowersBehindClusters
Definition: GsfElectron.h:374
std::unique_ptr< EcalClusterFunctionBaseClass > crackCorrectionFunction_
const IsolationConfiguration iso
static bool isNextToRingBoundary(EEDetId id)
Definition: EEDetId.cc:284
edm::EDGetTokenT< reco::TrackCollection > ctfTracks
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
reco::GsfElectron::ShowerShape calculateShowerShape(const reco::SuperClusterRef &, ElectronHcalHelper const &hcalHelperCone, ElectronHcalHelper const &hcalHelperBc, EventData const &eventData, CaloTopology const &topology, CaloGeometry const &geometry, EcalPFRecHitThresholds const &thresholds, const HcalPFCuts *hcalCuts) const
bool isEEDeeGap() const
Definition: GsfElectron.h:336
edm::EDGetTokenT< reco::ElectronSeedCollection > seedsTag
const reco::BeamSpot * beamspot
float classBasedElectronEnergy(reco::GsfElectron const &, reco::BeamSpot const &, EcalClusterFunctionBaseClass const &crackCorrectionFunction)
edm::Handle< reco::ConversionCollection > conversions
static bool isNextToDBoundary(EEDetId id)
Definition: EEDetId.cc:279
bool isNull() const
Checks for null.
Definition: Ref.h:235
std::vector< edm::Handle< reco::PFClusterCollection > > hcalClustersHandle
float hcalOverEcal(const ShowerShape &ss, int depth) const
Definition: GsfElectron.h:425
EleTkIsolFromCands tkIsolHEEP04Calc
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:228
reco::GsfElectron::SaturationInfo calculateSaturationInfo(const reco::SuperClusterRef &, EventData const &eventData) const
const_iterator end() const
double energy() const
cluster energy
Definition: CaloCluster.h:148
bool calculateTSOS(MultiTrajectoryStateTransform const &, GsfConstraintAtVertex const &)
const EleTkIsolFromCands::Configuration tkIsolHEEP04CalcCfg_
void setPixelMatchDPhi2(float dPhi2)
Definition: GsfElectron.h:931
reco::CaloClusterPtr getEleBasicCluster(MultiTrajectoryStateTransform const &)
Definition: DetId.h:17
edm::Handle< reco::VertexCollection > vertices
EgammaRecHitIsolation ecalBarrelIsol04
const PFClusterIsolationConfiguration pfiso
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:225
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducer
ElectronMomentum correctElectronMomentum(reco::GsfElectron const &, TrajectoryStateOnSurface const &)
float ecalClusterEnergyUncertaintyElectronSpecific(reco::SuperCluster const &superCluster)
bool isEE() const
Definition: GsfElectron.h:329
Detector
Definition: DetId.h:24
const reco::GsfTrackRef gsfTrackRef
TrajectoryStateOnSurface extrapolatedState(const TrajectoryStateOnSurface tsos, const GlobalPoint &point) const
void setPixelMatchInfomation(reco::GsfElectron &) const
void ele_convert(const Type1 &obj1, Type2 &obj2)
void applyEcalRegression(reco::GsfElectron &electron, const reco::VertexCollection &vertices, const EcalRecHitCollection &rechitsEB, const EcalRecHitCollection &rechitsEE) const
auto hcalTowersBehindClusters(const reco::SuperCluster &sc) const
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
std::array< float, 7 > hcalOverEcalBc
Definition: GsfElectron.h:373
const StrategyConfiguration strategy
edm::soa::AddColumns< edm::soa::PtEtaPhiTable, TrackTableSpecificColumns >::type TrackTable
std::vector< std::string > vweightsfiles
math::XYZVectorF momentumAtVtxWithConstraint
Definition: GsfElectron.h:262
TrajectoryStateOnSurface seedTSOS
EgammaHcalIsolation hadIsolation04
iterator find(key_type k)
fixed size matrix
edm::Handle< reco::GsfTrackCollection > originalGsfTracks
TrajectoryStateOnSurface constrainAtBeamSpot(const reco::GsfTrack &, const reco::BeamSpot &) const
(multi)TSOS after including the beamspot
const CutsConfiguration cuts
HLT enums.
double getHcalEtSum(const reco::Candidate *c, int depth, const HcalPFCuts *hcalCuts) const
const EcalRecHitsConfiguration recHits
ElectronHcalHelper hcalHelperCone_
const reco::GsfElectronCoreRef coreRef
ElectronHcalHelper hcalHelperBc_
edm::Handle< reco::TrackCollection > currentCtfTracks
std::unique_ptr< ElectronHcalPFClusterIsolation > hcalisoAlgo_
std::unique_ptr< ElectronEcalPFClusterIsolation > ecalisoAlgo_
const auto hcalTopology() const
edm::EDGetTokenT< EcalRecHitCollection > barrelRecHitCollection
const reco::SuperClusterRef superClusterRef
TrajectoryStateOnSurface eleTSOS
std::unique_ptr< const SoftElectronMVAEstimator > sElectronMVAEstimator
TrajectoryStateOnSurface outTSOS
ElectronData(const reco::GsfElectronCoreRef &core, const reco::BeamSpot &bs)
double getEtSum(const reco::Candidate *emObject, EcalPFRecHitThresholds const &thresholds) const
Log< level::Warning, false > LogWarning
bool momentumFromModeCartesian(TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
const auto hcalChannelQuality() const
double hcalESum(const reco::SuperCluster &, int depth, const HcalPFCuts *hcalCuts) const
std::array< double, 4 > arrayHB
EventData beginEvent(edm::Event const &event, CaloGeometry const &caloGeometry, EcalSeverityLevelAlgo const &ecalSeveretyLevelAlgo)
strategy
Definition: nnet_common.h:18
edm::Handle< reco::GsfElectronCoreCollection > coreElectrons
const EleTkIsolFromCands::Configuration tkIsolHEEP03CalcCfg_
const edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
reco::GsfElectron::Classification classifyElectron(reco::GsfElectron const &)
void checkSetup(const edm::EventSetup &)
void setPixelMatchDRz1(float dRz1)
Definition: GsfElectron.h:932
def move(src, dest)
Definition: eostools.py:511
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:155
const EleTkIsolFromCands::Configuration tkIsol04CalcCfg_
Definition: event.py:1
math::PtEtaPhiELorentzVectorF LorentzVector
int charge() const final
electric charge
Global3DVector GlobalVector
Definition: GlobalVector.h:10
const auto hcalSevLvlComputer() const
TrajectoryStateOnSurface vtxTSOS
EleTkIsolFromCands tkIsolHEEP03Calc
reco::Candidate::LorentzVector calculateMomentum()
const reco::BeamSpot beamSpot
std::array< double, 7 > arrayHE