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>("useCombinationRegression", false);
135  desc.add<bool>("ecalDrivenEcalEnergyFromClassBasedParameterization", true);
136  desc.add<bool>("ecalDrivenEcalErrorFromClassBasedParameterization", true);
137  desc.add<bool>("applyPreselection", false);
138  desc.add<bool>("useEcalRegression", false);
139  desc.add<bool>("applyAmbResolution", false);
140  desc.add<bool>("useGsfPfRecTracks", true);
141  desc.add<bool>("pureTrackerDrivenEcalErrorFromSimpleParameterization", true);
142  desc.add<unsigned int>("ambSortingStrategy", 1);
143  desc.add<unsigned int>("ambClustersOverlapStrategy", 1);
144  desc.add<bool>("fillConvVtxFitProb", true);
145  desc.add<bool>("resetMvaValuesUsingPFCandidates", false);
146 
147  // Ecal rec hits configuration
148  desc.add<std::vector<std::string>>("recHitFlagsToBeExcludedBarrel");
149  desc.add<std::vector<std::string>>("recHitFlagsToBeExcludedEndcaps");
150  desc.add<std::vector<std::string>>("recHitSeverityToBeExcludedBarrel");
151  desc.add<std::vector<std::string>>("recHitSeverityToBeExcludedEndcaps");
152 
153  // Isolation algos configuration
154  desc.add("trkIsol03Cfg", EleTkIsolFromCands::pSetDescript());
155  desc.add("trkIsol04Cfg", EleTkIsolFromCands::pSetDescript());
156  desc.add("trkIsolHEEP03Cfg", EleTkIsolFromCands::pSetDescript());
157  desc.add("trkIsolHEEP04Cfg", EleTkIsolFromCands::pSetDescript());
158  desc.add<bool>("useNumCrystals", true);
159  desc.add<double>("etMinBarrel", 0.0);
160  desc.add<double>("etMinEndcaps", 0.11);
161  desc.add<double>("etMinHcal", 0.0);
162  desc.add<double>("eMinBarrel", 0.095);
163  desc.add<double>("eMinEndcaps", 0.0);
164  desc.add<double>("intRadiusEcalBarrel", 3.0);
165  desc.add<double>("intRadiusEcalEndcaps", 3.0);
166  desc.add<double>("intRadiusHcal", 0.15);
167  desc.add<double>("jurassicWidth", 1.5);
168  desc.add<bool>("vetoClustered", false);
169 
170  // backward compatibility mechanism for ctf tracks
171  desc.add<bool>("ctfTracksCheck", true);
172  desc.add<edm::InputTag>("ctfTracksTag", {"generalTracks"});
173 
174  desc.add<double>("MaxElePtForOnlyMVA", 50.0);
175  desc.add<double>("PreSelectMVA", -0.1);
176 
177  {
179  psd0.add<double>("minSCEtBarrel", 4.0);
180  psd0.add<double>("minSCEtEndcaps", 4.0);
181  psd0.add<double>("minEOverPBarrel", 0.0);
182  psd0.add<double>("minEOverPEndcaps", 0.0);
183  psd0.add<double>("maxEOverPBarrel", 999999999.0);
184  psd0.add<double>("maxEOverPEndcaps", 999999999.0);
185  psd0.add<double>("maxDeltaEtaBarrel", 0.02);
186  psd0.add<double>("maxDeltaEtaEndcaps", 0.02);
187  psd0.add<double>("maxDeltaPhiBarrel", 0.15);
188  psd0.add<double>("maxDeltaPhiEndcaps", 0.15);
189  psd0.add<double>("hOverEConeSize", 0.15);
190  psd0.add<double>("hOverEPtMin", 0.0);
191  psd0.add<double>("maxHOverEBarrelCone", 0.15);
192  psd0.add<double>("maxHOverEEndcapsCone", 0.15);
193  psd0.add<double>("maxHBarrelCone", 0.0);
194  psd0.add<double>("maxHEndcapsCone", 0.0);
195  psd0.add<double>("maxHOverEBarrelTower", 0.15);
196  psd0.add<double>("maxHOverEEndcapsTower", 0.15);
197  psd0.add<double>("maxHBarrelTower", 0.0);
198  psd0.add<double>("maxHEndcapsTower", 0.0);
199  psd0.add<double>("maxSigmaIetaIetaBarrel", 999999999.0);
200  psd0.add<double>("maxSigmaIetaIetaEndcaps", 999999999.0);
201  psd0.add<double>("maxFbremBarrel", 999999999.0);
202  psd0.add<double>("maxFbremEndcaps", 999999999.0);
203  psd0.add<bool>("isBarrel", false);
204  psd0.add<bool>("isEndcaps", false);
205  psd0.add<bool>("isFiducial", false);
206  psd0.add<bool>("seedFromTEC", true);
207  psd0.add<double>("maxTIP", 999999999.0);
208  psd0.add<double>("minMVA", -0.4);
209  psd0.add<double>("minMvaByPassForIsolated", -0.4);
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  .minMVA = pset.getParameter<double>("minMVA"),
275  .minMvaByPassForIsolated = pset.getParameter<double>("minMvaByPassForIsolated"),
276  .maxTIP = pset.getParameter<double>("maxTIP"),
277  .seedFromTEC = pset.getParameter<bool>("seedFromTEC"),
278  };
279  }
280 }; // namespace
281 
283  : cutsCfg_{makeCutsConfiguration(cfg.getParameter<edm::ParameterSet>("preselection"))},
284  ecalSeedingParametersChecked_(false),
285  electronPutToken_(produces<GsfElectronCollection>()),
286  gsfPfRecTracksTag_(consumes<reco::GsfPFRecTrackCollection>(cfg.getParameter<edm::InputTag>("gsfPfRecTracksTag"))),
287  useGsfPfRecTracks_(cfg.getParameter<bool>("useGsfPfRecTracks")),
288  resetMvaValuesUsingPFCandidates_(cfg.getParameter<bool>("resetMvaValuesUsingPFCandidates")) {
289  if (resetMvaValuesUsingPFCandidates_) {
290  egmPFCandidateCollection_ =
291  consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("egmPFCandidatesTag"));
292  }
293 
294  inputCfg_.gsfElectronCores =
295  consumes<reco::GsfElectronCoreCollection>(cfg.getParameter<edm::InputTag>("gsfElectronCoresTag"));
296  inputCfg_.hcalTowersTag = consumes<CaloTowerCollection>(cfg.getParameter<edm::InputTag>("hcalTowers"));
297  inputCfg_.barrelRecHitCollection =
298  consumes<EcalRecHitCollection>(cfg.getParameter<edm::InputTag>("barrelRecHitCollectionTag"));
299  inputCfg_.endcapRecHitCollection =
300  consumes<EcalRecHitCollection>(cfg.getParameter<edm::InputTag>("endcapRecHitCollectionTag"));
301  inputCfg_.ctfTracks = consumes<reco::TrackCollection>(cfg.getParameter<edm::InputTag>("ctfTracksTag"));
302  // used to check config consistency with seeding
303  inputCfg_.seedsTag = consumes<reco::ElectronSeedCollection>(cfg.getParameter<edm::InputTag>("seedsTag"));
304  inputCfg_.beamSpotTag = consumes<reco::BeamSpot>(cfg.getParameter<edm::InputTag>("beamSpotTag"));
305  inputCfg_.vtxCollectionTag = consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vtxTag"));
306  if (cfg.getParameter<bool>("fillConvVtxFitProb"))
307  inputCfg_.conversions = consumes<reco::ConversionCollection>(cfg.getParameter<edm::InputTag>("conversionsTag"));
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_.ambSortingStrategy = cfg.getParameter<unsigned>("ambSortingStrategy");
318  strategyCfg_.ambClustersOverlapStrategy = cfg.getParameter<unsigned>("ambClustersOverlapStrategy");
319  strategyCfg_.ctfTracksCheck = cfg.getParameter<bool>("ctfTracksCheck");
320  strategyCfg_.PreSelectMVA = cfg.getParameter<double>("PreSelectMVA");
321  strategyCfg_.MaxElePtForOnlyMVA = cfg.getParameter<double>("MaxElePtForOnlyMVA");
322  strategyCfg_.useEcalRegression = cfg.getParameter<bool>("useEcalRegression");
323  strategyCfg_.useCombinationRegression = cfg.getParameter<bool>("useCombinationRegression");
324  strategyCfg_.fillConvVtxFitProb = cfg.getParameter<bool>("fillConvVtxFitProb");
325 
326  // hcal helpers
327  auto const& psetPreselection = cfg.getParameter<edm::ParameterSet>("preselection");
328  hcalCfg_.hOverEConeSize = psetPreselection.getParameter<double>("hOverEConeSize");
329  if (hcalCfg_.hOverEConeSize > 0) {
330  hcalCfg_.useTowers = true;
331  hcalCfg_.checkHcalStatus = cfg.getParameter<bool>("checkHcalStatus");
332  hcalCfg_.hcalTowers = consumes<CaloTowerCollection>(cfg.getParameter<edm::InputTag>("hcalTowers"));
333  hcalCfg_.hOverEPtMin = psetPreselection.getParameter<double>("hOverEPtMin");
334  }
335 
336  // Ecal rec hits configuration
338  auto const& flagnamesbarrel = cfg.getParameter<std::vector<std::string>>("recHitFlagsToBeExcludedBarrel");
339  recHitsCfg.recHitFlagsToBeExcludedBarrel = StringToEnumValue<EcalRecHit::Flags>(flagnamesbarrel);
340  auto const& flagnamesendcaps = cfg.getParameter<std::vector<std::string>>("recHitFlagsToBeExcludedEndcaps");
341  recHitsCfg.recHitFlagsToBeExcludedEndcaps = StringToEnumValue<EcalRecHit::Flags>(flagnamesendcaps);
342  auto const& severitynamesbarrel = cfg.getParameter<std::vector<std::string>>("recHitSeverityToBeExcludedBarrel");
344  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesbarrel);
345  auto const& severitynamesendcaps = cfg.getParameter<std::vector<std::string>>("recHitSeverityToBeExcludedEndcaps");
347  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesendcaps);
348 
349  // isolation
351  .intRadiusHcal = cfg.getParameter<double>("intRadiusHcal"),
352  .etMinHcal = cfg.getParameter<double>("etMinHcal"),
353  .intRadiusEcalBarrel = cfg.getParameter<double>("intRadiusEcalBarrel"),
354  .intRadiusEcalEndcaps = cfg.getParameter<double>("intRadiusEcalEndcaps"),
355  .jurassicWidth = cfg.getParameter<double>("jurassicWidth"),
356  .etMinBarrel = cfg.getParameter<double>("etMinBarrel"),
357  .eMinBarrel = cfg.getParameter<double>("eMinBarrel"),
358  .etMinEndcaps = cfg.getParameter<double>("etMinEndcaps"),
359  .eMinEndcaps = cfg.getParameter<double>("eMinEndcaps"),
360  .vetoClustered = cfg.getParameter<bool>("vetoClustered"),
361  .useNumCrystals = cfg.getParameter<bool>("useNumCrystals")};
362 
363  const RegressionHelper::Configuration regressionCfg{
364  .ecalRegressionWeightLabels = cfg.getParameter<std::vector<std::string>>("ecalRefinedRegressionWeightLabels"),
365  .ecalWeightsFromDB = cfg.getParameter<bool>("ecalWeightsFromDB"),
366  .ecalRegressionWeightFiles = cfg.getParameter<std::vector<std::string>>("ecalRefinedRegressionWeightFiles"),
368  cfg.getParameter<std::vector<std::string>>("combinationRegressionWeightLabels"),
369  .combinationWeightsFromDB = cfg.getParameter<bool>("combinationWeightsFromDB"),
370  .combinationRegressionWeightFiles =
371  cfg.getParameter<std::vector<std::string>>("combinationRegressionWeightFile")};
372 
373  // create algo
374  algo_ = std::make_unique<GsfElectronAlgo>(
375  inputCfg_,
376  strategyCfg_,
377  cutsCfg_,
378  hcalCfg_,
379  isoCfg,
380  recHitsCfg,
381  EcalClusterFunctionFactory::get()->create(cfg.getParameter<std::string>("superClusterErrorFunction"), cfg),
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) {
439  std::sort(electrons.begin(), electrons.end(), egamma::isBetterElectron);
440  } else if (strategyCfg_.ambSortingStrategy == 1) {
441  std::sort(electrons.begin(), electrons.end(), egamma::isInnermostElectron);
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;
476  if (ignoreNotPreselected && !isPreselected(*e1))
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(), 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:153
Handle.h
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
GsfElectronAlgo::CutsConfiguration::maxHOverEBarrelCone
double maxHOverEBarrelCone
Definition: GsfElectronAlgo.h:108
GsfElectronAlgo::StrategyConfiguration::applyAmbResolution
bool applyAmbResolution
Definition: GsfElectronAlgo.h:81
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:27
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:72
PFCandidate.h
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
edm::Ref::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
GsfElectronProducer::inputCfg_
GsfElectronAlgo::Tokens inputCfg_
Definition: GsfElectronProducer.cc:95
EDProducer.h
GsfElectronAlgo::HeavyObjectCache::iElectronMVAEstimator
std::unique_ptr< const ElectronMVAEstimator > iElectronMVAEstimator
Definition: GsfElectronAlgo.h:55
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
GsfElectronAlgo::StrategyConfiguration::ambClustersOverlapStrategy
unsigned ambClustersOverlapStrategy
Definition: GsfElectronAlgo.h:83
GsfElectronProducer::cutsCfg_
const GsfElectronAlgo::CutsConfiguration cutsCfg_
Definition: GsfElectronProducer.cc:97
HLT_2018_cff.endcapRecHits
endcapRecHits
Definition: HLT_2018_cff.py:13538
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:152
GsfElectronAlgo::Tokens::seedsTag
edm::EDGetTokenT< reco::ElectronSeedCollection > seedsTag
Definition: GsfElectronAlgo.h:65
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:99
GsfElectronAlgo::Tokens::beamSpotTag
edm::EDGetTokenT< reco::BeamSpot > beamSpotTag
Definition: GsfElectronAlgo.h:67
GsfElectronAlgo::Tokens::barrelRecHitCollection
edm::EDGetTokenT< EcalRecHitCollection > barrelRecHitCollection
Definition: GsfElectronAlgo.h:63
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:109
edm::Ref
Definition: AssociativeIterator.h:58
GsfElectronProducer::resetMvaValuesUsingPFCandidates_
const bool resetMvaValuesUsingPFCandidates_
Definition: GsfElectronProducer.cc:115
GsfElectronAlgo::StrategyConfiguration::ambSortingStrategy
unsigned ambSortingStrategy
Definition: GsfElectronAlgo.h:82
EcalSeverityLevel.h
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:154
EleRelPoint
Definition: ElectronUtilities.h:25
GsfElectronAlgo::HeavyObjectCache
Definition: GsfElectronAlgo.h:51
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:98
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:25
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:23
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:64
GsfElectronProducer
Definition: GsfElectronProducer.cc:76
edm::LogWarning
Definition: MessageLogger.h:141
GsfElectronAlgo::StrategyConfiguration::MaxElePtForOnlyMVA
float MaxElePtForOnlyMVA
Definition: GsfElectronAlgo.h:87
GsfElectronAlgo::Tokens
Definition: GsfElectronAlgo.h:58
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:232
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
EleTkIsolFromCands.h
Event.h
GsfElectronProducer::algo_
std::unique_ptr< GsfElectronAlgo > algo_
Definition: GsfElectronProducer.cc:92
HiRegitMuonDetachedTripletStep_cff.minMVA
minMVA
Definition: HiRegitMuonDetachedTripletStep_cff.py:109
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:96
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:47
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:282
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:54
overlapproblemtsosanalyzer_cfi.title
title
Definition: overlapproblemtsosanalyzer_cfi.py:7
HLT_2018_cff.barrelRecHits
barrelRecHits
Definition: HLT_2018_cff.py:13541
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Reconstruction_hiPF_cff.maxHOverEEndcapsCone
maxHOverEEndcapsCone
Definition: Reconstruction_hiPF_cff.py:27
GsfElectronAlgo::StrategyConfiguration::applyPreselection
bool applyPreselection
Definition: GsfElectronAlgo.h:74
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:68
Provenance.h
GsfElectronProducer::hcalCfg_
ElectronHcalHelper::Configuration hcalCfg_
Definition: GsfElectronProducer.cc:98
EventSetup.h
reco::PFCandidateEGammaExtra::MVA_DeltaEtaTrackCluster
Definition: PFCandidateEGammaExtra.h:48
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:161
reco::PFCandidateEGammaExtra::MVA_FirstBrem
Definition: PFCandidateEGammaExtra.h:52
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
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:160
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:428
edm::InputTag
Definition: InputTag.h:15
GsfElectronProducer::gsfPfRecTracksTag_
const edm::EDGetTokenT< reco::GsfPFRecTrackCollection > gsfPfRecTracksTag_
Definition: GsfElectronProducer.cc:110
RegressionHelper::Configuration
Definition: RegressionHelper.h:25
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
ElectronSeed.h
GsfElectronAlgo::EcalRecHitsConfiguration
Definition: GsfElectronAlgo.h:151
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
GsfElectronAlgo.h
GsfElectronAlgo::EcalRecHitsConfiguration::recHitSeverityToBeExcludedEndcaps
std::vector< int > recHitSeverityToBeExcludedEndcaps
Definition: GsfElectronAlgo.h:155
electronEcalRecHitIsolationLcone_cfi.vetoClustered
vetoClustered
Definition: electronEcalRecHitIsolationLcone_cfi.py:27