CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes
SmearedJetProducerT< T > Class Template Reference

#include <SmearedJetProducerT.h>

Inheritance diagram for SmearedJetProducerT< T >:
edm::stream::EDProducer<>

Public Member Functions

void produce (edm::Event &event, const edm::EventSetup &setup) override
 
 SmearedJetProducerT (const edm::ParameterSet &cfg)
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

using JetCollection = std::vector< T >
 

Private Attributes

GreaterByPt< TjetPtComparator
 
bool m_debug
 
bool m_enabled
 
std::shared_ptr< pat::GenJetMatcherm_genJetMatcher
 
std::string m_jets_algo
 
std::string m_jets_algo_pt
 
edm::EDGetTokenT< JetCollectionm_jets_token
 
int m_nomVar
 
std::mt19937 m_random_generator
 
std::unique_ptr< JME::JetResolutionm_resolution_from_file
 
edm::EDGetTokenT< double > m_rho_token
 
std::unique_ptr< JME::JetResolutionScaleFactorm_scale_factor_from_file
 
Variation m_systematic_variation
 
std::string m_uncertaintySource
 
bool m_use_txt_files
 
bool m_useDeterministicSeed
 

Static Private Attributes

static constexpr const double MIN_JET_ENERGY = 1e-2
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

template<typename T>
class SmearedJetProducerT< T >

Produce collection of "smeared" jets.

The aim of this correction is to account for the difference in jet energy resolution between Monte Carlo simulation and Data.

Author
Sébastien Brochet

Definition at line 97 of file SmearedJetProducerT.h.

Member Typedef Documentation

◆ JetCollection

template<typename T >
using SmearedJetProducerT< T >::JetCollection = std::vector<T>
private

Definition at line 98 of file SmearedJetProducerT.h.

Constructor & Destructor Documentation

◆ SmearedJetProducerT()

template<typename T >
SmearedJetProducerT< T >::SmearedJetProducerT ( const edm::ParameterSet cfg)
inlineexplicit

Definition at line 101 of file SmearedJetProducerT.h.

102  : m_enabled(cfg.getParameter<bool>("enabled")),
103  m_useDeterministicSeed(cfg.getParameter<bool>("useDeterministicSeed")),
104  m_debug(cfg.getUntrackedParameter<bool>("debug", false)) {
105  m_jets_token = consumes<JetCollection>(cfg.getParameter<edm::InputTag>("src"));
106 
107  if (m_enabled) {
108  m_rho_token = consumes<double>(cfg.getParameter<edm::InputTag>("rho"));
109 
110  m_use_txt_files = cfg.exists("resolutionFile") && cfg.exists("scaleFactorFile");
111 
112  if (m_use_txt_files) {
113  std::string resolutionFile = cfg.getParameter<edm::FileInPath>("resolutionFile").fullPath();
114  std::string scaleFactorFile = cfg.getParameter<edm::FileInPath>("scaleFactorFile").fullPath();
115 
116  m_resolution_from_file.reset(new JME::JetResolution(resolutionFile));
117  m_scale_factor_from_file.reset(new JME::JetResolutionScaleFactor(scaleFactorFile));
118  } else {
119  m_jets_algo = cfg.getParameter<std::string>("algo");
120  m_jets_algo_pt = cfg.getParameter<std::string>("algopt");
121  }
122 
123  std::uint32_t seed = cfg.getParameter<std::uint32_t>("seed");
124  m_random_generator = std::mt19937(seed);
125 
126  bool skipGenMatching = cfg.getParameter<bool>("skipGenMatching");
127  if (!skipGenMatching)
128  m_genJetMatcher = std::make_shared<pat::GenJetMatcher>(cfg, consumesCollector());
129 
130  std::int32_t variation = cfg.getParameter<std::int32_t>("variation");
131  m_uncertaintySource = cfg.getParameter<std::string>("uncertaintySource");
132  m_nomVar = 1;
133  if (variation == 0)
135  else if (variation == 1)
137  else if (variation == -1)
139  else if (variation == 101) {
141  m_nomVar = 1;
142  } else if (variation == -101) {
144  m_nomVar = -1;
145  } else
147  "Invalid value for 'variation' parameter. Only -1, 0, 1 or 101, -101 are supported.");
148  }
149 
150  produces<JetCollection>();
151  }

