Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020 #include <cmath>
00021
00022
00023 #include "FWCore/Framework/interface/EDProducer.h"
00024 #include "FWCore/Framework/interface/Event.h"
00025 #include "FWCore/Framework/interface/MakerMacros.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027
00028
00029 #include "DataFormats/Common/interface/View.h"
00030 #include "DataFormats/Common/interface/Handle.h"
00031 #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
00032 #include "DataFormats/JetReco/interface/FFTJetPileupSummary.h"
00033
00034 #include "RecoJets/FFTJetProducers/interface/FFTJetParameterParser.h"
00035
00036 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
00037
00038 using namespace fftjetcms;
00039
00040
00041
00042
00043 class FFTJetPileupEstimator : public edm::EDProducer
00044 {
00045 public:
00046 explicit FFTJetPileupEstimator(const edm::ParameterSet&);
00047 ~FFTJetPileupEstimator();
00048
00049 protected:
00050
00051 void beginJob();
00052 void produce(edm::Event&, const edm::EventSetup&);
00053 void endJob();
00054
00055 private:
00056 FFTJetPileupEstimator();
00057 FFTJetPileupEstimator(const FFTJetPileupEstimator&);
00058 FFTJetPileupEstimator& operator=(const FFTJetPileupEstimator&);
00059
00060 template<class Ptr>
00061 inline void checkConfig(const Ptr& ptr, const char* message)
00062 {
00063 if (ptr.get() == NULL)
00064 throw cms::Exception("FFTJetBadConfig") << message << std::endl;
00065 }
00066
00067 edm::InputTag inputLabel;
00068 std::string outputLabel;
00069 double cdfvalue;
00070 double ptToDensityFactor;
00071 unsigned filterNumber;
00072 std::vector<double> uncertaintyZones;
00073 std::auto_ptr<fftjet::Functor1<double,double> > calibrationCurve;
00074 std::auto_ptr<fftjet::Functor1<double,double> > uncertaintyCurve;
00075 };
00076
00077
00078
00079
00080 FFTJetPileupEstimator::FFTJetPileupEstimator(const edm::ParameterSet& ps)
00081 : init_param(edm::InputTag, inputLabel),
00082 init_param(std::string, outputLabel),
00083 init_param(double, cdfvalue),
00084 init_param(double, ptToDensityFactor),
00085 init_param(unsigned, filterNumber),
00086 init_param(std::vector<double>, uncertaintyZones)
00087 {
00088 calibrationCurve = fftjet_Function_parser(
00089 ps.getParameter<edm::ParameterSet>("calibrationCurve"));
00090 checkConfig(calibrationCurve, "bad calibration curve definition");
00091
00092 uncertaintyCurve = fftjet_Function_parser(
00093 ps.getParameter<edm::ParameterSet>("uncertaintyCurve"));
00094 checkConfig(uncertaintyCurve, "bad uncertainty curve definition");
00095
00096 produces<reco::FFTJetPileupSummary>(outputLabel);
00097 }
00098
00099
00100 FFTJetPileupEstimator::~FFTJetPileupEstimator()
00101 {
00102 }
00103
00104
00105
00106
00107
00108
00109 void FFTJetPileupEstimator::produce(edm::Event& iEvent,
00110 const edm::EventSetup& iSetup)
00111 {
00112 edm::Handle<TH2D> input;
00113 iEvent.getByLabel(inputLabel, input);
00114
00115 const TH2D& h(*input);
00116 const unsigned nScales = h.GetXaxis()->GetNbins();
00117 const unsigned nCdfvalues = h.GetYaxis()->GetNbins();
00118
00119 const unsigned fixedCdfvalueBin = static_cast<unsigned>(
00120 std::floor(cdfvalue*nCdfvalues));
00121 if (fixedCdfvalueBin >= nCdfvalues)
00122 {
00123 throw cms::Exception("FFTJetBadConfig")
00124 << "Bad cdf value" << std::endl;
00125 }
00126 if (filterNumber >= nScales)
00127 {
00128 throw cms::Exception("FFTJetBadConfig")
00129 << "Bad filter number" << std::endl;
00130 }
00131
00132
00133 const double curve = h.GetBinContent(filterNumber+1U,
00134 fixedCdfvalueBin+1U);
00135 const double pileupRho = ptToDensityFactor*(*calibrationCurve)(curve);
00136 const double rhoUncert = ptToDensityFactor*(*uncertaintyCurve)(curve);
00137
00138
00139
00140
00141
00142
00143
00144 int uncertaintyCode = -1;
00145 if (!uncertaintyZones.empty())
00146 {
00147 const unsigned nZones = uncertaintyZones.size();
00148 for (unsigned i = 0; i < nZones; ++i)
00149 if (curve >= uncertaintyZones[i])
00150 {
00151 if (i == nZones - 1U)
00152 {
00153 uncertaintyCode = i;
00154 break;
00155 }
00156 else if (curve < uncertaintyZones[i + 1])
00157 {
00158 uncertaintyCode = i;
00159 break;
00160 }
00161 }
00162 }
00163
00164 std::auto_ptr<reco::FFTJetPileupSummary> summary(
00165 new reco::FFTJetPileupSummary(curve, pileupRho,
00166 rhoUncert, uncertaintyCode));
00167 iEvent.put(summary, outputLabel);
00168 }
00169
00170
00171 void FFTJetPileupEstimator::beginJob()
00172 {
00173 }
00174
00175
00176 void FFTJetPileupEstimator::endJob()
00177 {
00178 }
00179
00180
00181
00182 DEFINE_FWK_MODULE(FFTJetPileupEstimator);