CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetCorrExtractorT.h
Go to the documentation of this file.
1 #ifndef JetMETCorrections_Type1MET_JetCorrExtractorT_h
2 #define JetMETCorrections_Type1MET_JetCorrExtractorT_h
3 
24 
29 
30 namespace
31 {
32  template <typename T>
33  double getCorrection(const T& rawJet, const std::string& jetCorrLabel,
34  const edm::Event& evt, const edm::EventSetup& es)
35  {
36  const JetCorrector* jetCorrector = JetCorrector::getJetCorrector(jetCorrLabel, es);
37  if ( !jetCorrector )
38  throw cms::Exception("JetCorrExtractor")
39  << "Failed to access Jet corrections for = " << jetCorrLabel << " !!\n";
40  return jetCorrector->correction(rawJet, evt, es);
41  }
42 
43  double sign(double x)
44  {
45  if ( x > 0. ) return +1.;
46  else if ( x < 0. ) return -1.;
47  else return 0.;
48  }
49 }
50 
51 template <typename T>
53 {
54  public:
55 
56  reco::Candidate::LorentzVector operator()(const T& rawJet, const std::string& jetCorrLabel,
57  const edm::Event* evt = 0, const edm::EventSetup* es = 0,
58  double jetCorrEtaMax = 9.9,
59  const reco::Candidate::LorentzVector* rawJetP4_specified = 0)
60  {
61  // "general" implementation requires access to edm::Event and edm::EventSetup,
62  // only specialization for pat::Jets doesn't
63  assert(evt && es);
64 
65  // allow to specify four-vector to be used as "raw" (uncorrected) jet momentum,
66  // call 'rawJet.p4()' in case four-vector not specified explicitely
67  reco::Candidate::LorentzVector rawJetP4 = ( rawJetP4_specified ) ?
68  (*rawJetP4_specified) : rawJet.p4();
69 
70  double jetCorrFactor = 1.;
71  if ( fabs(rawJetP4.eta()) < jetCorrEtaMax ) {
72  jetCorrFactor = getCorrection(rawJet, jetCorrLabel, *evt, *es);
73  } else {
74  reco::Candidate::PolarLorentzVector modJetPolarP4(rawJetP4);
75  modJetPolarP4.SetEta(sign(rawJetP4.eta())*jetCorrEtaMax);
76 
77  reco::Candidate::LorentzVector modJetP4(modJetPolarP4);
78 
79  T modJet(rawJet);
80  modJet.setP4(modJetP4);
81 
82  jetCorrFactor = getCorrection(modJet, jetCorrLabel, *evt, *es);
83  }
84 
85  reco::Candidate::LorentzVector corrJetP4 = rawJetP4;
86  corrJetP4 *= jetCorrFactor;
87 
88  return corrJetP4;
89  }
90 };
91 
92 #endif
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:51
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:38
x
Definition: VDTMath.h:216
long double T
reco::Candidate::LorentzVector operator()(const T &rawJet, const std::string &jetCorrLabel, const edm::Event *evt=0, const edm::EventSetup *es=0, double jetCorrEtaMax=9.9, const reco::Candidate::LorentzVector *rawJetP4_specified=0)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:40