CMS 3D CMS Logo

GEDGsfElectronProducer.cc
Go to the documentation of this file.
1 
4 
11 
13 
16 
18 
23 
24 #include <iostream>
25 #include <string>
26 
27 using namespace reco;
28 
31  : GsfElectronBaseProducer(cfg, hoc),
32  egmPFCandidateCollection_(
33  consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("egmPFCandidatesTag"))) {
34  produces<edm::ValueMap<reco::GsfElectronRef>>();
35 }
36 
37 // ------------ method called to produce the data ------------
39  matchWithPFCandidates(event);
41  algo_->completeElectrons(electrons, event, setup, globalCache());
42  setMVAOutputs(electrons, globalCache(), gsfMVAOutputMap_, event.get(inputCfg_.vtxCollectionTag));
43  for (auto& el : electrons)
44  el.setMvaInput(gsfMVAInputMap_.find(el.gsfTrack())->second); // set MVA inputs
45  fillEvent(electrons, event);
46 
47  // ValueMap
48  auto valMap_p = std::make_unique<edm::ValueMap<reco::GsfElectronRef>>();
49  edm::ValueMap<reco::GsfElectronRef>::Filler valMapFiller(*valMap_p);
50  fillGsfElectronValueMap(event, valMapFiller);
51  valMapFiller.fill();
52  event.put(std::move(valMap_p));
53  // Done with the ValueMap
54 }
55 
58  // Read the collection of PFCandidates
60 
61  bool found = event.getByToken(egmPFCandidateCollection_, pfCandidates);
62  if (!found) {
63  edm::LogError("GEDGsfElectronProducer") << " cannot get PFCandidates! ";
64  }
65 
66  //Loop over the collection of PFFCandidates
67  reco::PFCandidateCollection::const_iterator it = pfCandidates->begin();
68  reco::PFCandidateCollection::const_iterator itend = pfCandidates->end();
69  std::vector<reco::GsfElectronRef> values;
70 
71  for (; it != itend; ++it) {
73  // First check that the GsfTrack is non null
74  if (it->gsfTrackRef().isNonnull()) {
75  // now look for the corresponding GsfElectron
76  const auto itcheck = std::find_if(orphanHandle()->begin(), orphanHandle()->end(), [it](const auto& ele) {
77  return (ele.gsfTrack() == it->gsfTrackRef());
78  });
79  if (itcheck != orphanHandle()->end()) {
80  // Build the Ref from the handle and the index
81  myRef = reco::GsfElectronRef(orphanHandle(), itcheck - orphanHandle()->begin());
82  }
83  }
84  values.push_back(myRef);
85  }
86  filler.insert(pfCandidates, values.begin(), values.end());
87 }
88 
89 // Something more clever has to be found. The collections are small, so the timing is not
90 // an issue here; but it is clearly suboptimal
91 
93  gsfMVAInputMap_.clear();
94  gsfMVAOutputMap_.clear();
95 
96  // Read the collection of PFCandidates
98 
99  bool found = event.getByToken(egmPFCandidateCollection_, pfCandidates);
100  if (!found) {
101  edm::LogError("GEDGsfElectronProducer") << " cannot get PFCandidates! ";
102  }
103 
104  //Loop over the collection of PFFCandidates
105  reco::PFCandidateCollection::const_iterator it = pfCandidates->begin();
106  reco::PFCandidateCollection::const_iterator itend = pfCandidates->end();
107 
108  for (; it != itend; ++it) {
109  reco::GsfElectronRef myRef;
110  // First check that the GsfTrack is non null
111  if (it->gsfTrackRef().isNonnull()) {
112  reco::GsfElectron::MvaOutput myMvaOutput;
113  // at the moment, undefined
114  myMvaOutput.status = it->egammaExtraRef()->electronStatus();
115  gsfMVAOutputMap_[it->gsfTrackRef()] = myMvaOutput;
116 
117  reco::GsfElectron::MvaInput myMvaInput;
118  myMvaInput.earlyBrem = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_FirstBrem);
119  myMvaInput.lateBrem = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_LateBrem);
120  myMvaInput.deltaEta = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_DeltaEtaTrackCluster);
121  myMvaInput.sigmaEtaEta = it->egammaExtraRef()->sigmaEtaEta();
122  myMvaInput.hadEnergy = it->egammaExtraRef()->hadEnergy();
123  gsfMVAInputMap_[it->gsfTrackRef()] = myMvaInput;
124  }
125  }
126 }
127 
130  const std::map<reco::GsfTrackRef, reco::GsfElectron::MvaOutput>& mvaOutputs,
131  reco::VertexCollection const& vertices) const {
132  for (auto el = electrons.begin(); el != electrons.end(); el++) {
133  float mva_NIso_Value = hoc->sElectronMVAEstimator->mva(*el, vertices);
134  float mva_Iso_Value = hoc->iElectronMVAEstimator->mva(*el, vertices.size());
135  GsfElectron::MvaOutput mvaOutput;
136  mvaOutput.mva_e_pi = mva_NIso_Value;
137  mvaOutput.mva_Isolated = mva_Iso_Value;
138  el->setMvaOutput(mvaOutput);
139  }
140 }
void matchWithPFCandidates(edm::Event &event)
std::unique_ptr< GsfElectronAlgo > algo_
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::VertexCollection > vtxCollectionTag
GEDGsfElectronProducer(const edm::ParameterSet &, const GsfElectronAlgo::HeavyObjectCache *)
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
void fillEvent(reco::GsfElectronCollection &electrons, edm::Event &event)
std::unique_ptr< const ElectronMVAEstimator > iElectronMVAEstimator
U second(std::pair< T, U > const &p)
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:334
#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
void setMVAOutputs(reco::GsfElectronCollection &electrons, const GsfElectronAlgo::HeavyObjectCache *, const std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > &mvaOutputs, reco::VertexCollection const &vertices) const
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > gsfMVAOutputMap_
fixed size matrix
#define begin
Definition: vmac.h:32
HLT enums.
GsfElectronAlgo::Tokens inputCfg_
std::unique_ptr< const SoftElectronMVAEstimator > sElectronMVAEstimator
def move(src, dest)
Definition: eostools.py:511
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > gsfMVAInputMap_
Definition: event.py:1