Imperial Analysis
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ICMuonProducer.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/VertexReco/interface/Vertex.h"
13 #include "DataFormats/VertexReco/interface/VertexFwd.h"
14 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
20 #include "DataFormats/MuonReco/interface/Muon.h"
21 #include "DataFormats/MuonReco/interface/MuonFwd.h"
22 #include "DataFormats/PatCandidates/interface/Muon.h"
23 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
24 
25 
26 ICMuonProducer::IsoTags::IsoTags(edm::ParameterSet const& pset, edm::ConsumesCollector && collector)
27  : charged_all(pset.getParameter<edm::InputTag>("chargedAll")),
28  charged(pset.getParameter<edm::InputTag>("charged")),
29  neutral(pset.getParameter<edm::InputTag>("neutral")),
30  gamma(pset.getParameter<edm::InputTag>("gamma")),
31  pu(pset.getParameter<edm::InputTag>("pu")) {
32  collector.consumes<edm::ValueMap<double>>(charged_all);
33  collector.consumes<edm::ValueMap<double>>(charged);
34  collector.consumes<edm::ValueMap<double>>(neutral);
35  collector.consumes<edm::ValueMap<double>>(gamma);
36  collector.consumes<edm::ValueMap<double>>(pu);
37  }
38 
39 ICMuonProducer::ICMuonProducer(const edm::ParameterSet& config)
40  : input_(config.getParameter<edm::InputTag>("input")),
41  branch_(config.getParameter<std::string>("branch")),
42  is_pf_(config.getParameter<bool>("isPF")),
43  input_vertices_(config.getParameter<edm::InputTag>("inputVertices")),
44  do_vertex_ip_(config.getParameter<bool>("includeVertexIP")),
45  input_beamspot_(config.getParameter<edm::InputTag>("inputBeamspot")),
46  do_beamspot_ip_(config.getParameter<bool>("includeBeamspotIP")),
47  pf_iso_03_(config.getParameterSet("pfIso03"),consumesCollector()),
48  pf_iso_04_(config.getParameterSet("pfIso04"),consumesCollector()),
49  do_pf_iso_03_(config.getParameter<bool>("includePFIso03")),
50  do_pf_iso_04_(config.getParameter<bool>("includePFIso04")) {
51  if(is_pf_){
52  consumes<edm::View<reco::PFCandidate>>(input_);
53  } else {
54  consumes<edm::View<reco::Muon>>(input_);
55  }
56  consumes<edm::View<reco::Vertex>>(input_vertices_);
57  consumes<reco::BeamSpot>(input_beamspot_);
58  muons_ = new std::vector<ic::Muon>();
59 
60  edm::ParameterSet pset_floats =
61  config.getParameter<edm::ParameterSet>("includeFloats");
62  std::vector<std::string> vec =
63  pset_floats.getParameterNamesForType<edm::InputTag>();
64  for (unsigned i = 0; i < vec.size(); ++i) {
65  input_vmaps_.push_back(std::make_pair(
66  vec[i], pset_floats.getParameter<edm::InputTag>(vec[i])));
67  consumes<edm::ValueMap<float>>(input_vmaps_[i].second);
68  }
69 
70  edm::ParameterSet pset_doubles =
71  config.getParameter<edm::ParameterSet>("includeDoubles");
72  std::vector<std::string> doubles_vec =
73  pset_doubles.getParameterNamesForType<edm::InputTag>();
74  for (unsigned i = 0; i < doubles_vec.size(); ++i) {
75  input_double_vmaps_.push_back(std::make_pair(
76  doubles_vec[i], pset_doubles.getParameter<edm::InputTag>(doubles_vec[i])));
77  consumes<edm::ValueMap<double>>(input_double_vmaps_[i].second);
78  }
79 
80  PrintHeaderWithProduces(config, input_, branch_);
81  PrintOptional(1, is_pf_, "isPF");
82  PrintOptional(1, do_vertex_ip_, "includeVertexIP");
83  PrintOptional(1, do_beamspot_ip_, "includeBeamspotIP");
84  PrintOptional(1, do_pf_iso_03_, "includePFIso03");
85  PrintOptional(1, do_pf_iso_04_, "includePFIso04");
86 }
87 
88 ICMuonProducer::~ICMuonProducer() { delete muons_; }
89 
90 void ICMuonProducer::produce(edm::Event& event, const edm::EventSetup& setup) {
91  edm::Handle<edm::View<reco::Muon> > muons_handle;
92  edm::Handle<edm::View<reco::PFCandidate> > pfs_handle;
93  unsigned n_muons = 0;
94  if (is_pf_) {
95  event.getByLabel(input_, pfs_handle);
96  n_muons = pfs_handle->size();
97  } else {
98  event.getByLabel(input_, muons_handle);
99  n_muons = muons_handle->size();
100  }
101 
102  edm::Handle<edm::View<reco::Vertex> > vertices_handle;
103  if (do_vertex_ip_) event.getByLabel(input_vertices_, vertices_handle);
104 
105  edm::Handle<reco::BeamSpot> beamspot_handle;
106  if (do_beamspot_ip_) event.getByLabel(input_beamspot_, beamspot_handle);
107 
108  std::vector<edm::Handle<edm::ValueMap<float> > > float_handles(
109  input_vmaps_.size());
110  for (unsigned i = 0; i < float_handles.size(); ++i) {
111  event.getByLabel(input_vmaps_[i].second, float_handles[i]);
112  }
113 
114  std::vector<edm::Handle<edm::ValueMap<double> > > double_handles(
115  input_double_vmaps_.size());
116  for (unsigned i = 0; i < double_handles.size(); ++i) {
117  event.getByLabel(input_double_vmaps_[i].second, double_handles[i]);
118  }
119 
120  edm::Handle<edm::ValueMap<double> > charged_all_03;
121  edm::Handle<edm::ValueMap<double> > charged_03;
122  edm::Handle<edm::ValueMap<double> > neutral_03;
123  edm::Handle<edm::ValueMap<double> > gamma_03;
124  edm::Handle<edm::ValueMap<double> > pu_03;
125  edm::Handle<edm::ValueMap<double> > neutral_pfw_03;
126  edm::Handle<edm::ValueMap<double> > gamma_pfw_03;
127  if (do_pf_iso_03_) {
128  event.getByLabel(pf_iso_03_.charged_all, charged_all_03);
129  event.getByLabel(pf_iso_03_.charged, charged_03);
130  event.getByLabel(pf_iso_03_.neutral, neutral_03);
131  event.getByLabel(pf_iso_03_.gamma, gamma_03);
132  event.getByLabel(pf_iso_03_.pu, pu_03);
133  }
134 
135  edm::Handle<edm::ValueMap<double> > charged_all_04;
136  edm::Handle<edm::ValueMap<double> > charged_04;
137  edm::Handle<edm::ValueMap<double> > neutral_04;
138  edm::Handle<edm::ValueMap<double> > gamma_04;
139  edm::Handle<edm::ValueMap<double> > pu_04;
140  edm::Handle<edm::ValueMap<double> > neutral_pfw_04;
141  edm::Handle<edm::ValueMap<double> > gamma_pfw_04;
142  if (do_pf_iso_04_) {
143  event.getByLabel(pf_iso_04_.charged_all, charged_all_04);
144  event.getByLabel(pf_iso_04_.charged, charged_04);
145  event.getByLabel(pf_iso_04_.neutral, neutral_04);
146  event.getByLabel(pf_iso_04_.gamma, gamma_04);
147  event.getByLabel(pf_iso_04_.pu, pu_04);
148  }
149 
150  // Prepare output collection
151  muons_->clear();
152  muons_->resize(n_muons, ic::Muon());
153 
154  for (unsigned i = 0; i < n_muons; ++i) {
155  ic::Muon & dest = muons_->at(i);
156 
157  reco::MuonRef muon_ref;
158  edm::RefToBase<reco::Muon> muon_base_ref;
159  edm::RefToBase<reco::PFCandidate> pf_base_ref;
160  if (is_pf_) {
161  reco::PFCandidate const& pf_src = pfs_handle->at(i);
162  dest.set_id(pf_hasher_(&pf_src));
163  dest.set_pt(pf_src.pt());
164  dest.set_eta(pf_src.eta());
165  dest.set_phi(pf_src.phi());
166  dest.set_energy(pf_src.energy());
167  dest.set_charge(pf_src.charge());
168  dest.set_is_pf(true);
169  muon_ref = pf_src.muonRef();
170  pf_base_ref = pfs_handle->refAt(i);
171  } else {
172  reco::Muon const& reco_src = muons_handle->at(i);
173  dest.set_id(muon_hasher_(&reco_src));
174  dest.set_pt(reco_src.pt());
175  dest.set_eta(reco_src.eta());
176  dest.set_phi(reco_src.phi());
177  dest.set_energy(reco_src.energy());
178  dest.set_charge(reco_src.charge());
179  dest.set_is_pf(reco_src.isPFMuon());
180  muon_base_ref = muons_handle->refAt(i);
181  }
182 
183  reco::Muon const& src =
184  is_pf_ ? *(pfs_handle->at(i).muonRef()) : *muons_handle->refAt(i);
185 
186  dest.set_dr03_tk_sum_pt(src.isolationR03().sumPt);
187  dest.set_dr03_ecal_rechit_sum_et(src.isolationR03().emEt);
188  dest.set_dr03_hcal_tower_sum_et(src.isolationR03().hadEt);
189 
190 
191  dest.set_is_standalone(src.isStandAloneMuon());
192  dest.set_is_global(src.isGlobalMuon());
193  dest.set_is_tracker(src.isTrackerMuon());
194  dest.set_is_calo(src.isCaloMuon());
195  dest.set_matched_stations(src.numberOfMatchedStations());
196 
197  if (src.isGlobalMuon() && src.globalTrack().isNonnull()) {
198  dest.set_gt_normalized_chi2(src.globalTrack()->normalizedChi2());
199  dest.set_cq_chi2_localposition(src.combinedQuality().chi2LocalPosition);
200  dest.set_cq_trk_kink(src.combinedQuality().trkKink);
202  src.globalTrack()->hitPattern().numberOfValidMuonHits());
203  }
204 
205  if (src.isTrackerMuon() && src.innerTrack().isNonnull()) {
206  dest.set_it_pixel_hits(
207  src.innerTrack()->hitPattern().numberOfValidPixelHits());
208  dest.set_it_tracker_hits(
209  src.innerTrack()->hitPattern().numberOfValidTrackerHits());
211  src.innerTrack()->hitPattern().trackerLayersWithMeasurement());
213  src.innerTrack()->validFraction());
214  }
215 
216  dest.set_segment_compatibility(muon::segmentCompatibility(src));
217 
218  dest.set_vx(src.vx());
219  dest.set_vy(src.vy());
220  dest.set_vz(src.vz());
221 
222  for (unsigned v = 0; v < float_handles.size(); ++v) {
223  if (is_pf_) {
224  dest.SetIdIso(input_vmaps_[v].first,
225  (*(float_handles[v]))[pf_base_ref]);
226  } else {
227  dest.SetIdIso(input_vmaps_[v].first,
228  (*(float_handles[v]))[muon_base_ref]);
229  }
230  }
231 
232  for (unsigned v = 0; v < double_handles.size(); ++v) {
233  if (is_pf_) {
234  dest.SetIdIso(input_double_vmaps_[v].first,
235  float((*(double_handles[v]))[pf_base_ref]));
236  } else {
237  dest.SetIdIso(input_double_vmaps_[v].first,
238  float((*(double_handles[v]))[muon_base_ref]));
239  }
240  }
241 
242  if (is_pf_) {
243  if (do_pf_iso_03_) {
244  dest.set_dr03_pfiso_charged_all((*charged_all_03)[pf_base_ref]);
245  dest.set_dr03_pfiso_charged((*charged_03)[pf_base_ref]);
246  dest.set_dr03_pfiso_neutral((*neutral_03)[pf_base_ref]);
247  dest.set_dr03_pfiso_gamma((*gamma_03)[pf_base_ref]);
248  dest.set_dr03_pfiso_pu((*pu_03)[pf_base_ref]);
249  }
250  if (do_pf_iso_04_) {
251  dest.set_dr04_pfiso_charged_all((*charged_all_04)[pf_base_ref]);
252  dest.set_dr04_pfiso_charged((*charged_04)[pf_base_ref]);
253  dest.set_dr04_pfiso_neutral((*neutral_04)[pf_base_ref]);
254  dest.set_dr04_pfiso_gamma((*gamma_04)[pf_base_ref]);
255  dest.set_dr04_pfiso_pu((*pu_04)[pf_base_ref]);
256  }
257  } else {
258  if (do_pf_iso_03_) {
259  dest.set_dr03_pfiso_charged_all((*charged_all_03)[muon_base_ref]);
260  dest.set_dr03_pfiso_charged((*charged_03)[muon_base_ref]);
261  dest.set_dr03_pfiso_neutral((*neutral_03)[muon_base_ref]);
262  dest.set_dr03_pfiso_gamma((*gamma_03)[muon_base_ref]);
263  dest.set_dr03_pfiso_pu((*pu_03)[muon_base_ref]);
264  }
265  if (do_pf_iso_04_) {
266  dest.set_dr04_pfiso_charged_all((*charged_all_04)[muon_base_ref]);
267  dest.set_dr04_pfiso_charged((*charged_04)[muon_base_ref]);
268  dest.set_dr04_pfiso_neutral((*neutral_04)[muon_base_ref]);
269  dest.set_dr04_pfiso_gamma((*gamma_04)[muon_base_ref]);
270  dest.set_dr04_pfiso_pu((*pu_04)[muon_base_ref]);
271  }
272  }
273 
274  if (do_vertex_ip_ && vertices_handle->size() > 0 &&
275  src.muonBestTrack().isNonnull()) {
276  reco::Vertex const& vtx = vertices_handle->at(0);
277  dest.set_dz_vertex(src.muonBestTrack()->dz(vtx.position()));
278  dest.set_dxy_vertex(src.muonBestTrack()->dxy(vtx.position()));
279  }
280  if (do_beamspot_ip_&& src.muonBestTrack().isNonnull()) {
281  dest.set_dxy_beamspot(src.muonBestTrack()->dxy(*beamspot_handle));
282  }
283  }
284 }
285 
286 void ICMuonProducer::beginJob() {
287  ic::StaticTree::tree_->Branch(branch_.c_str(), &muons_);
288 }
289 
290 void ICMuonProducer::endJob() {}
291 
void set_vy(double const &y)
The y-coordinate of the ref_point()
Definition: Muon.hh:314
void set_is_global(bool const &is_global)
Muon was reconstructed by the global algorithm.
Definition: Muon.hh:180
void set_dr04_pfiso_charged_all(float const &dr04_pfiso_charged_all)
PF isolation, using all charged particles in a cone with .
Definition: Muon.hh:286
void set_cq_chi2_localposition(float const &cq_chi2_localposition)
for the sta-tk matching of local position
Definition: Muon.hh:199
void set_is_calo(bool const &is_calo)
Muon was reconstructed by the calo-muon algorithm.
Definition: Muon.hh:188
void set_dr03_ecal_rechit_sum_et(float const &dr03_ecal_rechit_sum_et)
ECAL isolation in a cone with .
Definition: Muon.hh:250
void set_phi(double const &phi)
Direct access to .
Definition: Candidate.hh:75
void set_dxy_beamspot(double const &dxy_beamspot)
Transverse impact parameter of the tracker track with the beamspot.
Definition: Muon.hh:328
void set_vz(double const &z)
The z-coordinate of the ref_point()
Definition: Muon.hh:317
void set_id(std::size_t const &id)
Unique identifier.
Definition: Candidate.hh:66
DEFINE_FWK_MODULE(ICMuonProducer)
void set_is_pf(bool const &is_pf)
Muon was reconstructed by the PF algorithm.
Definition: Muon.hh:191
void set_dr03_pfiso_gamma(float const &dr03_pfiso_gamma)
PF isolation, using photons in a cone with .
Definition: Muon.hh:276
void set_segment_compatibility(float const &segment_compatibility)
Compatibility of segment with global fit.
Definition: Muon.hh:240
void set_is_tracker(bool const &is_tracker)
Muon was reconstructed by the tracker-only algorithm.
Definition: Muon.hh:183
void set_charge(int const &charge)
Electric charge.
Definition: Candidate.hh:81
void set_dr03_hcal_tower_sum_et(float const &dr03_hcal_tower_sum_et)
HCAL isolation in a cone with .
Definition: Muon.hh:256
void set_vx(double const &x)
The x-coordinate of the ref_point()
Definition: Muon.hh:311
void set_is_standalone(bool const &is_standalone)
Muon was reconstructed by the stand-alone algorithm.
Definition: Muon.hh:175
static TTree * tree_
Definition: StaticTree.hh:13
void set_it_pixel_hits(int const &it_pixel_hits)
Number of pixel layer hits in the tracker.
Definition: Muon.hh:219
void set_dr03_pfiso_neutral(float const &dr03_pfiso_neutral)
PF isolation, using neutral hadrons in a cone with .
Definition: Muon.hh:271
void set_gt_valid_muon_hits(int const &gt_valid_muon_hits)
Number of muon station hits used in the global track fit.
Definition: Muon.hh:209
void set_dr04_pfiso_charged(float const &dr04_pfiso_charged)
PF isolation, using charged hadrons in a cone with .
Definition: Muon.hh:291
void set_dr03_pfiso_charged(float const &dr03_pfiso_charged)
PF isolation, using charged hadrons in a cone with .
Definition: Muon.hh:266
void set_it_tracker_hits(int const &it_tracker_hits)
Number of hits in the tracker.
Definition: Muon.hh:224
void set_cq_trk_kink(float const &cq_trk_kink)
Kink position for the tracker stub and global track.
Definition: Muon.hh:204
This class stores a subset of the reco::Muon properties which are most commonly used in analysis...
Definition: Muon.hh:22
void set_energy(double const &energy)
Direct access to the energy.
Definition: Candidate.hh:78
void set_dr04_pfiso_pu(float const &dr04_pfiso_pu)
PF isolation, using charged pileup in a cone with .
Definition: Muon.hh:306
void set_dr04_pfiso_gamma(float const &dr04_pfiso_gamma)
PF isolation, using photons in a cone with .
Definition: Muon.hh:301
ICMuonProducer(const edm::ParameterSet &)
void set_dxy_vertex(double const &dxy_vertex)
Transverse impact parameter of the tracker track with the primary vertex.
Definition: Muon.hh:320
void set_dr03_tk_sum_pt(float const &dr03_tk_sum_pt)
Tracker isolation in a cone with .
Definition: Muon.hh:245
void SetIdIso(std::string const &name, float const &value)
Add a new entry, overwriting any existing one with the same name.
Definition: Muon.cc:42
void set_dr03_pfiso_pu(float const &dr03_pfiso_pu)
PF isolation, using charged pileup in a cone with .
Definition: Muon.hh:281
See documentation here.
void PrintOptional(unsigned depth, bool value, std::string text)
Definition: Consumes.h:19
void set_dr04_pfiso_neutral(float const &dr04_pfiso_neutral)
PF isolation, using neutral hadrons in a cone with .
Definition: Muon.hh:296
edm::ConsumesCollector consumesCollector()
Definition: Consumes.cc:4
void set_pt(double const &pt)
Direct access to the .
Definition: Candidate.hh:69
void set_gt_normalized_chi2(double const &gt_normalized_chi2)
Normalised of the global track fit.
Definition: Muon.hh:194
void set_eta(double const &eta)
Direct access to .
Definition: Candidate.hh:72
void set_matched_stations(int const &matched_stations)
Number of matched muon station track segments.
Definition: Muon.hh:214
void set_dz_vertex(double const &dz_vertex)
Longitudinal impact parameter of the tracker track with primary vertex.
Definition: Muon.hh:325
void set_dr03_pfiso_charged_all(float const &dr03_pfiso_charged_all)
PF isolation, using all charged particles in a cone with .
Definition: Muon.hh:261
void set_it_valid_fraction(double const &it_valid_fraction)
Fraction of valid inner tracker hits.
Definition: Muon.hh:235
void set_it_layers_with_measurement(int const &it_layers_with_measurement)
Number of tracker layers with measurement.
Definition: Muon.hh:229
void PrintHeaderWithProduces(edm::ParameterSet const &config, edm::InputTag const &in, std::string branch)