References looper::cfg, edm::errors::ConfigFileReadError, DOWN, Exception, contentValuesFiles::fullPath, SmearedJetProducerT< T >::m_enabled, SmearedJetProducerT< T >::m_genJetMatcher, SmearedJetProducerT< T >::m_jets_algo, SmearedJetProducerT< T >::m_jets_algo_pt, SmearedJetProducerT< T >::m_jets_token, SmearedJetProducerT< T >::m_nomVar, SmearedJetProducerT< T >::m_random_generator, SmearedJetProducerT< T >::m_resolution_from_file, SmearedJetProducerT< T >::m_rho_token, SmearedJetProducerT< T >::m_scale_factor_from_file, SmearedJetProducerT< T >::m_systematic_variation, SmearedJetProducerT< T >::m_uncertaintySource, SmearedJetProducerT< T >::m_use_txt_files, NOMINAL, SurveyInfoScenario_cff::seed, patPFMETCorrections_cff::skipGenMatching, AlCaHLTBitMon_QueryRunRegistry::string, UP, and patPFMETCorrections_cff::variation.

Member Function Documentation

◆ fillDescriptions()

template<typename T >
static void SmearedJetProducerT< T >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 153 of file SmearedJetProducerT.h.

153  {
155 
156  desc.add<edm::InputTag>("src");
157  desc.add<bool>("enabled");
158  desc.add<edm::InputTag>("rho");
159  desc.add<std::int32_t>("variation", 0);
160  desc.add<std::string>("uncertaintySource", "");
161  desc.add<std::uint32_t>("seed", 37428479);
162  desc.add<bool>("skipGenMatching", false);
163  desc.add<bool>("useDeterministicSeed", true);
164  desc.addUntracked<bool>("debug", false);
165 
166  auto source = (edm::ParameterDescription<std::string>("algo", true) and
167  edm::ParameterDescription<std::string>("algopt", true)) xor
168  (edm::ParameterDescription<edm::FileInPath>("resolutionFile", true) and
169  edm::ParameterDescription<edm::FileInPath>("scaleFactorFile", true));
170  desc.addNode(std::move(source));
171 
173 
174  descriptions.addDefault(desc);
175  }

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addDefault(), edm::ParameterSetDescription::addNode(), edm::ParameterSetDescription::addUntracked(), pat::GenJetMatcher::fillDescriptions(), eostools::move(), source, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ produce()

template<typename T >
void SmearedJetProducerT< T >::produce ( edm::Event event,
const edm::EventSetup setup 
)
inlineoverride

Definition at line 177 of file SmearedJetProducerT.h.

