CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFJetMETcorrInputProducerT.h
Go to the documentation of this file.
1 #ifndef JetMETCorrections_Type1MET_PFJetMETcorrInputProducerT_h
2 #define JetMETCorrections_Type1MET_PFJetMETcorrInputProducerT_h
3 
27 
34 
37 
39 
40 #include <string>
41 
42 namespace PFJetMETcorrInputProducer_namespace
43 {
44  template <typename T, typename Textractor>
46  {
47  public:
48 
49  void operator()(const T&) const {} // no type-checking needed for reco::PFJet input
50  };
51 
52  template <typename T>
53  class RawJetExtractorT // this template is neccessary to support pat::Jets
54  // (because pat::Jet->p4() returns the JES corrected, not the raw, jet momentum)
55  {
56  public:
57 
59  {
60  return jet.p4();
61  }
62  };
63 }
64 
65 template <typename T, typename Textractor>
67 {
68  public:
69 
71  : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
73  {
74  src_ = cfg.getParameter<edm::InputTag>("src");
75 
76  offsetCorrLabel_ = ( cfg.exists("offsetCorrLabel") ) ?
77  cfg.getParameter<std::string>("offsetCorrLabel") : "";
78  jetCorrLabel_ = cfg.getParameter<std::string>("jetCorrLabel");
79 
80  jetCorrEtaMax_ = ( cfg.exists("jetCorrEtaMax") ) ?
81  cfg.getParameter<double>("jetCorrEtaMax") : 9.9;
82 
83  type1JetPtThreshold_ = cfg.getParameter<double>("type1JetPtThreshold");
84 
85  skipEM_ = cfg.getParameter<bool>("skipEM");
86  if ( skipEM_ ) {
87  skipEMfractionThreshold_ = cfg.getParameter<double>("skipEMfractionThreshold");
88  }
89 
90  skipMuons_ = cfg.getParameter<bool>("skipMuons");
91  if ( skipMuons_ ) {
92  std::string skipMuonSelection_string = cfg.getParameter<std::string>("skipMuonSelection");
93  skipMuonSelection_ = new StringCutObjectSelector<reco::Muon>(skipMuonSelection_string);
94  }
95 
96  if ( cfg.exists("type2Binning") ) {
97  typedef std::vector<edm::ParameterSet> vParameterSet;
98  vParameterSet cfgType2Binning = cfg.getParameter<vParameterSet>("type2Binning");
99  for ( vParameterSet::const_iterator cfgType2BinningEntry = cfgType2Binning.begin();
100  cfgType2BinningEntry != cfgType2Binning.end(); ++cfgType2BinningEntry ) {
101  type2Binning_.push_back(new type2BinningEntryType(*cfgType2BinningEntry));
102  }
103  } else {
104  type2Binning_.push_back(new type2BinningEntryType());
105  }
106 
107  produces<CorrMETData>("type1");
108  for ( typename std::vector<type2BinningEntryType*>::const_iterator type2BinningEntry = type2Binning_.begin();
109  type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
110  produces<CorrMETData>((*type2BinningEntry)->getInstanceLabel_full("type2"));
111  produces<CorrMETData>((*type2BinningEntry)->getInstanceLabel_full("offset"));
112  }
113  }
115  {
116  delete skipMuonSelection_;
117 
118  for ( typename std::vector<type2BinningEntryType*>::const_iterator it = type2Binning_.begin();
119  it != type2Binning_.end(); ++it ) {
120  delete (*it);
121  }
122  }
123 
124  private:
125 
126  void produce(edm::Event& evt, const edm::EventSetup& es)
127  {
128  std::auto_ptr<CorrMETData> type1Correction(new CorrMETData());
129  for ( typename std::vector<type2BinningEntryType*>::iterator type2BinningEntry = type2Binning_.begin();
130  type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
131  (*type2BinningEntry)->binUnclEnergySum_ = CorrMETData();
132  (*type2BinningEntry)->binOffsetEnergySum_ = CorrMETData();
133  }
134 
135  typedef std::vector<T> JetCollection;
137  evt.getByLabel(src_, jets);
138 
139  int numJets = jets->size();
140  for ( int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
141  const T& rawJet = jets->at(jetIndex);
142 
144  checkInputType(rawJet);
145 
146  double emEnergyFraction = rawJet.chargedEmEnergyFraction() + rawJet.neutralEmEnergyFraction();
147  if ( skipEM_ && emEnergyFraction > skipEMfractionThreshold_ ) continue;
148 
150  reco::Candidate::LorentzVector rawJetP4 = rawJetExtractor(rawJet);
151  if ( skipMuons_ ) {
152  std::vector<reco::PFCandidatePtr> cands = rawJet.getPFConstituents();
153  for ( std::vector<reco::PFCandidatePtr>::const_iterator cand = cands.begin();
154  cand != cands.end(); ++cand ) {
155  if ( (*cand)->muonRef().isNonnull() && (*skipMuonSelection_)(*(*cand)->muonRef()) ) {
156  reco::Candidate::LorentzVector muonP4 = (*cand)->p4();
157  rawJetP4 -= muonP4;
158  }
159  }
160  }
161 
162  reco::Candidate::LorentzVector corrJetP4 = jetCorrExtractor_(rawJet, jetCorrLabel_, &evt, &es, jetCorrEtaMax_, &rawJetP4);
163 
164  if ( corrJetP4.pt() > type1JetPtThreshold_ ) {
165 
166  reco::Candidate::LorentzVector rawJetP4offsetCorr = rawJetP4;
167  if ( offsetCorrLabel_ != "" ) {
168  rawJetP4offsetCorr = jetCorrExtractor_(rawJet, offsetCorrLabel_, &evt, &es, jetCorrEtaMax_, &rawJetP4);
169 
170  for ( typename std::vector<type2BinningEntryType*>::iterator type2BinningEntry = type2Binning_.begin();
171  type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
172  if ( !(*type2BinningEntry)->binSelection_ || (*(*type2BinningEntry)->binSelection_)(corrJetP4) ) {
173  (*type2BinningEntry)->binOffsetEnergySum_.mex += (rawJetP4.px() - rawJetP4offsetCorr.px());
174  (*type2BinningEntry)->binOffsetEnergySum_.mey += (rawJetP4.py() - rawJetP4offsetCorr.py());
175  (*type2BinningEntry)->binOffsetEnergySum_.sumet += (rawJetP4.Et() - rawJetP4offsetCorr.Et());
176  }
177  }
178  }
179 
180 //--- MET balances momentum of reconstructed particles,
181 // hence correction to jets and corresponding Type 1 MET correction are of opposite sign
182  type1Correction->mex -= (corrJetP4.px() - rawJetP4offsetCorr.px());
183  type1Correction->mey -= (corrJetP4.py() - rawJetP4offsetCorr.py());
184  type1Correction->sumet += (corrJetP4.Et() - rawJetP4offsetCorr.Et());
185  } else {
186  for ( typename std::vector<type2BinningEntryType*>::iterator type2BinningEntry = type2Binning_.begin();
187  type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
188  if ( !(*type2BinningEntry)->binSelection_ || (*(*type2BinningEntry)->binSelection_)(corrJetP4) ) {
189  (*type2BinningEntry)->binUnclEnergySum_.mex += rawJetP4.px();
190  (*type2BinningEntry)->binUnclEnergySum_.mey += rawJetP4.py();
191  (*type2BinningEntry)->binUnclEnergySum_.sumet += rawJetP4.Et();
192  }
193  }
194  }
195  }
196 
197 //--- add
198 // o Type 1 MET correction (difference corrected-uncorrected jet energy for jets of (corrected) Pt > 10 GeV)
199 // o momentum sum of "unclustered energy" (jets of (corrected) Pt < 10 GeV)
200 // o momentum sum of "offset energy" (sum of energy attributed to pile-up/underlying event)
201 // to the event
202  evt.put(type1Correction, "type1");
203  for ( typename std::vector<type2BinningEntryType*>::const_iterator type2BinningEntry = type2Binning_.begin();
204  type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
205  evt.put(std::auto_ptr<CorrMETData>(new CorrMETData((*type2BinningEntry)->binUnclEnergySum_)), (*type2BinningEntry)->getInstanceLabel_full("type2"));
206  evt.put(std::auto_ptr<CorrMETData>(new CorrMETData((*type2BinningEntry)->binOffsetEnergySum_)), (*type2BinningEntry)->getInstanceLabel_full("offset"));
207  }
208  }
209 
210  std::string moduleLabel_;
211 
212  edm::InputTag src_; // PFJet input collection
213 
214  std::string offsetCorrLabel_; // e.g. 'ak5PFJetL1Fastjet'
215  std::string jetCorrLabel_; // e.g. 'ak5PFJetL1FastL2L3' (MC) / 'ak5PFJetL1FastL2L3Residual' (Data)
216  Textractor jetCorrExtractor_;
217 
218  double jetCorrEtaMax_; // do not use JEC factors for |eta| above this threshold
219 
220  double type1JetPtThreshold_; // threshold to distinguish between jets entering Type 1 MET correction
221  // and jets entering "unclustered energy" sum
222  // NOTE: threshold is applied on **corrected** jet energy (recommended default = 10 GeV)
223 
224  bool skipEM_; // flag to exclude jets with large fraction of electromagnetic energy (electrons/photons)
225  // from Type 1 + 2 MET corrections
227 
228  bool skipMuons_; // flag to subtract momentum of muons (provided muons pass selection cuts) which are within jets
229  // from jet energy before compute JECs/propagating JECs to Type 1 + 2 MET corrections
231 
233  {
235  : binLabel_(""),
236  binSelection_(0)
237  {}
239  : binLabel_(cfg.getParameter<std::string>("binLabel")),
240  binSelection_(new StringCutObjectSelector<reco::Candidate::LorentzVector>(cfg.getParameter<std::string>("binSelection")))
241  {}
243  {
244  delete binSelection_;
245  }
246  std::string getInstanceLabel_full(const std::string& instanceLabel)
247  {
248  std::string retVal = instanceLabel;
249  if ( instanceLabel != "" && binLabel_ != "" ) retVal.append("#");
250  retVal.append(binLabel_);
251  return retVal;
252  }
253  std::string binLabel_;
257  };
258  std::vector<type2BinningEntryType*> type2Binning_;
259 };
260 
261 #endif
262 
263 
264 
265 
T getParameter(std::string const &) const
reco::Candidate::LorentzVector operator()(const T &jet) const
std::vector< Jet > JetCollection
Definition: Jet.h:50
math::XYZTLorentzVector LorentzVector
bool exists(std::string const &parameterName) const
checks if a parameter exists
void produce(edm::Event &evt, const edm::EventSetup &es)
std::vector< type2BinningEntryType * > type2Binning_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
vector< PseudoJet > jets
StringCutObjectSelector< reco::Candidate::LorentzVector > * binSelection_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
PFJetMETcorrInputProducerT(const edm::ParameterSet &cfg)
std::string getInstanceLabel_full(const std::string &instanceLabel)
StringCutObjectSelector< reco::Muon > * skipMuonSelection_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:38
a MET correction term
Definition: CorrMETData.h:14
long double T