1 #ifndef JetMETCorrections_Type1MET_PFJetMETcorrInputProducerT_h 2 #define JetMETCorrections_Type1MET_PFJetMETcorrInputProducerT_h 44 #include <type_traits> 48 template <
typename T,
typename Textractor>
75 template <
typename T,
typename Textractor>
81 : moduleLabel_(cfg.getParameter<
std::
string>(
"@module_label")),
87 if ( cfg.
exists(
"offsetCorrLabel") ) {
89 offsetCorrToken_ = consumes<reco::JetCorrector>(offsetCorrLabel_);
93 jetCorrToken_ = mayConsume<reco::JetCorrector>(jetCorrLabel_);
94 jetCorrResToken_ = mayConsume<reco::JetCorrector>(jetCorrLabelRes_);
96 jetCorrEtaMax_ = ( cfg.
exists(
"jetCorrEtaMax") ) ?
99 type1JetPtThreshold_ = cfg.
getParameter<
double>(
"type1JetPtThreshold");
103 skipEMfractionThreshold_ = cfg.
getParameter<
double>(
"skipEMfractionThreshold");
112 if ( cfg.
exists(
"type2Binning") ) {
113 typedef std::vector<edm::ParameterSet> vParameterSet;
114 vParameterSet cfgType2Binning = cfg.
getParameter<vParameterSet>(
"type2Binning");
115 for ( vParameterSet::const_iterator cfgType2BinningEntry = cfgType2Binning.begin();
116 cfgType2BinningEntry != cfgType2Binning.end(); ++cfgType2BinningEntry ) {
123 produces<CorrMETData>(
"type1");
124 for (
typename std::vector<type2BinningEntryType*>::const_iterator type2BinningEntry = type2Binning_.begin();
125 type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
126 produces<CorrMETData>((*type2BinningEntry)->getInstanceLabel_full(
"type2"));
127 produces<CorrMETData>((*type2BinningEntry)->getInstanceLabel_full(
"offset"));
132 delete skipMuonSelection_;
134 for (
typename std::vector<type2BinningEntryType*>::const_iterator it = type2Binning_.begin();
135 it != type2Binning_.end(); ++it ) {
146 desc.
add<
double>(
"jetCorrEtaMax",9.9);
147 desc.
add<
double>(
"type1JetPtThreshold",15);
148 desc.
add<
bool>(
"skipEM",
true);
149 desc.
add<
double>(
"skipEMfractionThreshold",0.90);
150 desc.
add<
bool>(
"skipMuons",
true);
151 desc.
add<
std::string>(
"skipMuonSelection",
"isGlobalMuon | isStandAloneMuon");
161 std::unique_ptr<CorrMETData> type1Correction(
new CorrMETData());
162 for (
typename std::vector<type2BinningEntryType*>::iterator type2BinningEntry = type2Binning_.begin();
163 type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
164 (*type2BinningEntry)->binUnclEnergySum_ =
CorrMETData();
165 (*type2BinningEntry)->binOffsetEnergySum_ =
CorrMETData();
171 jetCorrLabel_ = jetCorrLabelRes_;
181 int numJets = jets->size();
182 for (
int jetIndex = 0; jetIndex < numJets; ++jetIndex ) {
183 const T&
jet = jets->at(jetIndex);
188 double emEnergyFraction = jet.chargedEmEnergyFraction() + jet.neutralEmEnergyFraction();
189 if ( skipEM_ && emEnergyFraction > skipEMfractionThreshold_ )
continue;
195 const std::vector<reco::CandidatePtr> &
cands = jet.daughterPtrVector();
196 for ( std::vector<reco::CandidatePtr>::const_iterator
cand = cands.begin();
200 if ( mu !=
nullptr && (*skipMuonSelection_)(*mu) ) {
208 if ( checkInputType.isPatJet(jet) )
209 corrJetP4 = jetCorrExtractor_(jet, jetCorrLabel_.label(), jetCorrEtaMax_, &rawJetP4);
211 corrJetP4 = jetCorrExtractor_(jet, jetCorr.
product(), jetCorrEtaMax_, &rawJetP4);
213 if ( corrJetP4.pt() > type1JetPtThreshold_ ) {
216 if ( !offsetCorrLabel_.label().empty() ) {
219 if ( checkInputType.isPatJet(jet) )
220 rawJetP4offsetCorr = jetCorrExtractor_(jet, offsetCorrLabel_.label(), jetCorrEtaMax_, &rawJetP4);
222 rawJetP4offsetCorr = jetCorrExtractor_(jet, offsetCorr.
product(), jetCorrEtaMax_, &rawJetP4);
224 for (
typename std::vector<type2BinningEntryType*>::iterator type2BinningEntry = type2Binning_.begin();
225 type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
226 if ( !(*type2BinningEntry)->binSelection_ || (*(*type2BinningEntry)->binSelection_)(corrJetP4) ) {
227 (*type2BinningEntry)->binOffsetEnergySum_.mex += (rawJetP4.px() - rawJetP4offsetCorr.px());
228 (*type2BinningEntry)->binOffsetEnergySum_.mey += (rawJetP4.py() - rawJetP4offsetCorr.py());
229 (*type2BinningEntry)->binOffsetEnergySum_.sumet += (rawJetP4.Et() - rawJetP4offsetCorr.Et());
236 type1Correction->mex -= (corrJetP4.px() - rawJetP4offsetCorr.px());
237 type1Correction->mey -= (corrJetP4.py() - rawJetP4offsetCorr.py());
238 type1Correction->sumet += (corrJetP4.Et() - rawJetP4offsetCorr.Et());
240 for (
typename std::vector<type2BinningEntryType*>::iterator type2BinningEntry = type2Binning_.begin();
241 type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
242 if ( !(*type2BinningEntry)->binSelection_ || (*(*type2BinningEntry)->binSelection_)(corrJetP4) ) {
243 (*type2BinningEntry)->binUnclEnergySum_.mex += rawJetP4.px();
244 (*type2BinningEntry)->binUnclEnergySum_.mey += rawJetP4.py();
245 (*type2BinningEntry)->binUnclEnergySum_.sumet += rawJetP4.Et();
257 for (
typename std::vector<type2BinningEntryType*>::const_iterator type2BinningEntry = type2Binning_.begin();
258 type2BinningEntry != type2Binning_.end(); ++type2BinningEntry ) {
259 evt.
put(std::unique_ptr<CorrMETData>(
new CorrMETData((*type2BinningEntry)->binUnclEnergySum_)), (*type2BinningEntry)->getInstanceLabel_full(
"type2"));
260 evt.
put(std::unique_ptr<CorrMETData>(
new CorrMETData((*type2BinningEntry)->binOffsetEnergySum_)), (*type2BinningEntry)->getInstanceLabel_full(
"offset"));
297 : binLabel_(cfg.getParameter<
std::
string>(
"binLabel")),
302 delete binSelection_;
307 if ( instanceLabel !=
"" && binLabel_ !=
"" ) retVal.append(
"#");
308 retVal.append(binLabel_);
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool isNonnull() const
Checks for non-null.
CorrMETData binUnclEnergySum_
std::vector< Jet > JetCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string defaultModuleLabel()
StringCutObjectSelector< reco::Candidate::LorentzVector > * binSelection_
math::XYZTLorentzVector LorentzVector
T const * get() const
Returns C++ pointer to the item.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
reco::MuonRef muonRef() const
type2BinningEntryType(const edm::ParameterSet &cfg)
T const * product() const
std::string getInstanceLabel_full(const std::string &instanceLabel)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Particle reconstructed by the particle flow algorithm.
CorrMETData binOffsetEnergySum_