177  {
178  edm::Handle<JetCollection> jets_collection;
179  event.getByToken(m_jets_token, jets_collection);
180 
181  // Disable the module when running on real data
182  if (m_enabled && event.isRealData()) {
183  m_enabled = false;
184  m_genJetMatcher.reset();
185  }
186 
188  if (m_enabled)
189  event.getByToken(m_rho_token, rho);
190 
192  JME::JetResolutionScaleFactor resolution_sf;
193 
194  const JetCollection& jets = *jets_collection;
195 
196  if (m_enabled) {
197  if (m_use_txt_files) {
199  resolution_sf = *m_scale_factor_from_file;
200  } else {
203  }
204 
206  unsigned int runNum_uint = static_cast<unsigned int>(event.id().run());
207  unsigned int lumiNum_uint = static_cast<unsigned int>(event.id().luminosityBlock());
208  unsigned int evNum_uint = static_cast<unsigned int>(event.id().event());
209  unsigned int jet0eta = uint32_t(jets.empty() ? 0 : jets[0].eta() / 0.01);
210  std::uint32_t seed = jet0eta + m_nomVar + (lumiNum_uint << 10) + (runNum_uint << 20) + evNum_uint;
211  m_random_generator.seed(seed);
212  }
213  }
214 
215  if (m_genJetMatcher)
216  m_genJetMatcher->getTokens(event);
217 
218  auto smearedJets = std::make_unique<JetCollection>();
219 
220  for (const auto& jet : jets) {
221  if ((!m_enabled) || (jet.pt() == 0)) {
222  // Module disabled or invalid p4. Simply copy the input jet.
223  smearedJets->push_back(jet);
224 
225  continue;
226  }
227 
228  double jet_resolution = resolution.getResolution(
230  double jer_sf = resolution_sf.getScaleFactor({{JME::Binning::JetPt, jet.pt()}, {JME::Binning::JetEta, jet.eta()}},
233 
234  if (m_debug) {
235  std::cout << "jet: pt: " << jet.pt() << " eta: " << jet.eta() << " phi: " << jet.phi()
236  << " e: " << jet.energy() << std::endl;
237  std::cout << "resolution: " << jet_resolution << std::endl;
238  std::cout << "resolution scale factor: " << jer_sf << std::endl;
239  }
240 
241  const reco::GenJet* genJet = nullptr;
242  if (m_genJetMatcher)
243  genJet = m_genJetMatcher->match(jet, jet.pt() * jet_resolution);
244 
245  double smearFactor = 1.;
246 
247  if (genJet) {
248  /*
249  * Case 1: we have a "good" gen jet matched to the reco jet
250  */
251 
252  if (m_debug) {
253  std::cout << "gen jet: pt: " << genJet->pt() << " eta: " << genJet->eta() << " phi: " << genJet->phi()
254  << " e: " << genJet->energy() << std::endl;
255  }
256 
257  double dPt = jet.pt() - genJet->pt();
258  smearFactor = 1 + m_nomVar * (jer_sf - 1.) * dPt / jet.pt();
259 
260  } else if (jer_sf > 1) {
261  /*
262  * Case 2: we don't have a gen jet. Smear jet pt using a random gaussian variation
263  */
264 
265  double sigma = jet_resolution * std::sqrt(jer_sf * jer_sf - 1);
266  if (m_debug) {
267  std::cout << "gaussian width: " << sigma << std::endl;
268  }
269 
270  std::normal_distribution<> d(0, sigma);
271  smearFactor = 1. + m_nomVar * d(m_random_generator);
272  } else if (m_debug) {
273  std::cout << "Impossible to smear this jet" << std::endl;
274  }
275 
276  if (jet.energy() * smearFactor < MIN_JET_ENERGY) {
277  // Negative or too small smearFactor. We would change direction of the jet
278  // and this is not what we want.
279  // Recompute the smearing factor in order to have jet.energy() == MIN_JET_ENERGY
280  double newSmearFactor = MIN_JET_ENERGY / jet.energy();
281  if (m_debug) {
282  std::cout << "The smearing factor (" << smearFactor << ") is either negative or too small. Fixing it to "
283  << newSmearFactor << " to avoid change of direction." << std::endl;
284  }
285  smearFactor = newSmearFactor;
286  }
287 
288  T smearedJet = jet;
289  smearedJet.scaleEnergy(smearFactor);
290 
291  if (m_debug) {
292  std::cout << "smeared jet (" << smearFactor << "): pt: " << smearedJet.pt() << " eta: " << smearedJet.eta()
293  << " phi: " << smearedJet.phi() << " e: " << smearedJet.energy() << std::endl;
294  }
295 
296  smearedJets->push_back(smearedJet);
297  }
298 
299  // Sort jets by pt
300  std::sort(smearedJets->begin(), smearedJets->end(), jetPtComparator);
301 
302  event.put(std::move(smearedJets));
303  }

References gather_cfg::cout, ztail::d, reco::LeafCandidate::energy(), reco::LeafCandidate::eta(), JME::JetResolution::get(), JME::JetResolutionScaleFactor::get(), JME::JetResolutionScaleFactor::getScaleFactor(), metsig::jet, JME::JetEta, JME::JetPt, SmearedJetProducerT< T >::jetPtComparator, singleTopDQM_cfi::jets, SmearedJetProducerT< T >::m_debug, SmearedJetProducerT< T >::m_enabled, SmearedJetProducerT< T >::m_genJetMatcher, SmearedJetProducerT< T >::m_jets_algo, SmearedJetProducerT< T >::m_jets_algo_pt, SmearedJetProducerT< T >::m_jets_token, SmearedJetProducerT< T >::m_nomVar, SmearedJetProducerT< T >::m_random_generator, SmearedJetProducerT< T >::m_resolution_from_file, SmearedJetProducerT< T >::m_rho_token, SmearedJetProducerT< T >::m_scale_factor_from_file, SmearedJetProducerT< T >::m_systematic_variation, SmearedJetProducerT< T >::m_uncertaintySource, SmearedJetProducerT< T >::m_use_txt_files, SmearedJetProducerT< T >::m_useDeterministicSeed, SmearedJetProducerT< T >::MIN_JET_ENERGY, eostools::move(), reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), L1TObjectsTimingClient_cff::resolution, rho, JME::Rho, SurveyInfoScenario_cff::seed, singleTopDQM_cfi::setup, and mathSSE::sqrt().

