Imperial Analysis
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ICPhotonProducer.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/Photon.h"
13 #include "DataFormats/PatCandidates/interface/Photon.h"
14 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
15 #include "RecoEgamma/EgammaTools/interface/ConversionTools.h"
18 
19 ICPhotonProducer::IsoTags::IsoTags(edm::ParameterSet const& pset, edm::ConsumesCollector && collector)
20  : charged_all(pset.getParameter<edm::InputTag>("chargedAll")),
21  charged(pset.getParameter<edm::InputTag>("charged")),
22  neutral(pset.getParameter<edm::InputTag>("neutral")),
23  gamma(pset.getParameter<edm::InputTag>("gamma")),
24  pu(pset.getParameter<edm::InputTag>("pu")) {
25  collector.consumes<edm::ValueMap<double>>(charged_all);
26  collector.consumes<edm::ValueMap<double>>(charged);
27  collector.consumes<edm::ValueMap<double>>(neutral);
28  collector.consumes<edm::ValueMap<double>>(gamma);
29  collector.consumes<edm::ValueMap<double>>(pu);
30  }
31 
32 
33 ICPhotonProducer::ICPhotonProducer(const edm::ParameterSet& config)
34  : input_(config.getParameter<edm::InputTag>("input")),
35  branch_(config.getParameter<std::string>("branch")),
36  input_electron_veto_(
37  config.getParameter<edm::InputTag>("inputElectronVeto")),
38  do_electron_veto_(config.getParameter<bool>("includeElectronVeto")),
39  do_had_tow_over_em_(config.getParameter<bool>("includeHadTowOverEm")),
40  pf_iso_03_(config.getParameterSet("pfIso03"),consumesCollector()),
41  pf_iso_04_(config.getParameterSet("pfIso04"),consumesCollector()),
42  do_pf_iso_03_(config.getParameter<bool>("includePFIso03")),
43  do_pf_iso_04_(config.getParameter<bool>("includePFIso04")),
44  do_iso_from_pat_(config.getParameter<bool>("includeIsoFromPat")) {
45  // isolator_ = new PFIsolationEstimator();
46  // isolator_->initializePhotonIsolation(true);
47  // isolator_->setConeSize(0.3);
48  consumes<edm::View<reco::Photon>>(input_);
49  consumes<edm::View<pat::Photon>>(input_);
50  //if(do_iso_from_pat_){
51  // consumes<edm::View<pat::Photon>>(input_);
52  //} else {
53  // consumes<edm::View<reco::Photon>>(input_);
54  //}
55  consumes<edm::ValueMap<bool>>(input_electron_veto_);
56  photons_ = new std::vector<ic::Photon>();
57 
58  PrintHeaderWithProduces(config, input_, branch_);
59  PrintOptional(1, do_electron_veto_, "includeElectronVeto");
60  PrintOptional(1, do_had_tow_over_em_, "includeHadTowOverEm");
61  PrintOptional(1, do_pf_iso_03_, "includePFIso03");
62  PrintOptional(1, do_pf_iso_04_, "includePFIso04");
63  PrintOptional(1, do_iso_from_pat_, "includeIsoFromPat");
64 }
65 
67  delete photons_;
68  // delete isolator_;
69 }
70 
71 void ICPhotonProducer::produce(edm::Event& event,
72  const edm::EventSetup& setup) {
73  edm::Handle<edm::View<reco::Photon> > photons_handle;
74  event.getByLabel(input_, photons_handle);
75  edm::Handle<edm::View<pat::Photon> > pat_photons_handle;
76  if(do_iso_from_pat_)event.getByLabel(input_, pat_photons_handle);
77 
78  edm::Handle<edm::ValueMap<bool> > electron_veto_handle;
79  if (do_electron_veto_)
80  event.getByLabel(input_electron_veto_, electron_veto_handle);
81 
82  edm::Handle<edm::ValueMap<double> > charged_all_03;
83  edm::Handle<edm::ValueMap<double> > charged_03;
84  edm::Handle<edm::ValueMap<double> > neutral_03;
85  edm::Handle<edm::ValueMap<double> > gamma_03;
86  edm::Handle<edm::ValueMap<double> > pu_03;
87 
89  //std::cout<<"n photons: "<<photons_handle->size()<<std::endl;
90  //std::cout<<"pho"<<pf_iso_03_.charged_all<<std::endl;
91  if (do_pf_iso_03_&&!do_iso_from_pat_) {
92  event.getByLabel(pf_iso_03_.charged_all, charged_all_03);
93  event.getByLabel(pf_iso_03_.charged, charged_03);
94  event.getByLabel(pf_iso_03_.neutral, neutral_03);
95  event.getByLabel(pf_iso_03_.gamma, gamma_03);
96  event.getByLabel(pf_iso_03_.pu, pu_03);
97  }
98 
99  edm::Handle<edm::ValueMap<double> > charged_all_04;
100  edm::Handle<edm::ValueMap<double> > charged_04;
101  edm::Handle<edm::ValueMap<double> > neutral_04;
102  edm::Handle<edm::ValueMap<double> > gamma_04;
103  edm::Handle<edm::ValueMap<double> > pu_04;
104  if (do_pf_iso_04_&&!do_iso_from_pat_) {
105  event.getByLabel(pf_iso_04_.charged_all, charged_all_04);
106  event.getByLabel(pf_iso_04_.charged, charged_04);
107  event.getByLabel(pf_iso_04_.neutral, neutral_04);
108  event.getByLabel(pf_iso_04_.gamma, gamma_04);
109  event.getByLabel(pf_iso_04_.pu, pu_04);
110  }
111 
112  // Get other inputs
113  // Handle<reco::PFCandidateCollection> pfCandidatesH;
114  // event.getByLabel("particleFlow", pfCandidatesH);
115  // edm::Handle<reco::VertexCollection> vertexCollection;
116  // event.getByLabel("offlinePrimaryVertices", vertexCollection);
117 
118  photons_->clear();
119  photons_->resize(photons_handle->size(), ic::Photon());
120 
121  // unsigned idx = 0;
122  for (unsigned i = 0; i < photons_handle->size(); ++i) {
123  reco::Photon const& src = photons_handle->at(i);
124  edm::RefToBase<reco::Photon> ref = photons_handle->refAt(i);
125  ic::Photon & dest = photons_->at(i);
126 
127  dest.set_id(photon_hasher_(&src));
128  dest.set_pt(src.pt());
129  dest.set_eta(src.eta());
130  dest.set_phi(src.phi());
131  dest.set_energy(src.energy());
132  dest.set_charge(src.charge());
133  dest.set_sigma_IetaIeta(src.sigmaIetaIeta());
134 
135  // isolator_->fGetIsolation(&(*iter), &(*pfCandidatesH),
136  // reco::VertexRef(vertexCollection,0), vertexCollection);
137 
138  // pho.set_dr03_pfiso_charged(isolator_->getIsolationCharged());
139  // pho.set_dr03_pfiso_gamma(isolator_->getIsolationPhoton());
140  // pho.set_dr03_pfiso_neutral(isolator_->getIsolationNeutral());
141 
142  if (do_electron_veto_) {
143  dest.set_pass_electron_veto((*electron_veto_handle)[ref]);
144  }
145 
146  if (do_had_tow_over_em_) {
147  dest.set_had_tower_over_em(src.hadTowOverEm());
148  }
149 
150  if (do_pf_iso_03_&&!do_iso_from_pat_) {
151  dest.set_dr03_pfiso_charged_all((*charged_all_03)[ref]);
152  dest.set_dr03_pfiso_charged((*charged_03)[ref]);
153  dest.set_dr03_pfiso_neutral((*neutral_03)[ref]);
154  dest.set_dr03_pfiso_gamma((*gamma_03)[ref]);
155  dest.set_dr03_pfiso_pu((*pu_03)[ref]);
156  }
157 
158  if (do_pf_iso_04_&&!do_iso_from_pat_) {
159  dest.set_dr04_pfiso_charged_all((*charged_all_04)[ref]);
160  dest.set_dr04_pfiso_charged((*charged_04)[ref]);
161  dest.set_dr04_pfiso_neutral((*neutral_04)[ref]);
162  dest.set_dr04_pfiso_gamma((*gamma_04)[ref]);
163  dest.set_dr04_pfiso_pu((*pu_04)[ref]);
164  }
165 
166  if(do_pf_iso_03_&&do_iso_from_pat_&&do_pf_iso_04_){
167  throw cms::Exception("FillingTwoIsosFromOnePatIso") << "You are trying to fill both the 03 and 04 photon isolation from the single pat isolation values!!";
168  }
169 
170  if(do_pf_iso_03_&&do_iso_from_pat_) {
171  pat::Photon const& patsrc = pat_photons_handle->at(i);
172  dest.set_dr03_pfiso_charged(patsrc.chargedHadronIso());
173  dest.set_dr03_pfiso_neutral(patsrc.neutralHadronIso());
174  dest.set_dr03_pfiso_gamma(patsrc.photonIso());
175 #if CMSSW_MAJOR_VERSION >= 7 && CMSSW_MINOR_VERSION >= 0
176 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 6)
177  dest.set_dr03_pfiso_charged_all(patsrc.patParticleIso());
178 #else
179  dest.set_dr03_pfiso_charged_all(patsrc.particleIso());
180 #endif
181  dest.set_dr03_pfiso_pu(patsrc.puChargedHadronIso());
182 #endif
183  }
184 
185  if(do_pf_iso_04_&&do_iso_from_pat_) {
186  pat::Photon const& patsrc = pat_photons_handle->at(i);
187  dest.set_dr04_pfiso_charged(patsrc.chargedHadronIso());
188  dest.set_dr04_pfiso_neutral(patsrc.neutralHadronIso());
189  dest.set_dr04_pfiso_gamma(patsrc.photonIso());
190 #if CMSSW_MAJOR_VERSION >= 7 && CMSSW_MINOR_VERSION >= 0
191 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 6)
192  dest.set_dr04_pfiso_charged_all(patsrc.patParticleIso());
193 #else
194  dest.set_dr04_pfiso_charged_all(patsrc.particleIso());
195 #endif
196  dest.set_dr04_pfiso_pu(patsrc.puChargedHadronIso());
197 #endif
198  }
199 
200 
201 
202  // #ifndef CMSSW_4_2_8_patch7
203  // pho.set_had_tower_over_em(iter->hadTowOverEm());
204  // #else
205  // pho.set_had_tower_over_em(0.0);
206  // #endif
207  }
208 }
209 
210 void ICPhotonProducer::beginJob() {
211  ic::StaticTree::tree_->Branch(branch_.c_str(), &photons_);
212 }
213 
214 void ICPhotonProducer::endJob() {}
215 
216 // define this as a plug-in
void set_dr03_pfiso_gamma(float const &dr03_pfiso_gamma)
PF isolation, using photons in a cone with .
Definition: Photon.hh:86
void set_dr03_pfiso_neutral(float const &dr03_pfiso_neutral)
PF isolation, using neutral hadrons in a cone with .
Definition: Photon.hh:81
void set_dr04_pfiso_neutral(float const &dr04_pfiso_neutral)
PF isolation, using neutral hadrons in a cone with .
Definition: Photon.hh:106
void set_phi(double const &phi)
Direct access to .
Definition: Candidate.hh:75
void set_id(std::size_t const &id)
Unique identifier.
Definition: Candidate.hh:66
void set_charge(int const &charge)
Electric charge.
Definition: Candidate.hh:81
static TTree * tree_
Definition: StaticTree.hh:13
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: Photon.hh:126
void set_had_tower_over_em(float const &had_tower_over_em)
Hadronic over electromagnetic energy fraction.
Definition: Photon.hh:121
void set_dr04_pfiso_charged_all(float const &dr04_pfiso_charged_all)
PF isolation, using all charged particles in a cone with .
Definition: Photon.hh:96
void set_dr04_pfiso_gamma(float const &dr04_pfiso_gamma)
PF isolation, using photons in a cone with .
Definition: Photon.hh:111
This class stores a subset of the reco::Photon properties which are most commonly used in analysis...
Definition: Photon.hh:13
void set_dr04_pfiso_charged(float const &dr04_pfiso_charged)
PF isolation, using charged hadrons in a cone with .
Definition: Photon.hh:101
void set_pass_electron_veto(bool const &pass_electron_veto)
True if photon passes the electron veto.
Definition: Photon.hh:131
void set_energy(double const &energy)
Direct access to the energy.
Definition: Candidate.hh:78
ICPhotonProducer(const edm::ParameterSet &)
See documentation here.
void PrintOptional(unsigned depth, bool value, std::string text)
void set_dr03_pfiso_charged_all(float const &dr03_pfiso_charged_all)
PF isolation, using all charged particles in a cone with .
Definition: Photon.hh:71
void set_dr04_pfiso_pu(float const &dr04_pfiso_pu)
PF isolation, using charged pileup in a cone with .
Definition: Photon.hh:116
void set_dr03_pfiso_pu(float const &dr03_pfiso_pu)
PF isolation, using charged pileup in a cone with .
Definition: Photon.hh:91
DEFINE_FWK_MODULE(ICPhotonProducer)
Definition: Consumes.h:19
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 PrintHeaderWithProduces(edm::ParameterSet const &config, edm::InputTag const &in, std::string branch)
void set_dr03_pfiso_charged(float const &dr03_pfiso_charged)
PF isolation, using charged hadrons in a cone with .
Definition: Photon.hh:76