CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  std::auto_ptr<edm::ValueMap<reco::GsfElectronRef> > valMap_p(new edm::ValueMap<reco::GsfElectronRef>);
55  edm::ValueMap<reco::GsfElectronRef>::Filler valMapFiller(*valMap_p);
56  fillGsfElectronValueMap(event,valMapFiller);
57  valMapFiller.fill();
58  event.put(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)
tuple cfg
Definition: looper.py:293
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
void setMVAInputs(const std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > &mvaInputs)
void completeElectrons(const gsfAlgoHelpers::HeavyObjectCache *)
virtual void produce(edm::Event &, const edm::EventSetup &)
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
#define end
Definition: vmac.h:37
edm::EDGetTokenT< reco::PFCandidateCollection > egmPFCandidateCollection_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
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 &)
#define begin
Definition: vmac.h:30
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
std::map< reco::GsfTrackRef, reco::GsfElectron::MvaInput > gsfMVAInputMap_