Member Data Documentation

◆ jetPtComparator

template<typename T >
GreaterByPt<T> SmearedJetProducerT< T >::jetPtComparator
private

Definition at line 325 of file SmearedJetProducerT.h.

Referenced by SmearedJetProducerT< T >::produce().

◆ m_debug

template<typename T >
bool SmearedJetProducerT< T >::m_debug
private

Definition at line 316 of file SmearedJetProducerT.h.

Referenced by SmearedJetProducerT< T >::produce().

◆ m_enabled

template<typename T >
bool SmearedJetProducerT< T >::m_enabled
private

◆ m_genJetMatcher

template<typename T >
std::shared_ptr<pat::GenJetMatcher> SmearedJetProducerT< T >::m_genJetMatcher
private

◆ m_jets_algo

template<typename T >
std::string SmearedJetProducerT< T >::m_jets_algo
private

◆ m_jets_algo_pt

template<typename T >
std::string SmearedJetProducerT< T >::m_jets_algo_pt
private

◆ m_jets_token

template<typename T >
edm::EDGetTokenT<JetCollection> SmearedJetProducerT< T >::m_jets_token
private

◆ m_nomVar

template<typename T >
int SmearedJetProducerT< T >::m_nomVar
private

◆ m_random_generator

template<typename T >
std::mt19937 SmearedJetProducerT< T >::m_random_generator
private

◆ m_resolution_from_file

template<typename T >
std::unique_ptr<JME::JetResolution> SmearedJetProducerT< T >::m_resolution_from_file
private

◆ m_rho_token

template<typename T >
edm::EDGetTokenT<double> SmearedJetProducerT< T >::m_rho_token
private

◆ m_scale_factor_from_file

template<typename T >
std::unique_ptr<JME::JetResolutionScaleFactor> SmearedJetProducerT< T >::m_scale_factor_from_file
private

◆ m_systematic_variation

template<typename T >
Variation SmearedJetProducerT< T >::m_systematic_variation
private

◆ m_uncertaintySource

template<typename T >
std::string SmearedJetProducerT< T >::m_uncertaintySource
private

◆ m_use_txt_files

template<typename T >
bool SmearedJetProducerT< T >::m_use_txt_files
private

◆ m_useDeterministicSeed

template<typename T >
bool SmearedJetProducerT< T >::m_useDeterministicSeed
private

Definition at line 315 of file SmearedJetProducerT.h.

Referenced by SmearedJetProducerT< T >::produce().

◆ MIN_JET_ENERGY

template<typename T >
constexpr const double SmearedJetProducerT< T >::MIN_JET_ENERGY = 1e-2
staticconstexprprivate

Definition at line 306 of file SmearedJetProducerT.h.

Referenced by SmearedJetProducerT< T >::produce().

