CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  previousGsfElectrons_ =
19  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(
25  consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumChargedHadronPt")));
26  tokenElectronIsoVals_.push_back(
27  consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPhotonEt")));
28  tokenElectronIsoVals_.push_back(
29  consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumNeutralHadronEt")));
30  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPUPt")));
31  tokenElectronIsoVals_.push_back(
32  consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumEcalClusterEt")));
33  tokenElectronIsoVals_.push_back(
34  consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumHcalClusterEt")));
35 
36  nDeps_ = tokenElectronIsoVals_.size();
37 
38  if (cfg.existsAs<edm::ParameterSet>("regressionConfig")) {
39  const edm::ParameterSet& iconf = cfg.getParameterSet("regressionConfig");
40  const std::string& mname = iconf.getParameter<std::string>("modifierName");
41  auto cc = consumesCollector();
42  gedRegression_ = ModifyObjectValueFactory::get()->create(mname, iconf, cc);
43  }
44 
45  produces<reco::GsfElectronCollection>(outputCollectionLabel_);
46 }
47 
49 
50 // ------------ method called to produce the data ------------
52  // Output collection
53  auto outputElectrons_p = std::make_unique<reco::GsfElectronCollection>();
54 
55  if (gedRegression_) {
56  gedRegression_->setEvent(event);
57  gedRegression_->setEventContent(setup);
58  }
59 
60  // read input collections
61  // electrons
63  event.getByToken(previousGsfElectrons_, gedElectronHandle);
64 
65  // PFCandidates
67  event.getByToken(pfCandidates_, pfCandidateHandle);
68  // value maps
69  std::vector<edm::Handle<edm::ValueMap<float> > > isolationValueMaps(nDeps_);
70 
71  for (unsigned i = 0; i < nDeps_; ++i) {
72  event.getByToken(tokenElectronIsoVals_[i], isolationValueMaps[i]);
73  }
74 
75  // prepare a map of PFCandidates having a valid GsfTrackRef to save time
76  std::map<reco::GsfTrackRef, const reco::PFCandidate*> gsfPFMap;
77  reco::PFCandidateCollection::const_iterator it = pfCandidateHandle->begin();
78  reco::PFCandidateCollection::const_iterator itend = pfCandidateHandle->end();
79  for (; it != itend; ++it) {
80  // First check that the GsfTrack is non null
81  if (it->gsfTrackRef().isNonnull()) {
82  if (abs(it->pdgId()) == 11) // consider only the electrons
83  gsfPFMap[it->gsfTrackRef()] = &(*it);
84  }
85  }
86 
87  // Now loop on the electrons
88  unsigned nele = gedElectronHandle->size();
89  for (unsigned iele = 0; iele < nele; ++iele) {
90  reco::GsfElectronRef myElectronRef(gedElectronHandle, iele);
91 
92  reco::GsfElectron newElectron(*myElectronRef);
94  isoVariables.sumChargedHadronPt = (*(isolationValueMaps)[0])[myElectronRef];
95  isoVariables.sumPhotonEt = (*(isolationValueMaps)[1])[myElectronRef];
96  isoVariables.sumNeutralHadronEt = (*(isolationValueMaps)[2])[myElectronRef];
97  isoVariables.sumPUPt = (*(isolationValueMaps)[3])[myElectronRef];
98  isoVariables.sumEcalClusterEt = (*(isolationValueMaps)[4])[myElectronRef];
99  isoVariables.sumHcalClusterEt = (*(isolationValueMaps)[5])[myElectronRef];
100 
101  newElectron.setPfIsolationVariables(isoVariables);
102 
103  // now set a status if not already done (in GEDGsfElectronProducer.cc)
104  // std::cout << " previous status " << newElectron.mvaOutput().status << std::endl;
105  if (newElectron.mvaOutput().status <= 0) {
106  std::map<reco::GsfTrackRef, const reco::PFCandidate*>::const_iterator itcheck =
107  gsfPFMap.find(newElectron.gsfTrack());
108  reco::GsfElectron::MvaOutput myMvaOutput(newElectron.mvaOutput());
109  if (itcheck != gsfPFMap.end()) {
110  // it means that there is a PFCandidate with the same GsfTrack
111  myMvaOutput.status = 3; //as defined in PFCandidateEGammaExtra.h
112  //this is currently fully redundant with mvaOutput.stats so candidate for removal
113  newElectron.setPassPflowPreselection(true);
114  } else {
115  myMvaOutput.status = 4; //
116  //this is currently fully redundant with mvaOutput.stats so candidate for removal
117  newElectron.setPassPflowPreselection(false);
118  }
119  newElectron.setMvaOutput(myMvaOutput);
120  }
121 
122  if (gedRegression_) {
123  gedRegression_->modifyObject(newElectron);
124  }
125  outputElectrons_p->push_back(newElectron);
126  }
127 
128  event.put(std::move(outputElectrons_p), outputCollectionLabel_);
129 }
T getParameter(std::string const &) const
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:607
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:659
void setMvaOutput(const MvaOutput &mo)
Definition: GsfElectron.h:661
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:602
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:601
ParameterSet const & getParameterSet(std::string const &) const
const MvaOutput & mvaOutput() const
Definition: GsfElectron.h:656
fixed size matrix
void setPassPflowPreselection(bool flag)
Definition: GsfElectron.h:688
void produce(edm::Event &, const edm::EventSetup &) override
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:600
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1