CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
GEDGsfElectronProducer Class Reference

#include <GEDGsfElectronProducer.h>

Inheritance diagram for GEDGsfElectronProducer:
GsfElectronBaseProducer edm::stream::EDProducer< edm::GlobalCache< gsfAlgoHelpers::HeavyObjectCache > >

Public Member Functions

 GEDGsfElectronProducer (const edm::ParameterSet &, const gsfAlgoHelpers::HeavyObjectCache *)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
- Public Member Functions inherited from GsfElectronBaseProducer
 GsfElectronBaseProducer (const edm::ParameterSet &, const gsfAlgoHelpers::HeavyObjectCache *)
 
 ~GsfElectronBaseProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< gsfAlgoHelpers::HeavyObjectCache > >
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Member Functions

void fillGsfElectronValueMap (edm::Event &event, edm::ValueMap< reco::GsfElectronRef >::Filler &filler)
 
void matchWithPFCandidates (edm::Event &event)
 
void setMVAOutputs (reco::GsfElectronCollection &electrons, const gsfAlgoHelpers::HeavyObjectCache *, const std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > &mvaOutputs, reco::VertexCollection const &vertices) const
 

Private Attributes

edm::EDGetTokenT< reco::PFCandidateCollectionegmPFCandidateCollection_
 
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInputgsfMVAInputMap_
 
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutputgsfMVAOutputMap_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< gsfAlgoHelpers::HeavyObjectCache > >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Static Public Member Functions inherited from GsfElectronBaseProducer
static void fillDescriptions (edm::ConfigurationDescriptions &)
 
static void globalEndJob (gsfAlgoHelpers::HeavyObjectCache const *)
 
static std::unique_ptr< gsfAlgoHelpers::HeavyObjectCacheinitializeGlobalCache (const edm::ParameterSet &conf)
 
- Protected Member Functions inherited from GsfElectronBaseProducer
void beginEvent (edm::Event &, const edm::EventSetup &)
 
void fillEvent (reco::GsfElectronCollection &electrons, edm::Event &event)
 
const edm::OrphanHandle< reco::GsfElectronCollection > & orphanHandle () const
 
- Protected Attributes inherited from GsfElectronBaseProducer
GsfElectronAlgoalgo_
 
const GsfElectronAlgo::CutsConfiguration cutsCfg_
 
const GsfElectronAlgo::CutsConfiguration cutsCfgPflow_
 
ElectronHcalHelper::Configuration hcalCfg_
 
ElectronHcalHelper::Configuration hcalCfgPflow_
 
GsfElectronAlgo::InputTagsConfiguration inputCfg_
 
edm::EDGetTokenT< edm::ValueMap< float > > pfMVA_
 
GsfElectronAlgo::StrategyConfiguration strategyCfg_
 

Detailed Description

Definition at line 9 of file GEDGsfElectronProducer.h.

Constructor & Destructor Documentation

GEDGsfElectronProducer::GEDGsfElectronProducer ( const edm::ParameterSet cfg,
const gsfAlgoHelpers::HeavyObjectCache hoc 
)
explicit

Definition at line 30 of file GEDGsfElectronProducer.cc.