JME::JetResolution
Definition: JetResolution.h:17
SmearedJetProducerT::jetPtComparator
GreaterByPt< T > jetPtComparator
Definition: SmearedJetProducerT.h:325
SmearedJetProducerT::m_nomVar
int m_nomVar
Definition: SmearedJetProducerT.h:327
ParameterDescription
JME::JetResolutionScaleFactor::getScaleFactor
float getScaleFactor(const JetParameters &parameters, Variation variation=Variation::NOMINAL, std::string uncertaintySource="") const
Definition: JetResolution.cc:56
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
reco::GenJet
Jets made from MC generator particles.
Definition: GenJet.h:23
reco::PhysObjectMatcher
Definition: PhysObjectMatcher.h:58
JME::Binning::JetEta
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
edm
HLT enums.
Definition: AlignableModifier.h:19
SmearedJetProducerT::m_genJetMatcher
std::shared_ptr< pat::GenJetMatcher > m_genJetMatcher
Definition: SmearedJetProducerT.h:317
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SmearedJetProducerT::JetCollection
std::vector< T > JetCollection
Definition: SmearedJetProducerT.h:98
Variation::UP
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
SmearedJetProducerT::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SmearedJetProducerT.h:153
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
SmearedJetProducerT::MIN_JET_ENERGY
static constexpr const double MIN_JET_ENERGY
Definition: SmearedJetProducerT.h:306
edm::Handle
Definition: AssociativeIterator.h:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
SmearedJetProducerT::m_jets_token
edm::EDGetTokenT< JetCollection > m_jets_token
Definition: SmearedJetProducerT.h:308
edm::FileInPath
Definition: FileInPath.h:64
SmearedJetProducerT::m_uncertaintySource
std::string m_uncertaintySource
Definition: SmearedJetProducerT.h:314
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Variation::NOMINAL
source
static const std::string source
Definition: EdmProvDump.cc:47
SmearedJetProducerT::m_resolution_from_file
std::unique_ptr< JME::JetResolution > m_resolution_from_file
Definition: SmearedJetProducerT.h:320
patPFMETCorrections_cff.variation
variation
Definition: patPFMETCorrections_cff.py:134
L1TObjectsTimingClient_cff.resolution
resolution
Definition: L1TObjectsTimingClient_cff.py:52
SmearedJetProducerT::m_systematic_variation
Variation m_systematic_variation
Definition: SmearedJetProducerT.h:313
DDAxes::rho
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SmearedJetProducerT::m_useDeterministicSeed
bool m_useDeterministicSeed
Definition: SmearedJetProducerT.h:315
SmearedJetProducerT::m_enabled
bool m_enabled
Definition: SmearedJetProducerT.h:310
funct::true
true
Definition: Factorize.h:173
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
pat
Definition: HeavyIon.h:7
JME::JetResolutionScaleFactor
Definition: JetResolution.h:40
SmearedJetProducerT::m_jets_algo_pt
std::string m_jets_algo_pt
Definition: SmearedJetProducerT.h:311
looper.cfg
cfg
Definition: looper.py:297
JME::Binning::Rho
SmearedJetProducerT::m_jets_algo
std::string m_jets_algo
Definition: SmearedJetProducerT.h:312
JME::JetResolutionScaleFactor::get
static const JetResolutionScaleFactor get(const edm::EventSetup &, const std::string &)
Definition: JetResolution.cc:48
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
SmearedJetProducerT::m_random_generator
std::mt19937 m_random_generator
Definition: SmearedJetProducerT.h:323
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
edm::errors::ConfigFileReadError
Definition: EDMException.h:25
T
long double T
Definition: Basic3DVectorLD.h:48
SmearedJetProducerT::m_use_txt_files
bool m_use_txt_files
Definition: SmearedJetProducerT.h:319
metsig::jet
Definition: SignAlgoResolutions.h:47
Exception
Definition: hltDiff.cc:246
SmearedJetProducerT::m_debug
bool m_debug
Definition: SmearedJetProducerT.h:316
Variation::DOWN
SmearedJetProducerT::m_rho_token
edm::EDGetTokenT< double > m_rho_token
Definition: SmearedJetProducerT.h:309
patPFMETCorrections_cff.skipGenMatching
skipGenMatching
Definition: patPFMETCorrections_cff.py:110
reco::LeafCandidate::energy
double energy() const final
energy
Definition: LeafCandidate.h:125
ztail.d
d
Definition: ztail.py:151
JME::Binning::JetPt
JME::JetResolution::get
static const JetResolution get(const edm::EventSetup &, const std::string &)
Definition: JetResolution.cc:23
SmearedJetProducerT::m_scale_factor_from_file
std::unique_ptr< JME::JetResolutionScaleFactor > m_scale_factor_from_file
Definition: SmearedJetProducerT.h:321
patPFMETCorrections_cff.algopt
algopt
Definition: patPFMETCorrections_cff.py:118
event
Definition: event.py:1
edm::ParameterDescription
Definition: ParameterDescription.h:110
edm::InputTag
Definition: InputTag.h:15
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295