1 #ifndef UserCode_ICHiggsTauTau_ICTauProducer_h
2 #define UserCode_ICHiggsTauTau_ICTauProducer_h
6 #include "boost/functional/hash.hpp"
7 #include "boost/format.hpp"
8 #include "FWCore/Framework/interface/EDProducer.h"
9 #include "FWCore/ParameterSet/interface/ParameterSet.h"
10 #include "FWCore/Framework/interface/Event.h"
11 #include "FWCore/Framework/interface/EventSetup.h"
12 #include "DataFormats/TauReco/interface/PFTauFwd.h"
13 #include "DataFormats/TauReco/interface/PFTau.h"
14 #if CMSSW_MAJOR_VERSION>=7
15 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
17 #include "DataFormats/TauReco/interface/PFTauDiscriminator.h"
18 #include "DataFormats/PatCandidates/interface/Tau.h"
19 #include "DataFormats/VertexReco/interface/Vertex.h"
20 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
37 virtual void beginJob();
38 virtual void produce(edm::Event &,
const edm::EventSetup &);
39 virtual void endJob();
40 void constructSpecific(edm::Handle<edm::View<T> >
const& taus_handle,
41 edm::Event& event,
const edm::EventSetup& setup);
43 std::vector<ic::Tau> *taus_;
46 boost::hash<T const*> tau_hasher_;
47 boost::hash<reco::Track const*> track_hasher_;
48 boost::hash<reco::Candidate const*> cand_hasher_;
49 edm::InputTag track_input_;
50 std::vector<std::pair<std::string, edm::InputTag> > tau_ids_;
51 edm::InputTag input_vertices_;
54 std::map<std::string, std::size_t> observed_id_;
55 bool do_total_charged_;
56 std::string total_charged_label_;
58 edm::InputTag input_cands_;
67 : input_(config.getParameter<
edm::InputTag>(
"input")),
68 branch_(config.getParameter<
std::string>(
"branch")),
69 input_vertices_(config.getParameter<
edm::InputTag>(
"inputVertices")),
70 do_vertex_ip_(config.getParameter<bool>(
"includeVertexIP")),
71 request_trks_(config.getParameter<bool>(
"requestTracks")),
72 do_total_charged_(config.getParameter<bool>(
"includeTotalCharged")),
73 total_charged_label_(config.getParameter<
std::string>(
"totalChargedLabel")),
74 request_cands_(config.getParameter<bool>(
"requestPFCandidates")),
75 input_cands_(config.getParameter<
edm::InputTag>(
"inputPFCandidates")),
76 is_slimmed_(config.getParameter<bool>(
"isSlimmed")) {
77 consumes<edm::View<T>>(input_);
78 consumes<edm::View<reco::Vertex>>(input_vertices_);
79 taus_ =
new std::vector<ic::Tau>();
81 edm::ParameterSet pset = config.getParameter<edm::ParameterSet>(
"tauIDs");
82 std::vector<std::string> vec = pset.getParameterNamesForType<edm::InputTag>();
83 for (
unsigned i = 0; i < vec.size(); ++i) {
85 std::make_pair(vec[i], pset.getParameter<edm::InputTag>(vec[i])));
86 consumes<reco::PFTauDiscriminator>(tau_ids_[i].second);
90 produces<reco::TrackRefVector>(
"requestedTracks");
94 consumes<edm::View<reco::Candidate>>(input_cands_);
96 #if CMSSW_MAJOR_VERSION >= 7
97 produces<pat::PackedCandidateRefVector>(
"requestedPFCandidates");
100 produces<reco::PFCandidateRefVector>(
"requestedPFCandidates");
120 const edm::EventSetup& setup) {
121 edm::Handle<edm::View<T> > taus_handle;
122 event.getByLabel(input_, taus_handle);
124 edm::Handle<edm::View<reco::Vertex> > vertices_handle;
125 if (do_vertex_ip_)
event.getByLabel(input_vertices_, vertices_handle);
127 std::auto_ptr<reco::TrackRefVector> trk_requests(
new reco::TrackRefVector());
130 taus_->resize(taus_handle->size(),
ic::Tau());
131 for (
unsigned i = 0; i < taus_handle->size(); ++i) {
132 T
const& src = taus_handle->at(i);
135 dest.
set_id(tau_hasher_(&src));
143 if (src.leadPFChargedHadrCand().isNonnull()) {
146 dest.
set_lead_p(src.leadPFChargedHadrCand()->p());
147 reco::TrackRef
const& trk = src.leadPFChargedHadrCand()->trackRef();
148 reco::GsfTrackRef
const& gsf = src.leadPFChargedHadrCand()->gsfTrackRef();
149 if (do_vertex_ip_ && vertices_handle->size() > 0) {
150 reco::Vertex
const& vtx = vertices_handle->at(0);
151 if (trk.isNonnull()) {
154 }
else if (gsf.isNonnull()) {
163 std::vector<std::size_t> trk_ids;
164 for (
unsigned j = 0; j < src.signalPFChargedHadrCands().size(); ++j) {
165 reco::TrackRef
const& trk =
166 src.signalPFChargedHadrCands().at(j)->trackRef();
167 if (trk.isNonnull()) {
168 trk_requests->push_back(trk);
169 trk_ids.push_back(track_hasher_(&(*trk)));
179 constructSpecific(taus_handle, event, setup);
180 if (request_trks_)
event.put(trk_requests,
"requestedTracks");
188 edm::Handle<edm::View<T> >
const& taus_handle, edm::Event& event,
189 const edm::EventSetup& setup) {}
193 edm::Handle<edm::View<reco::PFTau> >
const& taus_handle, edm::Event& event,
194 const edm::EventSetup& setup) {
196 std::vector<edm::Handle<reco::PFTauDiscriminator> > id_handles(
198 for (
unsigned i = 0; i < id_handles.size(); ++i) {
199 event.getByLabel(tau_ids_[i].second, id_handles[i]);
202 for (
unsigned i = 0; i < taus_handle->size(); ++i) {
205 reco::PFTauRef
const& ref = taus_handle->refAt(i).castTo<reco::PFTauRef>();
206 for (
unsigned j = 0; j < tau_ids_.size(); ++j) {
207 dest.
SetTauID(tau_ids_[j].first, (*(id_handles[j]))[ref]);
208 observed_id_[tau_ids_[j].first] =
CityHash64(tau_ids_[j].first);
215 edm::Handle<edm::View<pat::Tau> >
const& taus_handle, edm::Event& event,
216 const edm::EventSetup& setup) {
218 edm::Handle<edm::View<reco::Candidate> > cands_handle;
219 if (request_cands_) {
220 event.getByLabel(input_cands_, cands_handle);
223 #if CMSSW_MAJOR_VERSION >= 7
224 std::auto_ptr<pat::PackedCandidateRefVector> cand_requests_slimmed(
new pat::PackedCandidateRefVector());
226 std::auto_ptr<reco::PFCandidateRefVector> cand_requests(
new reco::PFCandidateRefVector());
228 for (
unsigned i = 0; i < taus_handle->size(); ++i) {
229 pat::Tau
const& src = taus_handle->at(i);
231 std::vector<std::pair<std::string, float> > tau_ids = src.tauIDs();
232 for (
unsigned j = 0; j < tau_ids.size(); ++j) {
233 dest.
SetTauID(tau_ids[j].first, tau_ids[j].second);
234 observed_id_[tau_ids[j].first] =
CityHash64(tau_ids[j].first);
238 #if CMSSW_MAJOR_VERSION >= 7
239 if(src.leadChargedHadrCand().isNonnull()){
240 pat::PackedCandidate
const* packedCand =
dynamic_cast<pat::PackedCandidate const*
>(src.leadChargedHadrCand().get());
248 if (do_total_charged_ &&
249 src.signalChargedHadrCands().isNonnull() &&
250 src.isolationChargedHadrCands().isNonnull()) {
252 float(src.signalChargedHadrCands().size() + src.isolationChargedHadrCands().size()));
253 observed_id_[total_charged_label_] =
CityHash64(total_charged_label_);
256 if (request_cands_) {
257 if (src.signalChargedHadrCands().isNonnull()) {
258 auto cands = src.signalChargedHadrCands();
259 std::vector<std::size_t> ids;
260 for (
unsigned c = 0; c < cands.size(); ++c) {
261 cand_requests_slimmed->push_back(cands_handle->refAt(cands[c].key()).castTo<pat::PackedCandidateRef>());
262 ids.push_back(cand_hasher_(&(*(cands[c]))));
267 if (src.isolationChargedHadrCands().isNonnull()) {
268 auto cands = src.isolationChargedHadrCands();
269 std::vector<std::size_t> ids;
270 for (
unsigned c = 0; c < cands.size(); ++c) {
271 cand_requests_slimmed->push_back(cands_handle->refAt(cands[c].key()).castTo<pat::PackedCandidateRef>());
272 ids.push_back(cand_hasher_(&(*(cands[c]))));
277 if (src.signalGammaCands().isNonnull()) {
278 auto cands = src.signalGammaCands();
279 std::vector<std::size_t> ids;
280 for (
unsigned c = 0; c < cands.size(); ++c) {
281 cand_requests_slimmed->push_back(cands_handle->refAt(cands[c].key()).castTo<pat::PackedCandidateRef>());
282 ids.push_back(cand_hasher_(&(*(cands[c]))));
287 if (src.isolationGammaCands().isNonnull()) {
288 auto cands = src.isolationGammaCands();
289 std::vector<std::size_t> ids;
290 for (
unsigned c = 0; c < cands.size(); ++c) {
291 cand_requests_slimmed->push_back(cands_handle->refAt(cands[c].key()).castTo<pat::PackedCandidateRef>());
292 ids.push_back(cand_hasher_(&(*(cands[c]))));
300 if (request_cands_) {
302 #if CMSSW_MAJOR_VERSION >= 7
303 event.put(cand_requests_slimmed,
"requestedPFCandidates");
306 event.put(cand_requests,
"requestedPFCandidates");
319 std::cout << std::string(78,
'-') <<
"\n";
320 std::cout << boost::format(
"%-56s %20s\n")
321 % std::string(
"Tau Discriminators") % std::string(
"Hash Summmary");
322 std::map<std::string, std::size_t>::const_iterator iter;
323 for (iter = observed_id_.begin(); iter != observed_id_.end(); ++iter) {
324 std::cout << boost::format(
"%-56s| %020i\n") % iter->first % iter->second;
void set_iso_gamma_cands(std::vector< std::size_t > const &iso_gamma_cands)
A vector referring to the isolation PFCandidates.
void set_lead_ecal_energy(float const &lead_ecal_energy)
ECAL energy of the leading charged PF constituent.
void SetTauID(std::string const &name, float const &value)
Add a new entry, overwriting any existing one with the same name.
uint64 CityHash64(const char *buf, size_t len)
void set_sig_gamma_cands(std::vector< std::size_t > const &sig_gamma_cands)
A vector referring to the isolation PFCandidates.
void set_lead_hcal_energy(float const &lead_hcal_energy)
HCAL energy of the leading charged PF constituent.
void set_lead_dz_vertex(float const &lead_dz_vertex)
Longitudinal impact parameter of the leading charged constituent track with the primary vertex...
void set_phi(double const &phi)
Direct access to .
void set_constituent_tracks(std::vector< std::size_t > const &constituent_tracks)
A vector referring to the constituent track ic::Track::id()
void set_sig_charged_cands(std::vector< std::size_t > const &sig_charged_cands)
A vector referring to the isolation PFCandidates.
void set_id(std::size_t const &id)
Unique identifier.
void set_lead_p(float const &lead_p)
Momentum of the leading charged PF constituent.
void set_charge(int const &charge)
Electric charge.
void set_vz(double const &z)
The z-coordinate of the leading track PCA.
void set_vy(double const &y)
The y-coordinate of the leading track PCA.
void set_vx(double const &x)
The x-coordinate of the leading track PCA.
void set_energy(double const &energy)
Direct access to the energy.
void set_lead_dxy_vertex(float const &lead_dxy_vertex)
Transverse impact parameter of the leading charged constituent track with the primary vertex...
void set_decay_mode(int const &decay_mode)
The tau decay mode identifier.
void set_pt(double const &pt)
Direct access to the .
void set_eta(double const &eta)
Direct access to .
void set_iso_charged_cands(std::vector< std::size_t > const &iso_charged_cands)
A vector referring to the isolation PFCandidates.
ICTauProducer(const edm::ParameterSet &)
This class stores a subset of the reco::PFTau properties which are most commonly used in analysis...