#include <string>
#include <vector>
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/MuonReco/interface/MuonFwd.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/MuonReco/interface/MuonSelectors.h"
: charged_all(pset.getParameter<
edm::InputTag>(
"chargedAll")),
charged(pset.getParameter<
edm::InputTag>(
"charged")),
neutral(pset.getParameter<
edm::InputTag>(
"neutral")),
gamma(pset.getParameter<
edm::InputTag>(
"gamma")),
pu(pset.getParameter<
edm::InputTag>(
"pu")) {
collector.consumes<edm::ValueMap<double>>(charged_all);
collector.consumes<edm::ValueMap<double>>(charged);
collector.consumes<edm::ValueMap<double>>(neutral);
collector.consumes<edm::ValueMap<double>>(
gamma);
collector.consumes<edm::ValueMap<double>>(pu);
}
: input_(config.getParameter<
edm::InputTag>(
"input")),
branch_(config.getParameter<
std::string>(
"branch")),
is_pf_(config.getParameter<bool>("isPF")),
input_vertices_(config.getParameter<
edm::InputTag>(
"inputVertices")),
do_vertex_ip_(config.getParameter<bool>("includeVertexIP")),
input_beamspot_(config.getParameter<
edm::InputTag>(
"inputBeamspot")),
do_beamspot_ip_(config.getParameter<bool>("includeBeamspotIP")),
do_pf_iso_03_(config.getParameter<bool>("includePFIso03")),
do_pf_iso_04_(config.getParameter<bool>("includePFIso04")) {
if(is_pf_){
consumes<edm::View<reco::PFCandidate>>(input_);
} else {
consumes<edm::View<reco::Muon>>(input_);
}
consumes<edm::View<reco::Vertex>>(input_vertices_);
consumes<reco::BeamSpot>(input_beamspot_);
muons_ = new std::vector<ic::Muon>();
edm::ParameterSet pset_floats =
config.getParameter<edm::ParameterSet>("includeFloats");
std::vector<std::string> vec =
pset_floats.getParameterNamesForType<edm::InputTag>();
for (unsigned i = 0; i < vec.size(); ++i) {
input_vmaps_.push_back(std::make_pair(
vec[i], pset_floats.getParameter<edm::InputTag>(vec[i])));
consumes<edm::ValueMap<float>>(input_vmaps_[i].second);
}
edm::ParameterSet pset_doubles =
config.getParameter<edm::ParameterSet>("includeDoubles");
std::vector<std::string> doubles_vec =
pset_doubles.getParameterNamesForType<edm::InputTag>();
for (unsigned i = 0; i < doubles_vec.size(); ++i) {
input_double_vmaps_.push_back(std::make_pair(
doubles_vec[i], pset_doubles.getParameter<edm::InputTag>(doubles_vec[i])));
consumes<edm::ValueMap<double>>(input_double_vmaps_[i].second);
}
}
void ICMuonProducer::produce(edm::Event& event, const edm::EventSetup& setup) {
edm::Handle<edm::View<reco::Muon> > muons_handle;
edm::Handle<edm::View<reco::PFCandidate> > pfs_handle;
unsigned n_muons = 0;
if (is_pf_) {
event.getByLabel(input_, pfs_handle);
n_muons = pfs_handle->size();
} else {
event.getByLabel(input_, muons_handle);
n_muons = muons_handle->size();
}
edm::Handle<edm::View<reco::Vertex> > vertices_handle;
if (do_vertex_ip_) event.getByLabel(input_vertices_, vertices_handle);
edm::Handle<reco::BeamSpot> beamspot_handle;
if (do_beamspot_ip_) event.getByLabel(input_beamspot_, beamspot_handle);
std::vector<edm::Handle<edm::ValueMap<float> > > float_handles(
input_vmaps_.size());
for (unsigned i = 0; i < float_handles.size(); ++i) {
event.getByLabel(input_vmaps_[i].second, float_handles[i]);
}
std::vector<edm::Handle<edm::ValueMap<double> > > double_handles(
input_double_vmaps_.size());
for (unsigned i = 0; i < double_handles.size(); ++i) {
event.getByLabel(input_double_vmaps_[i].second, double_handles[i]);
}
edm::Handle<edm::ValueMap<double> > charged_all_03;
edm::Handle<edm::ValueMap<double> > charged_03;
edm::Handle<edm::ValueMap<double> > neutral_03;
edm::Handle<edm::ValueMap<double> > gamma_03;
edm::Handle<edm::ValueMap<double> > pu_03;
edm::Handle<edm::ValueMap<double> > neutral_pfw_03;
edm::Handle<edm::ValueMap<double> > gamma_pfw_03;
if (do_pf_iso_03_) {
event.getByLabel(pf_iso_03_.charged_all, charged_all_03);
event.getByLabel(pf_iso_03_.charged, charged_03);
event.getByLabel(pf_iso_03_.neutral, neutral_03);
event.getByLabel(pf_iso_03_.gamma, gamma_03);
event.getByLabel(pf_iso_03_.pu, pu_03);
}
edm::Handle<edm::ValueMap<double> > charged_all_04;
edm::Handle<edm::ValueMap<double> > charged_04;
edm::Handle<edm::ValueMap<double> > neutral_04;
edm::Handle<edm::ValueMap<double> > gamma_04;
edm::Handle<edm::ValueMap<double> > pu_04;
edm::Handle<edm::ValueMap<double> > neutral_pfw_04;
edm::Handle<edm::ValueMap<double> > gamma_pfw_04;
if (do_pf_iso_04_) {
event.getByLabel(pf_iso_04_.charged_all, charged_all_04);
event.getByLabel(pf_iso_04_.charged, charged_04);
event.getByLabel(pf_iso_04_.neutral, neutral_04);
event.getByLabel(pf_iso_04_.gamma, gamma_04);
event.getByLabel(pf_iso_04_.pu, pu_04);
}
muons_->clear();
for (unsigned i = 0; i < n_muons; ++i) {
reco::MuonRef muon_ref;
edm::RefToBase<reco::Muon> muon_base_ref;
edm::RefToBase<reco::PFCandidate> pf_base_ref;
if (is_pf_) {
reco::PFCandidate const& pf_src = pfs_handle->at(i);
dest.
set_id(pf_hasher_(&pf_src));
muon_ref = pf_src.muonRef();
pf_base_ref = pfs_handle->refAt(i);
} else {
reco::Muon const& reco_src = muons_handle->at(i);
dest.
set_id(muon_hasher_(&reco_src));
muon_base_ref = muons_handle->refAt(i);
}
reco::Muon const& src =
is_pf_ ? *(pfs_handle->at(i).muonRef()) : *muons_handle->refAt(i);
if (src.isGlobalMuon() && src.globalTrack().isNonnull()) {
src.globalTrack()->hitPattern().numberOfValidMuonHits());
}
if (src.isTrackerMuon() && src.innerTrack().isNonnull()) {
src.innerTrack()->hitPattern().numberOfValidPixelHits());
src.innerTrack()->hitPattern().numberOfValidTrackerHits());
src.innerTrack()->hitPattern().trackerLayersWithMeasurement());
src.innerTrack()->validFraction());
}
for (unsigned v = 0; v < float_handles.size(); ++v) {
if (is_pf_) {
(*(float_handles[v]))[pf_base_ref]);
} else {
(*(float_handles[v]))[muon_base_ref]);
}
}
for (unsigned v = 0; v < double_handles.size(); ++v) {
if (is_pf_) {
dest.
SetIdIso(input_double_vmaps_[v].first,
float((*(double_handles[v]))[pf_base_ref]));
} else {
dest.
SetIdIso(input_double_vmaps_[v].first,
float((*(double_handles[v]))[muon_base_ref]));
}
}
if (is_pf_) {
if (do_pf_iso_03_) {
}
if (do_pf_iso_04_) {
}
} else {
if (do_pf_iso_03_) {
}
if (do_pf_iso_04_) {
}
}
if (do_vertex_ip_ && vertices_handle->size() > 0 &&
src.muonBestTrack().isNonnull()) {
reco::Vertex const& vtx = vertices_handle->at(0);
}
if (do_beamspot_ip_&& src.muonBestTrack().isNonnull()) {
}
}
}
void ICMuonProducer::beginJob() {
}
void ICMuonProducer::endJob() {}