CMS 3D CMS Logo

GsfElectronProducer.cc
Go to the documentation of this file.
24 
25 using namespace reco;
26 
27 namespace {
28 
29  void setMVAOutputs(reco::GsfElectronCollection& electrons,
32  for (auto& el : electrons) {
33  GsfElectron::MvaOutput mvaOutput;
34  mvaOutput.mva_e_pi = hoc->sElectronMVAEstimator->mva(el, vertices);
35  mvaOutput.mva_Isolated = hoc->iElectronMVAEstimator->mva(el, vertices.size());
36  el.setMvaOutput(mvaOutput);
37  }
38  }
39 
40  // Something more clever has to be found. The collections are small, so the timing is not
41  // an issue here; but it is clearly suboptimal
42 
43  auto matchWithPFCandidates(std::vector<reco::PFCandidate> const& pfCandidates) {
44  std::map<reco::GsfTrackRef, reco::GsfElectron::MvaInput> gsfMVAInputs{};
45 
46  //Loop over the collection of PFFCandidates
47  for (auto const& pfCand : pfCandidates) {
49  // First check that the GsfTrack is non null
50  if (pfCand.gsfTrackRef().isNonnull()) {
52  input.earlyBrem = pfCand.egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_FirstBrem);
53  input.lateBrem = pfCand.egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_LateBrem);
54  input.deltaEta = pfCand.egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_DeltaEtaTrackCluster);
55  input.sigmaEtaEta = pfCand.egammaExtraRef()->sigmaEtaEta();
56  input.hadEnergy = pfCand.egammaExtraRef()->hadEnergy();
57  gsfMVAInputs[pfCand.gsfTrackRef()] = input;
58  }
59  }
60  return gsfMVAInputs;
61  }
62 
63  void logElectrons(reco::GsfElectronCollection const& electrons, edm::Event const& event, const std::string& title) {
64  LogTrace("GsfElectronAlgo") << "========== " << title << " ==========";
65  LogTrace("GsfElectronAlgo") << "Event: " << event.id();
66  LogTrace("GsfElectronAlgo") << "Number of electrons: " << electrons.size();
67  for (auto const& ele : electrons) {
68  LogTrace("GsfElectronAlgo") << "Electron with charge, pt, eta, phi: " << ele.charge() << " , " << ele.pt()
69  << " , " << ele.eta() << " , " << ele.phi();
70  }
71  LogTrace("GsfElectronAlgo") << "=================================================";
72  }
73 
74 } // namespace
75 
76 class GsfElectronProducer : public edm::stream::EDProducer<edm::GlobalCache<GsfElectronAlgo::HeavyObjectCache>> {
77 public:
79 
81 
82  static std::unique_ptr<GsfElectronAlgo::HeavyObjectCache> initializeGlobalCache(const edm::ParameterSet& conf) {
83  return std::make_unique<GsfElectronAlgo::HeavyObjectCache>(conf);
84  }
85 
87 
88  // ------------ method called to produce the data ------------
89  void produce(edm::Event& event, const edm::EventSetup& setup) override;
90 
91 private:
92  std::unique_ptr<GsfElectronAlgo> algo_;
93 
94  // configurables
99 
100  bool isPreselected(reco::GsfElectron const& ele) const;
101  void setAmbiguityData(reco::GsfElectronCollection& electrons,
102  edm::Event const& event,
103  bool ignoreNotPreselected = true) const;
104 
105  // check expected configuration of previous modules
107  void checkEcalSeedingParameters(edm::ParameterSet const&);
108 
112 
113  const bool useGsfPfRecTracks_;
114 
116 };
117 
120  // input collections
121  desc.add<edm::InputTag>("gsfElectronCoresTag", {"ecalDrivenGsfElectronCores"});
122  desc.add<edm::InputTag>("hcalTowers", {"towerMaker"});
123  desc.add<edm::InputTag>("vtxTag", {"offlinePrimaryVertices"});
124  desc.add<edm::InputTag>("conversionsTag", {"allConversions"});
125  desc.add<edm::InputTag>("gsfPfRecTracksTag", {"pfTrackElec"});
126  desc.add<edm::InputTag>("barrelRecHitCollectionTag", {"ecalRecHit", "EcalRecHitsEB"});
127  desc.add<edm::InputTag>("endcapRecHitCollectionTag", {"ecalRecHit", "EcalRecHitsEE"});
128  desc.add<edm::InputTag>("seedsTag", {"ecalDrivenElectronSeeds"});
129  desc.add<edm::InputTag>("beamSpotTag", {"offlineBeamSpot"});
130  desc.add<edm::InputTag>("egmPFCandidatesTag", {"particleFlowEGamma"});
131  desc.add<bool>("checkHcalStatus", true);
132 
133  // steering
134  desc.add<bool>("useDefaultEnergyCorrection", true);
135  desc.add<bool>("useCombinationRegression", false);
136  desc.add<bool>("ecalDrivenEcalEnergyFromClassBasedParameterization", true);
137  desc.add<bool>("ecalDrivenEcalErrorFromClassBasedParameterization", true);
138  desc.add<bool>("applyPreselection", false);
139  desc.add<bool>("useEcalRegression", false);
140  desc.add<bool>("applyAmbResolution", false);
141  desc.add<bool>("ignoreNotPreselected", true);
142  desc.add<bool>("useGsfPfRecTracks", true);
143  desc.add<bool>("pureTrackerDrivenEcalErrorFromSimpleParameterization", true);
144  desc.add<unsigned int>("ambSortingStrategy", 1);
145  desc.add<unsigned int>("ambClustersOverlapStrategy", 1);
146  desc.add<bool>("fillConvVtxFitProb", true);
147  desc.add<bool>("resetMvaValuesUsingPFCandidates", false);
148 
149  // Ecal rec hits configuration
150  desc.add<std::vector<std::string>>("recHitFlagsToBeExcludedBarrel");
151  desc.add<std::vector<std::string>>("recHitFlagsToBeExcludedEndcaps");
152  desc.add<std::vector<std::string>>("recHitSeverityToBeExcludedBarrel");
153  desc.add<std::vector<std::string>>("recHitSeverityToBeExcludedEndcaps");
154 
155  // Isolation algos configuration
156  desc.add("trkIsol03Cfg", EleTkIsolFromCands::pSetDescript());
157  desc.add("trkIsol04Cfg", EleTkIsolFromCands::pSetDescript());
158  desc.add("trkIsolHEEP03Cfg", EleTkIsolFromCands::pSetDescript());
159  desc.add("trkIsolHEEP04Cfg", EleTkIsolFromCands::pSetDescript());
160  desc.add<bool>("useNumCrystals", true);
161  desc.add<double>("etMinBarrel", 0.0);
162  desc.add<double>("etMinEndcaps", 0.11);
163  desc.add<double>("etMinHcal", 0.0);
164  desc.add<double>("eMinBarrel", 0.095);
165  desc.add<double>("eMinEndcaps", 0.0);
166  desc.add<double>("intRadiusEcalBarrel", 3.0);
167  desc.add<double>("intRadiusEcalEndcaps", 3.0);
168  desc.add<double>("intRadiusHcal", 0.15);
169  desc.add<double>("jurassicWidth", 1.5);
170  desc.add<bool>("vetoClustered", false);
171 
172  // backward compatibility mechanism for ctf tracks
173  desc.add<bool>("ctfTracksCheck", true);
174  desc.add<edm::InputTag>("ctfTracksTag", {"generalTracks"});
175 
176  desc.add<double>("MaxElePtForOnlyMVA", 50.0);
177  desc.add<double>("PreSelectMVA", -0.1);
178 
179  {
181  psd0.add<double>("minSCEtBarrel", 4.0);
182  psd0.add<double>("minSCEtEndcaps", 4.0);
183  psd0.add<double>("minEOverPBarrel", 0.0);
184  psd0.add<double>("minEOverPEndcaps", 0.0);
185  psd0.add<double>("maxEOverPBarrel", 999999999.0);
186  psd0.add<double>("maxEOverPEndcaps", 999999999.0);
187  psd0.add<double>("maxDeltaEtaBarrel", 0.02);
188  psd0.add<double>("maxDeltaEtaEndcaps", 0.02);
189  psd0.add<double>("maxDeltaPhiBarrel", 0.15);
190  psd0.add<double>("maxDeltaPhiEndcaps", 0.15);
191  psd0.add<double>("hOverEConeSize", 0.15);
192  psd0.add<double>("hOverEPtMin", 0.0);
193  psd0.add<double>("maxHOverEBarrelCone", 0.15);
194  psd0.add<double>("maxHOverEEndcapsCone", 0.15);
195  psd0.add<double>("maxHBarrelCone", 0.0);
196  psd0.add<double>("maxHEndcapsCone", 0.0);
197  psd0.add<double>("maxHOverEBarrelTower", 0.15);
198  psd0.add<double>("maxHOverEEndcapsTower", 0.15);
199  psd0.add<double>("maxHBarrelTower", 0.0);
200  psd0.add<double>("maxHEndcapsTower", 0.0);
201  psd0.add<double>("maxSigmaIetaIetaBarrel", 999999999.0);
202  psd0.add<double>("maxSigmaIetaIetaEndcaps", 999999999.0);
203  psd0.add<double>("maxFbremBarrel", 999999999.0);
204  psd0.add<double>("maxFbremEndcaps", 999999999.0);
205  psd0.add<bool>("isBarrel", false);
206  psd0.add<bool>("isEndcaps", false);
207  psd0.add<bool>("isFiducial", false);
208  psd0.add<bool>("seedFromTEC", true);
209  psd0.add<double>("maxTIP", 999999999.0);
210  // preselection parameters
211  desc.add<edm::ParameterSetDescription>("preselection", psd0);
212  }
213 
214  // Corrections
215  desc.add<std::string>("superClusterErrorFunction", "EcalClusterEnergyUncertaintyObjectSpecific");
216  desc.add<std::string>("crackCorrectionFunction", "EcalClusterCrackCorrection");
217 
218  desc.add<bool>("ecalWeightsFromDB", true);
219  desc.add<std::vector<std::string>>("ecalRefinedRegressionWeightFiles", {})
220  ->setComment("if not from DB. Otherwise, keep empty");
221  desc.add<bool>("combinationWeightsFromDB", true);
222  desc.add<std::vector<std::string>>("combinationRegressionWeightFile", {})
223  ->setComment("if not from DB. Otherwise, keep empty");
224 
225  // regression. The labels are needed in all cases.
226  desc.add<std::vector<std::string>>("ecalRefinedRegressionWeightLabels", {});
227  desc.add<std::vector<std::string>>("combinationRegressionWeightLabels", {});
228 
229  desc.add<std::vector<std::string>>(
230  "ElecMVAFilesString",
231  {
232  "RecoEgamma/ElectronIdentification/data/TMVA_Category_BDTSimpleCat_10_17Feb2011.weights.xml",
233  "RecoEgamma/ElectronIdentification/data/TMVA_Category_BDTSimpleCat_12_17Feb2011.weights.xml",
234  "RecoEgamma/ElectronIdentification/data/TMVA_Category_BDTSimpleCat_20_17Feb2011.weights.xml",
235  "RecoEgamma/ElectronIdentification/data/TMVA_Category_BDTSimpleCat_22_17Feb2011.weights.xml",
236  });
237  desc.add<std::vector<std::string>>(
238  "SoftElecMVAFilesString",
239  {
240  "RecoEgamma/ElectronIdentification/data/TMVA_BDTSoftElectrons_7Feb2014.weights.xml",
241  });
242 
243  descriptions.add("gsfElectronProducer", desc);
244 }
245 
246 namespace {
247  GsfElectronAlgo::CutsConfiguration makeCutsConfiguration(edm::ParameterSet const& pset) {
249  .minSCEtBarrel = pset.getParameter<double>("minSCEtBarrel"),
250  .minSCEtEndcaps = pset.getParameter<double>("minSCEtEndcaps"),
251  .maxEOverPBarrel = pset.getParameter<double>("maxEOverPBarrel"),
252  .maxEOverPEndcaps = pset.getParameter<double>("maxEOverPEndcaps"),
253  .minEOverPBarrel = pset.getParameter<double>("minEOverPBarrel"),
254  .minEOverPEndcaps = pset.getParameter<double>("minEOverPEndcaps"),
255  .maxHOverEBarrelCone = pset.getParameter<double>("maxHOverEBarrelCone"),
256  .maxHOverEEndcapsCone = pset.getParameter<double>("maxHOverEEndcapsCone"),
257  .maxHBarrelCone = pset.getParameter<double>("maxHBarrelCone"),
258  .maxHEndcapsCone = pset.getParameter<double>("maxHEndcapsCone"),
259  .maxHOverEBarrelTower = pset.getParameter<double>("maxHOverEBarrelTower"),
260  .maxHOverEEndcapsTower = pset.getParameter<double>("maxHOverEEndcapsTower"),
261  .maxHBarrelTower = pset.getParameter<double>("maxHBarrelTower"),
262  .maxHEndcapsTower = pset.getParameter<double>("maxHEndcapsTower"),
263  .maxDeltaEtaBarrel = pset.getParameter<double>("maxDeltaEtaBarrel"),
264  .maxDeltaEtaEndcaps = pset.getParameter<double>("maxDeltaEtaEndcaps"),
265  .maxDeltaPhiBarrel = pset.getParameter<double>("maxDeltaPhiBarrel"),
266  .maxDeltaPhiEndcaps = pset.getParameter<double>("maxDeltaPhiEndcaps"),
267  .maxSigmaIetaIetaBarrel = pset.getParameter<double>("maxSigmaIetaIetaBarrel"),
268  .maxSigmaIetaIetaEndcaps = pset.getParameter<double>("maxSigmaIetaIetaEndcaps"),
269  .maxFbremBarrel = pset.getParameter<double>("maxFbremBarrel"),
270  .maxFbremEndcaps = pset.getParameter<double>("maxFbremEndcaps"),
271  .isBarrel = pset.getParameter<bool>("isBarrel"),
272  .isEndcaps = pset.getParameter<bool>("isEndcaps"),
273  .isFiducial = pset.getParameter<bool>("isFiducial"),
274  .maxTIP = pset.getParameter<double>("maxTIP"),
275  .seedFromTEC = pset.getParameter<bool>("seedFromTEC"),
276  };
277  }
278 }; // namespace
279 
281  : cutsCfg_{makeCutsConfiguration(cfg.getParameter<edm::ParameterSet>("preselection"))},
282  ecalSeedingParametersChecked_(false),
283  electronPutToken_(produces<GsfElectronCollection>()),
284  gsfPfRecTracksTag_(consumes(cfg.getParameter<edm::InputTag>("gsfPfRecTracksTag"))),
285  useGsfPfRecTracks_(cfg.getParameter<bool>("useGsfPfRecTracks")),
286  resetMvaValuesUsingPFCandidates_(cfg.getParameter<bool>("resetMvaValuesUsingPFCandidates")) {
287  if (resetMvaValuesUsingPFCandidates_) {
288  egmPFCandidateCollection_ = consumes(cfg.getParameter<edm::InputTag>("egmPFCandidatesTag"));
289  }
290 
291  inputCfg_.gsfElectronCores = consumes(cfg.getParameter<edm::InputTag>("gsfElectronCoresTag"));
292  inputCfg_.hcalTowersTag = consumes(cfg.getParameter<edm::InputTag>("hcalTowers"));
293  inputCfg_.barrelRecHitCollection = consumes(cfg.getParameter<edm::InputTag>("barrelRecHitCollectionTag"));
294  inputCfg_.endcapRecHitCollection = consumes(cfg.getParameter<edm::InputTag>("endcapRecHitCollectionTag"));
295  inputCfg_.ctfTracks = consumes(cfg.getParameter<edm::InputTag>("ctfTracksTag"));
296  // used to check config consistency with seeding
297  inputCfg_.seedsTag = consumes(cfg.getParameter<edm::InputTag>("seedsTag"));
298  inputCfg_.beamSpotTag = consumes(cfg.getParameter<edm::InputTag>("beamSpotTag"));
299  inputCfg_.vtxCollectionTag = consumes(cfg.getParameter<edm::InputTag>("vtxTag"));
300  if (cfg.getParameter<bool>("fillConvVtxFitProb"))
301  inputCfg_.conversions = consumes(cfg.getParameter<edm::InputTag>("conversionsTag"));
302 
303  strategyCfg_.useDefaultEnergyCorrection = cfg.getParameter<bool>("useDefaultEnergyCorrection");
304 
305  strategyCfg_.applyPreselection = cfg.getParameter<bool>("applyPreselection");
306  strategyCfg_.ecalDrivenEcalEnergyFromClassBasedParameterization =
307  cfg.getParameter<bool>("ecalDrivenEcalEnergyFromClassBasedParameterization");
308  strategyCfg_.ecalDrivenEcalErrorFromClassBasedParameterization =
309  cfg.getParameter<bool>("ecalDrivenEcalErrorFromClassBasedParameterization");
310  strategyCfg_.pureTrackerDrivenEcalErrorFromSimpleParameterization =
311  cfg.getParameter<bool>("pureTrackerDrivenEcalErrorFromSimpleParameterization");
312  strategyCfg_.applyAmbResolution = cfg.getParameter<bool>("applyAmbResolution");
313  strategyCfg_.ignoreNotPreselected = cfg.getParameter<bool>("ignoreNotPreselected");
314  strategyCfg_.ambSortingStrategy = cfg.getParameter<unsigned>("ambSortingStrategy");
315  strategyCfg_.ambClustersOverlapStrategy = cfg.getParameter<unsigned>("ambClustersOverlapStrategy");
316  strategyCfg_.ctfTracksCheck = cfg.getParameter<bool>("ctfTracksCheck");
317  strategyCfg_.PreSelectMVA = cfg.getParameter<double>("PreSelectMVA");
318  strategyCfg_.MaxElePtForOnlyMVA = cfg.getParameter<double>("MaxElePtForOnlyMVA");
319  strategyCfg_.useEcalRegression = cfg.getParameter<bool>("useEcalRegression");
320  strategyCfg_.useCombinationRegression = cfg.getParameter<bool>("useCombinationRegression");
321  strategyCfg_.fillConvVtxFitProb = cfg.getParameter<bool>("fillConvVtxFitProb");
322 
323  // hcal helpers
324  auto const& psetPreselection = cfg.getParameter<edm::ParameterSet>("preselection");
325  hcalCfg_.hOverEConeSize = psetPreselection.getParameter<double>("hOverEConeSize");
326  if (hcalCfg_.hOverEConeSize > 0) {
327  hcalCfg_.useTowers = true;
328  hcalCfg_.checkHcalStatus = cfg.getParameter<bool>("checkHcalStatus");
329  hcalCfg_.hcalTowers = consumes(cfg.getParameter<edm::InputTag>("hcalTowers"));
330  hcalCfg_.hOverEPtMin = psetPreselection.getParameter<double>("hOverEPtMin");
331  }
332 
333  // Ecal rec hits configuration
335  auto const& flagnamesbarrel = cfg.getParameter<std::vector<std::string>>("recHitFlagsToBeExcludedBarrel");
336  recHitsCfg.recHitFlagsToBeExcludedBarrel = StringToEnumValue<EcalRecHit::Flags>(flagnamesbarrel);
337  auto const& flagnamesendcaps = cfg.getParameter<std::vector<std::string>>("recHitFlagsToBeExcludedEndcaps");
338  recHitsCfg.recHitFlagsToBeExcludedEndcaps = StringToEnumValue<EcalRecHit::Flags>(flagnamesendcaps);
339  auto const& severitynamesbarrel = cfg.getParameter<std::vector<std::string>>("recHitSeverityToBeExcludedBarrel");
341  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesbarrel);
342  auto const& severitynamesendcaps = cfg.getParameter<std::vector<std::string>>("recHitSeverityToBeExcludedEndcaps");
344  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesendcaps);
345 
346  // isolation
348  .intRadiusHcal = cfg.getParameter<double>("intRadiusHcal"),
349  .etMinHcal = cfg.getParameter<double>("etMinHcal"),
350  .intRadiusEcalBarrel = cfg.getParameter<double>("intRadiusEcalBarrel"),
351  .intRadiusEcalEndcaps = cfg.getParameter<double>("intRadiusEcalEndcaps"),
352  .jurassicWidth = cfg.getParameter<double>("jurassicWidth"),
353  .etMinBarrel = cfg.getParameter<double>("etMinBarrel"),
354  .eMinBarrel = cfg.getParameter<double>("eMinBarrel"),
355  .etMinEndcaps = cfg.getParameter<double>("etMinEndcaps"),
356  .eMinEndcaps = cfg.getParameter<double>("eMinEndcaps"),
357  .vetoClustered = cfg.getParameter<bool>("vetoClustered"),
358  .useNumCrystals = cfg.getParameter<bool>("useNumCrystals")};
359 
360  const RegressionHelper::Configuration regressionCfg{
361  .ecalRegressionWeightLabels = cfg.getParameter<std::vector<std::string>>("ecalRefinedRegressionWeightLabels"),
362  .ecalWeightsFromDB = cfg.getParameter<bool>("ecalWeightsFromDB"),
363  .ecalRegressionWeightFiles = cfg.getParameter<std::vector<std::string>>("ecalRefinedRegressionWeightFiles"),
365  cfg.getParameter<std::vector<std::string>>("combinationRegressionWeightLabels"),
366  .combinationWeightsFromDB = cfg.getParameter<bool>("combinationWeightsFromDB"),
367  .combinationRegressionWeightFiles =
368  cfg.getParameter<std::vector<std::string>>("combinationRegressionWeightFile")};
369 
370  // create algo
371  algo_ = std::make_unique<GsfElectronAlgo>(
372  inputCfg_,
373  strategyCfg_,
374  cutsCfg_,
375  hcalCfg_,
376  isoCfg,
377  recHitsCfg,
378  EcalClusterFunctionFactory::get()->create(cfg.getParameter<std::string>("superClusterErrorFunction"), cfg),
379  EcalClusterFunctionFactory::get()->create(cfg.getParameter<std::string>("crackCorrectionFunction"), cfg),
380  regressionCfg,
381  cfg.getParameter<edm::ParameterSet>("trkIsol03Cfg"),
382  cfg.getParameter<edm::ParameterSet>("trkIsol04Cfg"),
383  cfg.getParameter<edm::ParameterSet>("trkIsolHEEP03Cfg"),
384  cfg.getParameter<edm::ParameterSet>("trkIsolHEEP04Cfg"),
385  consumesCollector());
386 }
387 
389  if (!pset.exists("SeedConfiguration")) {
390  return;
391  }
392  edm::ParameterSet seedConfiguration = pset.getParameter<edm::ParameterSet>("SeedConfiguration");
393 
394  if (seedConfiguration.getParameter<bool>("applyHOverECut")) {
395  if ((hcalCfg_.hOverEConeSize != 0) &&
396  (hcalCfg_.hOverEConeSize != seedConfiguration.getParameter<double>("hOverEConeSize"))) {
397  edm::LogWarning("GsfElectronAlgo|InconsistentParameters")
398  << "The H/E cone size (" << hcalCfg_.hOverEConeSize << ") is different from ecal seeding ("
399  << seedConfiguration.getParameter<double>("hOverEConeSize") << ").";
400  }
401  if (cutsCfg_.maxHOverEBarrelCone < seedConfiguration.getParameter<double>("maxHOverEBarrel")) {
402  edm::LogWarning("GsfElectronAlgo|InconsistentParameters")
403  << "The max barrel cone H/E is lower than during ecal seeding.";
404  }
405  if (cutsCfg_.maxHOverEEndcapsCone < seedConfiguration.getParameter<double>("maxHOverEEndcaps")) {
406  edm::LogWarning("GsfElectronAlgo|InconsistentParameters")
407  << "The max endcaps cone H/E is lower than during ecal seeding.";
408  }
409  }
410 
411  if (cutsCfg_.minSCEtBarrel < seedConfiguration.getParameter<double>("SCEtCut")) {
412  edm::LogWarning("GsfElectronAlgo|InconsistentParameters")
413  << "The minimum super-cluster Et in barrel is lower than during ecal seeding.";
414  }
415  if (cutsCfg_.minSCEtEndcaps < seedConfiguration.getParameter<double>("SCEtCut")) {
416  edm::LogWarning("GsfElectronAlgo|InconsistentParameters")
417  << "The minimum super-cluster Et in endcaps is lower than during ecal seeding.";
418  }
419 }
420 
421 //=======================================================================================
422 // Ambiguity solving
423 //=======================================================================================
424 
426  edm::Event const& event,
427  bool ignoreNotPreselected) const {
428  // Getting required event data
429  auto const& beamspot = event.get(inputCfg_.beamSpotTag);
430  auto gsfPfRecTracks =
432  auto const& barrelRecHits = event.get(inputCfg_.barrelRecHitCollection);
433  auto const& endcapRecHits = event.get(inputCfg_.endcapRecHitCollection);
434 
435  if (strategyCfg_.ambSortingStrategy == 0) {
436  std::sort(electrons.begin(), electrons.end(), egamma::isBetterElectron);
437  } else if (strategyCfg_.ambSortingStrategy == 1) {
438  std::sort(electrons.begin(), electrons.end(), egamma::isInnermostElectron);
439  } else {
440  throw cms::Exception("GsfElectronAlgo|UnknownAmbiguitySortingStrategy")
441  << "value of strategyCfg_.ambSortingStrategy is : " << strategyCfg_.ambSortingStrategy;
442  }
443 
444  // init
445  for (auto& electron : electrons) {
446  electron.clearAmbiguousGsfTracks();
447  electron.setAmbiguous(false);
448  }
449 
450  // get ambiguous from GsfPfRecTracks
451  if (useGsfPfRecTracks_) {
452  for (auto& e1 : electrons) {
453  bool found = false;
454  for (auto const& gsfPfRecTrack : *gsfPfRecTracks) {
455  if (gsfPfRecTrack.gsfTrackRef() == e1.gsfTrack()) {
456  if (found) {
457  edm::LogWarning("GsfElectronAlgo") << "associated gsfPfRecTrack already found";
458  } else {
459  found = true;
460  for (auto const& duplicate : gsfPfRecTrack.convBremGsfPFRecTrackRef()) {
461  e1.addAmbiguousGsfTrack(duplicate->gsfTrackRef());
462  }
463  }
464  }
465  }
466  }
467  }
468  // or search overlapping clusters
469  else {
470  for (auto e1 = electrons.begin(); e1 != electrons.end(); ++e1) {
471  if (e1->ambiguous())
472  continue;
474  continue;
475 
476  SuperClusterRef scRef1 = e1->superCluster();
477  CaloClusterPtr eleClu1 = e1->electronCluster();
478  LogDebug("GsfElectronAlgo") << "Blessing electron with E/P " << e1->eSuperClusterOverP() << ", cluster "
479  << scRef1.get() << " & track " << e1->gsfTrack().get();
480 
481  for (auto e2 = e1 + 1; e2 != electrons.end(); ++e2) {
482  if (e2->ambiguous())
483  continue;
484  if (ignoreNotPreselected && !isPreselected(*e2))
485  continue;
486 
487  SuperClusterRef scRef2 = e2->superCluster();
488  CaloClusterPtr eleClu2 = e2->electronCluster();
489 
490  // search if same cluster
491  bool sameCluster = false;
493  sameCluster = (scRef1 == scRef2);
494  } else if (strategyCfg_.ambClustersOverlapStrategy == 1) {
495  float eMin = 1.;
496  float threshold = eMin * cosh(EleRelPoint(scRef1->position(), beamspot.position()).eta());
497  using egamma::sharedEnergy;
498  sameCluster = ((sharedEnergy(*eleClu1, *eleClu2, barrelRecHits, endcapRecHits) >= threshold) ||
499  (sharedEnergy(*scRef1->seed(), *eleClu2, barrelRecHits, endcapRecHits) >= threshold) ||
500  (sharedEnergy(*eleClu1, *scRef2->seed(), barrelRecHits, endcapRecHits) >= threshold) ||
501  (sharedEnergy(*scRef1->seed(), *scRef2->seed(), barrelRecHits, endcapRecHits) >= threshold));
502  } else {
503  throw cms::Exception("GsfElectronAlgo|UnknownAmbiguityClustersOverlapStrategy")
504  << "value of strategyCfg_.ambClustersOverlapStrategy is : " << strategyCfg_.ambClustersOverlapStrategy;
505  }
506 
507  // main instructions
508  if (sameCluster) {
509  LogDebug("GsfElectronAlgo") << "Discarding electron with E/P " << e2->eSuperClusterOverP() << ", cluster "
510  << scRef2.get() << " and track " << e2->gsfTrack().get();
511  e1->addAmbiguousGsfTrack(e2->gsfTrack());
512  e2->setAmbiguous(true);
513  } else if (e1->gsfTrack() == e2->gsfTrack()) {
514  edm::LogWarning("GsfElectronAlgo") << "Forgetting electron with E/P " << e2->eSuperClusterOverP()
515  << ", cluster " << scRef2.get() << " and track " << e2->gsfTrack().get();
516  e2->setAmbiguous(true);
517  }
518  }
519  }
520  }
521 }
522 
524  bool passCutBased = ele.passingCutBasedPreselection();
525  bool passPF = ele.passingPflowPreselection();
526  // it is worth nothing for gedGsfElectrons, this does nothing as its not set
527  // till GedGsfElectron finaliser, this is always false
528  bool passmva = ele.passingMvaPreselection();
529  if (!ele.ecalDrivenSeed()) {
530  if (ele.pt() > strategyCfg_.MaxElePtForOnlyMVA)
531  return passmva && passCutBased;
532  else
533  return passmva;
534  } else {
535  return passCutBased || passPF || passmva;
536  }
537 }
538 
539 // ------------ method called to produce the data ------------
541  // check configuration
544  auto seeds = event.getHandle(inputCfg_.seedsTag);
545  if (!seeds.isValid()) {
546  edm::LogWarning("GsfElectronAlgo|UnreachableSeedsProvenance")
547  << "Cannot check consistency of parameters with ecal seeding ones,"
548  << " because the original collection of seeds is not any more available.";
549  } else {
550  checkEcalSeedingParameters(edm::parameterSet(*seeds.provenance(), event.processHistory()));
551  }
552  }
553 
554  auto electrons = algo_->completeElectrons(event, setup, globalCache());
556  const auto gsfMVAInputMap = matchWithPFCandidates(event.get(egmPFCandidateCollection_));
557  setMVAOutputs(electrons, globalCache(), event.get(inputCfg_.vtxCollectionTag));
558  for (auto& el : electrons)
559  el.setMvaInput(gsfMVAInputMap.find(el.gsfTrack())->second); // set MVA inputs
560  }
561 
562  // all electrons
563  logElectrons(electrons, event, "GsfElectronAlgo Info (before preselection)");
564  // preselection
566  electrons.erase(
567  std::remove_if(electrons.begin(), electrons.end(), [this](auto const& ele) { return !isPreselected(ele); }),
568  electrons.end());
569  logElectrons(electrons, event, "GsfElectronAlgo Info (after preselection)");
570  }
571  // ambiguity
574  electrons.erase(std::remove_if(electrons.begin(), electrons.end(), std::mem_fn(&reco::GsfElectron::ambiguous)),
575  electrons.end());
576  logElectrons(electrons, event, "GsfElectronAlgo Info (after amb. solving)");
577  }
578  // final filling
579  event.emplace(electronPutToken_, std::move(electrons));
580 }
581 
ConfigurationDescriptions.h
GsfElectronAlgo::EcalRecHitsConfiguration::recHitFlagsToBeExcludedEndcaps
std::vector< int > recHitFlagsToBeExcludedEndcaps
Definition: GsfElectronAlgo.h:152
Handle.h
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
GsfElectronAlgo::CutsConfiguration::maxHOverEBarrelCone
double maxHOverEBarrelCone
Definition: GsfElectronAlgo.h:111
GsfElectronAlgo::StrategyConfiguration::applyAmbResolution
bool applyAmbResolution
Definition: GsfElectronAlgo.h:82
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
input
static const std::string input
Definition: EdmProvDump.cc:48
RegressionHelper::Configuration::ecalRegressionWeightLabels
std::vector< std::string > ecalRegressionWeightLabels
Definition: RegressionHelper.h:29
MessageLogger.h
TrackCandidateCollection.h
GsfElectronProducer::initializeGlobalCache
static std::unique_ptr< GsfElectronAlgo::HeavyObjectCache > initializeGlobalCache(const edm::ParameterSet &conf)
Definition: GsfElectronProducer.cc:82
reco::GsfElectron::passingMvaPreselection
bool passingMvaPreselection() const
Definition: GsfElectron.h:703
GsfElectronAlgo::StrategyConfiguration
Definition: GsfElectronAlgo.h:73
PFCandidate.h
HLT_FULL_cff.endcapRecHits
endcapRecHits
Definition: HLT_FULL_cff.py:14918
edm::EDGetTokenT< reco::GsfPFRecTrackCollection >
reco::GsfElectron::MvaOutput::mva_e_pi
float mva_e_pi
Definition: GsfElectron.h:652
edm::EDPutTokenT< reco::GsfElectronCollection >
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HLT_FULL_cff.barrelRecHits
barrelRecHits
Definition: HLT_FULL_cff.py:14921
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
GsfElectronAlgo::StrategyConfiguration::ignoreNotPreselected
bool ignoreNotPreselected
Definition: GsfElectronAlgo.h:83
GsfElectronProducer::inputCfg_
GsfElectronAlgo::Tokens inputCfg_
Definition: GsfElectronProducer.cc:95
EDProducer.h
GsfElectronAlgo::HeavyObjectCache::iElectronMVAEstimator
std::unique_ptr< const ElectronMVAEstimator > iElectronMVAEstimator
Definition: GsfElectronAlgo.h:56
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
GsfElectronAlgo::StrategyConfiguration::ambClustersOverlapStrategy
unsigned ambClustersOverlapStrategy
Definition: GsfElectronAlgo.h:85
GsfElectronProducer::cutsCfg_
const GsfElectronAlgo::CutsConfiguration cutsCfg_
Definition: GsfElectronProducer.cc:97
reco::GsfElectronCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
Definition: GsfElectronFwd.h:14
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
GsfElectronProducer::produce
void produce(edm::Event &event, const edm::EventSetup &setup) override
Definition: GsfElectronProducer.cc:540
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ElectronUtilities.h
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
GsfElectronAlgo::EcalRecHitsConfiguration::recHitFlagsToBeExcludedBarrel
std::vector< int > recHitFlagsToBeExcludedBarrel
Definition: GsfElectronAlgo.h:151
GsfElectronAlgo::Tokens::seedsTag
edm::EDGetTokenT< reco::ElectronSeedCollection > seedsTag
Definition: GsfElectronAlgo.h:66
gedGsfElectrons_cfi.minSCEtEndcaps
minSCEtEndcaps
Definition: gedGsfElectrons_cfi.py:27
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
GsfElectronAlgo::CutsConfiguration::minSCEtEndcaps
double minSCEtEndcaps
Definition: GsfElectronAlgo.h:102
GsfElectronAlgo::Tokens::beamSpotTag
edm::EDGetTokenT< reco::BeamSpot > beamSpotTag
Definition: GsfElectronAlgo.h:68
GsfElectronAlgo::Tokens::barrelRecHitCollection
edm::EDGetTokenT< EcalRecHitCollection > barrelRecHitCollection
Definition: GsfElectronAlgo.h:64
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
GsfElectronProducer::isPreselected
bool isPreselected(reco::GsfElectron const &ele) const
Definition: GsfElectronProducer.cc:523
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
GsfElectronAlgo::CutsConfiguration::maxHOverEEndcapsCone
double maxHOverEEndcapsCone
Definition: GsfElectronAlgo.h:112
edm::Ref
Definition: AssociativeIterator.h:58
GsfElectronProducer::resetMvaValuesUsingPFCandidates_
const bool resetMvaValuesUsingPFCandidates_
Definition: GsfElectronProducer.cc:115
GsfElectronAlgo::StrategyConfiguration::ambSortingStrategy
unsigned ambSortingStrategy
Definition: GsfElectronAlgo.h:84
EcalSeverityLevel.h
gsfElectrons_cfi.ignoreNotPreselected
ignoreNotPreselected
Definition: gsfElectrons_cfi.py:37
uncleanedOnlyElectronSequence_cff.gsfPfRecTracks
gsfPfRecTracks
Definition: uncleanedOnlyElectronSequence_cff.py:141
MakerMacros.h
reco::GsfElectron::passingPflowPreselection
bool passingPflowPreselection() const
Definition: GsfElectron.h:688
GsfElectronAlgo::EcalRecHitsConfiguration::recHitSeverityToBeExcludedBarrel
std::vector< int > recHitSeverityToBeExcludedBarrel
Definition: GsfElectronAlgo.h:153
EleRelPoint
Definition: ElectronUtilities.h:25
GsfElectronAlgo::HeavyObjectCache
Definition: GsfElectronAlgo.h:52
EgAmbiguityTools.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
PVValHelper::eta
Definition: PVValidationHelpers.h:69
photonAnalyzer_cfi.eMin
eMin
Definition: photonAnalyzer_cfi.py:50
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
reco::GsfElectron::MvaOutput::mva_Isolated
float mva_Isolated
Definition: GsfElectron.h:651
reco::GsfElectron::ecalDrivenSeed
bool ecalDrivenSeed() const
Definition: GsfElectron.h:166
metsig::electron
Definition: SignAlgoResolutions.h:48
GsfElectronAlgo::CutsConfiguration::minSCEtBarrel
double minSCEtBarrel
Definition: GsfElectronAlgo.h:101
GsfElectronProducer::globalEndJob
static void globalEndJob(GsfElectronAlgo::HeavyObjectCache const *)
Definition: GsfElectronProducer.cc:86
beamspot
Definition: BeamSpotWrite2Txt.h:8
ElectronHcalHelper::Configuration::hOverEConeSize
double hOverEConeSize
Definition: ElectronHcalHelper.h:27
StringToEnumValue.h
reco::GsfElectron
Definition: GsfElectron.h:35
EcalClusterFunctionFactory.h
ParameterSetDescription.h
GsfElectron.h
GsfElectronProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: GsfElectronProducer.cc:118
ElectronHcalHelper::Configuration
Definition: ElectronHcalHelper.h:25
reco::GsfElectron::MvaInput
Definition: GsfElectron.h:631
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GsfElectronAlgo::Tokens::endcapRecHitCollection
edm::EDGetTokenT< EcalRecHitCollection > endcapRecHitCollection
Definition: GsfElectronAlgo.h:65
GsfElectronProducer
Definition: GsfElectronProducer.cc:76
GsfElectronAlgo::StrategyConfiguration::MaxElePtForOnlyMVA
float MaxElePtForOnlyMVA
Definition: GsfElectronAlgo.h:89
GsfElectronAlgo::Tokens
Definition: GsfElectronAlgo.h:59
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:230
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
EleTkIsolFromCands.h
Event.h
GsfElectronProducer::algo_
std::unique_ptr< GsfElectronAlgo > algo_
Definition: GsfElectronProducer.cc:92
GsfElectronProducer::useGsfPfRecTracks_
const bool useGsfPfRecTracks_
Definition: GsfElectronProducer.cc:113
StorageManager_cfg.e1
e1
Definition: StorageManager_cfg.py:16
GsfElectronProducer::egmPFCandidateCollection_
edm::EDGetTokenT< reco::PFCandidateCollection > egmPFCandidateCollection_
Definition: GsfElectronProducer.cc:111
Reconstruction_hiPF_cff.maxEOverPEndcaps
maxEOverPEndcaps
Definition: Reconstruction_hiPF_cff.py:31
GsfTrack.h
GsfElectronAlgo::CutsConfiguration
Definition: GsfElectronAlgo.h:99
reco::GsfElectron::passingCutBasedPreselection
bool passingCutBasedPreselection() const
Definition: GsfElectron.h:687
edm::stream::EDProducer
Definition: EDProducer.h:38
EleTkIsolFromCands::pSetDescript
static edm::ParameterSetDescription pSetDescript()
Definition: EleTkIsolFromCands.cc:43
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
electronEcalRecHitIsolationLcone_cfi.etMinBarrel
etMinBarrel
Definition: electronEcalRecHitIsolationLcone_cfi.py:19
GsfElectronProducer::GsfElectronProducer
GsfElectronProducer(const edm::ParameterSet &, const GsfElectronAlgo::HeavyObjectCache *)
Definition: GsfElectronProducer.cc:280
egamma::sharedEnergy
float sharedEnergy(reco::CaloCluster const &clu1, reco::CaloCluster const &clu2, EcalRecHitCollection const &barrelRecHits, EcalRecHitCollection const &endcapRecHits)
Definition: EgAmbiguityTools.cc:140
edm::Ptr< CaloCluster >
looper.cfg
cfg
Definition: looper.py:297
GsfElectronProducer::checkEcalSeedingParameters
void checkEcalSeedingParameters(edm::ParameterSet const &)
Definition: GsfElectronProducer.cc:388
GsfElectronAlgo::HeavyObjectCache::sElectronMVAEstimator
std::unique_ptr< const SoftElectronMVAEstimator > sElectronMVAEstimator
Definition: GsfElectronAlgo.h:55
Reconstruction_hiPF_cff.maxHOverEEndcapsCone
maxHOverEEndcapsCone
Definition: Reconstruction_hiPF_cff.py:27
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
GsfElectronAlgo::StrategyConfiguration::applyPreselection
bool applyPreselection
Definition: GsfElectronAlgo.h:75
eostools.move
def move(src, dest)
Definition: eostools.py:511
GsfElectronProducer::electronPutToken_
const edm::EDPutTokenT< reco::GsfElectronCollection > electronPutToken_
Definition: GsfElectronProducer.cc:109
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
PFCandidateEGammaExtra.h
Exception
Definition: hltDiff.cc:246
Reconstruction_hiPF_cff.maxHOverEEndcapsTower
maxHOverEEndcapsTower
Definition: Reconstruction_hiPF_cff.py:29
reco::GsfElectron::MvaOutput
Definition: GsfElectron.h:649
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
GsfElectronProducer::ecalSeedingParametersChecked_
bool ecalSeedingParametersChecked_
Definition: GsfElectronProducer.cc:106
GsfElectronAlgo::Tokens::vtxCollectionTag
edm::EDGetTokenT< reco::VertexCollection > vtxCollectionTag
Definition: GsfElectronAlgo.h:69
Provenance.h
GsfElectronProducer::hcalCfg_
ElectronHcalHelper::Configuration hcalCfg_
Definition: GsfElectronProducer.cc:98
EventSetup.h
reco::PFCandidateEGammaExtra::MVA_DeltaEtaTrackCluster
Definition: PFCandidateEGammaExtra.h:48
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
egamma::isBetterElectron
bool isBetterElectron(reco::GsfElectron const &, reco::GsfElectron const &)
Definition: EgAmbiguityTools.cc:16
egamma::isInnermostElectron
bool isInnermostElectron(reco::GsfElectron const &, reco::GsfElectron const &)
Definition: EgAmbiguityTools.cc:20
GsfElectronProducer::strategyCfg_
GsfElectronAlgo::StrategyConfiguration strategyCfg_
Definition: GsfElectronProducer.cc:96
reco::PFCandidateEGammaExtra::MVA_LateBrem
Definition: PFCandidateEGammaExtra.h:51
GsfElectronAlgo::IsolationConfiguration::intRadiusHcal
double intRadiusHcal
Definition: GsfElectronAlgo.h:160
reco::PFCandidateEGammaExtra::MVA_FirstBrem
Definition: PFCandidateEGammaExtra.h:52
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
ParameterSet.h
GsfPFRecTrack.h
event
Definition: event.py:1
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
edm::Event
Definition: Event.h:73
GsfElectronAlgo::IsolationConfiguration
Definition: GsfElectronAlgo.h:159
gedGsfElectrons_cfi.combinationRegressionWeightLabels
combinationRegressionWeightLabels
Definition: gedGsfElectrons_cfi.py:21
reco::GsfElectron::ambiguous
bool ambiguous() const
Definition: GsfElectron.h:689
GsfElectronProducer::setAmbiguityData
void setAmbiguityData(reco::GsfElectronCollection &electrons, edm::Event const &event, bool ignoreNotPreselected=true) const
Definition: GsfElectronProducer.cc:425
edm::InputTag
Definition: InputTag.h:15
GsfElectronProducer::gsfPfRecTracksTag_
const edm::EDGetTokenT< reco::GsfPFRecTrackCollection > gsfPfRecTracksTag_
Definition: GsfElectronProducer.cc:110
RegressionHelper::Configuration
Definition: RegressionHelper.h:27
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
ElectronSeed.h
GsfElectronAlgo::EcalRecHitsConfiguration
Definition: GsfElectronAlgo.h:150
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
GsfElectronAlgo.h
GsfElectronAlgo::EcalRecHitsConfiguration::recHitSeverityToBeExcludedEndcaps
std::vector< int > recHitSeverityToBeExcludedEndcaps
Definition: GsfElectronAlgo.h:154
electronEcalRecHitIsolationLcone_cfi.vetoClustered
vetoClustered
Definition: electronEcalRecHitIsolationLcone_cfi.py:27