1 #ifndef UserCode_ICHiggsTauTau_ICJetDestHelper_h
2 #define UserCode_ICHiggsTauTau_ICJetDestHelper_h
5 #include "boost/functional/hash.hpp"
6 #include "FWCore/ParameterSet/interface/ParameterSet.h"
7 #include "FWCore/Framework/interface/Event.h"
8 #include "FWCore/Framework/interface/EventSetup.h"
9 #include "FWCore/Framework/interface/EDProducer.h"
10 #include "FWCore/Utilities/interface/InputTag.h"
11 #include "DataFormats/Math/interface/deltaR.h"
12 #include "DataFormats/JetReco/interface/CaloJet.h"
13 #include "DataFormats/JetReco/interface/PFJet.h"
14 #include "DataFormats/TrackReco/interface/TrackFwd.h"
18 #include "PhysicsTools/SelectorUtils/interface/JetIDSelectionFunctor.h"
37 : do_jet_id(pset.getParameter<bool>(
"includeJetID")),
38 input_jet_id(pset.getParameter<
edm::InputTag>(
"inputJetID")),
41 do_n_carrying(pset.getParameter<bool>(
"includeTowerCounts")) {
42 collector.consumes<reco::JetIDValueMap>(input_jet_id);
43 loose_id =
new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
44 JetIDSelectionFunctor::LOOSE);
45 tight_id =
new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
46 JetIDSelectionFunctor::TIGHT);
50 std::cout <<
"CaloJet specific options:\n";
75 : do_jet_id(pset.getParameter<bool>(
"includeJetID")),
76 input_jet_id(pset.getParameter<
edm::InputTag>(
"inputJetID")),
79 request_trks(pset.getParameter<bool>(
"requestTracks")),
80 do_trk_vars(pset.getParameter<bool>(
"includeTrackBasedVars")),
81 input_trks(pset.getParameter<
edm::InputTag>(
"inputTracks")),
82 input_vtxs(pset.getParameter<
edm::InputTag>(
"inputVertices")),
83 do_n_carrying(pset.getParameter<bool>(
"includeTowerCounts")) {
84 collector.consumes<edm::ValueMap<float>>(input_jet_id);
87 loose_id =
new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
88 JetIDSelectionFunctor::LOOSE);
89 tight_id =
new JetIDSelectionFunctor(JetIDSelectionFunctor::PURE09,
90 JetIDSelectionFunctor::TIGHT);
95 prod->produces<reco::TrackRefVector>(
"requestedTracks");
97 std::cout <<
"JPTJet specific options:\n";
105 reco::TrackRefVector
const &ref_vec, reco::TrackRefVector *target) {
106 std::vector<std::size_t> res(ref_vec.size(), 0);
107 for (
unsigned i = 0; i < ref_vec.size(); ++i) {
108 res[i] = track_hasher(&(*(ref_vec[i])));
109 target->push_back(ref_vec[i]);
115 std::vector<reco::Track const *> *target) {
116 for (
unsigned i = 0; i < ref_vec.size(); ++i) {
117 target->push_back(&(*(ref_vec[i])));
138 : do_pu_id(pset.getParameter<bool>(
"includePileupID")),
139 input_pu_id(pset.getParameter<
edm::InputTag>(
"inputPileupID")),
140 do_trk_vars(pset.getParameter<bool>(
"includeTrackBasedVars")),
141 input_trks(pset.getParameter<
edm::InputTag>(
"inputTracks")),
142 input_vtxs(pset.getParameter<
edm::InputTag>(
"inputVertices")),
143 request_trks(pset.getParameter<bool>(
"requestTracks")) {
144 collector.consumes<edm::ValueMap<float>>(input_pu_id);
151 prod->produces<reco::TrackRefVector>(
"requestedTracks");
153 std::cout <<
"PFJet specific options:\n";
213 edm::Handle<reco::TrackCollection>
const &trk_handle,
214 edm::Handle<reco::VertexCollection>
const &vtx_handle) {
215 std::map<unsigned, unsigned> trk_vtx_map;
216 if (trk_handle->size() > 0) {
217 reco::Track
const *ptr_to_first = &(trk_handle->at(0));
218 for (
unsigned i = 0; i < vtx_handle->size(); ++i) {
219 std::vector<reco::TrackBaseRef>::const_iterator trk_it;
220 for (trk_it = vtx_handle->at(i).tracks_begin();
221 trk_it != vtx_handle->at(i).tracks_end(); ++trk_it) {
222 reco::Track
const *ptr_to_trk =
223 dynamic_cast<reco::Track
const *
>(&(**trk_it));
224 unsigned trk_idx = (unsigned(ptr_to_trk - ptr_to_first));
225 trk_vtx_map[trk_idx] = i;
233 std::vector<reco::PFCandidatePtr>
const &pfcands,
234 reco::TrackRefVector *track_requests,
235 boost::hash<reco::Track const *> *track_hasher) {
236 std::vector<std::size_t> track_ids;
237 for (
unsigned iP = 0; iP < pfcands.size(); ++iP) {
238 if (pfcands[iP]->trackRef().isNonnull()) {
239 track_requests->push_back(pfcands[iP]->trackRef());
240 track_ids.push_back((*track_hasher)(&(*(pfcands[iP]->trackRef()))));
247 std::vector<reco::Track const *>
const &all_tracks,
248 edm::Handle<reco::TrackCollection>
const &trk_handle,
249 edm::Handle<reco::VertexCollection>
const &vtx_handle,
250 std::map<unsigned, unsigned>
const &trk_vtx_map) {
251 std::vector<double> pt_at_vtx_vec(vtx_handle->size(), 0.0);
252 reco::Track
const *ptr_first = &(trk_handle->at(0));
253 double trk_pt_total = 0.0;
254 for (
unsigned j = 0; j < all_tracks.size(); ++j) {
255 unsigned idx = unsigned(all_tracks[j] - ptr_first);
256 trk_pt_total += all_tracks[j]->pt();
258 if (trk_vtx_map.count(idx) > 0) {
259 pt_at_vtx_vec[trk_vtx_map.find(idx)->second] += all_tracks[j]->pt();
261 std::vector<double> dz_with_vtx(vtx_handle->size(), 0.0);
262 for (
unsigned k = 0; k < vtx_handle->size(); ++k) {
263 dz_with_vtx[k] = fabs(vtx_handle->at(k).z() - all_tracks[j]->vz());
265 std::vector<double>::const_iterator min =
266 std::min_element(dz_with_vtx.begin(), dz_with_vtx.end());
267 if (min != dz_with_vtx.end()) {
269 pt_at_vtx_vec[unsigned(min - dz_with_vtx.begin())] +=
275 if (vtx_handle->size() > 0 && trk_pt_total > 0.0) {
276 for (
unsigned j = 0; j < pt_at_vtx_vec.size(); ++j) {
277 pt_at_vtx_vec[j] = pt_at_vtx_vec[j] / trk_pt_total;
281 *std::max_element(pt_at_vtx_vec.begin(), pt_at_vtx_vec.end()));
291 std::vector<reco::PFCandidatePtr>
const &pfcands,
292 edm::Handle<reco::TrackCollection>
const &trk_handle,
293 edm::Handle<reco::VertexCollection>
const &vtx_handle,
294 std::map<unsigned, unsigned>
const &trk_vtx_map) {
295 int charged_multiplicity_nopu = 0;
296 float linear_radial_moment_nopu = 0.0;
297 double trk_pt_total = 0.0;
298 std::vector<double> pt_at_vtx_vec(vtx_handle->size(), 0.0);
299 reco::Track
const* ptr_first = &(trk_handle->at(0));
300 for (
unsigned iP = 0; iP < pfcands.size(); ++iP) {
301 if (pfcands[iP]->trackRef().isNonnull()) {
302 unsigned idx = unsigned(&(*(pfcands[iP]->trackRef())) - ptr_first);
303 trk_pt_total += pfcands[iP]->trackRef()->pt();
305 if (trk_vtx_map.count(idx) > 0) {
308 if (trk_vtx_map.find(idx)->second == 0) {
309 ++charged_multiplicity_nopu;
310 linear_radial_moment_nopu +=
311 pfcands[iP]->pt() * deltaR(dest->
vector().Rapidity(), dest->
phi(),
312 pfcands[iP]->rapidity(),
315 pt_at_vtx_vec[trk_vtx_map.find(idx)->second] +=
316 pfcands[iP]->trackRef()->pt();
318 std::vector<double> dz_with_vtx(vtx_handle->size(), 0.0);
319 for (
unsigned iV = 0; iV < vtx_handle->size(); ++iV) {
321 fabs(vtx_handle->at(iV).z() - pfcands[iP]->trackRef()->vz());
323 std::vector<double>::const_iterator min =
324 std::min_element(dz_with_vtx.begin(), dz_with_vtx.end());
325 if (min != dz_with_vtx.end()) {
330 if (
unsigned(min-dz_with_vtx.begin()) == 0) {
331 ++charged_multiplicity_nopu;
332 linear_radial_moment_nopu +=
333 pfcands[iP]->pt() * deltaR(dest->
vector().Rapidity(), dest->
phi(),
334 pfcands[iP]->rapidity(),
337 pt_at_vtx_vec[unsigned(min - dz_with_vtx.begin())] +=
338 pfcands[iP]->trackRef()->pt();
343 linear_radial_moment_nopu +=
344 pfcands[iP]->pt() * deltaR(dest->
vector().Rapidity(), dest->
phi(),
345 pfcands[iP]->rapidity(),
350 linear_radial_moment_nopu = linear_radial_moment_nopu / dest->
pt();
354 if (vtx_handle->size() > 0 && trk_pt_total > 0.0) {
355 for (
unsigned iV = 0; iV < pt_at_vtx_vec.size(); ++iV) {
356 pt_at_vtx_vec[iV] = pt_at_vtx_vec[iV] / trk_pt_total;
360 *std::max_element(pt_at_vtx_vec.begin(), pt_at_vtx_vec.end()));
void set_neutral_had_multiplicity(int const &neutral_had_multiplicity)
Number of neutral hadron constituents.
void set_had_energy_HO(float const &had_energy_HO)
Hadronic energy in the HO detector.
void DoSetup(edm::EDProducer *prod)
void set_beta(float const &beta)
The fraction of the constituent track momentum associated to the primary vertex.
JetDestHelper(const edm::ParameterSet &pset, edm::ConsumesCollector &&collector)
void set_neutral_em_energy(float const &neutral_em_energy)
Neutral EM energy.
std::vector< ic::Vertex > VertexCollection
void set_neutral_em_energy(float const &neutral_em_energy)
Neutral electromagnetic energy.
void FillCommonPFJet(ic::PFJet *dest, U const &src)
void set_muon_multiplicity(int const &muon_multiplicity)
Number of PF muon constituents.
void DoSetup(edm::EDProducer *prod)
void set_HF_had_energy(float const &HF_had_energy)
HF hadronic energy.
void set_charged_multiplicity_nopu(int const &charged_multiplicity_nopu)
The number of charged constituents associated to the PV.
void set_neutral_had_energy(float const &neutral_had_energy)
Neutral hadron energy.
void FillPFTrackVars(ic::PFJet *dest, 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)
void set_max_em_tower_energy(float const &max_em_tower_energy)
Maximum energy deposited in the ECAL towers.
void DoSetup(edm::EDProducer *prod)
JetDestHelper(const edm::ParameterSet &pset, edm::ConsumesCollector &&collector)
void set_em_energy_EE(float const &em_energy_EE)
Electromagnetic energy in the EE detector.
JetDestHelper(const edm::ParameterSet &pset, edm::ConsumesCollector &&collector)
void set_charged_multiplicity(int const &charged_multiplicity)
Total number of charged constituents.
JetDestHelper(const edm::ParameterSet &pset, edm::ConsumesCollector &&collector)
Vector const & vector() const
Four-momentum.
void set_photon_multiplicity(int const &photon_multiplicity)
Number of PF photon constituents.
edm::InputTag input_jet_id
void set_linear_radial_moment(float const &linear_radial_moment)
Used for quark-gluon discrimination.
JetIDSelectionFunctor * tight_id
std::vector< ic::Track > TrackCollection
std::vector< std::size_t > DoTrackCollection(reco::TrackRefVector const &ref_vec, reco::TrackRefVector *target)
void set_electron_multiplicity(int const &electron_multiplicity)
Number of PF electron constituents.
void set_beta(float const &beta)
The fraction of the constituent track momentum associated to the primary vertex.
A class derived from ic::Jet which adds Jet-plus-track specific information.
void set_charged_multiplicity(int const &charged_multiplicity)
Number of charged constituents.
void FillCommonJPTJet(ic::JPTJet *dest, U const &src)
void set_had_energy_HB(float const &had_energy_HB)
Hadronic energy in the HB detector.
void set_charged_em_energy(float const &charged_em_energy)
Charged EM energy.
void AddTrackCollection(reco::TrackRefVector const &ref_vec, std::vector< reco::Track const * > *target)
void DoSetup(edm::EDProducer *prod)
double phi() const
Direct access to .
void set_charged_had_energy(float const &charged_had_energy)
Charged hadron energy.
void set_HF_em_multiplicity(int const &HF_em_multiplicity)
Number of PF HF electromagnetic constituents.
void set_charged_had_multiplicity(int const &charged_had_multiplicity)
Number of charged hadron constituents.
void set_HF_had_multiplicity(int const &HF_had_multiplicity)
Number PF HF hadronic constituents.
JetIDSelectionFunctor * tight_id
void FillCommonCaloJet(ic::CaloJet *dest, U const &src)
void set_em_energy_HF(float const &em_energy_HF)
Electromagnetic energy in the HF detector.
void FillJPTTrackVars(ic::JPTJet *dest, 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)
void set_charged_mu_energy(float const &charged_mu_energy)
Muon energy.
void set_muon_energy(float const &muon_energy)
Muon energy.
void set_track_pt_total(float const &track_pt_total)
The scalar sum of track .
void set_electron_energy(float const &electron_energy)
Electron energy.
Derived from the ic::Jet class and adding information specific to calorimeter jets.
void set_energy_frac_had(float const &energy_frac_had)
Hadronic fraction of the jet energy.
void set_charged_em_energy(float const &charged_em_energy)
Charged electromagnetic energy.
edm::InputTag input_jet_id
void set_HF_em_energy(float const &HF_em_energy)
HF electromagnetic energy.
JetIDSelectionFunctor * loose_id
A class deriving from ic::Jet that provides specific information for particle-flow jets...
boost::hash< reco::Track const * > track_hasher
void set_beta_max(float const &beta_max)
The largest value of beta() obtained when it is evaluated for every vertex in the event...
void set_max_had_tower_energy(float const &max_had_tower_energy)
Maximum energy deposited in the HCAL towers.
boost::hash< reco::Track const * > track_hasher
void set_constituent_tracks(std::vector< std::size_t > const &constituent_tracks)
A vector to refer to the constituent track ic::Track::id() values.
edm::InputTag input_pu_id
void set_neutral_multiplicity(int const &neutral_multiplicity)
Number of neutral constituents.
void set_energy_frac_em(float const &energy_frac_em)
Electromagnetic fraction of the jet energy.
void set_neutral_had_energy(float const &neutral_had_energy)
Neutral hadron energy.
JetIDSelectionFunctor * loose_id
void set_photon_energy(float const &photon_energy)
Photon energy.
double pt() const
Direct access to the .
void set_had_energy_HF(float const &had_energy_HF)
Hadronic energy in the HF detector.
void set_em_energy_EB(float const &em_energy_EB)
Electromagnetic energy in the EB detector.
void set_charged_had_energy(float const &charged_had_energy)
Charged hadron energy.
std::map< unsigned, unsigned > BuildTrkVtxMap(edm::Handle< reco::TrackCollection > const &trk_handle, edm::Handle< reco::VertexCollection > const &vtx_handle)
void set_towers_area(float const &towers_area)
Area of towers contributing to the jet.
void set_beta_max(float const &beta_max)
The largest value of beta() obtained when it is evaluated for every vertex in the event...
void FillPFTracksAndRequest(ic::PFJet *dest, std::vector< reco::PFCandidatePtr > const &pfcands, reco::TrackRefVector *track_requests, boost::hash< reco::Track const * > *track_hasher)
void set_muon_multiplicity(int const &muon_multiplicity)
Number of muon constituents.
void set_had_energy_HE(float const &had_energy_HE)
Hadronic energy in the HE detector.