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");
37  ModifyObjectValueFactory::get()->create(mname,iconf);
38  gedRegression_.reset(plugin);
39  edm::ConsumesCollector sumes = consumesCollector();
40  gedRegression_->setConsumes(sumes);
41  } else {
42  gedRegression_.reset(nullptr);
43  }
44 
45  produces<reco::GsfElectronCollection> (outputCollectionLabel_);
46 }
47 
49  {}
50 
51 // ------------ method called to produce the data ------------
53  {
54 
55  // Output collection
56  auto outputElectrons_p = std::make_unique<reco::GsfElectronCollection>();
57 
58  if( gedRegression_ ) {
59  gedRegression_->setEvent(event);
60  gedRegression_->setEventContent(setup);
61  }
62 
63  // read input collections
64  // electrons
66  event.getByToken(previousGsfElectrons_,gedElectronHandle);
67 
68  // PFCandidates
70  event.getByToken(pfCandidates_,pfCandidateHandle);
71  // value maps
72  std::vector< edm::Handle< edm::ValueMap<float> > > isolationValueMaps(nDeps_);
73 
74  for(unsigned i=0; i < nDeps_ ; ++i) {
75  event.getByToken(tokenElectronIsoVals_[i],isolationValueMaps[i]);
76  }
77 
78  // prepare a map of PFCandidates having a valid GsfTrackRef to save time
79  std::map<reco::GsfTrackRef, const reco::PFCandidate* > gsfPFMap;
80  reco::PFCandidateCollection::const_iterator it = pfCandidateHandle->begin();
81  reco::PFCandidateCollection::const_iterator itend = pfCandidateHandle->end() ;
82  for(;it!=itend;++it) {
83  // First check that the GsfTrack is non null
84  if( it->gsfTrackRef().isNonnull()) {
85  if(abs(it->pdgId())==11) // consider only the electrons
86  gsfPFMap[it->gsfTrackRef()]=&(*it);
87  }
88  }
89 
90 
91  // Now loop on the electrons
92  unsigned nele=gedElectronHandle->size();
93  for(unsigned iele=0; iele<nele;++iele) {
94  reco::GsfElectronRef myElectronRef(gedElectronHandle,iele);
95 
96  reco::GsfElectron newElectron(*myElectronRef);
98  isoVariables.sumChargedHadronPt = (*(isolationValueMaps)[0])[myElectronRef];
99  isoVariables.sumPhotonEt = (*(isolationValueMaps)[1])[myElectronRef];
100  isoVariables.sumNeutralHadronEt = (*(isolationValueMaps)[2])[myElectronRef];
101  isoVariables.sumPUPt = (*(isolationValueMaps)[3])[myElectronRef];
102  isoVariables.sumEcalClusterEt = (*(isolationValueMaps)[4])[myElectronRef];
103  isoVariables.sumHcalClusterEt = (*(isolationValueMaps)[5])[myElectronRef];
104 
105  newElectron.setPfIsolationVariables(isoVariables);
106 
107  // now set a status if not already done (in GEDGsfElectronProducer.cc)
108  // std::cout << " previous status " << newElectron.mvaOutput().status << std::endl;
109  if(newElectron.mvaOutput().status<=0) {
110  std::map<reco::GsfTrackRef, const reco::PFCandidate * >::const_iterator itcheck=gsfPFMap.find(newElectron.gsfTrack());
111  reco::GsfElectron::MvaOutput myMvaOutput(newElectron.mvaOutput());
112  if(itcheck!=gsfPFMap.end()) {
113  // it means that there is a PFCandidate with the same GsfTrack
114  myMvaOutput.status = 3; //as defined in PFCandidateEGammaExtra.h
115  newElectron.setPassPflowPreselection(true); //this is currently fully redundant with mvaOutput.stats so candidate for removal
116  }
117  else{
118  myMvaOutput.status = 4 ; //
119  newElectron.setPassPflowPreselection(false);//this is currently fully redundant with mvaOutput.stats so candidate for removal
120  }
121  newElectron.setMvaOutput(myMvaOutput);
122  }
123 
124  if( gedRegression_ ) {
125  gedRegression_->modifyObject(newElectron);
126  }
127  outputElectrons_p->push_back(newElectron);
128  }
129 
130  event.put(std::move(outputElectrons_p),outputCollectionLabel_);
131  }
132 
133 
T getParameter(std::string const &) const
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Definition: GsfElectron.h:185
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
auto_ptr< JetDefinition::Plugin > plugin
float sumPUPt
sum pt of charged Particles not from PV (for Pu corrections)
Definition: GsfElectron.h:636
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:686
void setMvaOutput(const MvaOutput &mo)
Definition: GsfElectron.h:688
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:631
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:630
ParameterSet const & getParameterSet(std::string const &) const
const MvaOutput & mvaOutput() const
Definition: GsfElectron.h:683
fixed size matrix
void setPassPflowPreselection(bool flag)
Definition: GsfElectron.h:718
void produce(edm::Event &, const edm::EventSetup &) override
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:629
def move(src, dest)
Definition: eostools.py:510
T get(const Candidate &c)
Definition: component.h:55
Definition: event.py:1