CMS 3D CMS Logo

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