CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: FFTJetPileupEstimator.cc,v 1.3 2012/11/21 03:13:26 igv Exp $
17 //
18 //
19 
20 #include <cmath>
21 
22 // Framework include files
27 
28 // Data formats
31 // #include "DataFormats/Histograms/interface/MEtoEDMFormat.h"
34 
36 
37 // Loader for the lookup tables
39 
40 #define init_param(type, varname) varname (ps.getParameter< type >( #varname ))
41 
42 using namespace fftjetcms;
43 
44 //
45 // class declaration
46 //
48 {
49 public:
52 
53 protected:
54  // methods
55  void beginJob();
56  void produce(edm::Event&, const edm::EventSetup&);
57  void endJob();
58 
59 private:
63 
64  std::auto_ptr<reco::FFTJetPileupSummary> calibrateFromConfig(
65  double uncalibrated) const;
66 
67  std::auto_ptr<reco::FFTJetPileupSummary> calibrateFromDB(
68  double uncalibrated, const edm::EventSetup& iSetup) const;
69 
70  template<class Ptr>
71  inline void checkConfig(const Ptr& ptr, const char* message)
72  {
73  if (ptr.get() == NULL)
74  throw cms::Exception("FFTJetBadConfig") << message << std::endl;
75  }
76 
79  double cdfvalue;
81  unsigned filterNumber;
82  std::vector<double> uncertaintyZones;
83  std::auto_ptr<fftjet::Functor1<double,double> > calibrationCurve;
84  std::auto_ptr<fftjet::Functor1<double,double> > uncertaintyCurve;
85 
86  // Alternative method to calibrate the pileup.
87  // We will fetch three lookup tables from the database:
88  //
89  // 1. calibration curve table
90  //
91  // 2. uncertainty curve table
92  //
93  // 3. the table that will lookup the uncertainty code
94  // given the uncalibrated pileup value
95  //
96  // It will be assumed that all these tables will have
97  // the same record and category but different names.
98  //
105 };
106 
107 //
108 // constructors and destructor
109 //
111  : init_param(edm::InputTag, inputLabel),
112  init_param(std::string, outputLabel),
113  init_param(double, cdfvalue),
114  init_param(double, ptToDensityFactor),
115  init_param(unsigned, filterNumber),
116  init_param(std::vector<double>, uncertaintyZones),
117  init_param(std::string, calibTableRecord),
118  init_param(std::string, calibTableCategory),
119  init_param(std::string, uncertaintyZonesName),
120  init_param(std::string, calibrationCurveName),
121  init_param(std::string, uncertaintyCurveName),
122  init_param(bool, loadCalibFromDB)
123 {
125  ps.getParameter<edm::ParameterSet>("calibrationCurve"));
126  checkConfig(calibrationCurve, "bad calibration curve definition");
127 
129  ps.getParameter<edm::ParameterSet>("uncertaintyCurve"));
130  checkConfig(uncertaintyCurve, "bad uncertainty curve definition");
131 
132  produces<reco::FFTJetPileupSummary>(outputLabel);
133 }
134 
135 
137 {
138 }
139 
140 //
141 // member functions
142 //
143 
144 // ------------ method called to for each event ------------
146  const edm::EventSetup& iSetup)
147 {
149  iEvent.getByLabel(inputLabel, input);
150 
151  const reco::DiscretizedEnergyFlow& h(*input);
152  const unsigned nScales = h.nEtaBins();
153  const unsigned nCdfvalues = h.nPhiBins();
154 
155  const unsigned fixedCdfvalueBin = static_cast<unsigned>(
156  std::floor(cdfvalue*nCdfvalues));
157  if (fixedCdfvalueBin >= nCdfvalues)
158  {
159  throw cms::Exception("FFTJetBadConfig")
160  << "Bad cdf value" << std::endl;
161  }
162  if (filterNumber >= nScales)
163  {
164  throw cms::Exception("FFTJetBadConfig")
165  << "Bad filter number" << std::endl;
166  }
167 
168  // Simple fixed-point pile-up estimate
169  const double curve = h.data()[filterNumber*nCdfvalues + fixedCdfvalueBin];
170 
171  std::auto_ptr<reco::FFTJetPileupSummary> summary;
172  if (loadCalibFromDB)
173  summary = calibrateFromDB(curve, iSetup);
174  else
175  summary = calibrateFromConfig(curve);
176  iEvent.put(summary, outputLabel);
177 }
178 
179 
181 {
182 }
183 
184 
186 {
187 }
188 
189 
190 std::auto_ptr<reco::FFTJetPileupSummary>
192 {
193  const double pileupRho = ptToDensityFactor*(*calibrationCurve)(curve);
194  const double rhoUncert = ptToDensityFactor*(*uncertaintyCurve)(curve);
195 
196  // Determine the uncertainty zone of the estimate. The "curve"
197  // has to be above or equal to uncertaintyZones[i] but below
198  // uncertaintyZones[i + 1] (the second condition is also satisfied
199  // by i == uncertaintyZones.size() - 1). Of course, it is assumed
200  // that the vector of zones is configured appropriately -- the zone
201  // boundaries must be presented in the increasing order.
202  int uncertaintyCode = -1;
203  if (!uncertaintyZones.empty())
204  {
205  const unsigned nZones = uncertaintyZones.size();
206  for (unsigned i = 0; i < nZones; ++i)
207  if (curve >= uncertaintyZones[i])
208  {
209  if (i == nZones - 1U)
210  {
211  uncertaintyCode = i;
212  break;
213  }
214  else if (curve < uncertaintyZones[i + 1])
215  {
216  uncertaintyCode = i;
217  break;
218  }
219  }
220  }
221 
222  return std::auto_ptr<reco::FFTJetPileupSummary>(
223  new reco::FFTJetPileupSummary(curve, pileupRho,
224  rhoUncert, uncertaintyCode));
225 }
226 
227 
228 std::auto_ptr<reco::FFTJetPileupSummary>
230  const double curve, const edm::EventSetup& iSetup) const
231 {
234  iSetup, calibTableRecord, h);
235  boost::shared_ptr<npstat::StorableMultivariateFunctor> uz =
237  boost::shared_ptr<npstat::StorableMultivariateFunctor> cc =
239  boost::shared_ptr<npstat::StorableMultivariateFunctor> uc =
241 
242  const double pileupRho = ptToDensityFactor*(*cc)(&curve, 1U);
243  const double rhoUncert = ptToDensityFactor*(*uc)(&curve, 1U);
244  const int uncertaintyCode = round((*uz)(&curve, 1U));
245 
246  return std::auto_ptr<reco::FFTJetPileupSummary>(
247  new reco::FFTJetPileupSummary(curve, pileupRho,
248  rhoUncert, uncertaintyCode));
249 }
250 
251 
252 //define this as a plug-in
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
#define NULL
Definition: scimark2.h:8
Summary info for pile-up determined by Gaussian filtering.
std::auto_ptr< fftjet::Functor1< double, double > > calibrationCurve
void beginJob()
Definition: Breakpoints.cc:15
const double * data() const
int iEvent
Definition: GenABIO.cc:243
void produce(edm::Event &, const edm::EventSetup &)
std::auto_ptr< fftjet::Functor1< double, double > > fftjet_Function_parser(const edm::ParameterSet &ps)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< double > uncertaintyZones
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
std::auto_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
std::auto_ptr< reco::FFTJetPileupSummary > calibrateFromDB(double uncalibrated, const edm::EventSetup &iSetup) const
static const Mapper & instance()
#define init_param(type, varname)
void checkConfig(const Ptr &ptr, const char *message)
std::auto_ptr< reco::FFTJetPileupSummary > calibrateFromConfig(double uncalibrated) const