CMS 3D CMS Logo

GEDGsfElectronFinalizer.cc
Go to the documentation of this file.
2 
8 
11 
12 #include <iostream>
13 #include <string>
14 
15 using namespace reco;
16 
18  {
19  previousGsfElectrons_ = consumes<reco::GsfElectronCollection>(cfg.getParameter<edm::InputTag>("previousGsfElectronsTag"));
20  pfCandidates_ = consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("pfCandidatesTag"));
21  outputCollectionLabel_ = cfg.getParameter<std::string>("outputCollectionLabel");
22  edm::ParameterSet pfIsoVals(cfg.getParameter<edm::ParameterSet> ("pfIsolationValues"));
23 
24  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumChargedHadronPt")));
25  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPhotonEt")));
26  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumNeutralHadronEt")));
27  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPUPt")));
28  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumEcalClusterEt")));
29  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumHcalClusterEt")));
30 
31  nDeps_ = tokenElectronIsoVals_.size();
32 
33  if( cfg.existsAs<edm::ParameterSet>("regressionConfig") ) {
34  const edm::ParameterSet& iconf = cfg.getParameterSet("regressionConfig");
35  const std::string& mname = iconf.getParameter<std::string>("modifierName");
36  edm::ConsumesCollector&& cc = consumesCollector();
38  ModifyObjectValueFactory::get()->create(mname,iconf,cc);
39  gedRegression_.reset(plugin);
40  } else {
41  gedRegression_.reset(nullptr);
42  }
43 
44  produces<reco::GsfElectronCollection> (outputCollectionLabel_);
45 }
46 
48  {}
49 
50 // ------------ method called to produce the data ------------
52  {
53 
54  // Output collection
55  auto outputElectrons_p = std::make_unique<reco::GsfElectronCollection>();
56 
57  if( gedRegression_ ) {
58  gedRegression_->setEvent(event);
59  gedRegression_->setEventContent(setup);
60  }
61 
62  // read input collections
63  // electrons
65  event.getByToken(previousGsfElectrons_,gedElectronHandle);
66 
67  // PFCandidates
69  event.getByToken(pfCandidates_,pfCandidateHandle);
70  // value maps
71  std::vector< edm::Handle< edm::ValueMap<float> > > isolationValueMaps(nDeps_);
72 
73  for(unsigned i=0; i < nDeps_ ; ++i) {
74  event.getByToken(tokenElectronIsoVals_[i],isolationValueMaps[i]);
75  }
76 
77  // prepare a map of PFCandidates having a valid GsfTrackRef to save time
78  std::map<reco::GsfTrackRef, const reco::PFCandidate* > gsfPFMap;
79  reco::PFCandidateCollection::const_iterator it = pfCandidateHandle->begin();
80  reco::PFCandidateCollection::const_iterator itend = pfCandidateHandle->end() ;
81  for(;it!=itend;++it) {
82  // First check that the GsfTrack is non null
83  if( it->gsfTrackRef().isNonnull()) {
84  if(abs(it->pdgId())==11) // consider only the electrons
85  gsfPFMap[it->gsfTrackRef()]=&(*it);
86  }
87  }
88 
89 
90  // Now loop on the electrons
91  unsigned nele=gedElectronHandle->size();
92  for(unsigned iele=0; iele<nele;++iele) {
93  reco::GsfElectronRef myElectronRef(gedElectronHandle,iele);
94 
95  reco::GsfElectron newElectron(*myElectronRef);
97  isoVariables.sumChargedHadronPt = (*(isolationValueMaps)[0])[myElectronRef];
98  isoVariables.sumPhotonEt = (*(isolationValueMaps)[1])[myElectronRef];
99  isoVariables.sumNeutralHadronEt = (*(isolationValueMaps)[2])[myElectronRef];
100  isoVariables.sumPUPt = (*(isolationValueMaps)[3])[myElectronRef];
101  isoVariables.sumEcalClusterEt = (*(isolationValueMaps)[4])[myElectronRef];
102  isoVariables.sumHcalClusterEt = (*(isolationValueMaps)[5])[myElectronRef];
103 
104  newElectron.setPfIsolationVariables(isoVariables);
105 
106  // now set a status if not already done (in GEDGsfElectronProducer.cc)
107  // std::cout << " previous status " << newElectron.mvaOutput().status << std::endl;
108  if(newElectron.mvaOutput().status<=0) {
109  std::map<reco::GsfTrackRef, const reco::PFCandidate * >::const_iterator itcheck=gsfPFMap.find(newElectron.gsfTrack());
110  reco::GsfElectron::MvaOutput myMvaOutput(newElectron.mvaOutput());
111  if(itcheck!=gsfPFMap.end()) {
112  // it means that there is a PFCandidate with the same GsfTrack
113  myMvaOutput.status = 3; //as defined in PFCandidateEGammaExtra.h
114  newElectron.setPassPflowPreselection(true); //this is currently fully redundant with mvaOutput.stats so candidate for removal
115  }
116  else{
117  myMvaOutput.status = 4 ; //
118  newElectron.setPassPflowPreselection(false);//this is currently fully redundant with mvaOutput.stats so candidate for removal
119  }
120  newElectron.setMvaOutput(myMvaOutput);
121  }
122 
123  if( gedRegression_ ) {
124  gedRegression_->modifyObject(newElectron);
125  }
126  outputElectrons_p->push_back(newElectron);
127  }
128 
129  event.put(std::move(outputElectrons_p),outputCollectionLabel_);
130  }
131 
132 
T getParameter(std::string const &) const
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:186
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:646
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:696
void setMvaOutput(const MvaOutput &mo)
Definition: GsfElectron.h:698
unique_ptr< JetDefinition::Plugin > plugin
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:641
GEDGsfElectronFinalizer(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float sumNeutralHadronEt
sum pt of neutral hadrons // old float neutralHadronIso ;
Definition: GsfElectron.h:640
ParameterSet const & getParameterSet(std::string const &) const
const MvaOutput & mvaOutput() const
Definition: GsfElectron.h:693
fixed size matrix
void setPassPflowPreselection(bool flag)
Definition: GsfElectron.h:728
void produce(edm::Event &, const edm::EventSetup &) override
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:639
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
Definition: event.py:1