CMS 3D CMS Logo

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