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")),
107 m_debug(cfg.getUntrackedParameter<bool>(
"debug",
false)) {
130 bool skipGenMatching = cfg.
getParameter<
bool>(
"skipGenMatching");
131 if (! skipGenMatching)
134 std::int32_t variation = cfg.getParameter<std::int32_t>(
"variation");
137 else if (variation == 1)
139 else if (variation == -1)
145 produces<JetCollection>();
152 desc.
add<
bool>(
"enabled");
154 desc.
add<std::int32_t>(
"variation", 0);
155 desc.
add<std::uint32_t>(
"seed", 37428479);
156 desc.
add<
bool>(
"skipGenMatching",
false);
157 desc.
add<
bool>(
"useDeterministicSeed",
true);
200 unsigned int runNum_uint = static_cast <
unsigned int> (
event.id().run());
201 unsigned int lumiNum_uint = static_cast <
unsigned int> (
event.id().luminosityBlock());
202 unsigned int evNum_uint = static_cast <
unsigned int> (
event.id().event());
203 unsigned int jet0eta = uint32_t(jets.empty() ? 0 : jets[0].eta()/0.01);
204 std::uint32_t
seed = jet0eta + (lumiNum_uint<<10) + (runNum_uint<<20) + evNum_uint;
212 std::unique_ptr<JetCollection> smearedJets(
new JetCollection());
214 for (
const auto&
jet: jets) {
218 smearedJets->push_back(
jet);
227 std::cout <<
"jet: pt: " <<
jet.pt() <<
" eta: " <<
jet.eta() <<
" phi: " <<
jet.phi() <<
" e: " <<
jet.energy() << std::endl;
228 std::cout <<
"resolution: " << jet_resolution << std::endl;
229 std::cout <<
"resolution scale factor: " << jer_sf << std::endl;
236 double smearFactor = 1.;
244 std::cout <<
"gen jet: pt: " << genJet->
pt() <<
" eta: " << genJet->
eta() <<
" phi: " << genJet->
phi() <<
" e: " << genJet->
energy() << std::endl;
247 double dPt =
jet.pt() - genJet->
pt();
248 smearFactor = 1 + (jer_sf - 1.) * dPt /
jet.pt();
250 }
else if (jer_sf > 1) {
255 double sigma = jet_resolution *
std::sqrt(jer_sf * jer_sf - 1);
257 std::cout <<
"gaussian width: " << sigma << std::endl;
260 std::normal_distribution<>
d(0, sigma);
263 std::cout <<
"Impossible to smear this jet" << std::endl;
272 std::cout <<
"The smearing factor (" << smearFactor <<
") is either negative or too small. Fixing it to " << newSmearFactor <<
" to avoid change of direction." << std::endl;
274 smearFactor = newSmearFactor;
278 smearedJet.scaleEnergy(smearFactor);
281 std::cout <<
"smeared jet (" << smearFactor <<
"): pt: " << smearedJet.pt() <<
" eta: " << smearedJet.eta() <<
" phi: " << smearedJet.phi() <<
" e: " << smearedJet.energy() << std::endl;
284 smearedJets->push_back(smearedJet);
edm::EDGetTokenT< JetCollection > m_jets_token
T getParameter(std::string const &) const
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)
virtual double energy() const final
energy
static const JetResolution get(const edm::EventSetup &, const std::string &)
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)
virtual double phi() const final
momentum azimuthal angle
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
GreaterByPt< T > jetPtComparator
const reco::GenJet * match(const T &jet, double resolution)
std::unique_ptr< JME::JetResolution > m_resolution_from_file
static void fillDescriptions(edm::ParameterSetDescription &desc)
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< T > JetCollection
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::string m_jets_algo_pt
bool m_useDeterministicSeed
Abs< T >::type abs(const T &t)
Jets made from MC generator particles.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
edm::EDGetTokenT< double > m_rho_token
static const double MIN_JET_ENERGY
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
virtual double eta() const final
momentum pseudorapidity
volatile std::atomic< bool > shutdown_flag false
static std::string const source
virtual double pt() const final
transverse momentum