CMS 3D CMS Logo

FFTJetPileupEstimator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoJets/FFTJetProducers
4 // Class: FFTJetPileupEstimator
5 //
13 //
14 // Original Author: Igor Volobouev
15 // Created: Wed Apr 20 13:52:23 CDT 2011
16 //
17 //
18 
19 #include <cmath>
20 
21 // Framework include files
26 
27 // Data formats
30 // #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
33 
35 
36 // Loader for the lookup tables
38 
39 #define init_param(type, varname) varname(ps.getParameter<type>(#varname))
40 
41 using namespace fftjetcms;
42 
43 //
44 // class declaration
45 //
47 public:
49  FFTJetPileupEstimator() = delete;
52  ~FFTJetPileupEstimator() override;
53 
54 protected:
55  // methods
56  void produce(edm::Event&, const edm::EventSetup&) override;
57 
58 private:
59  std::unique_ptr<reco::FFTJetPileupSummary> calibrateFromConfig(double uncalibrated) const;
60 
61  std::unique_ptr<reco::FFTJetPileupSummary> calibrateFromDB(double uncalibrated, const edm::EventSetup& iSetup) const;
62 
63  template <class Ptr>
64  inline void checkConfig(const Ptr& ptr, const char* message) {
65  if (ptr.get() == nullptr)
66  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
67  }
68 
71 
73  double cdfvalue;
75  unsigned filterNumber;
76  std::vector<double> uncertaintyZones;
77  std::unique_ptr<fftjet::Functor1<double, double> > calibrationCurve;
78  std::unique_ptr<fftjet::Functor1<double, double> > uncertaintyCurve;
79 
80  // Alternative method to calibrate the pileup.
81  // We will fetch three lookup tables from the database:
82  //
83  // 1. calibration curve table
84  //
85  // 2. uncertainty curve table
86  //
87  // 3. the table that will lookup the uncertainty code
88  // given the uncalibrated pileup value
89  //
90  // It will be assumed that all these tables will have
91  // the same record and category but different names.
92  //
99 
101 };
102 
103 //
104 // constructors and destructor
105 //
109  init_param(double, cdfvalue),
110  init_param(double, ptToDensityFactor),
111  init_param(unsigned, filterNumber),
120  checkConfig(calibrationCurve, "bad calibration curve definition");
121 
123  checkConfig(uncertaintyCurve, "bad uncertainty curve definition");
124 
125  inputToken = consumes<reco::DiscretizedEnergyFlow>(inputLabel);
126 
127  produces<reco::FFTJetPileupSummary>(outputLabel);
128 
129  esLoader.acquireToken(calibTableRecord, consumesCollector());
130 }
131 
133 
134 //
135 // member functions
136 //
137 
138 // ------------ method called to for each event ------------
141  iEvent.getByToken(inputToken, input);
142 
144  const unsigned nScales = h.nEtaBins();
145  const unsigned nCdfvalues = h.nPhiBins();
146 
147  const unsigned fixedCdfvalueBin = static_cast<unsigned>(std::floor(cdfvalue * nCdfvalues));
148  if (fixedCdfvalueBin >= nCdfvalues) {
149  throw cms::Exception("FFTJetBadConfig") << "Bad cdf value" << std::endl;
150  }
151  if (filterNumber >= nScales) {
152  throw cms::Exception("FFTJetBadConfig") << "Bad filter number" << std::endl;
153  }
154 
155  // Simple fixed-point pile-up estimate
156  const double curve = h.data()[filterNumber * nCdfvalues + fixedCdfvalueBin];
157 
158  std::unique_ptr<reco::FFTJetPileupSummary> summary;
159  if (loadCalibFromDB)
160  summary = calibrateFromDB(curve, iSetup);
161  else
162  summary = calibrateFromConfig(curve);
164 }
165 
166 std::unique_ptr<reco::FFTJetPileupSummary> FFTJetPileupEstimator::calibrateFromConfig(const double curve) const {
167  const double pileupRho = ptToDensityFactor * (*calibrationCurve)(curve);
168  const double rhoUncert = ptToDensityFactor * (*uncertaintyCurve)(curve);
169 
170  // Determine the uncertainty zone of the estimate. The "curve"
171  // has to be above or equal to uncertaintyZones[i] but below
172  // uncertaintyZones[i + 1] (the second condition is also satisfied
173  // by i == uncertaintyZones.size() - 1). Of course, it is assumed
174  // that the vector of zones is configured appropriately -- the zone
175  // boundaries must be presented in the increasing order.
176  int uncertaintyCode = -1;
177  if (!uncertaintyZones.empty()) {
178  const unsigned nZones = uncertaintyZones.size();
179  for (unsigned i = 0; i < nZones; ++i)
180  if (curve >= uncertaintyZones[i]) {
181  if (i == nZones - 1U) {
182  uncertaintyCode = i;
183  break;
184  } else if (curve < uncertaintyZones[i + 1]) {
185  uncertaintyCode = i;
186  break;
187  }
188  }
189  }
190 
191  return std::make_unique<reco::FFTJetPileupSummary>(curve, pileupRho, rhoUncert, uncertaintyCode);
192 }
193 
194 std::unique_ptr<reco::FFTJetPileupSummary> FFTJetPileupEstimator::calibrateFromDB(const double curve,
195  const edm::EventSetup& iSetup) const {
197  std::shared_ptr<npstat::StorableMultivariateFunctor> uz = (*h)[calibTableCategory][uncertaintyZonesName];
198  std::shared_ptr<npstat::StorableMultivariateFunctor> cc = (*h)[calibTableCategory][calibrationCurveName];
199  std::shared_ptr<npstat::StorableMultivariateFunctor> uc = (*h)[calibTableCategory][uncertaintyCurveName];
200 
201  const double pileupRho = ptToDensityFactor * (*cc)(&curve, 1U);
202  const double rhoUncert = ptToDensityFactor * (*uc)(&curve, 1U);
203  const int uncertaintyCode = round((*uz)(&curve, 1U));
204 
205  return std::make_unique<reco::FFTJetPileupSummary>(curve, pileupRho, rhoUncert, uncertaintyCode);
206 }
207 
208 //define this as a plug-in
edm::ESHandle< DataType > load(const std::string &record, const edm::EventSetup &iSetup) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Basic3DVector & operator=(const Basic3DVector &)=default
Assignment operator.
void produce(edm::Event &, const edm::EventSetup &) override
FFTJetPileupEstimator()=delete
FFTJetLookupTableSequenceLoader esLoader
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
void acquireToken(const std::string &record, edm::ConsumesCollector iC)
std::unique_ptr< reco::FFTJetPileupSummary > calibrateFromConfig(double uncalibrated) const
static std::string const input
Definition: EdmProvDump.cc:50
edm::EDGetTokenT< reco::DiscretizedEnergyFlow > inputToken
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< fftjet::Functor1< double, double > > calibrationCurve
std::vector< double > uncertaintyZones
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< fftjet::Functor1< double, double > > fftjet_Function_parser(const edm::ParameterSet &ps)
std::unique_ptr< reco::FFTJetPileupSummary > calibrateFromDB(double uncalibrated, const edm::EventSetup &iSetup) const
HLT enums.
std::unique_ptr< fftjet::Functor1< double, double > > uncertaintyCurve
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define init_param(type, varname)
def move(src, dest)
Definition: eostools.py:511
void checkConfig(const Ptr &ptr, const char *message)