CMS 3D CMS Logo

GsfElectronProducer.cc
Go to the documentation of this file.
1 #include "GsfElectronProducer.h"
2 
11 
20 
21 #include <iostream>
22 
23 using namespace reco;
24 
26  : GsfElectronBaseProducer(cfg, hoc), pfTranslatorParametersChecked_(false) {}
27 
30 
31  auto coreElectrons = event.getHandle(inputCfg_.gsfElectronCores);
32  const GsfElectronCoreCollection* newCores = coreElectrons.product();
33 
34  for (auto const& oldElectron : event.get(inputCfg_.previousGsfElectrons)) {
35  const GsfElectronCoreRef oldCoreRef = oldElectron.core();
36  const GsfTrackRef oldElectronGsfTrackRef = oldCoreRef->gsfTrack();
37  unsigned int icore;
38  for (icore = 0; icore < newCores->size(); ++icore) {
39  if (oldElectronGsfTrackRef == (*newCores)[icore].gsfTrack()) {
40  const GsfElectronCoreRef coreRef = edm::Ref<GsfElectronCoreCollection>(coreElectrons, icore);
41  electrons.emplace_back(oldElectron, coreRef);
42  break;
43  }
44  }
45  }
46  return electrons;
47 }
48 
50  auto electrons = clonePreviousElectrons(event);
51  // don't add pflow only electrons if one so wish
53  algo_->completeElectrons(electrons, event, setup, globalCache());
54  }
55  addPflowInfo(electrons, event);
56  fillEvent(electrons, event);
57 }
58 
60  // extra configuration checks
64  event.getByToken(pfMVA_, pfMva);
66  }
67 
68  // call to base class
69  return GsfElectronBaseProducer::beginEvent(event, setup);
70 }
71 
73  edm::ParameterSet mvaBlock = pset.getParameter<edm::ParameterSet>("MVACutBlock");
74  double pfTranslatorMinMva = mvaBlock.getParameter<double>("MVACut");
75  double pfTranslatorUndefined = -99.;
76  if (strategyCfg_.applyPreselection && (cutsCfgPflow_.minMVA < pfTranslatorMinMva)) {
77  // For pure tracker seeded electrons, if MVA is under translatorMinMva, there is no supercluster
78  // of any kind available, so GsfElectronCoreProducer has already discarded the electron.
79  edm::LogWarning("GsfElectronAlgo|MvaCutTooLow")
80  << "Parameter minMVAPflow (" << cutsCfgPflow_.minMVA
81  << ") will have no effect on purely tracker seeded electrons."
82  << " It is inferior to the cut already applied by PFlow translator (" << pfTranslatorMinMva << ").";
83  }
84  if (strategyCfg_.applyPreselection && (cutsCfg_.minMVA < pfTranslatorMinMva)) {
85  // For ecal seeded electrons, there is a cluster and GsfElectronCoreProducer has kept all electrons,
86  // but when MVA is under translatorMinMva, the translator has not stored the supercluster and
87  // forced the MVA value to translatorUndefined
88  if (cutsCfg_.minMVA > pfTranslatorUndefined) {
89  edm::LogWarning("GsfElectronAlgo|IncompletePflowInformation")
90  << "Parameter minMVA (" << cutsCfg_.minMVA << ")is inferior to the cut applied by PFlow translator ("
91  << pfTranslatorMinMva << ")."
92  << " Some ecal (and eventually tracker) seeded electrons may lack their MVA value and PFlow supercluster.";
93  } else {
94  // the MVA value has been forced to translatorUndefined, inferior minMVAPflow
95  // so the cut actually applied is the PFlow one
96  throw cms::Exception("GsfElectronAlgo|BadMvaCut") << "Parameter minMVA is inferior to the lowest possible value."
97  << " Every electron will be blessed whatever other criteria.";
98  }
99  }
100 }
101 
102 // now deprecated
104  //Isolation Value Maps for PF and EcalDriven electrons
105  typedef std::vector<edm::Handle<edm::ValueMap<double> > > IsolationValueMaps;
106  IsolationValueMaps pfIsolationValues;
107  IsolationValueMaps edIsolationValues;
108 
109  //Fill in the Isolation Value Maps for PF and EcalDriven electrons
110  std::vector<edm::InputTag> inputTagIsoVals;
111  if (!pfIsoVals_.empty()) {
112  inputTagIsoVals.push_back(pfIsoVals_.getParameter<edm::InputTag>("pfSumChargedHadronPt"));
113  inputTagIsoVals.push_back(pfIsoVals_.getParameter<edm::InputTag>("pfSumPhotonEt"));
114  inputTagIsoVals.push_back(pfIsoVals_.getParameter<edm::InputTag>("pfSumNeutralHadronEt"));
115 
116  pfIsolationValues.resize(inputTagIsoVals.size());
117 
118  for (size_t j = 0; j < inputTagIsoVals.size(); ++j) {
119  event.getByLabel(inputTagIsoVals[j], pfIsolationValues[j]);
120  }
121  }
122 
123  if (!edIsoVals_.empty()) {
124  inputTagIsoVals.clear();
125  inputTagIsoVals.push_back(edIsoVals_.getParameter<edm::InputTag>("edSumChargedHadronPt"));
126  inputTagIsoVals.push_back(edIsoVals_.getParameter<edm::InputTag>("edSumPhotonEt"));
127  inputTagIsoVals.push_back(edIsoVals_.getParameter<edm::InputTag>("edSumNeutralHadronEt"));
128 
129  edIsolationValues.resize(inputTagIsoVals.size());
130 
131  for (size_t j = 0; j < inputTagIsoVals.size(); ++j) {
132  event.getByLabel(inputTagIsoVals[j], edIsolationValues[j]);
133  }
134  }
135 
136  bool found;
137  auto edElectrons = event.getHandle(inputCfg_.previousGsfElectrons);
138  auto pfElectrons = event.getHandle(inputCfg_.pflowGsfElectronsTag);
139  reco::GsfElectronCollection::const_iterator pfElectron, edElectron;
140  unsigned int edIndex, pfIndex;
141 
142  for (auto& el : electrons) {
143  // Retreive info from pflow electrons
144  found = false;
145  for (pfIndex = 0, pfElectron = pfElectrons->begin(); pfElectron != pfElectrons->end(); pfIndex++, pfElectron++) {
146  if (pfElectron->gsfTrack() == el.gsfTrack()) {
147  if (found) {
148  edm::LogWarning("GsfElectronProducer") << "associated pfGsfElectron already found";
149  } else {
150  found = true;
151 
152  // Isolation Values
153  if (!(pfIsolationValues).empty()) {
154  reco::GsfElectronRef pfElectronRef(pfElectrons, pfIndex);
156  isoVariables.sumChargedHadronPt = (*(pfIsolationValues)[0])[pfElectronRef];
157  isoVariables.sumPhotonEt = (*(pfIsolationValues)[1])[pfElectronRef];
158  isoVariables.sumNeutralHadronEt = (*(pfIsolationValues)[2])[pfElectronRef];
159  el.setPfIsolationVariables(isoVariables);
160  }
161 
162  // el.setPfIsolationVariables(pfElectron->pfIsolationVariables()) ;
163  el.setMvaInput(pfElectron->mvaInput());
164  el.setMvaOutput(pfElectron->mvaOutput());
165  if (el.ecalDrivenSeed()) {
166  el.setP4(GsfElectron::P4_PFLOW_COMBINATION,
167  pfElectron->p4(GsfElectron::P4_PFLOW_COMBINATION),
168  pfElectron->p4Error(GsfElectron::P4_PFLOW_COMBINATION),
169  false);
170  } else {
171  el.setP4(GsfElectron::P4_PFLOW_COMBINATION,
172  pfElectron->p4(GsfElectron::P4_PFLOW_COMBINATION),
173  pfElectron->p4Error(GsfElectron::P4_PFLOW_COMBINATION),
174  true);
175  }
176  double noCutMin = -999999999.;
177  if (el.mva_e_pi() < noCutMin) {
178  throw cms::Exception("GsfElectronAlgo|UnexpectedMvaValue") << "unexpected MVA value: " << el.mva_e_pi();
179  }
180  }
181  }
182  }
183 
184  // Isolation Values
185  // Retreive not found info from ed electrons
186  if (!(edIsolationValues).empty()) {
187  edIndex = 0, edElectron = edElectrons->begin();
188  while ((found == false) && (edElectron != edElectrons->end())) {
189  if (edElectron->gsfTrack() == el.gsfTrack()) {
190  found = true;
191 
192  // CONSTRUCTION D UNE REF dans le handle previousElectrons avec l'indice edIndex,
193  // puis recuperation dans la ValueMap ED
194 
195  reco::GsfElectronRef edElectronRef(edElectrons, edIndex);
197  isoVariables.sumChargedHadronPt = (*(edIsolationValues)[0])[edElectronRef];
198  isoVariables.sumPhotonEt = (*(edIsolationValues)[1])[edElectronRef];
199  isoVariables.sumNeutralHadronEt = (*(edIsolationValues)[2])[edElectronRef];
200  el.setPfIsolationVariables(isoVariables);
201  }
202 
203  edIndex++;
204  edElectron++;
205  }
206  }
207 
208  // Preselection
210  }
211 }
212 
214  ele.setPassMvaPreselection(false);
215 
216  if (ele.core()->ecalDrivenSeed()) {
217  if (ele.mvaOutput().mva_e_pi >= cutsCfg_.minMVA)
218  ele.setPassMvaPreselection(true);
219  } else {
220  if (ele.mvaOutput().mva_e_pi >= cutsCfgPflow_.minMVA)
221  ele.setPassMvaPreselection(true);
222  }
223 
224  if (ele.passingMvaPreselection()) {
225  LogTrace("GsfElectronAlgo") << "Main mva criterion is satisfied";
226  }
227 
229 }
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:190
std::unique_ptr< GsfElectronAlgo > algo_
reco::GsfElectronCollection clonePreviousElectrons(edm::Event const &event) const
bool passingMvaPreselection() const
Definition: GsfElectron.h:695
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
edm::EDGetTokenT< reco::GsfElectronCoreCollection > gsfElectronCores
edm::EDGetTokenT< reco::GsfElectronCollection > pflowGsfElectronsTag
void fillEvent(reco::GsfElectronCollection &electrons, edm::Event &event)
void checkPfTranslatorParameters(edm::ParameterSet const &)
void setPflowPreselectionFlag(reco::GsfElectron &ele) const
GsfElectronProducer(const edm::ParameterSet &, const GsfElectronAlgo::HeavyObjectCache *)
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:602
std::vector< GsfElectronCore > GsfElectronCoreCollection
void setPassMvaPreselection(bool flag)
Definition: GsfElectron.h:694
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:334
float sumNeutralHadronEt
sum pt of neutral hadrons // old float neutralHadronIso ;
Definition: GsfElectron.h:601
#define LogTrace(id)
void addPflowInfo(reco::GsfElectronCollection &electrons, edm::Event const &event) const
const MvaOutput & mvaOutput() const
Definition: GsfElectron.h:656
GsfElectronAlgo::StrategyConfiguration strategyCfg_
void beginEvent(edm::Event &, const edm::EventSetup &)
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
edm::EDGetTokenT< edm::ValueMap< float > > pfMVA_
edm::EDGetTokenT< reco::GsfElectronCollection > previousGsfElectrons
void beginEvent(edm::Event &, const edm::EventSetup &)
fixed size matrix
GsfElectronAlgo::Tokens inputCfg_
void setPassPflowPreselection(bool flag)
Definition: GsfElectron.h:688
const GsfElectronAlgo::CutsConfiguration cutsCfgPflow_
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:600
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
Definition: event.py:1
Provenance const * provenance() const
Definition: HandleBase.h:74
const GsfElectronAlgo::CutsConfiguration cutsCfg_
void produce(edm::Event &, const edm::EventSetup &) override