1 #ifndef PAT_SMEAREDJETPRODUCERT_H 2 #define PAT_SMEAREDJETPRODUCERT_H 44 m_dR_max(cfg.getParameter<double>(
"dRMax")),
51 desc.
add<
double>(
"dRMax");
52 desc.
add<
double>(
"dPtMaxFactor");
70 for (
const auto& genJet: genJets) {
77 double dPt =
std::abs(genJet.pt() - jet.pt());
82 matched_genJet = &genJet;
86 return matched_genJet;
105 m_enabled(cfg.getParameter<bool>(
"enabled")),
106 m_debug(cfg.getUntrackedParameter<bool>(
"debug",
false)) {
113 m_use_txt_files = cfg.
exists(
"resolutionFile") && cfg.
exists(
"scaleFactorFile");
115 if (m_use_txt_files) {
127 m_random_generator = std::mt19937(seed);
130 if (! skipGenMatching)
131 m_genJetMatcher = std::make_shared<pat::GenJetMatcher>(
cfg, consumesCollector());
133 std::int32_t
variation = cfg.getParameter<std::int32_t>(
"variation");
137 else if (variation == 1)
139 else if (variation == -1)
141 else if (variation == 101) {
145 else if (variation == -101) {
153 produces<JetCollection>();
160 desc.
add<
bool>(
"enabled");
162 desc.
add<std::int32_t>(
"variation", 0);
163 desc.
add<std::uint32_t>(
"seed", 37428479);
164 desc.
add<
bool>(
"skipGenMatching",
false);
180 event.getByToken(m_jets_token, jets_collection);
185 m_genJetMatcher.reset();
190 event.getByToken(m_rho_token, rho);
196 if (m_use_txt_files) {
197 resolution = *m_resolution_from_file;
198 resolution_sf = *m_scale_factor_from_file;
208 m_genJetMatcher->getTokens(event);
210 auto smearedJets = std::make_unique<JetCollection>();
212 for (
const auto&
jet: jets) {
214 if ((! m_enabled) || (
jet.pt() == 0)) {
216 smearedJets->push_back(
jet);
225 std::cout <<
"jet: pt: " <<
jet.pt() <<
" eta: " <<
jet.eta() <<
" phi: " <<
jet.phi() <<
" e: " <<
jet.energy() << std::endl;
226 std::cout <<
"resolution: " << jet_resolution << std::endl;
227 std::cout <<
"resolution scale factor: " << jer_sf << std::endl;
232 genJet = m_genJetMatcher->match(
jet,
jet.pt() * jet_resolution);
234 double smearFactor = 1.;
242 std::cout <<
"gen jet: pt: " << genJet->
pt() <<
" eta: " << genJet->
eta() <<
" phi: " << genJet->
phi() <<
" e: " << genJet->
energy() << std::endl;
245 double dPt =
jet.pt() - genJet->
pt();
246 smearFactor = 1 + m_nomVar*(jer_sf - 1.) * dPt /
jet.pt();
248 }
else if (jer_sf > 1) {
255 std::cout <<
"gaussian width: " << sigma << std::endl;
258 std::normal_distribution<>
d(0, sigma);
259 smearFactor = 1. + m_nomVar*
d(m_random_generator);
260 }
else if (m_debug) {
261 std::cout <<
"Impossible to smear this jet" << std::endl;
264 if (
jet.energy() * smearFactor < MIN_JET_ENERGY) {
268 double newSmearFactor = MIN_JET_ENERGY /
jet.energy();
270 std::cout <<
"The smearing factor (" << smearFactor <<
") is either negative or too small. Fixing it to " << newSmearFactor <<
" to avoid change of direction." << std::endl;
272 smearFactor = newSmearFactor;
276 smearedJet.scaleEnergy(smearFactor);
279 std::cout <<
"smeared jet (" << smearFactor <<
"): pt: " << smearedJet.pt() <<
" eta: " << smearedJet.eta() <<
" phi: " << smearedJet.phi() <<
" e: " << smearedJet.energy() << std::endl;
282 smearedJets->push_back(smearedJet);
286 std::sort(smearedJets->begin(), smearedJets->end(), jetPtComparator);
edm::EDGetTokenT< JetCollection > m_jets_token
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
float getResolution(const JetParameters ¶meters) const
void getTokens(const edm::Event &event)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static const JetResolution get(const edm::EventSetup &, const std::string &)
virtual double eta() const final
momentum pseudorapidity
edm::Handle< reco::GenJetCollection > m_genJets
std::vector< GenJet > GenJetCollection
collection of GenJet objects
virtual void produce(edm::Event &event, const edm::EventSetup &setup) override
GenJetMatcher(const edm::ParameterSet &cfg, edm::ConsumesCollector &&collector)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
SmearedJetProducerT(const edm::ParameterSet &cfg)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
def setup(process, global_tag, zero_tesla=False)
GreaterByPt< T > jetPtComparator
const reco::GenJet * match(const T &jet, double resolution)
virtual double phi() const final
momentum azimuthal angle
std::unique_ptr< JME::JetResolution > m_resolution_from_file
static void fillDescriptions(edm::ParameterSetDescription &desc)
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< T > JetCollection
std::string m_jets_algo_pt
virtual double energy() const final
energy
Abs< T >::type abs(const T &t)
Jets made from MC generator particles.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< double > m_rho_token
double deltaR(double eta1, double eta2, double phi1, double phi2)
std::mt19937 m_random_generator
float getScaleFactor(const JetParameters ¶meters, Variation variation=Variation::NOMINAL) const
Variation m_systematic_variation
static const JetResolutionScaleFactor get(const edm::EventSetup &, const std::string &)
std::shared_ptr< pat::GenJetMatcher > m_genJetMatcher
std::unique_ptr< JME::JetResolutionScaleFactor > m_scale_factor_from_file
edm::EDGetTokenT< reco::GenJetCollection > m_genJetsToken
static std::string const source