CMS 3D CMS Logo

GEDGsfElectronProducer.cc
Go to the documentation of this file.
1 
4 
11 
13 
16 
18 
19 
25 
26 #include <iostream>
27 #include <string>
28 
29 using namespace reco;
30 
32  : GsfElectronBaseProducer(cfg,hoc)
33  {
34  egmPFCandidateCollection_ = consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("egmPFCandidatesTag"));
35  outputValueMapLabel_ = cfg.getParameter<std::string>("outputEGMPFValueMap");
36 
37  produces<edm::ValueMap<reco::GsfElectronRef> >(outputValueMapLabel_);
38 }
39 
41  {}
42 
43 // ------------ method called to produce the data ------------
45  {
46  beginEvent(event,setup) ;
47  matchWithPFCandidates(event);
48  algo_->completeElectrons(globalCache()) ;
49  algo_->setMVAOutputs(globalCache(),gsfMVAOutputMap_);
51  fillEvent(event) ;
52 
53  // ValueMap
54  auto valMap_p = std::make_unique<edm::ValueMap<reco::GsfElectronRef>>();
55  edm::ValueMap<reco::GsfElectronRef>::Filler valMapFiller(*valMap_p);
56  fillGsfElectronValueMap(event,valMapFiller);
57  valMapFiller.fill();
58  event.put(std::move(valMap_p),outputValueMapLabel_);
59  // Done with the ValueMap
60 
61  endEvent() ;
62  }
63 
65 {
66  // Read the collection of PFCandidates
68 
69  bool found = event.getByToken(egmPFCandidateCollection_, pfCandidates);
70  if(!found) {
71  edm::LogError("GEDGsfElectronProducer")
72  <<" cannot get PFCandidates! ";
73  }
74 
75  //Loop over the collection of PFFCandidates
76  reco::PFCandidateCollection::const_iterator it = pfCandidates->begin();
77  reco::PFCandidateCollection::const_iterator itend = pfCandidates->end() ;
78  std::vector<reco::GsfElectronRef> values;
79 
80  for ( ; it != itend ; ++it) {
82  // First check that the GsfTrack is non null
83  if( it->gsfTrackRef().isNonnull()) {
84  // now look for the corresponding GsfElectron
85  GsfElectronEqual myEqual(it->gsfTrackRef());
86  const reco::GsfElectronCollection::const_iterator itcheck=
87  std::find_if(orphanHandle()->begin(),orphanHandle()->end(),myEqual);
88  if (itcheck != orphanHandle()->end()) {
89  // Build the Ref from the handle and the index
90  myRef = reco::GsfElectronRef(orphanHandle(),itcheck-orphanHandle()->begin());
91  }
92  }
93  values.push_back(myRef);
94  }
95  filler.insert(pfCandidates,values.begin(),values.end());
96 }
97 
98 
99 // Something more clever has to be found. The collections are small, so the timing is not
100 // an issue here; but it is clearly suboptimal
101 
103 {
104  gsfMVAInputMap_.clear();
105  gsfMVAOutputMap_.clear();
106 
107  // Read the collection of PFCandidates
109 
110  bool found = event.getByToken(egmPFCandidateCollection_, pfCandidates);
111  if(!found) {
112  edm::LogError("GEDGsfElectronProducer")
113  <<" cannot get PFCandidates! ";
114  }
115 
116  //Loop over the collection of PFFCandidates
117  reco::PFCandidateCollection::const_iterator it = pfCandidates->begin();
118  reco::PFCandidateCollection::const_iterator itend = pfCandidates->end() ;
119 
120  for ( ; it != itend ; ++it) {
121  reco::GsfElectronRef myRef;
122  // First check that the GsfTrack is non null
123  if( it->gsfTrackRef().isNonnull()) {
124 
125  reco::GsfElectron::MvaOutput myMvaOutput;
126  // at the moment, undefined
127  myMvaOutput.status = it->egammaExtraRef()->electronStatus() ;
128  gsfMVAOutputMap_[it->gsfTrackRef()] = myMvaOutput;
129 
130  reco::GsfElectron::MvaInput myMvaInput;
131  myMvaInput.earlyBrem = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_FirstBrem);
132  myMvaInput.lateBrem = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_LateBrem);
133  myMvaInput.deltaEta = it->egammaExtraRef()->mvaVariable(reco::PFCandidateEGammaExtra::MVA_DeltaEtaTrackCluster);
134  myMvaInput.sigmaEtaEta = it->egammaExtraRef()->sigmaEtaEta();
135  myMvaInput.hadEnergy = it->egammaExtraRef()->hadEnergy();
136  gsfMVAInputMap_[it->gsfTrackRef()] = myMvaInput;
137  }
138  }
139 }
T getParameter(std::string const &) const
void matchWithPFCandidates(edm::Event &event)
void setMVAOutputs(const gsfAlgoHelpers::HeavyObjectCache *, const std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > &mvaOutputs)
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
void setMVAInputs(const std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > &mvaInputs)
void completeElectrons(const gsfAlgoHelpers::HeavyObjectCache *)
virtual void produce(edm::Event &, const edm::EventSetup &)
#define end
Definition: vmac.h:37
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
GEDGsfElectronProducer(const edm::ParameterSet &, const gsfAlgoHelpers::HeavyObjectCache *)
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaOutput > gsfMVAOutputMap_
void beginEvent(edm::Event &, const edm::EventSetup &)
fixed size matrix
#define begin
Definition: vmac.h:30
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > gsfMVAInputMap_