1 #ifndef PAT_SMEAREDJETPRODUCERT_H 2 #define PAT_SMEAREDJETPRODUCERT_H 51 desc.add<
double>(
"dRMax");
52 desc.add<
double>(
"dPtMaxFactor");
68 for (
const auto& genJet :
genJets) {
80 matched_genJet = &genJet;
84 return matched_genJet;
125 std::uint32_t
seed =
cfg.getParameter<std::uint32_t>(
"seed");
132 std::int32_t
variation =
cfg.getParameter<std::int32_t>(
"variation");
149 "Invalid value for 'variation' parameter. Only -1, 0, 1 or 101, -101 are supported.");
152 produces<JetCollection>();
159 desc.add<
bool>(
"enabled");
161 desc.add<std::int32_t>(
"variation", 0);
163 desc.add<std::uint32_t>(
"seed", 37428479);
164 desc.add<
bool>(
"skipGenMatching",
false);
165 desc.add<
bool>(
"useDeterministicSeed",
true);
166 desc.addUntracked<
bool>(
"debug",
false);
208 unsigned int runNum_uint =
static_cast<unsigned int>(
event.id().run());
209 unsigned int lumiNum_uint =
static_cast<unsigned int>(
event.id().luminosityBlock());
210 unsigned int evNum_uint =
static_cast<unsigned int>(
event.id().event());
211 unsigned int jet0eta = uint32_t(
jets.empty() ? 0 :
jets[0].eta() / 0.01);
212 std::uint32_t
seed = jet0eta +
m_nomVar + (lumiNum_uint << 10) + (runNum_uint << 20) + evNum_uint;
220 auto smearedJets = std::make_unique<JetCollection>();
225 smearedJets->push_back(
jet);
230 double jet_resolution =
resolution.getResolution(
237 std::cout <<
"jet: pt: " <<
jet.pt() <<
" eta: " <<
jet.eta() <<
" phi: " <<
jet.phi()
238 <<
" e: " <<
jet.energy() << std::endl;
239 std::cout <<
"resolution: " << jet_resolution << std::endl;
240 std::cout <<
"resolution scale factor: " << jer_sf << std::endl;
247 double smearFactor = 1.;
255 std::cout <<
"gen jet: pt: " << genJet->
pt() <<
" eta: " << genJet->
eta() <<
" phi: " << genJet->
phi()
256 <<
" e: " << genJet->
energy() << std::endl;
259 double dPt =
jet.pt() - genJet->
pt();
260 smearFactor = 1 +
m_nomVar * (jer_sf - 1.) * dPt /
jet.pt();
262 }
else if (jer_sf > 1) {
267 double sigma = jet_resolution *
std::sqrt(jer_sf * jer_sf - 1);
269 std::cout <<
"gaussian width: " << sigma << std::endl;
272 std::normal_distribution<>
d(0, sigma);
275 std::cout <<
"Impossible to smear this jet" << std::endl;
284 std::cout <<
"The smearing factor (" << smearFactor <<
") is either negative or too small. Fixing it to " 285 << newSmearFactor <<
" to avoid change of direction." << std::endl;
287 smearFactor = newSmearFactor;
291 smearedJet.scaleEnergy(smearFactor);
294 std::cout <<
"smeared jet (" << smearFactor <<
"): pt: " << smearedJet.pt() <<
" eta: " << smearedJet.eta()
295 <<
" phi: " << smearedJet.phi() <<
" e: " << smearedJet.energy() << std::endl;
298 smearedJets->push_back(smearedJet);
edm::EDGetTokenT< JetCollection > m_jets_token
static constexpr const double MIN_JET_ENERGY
static const JetResolutionScaleFactor get(const edm::EventSetup &, const Token &)
void getTokens(const edm::Event &event)
double pt() const final
transverse momentum
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::Handle< reco::GenJetCollection > m_genJets
std::vector< GenJet > GenJetCollection
collection of GenJet objects
GenJetMatcher(const edm::ParameterSet &cfg, edm::ConsumesCollector &&collector)
SmearedJetProducerT(const edm::ParameterSet &cfg)
std::string m_uncertaintySource
GreaterByPt< T > jetPtComparator
const reco::GenJet * match(const T &jet, double resolution)
JME::JetResolutionScaleFactor::Token m_jets_algo_token
std::unique_ptr< JME::JetResolution > m_resolution_from_file
void produce(edm::Event &event, const edm::EventSetup &setup) override
static void fillDescriptions(edm::ParameterSetDescription &desc)
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< T > JetCollection
float getScaleFactor(const JetParameters ¶meters, Variation variation=Variation::NOMINAL, std::string uncertaintySource="") const
std::string m_jets_algo_pt
bool m_useDeterministicSeed
Abs< T >::type abs(const T &t)
Jets made from MC generator particles.
edm::EDGetTokenT< double > m_rho_token
std::mt19937 m_random_generator
Variation m_systematic_variation
std::shared_ptr< pat::GenJetMatcher > m_genJetMatcher
std::unique_ptr< JME::JetResolutionScaleFactor > m_scale_factor_from_file
edm::EDGetTokenT< reco::GenJetCollection > m_genJetsToken
double phi() const final
momentum azimuthal angle
static std::string const source
JME::JetResolution::Token m_jets_algo_pt_token
static const JetResolution get(const edm::EventSetup &, const Token &)
double energy() const final
energy
double eta() const final
momentum pseudorapidity