1 #ifndef UserCode_ICHiggsTauTau_ICJetSrcHelper_h
2 #define UserCode_ICHiggsTauTau_ICJetSrcHelper_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/JetReco/interface/CaloJet.h"
12 #include "DataFormats/JetReco/interface/PFJet.h"
13 #include "DataFormats/TrackReco/interface/TrackFwd.h"
14 #include "PhysicsTools/SelectorUtils/interface/JetIDSelectionFunctor.h"
15 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 6)
16 #include "JetMETCorrections/Modules/interface/CorrectedJetProducer.h"
18 #include "JetMETCorrections/Objects/interface/JetCorrector.h"
20 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
50 config.getParameter<
edm::InputTag>(
"inputJetFlavour")),
54 cut(config.getParameter<
std::string>(
"cutAfterJECs")),
60 collector.consumes<reco::SecondaryVertexTagInfoCollection>(
input_sv_info);
62 edm::ParameterSet pset = config.getParameter<edm::ParameterSet>(
"JECs");
63 std::vector<std::string> vec =
64 pset.getParameterNamesForType<std::string>();
65 for (
unsigned i = 0; i < vec.size(); ++i) {
67 std::make_pair(vec[i], pset.getParameter<std::string>(vec[i])));
68 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION ==7 && CMSSW_MINOR_VERSION >= 6 )
69 collector.consumes<reco::JetCorrector>(
jecs[i].second);
71 collector.consumes<
double>(
jecs[i].second);
75 edm::ParameterSet btag_pset =
76 config.getParameter<edm::ParameterSet>(
"BTagDiscriminators");
77 std::vector<std::string> btag_vec =
78 btag_pset.getParameterNamesForType<edm::InputTag>();
79 for (
unsigned i = 0; i < btag_vec.size(); ++i) {
81 btag_vec[i], btag_pset.getParameter<edm::InputTag>(btag_vec[i])));
82 collector.consumes<reco::JetFloatAssociation::Container>(
input_btags[i].second);
88 prod->produces<reco::SecondaryVertexTagInfoRefVector>(
"requestedSVInfo");
99 void Produce(edm::Handle<edm::View<U> >
const &jets_handle,
100 std::vector<T> *jets, std::vector<unsigned> *passed,
101 edm::Event &event,
const edm::EventSetup &setup) {
102 edm::Handle<edm::ValueMap<std::vector<int>> > jet_flavour_handle;
105 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 6 )
106 std::vector<reco::JetCorrector const *> correctors(
jecs.size(), NULL);
108 std::vector<JetCorrector const*> correctors(
jecs.size(), NULL);
110 for (
unsigned i = 0; i < correctors.size(); ++i) {
111 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 6)
112 edm::Handle<reco::JetCorrector> corrector_handle;
113 event.getByLabel(
jecs[i].second,corrector_handle);
114 correctors[i] = corrector_handle.product();
116 correctors[i] = JetCorrector::getJetCorrector(
jecs[i].second, setup);
120 edm::Handle<reco::SecondaryVertexTagInfoCollection> sv_info_handle;
125 std::vector<edm::Handle<reco::JetFloatAssociation::Container> >
127 for (
unsigned i = 0; i < btag_handles.size(); ++i) {
128 event.getByLabel(
input_btags[i].second, btag_handles[i]);
131 std::auto_ptr<reco::SecondaryVertexTagInfoRefVector> sv_info_requests(
132 new reco::SecondaryVertexTagInfoRefVector());
134 for (
unsigned i = 0; i < jets_handle->size(); ++i) {
135 U
const &src = jets_handle->at(i);
136 double full_jec_factor = 1.0;
137 std::vector<float> factors(correctors.size(), 0.);
138 bool keep_jet =
true;
140 if (correctors.size() > 0) {
142 U jet_cpy = jets_handle->at(i);
144 for (
unsigned j = 0; j < correctors.size(); ++j) {
145 #ifndef CMSSW_4_2_8_patch7
146 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION ==7 && CMSSW_MINOR_VERSION >= 6)
147 double factor = correctors[j]->correction(jet_cpy);
149 double factor = correctors[j]->correction(jet_cpy, event, setup);
152 double factor = correctors[j]->correction(jet_cpy,
153 edm::RefToBase<reco::Jet>(jets_handle->refAt(i)), event, setup);
157 jet_cpy.scaleEnergy(factor);
163 passed->push_back(i);
168 jets->push_back(T());
169 T &dest = jets->back();
172 dest.set_pt(src.pt() * full_jec_factor);
173 dest.set_eta(src.eta());
174 dest.set_phi(src.phi());
175 dest.set_energy(src.energy() * full_jec_factor);
176 dest.set_charge(src.charge());
177 dest.set_jet_area(src.jetArea());
179 dest.set_parton_flavour((*jet_flavour_handle)[jets_handle->refAt(i)].at(0));
180 dest.set_hadron_flavour((*jet_flavour_handle)[jets_handle->refAt(i)].at(1));
184 for (
unsigned j = 0; j < correctors.size(); ++j) {
185 dest.SetJecFactor(
jecs[j].first, factors[j]);
190 for (
unsigned iS = 0; iS < sv_info_handle->size(); ++iS) {
191 if (&src == (*sv_info_handle)[iS].jet().get()) {
192 reco::SecondaryVertexTagInfoRef ref(sv_info_handle, iS);
193 sv_info_requests->push_back(ref);
194 std::vector<std::size_t> jet_sv_ids;
195 for (
unsigned iV = 0; iV < (*sv_info_handle)[iS].nVertices();
197 reco::Vertex
const &sv =
198 (*sv_info_handle)[iS].secondaryVertex(iV);
201 dest.set_secondary_vertices(jet_sv_ids);
206 for (
unsigned iB = 0; iB < btag_handles.size(); ++iB) {
208 (*btag_handles[iB])[edm::RefToBase<reco::Jet>(
209 jets_handle->refAt(i))]);
213 event.put(sv_info_requests,
"requestedSVInfo");
223 std::vector<std::pair<std::string, std::string> >
jecs;
227 StringCutObjectSelector<U>
cut;
253 is_slimmed(config.getParameter<bool>(
"isSlimmed")),
254 slimmed_puid_label(config.getParameter<
std::string>(
"slimmedPileupIDLabel")) {
255 collector.consumes<reco::SecondaryVertexTagInfoCollection>(
input_sv_info);
259 prod->produces<reco::SecondaryVertexTagInfoRefVector>(
"requestedSVInfo");
268 void Produce(edm::Handle<edm::View<pat::Jet> >
const &jets_handle,
269 std::vector<T> *jets, std::vector<unsigned> *passed,
270 edm::Event &event,
const edm::EventSetup &setup) {
271 edm::Handle<reco::SecondaryVertexTagInfoCollection> sv_info_handle;
276 std::auto_ptr<reco::SecondaryVertexTagInfoRefVector> sv_info_requests(
277 new reco::SecondaryVertexTagInfoRefVector());
279 for (
unsigned i = 0; i < jets_handle->size(); ++i) {
280 pat::Jet
const &src = jets_handle->at(i);
281 passed->push_back(i);
282 jets->push_back(T());
283 T &dest = jets->back();
286 dest.set_pt(src.pt());
287 dest.set_eta(src.eta());
288 dest.set_phi(src.phi());
289 dest.set_energy(src.energy());
290 dest.set_charge(src.charge());
291 dest.set_jet_area(src.jetArea());
293 dest.set_parton_flavour(src.partonFlavour());
294 dest.set_hadron_flavour(src.hadronFlavour());
298 std::vector<std::string> jec_levels = src.availableJECLevels();
299 for (
unsigned j = 1; j < jec_levels.size(); ++j) {
302 src.jecFactor(jec_levels[j]) / src.jecFactor(jec_levels[j - 1]));
307 for (
unsigned iS = 0; iS < sv_info_handle->size(); ++iS) {
308 if (&(*(src.originalObjectRef())) ==
309 (*sv_info_handle)[iS].jet().get()) {
310 reco::SecondaryVertexTagInfoRef ref(sv_info_handle, iS);
311 sv_info_requests->push_back(ref);
312 std::vector<std::size_t> jet_sv_ids;
313 for (
unsigned iV = 0; iV < (*sv_info_handle)[iS].nVertices();
315 reco::Vertex
const &sv =
316 (*sv_info_handle)[iS].secondaryVertex(iV);
319 dest.set_secondary_vertices(jet_sv_ids);
324 for (
unsigned iB = 0; iB < src.getPairDiscri().size(); ++iB) {
325 dest.SetBDiscriminator(src.getPairDiscri().at(iB).first,
326 src.getPairDiscri().at(iB).second);
330 event.put(sv_info_requests,
"requestedSVInfo");
void DoSetup(edm::EDProducer *prod)
std::vector< std::pair< std::string, edm::InputTag > > input_btags
void DoSetup(edm::EDProducer *prod)
JetSrcHelper(const edm::ParameterSet &config, edm::ConsumesCollector &&collector)
boost::hash< U const * > jet_hasher
std::string slimmed_puid_label
A struct to help with the configuration of the ICJetProducer, in particular the aspects that depend o...
edm::InputTag input_sv_info
void Produce(edm::Handle< edm::View< pat::Jet > > const &jets_handle, std::vector< T > *jets, std::vector< unsigned > *passed, edm::Event &event, const edm::EventSetup &setup)
boost::hash< reco::Vertex const * > vertex_hasher
std::vector< std::pair< std::string, std::string > > jecs
JetSrcHelper(const edm::ParameterSet &config, edm::ConsumesCollector &&collector)
boost::hash< reco::Vertex const * > vertex_hasher
boost::hash< pat::Jet const * > jet_hasher
edm::InputTag input_jet_flavour
edm::InputTag input_sv_info
void Produce(edm::Handle< edm::View< U > > const &jets_handle, std::vector< T > *jets, std::vector< unsigned > *passed, edm::Event &event, const edm::EventSetup &setup)
StringCutObjectSelector< U > cut