CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
SmearedJetProducerT< T, Textractor > Class Template Reference

#include <SmearedJetProducerT.h>

Inheritance diagram for SmearedJetProducerT< T, Textractor >:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 SmearedJetProducerT (const edm::ParameterSet &cfg)
 
 ~SmearedJetProducerT ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Types

typedef std::vector< TJetCollection
 
typedef edm::ValueMap< int > JetSmearingFlags
 

Private Member Functions

virtual void produce (edm::Event &evt, const edm::EventSetup &es)
 

Private Attributes

SmearedJetProducer_namespace::GenJetMatcherT
< T
genJetMatcher_
 
TFile * inputFile_
 
double jetCorrEtaMax_
 
Textractor jetCorrExtractor_
 
std::string jetCorrLabel_
 
SmearedJetProducer_namespace::JetResolutionExtractorT
< T
jetResolutionExtractor_
 
TH2 * lut_
 
std::string moduleLabel_
 
TRandom3 rnd_
 
double shiftBy_
 
double sigmaMaxGenJetMatch_
 
double skipCorrJetPtThreshold_
 
StringCutObjectSelector< T > * skipJetSelection_
 
double skipRawJetPtThreshold_
 
double smearBy_
 
edm::InputTag src_
 
int verbosity_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

template<typename T, typename Textractor>
class SmearedJetProducerT< T, Textractor >

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. The jet energy resolutions have been measured in QCD di-jet and gamma + jets events selected in 2010 data, as documented in the PAS JME-10-014.

Author
Christian Veelken, LLR

Definition at line 142 of file SmearedJetProducerT.h.

Member Typedef Documentation

template<typename T , typename Textractor >
typedef std::vector<T> SmearedJetProducerT< T, Textractor >::JetCollection
private

Definition at line 144 of file SmearedJetProducerT.h.

template<typename T , typename Textractor >
typedef edm::ValueMap<int> SmearedJetProducerT< T, Textractor >::JetSmearingFlags
private

Definition at line 145 of file SmearedJetProducerT.h.

Constructor & Destructor Documentation

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

Definition at line 149 of file SmearedJetProducerT.h.

References edm::hlt::Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), SmearedJetProducerT< T, Textractor >::inputFile_, SmearedJetProducerT< T, Textractor >::jetCorrEtaMax_, SmearedJetProducerT< T, Textractor >::jetCorrLabel_, SmearedJetProducerT< T, Textractor >::lut_, SmearedJetProducerT< T, Textractor >::shiftBy_, SmearedJetProducerT< T, Textractor >::sigmaMaxGenJetMatch_, SmearedJetProducerT< T, Textractor >::skipCorrJetPtThreshold_, SmearedJetProducerT< T, Textractor >::skipJetSelection_, SmearedJetProducerT< T, Textractor >::skipRawJetPtThreshold_, SmearedJetProducerT< T, Textractor >::smearBy_, SmearedJetProducerT< T, Textractor >::src_, edm::FileInPath::Unknown, and SmearedJetProducerT< T, Textractor >::verbosity_.

