Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:05

0001 /** \class ShiftedMETcorrInputProducer
0002  *
0003  * Vary px, py and sumEt of "unclustered energy" (PFJets of Pt < 10 GeV plus PFCandidates not within jets)
0004  * by +/- 1 standard deviation, in order to estimate resulting uncertainty on MET
0005  *
0006  * \author Christian Veelken, LLR
0007  *
0008  *
0009  *
0010  */
0011 
0012 #include "FWCore/Framework/interface/stream/EDProducer.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/Exception.h"
0017 #include "FWCore/Utilities/interface/InputTag.h"
0018 
0019 #include "DataFormats/METReco/interface/CorrMETData.h"
0020 
0021 #include <string>
0022 
0023 class ShiftedMETcorrInputProducer : public edm::stream::EDProducer<> {
0024 public:
0025   explicit ShiftedMETcorrInputProducer(const edm::ParameterSet&);
0026   ~ShiftedMETcorrInputProducer() override;
0027 
0028 private:
0029   void produce(edm::Event&, const edm::EventSetup&) override;
0030 
0031   typedef std::vector<edm::InputTag> vInputTag;
0032   vInputTag src_;
0033   std::vector<edm::EDGetTokenT<CorrMETData> > srcTokens_;
0034 
0035   struct binningEntryType {
0036     binningEntryType(double uncertainty) : binLabel_(""), binUncertainty_(uncertainty) {}
0037     binningEntryType(const edm::ParameterSet& cfg)
0038         : binLabel_(cfg.getParameter<std::string>("binLabel")),
0039           binUncertainty_(cfg.getParameter<double>("binUncertainty")) {}
0040     std::string getInstanceLabel_full(const std::string& instanceLabel) {
0041       std::string retVal = instanceLabel;
0042       if (!instanceLabel.empty() && !binLabel_.empty())
0043         retVal.append("#");
0044       retVal.append(binLabel_);
0045       return retVal;
0046     }
0047     ~binningEntryType() {}
0048     std::string binLabel_;
0049     double binUncertainty_;
0050   };
0051   std::vector<binningEntryType*> binning_;
0052 
0053   double shiftBy_;
0054 };
0055 
0056 ShiftedMETcorrInputProducer::ShiftedMETcorrInputProducer(const edm::ParameterSet& cfg) {
0057   src_ = cfg.getParameter<vInputTag>("src");
0058 
0059   //--- check that all InputTags refer to the same module label
0060   //   (i.e. differ by instance label only)
0061   for (vInputTag::const_iterator src_ref = src_.begin(); src_ref != src_.end(); ++src_ref) {
0062     for (vInputTag::const_iterator src_test = src_ref; src_test != src_.end(); ++src_test) {
0063       if (src_test->label() != src_ref->label())
0064         throw cms::Exception("ShiftedMETcorrInputProducer")
0065             << "InputTags specified by 'src' Configuration parameter must not refer to different module labels !!\n";
0066     }
0067   }
0068 
0069   shiftBy_ = cfg.getParameter<double>("shiftBy");
0070 
0071   if (cfg.exists("binning")) {
0072     typedef std::vector<edm::ParameterSet> vParameterSet;
0073     vParameterSet cfgBinning = cfg.getParameter<vParameterSet>("binning");
0074     for (vParameterSet::const_iterator cfgBinningEntry = cfgBinning.begin(); cfgBinningEntry != cfgBinning.end();
0075          ++cfgBinningEntry) {
0076       binning_.push_back(new binningEntryType(*cfgBinningEntry));
0077     }
0078   } else {
0079     double uncertainty = cfg.getParameter<double>("uncertainty");
0080     binning_.push_back(new binningEntryType(uncertainty));
0081   }
0082 
0083   for (vInputTag::const_iterator src_i = src_.begin(); src_i != src_.end(); ++src_i) {
0084     for (std::vector<binningEntryType*>::const_iterator binningEntry = binning_.begin(); binningEntry != binning_.end();
0085          ++binningEntry) {
0086       srcTokens_.push_back(consumes<CorrMETData>(
0087           edm::InputTag(src_i->label(), (*binningEntry)->getInstanceLabel_full(src_i->instance()))));
0088       produces<CorrMETData>((*binningEntry)->getInstanceLabel_full(src_i->instance()));
0089     }
0090   }
0091 }
0092 
0093 ShiftedMETcorrInputProducer::~ShiftedMETcorrInputProducer() {
0094   for (std::vector<binningEntryType*>::const_iterator it = binning_.begin(); it != binning_.end(); ++it) {
0095     delete (*it);
0096   }
0097 }
0098 
0099 void ShiftedMETcorrInputProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0100   unsigned countToken(0);
0101   for (vInputTag::const_iterator src_i = src_.begin(); src_i != src_.end(); ++src_i) {
0102     for (std::vector<binningEntryType*>::iterator binningEntry = binning_.begin(); binningEntry != binning_.end();
0103          ++binningEntry) {
0104       edm::Handle<CorrMETData> originalObject;
0105       evt.getByToken(srcTokens_.at(countToken), originalObject);
0106       ++countToken;
0107 
0108       double shift = shiftBy_ * (*binningEntry)->binUncertainty_;
0109 
0110       auto shiftedObject = std::make_unique<CorrMETData>(*originalObject);
0111       //--- MET balances momentum of reconstructed particles,
0112       //    hence variations of "unclustered energy" and MET are opposite in sign
0113       shiftedObject->mex = -shift * originalObject->mex;
0114       shiftedObject->mey = -shift * originalObject->mey;
0115       shiftedObject->sumet = shift * originalObject->sumet;
0116 
0117       evt.put(std::move(shiftedObject), (*binningEntry)->getInstanceLabel_full(src_i->instance()));
0118     }
0119   }
0120 }
0121 
0122 #include "FWCore/Framework/interface/MakerMacros.h"
0123 
0124 DEFINE_FWK_MODULE(ShiftedMETcorrInputProducer);