Imperial Analysis
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ICElectronProducer.cc
Go to the documentation of this file.
2 #include <string>
3 #include <vector>
4 #include "FWCore/Framework/interface/Event.h"
5 #include "FWCore/Framework/interface/EventSetup.h"
6 #include "FWCore/Framework/interface/MakerMacros.h"
7 #include "FWCore/ParameterSet/interface/ParameterSet.h"
8 #include "FWCore/Utilities/interface/InputTag.h"
9 #include "DataFormats/Common/interface/Handle.h"
10 #include "DataFormats/Common/interface/View.h"
11 #include "DataFormats/Common/interface/ValueMap.h"
12 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
13 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
14 #include "DataFormats/VertexReco/interface/Vertex.h"
15 #include "DataFormats/VertexReco/interface/VertexFwd.h"
16 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
22 
23 ICElectronProducer::IsoTags::IsoTags(edm::ParameterSet const& pset,edm::ConsumesCollector && collector)
24  : charged_all(pset.getParameter<edm::InputTag>("chargedAll")),
25  charged(pset.getParameter<edm::InputTag>("charged")),
26  neutral(pset.getParameter<edm::InputTag>("neutral")),
27  gamma(pset.getParameter<edm::InputTag>("gamma")),
28  pu(pset.getParameter<edm::InputTag>("pu")) {
29  collector.consumes<edm::ValueMap<double>>(charged_all);
30  collector.consumes<edm::ValueMap<double>>(charged);
31  collector.consumes<edm::ValueMap<double>>(neutral);
32  collector.consumes<edm::ValueMap<double>>(gamma);
33  collector.consumes<edm::ValueMap<double>>(pu);
34  }
35 
36 ICElectronProducer::ClusterIsoTags::ClusterIsoTags(edm::ParameterSet const& pset, edm::ConsumesCollector && collector)
37  : ecal(pset.getParameter<edm::InputTag>("ecal")),
38  hcal(pset.getParameter<edm::InputTag>("hcal")) {
39  collector.consumes<edm::ValueMap<double>>(ecal);
40  collector.consumes<edm::ValueMap<double>>(hcal);
41  }
42 
43 ICElectronProducer::ICElectronProducer(const edm::ParameterSet& config)
44  : input_(config.getParameter<edm::InputTag>("input")),
45  branch_(config.getParameter<std::string>("branch")),
46  input_r9_(config.getParameter<edm::InputTag>("inputR9")),
47  do_r9_(config.getParameter<bool>("includeR9")),
48  input_hcal_sum_(config.getParameter<edm::InputTag>("inputHcalSum")),
49  do_hcal_sum_(config.getParameter<bool>("includeHcalSum")),
50  input_vertices_(config.getParameter<edm::InputTag>("inputVertices")),
51  do_vertex_ip_(config.getParameter<bool>("includeVertexIP")),
52  input_beamspot_(config.getParameter<edm::InputTag>("inputBeamspot")),
53  do_beamspot_ip_(config.getParameter<bool>("includeBeamspotIP")),
54  input_conversion_matches_(
55  config.getParameter<edm::InputTag>("inputConversionMatches")),
56  do_conversion_matches_(
57  config.getParameter<bool>("includeConversionMatches")),
58  cluster_iso_(config.getParameterSet("clusterIso"),consumesCollector()),
59  pf_iso_03_(config.getParameterSet("pfIso03"),consumesCollector()),
60  pf_iso_04_(config.getParameterSet("pfIso04"),consumesCollector()),
61  do_cluster_iso_(config.getParameter<bool>("includeClusterIso")),
62  do_pf_iso_03_(config.getParameter<bool>("includePFIso03")),
63  do_pf_iso_04_(config.getParameter<bool>("includePFIso04")) {
64  consumes<edm::View<reco::GsfElectron>>(input_);
65  consumes<edm::ValueMap<float>>(input_r9_);
66  consumes<edm::ValueMap<float>>(input_hcal_sum_);
67  consumes<edm::View<reco::Vertex>>(input_vertices_);
68  consumes<reco::BeamSpot>(input_beamspot_);
69  consumes<edm::ValueMap<bool>>(input_conversion_matches_);
70 
71  electrons_ = new std::vector<ic::Electron>();
72 
73  edm::ParameterSet pset_floats =
74  config.getParameter<edm::ParameterSet>("includeFloats");
75  std::vector<std::string> vec =
76  pset_floats.getParameterNamesForType<edm::InputTag>();
77  for (unsigned i = 0; i < vec.size(); ++i) {
78  input_vmaps_.push_back(std::make_pair(
79  vec[i], pset_floats.getParameter<edm::InputTag>(vec[i])));
80  consumes<edm::ValueMap<float>>(input_vmaps_[i].second);
81  }
82 
83  //PrintHeaderWithProduces(config, input_, branch_);
84  PrintOptional(1, do_r9_, "includeR9");
85  PrintOptional(1, do_hcal_sum_, "includeHcalSum");
86  PrintOptional(1, do_vertex_ip_, "includeVertexIP");
87  PrintOptional(1, do_beamspot_ip_, "includeBeamspotIP");
88  PrintOptional(1, do_conversion_matches_, "includeConversionMatches");
89  PrintOptional(1, do_pf_iso_03_, "includePFIso03");
90  PrintOptional(1, do_pf_iso_04_, "includePFIso04");
91 }
92 
94 
95 void ICElectronProducer::produce(edm::Event& event,
96  const edm::EventSetup& setup) {
97  edm::Handle<edm::View<reco::GsfElectron> > elecs_handle;
98  event.getByLabel(input_, elecs_handle);
99 
100  edm::Handle<edm::ValueMap<float> > r9_handle;
101  if (do_r9_) event.getByLabel(input_r9_, r9_handle);
102 
103  edm::Handle<edm::ValueMap<float> > hcal_sum_handle;
104  if (do_hcal_sum_) event.getByLabel(input_hcal_sum_, hcal_sum_handle);
105 
106  edm::Handle<edm::ValueMap<bool> > conversion_matches_handle;
107  if (do_conversion_matches_)
108  event.getByLabel(input_conversion_matches_, conversion_matches_handle);
109 
110  edm::Handle<edm::View<reco::Vertex> > vertices_handle;
111  if (do_vertex_ip_) event.getByLabel(input_vertices_, vertices_handle);
112 
113  edm::Handle<reco::BeamSpot> beamspot_handle;
114  if (do_beamspot_ip_) event.getByLabel(input_beamspot_, beamspot_handle);
115 
116  std::vector<edm::Handle<edm::ValueMap<float> > > float_handles(
117  input_vmaps_.size());
118  for (unsigned i = 0; i < float_handles.size(); ++i) {
119  event.getByLabel(input_vmaps_[i].second, float_handles[i]);
120  }
121 
122  edm::Handle<edm::ValueMap<double> > charged_all_03;
123  edm::Handle<edm::ValueMap<double> > charged_03;
124  edm::Handle<edm::ValueMap<double> > neutral_03;
125  edm::Handle<edm::ValueMap<double> > gamma_03;
126  edm::Handle<edm::ValueMap<double> > pu_03;
127  edm::Handle<edm::ValueMap<double> > ecal_pf_cluster_iso;
128  edm::Handle<edm::ValueMap<double> > hcal_pf_cluster_iso;
129 
130  if (do_cluster_iso_){
131  event.getByLabel(cluster_iso_.ecal, ecal_pf_cluster_iso);
132  event.getByLabel(cluster_iso_.hcal, hcal_pf_cluster_iso);
133  }
134  if (do_pf_iso_03_) {
135  event.getByLabel(pf_iso_03_.charged_all, charged_all_03);
136  event.getByLabel(pf_iso_03_.charged, charged_03);
137  event.getByLabel(pf_iso_03_.neutral, neutral_03);
138  event.getByLabel(pf_iso_03_.gamma, gamma_03);
139  event.getByLabel(pf_iso_03_.pu, pu_03);
140  }
141 
142  edm::Handle<edm::ValueMap<double> > charged_all_04;
143  edm::Handle<edm::ValueMap<double> > charged_04;
144  edm::Handle<edm::ValueMap<double> > neutral_04;
145  edm::Handle<edm::ValueMap<double> > gamma_04;
146  edm::Handle<edm::ValueMap<double> > pu_04;
147  if (do_pf_iso_04_) {
148  event.getByLabel(pf_iso_04_.charged_all, charged_all_04);
149  event.getByLabel(pf_iso_04_.charged, charged_04);
150  event.getByLabel(pf_iso_04_.neutral, neutral_04);
151  event.getByLabel(pf_iso_04_.gamma, gamma_04);
152  event.getByLabel(pf_iso_04_.pu, pu_04);
153  }
154 
155  // Prepare output collection
156  electrons_->clear();
157  electrons_->resize(elecs_handle->size(), ic::Electron());
158 
159  for (unsigned i = 0; i < elecs_handle->size(); ++i) {
160  reco::GsfElectron const& src = elecs_handle->at(i);
161  edm::RefToBase<reco::GsfElectron> ref = elecs_handle->refAt(i);
162  ic::Electron & dest = electrons_->at(i);
163  dest.set_id(gsf_electron_hasher_(&src));
164  dest.set_pt(src.pt());
165  dest.set_eta(src.eta());
166  dest.set_phi(src.phi());
167  dest.set_energy(src.energy());
168  dest.set_charge(src.charge());
169  dest.set_dr03_tk_sum_pt(src.dr03TkSumPt());
170  dest.set_dr03_ecal_rechit_sum_et(src.dr03EcalRecHitSumEt());
171  dest.set_dr03_hcal_tower_sum_et(src.dr03HcalTowerSumEt());
172 
173  dest.set_hadronic_over_em(src.hadronicOverEm());
174  dest.set_sigma_IetaIeta(src.sigmaIetaIeta());
175 #if CMSSW_MAJOR_VERSION >7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 1)
176  dest.set_full5x5_sigma_IetaIeta(src.full5x5_sigmaIetaIeta());
177 #endif
178  dest.set_dphi_sc_tk_at_vtx(src.deltaPhiSuperClusterTrackAtVtx());
179  dest.set_deta_sc_tk_at_vtx(src.deltaEtaSuperClusterTrackAtVtx());
180  if (src.gsfTrack().isNonnull()) {
181 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 2)
182  dest.set_gsf_tk_nhits(
183  src.gsfTrack()->hitPattern().numberOfHits(
184  reco::HitPattern::MISSING_INNER_HITS));
185 #else
186  dest.set_gsf_tk_nhits(
187  src.gsfTrack()->trackerExpectedHitsInner().numberOfHits());
188 #endif
189  }
190  dest.set_conv_dist(src.convDist());
191  dest.set_conv_dcot(src.convDcot());
192  dest.set_f_brem(src.fbrem());
193  if (src.superCluster().isNonnull()) {
194  dest.set_sc_eta(src.superCluster()->eta());
195  dest.set_sc_theta(src.superCluster()->position().theta());
196  dest.set_sc_energy(src.superCluster()->energy());
197  dest.set_sc_e_over_p(src.eSuperClusterOverP());
198  }
199  dest.set_ecal_energy(src.ecalEnergy());
200  dest.set_vx(src.vx());
201  dest.set_vy(src.vy());
202  dest.set_vz(src.vz());
203 
204  if (do_r9_) {
205  dest.set_r9((*r9_handle)[ref]);
206  }
207  if (do_hcal_sum_) {
208  dest.set_hcal_sum((*hcal_sum_handle)[ref]);
209  }
210  if (do_conversion_matches_) {
211  dest.set_has_matched_conversion((*conversion_matches_handle)[ref]);
212  }
213 
214  for (unsigned v = 0; v < float_handles.size(); ++v) {
215  dest.SetIdIso(input_vmaps_[v].first,
216  (*(float_handles[v]))[ref]);
217  }
218 
219  if (do_cluster_iso_) {
220  dest.set_ecal_pf_cluster_iso((*ecal_pf_cluster_iso)[ref]);
221  dest.set_hcal_pf_cluster_iso((*hcal_pf_cluster_iso)[ref]);
222  }
223 
224  if (do_pf_iso_03_) {
225  dest.set_dr03_pfiso_charged_all((*charged_all_03)[ref]);
226  dest.set_dr03_pfiso_charged((*charged_03)[ref]);
227  dest.set_dr03_pfiso_neutral((*neutral_03)[ref]);
228  dest.set_dr03_pfiso_gamma((*gamma_03)[ref]);
229  dest.set_dr03_pfiso_pu((*pu_03)[ref]);
230  }
231 
232  if (do_pf_iso_04_) {
233  dest.set_dr04_pfiso_charged_all((*charged_all_04)[ref]);
234  dest.set_dr04_pfiso_charged((*charged_04)[ref]);
235  dest.set_dr04_pfiso_neutral((*neutral_04)[ref]);
236  dest.set_dr04_pfiso_gamma((*gamma_04)[ref]);
237  dest.set_dr04_pfiso_pu((*pu_04)[ref]);
238  }
239 
240  if (do_vertex_ip_) {
241  if (vertices_handle->size() > 0) {
242  reco::Vertex const& vtx = vertices_handle->at(0);
243  dest.set_dz_vertex(src.gsfTrack()->dz(vtx.position()));
244  dest.set_dxy_vertex(src.gsfTrack()->dxy(vtx.position()));
245  }
246  }
247  if (do_beamspot_ip_) {
248  dest.set_dxy_beamspot(src.gsfTrack()->dxy(*beamspot_handle));
249  }
250 
251  if (src.superCluster()->seed().isNonnull()) {
252  dest.set_sc_seed_eta(src.superCluster()->seed()->eta());
253  }
254 
255  }
256 }
257 
258 void ICElectronProducer::beginJob() {
259  ic::StaticTree::tree_->Branch(branch_.c_str(), &electrons_);
260 }
261 
262 void ICElectronProducer::endJob() {
263 }
264 
265 // define this as a plug-in
void set_full5x5_sigma_IetaIeta(float const &full5x5_sigma_IetaIeta)
Weighted cluster RMS in the -direction, measured in units of crystals in a 5x5 block centred on the s...
Definition: Electron.hh:285
void set_vz(double const &z)
The z-coordinate of the ref_point()
Definition: Electron.hh:360
void set_has_matched_conversion(bool const &has_matched_conversion)
True if electron is matched to a conversion vertex.
Definition: Electron.hh:349
void set_dphi_sc_tk_at_vtx(float const &dphi_sc_tk_at_vtx)
between the supercluster and track, where the latter is evaluated from the vertex position ...
Definition: Electron.hh:296
void set_dz_vertex(double const &dz_vertex)
Longitudinal impact parameter of the GSF track with the primary vertex.
Definition: Electron.hh:368
void set_hcal_pf_cluster_iso(float const &hcal_pf_cluster_iso)
HCAL PF cluster isolation.
Definition: Electron.hh:225
void set_hcal_sum(float const &hcal_sum)
Calorimeter tower isolation sum.
Definition: Electron.hh:341
void set_dr03_pfiso_pu(float const &dr03_pfiso_pu)
PF isolation, using charged pileup in a cone with .
Definition: Electron.hh:250
void set_dr04_pfiso_charged_all(float const &dr04_pfiso_charged_all)
PF isolation, using all charged particles in a cone with .
Definition: Electron.hh:255
void set_deta_sc_tk_at_vtx(float const &deta_sc_tk_at_vtx)
between the supercluster and track, where the latter is evaluated from the vertex position ...
Definition: Electron.hh:301
This class stores a subset of the reco::GsfElectron properties which are most commonly used in analys...
Definition: Electron.hh:26
void SetIdIso(std::string const &name, float const &value)
Add a new entry, overwriting any existing one with the same name.
Definition: Electron.cc:48
void set_sc_theta(float const &sc_theta)
Supercluster .
Definition: Electron.hh:327
void set_dr03_pfiso_charged(float const &dr03_pfiso_charged)
PF isolation, using charged hadrons in a cone with .
Definition: Electron.hh:235
void set_phi(double const &phi)
Direct access to .
Definition: Candidate.hh:75
void set_sc_energy(float const &sc_energy)
Supercluster energy.
Definition: Electron.hh:330
void set_dr03_pfiso_gamma(float const &dr03_pfiso_gamma)
PF isolation, using photons in a cone with .
Definition: Electron.hh:245
void set_id(std::size_t const &id)
Unique identifier.
Definition: Candidate.hh:66
void set_dr04_pfiso_pu(float const &dr04_pfiso_pu)
PF isolation, using charged pileup in a cone with .
Definition: Electron.hh:275
void set_dr04_pfiso_charged(float const &dr04_pfiso_charged)
PF isolation, using charged hadrons in a cone with .
Definition: Electron.hh:260
DEFINE_FWK_MODULE(ICElectronProducer)
void set_charge(int const &charge)
Electric charge.
Definition: Candidate.hh:81
void set_sc_eta(float const &sc_eta)
Supercluster .
Definition: Electron.hh:321
void set_ecal_pf_cluster_iso(float const &ecal_pf_cluster_iso)
ECAL PF cluster isolation.
Definition: Electron.hh:220
void set_f_brem(float const &f_brem)
Fraction of momentum lost as bremsstrahlung, as measured in the GSF fit.
Definition: Electron.hh:318
static TTree * tree_
Definition: StaticTree.hh:13
void set_sc_seed_eta(float const &sc_seed_eta)
Supercluster seed .
Definition: Electron.hh:324
void set_vx(double const &x)
The x-coordinate of the ref_point()
Definition: Electron.hh:354
void set_dr03_hcal_tower_sum_et(float const &dr03_hcal_tower_sum_et)
HCAL isolation in a cone with .
Definition: Electron.hh:215
void set_dr03_pfiso_charged_all(float const &dr03_pfiso_charged_all)
PF isolation, using all charged particles in a cone with .
Definition: Electron.hh:230
void set_dr04_pfiso_gamma(float const &dr04_pfiso_gamma)
PF isolation, using photons in a cone with .
Definition: Electron.hh:270
void set_conv_dist(float const &conv_dist)
Minimum distance between conversion tracks (if found)
Definition: Electron.hh:312
void set_dr03_tk_sum_pt(float const &dr03_tk_sum_pt)
Tracker isolation in a cone with .
Definition: Electron.hh:204
void set_dxy_beamspot(double const &dxy_beamspot)
Transverse impact parameter of the GSF track with the beamspot.
Definition: Electron.hh:371
void set_energy(double const &energy)
Direct access to the energy.
Definition: Candidate.hh:78
void set_hadronic_over_em(float const &hadronic_over_em)
Ratio of HCAL to supercluster energy in the region of the electron hit.
Definition: Electron.hh:280
void set_gsf_tk_nhits(int const &gsf_tk_nhits)
Number of tracker layers between the vertex and the first detected hit the electron should have trave...
Definition: Electron.hh:306
void PrintOptional(unsigned depth, bool value, std::string text)
void set_sigma_IetaIeta(float const &sigma_IetaIeta)
Weighted cluster RMS in the -direction, measured in units of crystals in a 5x5 block centred on the s...
Definition: Electron.hh:291
void set_r9(float const &r9)
The ratio of the energy in the 3x3 crystal array centred on the seed over the energy of the complete ...
Definition: Electron.hh:338
ICElectronProducer(const edm::ParameterSet &)
Definition: Consumes.h:19
void set_vy(double const &y)
The y-coordinate of the ref_point()
Definition: Electron.hh:357
edm::ConsumesCollector consumesCollector()
Definition: Consumes.cc:4
void set_pt(double const &pt)
Direct access to the .
Definition: Candidate.hh:69
void set_eta(double const &eta)
Direct access to .
Definition: Candidate.hh:72
void set_dr03_pfiso_neutral(float const &dr03_pfiso_neutral)
PF isolation, using neutral hadrons in a cone with .
Definition: Electron.hh:240
void set_conv_dcot(float const &conv_dcot)
between conversion tracks at the conversion vertex
Definition: Electron.hh:315
void set_ecal_energy(float const &ecal_energy)
The corrected supercluster energy.
Definition: Electron.hh:344
See documentation here.
void set_dr03_ecal_rechit_sum_et(float const &dr03_ecal_rechit_sum_et)
ECAL isolation in a cone with .
Definition: Electron.hh:209
void set_dr04_pfiso_neutral(float const &dr04_pfiso_neutral)
PF isolation, using neutral hadrons in a cone with .
Definition: Electron.hh:265
void set_dxy_vertex(double const &dxy_vertex)
Transverse impact parameter of the GSF track with the primary vertex.
Definition: Electron.hh:363
void set_sc_e_over_p(float const &sc_e_over_p)
Ratio of supercluster energy to track momentum, where the latter is evaluated at the PCA to the beams...
Definition: Electron.hh:333