150  : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
151  genJetMatcher_(cfg),
154  {
155  //std::cout << "<SmearedJetProducer::SmearedJetProducer>:" << std::endl;
156  //std::cout << " moduleLabel = " << moduleLabel_ << std::endl;
157 
158  src_ = cfg.getParameter<edm::InputTag>("src");
159 
160  edm::FileInPath inputFileName = cfg.getParameter<edm::FileInPath>("inputFileName");
161  std::string lutName = cfg.getParameter<std::string>("lutName");
162  if ( inputFileName.location() == edm::FileInPath::Unknown )
163  throw cms::Exception("JetMETsmearInputProducer")
164  << " Failed to find File = " << inputFileName << " !!\n";
165 
166  inputFile_ = new TFile(inputFileName.fullPath().data());
167  lut_ = dynamic_cast<TH2*>(inputFile_->Get(lutName.data()));
168  if ( !lut_ )
169  throw cms::Exception("SmearedJetProducer")
170  << " Failed to load LUT = " << lutName.data() << " from file = " << inputFileName.fullPath().data() << " !!\n";
171 
172  jetCorrLabel_ = ( cfg.exists("jetCorrLabel") ) ?
173  cfg.getParameter<std::string>("jetCorrLabel") : "";
174  jetCorrEtaMax_ = ( cfg.exists("jetCorrEtaMax") ) ?
175  cfg.getParameter<double>("jetCorrEtaMax") : 9.9;
176 
177  sigmaMaxGenJetMatch_ = cfg.getParameter<double>("sigmaMaxGenJetMatch");
178 
179  smearBy_ = ( cfg.exists("smearBy") ) ? cfg.getParameter<double>("smearBy") : 1.0;
180  //std::cout << "smearBy = " << smearBy_ << std::endl;
181 
182  shiftBy_ = ( cfg.exists("shiftBy") ) ? cfg.getParameter<double>("shiftBy") : 0.;
183  //std::cout << "shiftBy = " << shiftBy_ << std::endl;
184 
185  if ( cfg.exists("skipJetSelection") ) {
186  std::string skipJetSelection_string = cfg.getParameter<std::string>("skipJetSelection");
187  skipJetSelection_ = new StringCutObjectSelector<T>(skipJetSelection_string);
188  }
189 
190  skipRawJetPtThreshold_ = ( cfg.exists("skipRawJetPtThreshold") ) ?
191  cfg.getParameter<double>("skipRawJetPtThreshold") : 1.e-2;
192  skipCorrJetPtThreshold_ = ( cfg.exists("skipCorrJetPtThreshold") ) ?
193  cfg.getParameter<double>("skipCorrJetPtThreshold") : 1.e-2;
194 
195  verbosity_ = ( cfg.exists("verbosity") ) ?
196  cfg.getParameter<int>("verbosity") : 0;
197 
198  produces<JetCollection>();
199  produces<JetSmearingFlags>("jetSmearingFlags");
200 
201  }
T getParameter(std::string const &) const
StringCutObjectSelector< T > * skipJetSelection_
bool exists(std::string const &parameterName) const
checks if a parameter exists
SmearedJetProducer_namespace::GenJetMatcherT< T > genJetMatcher_
SmearedJetProducer_namespace::JetResolutionExtractorT< T > jetResolutionExtractor_
template<typename T , typename Textractor >
SmearedJetProducerT< T, Textractor >::~SmearedJetProducerT ( )
inline

Member Function Documentation

template<typename T , typename Textractor >
virtual void SmearedJetProducerT< T, Textractor >::produce ( edm::Event evt,
const edm::EventSetup es 
)
inlineprivatevirtual

Implements edm::EDProducer.

Definition at line 211 of file SmearedJetProducerT.h.

References gather_cfg::cout, reco::LeafCandidate::energy(), reco::LeafCandidate::eta(), edm::helper::Filler< Map >::fill(), SmearedJetProducerT< T, Textractor >::genJetMatcher_, edm::Event::getByLabel(), edm::helper::Filler< Map >::insert(), metsig::jet, SmearedJetProducerT< T, Textractor >::jetCorrEtaMax_, SmearedJetProducerT< T, Textractor >::jetCorrExtractor_, SmearedJetProducerT< T, Textractor >::jetCorrLabel_, SmearedJetProducerT< T, Textractor >::jetResolutionExtractor_, fwrapper::jets, edm::InputTag::label(), SmearedJetProducerT< T, Textractor >::lut_, SmearedJetProducerT< T, Textractor >::moduleLabel_, reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), edm::Event::put(), SmearedJetProducerT< T, Textractor >::rnd_, SmearedJetProducerT< T, Textractor >::shiftBy_, SmearedJetProducerT< T, Textractor >::sigmaMaxGenJetMatch_, SmearedJetProducerT< T, Textractor >::skipCorrJetPtThreshold_, SmearedJetProducerT< T, Textractor >::skipJetSelection_, SmearedJetProducerT< T, Textractor >::skipRawJetPtThreshold_, SmearedJetProducerT< T, Textractor >::smearBy_, SmearedJetProducerT< T, Textractor >::src_, SmearedJetProducerT< T, Textractor >::verbosity_, x, and detailsBasic3DVector::y.

