CMS 3D CMS Logo

JetEnergyShift.cc
Go to the documentation of this file.
4 
7 
35 public:
37  explicit JetEnergyShift(const edm::ParameterSet&);
38 
39 private:
41  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
42 
43 private:
53  double scaleFactor_;
58 };
59 
61  : inputJetsToken_(consumes<std::vector<pat::Jet>>(cfg.getParameter<edm::InputTag>("inputJets"))),
62  inputMETsToken_(consumes<std::vector<pat::MET>>(cfg.getParameter<edm::InputTag>("inputMETs"))),
63  scaleFactor_(cfg.getParameter<double>("scaleFactor")),
64  jetPTThresholdForMET_(cfg.getParameter<double>("jetPTThresholdForMET")),
65  jetEMLimitForMET_(cfg.getParameter<double>("jetEMLimitForMET")) {
66  // use label of input to create label for output
67  outputJets_ = cfg.getParameter<edm::InputTag>("inputJets").label();
68  outputMETs_ = cfg.getParameter<edm::InputTag>("inputMETs").label();
69  // register products
70  produces<std::vector<pat::Jet>>(outputJets_);
71  produces<std::vector<pat::MET>>(outputMETs_);
72 }
73 
76  event.getByToken(inputJetsToken_, jets);
77 
79  event.getByToken(inputMETsToken_, mets);
80 
81  auto pJets = std::make_unique<std::vector<pat::Jet>>();
82  auto pMETs = std::make_unique<std::vector<pat::MET>>();
83 
84  double dPx = 0.;
85  double dPy = 0.;
86  double dSumEt = 0.;
87 
88  for (std::vector<pat::Jet>::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
89  pat::Jet scaledJet = *jet;
90  scaledJet.scaleEnergy(scaleFactor_);
91  pJets->push_back(scaledJet);
92  // consider jet scale shift only if the raw jet pt and emf
93  // is above the thresholds given in the module definition
94  if (jet->correctedJet("raw").pt() > jetPTThresholdForMET_ && jet->emEnergyFraction() < jetEMLimitForMET_) {
95  dPx += scaledJet.px() - jet->px();
96  dPy += scaledJet.py() - jet->py();
97  dSumEt += scaledJet.et() - jet->et();
98  }
99  }
100 
101  // scale MET accordingly
102  pat::MET met = *(mets->begin());
103  double scaledMETPx = met.px() - dPx;
104  double scaledMETPy = met.py() - dPy;
105  pat::MET scaledMET(
106  reco::MET(met.sumEt() + dSumEt,
108  scaledMETPx, scaledMETPy, 0, sqrt(scaledMETPx * scaledMETPx + scaledMETPy * scaledMETPy)),
109  reco::MET::Point(0, 0, 0)));
110  pMETs->push_back(scaledMET);
111  event.put(std::move(pJets), outputJets_);
112  event.put(std::move(pMETs), outputMETs_);
113 }
114 
Analysis-level MET class.
Definition: MET.h:40
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
rescale jet energy and recalculated MET
void scaleEnergy(double fScale) override
Scale energy and correspondingly adjust raw jec factors.
Definition: Jet.h:177
double jetEMLimitForMET_
limit on the emf of the jet for Type1 MET corrections
std::string outputJets_
jet output collection
Definition: HeavyIon.h:7
char const * label
double px() const final
x coordinate of momentum vector
Definition: Jet.py:1
Definition: MET.h:41
T sqrt(T t)
Definition: SSEVec.h:19
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double py() const final
y coordinate of momentum vector
edm::EDGetTokenT< std::vector< pat::MET > > inputMETsToken_
met input collection
JetEnergyShift(const edm::ParameterSet &)
default constructor
Analysis-level calorimeter jet class.
Definition: Jet.h:77
double et() const final
transverse energy
HLT enums.
double scaleFactor_
scale factor for the rescaling
Plugin to shift the jet energy scale and recalculate the MET accordingly.
double jetPTThresholdForMET_
threshold on (raw!) jet pt for Type1 MET corrections
edm::EDGetTokenT< std::vector< pat::Jet > > inputJetsToken_
jet input collection
std::string outputMETs_
MET output collection.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
math::XYZPoint Point
point in the space
Definition: LeafCandidate.h:27