CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloJetMETcorrInputProducerT.h
Go to the documentation of this file.
1 #ifndef JetMETCorrections_Type1MET_CaloJetMETcorrInputProducer_h
2 #define JetMETCorrections_Type1MET_CaloJetMETcorrInputProducer_h
3 
25 
31 
33 
34 #include <string>
35 
36 namespace CaloJetMETcorrInputProducer_namespace
37 {
38  template <typename T>
40  {
41  public:
42 
43  void operator()(const T&) const {} // no type-checking needed for reco::CaloJet input
44  };
45 
46  template <typename T>
47  class RawJetExtractorT // this template is neccessary to support pat::Jets
48  // (because pat::Jet->p4() returns the JES corrected, not the raw, jet momentum)
49  {
50  public:
51 
53  {
54  return jet.p4();
55  }
56  };
57 }
58 
59 template <typename T, typename Textractor>
61 {
62  public:
63 
65  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
66  {
67  src_ = cfg.getParameter<edm::InputTag>("src");
68 
69  offsetCorrLabel_ = ( cfg.exists("offsetCorrLabel") ) ?
70  cfg.getParameter<std::string>("offsetCorrLabel") : "";
71  jetCorrLabel_ = cfg.getParameter<std::string>("jetCorrLabel");
72 
73  jetCorrEtaMax_ = ( cfg.exists("jetCorrEtaMax") ) ?
74  cfg.getParameter<double>("jetCorrEtaMax") : 9.9;
75 
76  type1JetPtThreshold_ = cfg.getParameter<double>("type1JetPtThreshold");
77 
78  skipEM_ = cfg.getParameter<bool>("skipEM");
79  if ( skipEM_ ) {
80  skipEMfractionThreshold_ = cfg.getParameter<double>("skipEMfractionThreshold");
81  }
82 
83  if ( cfg.exists("srcMET") ) {
84  srcMET_ = cfg.getParameter<edm::InputTag>("srcMET");
85  }
86 
87  produces<CorrMETData>("type1");
88  produces<CorrMETData>("type2");
89  produces<CorrMETData>("offset");
90  }
92 
93  private:
94 
95  void produce(edm::Event& evt, const edm::EventSetup& es)
96  {
97  std::auto_ptr<CorrMETData> type1Correction(new CorrMETData());
98  std::auto_ptr<CorrMETData> unclEnergySum(new CorrMETData());
99  std::auto_ptr<CorrMETData> offsetEnergySum(new CorrMETData());
100 
101  typedef std::vector<T> JetCollection;
103  evt.getByLabel(src_, jets);
104 
105  typedef edm::View<reco::MET> METView;
107  if ( srcMET_.label() != "" ) {
108  evt.getByLabel(srcMET_, met);
109  if ( met->size() != 1 )
110  throw cms::Exception("CaloJetMETcorrInputProducer::produce")
111  << "Failed to find unique MET in the event, src = " << srcMET_.label() << " !!\n";
112 
113 //--- compute "unclustered energy" by sutracting from the reconstructed MET
114 // (i.e. from the negative vectorial sum of all particles reconstructed in the event)
115 // the momenta of (high Pt) jets which enter Type 1 MET corrections
116 //
117 // NOTE: MET = -(jets + muons + "unclustered energy"),
118 // so "unclustered energy" = -(MET + jets + muons),
119 // i.e. (high Pt) jets enter the sum of "unclustered energy" with negative sign.
120 //
121  unclEnergySum->mex = -met->front().px();
122  unclEnergySum->mey = -met->front().py();
123  unclEnergySum->sumet = met->front().sumEt();
124  }
125 
126  int numJets = jets->size();
127  for ( int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
128  const T& rawJet = jets->at(jetIndex);
129 
131  checkInputType(rawJet);
132 
134  reco::Candidate::LorentzVector rawJetP4 = rawJetExtractor(rawJet);
135 
137 
138  if ( corrJetP4.pt() > type1JetPtThreshold_ ) {
139 
140  unclEnergySum->mex -= rawJetP4.px();
141  unclEnergySum->mey -= rawJetP4.py();
142  unclEnergySum->sumet -= rawJetP4.Et();
143 
144  if ( skipEM_ && rawJet.emEnergyFraction() > skipEMfractionThreshold_ ) continue;
145 
146  reco::Candidate::LorentzVector rawJetP4offsetCorr = rawJetP4;
147  if ( offsetCorrLabel_ != "" ) {
148  rawJetP4offsetCorr = jetCorrExtractor_(rawJet, offsetCorrLabel_, &evt, &es, jetCorrEtaMax_);
149 
150  offsetEnergySum->mex += (rawJetP4.px() - rawJetP4offsetCorr.px());
151  offsetEnergySum->mey += (rawJetP4.py() - rawJetP4offsetCorr.py());
152  offsetEnergySum->sumet += (rawJetP4.Et() - rawJetP4offsetCorr.Et());
153  }
154 
155 //--- MET balances momentum of reconstructed particles,
156 // hence correction to jets and corresponding Type 1 MET correction are of opposite sign
157  type1Correction->mex -= (corrJetP4.px() - rawJetP4offsetCorr.px());
158  type1Correction->mey -= (corrJetP4.py() - rawJetP4offsetCorr.py());
159  type1Correction->sumet += (corrJetP4.Et() - rawJetP4offsetCorr.Et());
160  }
161  }
162 
163 //--- add
164 // o Type 1 MET correction (difference corrected-uncorrected jet energy for jets of (corrected) Pt > 20 GeV)
165 // o momentum sum of "unclustered energy" (jets of (corrected) Pt < 20 GeV)
166 // o momentum sum of "offset energy" (sum of energy attributed to pile-up/underlying event)
167 // to the event
168  evt.put(type1Correction, "type1");
169  evt.put(unclEnergySum, "type2");
170  evt.put(offsetEnergySum, "offset");
171  }
172 
173  std::string moduleLabel_;
174 
175  edm::InputTag src_; // CaloJet input collection
176 
177  std::string offsetCorrLabel_; // e.g. 'ak5CaloJetL1Fastjet'
178  std::string jetCorrLabel_; // e.g. 'ak5CaloJetL1FastL2L3' (MC) / 'ak5CaloJetL1FastL2L3Residual' (Data)
179  Textractor jetCorrExtractor_;
180 
181  double jetCorrEtaMax_; // do not use JEC factors for |eta| above this threshold (recommended default = 4.7),
182  // in order to work around problem with CMSSW_4_2_x JEC factors at high eta,
183  // reported in
184  // https://hypernews.cern.ch/HyperNews/CMS/get/jes/270.html
185  // https://hypernews.cern.ch/HyperNews/CMS/get/JetMET/1259/1.html
186 
187  double type1JetPtThreshold_; // threshold to distinguish between jets entering Type 1 MET correction
188  // and jets entering "unclustered energy" sum
189  // NOTE: threshold is applied on **corrected** jet energy (recommended default = 10 GeV)
190 
191  bool skipEM_; // flag to exclude jets with large fraction of electromagnetic energy (electrons/photons)
192  // from Type 1 + 2 MET corrections
194 
195  edm::InputTag srcMET_; // MET input, needed to compute "unclustered energy" sum for Type 2 MET correction
196 };
197 
198 #endif
199 
200 
201 
202 
203 
T getParameter(std::string const &) const
std::vector< Jet > JetCollection
Definition: Jet.h:50
CaloJetMETcorrInputProducerT(const edm::ParameterSet &cfg)
reco::Candidate::LorentzVector operator()(const T &jet) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
vector< PseudoJet > jets
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void produce(edm::Event &evt, const edm::EventSetup &es)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:38
std::string const & label() const
Definition: InputTag.h:25
a MET correction term
Definition: CorrMETData.h:14
long double T