23 template <
typename T,
typename Textractor>
25 : genJetMatcher_(cfg,consumesCollector()),
26 jetResolutionExtractor_(cfg.getParameter<edm::
ParameterSet>(
"jetResolutions")),
38 <<
" Failed to find File = " << inputFileName <<
" !!\n";
44 <<
" Failed to load LUT = " << lutName.data() <<
" from file = " << inputFileName.
fullPath().data() <<
" !!\n";
46 if ( cfg.
exists(
"jetCorrLabel") ) {
77 produces<reco::PFCandidateCollection>();
80 template <
typename T,
typename Textractor>
85 delete skipJetSelection_;
89 template <
typename T,
typename Textractor>
93 evt.
getByToken(srcPFCandidates_, originalPFCandidates);
100 for ( reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
101 originalPFCandidate != originalPFCandidates->end(); ++originalPFCandidate ) {
103 const T* jet_matched =
nullptr;
104 for (
typename JetCollection::const_iterator
jet = jets->begin();
105 jet != jets->end(); ++
jet ) {
106 std::vector<reco::PFCandidatePtr> jetConstituents =
jet->getPFConstituents();
107 for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent =
jet->getPFConstituents().begin();
108 jetConstituent !=
jet->getPFConstituents().end() && jet_matched==
nullptr; ++jetConstituent ) {
109 if (
deltaR2(originalPFCandidate->p4(), (*jetConstituent)->p4()) <
dR2Match ) jet_matched = &(*jet);
113 if ( jet_matched==
nullptr )
continue;
122 if ( !jetCorrLabel_.label().empty() ) {
125 corrJetP4 = jetCorrExtractor_(*jet_matched, jetCorr.
product(), jetCorrEtaMax_, &rawJetP4);
131 double smearFactor = 1.;
133 double y = corrJetP4.pt();
134 if ( x > lut_->GetXaxis()->GetXmin() && x < lut_->GetXaxis()->GetXmax() &&
135 y > lut_->GetYaxis()->GetXmin() && y < lut_->GetYaxis()->GetXmax() ) {
136 int binIndex = lut_->FindBin(x, y);
138 if ( smearBy_ > 0. ) smearFactor += smearBy_*(lut_->GetBinContent(binIndex) - 1.);
139 double smearFactorErr = lut_->GetBinError(binIndex);
142 if ( shiftBy_ != 0. ) {
143 smearFactor += (shiftBy_*smearFactorErr);
148 double smearedJetEn = jet_matched->energy();
150 T rawJet(*jet_matched);
151 rawJet.setP4(rawJetP4);
152 double jetResolution = jetResolutionExtractor_(rawJet);
153 double sigmaEn = jetResolution;
155 const reco::GenJet* genJet = genJetMatcher_(*jet_matched, &evt);
156 bool isGenMatched =
false;
157 if ( genJet!=
nullptr ) {
161 double dEn = corrJetP4.E() - genJet->
energy();
162 if (
std::abs(dEn) < (sigmaMaxGenJetMatch_*sigmaEn) ) {
172 smearedJetEn = jet_matched->energy() + (smearFactor - 1.)*dEn;
176 if ( !isGenMatched ) {
185 if ( smearFactor > 1. ) {
192 double addSigmaEn = jetResolution*
sqrt(smearFactor*smearFactor - 1.);
194 smearedJetEn = jet_matched->energy() + rnd_.Gaus(0., addSigmaEn);
199 const double minJetEn = 1.e-2;
200 if ( smearedJetEn < minJetEn ) smearedJetEn = minJetEn;
207 if ( !((skipJetSelection_ && (*skipJetSelection_)(*jet_matched)) ||
208 rawJetP4.pt() < skipRawJetPtThreshold_ ||
209 corrJetP4.pt() < skipCorrJetPtThreshold_ ) ) {
213 smearedJetP4 *= (smearedJetEn/jet_matched->energy());
222 double scaleFactor = ( jet_matched->p4().energy() > 0. ) ?
223 (smearedJetP4.energy()/jet_matched->p4().energy()) : 1.0;
225 double smearedPx = scaleFactor*originalPFCandidate->px();
226 double smearedPy = scaleFactor*originalPFCandidate->py();
227 double smearedPz = scaleFactor*originalPFCandidate->pz();
228 double mass = originalPFCandidate->mass();
229 double smearedEn =
sqrt(smearedPx*smearedPx + smearedPy*smearedPy + smearedPz*smearedPz + mass*mass);
233 smearedPFCandidate.
setP4(smearedPFCandidateP4);
235 smearedPFCandidates->push_back(smearedPFCandidate);
238 evt.
put(smearedPFCandidates);
245 namespace SmearedJetProducer_namespace
248 class JetResolutionExtractorT<
reco::PFJet>
253 : jetResolutions_(cfg)
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
SmearedPFCandidateProducerForPFNoPUMEtT< reco::PFJet, JetCorrExtractorT< reco::PFJet > > SmearedPFCandidateProducerForPFNoPUMEt
edm::EDGetTokenT< reco::JetCorrector > jetCorrToken_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void setP4(const LorentzVector &p4)
set 4-momentum
double skipCorrJetPtThreshold_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidates_
StringCutObjectSelector< T > * skipJetSelection_
double sigmaMaxGenJetMatch_
Jets made from PFObjects.
edm::EDGetTokenT< JetCollection > srcJets_
T x() const
Cartesian x coordinate.
virtual double energy() const
energy
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
edm::InputTag jetCorrLabel_
Abs< T >::type abs(const T &t)
Jets made from MC generator particles.
double deltaR2(const T1 &t1, const T2 &t2)
void produce(edm::Event &, const edm::EventSetup &)
double skipRawJetPtThreshold_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
T const * product() const
LocationCode location() const
Where was the file found?
~SmearedPFCandidateProducerForPFNoPUMEtT()
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Particle reconstructed by the particle flow algorithm.
std::string fullPath() const
SmearedPFCandidateProducerForPFNoPUMEtT(const edm::ParameterSet &)