212  {
213  if ( verbosity_ ) {
214  std::cout << "<SmearedJetProducerT::produce>:" << std::endl;
215  std::cout << " moduleLabel = " << moduleLabel_ << std::endl;
216  std::cout << " src = " << src_.label() << std::endl;
217  }
218 
220  evt.getByLabel(src_, jets);
221 
222  int numJets = jets->size();
223 
224  std::auto_ptr<JetCollection> smearedJets(new JetCollection);
225  std::vector<int> jetSmearingFlags_tmp(numJets);
226 
227  for ( int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
228  const T& jet = jets->at(jetIndex);
229 
231  reco::Candidate::LorentzVector rawJetP4 = rawJetExtractor(jet);
232  if ( verbosity_ ) {
233  std::cout << "rawJet: Pt = " << rawJetP4.pt() << ", eta = " << rawJetP4.eta() << ", phi = " << rawJetP4.phi() << std::endl;
234  }
235 
236  reco::Candidate::LorentzVector corrJetP4 = jet.p4();
237  if ( jetCorrLabel_ != "" ) corrJetP4 = jetCorrExtractor_(jet, jetCorrLabel_, &evt, &es, jetCorrEtaMax_, &rawJetP4);
238  if ( verbosity_ ) {
239  std::cout << "corrJet: Pt = " << corrJetP4.pt() << ", eta = " << corrJetP4.eta() << ", phi = " << corrJetP4.phi() << std::endl;
240  }
241 
242  double smearFactor = 1.;
243  double x = TMath::Abs(corrJetP4.eta());
244  double y = corrJetP4.pt();
245  if ( x > lut_->GetXaxis()->GetXmin() && x < lut_->GetXaxis()->GetXmax() &&
246  y > lut_->GetYaxis()->GetXmin() && y < lut_->GetYaxis()->GetXmax() ) {
247  int binIndex = lut_->FindBin(x, y);
248 
249  if ( smearBy_ > 0. ) smearFactor += smearBy_*(lut_->GetBinContent(binIndex) - 1.);
250  double smearFactorErr = lut_->GetBinError(binIndex);
251  if ( verbosity_ ) std::cout << "smearFactor = " << smearFactor << " +/- " << smearFactorErr << std::endl;
252 
253  if ( shiftBy_ != 0. ) {
254  smearFactor += (shiftBy_*smearFactorErr);
255  if ( verbosity_ ) std::cout << "smearFactor(shifted) = " << smearFactor << std::endl;
256  }
257  }
258 
259  double smearedJetEn = jet.energy();
260 
261  T rawJet(jet);
262  rawJet.setP4(rawJetP4);
263  double jetResolution = jetResolutionExtractor_(rawJet);
264  double sigmaEn = jetResolution;
265 
266  const reco::GenJet* genJet = genJetMatcher_(jet, &evt);
267  bool isGenMatched = false;
268  if ( genJet ) {
269  if ( verbosity_ ) {
270  std::cout << "genJet: Pt = " << genJet->pt() << ", eta = " << genJet->eta() << ", phi = " << genJet->phi() << std::endl;
271  }
272  double dEn = corrJetP4.E() - genJet->energy();
273  if ( TMath::Abs(dEn) < (sigmaMaxGenJetMatch_*sigmaEn) ) {
274 //--- case 1: reconstructed jet matched to generator level jet,
275 // smear difference between reconstructed and "true" jet energy
276 
277  if ( verbosity_ ) {
278  std::cout << " successfully matched to genJet" << std::endl;
279  std::cout << "corrJetEn = " << corrJetP4.E() << ", genJetEn = " << genJet->energy() << " --> dEn = " << dEn << std::endl;
280  }
281 
282  //smearedJetEn = jet.energy()*(1. + (smearFactor - 1.)*dEn/TMath::Max(rawJetP4.E(), corrJetP4.E()));
283  smearedJetEn = jet.energy() + (smearFactor - 1.)*dEn;
284  isGenMatched = true;
285  }
286  }
287  if ( !isGenMatched ) {
288 //--- case 2: reconstructed jet **not** matched to generator level jet,
289 // smear jet energy using MC resolution functions implemented in PFMEt significance algorithm (CMS AN-10/400)
290 
291  if ( verbosity_ ) {
292  std::cout << " not matched to genJet" << std::endl;
293  std::cout << "corrJetEn = " << corrJetP4.E() << ", sigmaEn = " << sigmaEn << std::endl;
294  }
295 
296  if ( smearFactor > 1. ) {
297  // CV: MC resolution already accounted for in reconstructed jet,
298  // add additional Gaussian smearing of width = sqrt(smearFactor^2 - 1)
299  // to account for Data/MC **difference** in jet resolutions.
300  // Take maximum(rawJetEn, corrJetEn) to avoid pathological cases
301  // (e.g. corrJetEn << rawJetEn, due to L1Fastjet corrections)
302 
303  double addSigmaEn = jetResolution*TMath::Sqrt(smearFactor*smearFactor - 1.);
304  //smearedJetEn = jet.energy()*(1. + rnd_.Gaus(0., addSigmaEn)/TMath::Max(rawJetP4.E(), corrJetP4.E()));
305  smearedJetEn = jet.energy() + rnd_.Gaus(0., addSigmaEn);
306  }
307  }
308 
309  // CV: keep minimum jet energy, in order not to loose direction information
310  const double minJetEn = 1.e-2;
311  if ( smearedJetEn < minJetEn ) smearedJetEn = minJetEn;
312 
313  // CV: skip smearing in case either "raw" or "corrected" jet energy is very low
314  // or jet passes selection configurable via python
315  // (allows for protection against "pathological cases",
316  // cf. PhysicsTools/PatUtils/python/tools/metUncertaintyTools.py)
317  reco::Candidate::LorentzVector smearedJetP4 = jet.p4();
318  if ( !((skipJetSelection_ && (*skipJetSelection_)(jet)) ||
319  rawJetP4.pt() < skipRawJetPtThreshold_ ||
320  corrJetP4.pt() < skipCorrJetPtThreshold_ ) ) {
321  if ( verbosity_ ) {
322  std::cout << " multiplying jetP4 by factor = " << (smearedJetEn/jet.energy()) << " --> smearedJetEn = " << smearedJetEn << std::endl;
323  }
324  smearedJetP4 *= (smearedJetEn/jet.energy());
325  }
326 
327  if ( verbosity_ ) {
328  std::cout << "smearedJet: Pt = " << smearedJetP4.pt() << ", eta = " << smearedJetP4.eta() << ", phi = " << smearedJetP4.phi() << std::endl;
329  std::cout << " dPt = " << (smearedJetP4.pt() - jet.pt())
330  << " (Px = " << (smearedJetP4.px() - jet.px()) << ", Py = " << (smearedJetP4.py() - jet.py()) << ")" << std::endl;
331  }
332 
333  T smearedJet(jet);
334  smearedJet.setP4(smearedJetP4);
335 
336  smearedJets->push_back(smearedJet);
337 
338  if ( isGenMatched ) jetSmearingFlags_tmp[jetIndex] = 1;
339  else jetSmearingFlags_tmp[jetIndex] = 0;
340  }
341 
342  std::auto_ptr<JetSmearingFlags> jetSmearingFlags(new JetSmearingFlags);
343  JetSmearingFlags::Filler valueMapFiller(*jetSmearingFlags);
344  valueMapFiller.insert(jets, jetSmearingFlags_tmp.begin(), jetSmearingFlags_tmp.end());
345  valueMapFiller.fill();
346 
347 //--- add collection of "smeared" jets to the event
348  evt.put(smearedJets);
349  evt.put(jetSmearingFlags, "jetSmearingFlags");
350  }
StringCutObjectSelector< T > * skipJetSelection_
virtual double eta() const
momentum pseudorapidity
SmearedJetProducer_namespace::GenJetMatcherT< T > genJetMatcher_
virtual double energy() const
energy
edm::ValueMap< int > JetSmearingFlags
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
vector< PseudoJet > jets
Jets made from MC generator particles.
Definition: GenJet.h:25
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
helper::Filler< ValueMap< int > > Filler
Definition: ValueMap.h:157
virtual double pt() const
transverse momentum
SmearedJetProducer_namespace::JetResolutionExtractorT< T > jetResolutionExtractor_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:38
std::string const & label() const
Definition: InputTag.h:25
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
long double T
std::vector< T > JetCollection
virtual double phi() const
momentum azimuthal angle