31  : GsfElectronBaseProducer(cfg,hoc)
32  , egmPFCandidateCollection_(consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("egmPFCandidatesTag")))
33 {
34  produces<edm::ValueMap<reco::GsfElectronRef> >();
35 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::PFCandidateCollection > egmPFCandidateCollection_
GsfElectronBaseProducer(const edm::ParameterSet &, const gsfAlgoHelpers::HeavyObjectCache *)

Member Function Documentation

void GEDGsfElectronProducer::fillGsfElectronValueMap ( edm::Event event,
edm::ValueMap< reco::GsfElectronRef >::Filler &  filler 
)
private

Definition at line 57 of file GEDGsfElectronProducer.cc.

References begin, egmPFCandidateCollection_, end, runEdmFileComparison::found, edm::helper::Filler< Map >::insert(), GsfElectronBaseProducer::orphanHandle(), slimmedMuons_cfi::pfCandidates, and MuonErrorMatrixValues_cff::values.

Referenced by produce().

58 {
59  // Read the collection of PFCandidates
61 
62  bool found = event.getByToken(egmPFCandidateCollection_, pfCandidates);
63  if(!found) {
64  edm::LogError("GEDGsfElectronProducer")
65  <<" cannot get PFCandidates! ";
66  }
67 
68  //Loop over the collection of PFFCandidates
69  reco::PFCandidateCollection::const_iterator it = pfCandidates->begin();
70  reco::PFCandidateCollection::const_iterator itend = pfCandidates->end() ;
71  std::vector<reco::GsfElectronRef> values;
72 
73  for ( ; it != itend ; ++it) {
75  // First check that the GsfTrack is non null
76  if( it->gsfTrackRef().isNonnull()) {
77  // now look for the corresponding GsfElectron
78  const auto itcheck = std::find_if( orphanHandle()->begin(),orphanHandle()->end(),
79  [it](const auto& ele) {return (ele.gsfTrack() == it->gsfTrackRef());} );
80  if (itcheck != orphanHandle()->end()) {
81  // Build the Ref from the handle and the index
82  myRef = reco::GsfElectronRef(orphanHandle(),itcheck-orphanHandle()->begin());
83  }
84  }
85  values.push_back(myRef);
86  }
87  filler.insert(pfCandidates,values.begin(),values.end());
88 }
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
#define end
Definition: vmac.h:39
edm::EDGetTokenT< reco::PFCandidateCollection > egmPFCandidateCollection_
edm::Ref< GsfElectronCollection > GsfElectronRef
reference to an object in a collection of GsfElectron objects
const edm::OrphanHandle< reco::GsfElectronCollection > & orphanHandle() const
#define begin
Definition: vmac.h:32
void GEDGsfElectronProducer::matchWithPFCandidates ( edm::Event event)
private

Definition at line 94 of file GEDGsfElectronProducer.cc.

References reco::GsfElectron::MvaInput::deltaEta, reco::GsfElectron::MvaInput::earlyBrem, egmPFCandidateCollection_, runEdmFileComparison::found, gsfMVAInputMap_, gsfMVAOutputMap_, reco::GsfElectron::MvaInput::hadEnergy, reco::GsfElectron::MvaInput::lateBrem, reco::PFCandidateEGammaExtra::MVA_DeltaEtaTrackCluster, reco::PFCandidateEGammaExtra::MVA_FirstBrem, reco::PFCandidateEGammaExtra::MVA_LateBrem, slimmedMuons_cfi::pfCandidates, reco::GsfElectron::MvaInput::sigmaEtaEta, and reco::GsfElectron::MvaOutput::status.

Referenced by produce().

95 {
96  gsfMVAInputMap_.clear();
97  gsfMVAOutputMap_.clear();
98 
99  // Read the collection of PFCandidates
101 
102  bool found = event.getByToken(egmPFCandidateCollection_, pfCandidates);
103  if(!found) {
104  edm::LogError("GEDGsfElectronProducer")
105  <<" cannot get PFCandidates! ";
106  }
107 
108  //Loop over the collection of PFFCandidates
109  reco::PFCandidateCollection::const_iterator it = pfCandidates->begin();
110  reco::PFCandidateCollection::const_iterator itend = pfCandidates->end() ;
111 
112  for ( ; it != itend ; ++it) {
113  reco::GsfElectronRef myRef;
114  // First check that the GsfTrack is non null
115  if( it->gsfTrackRef().isNonnull()) {
116 
117  reco::GsfElectron::MvaOutput myMvaOutput;
118  // at the moment, undefined
119  myMvaOutput.status = it->egammaExtraRef()->electronStatus() ;
120  gsfMVAOutputMap_[it->gsfTrackRef()] = myMvaOutput;
121 
122  reco::GsfElectron::MvaInput myMvaInput;
123  myMvaInput.earlyBrem = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_FirstBrem);
124  myMvaInput.lateBrem = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_LateBrem);
125  myMvaInput.deltaEta = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_DeltaEtaTrackCluster);
126  myMvaInput.sigmaEtaEta = it->egammaExtraRef()->sigmaEtaEta();
127  myMvaInput.hadEnergy = it->egammaExtraRef()->hadEnergy();
128  gsfMVAInputMap_[it->gsfTrackRef()] = myMvaInput;
129  }
130  }
131 }
edm::EDGetTokenT< reco::PFCandidateCollection > egmPFCandidateCollection_
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > gsfMVAOutputMap_
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > gsfMVAInputMap_
void GEDGsfElectronProducer::produce ( edm::Event event,
const edm::EventSetup setup 
)
override

Definition at line 39 of file GEDGsfElectronProducer.cc.

