#ifndef UserCode_ICHiggsTauTau_ICJetDestHelper_h
#define UserCode_ICHiggsTauTau_ICJetDestHelper_h
#include <memory>
#include "boost/functional/hash.hpp"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/JetReco/interface/CaloJet.h"
#include "DataFormats/JetReco/interface/PFJet.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "PhysicsTools/SelectorUtils/interface/JetIDSelectionFunctor.h"
template <class U>
void DoSetup(edm::EDProducer * prod) {}
};
template <>
bool do_jet_id;
edm::InputTag input_jet_id;
JetIDSelectionFunctor *loose_id;
JetIDSelectionFunctor *tight_id;
bool do_n_carrying;
: do_jet_id(pset.getParameter<bool>("includeJetID")),
input_jet_id(pset.getParameter<
edm::InputTag>(
"inputJetID")),
loose_id(NULL),
tight_id(NULL),
do_n_carrying(pset.getParameter<bool>("includeTowerCounts")) {
collector.consumes<reco::JetIDValueMap>(input_jet_id);
loose_id = new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
JetIDSelectionFunctor::LOOSE);
tight_id = new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
JetIDSelectionFunctor::TIGHT);
}
void DoSetup(edm::EDProducer * prod) {
std::cout << "CaloJet specific options:\n";
}
delete loose_id;
delete tight_id;
}
};
template <>
bool do_jet_id;
edm::InputTag input_jet_id;
JetIDSelectionFunctor *loose_id;
JetIDSelectionFunctor *tight_id;
bool request_trks;
boost::hash<reco::Track const*> track_hasher;
bool do_trk_vars;
edm::InputTag input_trks;
edm::InputTag input_vtxs;
bool do_n_carrying;
: do_jet_id(pset.getParameter<bool>("includeJetID")),
input_jet_id(pset.getParameter<
edm::InputTag>(
"inputJetID")),
loose_id(NULL),
tight_id(NULL),
request_trks(pset.getParameter<bool>("requestTracks")),
do_trk_vars(pset.getParameter<bool>("includeTrackBasedVars")),
input_trks(pset.getParameter<
edm::InputTag>(
"inputTracks")),
input_vtxs(pset.getParameter<
edm::InputTag>(
"inputVertices")),
do_n_carrying(pset.getParameter<bool>("includeTowerCounts")) {
collector.consumes<edm::ValueMap<float>>(input_jet_id);
loose_id = new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
JetIDSelectionFunctor::LOOSE);
tight_id = new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
JetIDSelectionFunctor::TIGHT);
}
void DoSetup(edm::EDProducer * prod) {
if (request_trks) {
prod->produces<reco::TrackRefVector>("requestedTracks");
}
std::cout << "JPTJet specific options:\n";
}
std::vector<std::size_t> DoTrackCollection(
reco::TrackRefVector const &ref_vec, reco::TrackRefVector *target) {
std::vector<std::size_t> res(ref_vec.size(), 0);
for (unsigned i = 0; i < ref_vec.size(); ++i) {
res[i] = track_hasher(&(*(ref_vec[i])));
target->push_back(ref_vec[i]);
}
return res;
}
void AddTrackCollection(reco::TrackRefVector const &ref_vec,
std::vector<reco::Track const *> *target) {
for (unsigned i = 0; i < ref_vec.size(); ++i) {
target->push_back(&(*(ref_vec[i])));
}
}
delete loose_id;
delete tight_id;
}
};
template <>
bool do_pu_id;
edm::InputTag input_pu_id;
bool do_trk_vars;
edm::InputTag input_trks;
edm::InputTag input_vtxs;
bool request_trks;
boost::hash<reco::Track const*> track_hasher;
: do_pu_id(pset.getParameter<bool>("includePileupID")),
input_pu_id(pset.getParameter<
edm::InputTag>(
"inputPileupID")),
do_trk_vars(pset.getParameter<bool>("includeTrackBasedVars")),
input_trks(pset.getParameter<
edm::InputTag>(
"inputTracks")),
input_vtxs(pset.getParameter<
edm::InputTag>(
"inputVertices")),
request_trks(pset.getParameter<bool>("requestTracks")) {
collector.consumes<edm::ValueMap<float>>(input_pu_id);
}
void DoSetup(edm::EDProducer * prod) {
if (request_trks) {
prod->produces<reco::TrackRefVector>("requestedTracks");
}
std::cout << "PFJet specific options:\n";
}
};
template<class U>
}
template<class U>
}
template<class U>
}
edm::Handle<reco::TrackCollection> const &trk_handle,
edm::Handle<reco::VertexCollection> const &vtx_handle) {
std::map<unsigned, unsigned> trk_vtx_map;
if (trk_handle->size() > 0) {
reco::Track const *ptr_to_first = &(trk_handle->at(0));
for (unsigned i = 0; i < vtx_handle->size(); ++i) {
std::vector<reco::TrackBaseRef>::const_iterator trk_it;
for (trk_it = vtx_handle->at(i).tracks_begin();
trk_it != vtx_handle->at(i).tracks_end(); ++trk_it) {
reco::Track const *ptr_to_trk =
dynamic_cast<reco::Track const *>(&(**trk_it));
unsigned trk_idx = (unsigned(ptr_to_trk - ptr_to_first));
trk_vtx_map[trk_idx] = i;
}
}
}
return trk_vtx_map;
}
std::vector<reco::PFCandidatePtr> const &pfcands,
reco::TrackRefVector *track_requests,
boost::hash<reco::Track const *> *track_hasher) {
std::vector<std::size_t> track_ids;
for (unsigned iP = 0; iP < pfcands.size(); ++iP) {
if (pfcands[iP]->trackRef().isNonnull()) {
track_requests->push_back(pfcands[iP]->trackRef());
track_ids.push_back((*track_hasher)(&(*(pfcands[iP]->trackRef()))));
}
}
}
std::vector<reco::Track const *> const &all_tracks,
edm::Handle<reco::TrackCollection> const &trk_handle,
edm::Handle<reco::VertexCollection> const &vtx_handle,
std::map<unsigned, unsigned> const &trk_vtx_map) {
std::vector<double> pt_at_vtx_vec(vtx_handle->size(), 0.0);
reco::Track const *ptr_first = &(trk_handle->at(0));
double trk_pt_total = 0.0;
for (unsigned j = 0; j < all_tracks.size(); ++j) {
unsigned idx = unsigned(all_tracks[j] - ptr_first);
trk_pt_total += all_tracks[j]->pt();
if (trk_vtx_map.count(idx) > 0) {
pt_at_vtx_vec[trk_vtx_map.find(idx)->second] += all_tracks[j]->pt();
} else {
std::vector<double> dz_with_vtx(vtx_handle->size(), 0.0);
for (unsigned k = 0; k < vtx_handle->size(); ++k) {
dz_with_vtx[k] = fabs(vtx_handle->at(k).z() - all_tracks[j]->vz());
}
std::vector<double>::const_iterator min =
std::min_element(dz_with_vtx.begin(), dz_with_vtx.end());
if (min != dz_with_vtx.end()) {
if (*min < 0.2) {
pt_at_vtx_vec[unsigned(min - dz_with_vtx.begin())] +=
all_tracks[j]->pt();
}
}
}
}
if (vtx_handle->size() > 0 && trk_pt_total > 0.0) {
for (unsigned j = 0; j < pt_at_vtx_vec.size(); ++j) {
pt_at_vtx_vec[j] = pt_at_vtx_vec[j] / trk_pt_total;
}
*std::max_element(pt_at_vtx_vec.begin(), pt_at_vtx_vec.end()));
} else {
}
}
std::vector<reco::PFCandidatePtr> const &pfcands,
edm::Handle<reco::TrackCollection> const &trk_handle,
edm::Handle<reco::VertexCollection> const &vtx_handle,
std::map<unsigned, unsigned> const &trk_vtx_map) {
int charged_multiplicity_nopu = 0;
float linear_radial_moment_nopu = 0.0;
double trk_pt_total = 0.0;
std::vector<double> pt_at_vtx_vec(vtx_handle->size(), 0.0);
reco::Track const* ptr_first = &(trk_handle->at(0));
for (unsigned iP = 0; iP < pfcands.size(); ++iP) {
if (pfcands[iP]->trackRef().isNonnull()) {
unsigned idx = unsigned(&(*(pfcands[iP]->trackRef())) - ptr_first);
trk_pt_total += pfcands[iP]->trackRef()->pt();
if (trk_vtx_map.count(idx) > 0) {
if (trk_vtx_map.find(idx)->second == 0) {
++charged_multiplicity_nopu;
linear_radial_moment_nopu +=
pfcands[iP]->pt() * deltaR(dest->
vector().Rapidity(), dest->
phi(),
pfcands[iP]->rapidity(),
pfcands[iP]->phi());
}
pt_at_vtx_vec[trk_vtx_map.find(idx)->second] +=
pfcands[iP]->trackRef()->pt();
} else {
std::vector<double> dz_with_vtx(vtx_handle->size(), 0.0);
for (unsigned iV = 0; iV < vtx_handle->size(); ++iV) {
dz_with_vtx[iV] =
fabs(vtx_handle->at(iV).z() - pfcands[iP]->trackRef()->vz());
}
std::vector<double>::const_iterator min =
std::min_element(dz_with_vtx.begin(), dz_with_vtx.end());
if (min != dz_with_vtx.end()) {
if (*min < 0.2) {
if (unsigned(min-dz_with_vtx.begin()) == 0) {
++charged_multiplicity_nopu;
linear_radial_moment_nopu +=
pfcands[iP]->pt() * deltaR(dest->
vector().Rapidity(), dest->
phi(),
pfcands[iP]->rapidity(),
pfcands[iP]->phi());
}
pt_at_vtx_vec[unsigned(min - dz_with_vtx.begin())] +=
pfcands[iP]->trackRef()->pt();
}
}
}
} else {
linear_radial_moment_nopu +=
pfcands[iP]->pt() * deltaR(dest->
vector().Rapidity(), dest->
phi(),
pfcands[iP]->rapidity(),
pfcands[iP]->phi());
}
}
linear_radial_moment_nopu = linear_radial_moment_nopu / dest->
pt();
if (vtx_handle->size() > 0 && trk_pt_total > 0.0) {
for (unsigned iV = 0; iV < pt_at_vtx_vec.size(); ++iV) {
pt_at_vtx_vec[iV] = pt_at_vtx_vec[iV] / trk_pt_total;
}
*std::max_element(pt_at_vtx_vec.begin(), pt_at_vtx_vec.end()));
} else {
}
}
#endif