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  {
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<double> >(pfIsoVals.getParameter<edm::InputTag>("pfSumChargedHadronPt")));
25  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<double> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPhotonEt")));
26  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<double> >(pfIsoVals.getParameter<edm::InputTag>("pfSumNeutralHadronEt")));
27  tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<double> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPUPt")));
28 // std::vector<std::string> isoNames = pfIsoVals.getParameterNamesForType<edm::InputTag>();
29 // for(const std::string& name : isoNames) {
30 // edm::InputTag tag =
31 // pfIsoVals.getParameter<edm::InputTag>(name);
32 // tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<double> >(tag));
33 // }
34 
35  nDeps_ = tokenElectronIsoVals_.size();
36 
37  if( cfg.existsAs<edm::ParameterSet>("regressionConfig") ) {
38  const edm::ParameterSet& iconf = cfg.getParameterSet("regressionConfig");
39  const std::string& mname = iconf.getParameter<std::string>("modifierName");
41  ModifyObjectValueFactory::get()->create(mname,iconf);
42  gedRegression_.reset(plugin);
43  edm::ConsumesCollector sumes = consumesCollector();
44  gedRegression_->setConsumes(sumes);
45  } else {
46  gedRegression_.reset(nullptr);
47  }
48 
49  produces<reco::GsfElectronCollection> (outputCollectionLabel_);
50 }
51 
53  {}
54 
55 // ------------ method called to produce the data ------------
57  {
58 
59  // Output collection
60  std::auto_ptr<reco::GsfElectronCollection> outputElectrons_p(new reco::GsfElectronCollection);
61 
62  if( gedRegression_ ) {
63  gedRegression_->setEvent(event);
64  gedRegression_->setEventContent(setup);
65  }
66 
67  // read input collections
68  // electrons
70  event.getByToken(previousGsfElectrons_,gedElectronHandle);
71 
72  // PFCandidates
74  event.getByToken(pfCandidates_,pfCandidateHandle);
75  // value maps
76  std::vector< edm::Handle< edm::ValueMap<double> > > isolationValueMaps(nDeps_);
77 
78  for(unsigned i=0; i < nDeps_ ; ++i) {
79  event.getByToken(tokenElectronIsoVals_[i],isolationValueMaps[i]);
80  }
81 
82  // prepare a map of PFCandidates having a valid GsfTrackRef to save time
83  std::map<reco::GsfTrackRef, const reco::PFCandidate* > gsfPFMap;
84  reco::PFCandidateCollection::const_iterator it = pfCandidateHandle->begin();
85  reco::PFCandidateCollection::const_iterator itend = pfCandidateHandle->end() ;
86  for(;it!=itend;++it) {
87  // First check that the GsfTrack is non null
88  if( it->gsfTrackRef().isNonnull()) {
89  if(abs(it->pdgId())==11) // consider only the electrons
90  gsfPFMap[it->gsfTrackRef()]=&(*it);
91  }
92  }
93 
94 
95  // Now loop on the electrons
96  unsigned nele=gedElectronHandle->size();
97  for(unsigned iele=0; iele<nele;++iele) {
98  reco::GsfElectronRef myElectronRef(gedElectronHandle,iele);
99 
100  reco::GsfElectron newElectron(*myElectronRef);
102  isoVariables.sumChargedHadronPt = (*(isolationValueMaps)[0])[myElectronRef];
103  isoVariables.sumPhotonEt = (*(isolationValueMaps)[1])[myElectronRef];
104  isoVariables.sumNeutralHadronEt = (*(isolationValueMaps)[2])[myElectronRef];
105  isoVariables.sumPUPt = (*(isolationValueMaps)[3])[myElectronRef];
106  newElectron.setPfIsolationVariables(isoVariables);
107 
108  // now set a status if not already done (in GEDGsfElectronProducer.cc)
109  // std::cout << " previous status " << newElectron.mvaOutput().status << std::endl;
110  if(newElectron.mvaOutput().status<=0) {
111  std::map<reco::GsfTrackRef, const reco::PFCandidate * >::const_iterator itcheck=gsfPFMap.find(newElectron.gsfTrack());
112  reco::GsfElectron::MvaOutput myMvaOutput(newElectron.mvaOutput());
113  if(itcheck!=gsfPFMap.end()) {
114  // it means that there is a PFCandidate with the same GsfTrack
115  myMvaOutput.status = 3; //as defined in PFCandidateEGammaExtra.h
116  newElectron.setPassPflowPreselection(true); //this is currently fully redundant with mvaOutput.stats so candidate for removal
117  }
118  else{
119  myMvaOutput.status = 4 ; //
120  newElectron.setPassPflowPreselection(false);//this is currently fully redundant with mvaOutput.stats so candidate for removal
121  }
122  newElectron.setMvaOutput(myMvaOutput);
123  }
124 
125  if( gedRegression_ ) {
126  gedRegression_->modifyObject(newElectron);
127  }
128  outputElectrons_p->push_back(newElectron);
129  }
130 
131  event.put(outputElectrons_p,outputCollectionLabel_);
132  }
133 
134 
virtual void produce(edm::Event &, const edm::EventSetup &)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
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:580
void setPfIsolationVariables(const PflowIsolationVariables &iso)
Definition: GsfElectron.h:623
void setMvaOutput(const MvaOutput &mo)
Definition: GsfElectron.h:625
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
float sumPhotonEt
sum pt of PF photons // old float photonIso ;
Definition: GsfElectron.h:575
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:574
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
ParameterSet const & getParameterSet(std::string const &) const
const MvaOutput & mvaOutput() const
Definition: GsfElectron.h:620
void setPassPflowPreselection(bool flag)
Definition: GsfElectron.h:655
float sumChargedHadronPt
sum-pt of charged Hadron // old float chargedHadronIso ;
Definition: GsfElectron.h:573
T get(const Candidate &c)
Definition: component.h:55
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:183