References GsfElectronBaseProducer::algo_, GsfElectronAlgo::completeElectrons(), nano_cff::electrons, GsfElectronBaseProducer::fillEvent(), fillGsfElectronValueMap(), edm::Event::get(), gsfMVAInputMap_, gsfMVAOutputMap_, GsfElectronBaseProducer::inputCfg_, matchWithPFCandidates(), eostools::move(), edm::second(), setMVAOutputs(), and GsfElectronAlgo::InputTagsConfiguration::vtxCollectionTag.

40  {
41  matchWithPFCandidates(event);
43  algo_->completeElectrons(electrons, event, setup, globalCache()) ;
44  setMVAOutputs(electrons, globalCache(),gsfMVAOutputMap_, event.get(inputCfg_.vtxCollectionTag));
45  for(auto& el : electrons) el.setMvaInput(gsfMVAInputMap_.find(el.gsfTrack())->second); // set MVA inputs
46  fillEvent(electrons, event) ;
47 
48  // ValueMap
49  auto valMap_p = std::make_unique<edm::ValueMap<reco::GsfElectronRef>>();
50  edm::ValueMap<reco::GsfElectronRef>::Filler valMapFiller(*valMap_p);
51  fillGsfElectronValueMap(event,valMapFiller);
52  valMapFiller.fill();
53  event.put(std::move(valMap_p));
54  // Done with the ValueMap
55  }
void matchWithPFCandidates(edm::Event &event)
edm::EDGetTokenT< reco::VertexCollection > vtxCollectionTag
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
void fillEvent(reco::GsfElectronCollection &electrons, edm::Event &event)
void completeElectrons(reco::GsfElectronCollection &electrons, edm::Event const &event, edm::EventSetup const &eventSetup, const gsfAlgoHelpers::HeavyObjectCache *hoc)
U second(std::pair< T, U > const &p)
GsfElectronAlgo::InputTagsConfiguration inputCfg_
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:326
void fillGsfElectronValueMap(edm::Event &event, edm::ValueMap< reco::GsfElectronRef >::Filler &filler)
void setMVAOutputs(reco::GsfElectronCollection &electrons, const gsfAlgoHelpers::HeavyObjectCache *, const std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > &mvaOutputs, reco::VertexCollection const &vertices) const
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > gsfMVAOutputMap_
def move(src, dest)
Definition: eostools.py:511
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > gsfMVAInputMap_
void GEDGsfElectronProducer::setMVAOutputs ( reco::GsfElectronCollection electrons,
const gsfAlgoHelpers::HeavyObjectCache hoc,
const std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > &  mvaOutputs,
reco::VertexCollection const &  vertices 
) const
private

Definition at line 134 of file GEDGsfElectronProducer.cc.

References gsfAlgoHelpers::HeavyObjectCache::iElectronMVAEstimator, reco::GsfElectron::MvaOutput::mva_e_pi, reco::GsfElectron::MvaOutput::mva_Isolated, and gsfAlgoHelpers::HeavyObjectCache::sElectronMVAEstimator.

Referenced by produce().

138 {
139  for (auto el = electrons.begin(); el != electrons.end(); el++) {
140  float mva_NIso_Value = hoc->sElectronMVAEstimator->mva(*el, vertices);
141  float mva_Iso_Value = hoc->iElectronMVAEstimator->mva(*el, vertices.size());
142  GsfElectron::MvaOutput mvaOutput;
143  mvaOutput.mva_e_pi = mva_NIso_Value;
144  mvaOutput.mva_Isolated = mva_Iso_Value;
145  el->setMvaOutput(mvaOutput);
146  }
147 }
std::unique_ptr< const SoftElectronMVAEstimator > sElectronMVAEstimator
std::unique_ptr< const ElectronMVAEstimator > iElectronMVAEstimator

Member Data Documentation

edm::EDGetTokenT<reco::PFCandidateCollection> GEDGsfElectronProducer::egmPFCandidateCollection_
private

Definition at line 17 of file GEDGsfElectronProducer.h.

Referenced by fillGsfElectronValueMap(), and matchWithPFCandidates().

std::map<reco::GsfTrackRef,reco::GsfElectron::MvaInput> GEDGsfElectronProducer::gsfMVAInputMap_
private

Definition at line 18 of file GEDGsfElectronProducer.h.

Referenced by matchWithPFCandidates(), and produce().

std::map<reco::GsfTrackRef,reco::GsfElectron::MvaOutput> GEDGsfElectronProducer::gsfMVAOutputMap_
private

Definition at line 19 of file GEDGsfElectronProducer.h.

Referenced by matchWithPFCandidates(), and produce().