CMS 3D CMS Logo

GEDGsfElectronProducer.cc
Go to the documentation of this file.
1 
4 
11 
13 
16 
18 
19 
24 
25 #include <iostream>
26 #include <string>
27 
28 using namespace reco;
29 
31  : GsfElectronBaseProducer(cfg,hoc)
32  , egmPFCandidateCollection_(consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("egmPFCandidatesTag")))
33 {
34  produces<edm::ValueMap<reco::GsfElectronRef> >();
35 }
36 
37 
38 // ------------ method called to produce the data ------------
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  }
56 
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 }
89 
90 
91 // Something more clever has to be found. The collections are small, so the timing is not
92 // an issue here; but it is clearly suboptimal
93 
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 }
132 
133 
136  const std::map<reco::GsfTrackRef, reco::GsfElectron::MvaOutput>& mvaOutputs,
137  reco::VertexCollection const& vertices) const
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 }
void matchWithPFCandidates(edm::Event &event)
std::unique_ptr< const SoftElectronMVAEstimator > sElectronMVAEstimator
edm::EDGetTokenT< reco::VertexCollection > vtxCollectionTag
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
void produce(edm::Event &, const edm::EventSetup &) override
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
#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
void fillGsfElectronValueMap(edm::Event &event, edm::ValueMap< reco::GsfElectronRef >::Filler &filler)
const edm::OrphanHandle< reco::GsfElectronCollection > & orphanHandle() const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
GEDGsfElectronProducer(const edm::ParameterSet &, const gsfAlgoHelpers::HeavyObjectCache *)
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_
fixed size matrix
#define begin
Definition: vmac.h:32
HLT enums.
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< const ElectronMVAEstimator > iElectronMVAEstimator
Definition: event.py:1
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > gsfMVAInputMap_