CMS 3D CMS Logo

GEDGsfElectronFinalizer.cc
Go to the documentation of this file.
11 
13 public:
15 
16  void produce(edm::Event&, const edm::EventSetup&) override;
17 
18 private:
21  std::vector<edm::EDGetTokenT<edm::ValueMap<float> > > tokenElectronIsoVals_;
22  std::unique_ptr<ModifyObjectValueBase> gedRegression_;
23 
25 };
26 
27 using edm::InputTag;
28 using edm::ValueMap;
29 
31 
33  : previousGsfElectrons_(consumes<GsfElectronCollection>(cfg.getParameter<InputTag>("previousGsfElectronsTag"))),
34  pfCandidates_(consumes<reco::PFCandidateCollection>(cfg.getParameter<InputTag>("pfCandidatesTag"))),
35  putToken_{produces<reco::GsfElectronCollection>()} {
36  edm::ParameterSet pfIsoVals(cfg.getParameter<edm::ParameterSet>("pfIsolationValues"));
37 
38  tokenElectronIsoVals_ = {consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumChargedHadronPt")),
39  consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumPhotonEt")),
40  consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumNeutralHadronEt")),
41  consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumPUPt")),
42  consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumEcalClusterEt")),
43  consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumHcalClusterEt"))};
44 
45  if (cfg.existsAs<edm::ParameterSet>("regressionConfig")) {
46  auto const& iconf = cfg.getParameterSet("regressionConfig");
47  auto const& mname = iconf.getParameter<std::string>("modifierName");
48  auto cc = consumesCollector();
49  gedRegression_ = ModifyObjectValueFactory::get()->create(mname, iconf, cc);
50  }
51 }
52 
54  // Output collection
55  reco::GsfElectronCollection outputElectrons;
56 
57  if (gedRegression_) {
58  gedRegression_->setEvent(event);
59  gedRegression_->setEventContent(setup);
60  }
61 
62  // read input collections
63  // electrons
64  auto gedElectronHandle = event.getHandle(previousGsfElectrons_);
65 
66  // PFCandidates
67  auto pfCandidateHandle = event.getHandle(pfCandidates_);
68  // value maps
69  std::vector<edm::ValueMap<float> const*> isolationValueMaps(tokenElectronIsoVals_.size());
70 
71  for (unsigned i = 0; i < tokenElectronIsoVals_.size(); ++i) {
72  isolationValueMaps[i] = &event.get(tokenElectronIsoVals_[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  for (auto const& pfCand : *pfCandidateHandle) {
78  // First check that the GsfTrack is non null
79  if (pfCand.gsfTrackRef().isNonnull()) {
80  if (abs(pfCand.pdgId()) == 11) // consider only the electrons
81  gsfPFMap[pfCand.gsfTrackRef()] = &pfCand;
82  }
83  }
84 
85  // Now loop on the electrons
86  unsigned nele = gedElectronHandle->size();
87  for (unsigned iele = 0; iele < nele; ++iele) {
88  reco::GsfElectronRef myElectronRef(gedElectronHandle, iele);
89 
90  reco::GsfElectron newElectron(*myElectronRef);
92  isoVariables.sumChargedHadronPt = (*(isolationValueMaps)[0])[myElectronRef];
93  isoVariables.sumPhotonEt = (*(isolationValueMaps)[1])[myElectronRef];
94  isoVariables.sumNeutralHadronEt = (*(isolationValueMaps)[2])[myElectronRef];
95  isoVariables.sumPUPt = (*(isolationValueMaps)[3])[myElectronRef];
96  isoVariables.sumEcalClusterEt = (*(isolationValueMaps)[4])[myElectronRef];
97  isoVariables.sumHcalClusterEt = (*(isolationValueMaps)[5])[myElectronRef];
98 
99  newElectron.setPfIsolationVariables(isoVariables);
100 
101  // now set a status if not already done (in GEDGsfElectronProducer.cc)
102  // std::cout << " previous status " << newElectron.mvaOutput().status << std::endl;
103  if (newElectron.mvaOutput().status <= 0) {
104  reco::GsfElectron::MvaOutput myMvaOutput(newElectron.mvaOutput());
105  if (gsfPFMap.find(newElectron.gsfTrack()) != gsfPFMap.end()) {
106  // it means that there is a PFCandidate with the same GsfTrack
107  myMvaOutput.status = 3; //as defined in PFCandidateEGammaExtra.h
108  //this is currently fully redundant with mvaOutput.stats so candidate for removal
109  newElectron.setPassPflowPreselection(true);
110  } else {
111  myMvaOutput.status = 4; //
112  //this is currently fully redundant with mvaOutput.stats so candidate for removal
113  newElectron.setPassPflowPreselection(false);
114  }
115  newElectron.setMvaOutput(myMvaOutput);
116  }
117 
118  if (gedRegression_) {
119  gedRegression_->modifyObject(newElectron);
120  }
121  outputElectrons.push_back(newElectron);
122  }
123 
124  event.emplace(putToken_, std::move(outputElectrons));
125 }
126 
std::unique_ptr< ModifyObjectValueBase > gedRegression_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:670
const MvaOutput & mvaOutput() const
Definition: GsfElectron.h:735
std::vector< edm::EDGetTokenT< edm::ValueMap< float > > > tokenElectronIsoVals_
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:738
void setMvaOutput(const MvaOutput &mo)
Definition: GsfElectron.h:740
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:156
const edm::EDGetTokenT< reco::GsfElectronCollection > previousGsfElectrons_
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:665
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:664
const edm::EDPutTokenT< reco::GsfElectronCollection > putToken_
const edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidates_
fixed size matrix
void setPassPflowPreselection(bool flag)
Definition: GsfElectron.h:771
void produce(edm::Event &, const edm::EventSetup &) override
#define get
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:663
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1