Member Data Documentation

template<typename T , typename Textractor >
SmearedJetProducer_namespace::GenJetMatcherT<T> SmearedJetProducerT< T, Textractor >::genJetMatcher_
private
template<typename T , typename Textractor >
TFile* SmearedJetProducerT< T, Textractor >::inputFile_
private
template<typename T , typename Textractor >
double SmearedJetProducerT< T, Textractor >::jetCorrEtaMax_
private
template<typename T , typename Textractor >
Textractor SmearedJetProducerT< T, Textractor >::jetCorrExtractor_
private
template<typename T , typename Textractor >
std::string SmearedJetProducerT< T, Textractor >::jetCorrLabel_
private
template<typename T , typename Textractor >
SmearedJetProducer_namespace::JetResolutionExtractorT<T> SmearedJetProducerT< T, Textractor >::jetResolutionExtractor_
private
template<typename T , typename Textractor >
TH2* SmearedJetProducerT< T, Textractor >::lut_
private
template<typename T , typename Textractor >
std::string SmearedJetProducerT< T, Textractor >::moduleLabel_
private
template<typename T , typename Textractor >
TRandom3 SmearedJetProducerT< T, Textractor >::rnd_
private
template<typename T , typename Textractor >
double SmearedJetProducerT< T, Textractor >::shiftBy_
private
template<typename T , typename Textractor >
double SmearedJetProducerT< T, Textractor >::sigmaMaxGenJetMatch_
private
template<typename T , typename Textractor >
double SmearedJetProducerT< T, Textractor >::skipCorrJetPtThreshold_
private
template<typename T , typename Textractor >
StringCutObjectSelector<T>* SmearedJetProducerT< T, Textractor >::skipJetSelection_
private
template<typename T , typename Textractor >
double SmearedJetProducerT< T, Textractor >::skipRawJetPtThreshold_
private
template<typename T , typename Textractor >
double SmearedJetProducerT< T, Textractor >::smearBy_
private
template<typename T , typename Textractor >
edm::InputTag SmearedJetProducerT< T, Textractor >::src_
private
template<typename T , typename Textractor >
int SmearedJetProducerT< T, Textractor >::verbosity_
private