1 #ifndef UserCode_ICHiggsTauTau_ICJetProducer_h
2 #define UserCode_ICHiggsTauTau_ICJetProducer_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 "FWCore/Utilities/interface/InputTag.h"
13 #include "DataFormats/Math/interface/deltaR.h"
14 #include "DataFormats/JetReco/interface/CaloJet.h"
15 #include "DataFormats/JetReco/interface/PFJet.h"
16 #include "DataFormats/JetReco/interface/JPTJet.h"
17 #include "DataFormats/PatCandidates/interface/Jet.h"
18 #include "DataFormats/JetReco/interface/JetID.h"
19 #include "DataFormats/BTauReco/interface/JetTag.h"
20 #include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h"
21 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
22 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
39 template <
class T,
class U>
46 virtual void beginJob();
47 virtual void produce(edm::Event &,
const edm::EventSetup &);
48 virtual void endJob();
49 void constructSpecific(edm::Handle<edm::View<U> >
const& jets_handle,
50 edm::Event& event,
const edm::EventSetup& setup);
52 std::vector<T> *jets_;
56 std::vector<unsigned> passed_;
66 template <
class T,
class U>
68 : input_(config.getParameter<
edm::InputTag>(
"input")),
69 branch_(config.getParameter<
std::string>(
"branch")),
72 consumes<edm::View<U>>(input_);
73 jets_ =
new std::vector<T>();
83 template <
class T,
class U>
90 template <
class T,
class U>
92 const edm::EventSetup& setup) {
94 edm::Handle<edm::View<U> > jets_handle;
95 event.getByLabel(input_, jets_handle);
99 jets_->reserve(jets_handle->size());
100 passed_.reserve(jets_handle->size());
102 src_.Produce(jets_handle, jets_, &passed_, event, setup);
104 constructSpecific(jets_handle, event, setup);
111 template <
class T,
class U>
113 edm::Handle<edm::View<U> >
const& jets_handle, edm::Event& event,
114 const edm::EventSetup& setup) {}
122 edm::Handle<edm::View<reco::CaloJet> >
const& jets_handle,
123 edm::Event& event,
const edm::EventSetup& setup) {
126 edm::Handle<reco::JetIDValueMap> jet_id_handle;
127 if (dest_.do_jet_id)
event.getByLabel(dest_.input_jet_id, jet_id_handle);
128 for (
unsigned i = 0; i < passed_.size(); ++i) {
129 reco::CaloJet
const& src = jets_handle->at(passed_[i]);
132 if (dest_.do_n_carrying) {
138 if (dest_.do_jet_id) {
139 reco::JetID
const& jet_id =
140 (*jet_id_handle)[jets_handle->refAt(passed_[i])];
154 edm::Handle<edm::View<pat::Jet> >
const& jets_handle,
155 edm::Event& event,
const edm::EventSetup& setup) {
157 for (
unsigned i = 0; i < passed_.size(); ++i) {
158 pat::Jet
const& src = jets_handle->at(passed_[i]);
161 if (dest_.do_n_carrying) {
167 (src.jecSetsAvailable() ? src.jecFactor(0) : 1.) * src.energy());
168 if (dest_.do_jet_id) {
182 edm::Handle<edm::View<reco::JPTJet> >
const& jets_handle,
183 edm::Event& event,
const edm::EventSetup& setup) {
185 edm::Handle<reco::JetIDValueMap> jet_id_handle;
186 if (dest_.do_jet_id)
event.getByLabel(dest_.input_jet_id, jet_id_handle);
188 edm::Handle<reco::TrackCollection> trk_handle;
189 edm::Handle<reco::VertexCollection> vtx_handle;
190 std::map<unsigned, unsigned> trk_vtx_map;
192 std::auto_ptr<reco::TrackRefVector> track_requests(
193 new reco::TrackRefVector());
195 if (dest_.do_trk_vars) {
196 event.getByLabel(dest_.input_trks, trk_handle);
197 event.getByLabel(dest_.input_vtxs, vtx_handle);
201 for (
unsigned i = 0; i < passed_.size(); ++i) {
202 reco::JPTJet
const& src = jets_handle->at(passed_[i]);
204 reco::CaloJetRef calo(src.getCaloJetRef().castTo<reco::CaloJetRef>());
207 if (dest_.do_n_carrying) {
214 if (dest_.do_jet_id) {
215 reco::JetID
const& jet_id = (*jet_id_handle)[calo];
220 if (dest_.request_trks) {
222 src.getPionsInVertexInCalo(), track_requests.get()));
224 src.getPionsInVertexOutCalo(), track_requests.get()));
226 src.getPionsOutVertexInCalo(), track_requests.get()));
228 src.getMuonsInVertexInCalo(), track_requests.get()));
230 src.getMuonsInVertexOutCalo(), track_requests.get()));
232 src.getMuonsOutVertexInCalo(), track_requests.get()));
234 src.getElecsInVertexInCalo(), track_requests.get()));
236 src.getElecsInVertexOutCalo(), track_requests.get()));
238 src.getElecsOutVertexInCalo(), track_requests.get()));
241 if (dest_.do_trk_vars && trk_handle->size() > 0) {
242 std::vector<reco::Track const*> all_tracks;
243 dest_.AddTrackCollection(src.getPionsInVertexInCalo(), &all_tracks);
244 dest_.AddTrackCollection(src.getPionsInVertexOutCalo(), &all_tracks);
245 dest_.AddTrackCollection(src.getPionsOutVertexInCalo(), &all_tracks);
246 dest_.AddTrackCollection(src.getMuonsInVertexInCalo(), &all_tracks);
247 dest_.AddTrackCollection(src.getMuonsInVertexOutCalo(), &all_tracks);
248 dest_.AddTrackCollection(src.getMuonsOutVertexInCalo(), &all_tracks);
249 dest_.AddTrackCollection(src.getElecsInVertexInCalo(), &all_tracks);
250 dest_.AddTrackCollection(src.getElecsInVertexOutCalo(), &all_tracks);
251 dest_.AddTrackCollection(src.getElecsOutVertexInCalo(), &all_tracks);
255 if (dest_.request_trks) {
256 event.put(track_requests,
"requestedTracks");
265 edm::Handle<edm::View<pat::Jet> >
const& jets_handle,
266 edm::Event& event,
const edm::EventSetup& setup) {
268 edm::Handle<reco::TrackCollection> trk_handle;
269 edm::Handle<reco::VertexCollection> vtx_handle;
270 std::map<unsigned, unsigned> trk_vtx_map;
272 std::auto_ptr<reco::TrackRefVector> track_requests(
273 new reco::TrackRefVector());
275 if (dest_.do_trk_vars) {
276 event.getByLabel(dest_.input_trks, trk_handle);
277 event.getByLabel(dest_.input_vtxs, vtx_handle);
281 for (
unsigned i = 0; i < passed_.size(); ++i) {
282 pat::Jet
const& src = jets_handle->at(passed_[i]);
285 if (dest_.do_n_carrying) {
291 (src.jecSetsAvailable() ? src.jecFactor(0) : 1.) * src.energy());
292 if (dest_.do_jet_id) {
299 if (dest_.request_trks) {
301 src.pionsInVertexInCalo(), track_requests.get()));
303 src.pionsInVertexOutCalo(), track_requests.get()));
305 src.pionsOutVertexInCalo(), track_requests.get()));
307 src.muonsInVertexInCalo(), track_requests.get()));
309 src.muonsInVertexOutCalo(), track_requests.get()));
311 src.muonsOutVertexInCalo(), track_requests.get()));
313 src.elecsInVertexInCalo(), track_requests.get()));
315 src.elecsInVertexOutCalo(), track_requests.get()));
317 src.elecsOutVertexInCalo(), track_requests.get()));
320 if (dest_.do_trk_vars && trk_handle->size() > 0) {
321 std::vector<reco::Track const*> all_tracks;
322 dest_.AddTrackCollection(src.pionsInVertexInCalo(), &all_tracks);
323 dest_.AddTrackCollection(src.pionsInVertexOutCalo(), &all_tracks);
324 dest_.AddTrackCollection(src.pionsOutVertexInCalo(), &all_tracks);
325 dest_.AddTrackCollection(src.muonsInVertexInCalo(), &all_tracks);
326 dest_.AddTrackCollection(src.muonsInVertexOutCalo(), &all_tracks);
327 dest_.AddTrackCollection(src.muonsOutVertexInCalo(), &all_tracks);
328 dest_.AddTrackCollection(src.elecsInVertexInCalo(), &all_tracks);
329 dest_.AddTrackCollection(src.elecsInVertexOutCalo(), &all_tracks);
330 dest_.AddTrackCollection(src.elecsOutVertexInCalo(), &all_tracks);
334 if (dest_.request_trks) {
335 event.put(track_requests,
"requestedTracks");
344 edm::Handle<edm::View<reco::PFJet> >
const& jets_handle,
345 edm::Event& event,
const edm::EventSetup& setup) {
347 edm::Handle<edm::ValueMap<float> > pu_id_handle;
348 if (dest_.do_pu_id)
event.getByLabel(dest_.input_pu_id, pu_id_handle);
350 edm::Handle<reco::TrackCollection> trk_handle;
351 edm::Handle<reco::VertexCollection> vtx_handle;
352 std::map<unsigned, unsigned> trk_vtx_map;
354 std::auto_ptr<reco::TrackRefVector> track_requests(
355 new reco::TrackRefVector());
357 if (dest_.do_trk_vars) {
358 event.getByLabel(dest_.input_trks, trk_handle);
359 event.getByLabel(dest_.input_vtxs, vtx_handle);
363 for (
unsigned i = 0; i < passed_.size(); ++i) {
364 reco::PFJet
const& src = jets_handle->at(passed_[i]);
369 if (dest_.do_pu_id) {
373 if (dest_.request_trks) {
375 track_requests.get(), &(dest_.track_hasher));
378 if (dest_.do_trk_vars && trk_handle->size() > 0) {
379 if (dest_.do_trk_vars && trk_handle->size() > 0) {
380 FillPFTrackVars(&dest, src.getPFConstituents(), trk_handle, vtx_handle,
385 if (dest_.request_trks) {
386 event.put(track_requests,
"requestedTracks");
395 edm::Handle<edm::View<pat::Jet> >
const& jets_handle,
396 edm::Event& event,
const edm::EventSetup& setup) {
398 edm::Handle<edm::ValueMap<float> > pu_id_handle;
399 if (dest_.do_pu_id)
event.getByLabel(dest_.input_pu_id, pu_id_handle);
401 edm::Handle<reco::TrackCollection> trk_handle;
402 edm::Handle<reco::VertexCollection> vtx_handle;
403 std::map<unsigned, unsigned> trk_vtx_map;
405 std::auto_ptr<reco::TrackRefVector> track_requests(
406 new reco::TrackRefVector());
408 if (dest_.do_trk_vars) {
409 event.getByLabel(dest_.input_trks, trk_handle);
410 event.getByLabel(dest_.input_vtxs, vtx_handle);
414 for (
unsigned i = 0; i < passed_.size(); ++i) {
415 pat::Jet
const& src = jets_handle->at(passed_[i]);
419 (src.jecSetsAvailable() ? src.jecFactor(0) : 1.) * src.energy());
420 if (dest_.do_pu_id) {
421 if (src_.is_slimmed) {
426 (*pu_id_handle)[jets_handle->refAt(passed_[i])->originalObjectRef()]);
430 if (dest_.request_trks) {
432 track_requests.get(), &(dest_.track_hasher));
435 if (dest_.do_trk_vars && trk_handle->size() > 0) {
436 FillPFTrackVars(&dest, src.getPFConstituents(), trk_handle, vtx_handle,
440 if (dest_.request_trks) {
441 event.put(track_requests,
"requestedTracks");
445 template <
class T,
class U>
450 template <
class T,
class U>
void set_id_loose(bool const &id_loose)
Flag indicates if the jet passes the loose ID.
void set_id_tight(bool const &id_tight)
Flag indicates if the jet passes the tight ID.
void FillCommonPFJet(ic::PFJet *dest, U const &src)
void set_muons_in_vtx_in_calo(std::vector< std::size_t > const &muons_in_vtx_in_calo)
A vector of ic::Track::id() values for muons compatible with the jet both at the vertex and the calor...
void set_fRBX(float const &fRBX)
Fraction of energy carried by the "hottest" RBX (readout box)
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_pions_in_vtx_out_calo(std::vector< std::size_t > const &pions_in_vtx_out_calo)
A vector of ic::Track::id() values for pions compatible with the jet at the vertex but not at the cal...
void set_elecs_out_vtx_in_calo(std::vector< std::size_t > const &elecs_out_vtx_in_calo)
A vector of ic::Track::id() values for electrons compatible with the jet at the calorimeter but not a...
void set_n90(int const &n90)
Number of constituents carrying 90% of the jet energy.
void set_pions_in_vtx_in_calo(std::vector< std::size_t > const &pions_in_vtx_in_calo)
A vector of ic::Track::id() values for pions compatible with the jet both at the vertex and the calor...
A class derived from ic::Jet which adds Jet-plus-track specific information.
void FillCommonJPTJet(ic::JPTJet *dest, U const &src)
A struct to help with the configuration of the ICJetProducer, in particular the aspects that depend o...
ICJetProducer(const edm::ParameterSet &)
void DoSetup(edm::EDProducer *prod)
void set_pu_id_mva_value(float const &pu_id_mva_value)
The output of the pileup ID MVA.
void set_elecs_in_vtx_out_calo(std::vector< std::size_t > const &elecs_in_vtx_out_calo)
A vector of ic::Track::id() values for electrons compatible with the jet at the vertex but not at the...
void FillCommonCaloJet(ic::CaloJet *dest, U const &src)
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)
Derived from the ic::Jet class and adding information specific to calorimeter jets.
void set_elecs_in_vtx_in_calo(std::vector< std::size_t > const &elecs_in_vtx_in_calo)
A vector of ic::Track::id() values for electrons compatible with the jet both at the vertex and the c...
void set_muons_in_vtx_out_calo(std::vector< std::size_t > const &muons_in_vtx_out_calo)
A vector of ic::Track::id() values for muons compatible with the jet at the vertex but not at the cal...
A class deriving from ic::Jet that provides specific information for particle-flow jets...
void set_n60(int const &n60)
Number of constituents carrying 60% of the jet energy.
edm::ConsumesCollector consumesCollector()
void set_muons_out_vtx_in_calo(std::vector< std::size_t > const &muons_out_vtx_in_calo)
A vector of ic::Track::id() values for muons compatible with the jet at the calorimeter but not at th...
void set_fHPD(float const &fHPD)
Fraction of energy carried by the "hottest" HPD (hybrid photodiode)
std::map< unsigned, unsigned > BuildTrkVtxMap(edm::Handle< reco::TrackCollection > const &trk_handle, edm::Handle< reco::VertexCollection > const &vtx_handle)
void set_pions_out_vtx_in_calo(std::vector< std::size_t > const &pions_out_vtx_in_calo)
A vector of ic::Track::id() values for pions compatible with the jet at the calorimeter but not at th...
void set_uncorrected_energy(double const &uncorrected_energy)
The raw value of the jet energy.
void FillPFTracksAndRequest(ic::PFJet *dest, std::vector< reco::PFCandidatePtr > const &pfcands, reco::TrackRefVector *track_requests, boost::hash< reco::Track const * > *track_hasher)